#rupinder_api

1 messages ¡ Page 1 of 1 (latest)

midnight frostBOT
#

👋 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.

vale valve
#

Hi, let me help you with this.

knotty sphinx
#

done the same but not saving

vale valve
#

What do you mean by "not saving" exactly?

knotty sphinx
vale valve
#

Could you please share the PaymentIntent ID where the PaymentMethod was saved pi_xxx?

#

Or the Customer ID

knotty sphinx
#

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 : ''
]
]
]);

vale valve
knotty sphinx
#

req_9cgFlePUvb3PmJ

vale valve
knotty sphinx
#

I was using but still it is not working

vale valve
#

This is the reason the PaymentMethod can't be reused.

knotty sphinx
#

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 : ''
]
]
]);

vale valve
#

The options must be the same.

midnight frostBOT
knotty sphinx
#

where to add it in script?

vale valve
#

Could you please share the code where you initialize the Payment Element?

knotty sphinx
#

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

tawny mulch
#

And are you seeing the same error ?

#

If so can you share the new requestId ?

knotty sphinx
#

no error but card is not saving under payment methods

tawny mulch
#

Can you share an example of a succesfull PaymentIntent Id ?

#

and the test payment method you are using

knotty sphinx
#

yes

#

card: 6011 1111 1111 1117

#

it worked

#

pi_3RGcxKBVwduRnhGV1F4RYkSX

tawny mulch
#

Glad to hear that you managed to solve it then!