#M Awais - Subscriptions

1 messages · Page 1 of 1 (latest)

knotty mural
#

Hello! Stripe itself won't prevent creation of two Subscriptions in that timeframe, but you can write code on your end to prevent it from happening.

naive snow
#

i have to create subscription if there are two employees of a companies...
But if someone sends two requests at the same time, then both request tries to create the subscription in around 5 seconds...

knotty mural
#

Is that being caused by someone clicking twice on a subscribe button rapidly?

#

Or is something else causing it?

naive snow
#

I am not sure about that... let's say if I have two browsers open with same account(of a portal) then refresh both of those pages
I am using laravel middleware to ensure that companies have a subscription if they have more than 1 employee.
Now that middleware apply to both request and tries to create the subscription. In result there will be two subscription instead of one....

knotty mural
#

It sounds like you need to add a check server side to confirm there's no existing Subscription before creating a new one.

naive snow
#

I am hitting two requests at the same time, so there is no way to know if there is a active subscription as it will take time to create a subscription on stripe (curl/api request will take some seconds, in that time I don't know how I can check if there is already a request gone to stripe.)

knotty mural
#

Are the requests being sent to the same server or different servers?

naive snow
#

same server..

knotty mural
#

Can you implement a queue system on the server that processes incoming Subscription creation requests one at a time? That way you can check for an existing Subscription before creating a new one safely.

naive snow
#

I have not worked with queues but have some information, so if i add an item to queue then what should I display to customer?

knotty mural
#

A processing/loading indicator or similar is the usual approach.

#

Or a "creating Subscription" message.

naive snow
#

ok thanks, I will try it....

knotty mural
#

Another option is to make an entry in your database or other shared storage location that indicates a Subscription is being created for a particular company/employee/whatever combo of information you need, then start the Subscription creation process once that data is set. Then, at the beginning of every Subscription creation, you check to see if a Subscription creation is already in flight or if an existing Subscription already exists and stop if it does.

naive snow
knotty mural
naive snow
#

I have setup a webhook

#

should I wait for it?

knotty mural
#

Again, depends on your integration and your specific use case. Maybe?

naive snow
#

I think i can check something in
Customer Subscription Updated event right?

knotty mural
#

What do you mean by "check something"?

naive snow
#

like if a subscription is created or failed?

#

and then update the flag in database to show or hide the spinner/loader

knotty mural
#

Subscriptions have more statuses than that, and may have a more complex lifecycle than you're expecting, especially when async methods of payment are involved.

#

I recommend reading through the link I provided above and then letting us know if you have questions after that.

naive snow
#

I have read the subscription many time already...

knotty mural
#

What does "something" mean though?

#

And when are you checking it?

#

What point in the Subscription lifecycle?

naive snow
#

like maybe I can check the subscription status...
on every subscription update event?

knotty mural
#

I need more information. You can certainly do that, but I'm not clear why you want to do what/what your goal is with doing that. Are you asking about checking if the Subscription "failed" or not? Meaning if it was created or not?

naive snow
#

if two request comes to server, I can create a flag in one of these requests, that a subscription request is sent to the stripe server for this customer.
Then second request and first will show a spinner until webhook event arrives where If i see subscription status as active then i can change database flag to 1 maybe to indicate that subscription was created and then both of those request where spinner was, can then show the normal page?

knotty mural
#

Yes, you could technically do it that way, but I'm confused about why you would take that approach? Specifically, waiting for the webhook to tell you the Subscription is active and then using that to trigger display of the normal page implies you're not using Stripe.js to confirm the initial Subscription Setup or Payment Intent, which means you're not handling things like 3D Secure or async methods of payment. Is that the case?

naive snow
#

I already have payment method as default when a customer signup, and also in webhook even I can check if subscription status is incomplete, I can display(redirect) them a page where they can confirm the payment or add a new card in case issue like low balance etc...

knotty mural
#

Are you charging the customer when the Subscription begins, or is it free initially?

naive snow
#

there are two subscription
portal subscription that began when adding the card (company signup). so this one charge the customer $49

then there is another one which will start when every they add two employees...

knotty mural
#

Okay, so what if authentication (like 3D Secure) is required when the Subscription begins?

naive snow
#
         ...................
        $user->newSubscription('qcsEmployee', 'qcsEmployee')
                ->quantity($noOfEmployees)->create(null, [], $subscriptionOptions);
            } catch (IncompletePayment $exception) {
                $obj->status = 2;
                $obj->response = redirect()->route('cashier.payment', $exception->payment->id);
                return $obj;
            } catch (\Exception $e) {
                $obj->status = 0;
                $obj->message = $e->getMessage();
                return $obj;
            }

If an incomplete payment /3d secure error is thrown I redirect the user to a page where they will be asked to confirm the payment or add a new payment method