Adaptive Payments and Adaptive Accounts SDK
Node.js sdk for Paypal Adaptive Payments and Paypal Adaptive Accounts APIs, without dependencies
Usage
- Add dependency 'paypal-adaptive' in your package.json file.
- Require 'paypal-adaptive' in your file.
var Paypal = require('paypal-adaptive');
var paypalSdk = new Paypal({
userId: 'userId',
password: 'password',
signature: 'signature',
sandbox: true
});
- Call to sdk methods or to the generic method callApi. If you get an error, you can check the response too for better error handling.
var requestData = {
requestEnvelope: {
errorLanguage: 'en_US',
detailLevel: 'ReturnAll'
},
payKey: 'AP-1234567890'
};
paypalSdk.callApi('AdaptivePayments/PaymentDetails', requestData, function (err, response) {
if (err) {
console.log(err);
console.log(response);
} else {
console.log(response);
}
});
API
GetPaymentOptions
var payKey = 'AP-1234567890';
paypalSdk.getPaymentOptions(payKey, function (err, response) {
if (err) {
console.log(err);
} else {
console.log(response);
}
});
PaymentDetails
var params = {
payKey: 'AP-1234567890'
};
var params = {
transactionId: 'AP-1234567890'
};
var params = {
trackingId: 'AP-1234567890'
};
paypalSdk.paymentDetails(params, function (err, response) {
if (err) {
console.log(err);
} else {
console.log(response);
}
});
Pay
var payload = {
requestEnvelope: {
errorLanguage: 'en_US'
},
actionType: 'PAY',
currencyCode: 'USD',
feesPayer: 'EACHRECEIVER',
memo: 'Chained payment example',
cancelUrl: 'http://test.com/cancel',
returnUrl: 'http://test.com/success',
receiverList: {
receiver: [
{
email: 'primary@test.com',
amount: '100.00',
primary:'true'
},
{
email: 'secondary@test.com',
amount: '10.00',
primary:'false'
}
]
}
};
paypalSdk.pay(payload, function (err, response) {
if (err) {
console.log(err);
} else {
console.log(response);
console.log('Redirect to %s', response.paymentApprovalUrl);
}
});
Preapproval
var payload = {
currencyCode: 'USD',
startingDate: new Date().toISOString(),
endingDate: new Date('2020-01-01').toISOString(),
returnUrl: 'http://your-website.com',
cancelUrl: 'http://your-website.com',
ipnNotificationUrl: 'http://your-ipn-listener.com',
maxNumberOfPayments: 1,
displayMaxTotalAmount: true,
maxTotalAmountOfAllPayments: '100.00',
requestEnvelope: {
errorLanguage: 'en_US'
}
}
paypalSdk.preapproval(payload, function (err, response) {
if (err) {
console.log(err);
} else {
console.log(response);
console.log('Redirect to %s', response.preapprovalUrl);
}
});
Note:
The other API methods has default behavior by now: you send a payload and obtains the Paypal original response.
var payload = {
requestEnvelope: {
errorLanguage: 'en_US'
},
};
var callback = function (err, response) {
if (err) {
console.log(err);
} else {
console.log(response)
}
};
paypalSdk.cancelPreapproval(payload, callback);
paypalSdk.convertCurrency(payload, callback);
paypalSdk.executePayment(payload, callback);
paypalSdk.getFundingPlans(payload, callback);
paypalSdk.getShippingAddresses(payload, callback);
paypalSdk.preapprovalDetails(payload, callback);
paypalSdk.setPaymentOptions(payload, callback);
paypalSdk.addBankAccount(payload, callback);
paypalSdk.addPaymentCard(payload, callback);
paypalSdk.checkComplianceStatus(payload, callback);
paypalSdk.createAccount(payload, callback);
paypalSdk.getUserAgreement(payload, callback);
paypalSdk.getVerifiedStatus(payload, callback);
paypalSdk.setFundingSourceConfirmed(payload, callback);
paypalSdk.updateComplianceStatus(payload, callback);
Tests
Tests can be ran with:
mocha
Reference
Paypal Adaptive Payments
Paypal Adaptive Accounts
License
Copyright (c) 2014 Gonzalo Aguirre. See the LICENSE file for license rights and limitations (MIT).