#aruljothi-apple-sub

1 messages · Page 1 of 1 (latest)

orchid jewel
#

hello @idle shore! how can we help?

idle shore
#

hello alex

#

i need applepay subscrption

#

paymentRequest.canMakePayment().then(function(result) {
if (result) {
prButton.mount('#payment-request-button');
} else {
document.getElementById('payment-request-button').style.display = 'block';
}
});
paymentRequest.on('paymentmethod', function(ev) {}

#

first created button using stipe element

#

Next created the payment intent

#

After payemnt intent creation called this

#

stripe.confirmCardPayment(clientSecret,{payment_method: ev.paymentMethod.id},{handleActions: false})
.then(function(confirmResult) {

idle shore
#

hi

orchid jewel
#

hello, could you share what is the issue you're facing?

idle shore
#

i need applepay subscrption

#

if i pass customer with payment method attached

#

then i will create subscription means following error displyed- "The customer does not have a payment method with the ID pm_1JjhsJIX5abeNCfAdGn89ylv. The payment method must be attached to the customer."

orchid jewel
#

@idle shore as the error message mentioned : for a subscription payment, the payment method must be attached to the customer. So you should

  1. attach the created PaymentMethod to the customer
  2. create the PaymentIntent
  3. stripe.confirmCardPayment (clientSecret).then...
idle shore
#

if i attach payment method -This PaymentMethod was previously used without being attached to a Customer or was detached from a Customer, and may not be used again.

#

this error displayed

orchid jewel
#

@idle shore have you tried making a call to your server to attach the card to the customer first? like the below

paymentRequest.on('paymentmethod', function(ev) {
// make a call to your server to attach the card to the customer first
}
idle shore
#

okay

#

i am created customer in this function paymentRequest.on('paymentmethod', function(ev) {

#

}

orchid jewel
#

@idle shore alright, so are you having any other problems / errors?

idle shore
#

paymentRequest.on('paymentmethod', function(ev) {

fetch('https://dhyanfoundation.org.uk/ajax_function.php', {
method: "POST",
headers: {'Content-Type': 'application/json',},
body: JSON.stringify({'customer_name':customer_name,'customer_email':emailaddress,'ajax_call':'create_customer'}),
})
.then(function(customer_result) {
return customer_result.json();
})
.then(function( customer_data ) {
added aattchedment customer in this palce

#

but this gives the above errors

orchid jewel
#

what error are you receiving now?

idle shore
#

This PaymentMethod was previously used without being attached to a Customer or was detached from a Customer, and may not be used again.

orchid jewel
#

can you share the payment method id? it'd look like pm_123

idle shore
#

one moment

#

pm_1JjhsJIX5abeNCfAdGn89ylv

orchid jewel
#

@idle shore this is a live payment method, are you testing in live mode?

#

it's been used for a charge (and was not previously attached to a customer) before, which is why that particular payment method cannot be reused.

#

can you test in test mode, and create a new payment method to be attached to a customer

idle shore
#

live mode - payment method pm_1JmCVRIX5abeNCfA9L3TJGlI

#

{
"customer": "cus_KR4eGGBLyVeIat",
"default_payment_method": "pm_1JmCVRIX5abeNCfA9L3TJGlI",
"items": {
"0": {
"price": "price_1JmCVSIX5abeNCfAFXIZCLwo"
}
}
}
Response body
{
"error": {
"message": "The customer does not have a payment method with the ID pm_1JmCVRIX5abeNCfA9L3TJGlI. The payment method must be attached to the customer.",
"param": "payment_method",
"type": "invalid_request_error"
}
}

orchid jewel
#

my question here is, are you intentionally doing this in live mode?

#

most people would prefer to do this in test mode, to avoid charging their credit card

idle shore
#

we are using in live mode

#

in applepay wallet not passible to do in test

orchid jewel
#

you can test applepay in test mode

#

you should use your test API keys, Stripe will recognize that you are in test mode and will return a successful test card token for you to use.

idle shore
#

okay we will check

orchid jewel
#

i'd suggest shifting to using test mode first before you continue

idle shore
#

okay sure we will alter first