#Racka

1 messages ยท Page 1 of 1 (latest)

remote valveBOT
green mist
#

Hi! Let me help you with this.

#

Could you please share the code of how you're doing it?

frozen apex
#

And the api call is simply:
exports.userPaymentSheet = functions.https.onCall(async (data, context) => {
// User needs to be signed in.
if (!context.auth) return { status: 'error', code: 401, message: 'User not signed in.' }
const amount = data.amount;
const user = data.user;
const project = data.project;
const customerID = user.paymentCustomerId;
const ephemeralKey = await stripe.ephemeralKeys.create(
{ customer: customerID },
{ apiVersion: apiVersionStripe }
);
const paymentIntent = await stripe.paymentIntents.create({
amount: amount,
currency: 'eur',
automatic_payment_methods: {
enabled: true,
},
customer: customerID,
description: Donation of ${amount / 100} eur \nto organization: ${organizationID}, \nproject: ${project.id}, \ntitled: ${project.title}.,
metadata: {
is_subscription: false,
projectId: project.id,
projectTitle: project.title,
customerID: customerID,
userId: user.id,
organizationId: organizationID,
isAnonymous: false,
}
});
console.log(JSON.stringify(paymentIntent));
return {
paymentIntent: paymentIntent.client_secret,
ephemeralKey: ephemeralKey.secret,
customer: customerID,
publishableKey: pubKey
};
});

#

So as said every time the api is called, the payment method is set to null. But if the user chose some non default payment method we would need it to remain.

#

Did you maybe get a chance to look through it? ๐Ÿ˜Š

green mist
#

Sorry for delay, it's busy today. I'll be right with you!

frozen apex
#

Alright no problem, yea I saw you are bombarded with questions hah ๐Ÿ˜…

green mist
#

So, if I understand correctly, you want to update the PaymentSheet while it is open? Or you want to keep the payment method data between closing and opening the sheet?

frozen apex
#

While it's open yes.

green mist
#

But why would the amount change? The customer can't select any other items because the sheet is open. Or does it come from the backend? What's the use case?

frozen apex
#

Yes so the amount changes as it is also passed to the PaymentPanel. The new amount would come only from the front end.
So if I understand correctly after the sheet is open the amount can't be changed? It has to be created anew and thus we loose the new payment method (if the user choses one of course)?

#

This is basically an application where the user can choose how much they will pay, that is why we get the amount from the front end and not the back end.

green mist
#

Yes, you will need to init the PaymentSheet again.

frozen apex
#

And how can I keep my users selected payment method if I init the PaymentSheet again? ๐Ÿค”

green mist
#

I don't think you can, unfortunately.

frozen apex
#

Aaah, I see...well if that's the case at least it makes sense why it isn't working hah ๐Ÿ˜…
Well thank you so much for your time ๐Ÿ˜Š

#

You have been big help ๐Ÿค—

remote valveBOT
green mist
#

Happy to help. Please, let me know if you have any other questions.