title: Plan already exists - stripe/php
body: <p>I would like to conclude a monthly plan created by myself with the customer's ID and complete the fixed amount payment.</p>
  
  <p>However, when creating a "Subscription" after creating the original plan, "Plan already exists" is output.</p>
  
  <p>I can not truly understand the above error. For example, if I create and run "Subscription" without creating original plan, the code will work correctly.</p>
  
  <p>The log at that time is below. However, with this, it is impossible to judge what kind of plan contents are adapted to customers. How can you associate your plan with "Subscription"?</p>
  
  <h1>Implement Subscription without creating a plan</h1>
  
  <pre><code>// echo $customer-&gt;id;
  // $my_original_plan =  \Stripe\Plan::create(array(
  // "id"  =&gt; "basic-monthly",
  // "interval"  =&gt;  "month",
  // "currency"  =&gt; "jpy",
  // "product" =&gt; array("name" =&gt; "aaaaaa"),
  // "amount"  =&gt; 9800
  // ));
  // echo $my_original_plan;
  
  $subscription =  \Stripe\Subscription::create(array(
  "customer" =&gt; "$customer-&gt;id",
  "items" =&gt; array(
    array(
      "plan" =&gt; "basic-monthly",
    ),
  )
  ));
  
  echo $subscription;
  </code></pre>
  
  <h1>The above log</h1>
  
  <pre><code>Stripe\Subscription JSON: {
      "id": "sub_CXKozer939U80A",
      "object": "subscription",
      "application_fee_percent": null,
      "billing": "charge_automatically",
      "billing_cycle_anchor": 1521674075,
      "cancel_at_period_end": false,
      "canceled_at": null,
      "created": 1521674075,
      "current_period_end": 1524352475,
      "current_period_start": 1521674075,
      "customer": "cus_CXKovj687dz1Po",
      "days_until_due": null,
      "discount": null,
      "ended_at": null,
      "items": {
          "object": "list",
          "data": [
              {
                  "id": "si_CXKoBTbLbBICEL",
                  "object": "subscription_item",
                  "created": 1521674075,
                  "metadata": [],
                  "plan": {
  ...
  </code></pre>
  
  <h1>Plan already exists</h1>
  
  <pre><code>// echo $customer-&gt;id;
  
  $my_original_plan =  \Stripe\Plan::create(array(
  "id"  =&gt; "basic-monthly",
  "interval"  =&gt;  "month",
  "currency"  =&gt; "jpy",
  "product" =&gt; array("name" =&gt; "aaaaaa"),
  "amount"  =&gt; 9800
  ));
  
  // echo $my_original_plan;
  
  
  $subscription =  \Stripe\Subscription::create(array(
  "customer" =&gt; "$customer-&gt;id",
  "items" =&gt; array(
  array(
  "plan" =&gt; "basic-monthly",
  ),
  )
  ));
  
  echo $subscription;
  </code></pre>
  
  <h1>All source code</h1>
  
  <pre><code>&lt;?php
  
  header("Content-type: text/plain; charset=UTF-8");
  
  if(isset($_SERVER['HTTP_X_REQUESTED_WITH'])
  &amp;&amp; strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')
  {
  if (isset($_POST['request']))
  {
  
  //make token from ajax js 
  $token_from_js = $_POST['request'];
  
  //stripe from composer
  require_once 'vendor/autoload.php';
  
  //set api key
  \Stripe\Stripe::setApiKey("sk_test_");
  
  //make customer info 
  $customer =  \Stripe\Customer::create(array(
  "description" =&gt; "taylor@example.com",
  "source" =&gt; "$token_from_js",
  ));
  
  // echo $customer-&gt;id;
  
  $my_original_plan =  \Stripe\Plan::create(array(
  "id"  =&gt; "basic-monthly",
  "interval"  =&gt;  "month",
  "currency"  =&gt; "jpy",
  "product" =&gt; array("name" =&gt; "aaaaaa"),
  "amount"  =&gt; 9800
  ));
  
  // echo $my_original_plan;
  
  
  $subscription =  \Stripe\Subscription::create(array(
  "customer" =&gt; "$customer-&gt;id",
  "items" =&gt; array(
  array(
  "plan" =&gt; "basic-monthly",
  ),
  )
  ));
  
  echo $subscription;
  };
  };
  
  ?&gt;
  </code></pre>