#Felix Cao
1 messages · Page 1 of 1 (latest)
Thanks from your help
would you mind elaborating your use-case
what are you trying to achieve and if you can share your code, that would be great
- our platform is
Xoda Xodahas lots of merchant, we named gym- gym has lots of member
- member buy the gym's service
I reference the doc: https://stripe.com/docs/payments/save-and-reuse?platform=web&ui=elements
From Set up future payments
Step1. Our server side return client_secret by api
const stripe = require('stripe')('sk_test_26PHem9AhJZvU623DfE1x4sd');
const customer = await stripe.customers.create();
const intent = stripe.setupIntents.create({
customer: customer.id,
automatic_payment_methods: {enabled: true},
});
return res.status(200).json({ client_secret: intent.client_secret });
Step2. Our Front end will use the client_secret to render the payment method page with Stripe Elements
and confirmSetup
and submit the payment method to strip
then get the payment_method_id
then submit the payment_method_id to our server side
Through step1 and step2, will collect the payment method for customer
Is it right ?
Then
Step3, transaction:
const stripe = stripeWithSK(member.gym.stripe_secret_key);
try {
let paymentIntent = await stripe.paymentIntents.create(
{
amount,
currency: member.gym.currency_code,
automatic_payment_methods: { enabled: true },
customer: member.stripe_customer_id,
payment_method: member.stripe_payment_method_id,
confirm: false,
metadata: {
reference_number
}
}
);
paymentIntent = await confirm(paymentIntent.id, member.stripe_payment_method_id, stripe);
console.log('paymentIntent----', paymentIntent) // todo, will del
return paymentIntent;
} catch (err) {
console.log('Stripe Error code is: ', err.code);
const paymentIntentRetrieved = await stripe.paymentIntents.retrieve(err.raw.payment_intent.id);
console.log('PI retrieved: ', paymentIntentRetrieved.id);
}
I get the error here
All the code :
/**
*
* @param {object} member - a member info related gym info
* @param {number} amount - will pay the amount
* @param {string} reference_number
* @returns {Promise<object>}
*/
async function createCharge(member, amount, reference_number) {
const stripe = stripeWithSK(member.gym.stripe_secret_key);
try {
let paymentIntent = await stripe.paymentIntents.create(
{
amount,
currency: member.gym.currency_code,
automatic_payment_methods: { enabled: true },
customer: member.stripe_customer_id,
payment_method: member.stripe_payment_method_id,
confirm: false,
metadata: {
reference_number
}
}
);
paymentIntent = await confirm(paymentIntent.id, member.stripe_payment_method_id, stripe);
console.log('paymentIntent----', paymentIntent) // todo, will del
return paymentIntent;
} catch (err) {
console.log('Stripe Error code is: ', err.code);
const paymentIntentRetrieved = await stripe.paymentIntents.retrieve(err.raw.payment_intent.id);
console.log('PI retrieved: ', paymentIntentRetrieved.id);
}
}
ok just let me stop you for a second
before we go into more details
we strongly recommend against taking the secret keys of your Connected Accounts
instead you should use either Direct or Destination Charges
Let me understand and digest it