#harshil-ahir_code

1 messages ¡ Page 1 of 1 (latest)

mystic pelicanBOT
#

👋 Welcome to your new thread!

⏲️ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

🔗 This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1266345672932855921

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

cloud narwhalBOT
#

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.

dawn tapir
#

This PaymentIntent could not be captured because it has a status of requires_payment_method. Only a PaymentIntent with one of the following statuses may be captured: requires_capture.; code: payment_intent_unexpected_state; request-id: req_yToCnypRRYdeLM

#

that the error i am getting

short kiln
#

hi! sounds like you didn't actually process the payment fist?

#

you have to confirm the PaymentIntent (collect card details from the user) before you can capture any authorised payment.

dawn tapir
#

i have holded the payment public PaymentIntent createPaymentIntenet(Long finalAmount,String customerId) {
Stripe.apiKey = StripeKey;
PaymentIntentCreateParams.Builder paramsBuilder = PaymentIntentCreateParams.builder()
.setAmount(finalAmount)
.setCurrency("usd")
.setCaptureMethod(PaymentIntentCreateParams.
CaptureMethod.MANUAL)
.addPaymentMethodType("card")
.setCustomer(customerId);

      paramsBuilder.setSetupFutureUsage(PaymentIntentCreateParams.SetupFutureUsage.OFF_SESSION);
      
      PaymentIntentCreateParams params = paramsBuilder.build();

    try {
        PaymentIntent paymentIntent = PaymentIntent.create(params);
        return paymentIntent;
    } catch (StripeException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}

this is the code

dawn tapir
short kiln
#

cool, so where's the frontend code where you collect a payment method and confirm the PaymentIntent, the part that actually proccess a payment?

dawn tapir
#

yeah i am getting the request of this details and in an api i am holding the payment which works but at the time of relising the payment its shown error like above

short kiln
#

I don't understand your words I'm sorry.

mystic pelicanBOT
short kiln
#

nothing in the code or the PaymentIntent ID you shared actually did any "holding the payment", you never collected any card details or charged them

dawn tapir
short kiln
dawn tapir
#

public PaymentIntent createPaymentIntenet(Long finalAmount,String customerId) {
Stripe.apiKey = StripeKey;
PaymentIntentCreateParams.Builder paramsBuilder = PaymentIntentCreateParams.builder()
.setAmount(finalAmount)
.setCurrency("usd")
.setCaptureMethod(PaymentIntentCreateParams.
CaptureMethod.MANUAL)
.addPaymentMethodType("card")
.setCustomer(customerId);

      paramsBuilder.setSetupFutureUsage(PaymentIntentCreateParams.SetupFutureUsage.OFF_SESSION);
      
      PaymentIntentCreateParams params = paramsBuilder.build();

    try {
        PaymentIntent paymentIntent = PaymentIntent.create(params);
        return paymentIntent;
    } catch (StripeException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}

with these method i am holding the payment from card and with the

stark prawn
#

Which card exactly? All you're doing is setting the payment_method_types parameter on the intent which just restricts which types of payment methods can be used to pay

#

As stated, you need to actually confirm/process the intent to place the hold/auth which can then later be captured

stark prawn
dawn tapir
#

after then i am doing that

stark prawn
#

Doing what?

dawn tapir
#

and then i am trying to capture it and getting error

stark prawn
#

We've already explained why: the intent is in a requires_payment_method state

#

Where is your code that collects payment information from the customer and processes it?

stark prawn
#

Yes, exactly

dawn tapir
#

i am not collecting it ,frontend developer is giving me directly the amount and the card info is saved automatically in stripe

stark prawn
#

OK, so if you have saved card information in Stripe then you need to pass that to the intent on creation via the payment_method parameter

#

Right now you're just creating and intent to pay without actually providing a method (card) to pay it. How are we supposed to capture funds?

dawn tapir
#

so you are saying me to use this line in my hold code
.setAutomaticPaymentMethods(
PaymentIntentCreateParams.AutomaticPaymentMethods.builder().setEnabled(true).build()
)

#

because except this everything was present in my hold code

stark prawn
#

No, that's irrelevant. Please read the guide I've linked, specifically step 3 which has the JS code you need to use to collect payment details in a compliant manner

dawn tapir
stark prawn
#

Your front-end code is not working as you expect then. There's no confirmation attempts on that intent

dawn tapir
#

Are you sure thats the front-end error

#

??

stark prawn
dawn tapir
#

can you wait for a min i will share my frontend call with you

#

frontend are also capturing the code

#

cant you get idea of error from error message

stark prawn
#

I've no idea what that means. But we've explained the problem countless times, and the issue is quite self explanatory from the error message

You're trying to capture a payment but it's not in a state that allows capture (requires_capture). This is because you've not actually collected/provided any payment info for the payment and processed the initial authorization which happens before the capture

dawn tapir
stark prawn
#

I've found the ID, pi_3Pgl6mFkorCYEiZC1A6vzKwg. We've been looking at it all along

#

And only confirms what we've explained above