Stripe: Add metadata to subscription on creation
<p>So I've been trying to learn Stripe API recently... I'm getting there slowly but have come to a bit of a speed bump with this metadata information.</p>

<p>What I am looking to achieve is add metadata to the subscription when the subscription and customer are created.</p>

<p>This is the original script to create a customer &amp; subscription:</p>

<pre><code>$customer = \Stripe\Customer::create(array(
               'email' =&gt; $_POST['stripeEmail'],
               'source'  =&gt; $_POST['stripeToken'],
               'customer' =&gt; $randomID,
               'plan' =&gt; $item
              ));
</code></pre>

<p>And in the documentation I can see that there are multiple areas to add further information? Example:</p>

<pre><code>Stripe\StripeObject JSON: {
  "id": "sub_9aZ6q72UQs7664",
  "object": "subscription",
  "application_fee_percent": null,
  "cancel_at_period_end": false,
  "canceled_at": null,
  "created": 1479520145,
  "current_period_end": 1482112145,
  "current_period_start": 1479520145,
  "customer": "XXXXXXX",
  "discount": null,
  "ended_at": null,
  "livemode": false,
  "metadata": {
  },
  "plan": {
    "id": "AdFree",
    "object": "plan",
    "amount": 700,
    "created": 1479261871,
    "currency": "gbp",
    "interval": "month",
    "interval_count": 1,
    "livemode": false,
    "metadata": {
    },
    "name": "AdFree Hosting",
    "statement_descriptor": "WEBSITE",
    "trial_period_days": null
  },
  "quantity": 1,
  "start": 1479520145,
  "status": "active",
  "tax_percent": null,
  "trial_end": null,
  "trial_start": null
}
</code></pre>

<p>What I am interested in is the two <code>metadata</code> elements. The first one I have figured out is the <code>Customer metadata</code> which can be added like so... </p>

<pre><code>$customer = \Stripe\Customer::create(array(
               'email' =&gt; $_POST['stripeEmail'],
               'source'  =&gt; $_POST['stripeToken'],
               'customer' =&gt; $randomID,
               'plan' =&gt; $item,
               'metadata' =&gt; array("test1" =&gt; "test2", "testa" =&gt; "testb")
              ));
</code></pre>

<p>Although I am looking to add information to the second metadata tag so it will be added to the <code>"plan" (subscription)</code>. </p>

<p>I have checked around and can't seem to find any answers. I'm hoping somebody might be able to push me in the right direction. </p>

<p>I've also read the documentation and can't find any relevant help there, although the docs can be found here:</p>

<p><a href="https://stripe.com/docs/api#create_subscription" rel="noreferrer">https://stripe.com/docs/api#create_subscription</a></p>