#vell2x_code
1 messages · Page 1 of 1 (latest)
👋 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.
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?
yes I see the customer but not the amount
ephemeralKey is being flagged as an error though
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
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 });
}
});
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
UnhandledPromiseRejectionWarning: ReferenceError: customer is not defined
at /opt/render/project/src/server.js:896:15
Which line of your code threw this error?
stripe.ephemeralKeys.create() or stripe.paymentIntents.create()?
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?
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"
}
});
I'm referring to the stripe version in package.json
12.3.0
When you print customer ID, what is the value?
cus_QmLxir1fY5wfTT
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
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?
Hard code works but my payment sheet didnt appear
Did you present the payment sheet after returning these values?
I have a function for it but didnt call it
can you check to see if i am on the right track
You should call present payment sheet function after returning these values
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)
)
}
This is just the partial code. Where did you invoke this present payment sheet code?
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?