question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Doc Improvement for Create Intent And Capture later

See original GitHub issue

Describe the bug When I read the doc everywhere here, expo, stripe.dev (front/api) and other platforms, I can’t find anything that make a pre payment that’s not billed directly and we are able to capture payment later even will strongest 3D secure (2 authenticate at every step).

To Reproduce Steps to reproduce the behavior:

  1. Go to doc, sample or readme
  2. Take a example and copy paste
  3. Test your code
  4. Add payment type error, need authenticate error…

Expected behavior We should have a clear working example with last versions and react-native.

Screenshots Setup intent option capture or charge will not work with strong cards Screenshot 2022-06-09 at 08 34 58

Desktop (please complete the following information):

  • OS: OSX
  • Browser Brave

Smartphone (please complete the following information):

  • Device: Emulator
  • OS: Android 12

Here it’s what works Front

/**
   * When we create setup intent (save card and pay later)
   * We need to create separately a payment method and send it to Stripe API for confirm
   * Should be Called at clicking Validate Card button
   */
  const createPaymentMethodForCapture = async (): Promise<unknown> => {
    console.info("[PaymentCard] Init payment method");
    const result = await createPaymentMethod({
      paymentMethodType: "Card",
      card: refCardElement,
      billing_details: {
        name: user?.last_name,
        email: user?.email,
      },
    });

    // Handle payment method error while creation
    if (result.error) {
      console.error("[PaymentCard] Create payment method Error", result.error);
      return null;
    }
    // Handle payment method created success
    console.debug(
      "[PaymentCard] Create payment method: ",
      result.paymentMethod
    );
    //Create intent on serveur
    const intent = await apiCreatePaymentNew(result.paymentMethod?.id);
    if (intent.error) {
      console.info("[BikeSelection] Error creating intent", intent);
      return null;
    }
    console.log("[BikeSelection] Intent created with capture manual:", intent);
    const confirmPaymentIntent = await confirmPayment(intent.client_secret, {
      paymentMethodType: "Card",
      type: "Card",
      card: refCardElement,
    });
    console.log("[BikeSelection] Intent confirmed:", confirmPaymentIntent);
    setPaymentIntentId(confirmPaymentIntent.paymentIntent?.id);
    setPaymentSecret(confirmPaymentIntent.paymentIntent?.clientSecret);
    return intent;
  };

BACK

 # Initiate the payment
  # When a user tries to unlock a vehicle
  # Start/Beginning of the tour
  def create_intent_new
    payment_method_id = params[:payment_method_id]
    Rails.logger.info("[Payment] Create a payment intent for this transaction NEW: #{payment_method_id}")
    # head :unprocessable_entity unless current_user.stripe_customer_id && current_user.default_stripe_payment_source
    begin
      intent = Stripe::PaymentIntent.create({
                                              amount: rental_max_cents,
                                              currency: 'eur',
                                              customer: current_user.stripe_customer_id,
                                              capture_method: 'manual',
                                              payment_method: payment_method_id,
                                              confirm: true
                                            })
    rescue Stripe::CardError => e
      # Error code will be authentication_required if authentication is needed
      Rails.logger.info "[Payment] Error is: #{e.error.code}"
      payment_intent_id = e.error.payment_intent.id
      payment_intent = Stripe::PaymentIntent.retrieve(payment_intent_id)
      intent = payment_intent
      Rails.logger.info "[Payment] Retrieve #{payment_intent.id}"
    end
    Rails.logger.info "[Payment] Intent created #{intent}"
    render status: 200, json: intent
  end

# Capture full amount
  def capture_intent_new
    payment_intent_id = params[:payment_intent_id]
    Rails.logger.info "[Payment] Capture payment #{payment_intent_id}"

    begin
      intent = Stripe::PaymentIntent.capture(
        payment_intent_id, { amount_to_capture: rental_max_cents, }
      )
    rescue => e
      Rails.logger.warn "[Payment] Error while capturing the payment #{e.message}"
    end
    Rails.logger.info "[Payment] Finish to capture payment #{intent}" if intent
    intent
  end
```

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:2
  • Comments:5

github_iconTop GitHub Comments

2reactions
charliecruzan-stripecommented, Jul 11, 2022

Yes, in that case you’ll need to manually bring the customer back on-session for them to complete the SCA flow

1reaction
charliecruzan-stripecommented, Jul 12, 2022

the setup intent will allow the card to be used in off-session transactions, but issuers can still decline those transactions with authentication_required if they choose, so it’s best to implement a process for bringing payments back on-session when required

gonna go ahead and close this since we haven’t heard back from @73k05 on whether or not those docs were what they were looking for, but happy to keep answering questions!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Intents and Intent Filters - Android Developers
An intent filter is an expression in an app's manifest file that specifies the type of intents that the component would like to...
Read more >
Stripe API reference – PaymentIntents – curl
You can reference the PaymentIntent later to see the history of payment ... When using manual capture, a future timestamp after which the...
Read more >
Creating intents - IBM Cloud Docs
If the input is unrelated to any of the intents in your application, you can teach your assistant that by selecting the displayed...
Read more >
Authorize and Capture - PayPal Developer
Before you authorize funds, you must create an order with the intent field set ... After a successful authorization, PayPal recommends that you...
Read more >
Does a Stripe payment intent place a hold before or after ...
The creation, confirmation, and capture of a payment intent are three distinct steps that happen in that order over time. I have read...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found