paypal payment execute error

plmvijay
New Community Member

am using the following code in node js 

 

 

paypal.configure({
 
 'mode': 'live', //sandbox or live
 
 'client_id' : '***************************', 
 'client_secret' : '***********************'
 
});

var app.locals.baseurl="www.test.com";


// paypal payment configuration.
var payment = {
"intent": "sale",
"payer": {
"payment_method": "paypal"
},
"redirect_urls": {
"return_url": app.locals.baseurl+"/success"+"?vaultid="+Vault.id,
"cancel_url": app.locals.baseurl+"/cancel"
},

"transactions": [{
"item_list": {
"items": [
{
"name": req.body.vaultname,
"price":"1",
"currency": "GBP",
"quantity": 1
}
]
},
"amount": {
"total":"1",
"currency": "GBP"
},
"description": req.body.vaultname
}]
};

paypal.payment.create(payment, function (error, payment) {
if (error) {
res.redirect('/');
} else {
if(payment.payer.payment_method === 'paypal') {
req.paymentId = payment.id;
var redirectUrl;
console.log('paypal method');
console.log(payment);
for(var i=0; i < payment.links.length; i++) {
var link = payment.links[i];
if (link.method === 'REDIRECT') {
redirectUrl = link.href;
}
}
res.redirect(redirectUrl);
}
}
});

var execute_payment_json = {
"payer_id": req.query.PayerID,
"transactions": [{
"amount": {
"currency": "GBP",
"total": "1"
} 
}]
};

paypal.payment.execute(paymentId, execute_payment_json, function(error, payment){
if(error){
console.log(error);
} else {
console.log('success'); 
}
});



i get the following response from paypal while execute:

{ Error: Response Status : 400
at IncomingMessage.<anonymous> (/var/www/vhosts/Ideasvault.co.uk/httpdocs/ideasvault/node_modules/paypal-rest-sdk/lib/client.js:136:23)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:188:7)
at endReadableNT (_stream_readable.js:975:12)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickCallback (internal/process/next_tick.js:104:9)
response:
{ name: 'INSTRUMENT_DECLINED',
details: [],
message: 'The instrument presented was either declined by the processor or bank, or it can\'t be used for this payment.',
information_link: 'https://developer.paypal.com/docs/api/payments/#errors',
debug_id: '10f3006ada279',
httpStatusCode: 400 },
httpStatusCode: 400 }



anyone please tell me where i made mistake

 

Login to Me Too
0 REPLIES 0

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.