mercredi 26 mai 2021

How to retrieve existing stripe customer to charge him again in the future?

I used stripe paymentIntent to create and charge customers, and then used webhooks to activate a membership on my website staging server ... everything worked perfectly, I received events that the payment intent is succeeded and the payment method is attached to a customer, but I don't know how to retrieve the customer to charge him next month automatically from the saved card. This is the paymentIntent where the user pays for the first time and the card gets charged and attached.

public function checkitout (Request $request, $subscription_id)
    {
        \Stripe\Stripe::setApiKey('sk_test_51HcC9a-XXXXXX');
        header('Content-Type: application/json');

        try {
            $subscription = Subscription::findByUid($subscription_id);
            // retrieve JSON from POST body
            $json_str = file_get_contents('php://input');
            $json_obj = json_decode($json_str);
            $customer = \Stripe\Customer::create();
            $paymentIntent = \Stripe\PaymentIntent::create([
                'amount' => $subscription->plan->stripePrice(),
                'currency' => 'usd',
                'customer' => $customer->id,
                'setup_future_usage' => 'off_session',
                'description' => "$subscription_id",
            ]);

            $output = [
                'clientSecret' => $paymentIntent->client_secret,
            ];

            echo json_encode($output);
        } catch (Error $e) {
            http_response_code(500);
            echo json_encode(['error' => $e->getMessage()]);
        }
    }

can someone please give me some information on how to do it? Thank you



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3bT3AYI
via IFTTT

Aucun commentaire:

Enregistrer un commentaire