I want to make payment from PayPal vaulted credit card to PayPal merchant, I am using nodejs for doing this process and I am using payapl-rest-sdk
npm see below documentation
https://www.npmjs.com/package/paypal-rest-sdk
I stored credit card at vault successfully via using below code:
storeCreditCardVault: function (req, res) {
var paypal = require('paypal-rest-sdk');
uuid = require('node-uuid');
paypal.configure({
'mode': 'sandbox', //sandbox or live
'client_id': 'Aan_H7FviRQOuUALQ3fQhy5HFt_FZN_JLEkVSAHoiLHPSgDMnVqvbfFYLnnQ_Mq6ZiE1S2S-_2skyyag',
'client_secret': 'EDq_8CUG5g7X6TU9DF4PpuZh_ASr5oxTbZ9SUv0Iw5cpTHrjHFU_QzMsDI_1k0B5eL3s43AVxvlNvKP_',
'headers': {
'custom': 'header'
}
});
var card_data = {
"type": "visa",
"number": "4417119669820331",
"expire_month": "11",
"expire_year": "2020",
"cvv2": "123",
"first_name": "Joe",
"last_name": "Shopper",
"external_customer_id": uuid.v4()
};
paypal.creditCard.create(card_data, function(error, credit_card){
if (error) {
console.log(error);
throw error;
} else {
console.log("Create Credit-Card Response");
console.log(credit_card);
console.log(credit_card.id);console.log(credit_card.type);console.log(credit_card.number);
}
});
}
Vault success response is:
Create Credit-Card Response
{ id: 'CARD-4W491882YN380234BLDGDP6Y',
state: 'ok',
external_customer_id: '22896dc3-8b03-4a98-b1b4-0124df78b9cd',
type: 'visa',
number: 'xxxxxxxxxxxx0331',
expire_month: '11',
expire_year: '2020',
first_name: 'Joe',
last_name: 'Shopper',
valid_until: '2020-03-16T00:00:00Z',
create_time: '2017-03-17T19:24:43Z',
update_time: '2017-03-17T19:24:43Z',
links:
[ { href: 'https://api.sandbox.paypal.com/v1/vault/credit-cards/CARD-4W491882YN380234BLDGDP6Y',
rel: 'self',
method: 'GET' },
{ href: 'https://api.sandbox.paypal.com/v1/vault/credit-cards/CARD-4W491882YN380234BLDGDP6Y',
rel: 'delete',
method: 'DELETE' },
{ href: 'https://api.sandbox.paypal.com/v1/vault/credit-cards/CARD-4W491882YN380234BLDGDP6Y',
rel: 'patch',
method: 'PATCH' } ],
httpStatusCode: 201 }
Now I am using same vaulted card ID for making payment see below code:
autoRenewalPlan: function (req, res) {
var paypal = require('paypal-rest-sdk');
paypal.configure({
'mode': 'sandbox', //sandbox or live
'client_id': 'Aan_H7FviRQOuUALQ3fQhy5HFt_FZN_JLEkVSAHoiLHPSgDMnVqvbfFYLnnQ_Mq6ZiE1S2S-_2skyyag',
'client_secret': 'EDq_8CUG5g7X6TU9DF4PpuZh_ASr5oxTbZ9SUv0Iw5cpTHrjHFU_QzMsDI_1k0B5eL3s43AVxvlNvKP_'
});
var cardData = {
"intent": "sale",
"payer": {
"payment_method": "credit_card",
"funding_instruments": [{
"credit_card_token": {
"credit_card_id": "CARD-4W491882YN380234BLDGDP6Y",
"external_customer_id": "22896dc3-8b03-4a98-b1b4-0124df78b9cd"
}
}]
},
"transactions": [{
"amount": {
"total": "7.50",
"currency": "USD"
},
"description": "This is the payment transaction description."
}]
};
//console.log(cardData);
paypal.payment.create(cardData, function(error, payment){
if(error){
console.log(error);
} else {
//console.log(payment);
console.log(JSON.stringify(payment));
res.json({"status": true, "messagePaymentSUccess": "successfully done payment"});
}
});
}
Now its generating the below error:
'{"Authorization":"Bearer A101.cWT-2b5U_sj2rL05xKv-pnxvdAFqIJTNE9o4Q2ngn_NQsLtZALZBqDnNOFFXA5tG.RmxuHvVBbXw2ho0nEZ90CWk14Su","Content-Length":340,"Accept":"application/json","Content-Type":"application/json","PayPal-Request-Id":"af2fd326-214a-4bc8-9bab-729ea602b65b","User-Agent":"PayPalSDK/PayPal-node-SDK 1.7.1 (node v6.9.1-x64-win32; OpenSSL 1.0.2j)"}'
'{"intent":"sale","payer":{"payment_method":"credit_card","funding_instruments":[{"credit_card_token":{"credit_card_id":"CARD-4W491882YN380234BLDGDP6Y","external_customer_id":"22896dc3-8b03-4a98-b1b4-0124df78b9cd"}}]},"transactions":[{"amount":{"total":"7.50","currency":"USD"},"description":"This is the payment transaction description."}]}'
paypal-debug-id: be91c221ebbf5, be91c221ebbf5
'{"date":"Fri, 17 Mar 2017 19:27:36 GMT","server":"Apache","paypal-debug-id":"be91c221ebbf5, be91c221ebbf5","content-language":"*","connection":"close","set-cookie":["X-PP-SILOVER=name%3DSANDBOX3.API.1%26silo_version%3D1880%26app%3Dplatformapiserv%26TIME%3D2822294616%26HTTP_X_PP_AZ_LOCATOR%3D; Expires=Fri, 17 Mar 2017 19:57:37 GMT; domain=.paypal.com; path=/; Secure; HttpOnly","X-PP-SILOVER=; Expires=Thu, 01 Jan 1970 00:00:01 GMT"],"vary":"Authorization","content-length":"213","content-type":"application/json"}'
'{"name":"MALFORMED_REQUEST","message":"Incoming JSON request does not map to API request","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#MALFORMED_REQUEST","debug_id":"be91c221ebbf5"}'
{ Error: Response Status : 400
at IncomingMessage.<anonymous> (D:\node-project\lostcontact\node_modules\paypal-rest-sdk\lib\client.js:136:23)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickDomainCallback (internal/process/next_tick.js:122:9)
response:
{ name: 'MALFORMED_REQUEST',
message: 'Incoming JSON request does not map to API request',
information_link: 'https://developer.paypal.com/webapps/developer/docs/api/#MALFORMED_REQUEST',
debug_id: 'be91c221ebbf5',
httpStatusCode: 400 },
response_stringified: '{"name":"MALFORMED_REQUEST","message":"Incoming JSON request does not map to API request","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#MALFORMED_REQUEST","debug_id":"be91c221ebbf5","httpStatusCode":400}',
httpStatusCode: 400 }
paypal-debug-id: 5a3296fec4031, 5a3296fec4031
'{"date":"Fri, 17 Mar 2017 19:27:37 GMT","server":"Apache","paypal-debug-id":"5a3296fec4031, 5a3296fec4031","content-language":"*","connection":"close","set-cookie":["X-PP-SILOVER=name%3DSANDBOX3.API.1%26silo_version%3D1880%26app%3Dplatformapiserv%26TIME%3D2839071832%26HTTP_X_PP_AZ_LOCATOR%3D; Expires=Fri, 17 Mar 2017 19:57:37 GMT; domain=.paypal.com; path=/; Secure; HttpOnly","X-PP-SILOVER=; Expires=Thu, 01 Jan 1970 00:00:01 GMT"],"vary":"Authorization","content-length":"213","content-type":"application/json"}'
'{"name":"MALFORMED_REQUEST","message":"Incoming JSON request does not map to API request","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#MALFORMED_REQUEST","debug_id":"5a3296fec4031"}'
{ Error: Response Status : 400
at IncomingMessage.<anonymous> (D:\node-project\lostcontact\node_modules\paypal-rest-sdk\lib\client.js:136:23)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickDomainCallback (internal/process/next_tick.js:122:9)
response:
{ name: 'MALFORMED_REQUEST',
message: 'Incoming JSON request does not map to API request',
information_link: 'https://developer.paypal.com/webapps/developer/docs/api/#MALFORMED_REQUEST',
debug_id: '5a3296fec4031',
httpStatusCode: 400 },
response_stringified: '{"name":"MALFORMED_REQUEST","message":"Incoming JSON request does not map to API request","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#MALFORMED_REQUEST","debug_id":"5a3296fec4031","httpStatusCode":400}',
httpStatusCode: 400 }
Anybody face this kind of problem before?
via Raghbendra Nayak Systematix
No comments:
Post a Comment