#vell2x_code

1 messages · Page 1 of 1 (latest)

west swiftBOT
#

👋 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/1293015123891589245

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

strange wolf
#

Yes! To create ephemeral key, the customer ID (cus_xxx) should be set

#

When you attempt to log the customer ID in console.log("Customer ID: " + customerId);, is it in cus_xxx?

plush gorge
#

yes I see the customer but not the amount

#

ephemeralKey is being flagged as an error though

strange wolf
#

For stripe.ephemeralKeys.create() function, amount is not required

#

Which line is throwing error exactly?

#

I don't see any catch block in your code

plush gorge
#

app.post('/payment-sheet', async (req, res) => {
try {
const customerId = req.body.id; // Extract customer ID
const amount = req.body.amount; // Extract amount

console.log("Customer ID: " + customerId);
console.log("Amount: " + amount);

const ephemeralKey = await stripe.ephemeralKeys.create(
  { customer: customerId },
  { apiVersion: '2022-11-15' }
);

const paymentIntent = await stripe.paymentIntents.create({
  amount: amount,
  currency: 'usd',
  customer: customerId,
  automatic_payment_methods: { enabled: true },
});

res.json({
  paymentIntent: paymentIntent.client_secret,
  ephemeralKey: ephemeralKey.secret,
  customer: customerId,
  publishableKey: process.env.STRIPE_PUBLIC
});

} catch (error) {
res.status(500).json({ error: error.message });
}
});

strange wolf
#

Was the error thrown at stripe.ephemeralKeys.create() or stripe.paymentIntents.create()?

#

If the amount is undefined, stripe.paymentIntents.create() is expected to throw error

plush gorge
#

UnhandledPromiseRejectionWarning: ReferenceError: customer is not defined
at /opt/render/project/src/server.js:896:15

strange wolf
#

Which line of your code threw this error?

#

stripe.ephemeralKeys.create() or stripe.paymentIntents.create()?

plush gorge
#

ephemeralKey last line throws the error

#

ephemeralKey

strange wolf
#

I tested this code myself and it works for me if I set customer with cus_xxx

#

Which version of stripe-node are you using?

plush gorge
#

const stripe = require('stripe')(process.env.STRIPE_SECRET, {
apiVersion: '2020-08-27',
appInfo: { // For sample support and debugging, not required for production:
name: "stripe-samples/accept-a-payment/prebuilt-checkout-page",
version: "0.0.1",
url: "https://github.com/stripe-samples"
}
});

strange wolf
#

I'm referring to the stripe version in package.json

plush gorge
#

12.3.0

strange wolf
#

When you print customer ID, what is the value?

plush gorge
#

cus_QmLxir1fY5wfTT

strange wolf
#

As per checking, customer is supported in stripe-node v12.3.0: https://github.com/stripe/stripe-node/blob/v12.3.0/types/EphemeralKeysResource.d.ts#L9

With reference to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Not_defined, " ReferenceError: customer is not defined" means the value of customer is not defined

I'm also unable to reproduce the issue with the exact same code

GitHub

Node.js library for the Stripe API. . Contribute to stripe/stripe-node development by creating an account on GitHub.

plush gorge
#

What version of stripe are you using?

#

ok I will try hard coding it

strange wolf
#

I tried v14.19.1 and the latest v17.1.0. Both work fine

#

Yup! Can you try hard coding and check if it works?

plush gorge
#

Hard code works but my payment sheet didnt appear

strange wolf
#

Did you present the payment sheet after returning these values?

plush gorge
#

I have a function for it but didnt call it

#

can you check to see if i am on the right track

strange wolf
#

You should call present payment sheet function after returning these values

plush gorge
#

actually this should display it correct?

#

// Setup customer configuration
configuration = PaymentSheet.CustomerConfiguration(
id = jsonObject.getString("customerId"),
ephemeralKeySecret = jsonObject.getString("ephemeralKeySecret")
)
//paymentIntentClientSecret = jsonObject.getString("paymentIntent")
PaymentConfiguration.init(applicationContext, jsonObject.getString("publishableKey"))

                            if(paymentIntentClientSecret.isNotEmpty())
                            {
                                Log.d("NewJob", "Payment Sheet not empty")
                                paymentSheet.presentWithPaymentIntent(
                                    paymentIntentClientSecret,
                                    PaymentSheet.Configuration("Mowie INC.", configuration)
                                )
                            }
strange wolf
#

This is just the partial code. Where did you invoke this present payment sheet code?

plush gorge
#

looks like i didnt

#

private fun presentPaymentSheet(
paymentSheet: PaymentSheet,
customerConfig: PaymentSheet.CustomerConfiguration,
paymentIntentClientSecret: String
) {
paymentSheet.presentWithPaymentIntent(
paymentIntentClientSecret,
PaymentSheet.Configuration(
merchantDisplayName = "My merchant name",
customer = customerConfig,
// Set allowsDelayedPaymentMethods to true if your business handles
// delayed notification payment methods like US bank accounts.
allowsDelayedPaymentMethods = true
)
)
}

#

do i call this or do i invoke it another way?