Code Monkey home page Code Monkey logo

Comments (6)

sebastianro92 avatar sebastianro92 commented on August 21, 2024

Its recomendable add a delay in the listener to comprobe if the "customer.subscription.created" its ok?

image

from cashier-stripe.

driesvints avatar driesvints commented on August 21, 2024

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.

sebastianro92 avatar sebastianro92 commented on August 21, 2024

@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.

  1. Cancel a customer subscription from the Stripe dashboard
  2. 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,
         ]);
  1. 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.

laravel.log

This is my handle listener

image

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

And this is the total events when i created a new customer subscription

image

from cashier-stripe.

driesvints avatar driesvints commented on August 21, 2024

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.

sebastianro92 avatar sebastianro92 commented on August 21, 2024

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.

driesvints avatar driesvints commented on August 21, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.