#jahanzaib
1 messages · Page 1 of 1 (latest)
Hi, what issue do you have?
hello in my ios app i am using apple pay. from ios app i am getting token from stripe
let chargeTransaction = async data => {
try {
let charge = await stripe.paymentIntents.create({
amount: parseInt(data.amount * 100),
currency: data.currency,
customer: data.transferFromAccount,
payment_method: data.id,
off_session: true,
confirm: true,
capture_method: 'automatic'
});
return charge;
} catch (err) {
console.log('-----errrrrr', err);
return null;
}
};
this is m,y function in backedn to create payment intent
but here i require payment method id
when i pass the token i received from ios app in payment_method parameter...its giving me error
is there any way i can get the payment method id from the ios app instead of token
or do i have to change the above funtion in accordance to token implementation
Does the token looks like tok_xxxx?
yes
On backend, can you try to create a PaymentMethod by passing that token to this parameter? https://stripe.com/docs/api/payment_methods/create#create_payment_method-card
You can alternatively provide a Stripe token (e.g., for Apple Pay, Amex Express Checkout, or legacy Checkout) into the card hash with format card: {token: "tok_visa"}
Then you can convert that Token to a Payment Method object with id = pm_xxx, which you can use in Creating PaymentIntent
const paymentMethod = await stripe.paymentMethods.create({
type: 'card',
card: {
token: 'from apple pay'
},
});
like this /
isnt there any way i can get the payment method id from ios apple pay ?
because above is the general function i am using for other stripe payments
The could be. depends on the integration in iOS
let chargeTransaction = async data => {
try {
let charge = await stripe.paymentIntents.create({
amount: parseInt(data.amount * 100),
currency: data.currency,
customer: data.transferFromAccout,
off_session: true,
confirm: true,
capture_method: 'automatic',
card: {
token: 'from apple pay'
}
});
return charge;
} catch (err) {
console.log('-----errrrrr', err);
return null;
}
};
so i updated the above function is this fine ?
No, you should create the PaymentMethod, separately, by calling the Create PaymentMethod API, passing in the token
Then you use the PaymentMethod Id (pm_xxx) inside your stripe.paymentIntents.create function
in the line payment_method: data.id, you previously had
ok let me try