#kwac.
1 messages · Page 1 of 1 (latest)
Hello! We'll be with you shortly. 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.
- kwac., 2 days ago, 35 messages
- kwac., 2 days ago, 35 messages
- kwac-plugin-error, 3 days ago, 11 messages
- kwac.-account-support, 5 days ago, 4 messages
`
const { setupIntent, error } = await stripe.confirmSetup({
elements,
confirmParams: {
return_url: "https://mywebsite.com/checkout",
},
redirect: 'if_required'
});
if(error){
if (error.type === "card_error" || error.type === "validation_error") {
showMessage(error.message);
} else {
showMessage("An unexpected error occurred.");
}
} else {
let payment_form = document.querySelector("#stripe_form_checkout")
var hiddenInput = document.createElement("input");
hiddenInput.setAttribute('type', 'hidden');
hiddenInput.setAttribute('name', 'paymentMethod');
hiddenInput.setAttribute('value', setupIntent.payment_method);
payment_form.appendChild(hiddenInput);
}
}`
Could you please hare more details about the issue ?
are you seeing any error in the console for example ?
I get no errors in console, but on first submit paymentMethod is not detected but I have declared payment error check and get the message from ** wc_add_notice('Payment method is not set. Please try again.', 'error');** in window. But on second form submit it processes payment fine.
for this part $paymentMethod = $_POST['paymentMethod'];
`
public function process_payment( $order_id ) {
$order = wc_get_order( $order_id );
$paymentMethod = $_POST['paymentMethod'];
try {
if (isset($_POST['paymentMethod'])) {
$paymentMethod = wc_clean($_POST['paymentMethod']);
} else {
wc_add_notice('Payment method is not set. Please try again.', 'error');
return;
}
`
Maybe it's because the way I grab payment method? Maybe I need to do it using ajax call?
Oh wait I just checked logs in stripe and i see error 400 for setupintent (req_EYtGCnGFMrWAy5
)
You may have somthing blocking in your javascript function
ah let me check
The setup intent used is already submited
you need to use a Setupintent with a correct status
what do you mean
In other word you need to use a SetupIntent that wasn't submitted before, a new one.
okay but on first submit setup intent is fine req_G0orYA1oMlqD5d
why does it then processes payment still on second submit?
Ah that's your integration is trying to submit the same SetupIntent twice
you need to debug your integration and make sure that for each SetupIntent you are submitting it only once.
So it's not related with how the payment method is grabbed? I thought it's because in payment process function it's immediately trying to processes payment on form submit even when payment method is not set to hidden field in form, i thought i would need it to wait to be added from javascript side before processing payment on backend
Yes it seems youa re processing the same Setupintent twice
can tarzan come here, he might be more knowledgeable
The request id you've shared is very clear
You cannot update this SetupIntent because it has already succeeded.
so it still can process payment? even on second submit?
What you mean by process payment ?
The Setupintent is for collecting the PaymentMethod
then you can use it for processing a payment
i mean if it's processing same setupintent intent twice (400 error), the funds are still coming in and i can still capture them
Like I said I'm getting error 'Payment method is not set. Please try again on first submit but on second, i get no errors, and payment is processed, so I assumed it's related with how i grab payment method, I thought I need to use ajax call
Okay im sorry what I said here, I did not mean it
No worries! We are all happy to help!
First of all let's make things clear
Setupintent is just for collecting the PaymentMethod, there is no funds captured
In order to capture funds you need to use PaymentIntent
is this part clear ?
In following order I first:
Use setup intent mainly for grabbing client secret and attaching it onto javascript side
`
public function generate_setup_intent() {
if (!$this->client_secret) {
$intent = \Stripe\SetupIntent::create([
'payment_method_types' => ['card'],
]);
$this->client_secret = $intent->client_secret;
}
return $this->client_secret;
}
`
and attach goes here
const options = { currency: 'usd', appearance: {/*...*/}, clientSecret: '<?php echo esc_js($this->client_secret); ?>', };
Then I submit form and in process payment I try to grab payment method
$paymentMethod = $_POST['paymentMethod'];
Then we check if paymentmethod exists if it doesn't , we print this message ( wc_add_notice('Payment method is not set. Please try again.', 'error');) - this message being printed on first submit but on second it doesn't because payment method exists, also after that i create customer and then create payment intent. Is this correct order?
if (isset($_POST['paymentMethod'])) {
$paymentMethod = wc_clean($_POST['paymentMethod']);
} else {
wc_add_notice('Payment method is not set. Please try again.', 'error');
return;
}
$customer = \Stripe\Customer::create([
'name' => $order->get_billing_first_name(),
'email' => $order->get_billing_email(),
'payment_method' => $paymentMethod,
]);
$paymentIntent = \Stripe\PaymentIntent::create([
'payment_method' => $paymentMethod,
'amount' => $order->get_total() * 100,
'currency' => 'usd',
'payment_method_types' => ['card'],
'customer' => $customer->id,
'confirmation_method' => 'automatic',
'confirm' => 'true',
'description' => 'Payment for Order #' . $order_id,
'statement_descriptor' => 'ORDER ' . $order_id,
'capture_method' => 'manual',
'payment_method_options' => [ 'card_present' => ['request_incremental_authorization_support' => true], ],
]);
that doesn't make any sense really, no.
You shouldn't be creating a SetupIntent and then immediately creating a PaymentIntent.
Just create and use the PaymentIntent.
https://stripe.com/docs/payments/save-during-payment
but I first need to grab client secret for js side
the PaymentIntent has a client secret.