Comments (6)
Its recomendable add a delay in the listener to comprobe if the "customer.subscription.created" its ok?
![image](https://private-user-images.githubusercontent.com/21010074/333968622-b0ca9dc4-2d4b-4d23-9de7-ae2197c4955b.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjM4MDk1MTEsIm5iZiI6MTcyMzgwOTIxMSwicGF0aCI6Ii8yMTAxMDA3NC8zMzM5Njg2MjItYjBjYTlkYzQtMmQ0Yi00ZDIzLTlkZTctYWUyMTk3YzQ5NTViLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MTYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODE2VDExNTMzMVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTAzMDFiODNiYmNlZGJlMWFjN2I4ZGQxZmUwZmY1MTJmMDQxN2JiYTBiYTM0NjNkNWE3OWZhMDI0ZGFmOTcwM2QmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.1uuT8YI5oW7dF7bsokxV70WjVKwon3xA_aPvZnom-F4)
from cashier-stripe.
I don't really understand this. There should only be a single customer.subscription.created
event fired for each subscription. We already check for the stripe_id
here: https://github.com/laravel/cashier-stripe/blob/15.x/src/Http/Controllers/WebhookController.php#L73
I assume you "retried" the webhook? But that still doesn't explains the error because there's enough time between the webhooks for handling this event without it being flaky.
Could you please provide a repo and then post exact steps to reproduce this one?
laravel new bug-report --github="--public"
from cashier-stripe.
@driesvints Unfortunately, there is no exact way to replicate this issue as it does not always occur, but rather occurs randomly.
However, I'm almost sure that at some point the subscription that is created for the client is repeated twice; otherwise why would you get this error?
"Duplicate entry 'sub_1PL6sUFd5Q4HlP151A2WhXwH' for key 'subscriptions.subscriptions_stripe_id_unique'"
However, although I get this error, only one record is saved in the DB and this is fine, but there is a problem, when trying to save the second record and it generates the error, the "client.subscription.created" hook not is executed, causing my Application to fail because it does not detect the event and does not execute the functions that should be executed.
I hope it helps, but I share the error log that I just obtained a few minutes ago doing the process I mention.
- Cancel a customer subscription from the Stripe dashboard
- Then using the API to create a checkout session and add a new subscription for this customer
$checkout_session = $stripeClient->checkout->sessions->create([
'success_url' => config('access.STRIPE_REDIRECT_BACK'),
'cancel_url' => config('access.STRIPE_REDIRECT_BACK'),
'line_items' => [
[
'price' => config('access.LICENCE_PRICE_KEY'),
'quantity' => 1,
],
],
'mode' => 'subscription',
'allow_promotion_codes' => true,
'customer' => $customer->stripe_id,
]);
- Finally receive the Hooks, this is when possibly receive an error in "customer.subscription.created" -> "Integrity constraint violation: 1062 Duplicate entry 'sub_1PL6sUFd5Q4HlP151A2WhXwH' for key 'subscriptions.subscriptions_stripe_id_unique'" and the rest fails.
This is my handle listener
![image](https://private-user-images.githubusercontent.com/21010074/334182922-369cf974-39f9-496a-9dc7-564905197b2d.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjM4MDk1MTEsIm5iZiI6MTcyMzgwOTIxMSwicGF0aCI6Ii8yMTAxMDA3NC8zMzQxODI5MjItMzY5Y2Y5NzQtMzlmOS00OTZhLTlkYzctNTY0OTA1MTk3YjJkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MTYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODE2VDExNTMzMVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWM2Yzc1YTEwZTBkM2JmZWUwYjJjNGU0NzE0ZjI0ZWM1NTg4NzcyNGU5MmUzNDYzNTI5ZjMyNGViOWIxNzBhNDYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.gH92mDcRWEtBkZ2QarPXekvfUJ-svCfkLb7r0GQBHhQ)
Is normal that when I create a new subscription for a customer, the "customer.subscription.updated" hook is executed?
This is a console.log from my Front dev.
![image](https://private-user-images.githubusercontent.com/21010074/334186105-1f0403f6-b76f-45de-86ae-459553f1e6ed.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjM4MDk1MTEsIm5iZiI6MTcyMzgwOTIxMSwicGF0aCI6Ii8yMTAxMDA3NC8zMzQxODYxMDUtMWYwNDAzZjYtYjc2Zi00NWRlLTg2YWUtNDU5NTUzZjFlNmVkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MTYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODE2VDExNTMzMVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTY2N2I5MzdmNzIyNGFjMzJmM2QzZTE5N2I3MTVkNWU3MzBlN2JkZWFkNDk1ZDQ5MDRmMGY1MjQ2MmJkMmZiZGQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.UtOs6Caj2g4YOUT04Ly1XhhqXVvWZgamqlFrX9j_wNQ)
And this is the total events when i created a new customer subscription
![image](https://private-user-images.githubusercontent.com/21010074/334187487-7e8befeb-ec80-4936-8b4b-a2f96e52ee9a.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjM4MDk1MTEsIm5iZiI6MTcyMzgwOTIxMSwicGF0aCI6Ii8yMTAxMDA3NC8zMzQxODc0ODctN2U4YmVmZWItZWM4MC00OTM2LThiNGItYTJmOTZlNTJlZTlhLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MTYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODE2VDExNTMzMVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTYyM2EzYTQyZmJhZjcyNjdkZTkxZjI4NWY4ZWM4MTBmMTRjMzJiZmRjNzJhNGQ0OTZlZjc4MDMyMTdhZTNjNjcmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.PAUXtET_EupZagzYqRsycqMcurHjaqIDUwtzISOYr24)
from cashier-stripe.
I'm sorry but I couldn't reproduce it using your example. You also seem to be working outside the context of Cashier with directly talking to the Stripe client. That's not supported I'm afraid. If you can post a clear code example that reproduces the issue I can have another look but right now I don't believe there's a major issue and this is most likely something specifically happening for you. I suggest to never work outside the context of Cashier.
And yes it's normal that updated events are sent together with the created events. Stripe updates the subscription after creating it.
from cashier-stripe.
Hi @driesvints maybe i have the same problem #1300 and #1307 ?
In my case is when add a new customer subscription and the error is randomly, i updated the checkout portal using cashier according your suggestions.
`
$customer = auth()->user();
$checkout_session = $customer->newSubscription('default', 'my_price_key')
->allowPromotionCodes()
->collectTaxIds()
->checkout([
'success_url' => config('access.STRIPE_REDIRECT_BACK'),
'cancel_url' => config('access.STRIPE_REDIRECT_BACK'),
]);
// * Redirect client to Stripe Checkout
return response()->json($checkout_session->url);
`
from cashier-stripe.
I'm sorry @sebastianro92 but I'm going to leave things be. I just don't feel there's a widespread issue right now.
from cashier-stripe.
Related Issues (20)
- Support for upcoming changes to Stripe Prefilling saved cards in Checkout HOT 3
- Support for additional important Stripe signals for fraud detection HOT 1
- trial_ends_at is getting marked as NULL when webhook is received HOT 3
- Make card default for subscriptions via Stripe checkout HOT 3
- Confirm Payment notification never sent HOT 8
- Support for new usage Meters HOT 3
- Multiple Keys for Webhook Signing HOT 4
- invoice() method of subscription creates empty invoice HOT 5
- paymentMethods not returning bank accounts HOT 1
- Subscriptions: Support of billing cycle and trial in checkout HOT 1
- Migrate from the legacy metered billing system to use the new stripe event meters HOT 4
- No tax is calculated for single charges or single charge checkouts HOT 3
- Can't set payment_behavior when creating a new subscription HOT 9
- Cashier routes should have "web" middleware HOT 2
- Stripe Webhook using /stripe/webhook returning 301 in stripe dashboard HOT 1
- Collation not specifically set on stripe_id to correct utf8_bin HOT 2
- Cancel Subscription: Method subscription() should get last subcription but it get first subscription
- Cannot rollback migrations with SQLite
- Bug: "The attribute [stripe_id] either does not exist or was not retrieved for model [App\Models\User]" HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cashier-stripe.