#Rahim Dobani

1 messages · Page 1 of 1 (latest)

median waveBOT
cinder moat
#

Hi! Let me help you with this.

lethal coral
#

how i get pmID in this api response

#

After this i am calling update customer api

cinder moat
lethal coral
#

updateCustomer: async (req, res) => {
// console.log(req.body)
let token = req.headers['x-access-token'] || req.headers['authorization'];
// Remove Bearer from string
token = token ? token.replace(/^Bearer\s+/, "") : "";
if (token === process.env.BEARER_TOKEN) {
const customerID = req && req.body && req.body.customerID
const pmID = req && req.body && req.body.pmID
try {
const customer = await stripe.customers.update(
customerID,
{
'invoice_settings': {
'default_payment_method': pmID
}
});
// console.log(customer);
res.status(200).send({ customer, success: true });
} catch (err) {
// response.status(400).send(Webhook Error: ${err.message});
// console.log(err);
res.status(500).send({ message: "Please try again", error: err, success: false });
return;
}
}
else {
res.status(200).send({ success: false });
}

},
#

const confirmPayment = await stripe.confirmSetup({
//Elements instance that was used to create the Payment Element
elements,
confirmParams: {
return_url: 'https://www.google.com/',
},
}); another question is what if dont want to pass redirect url in this api?

lethal coral
#

is there any other api to add card to customer? i am using payment element

cinder moat
#

What you need to do, as I mentioned earlier, is to listen to setup_intent.succeeded webhook event, and then you can perform the necessary actions with your new PaymentMethod object.

cinder moat
lethal coral
#

const createCustomer = await axios({
url: "http://localhost:3070/api/createCustomer",
method: 'post',
headers: {
"Content-Type": "application/json",
},
data: {
name,
email,
// priceId
}
})
const customerID = createCustomer && createCustomer.data && createCustomer.data.customer && createCustomer.data.customer.id
// console.log(customerID);
const createSetupIntent = await axios({
url: "http://localhost:3070/api/createSetupIntent",
method: 'post',
headers: {
"Content-Type": "application/json",
},
data: {
customerID,
}
})
setClientSecret(createSetupIntent && createSetupIntent.data && createSetupIntent.data.setupIntent.client_secret)
// console.log(createSetupIntent);
}
// console.log(clientSecret);
const options = {
// passing the SetupIntent's client secret
clientSecret: clientSecret,
// Fully customizable with appearance API.
appearance: {/.../},
};
i am using this api to add customer

#

then passing options to render payment element.

cinder moat
lethal coral
#

do you have any example?

#

i am using nodejs

cinder moat