I am trying to refund a payment made by card using Paypal but I have an error 500 on refund
{ name: 'INTERNAL_SERVICE_ERROR',
message: 'An internal service error occurred.',
information_link: 'https://developer.paypal.com/webapps/developer/docs/api/#INTERNAL_SERVICE_ERROR',
debug_id: '4791f4fde5314',
httpStatusCode: 500
},
My code is
const paypal = require('paypal-rest-sdk');
const creditCardType = require('credit-card-type');
const util = require('util')
const card = creditCardType('4111111111111111');
paypal.configure({
'mode': 'sandbox', //sandbox or live
'client_id': 'id',
'client_secret': 'secret'
});
const paymentObj = {
intent: 'sale',
payer: {
payment_method: 'credit_card',
funding_instruments: [{
'credit_card': {
number: '4111111111111111',
type: card[0].type,
'expire_month': 11,
'expire_year': 2019,
cvv2: 123,
'first_name': 'Jon Doe'
}
}]
},
transactions: [{
amount: {
total: '12.12',
currency: 'EUR'
}
}]
};
console.log(util.inspect(paymentObj, false, null));
paypal.payment.create(paymentObj, (error, payment) => {
if(error) console.log(util.inspect(error, false, null));
console.log(util.inspect(payment, false, null));
paypal.sale.refund(payment.id, {
amount: {
total: '1.99',
currency: 'EUR'
}
}, (error, response) => {
if(error) console.log(util.inspect(error, false, null));
console.log(util.inspect(response, false, null));
})
})
I don't understand, I am not sure I have to capture the payment if this is a card payment, following the doc I shouldn't I tried paypal.sale.refund
, I don't know fi there is an other way.
via ant
No comments:
Post a Comment