#jahanzaib

1 messages · Page 1 of 1 (latest)

eager groveBOT
jovial timber
#

Hi, what issue do you have?

fringe sonnet
#

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

jovial timber
#

Does the token looks like tok_xxxx?

fringe sonnet
#

yes

jovial timber
#

Then you can convert that Token to a Payment Method object with id = pm_xxx, which you can use in Creating PaymentIntent

fringe sonnet
#

const paymentMethod = await stripe.paymentMethods.create({
type: 'card',
card: {
token: 'from apple pay'
},
});

#

like this /

jovial timber
#

Yep

#

Let's try it

fringe sonnet
#

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

jovial timber
#

The could be. depends on the integration in iOS

fringe sonnet
#

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 ?

eager groveBOT
jovial timber
#

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

fringe sonnet
#

ok let me try