#rupinder_api
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/1364149755546173501
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
Hi, let me help you with this.
Here's the guide: https://docs.stripe.com/payments/save-during-payment
done the same but not saving
What do you mean by "not saving" exactly?
here
Could you please share the PaymentIntent ID where the PaymentMethod was saved pi_xxx?
Or the Customer ID
it is giving error
This PaymentMethod was previously used without being attached to a Customer or was detached from a Customer, and may not be used again.
this is the code:
$checkout_session = $stripe->paymentIntents->create([
'amount' => round($grand_total * 100),
'currency' => $currency->code,
'customer' => $customer->id,
'metadata' => [
'country' => $system_region->code,
],
'payment_method_options' => [
'card' => [
'request_three_d_secure' => 'automatic',
],
],
'automatic_payment_methods' => [
'enabled' => true,
],
'shipping' => [
'name' => $user->name . ' ' . $user->last_name,
'address' => [
'line1' => $address->address,
'city' => $address->city_id,
'postal_code' => $address->postal_code,
'country' => $system_region->code,
'state' => isset($address->state_id) ? $address->state_id : ''
]
]
]);
Where do you see the error exactly?
Could you please share the Request ID req_xxx? https://support.stripe.com/questions/finding-the-id-for-an-api-request
req_9cgFlePUvb3PmJ
I don't see that you're providing setup_future_usage=off_session like in the guide:
https://docs.stripe.com/payments/save-during-payment#create-the-paymentintent
I was using but still it is not working
I don't see it in this code snippet.
Or in this request: https://dashboard.stripe.com/test/logs/req_T5ab9nQ7jK2JjJ
This is the reason the PaymentMethod can't be reused.
The provided setup_future_usage (off_session) does not match the expected setup_future_usage (null). Try confirming with a Payment Intent that is configured to use the same parameters as Stripe Elements.", param: "setup_future_usage"
$checkout_session = $stripe->paymentIntents->create([
'amount' => round($grand_total * 100),
'currency' => $currency->code,
'customer' => $customer->id,
'setup_future_usage'=> 'off_session',
'metadata' => [
'country' => $system_region->code,
],
'payment_method_options' => [
'card' => [
'request_three_d_secure' => 'automatic',
],
],
'automatic_payment_methods' => [
'enabled' => true,
],
'shipping' => [
'name' => $user->name . ' ' . $user->last_name,
'address' => [
'line1' => $address->address,
'city' => $address->city_id,
'postal_code' => $address->postal_code,
'country' => $system_region->code,
'state' => isset($address->state_id) ? $address->state_id : ''
]
]
]);
The error message means that you forgot to add setupFutureUsage=off_session when initializing Elements: https://docs.stripe.com/js/elements_object/create_without_intent#stripe_elements_no_intent-options-setupFutureUsage
The options must be the same.
where to add it in script?
Could you please share the code where you initialize the Payment Element?
const stripe = Stripe($('#stripe_secret_key').val());
const options = {
mode: 'payment',
amount: {{ intval($sum_total * 100) }},
setupFutureUsage: 'off_session',
currency: '{{ strtolower($currency->code) }}',
appearance : {
theme: 'stripe',
variables: {
colorPrimary: '#0570de',
colorBackground: '#F0F0F0',
colorText: '#30313d',
colorDanger: '#df1b41',
spacingUnit: '5px',
fontWeightNormal: '500',
border: 'none',
accessibleColorOnColorPrimary: '#1A1B25',
logoColor: 'dark'
},
rules: {
'.Input': {
backgroundColor: '#ffffff',
border: '2px solid #4FAD54 '
}
}
}
};
// Set up Stripe.js and Elements to use in checkout form
const elements = stripe.elements(options);
// Create and mount the Payment Element
const paymentElementOptions = {
layout: {
type: 'tabs',
defaultCollapsed: false,
},
defaultValues: {
billingDetails: {
address: {
country: '{{get_system_region()->code}}'
}
}
},
fields: {
billingDetails: {
address: {
country: 'never' // Hides country field
}
}
}
};
const paymentElement = elements.create('payment', paymentElementOptions);
paymentElement.mount('#stripe-checkout-form');
I added it here
Hey! Taking over for my colleague.
And are you seeing the same error ?
If so can you share the new requestId ?
no error but card is not saving under payment methods
Can you share an example of a succesfull PaymentIntent Id ?
and the test payment method you are using
Glad to hear that you managed to solve it then!