#sovie7ic
1 messages ยท Page 1 of 1 (latest)
Here's the guide to save the payment on Payment Elements for future usage: https://stripe.com/docs/payments/save-and-reuse
Hi river, super sorry
let elements = this.cc.current.props.elements
const {error: submitError} = await elements.submit();
if (submitError) {
// Show error to your customer
this.setState({
error: submitError.message,
loading: false,
});
if (this.props.hasStripeErrors) {
this.props.hasStripeErrors();
}
return;
}
const res = await axios.post(`/${this.props.org.url}/transaction/create_intent`, {
contact_id: contact.id,
client_id: contact.client_id,
anonymous: formValues.anonymous,
msg: formValues.msg,
cur: this.state.cur,
cmp_id: this.props.cmp.id,
amount: this.state.amount,
perk_id: this.state.perk.id,
}).catch((error) => {
notification.error({
message: 'Error',
description: 'Something went wrong. Please try again later.',
});
if (this.props.hasStripeErrors) {
this.props.hasStripeErrors();
}
});
// Use the clientSecret and Elements instance to confirm the setup
const {error} = await this.cc.current.props.stripe.confirmPayment({
elements,
confirmParams: {
return_url: `${window.location.origin}/${this.props.org.url}/thanks`,
shipping: {
name: contact.name,
address: {
line1: contact.address,
city: contact.city,
postal_code: contact.postal,
state: contact.short_state,
country: contact.short_country,
},
},
},
});
Thanks the react web code
Thats*
Can you elaborate the issue you're facing?
I think im creating 2 payment intents
One on the front end
And one on the backend
But there should be only one
Is there a way of getting the PI on the front end?
Frontend doesn't create payment intent unless your frontend make a request to your server to create another payment intent
const options = {
mode: 'payment',
amount: this.state.amount ? this.state.amount * 100 : 500,
currency: this.state.cur,
};
Which guide are you following for your Payment Element integration?
Some elements from there
Can you follow the guide here for Payment Element integration? https://stripe.com/docs/payments/accept-a-payment?platform=web&ui=elements
Some from here
I'd recommend following the guide above as your code is a mix and match of different payment integrations
The above doc should guide you the proper way to integrate Payment Element
Ok, I think I found the issue
When there is an error with stripe.confirmPayment
I re-run the function
So it reacrate a PI
Is it an OK behaviour
Or I should avoid doing this?
And how should I manage the future use of the credit card in this case?
No, you shouldn't recreate a payment intent when there's an error of stripe.confirmPayment(). If the error is due to declines, then same payment intent should be re-used
Payment intent can always be re-used as long as it's not completed or canceled
You should save the PI associated to the your internal order number. If the order has payment fails and requires a payment again, then your frontend will retrieve its associated payment intent to retry it again
So lets say I receive this error
On the confirm payment side, and I change few info... I should simply reuse the created PI correct?
Yes, as long as the amount is the same. If the amount is updated, the Payment Intent should be updated to the new amount
$stripe = new \Stripe\StripeClient($org->getStripeSecretAttribute());
$amount = $request->input('amount') ?? 5;
$data = [
'metadata' => [
'org_id' => $org->id,
],
'automatic_payment_methods' => [
'enabled' => true,
],
'amount' => $amount * 100,
'currency' => $org->cur
];
if (empty($org->cc_desc)) {
$data['statement_descriptor_suffix'] = $org->cc_desc;
}
if (!empty($request->input('pi'))) {
$paymentIntent = $stripe->paymentIntents->retrieve(
$request->input('pi'),
);
$paymentIntent->update($data);
} else {
$pi = $stripe->paymentIntents->create(
$data,
);
}
Only element that can be updated is the Amount?
And also, how can I make sure I can reuse the credit card on file? To create a subscription etc?
Thanks for your help and sorry for the 109 questions ๐
How can I re-use a credit card in the future while creating a payment item with the automatic payment methods?
Only element that can be updated is the Amount?
If the amount of an order is updated, you should update both payment intent at server and elements at client
I'm doing this:
$pi = $stripe->paymentIntents->retrieve(
$request->input('pi'),
);
$stripe->paymentIntents->update($request->input('pi'), [
'amount' => $amount * 100,
'currency' => $request->input('cur') ?? $org->cur,
]);
Just updaing the amount / currency on the PI
And also, how can I make sure I can reuse the credit card on file? To create a subscription etc?
If the payment method has been saved with Stripe, the payment method (pm_xxx) can be set todefault_payment_method: https://stripe.com/docs/api/subscriptions/create#create_subscription-default_payment_method
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
You can follow the guide here on how to use saved payment method on a payment intent: https://stripe.com/docs/payments/save-during-payment?platform=web#charge-saved-payment-method
Getting this
You cannot confirm this PaymentIntent because it's missing a payment method. You can either update the PaymentIntent with a payment method and then confirm it again, or confirm it again directly with a payment method.
Its because of this: automatic_payment_methods - correct?
I want to simply be able to manually add a subscription in the future for a PI
From the dashbaord...
Its because of this: automatic_payment_methods - correct?
No. A payment method should be collected whenconfirmPayment()is called, i.e. the elements should have payment method collected before making a confirm request
So in my case, I will need an extra call?
As I have
confirmParams: {
return_url: ${window.location.origin}/${this.props.org.url}/thanks,
shipping: {
name: contact.name,
address: {
line1: contact.address,
city: contact.city,
postal_code: contact.postal,
state: contact.short_state,
country: contact.short_country,
},
},
},
It goes to a thank you page
The update should be before any gesture event listener, not right before confirm request. The amount should be updated as soon as the order number is changed
Ok but how can I save the payment method for later use?
Have you checked the guide? https://stripe.com/docs/payments/save-during-payment
So just by putting setup_future_usage: 'off_session' it solve the issue?