Assign metadata to invoice in Stripe subscriptions

好久不见. 提交于 2020-01-02 08:47:08

问题


here is my code to create a subscription:

$subscription = \Stripe\Subscription::create(array(
        "customer" => $customer->id, //customer id from previous lines after creating customer
        "plan" => 'premium-plan',
        'metadata' => ['user_id' => $userId]
        ));

here is my code to update plans:

$subscriptionUpdate = \Stripe\Subscription::retrieve($subscriptionIdFromDatabase);
    $subscriptionUpdate->plan = 'best-premium-plan';
    $subscriptionUpdate->save();

How can I add metadata to an invoice if the user wants to update plans?

if the user wants to update their plan using the second block of code, it will generate an invoice. how can i assign metadata to that invoice when user changes plans?


回答1:


Perform an update on the invoice.

Invoice::update($invoiceId, ['metadata' => [
    'my_data' => $someVar
]]);

https://stripe.com/docs/api/metadata



来源:https://stackoverflow.com/questions/43786878/assign-metadata-to-invoice-in-stripe-subscriptions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!