#harshil-ahir_code
1 messages ¡ Page 1 of 1 (latest)
đ 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.
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.
- harshil-ahir_code, 2 days ago, 27 messages
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
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.
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
yeah its done after that at the time of relasing the payment i am getting this error
cool, so where's the frontend code where you collect a payment method and confirm the PaymentIntent, the part that actually proccess a payment?
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
I don't understand your words I'm sorry.
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
I suggest you follow the guide https://docs.stripe.com/payments/accept-a-payment?platform=web&ui=elements and carefully read step 3.
its done automatically i am not storing the card details like this
how is it done automatically exactly?
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
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
Follow this part of the guide
i have done this see this code first please
after then i am doing that
Doing what?
the step you said to hold i have done that
and then i am trying to capture it and getting error
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?
like its card details??
Yes, exactly
i am not collecting it ,frontend developer is giving me directly the amount and the card info is saved automatically in stripe
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
I recommended taking a step back and reading through the guide linked earlier to understand how these APIs work: https://docs.stripe.com/payments/accept-a-payment?platform=web&ui=elements
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?
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
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
yeah thats was done my frontend team but i am getting error in backend not frontend can you please solve that error ,my frontend is working with the code you have given i am a backend developer
Your front-end code is not working as you expect then. There's no confirmation attempts on that intent
Your error is not from the front-end code, no. But you're missing the part in your front-end code to collect and confirm the intent. This part: https://docs.stripe.com/payments/accept-a-payment?platform=web&ui=elements#web-collect-payment-details
You need to do that before you can call the /capture endpoint. That is the root issue here
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
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
in these code from the return statement if i am getting id then can you know that its working or not ,or anything with the help of return statement