-
Notifications
You must be signed in to change notification settings - Fork 684
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] Stripe Checkout Support #1007
Conversation
01496b8
to
8e44f86
Compare
Wrote the docs for this today: laravel/docs#6465 |
We've updated |
Hi, Whenever I create a subscription via checkout, Stripe send to webhooks, one for the subscription creation (with a status Any thoughts on that ? |
@JhumanJ The order that webhook events are delivered isn't guaranteed. There are a couple options. (1) listen for the |
@cjavilla-stripe I understand the issue, but I'm worried that everyone will be facing it with the current state of this pull request... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any code that would update the User's default payment method. Am I missing something or has it been overlooked?
@dannywp the current |
179218c
to
a77b65b
Compare
@driesvints correct, but only if the stripe customer has a default payment method. I have been implementing stripe hosted checkout for subscriptions and it seems like the card that is attached to the customer is not set as the default payment method. |
@dannywp last time I tried it it worked for me. You need to explicitly check it as the new default payment method. |
@JhumanJ heya, you're gonna have to help me walk through on how to recreate your situation. I haven't had a situation yet where the original subscription was set to incomplete first and the subscription update event was triggered. Can you share the specifics on how to recreate your use case? |
@dannywp to jump in with a bit more context. When creating a subscription with Checkout, a new PaymentMethod is created and a new Subscription is created. You can either create the Checkout session with or without a customer object. If no customer object is provided, then a new customer will also be created. When collecting recurring payments for a subscription, Stripe will determine which payment method to use for the invoice by looking in a few places. First, we'll look at the Subscription itself to see if it has a default_payment_method set. This is where the payment method is set in the case of Checkout in Second, we'll look at the Subscriptions Third, if there is no Fourth, we'll look at the customer's If you are collecting payments outside of the automatic recurring payments that result from the Subscription created with Checkout, I would recommend storing the ID of the default_payment_method from the original subscription as a field in your db, then using that for future payments. (I don't know whether or not this is built into the existing Checkout flow with cashier :D) Hope this helps 👍 |
@driesvints I'm involved with a charity trying to solve the need for foodbanks and was thinking of waiting for this PR to be merged before implementing the "donate" function on their website. Are you hoping to have this merged in the next few weeks, or is it more likely to be next year? Completely understand either way. If I had the expertise I would offer to help. |
@StephenGillCoop We're currently evaluating the feature internally. I don't have an ETA, sorry. |
31ccf74
to
4166903
Compare
@JhumanJ I again tried out scenarios with test cards from https://stripe.com/docs/testing but don't encounter any unexpected bug from happening. I think it's best that you be really specific about the scenario that you encounter if I'm to recreate it. |
I just had the same issue as @JhumanJ. In my case the |
@andrebreia we can't account for errors in your code. If you don't have an error in your code and the webhooks work properly then I think the feature works as expected. |
@driesvints That's fair. Just thought that there might be situations where the webhook could fail. |
c1d8506
to
7f4611a
Compare
@abbasali thanks for that input. I've pushed some changes which now allow These changes have removed the "quantity" parameter on the |
@driesvints The changes look good, thanks. However, it doesn't support the inline pricing object. Would be nice to have inline |
@abbasali it does have support for that though: $checkout = Auth::user()->checkout([
[
'price_data' => [...]
],
]);
return view('checkout', compact('checkout')); |
Ok cool. Wasn't in the PR docs so thought it isn't there :). Thanks. |
@abbasali added an example. It's a bit more cumbersome to add a custom item together with existing price ID products. I'm not sure what we can do there to improve the API. |
@driesvints What if the API is changed to something like.. $checkout = $user->checkout()
->addItem('price_xxx', 1)
->addItem('price_yyy')
->addItem(['price_data' => [...]])
->create(); or something along those lines? Otherwise, the current API looks good. Yes, the custom price is a bit cumbersome but if documented and explained properly - it should be fine. |
Can I use this branch on my Laravel project while it hasn't been merged to 12.x? |
@matheuscandido purely on your own risk as we might merge and delete this branch at any time. Forking the package and requiring it as a VCS might be the better choice. |
@abbasali yeah I'm just gonna leave it as is I think. |
@matheuscandido I also needed the Checkout feature. So what I did is created a custom trait Then in User model, I used the Lastly, for the button HTML, I created a custom view (again copied the code from this branch). I didn't need the subscription logic so left out all other modified files/logic from this branch and just the above 3 files made it work for me. Later when this branch goes into 12.x, I will simply remove the trait |
is there any timeline for this branch to be merged? |
No sorry |
This will be in next week's release! |
Great news! Thanks for the update. |
Fixed priced items don't seem to make it to database? I am using p.s i can get to the success url |
Please open an issue |
This PR adds functionality for Stripe checkout and is a continuation of #652. All concerns on the original PR have been resolved since.
Docs: laravel/docs#6465
Usage
Checking out a single priced product:
Checking out a single priced product with a specific quantity:
Checking out multiple priced products and optionally assign quantities to some:
Checking out a single priced product and allow promotional codes to be applied:
Checking out a new $12 priced product (this will create a new product in the dashboard):
Checking out a new $12 priced product together with a Price ID product:
Check out a subscription:
Check out a subscription and allow promotional codes to be applied:
Then place any of these in a view:
{!! $checkout->button() !!}
Button Styling
By default a generated checkout button will have the following styling:
It's however easy to style this. Pass either a custom
style
orclass
attribute:Todos
Closes #637