Closed connecteev closed 4 years ago
Hey @connecteev. Think you missed this section:
@driesvints I tried it but it does not work
This works fine:
Stripe::setApiKey(env('STRIPE_SECRET'));
\Stripe\Subscription::update(
$stripeSubscriptionId,
['coupon' => $couponCode]
);
However, this throws an exception:
$stripeSubscription = $currentSubscription->asStripeSubscription();
$stripeSubscriptionId = $stripeSubscription->id;
$stripeSubscription->update(
json_encode(['coupon' => $couponCode])
);
Exception error message:
{
"error": "No API key provided. (HINT: set your API key using \"Stripe::setApiKey(<API-KEY>)\". You can generate API keys from the Stripe web interface. See https://stripe.com/api for details, or email support@stripe.com if you have any questions."
}
which is strange, because I have these defined in my .env file
STRIPE_KEY=your-stripe-key
STRIPE_SECRET=your-stripe-secret
Does it work for you? Can you apply a coupon this way?
@driesvints one more note:
If I manually call Stripe::setApiKey(env('STRIPE_SECRET'));
I can get past the "No API key provided." error exception. Even though calling the Stripe library directly like that defeats the purpose, I am encountered with a different error.
{
"error": "No such subscription: {\"coupon\":\"coupon_forever_plan\"}"
}
Note that this is a valid subscription and valid coupon code, and it works fine on doing this:
Stripe::setApiKey(env('STRIPE_SECRET'));
\Stripe\Subscription::update(
$stripeSubscriptionId,
['coupon' => $couponCode]
);
(just trying to convey that in all likelihood it's not user-error)
Hmm, odd. The example in the docs indeed appears to be wrong. I'll rectify it.
I've also send in a PR to add two convenience methods for updating the underlying stripe objects: https://github.com/laravel/cashier/pull/943
thanks @driesvints once this is merged in I will test my code again
There is no way to update a subscription using Cashier. I'd like to be able to use Cashier to do the following:
It would also be nice to be able to do other things such as:
But even if we just get 1, that would be a start :)
Thanks for the work on Cashier, btw...definitely makes our lives easier.