#sergixel04

1 messages · Page 1 of 1 (latest)

tiny knollBOT
#

Hello! We'll be with you shortly. Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

unborn merlin
#

I paste the code:

#
public function storeBusiness(Request $request, BusinessService $businessService)
    {
        $request->validate([
            'subCycle' => 'required',
        ];

        $stripe = new \Stripe\StripeClient(config('app.stripe_secret'));
        $user = User::find(auth()->id());

        if ($request->subCycle == 'monthly') {
            $priceId = config('app.plan_extra_monthly');
        } else {
            $priceId = config('app.plan_extra_yearly');
        }

        try {
            $createdSubscription = $stripe->subscriptions->create([
                'customer' => $user->stripe_id,
                'items' => [
                    ['price' => $priceId],
                ],
                'automatic_tax' => ['enabled' => true],
                'description' => 'THIS SUBSCRIPTION BELONGS TO: ' . $request->name,
            ]);

            if ($createdSubscription->status !== 'active' && $createdSubscription->status !== 'incomplete') {
                return back()->with('message', 'It wasnt possible to charge. Please contact with us.');
            }

            $createdBusiness = $businessService->onAddBusiness($request);
            if ($createdBusiness) {
                $user->addSms(40);
                $createdBusiness->businesses()->create([
                    'user_id' => $createdBusiness->id,
                    'subscription_id' => $createdSubscription->id,
                    'billing_cycle' => $request->subCycle,
                    'token' => Str::random(32),
                ]);

                return redirect()->route('activation');
            }
        } catch (\Exception $e) {
            Log::error('Error to charge', [
                'error' => $e->getMessage(),
            ]);

            return back()->with('message', 'An error has ocurred. Please contact with us');
        }
    }
#

I have that logic to create a subscription and an account in my database. It happened that the payment was incomplete due to 3D Secure payment intent

#

How could I handle that?

gray glade
#

You'd need to retreive the PaymentIntent client-secret associated with the invoice generated by the subscription and use confirmPayment client-side when the customer is on-session

You can get the payment intent by looking at
subscription.latest_invoice.payment_intent

unborn merlin
#

I think I don't get it 😦

unborn merlin
#

How can I use confirmPayment client-side? Is that the popup it has to appear?

gray glade
#

The link above has the detailed steps

#

I'd actually start from the top

unborn merlin
#

Perfect thank you so much hanzo