#Felix Cao

1 messages · Page 1 of 1 (latest)

true burrowBOT
placid plank
#

👋 happy to help

#

How to get the Authorization detail error here
Thanks

kindred gyro
#

Thanks from your help

placid plank
#

would you mind elaborating your use-case

#

what are you trying to achieve and if you can share your code, that would be great

kindred gyro
#
  1. our platform is Xoda
  2. Xoda has lots of merchant, we named gym
  3. gym has lots of member
  4. member buy the gym's service
#

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 ?

placid plank
#

where did you get the error?

#

you didn't share that code

kindred gyro
#

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);
  }
}
placid plank
#

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

kindred gyro
#

Let me understand and digest it

placid plank
#

yes sure

#

but you're going the wrong route, and I wanted to get you back on track, instead of just fixing a coding error