1
votes

No problems when I create an on-session payment, can't make a second charge when authentication required, don't understand an approach when Stripe must send a letter to the customer with a confirm link, the link lead to the Stripe hosted page like in Docs

The request with SCA required card I got a card error (authorization_required).

        $intent = PaymentIntent::create([
            'amount'               => 1100,
            'currency'             => 'usd',
            'payment_method_types' => ['card'],
            'customer'             => $customerId,
            'payment_method'       => $paymentMethodId,
            'off_session'          => true,
            'confirm'              => true,
        ]);

I found this approach here. Set settings in the Stripe dashboard for email. Maybe must be a relation with invoice API, but I don't see a flow in docs.

Expected a success paymentIndent creation with requires_confirmation status. Email sent to the customer with a confirmation button.

1
Those settings only apply if you're using Stripe's Billing product(Subscriptions/Invoices, so this flow : stripe.com/docs/billing/subscriptions/payment). If you use that you don't create PaymentIntents yourself. If you're making off session payments manually yourself like in the second link you shared, you need to build something to email the customer and bring them back on session.karllekko

1 Answers

1
votes

As per new regulations of 3D secure, Need additional payment confirmation. You can achieve that using following code.

Pass intent to this Function (Server code)

    const generate_payment_response = (intent) => {
    if (
      intent.status === 'requires_action' &&
      intent.next_action.type === 'use_stripe_sdk'
    ) {
      // Tell the client to handle the action
      return {
        requires_action: true,
        payment_intent_client_secret: intent.client_secret
      };
    } else if (intent.status === 'succeeded') {
      // The payment didn’t need any additional actions and completed!
      // Handle post-payment fulfillment
      return {
        success: true
      };
    } else {
      // Invalid status
      return {
        error: 'Invalid PaymentIntent status'
      }
    }
  };

Prompt aditional 3D secure popup (Front-End Code)

function handleServerResponse(response) {
    console.log(response, "handling response");

    if (response.data.success) {
      // Show error from server on payment form
      alert("Paymemt successful");

    } else if (response.data.requires_action) {
        alert("require additional action");
        // Use Stripe.js to handle required card action
        stripe.handleCardAction(
            response.data.payment_intent_client_secret
            ).then(function(result) {
                if (result.error) {
                    // Show error in payment form
                } else {
                    // The card action has been handled
                    // The PaymentIntent can be confirmed again on the server
                    let data = {
                        payment_intent_id: result.paymentIntent.id 

                    }
                    axios.post(`${baseUrl}/confirmPayment`, data).then(response => {
                        handleServerResponse(response);
                    });
                }
            }).catch(error => {
                console.log(error, "error");

                alert("rejected payment");
            })
        } else {
            // Show failed
            alert("Failed transaction");
            alert(response.data.message);
            console.log(response.data, "error during payment confirmation");
    }
  }