Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[12.x] Add withPromotionCode method #1032

Merged
merged 1 commit into from
Nov 24, 2020
Merged

[12.x] Add withPromotionCode method #1032

merged 1 commit into from
Nov 24, 2020

Conversation

driesvints
Copy link
Member

This adds a withPromotionCode method to the subscription builder in addition to the withCoupon method in order to provide for Stripe's new promotion codes. When using this method, the API ID for the promotion code needs to be passed, not the promotion code itself.

$subscription = Auth::user()->newSubscription('default', 'price_xxx')
    ->withPromotionCode('promo_xxx')
    ->create($paymentMethod);

@Naveedali1234
Copy link

how can we retrieve the promotion code using promo code?

@driesvints
Copy link
Member Author

@Naveedali1234 I don't understand your question, can you explain a bit more thoroughly?

@Naveedali1234
Copy link

okay let me explain it.

i am trying to verify promotion code if it exist in stripe dashboard or not. so when a user enter a promo code in text box for example: 7OIzSX3E

now i will need to retrieve this promo code from stripe dashboard if it exist or not, so i fetch it in this way: $promotion_code = \Stripe\PromotionCode::retrieve($request_input('promo_code'), []);

but this input is only the code and this input needs ID of the promotion code.

How can i achieve it?

i am sorry if i am asking something different, but i am just trying to fetch the response of it.

@driesvints
Copy link
Member Author

You can use the Stripe API like you posted above. I myself would just hardcode a list of promotion codes and their ids in the app itself. If you need something more dynamic, use the Stripe API.

@jfvoliveira
Copy link

Hey there @driesvints .

Couldn't we use a promo code as well when swaping subscriptions?

$user->subscription('default', $newPriceId)
   ->withPromotionCode($code)
   ->swapAndInvoice($newPriceId);

This doesn't work. From what I've been able to check, it only works in newSubscriptions.
Shouldn't it also work with swaps or am I thinking wrong?

Thanks

@driesvints
Copy link
Member Author

@jfvoliveira done: #1230

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants