
Product
Introducing Socket Scanning for OpenVSX Extensions
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.
@opencollective/paypal-adaptive
Advanced tools
Paypal Adaptive (Payments & Accounts) SDK in node.js
Node.js sdk for Paypal Adaptive Payments and Paypal Adaptive Accounts APIs. Forked from https://github.com/Ideame/paypal-adaptive-sdk-nodejs and updated with Typescript + security fixes. Backward compatible with the original sdk.
npm install --save-exact @opencollective/paypal-adaptive
import Paypal from '@opencollective/paypal-adaptive';
var paypalSdk = new Paypal({
userId: 'userId',
password: 'password',
signature: 'signature',
sandbox: true, //defaults to false
});
const requestData = { payKey: 'AP-1234567890' };
paypalSdk.callApi('AdaptivePayments/PaymentDetails', requestData, function (err, response) {
if (err) {
// You can see the error
console.log(err);
//And the original Paypal API response too
console.log(response);
} else {
// Successful response
console.log(response);
}
});
var payKey = 'AP-1234567890';
paypalSdk.getPaymentOptions(payKey, function (err, response) {
if (err) {
console.log(err);
} else {
// payments options for this payKey
console.log(response);
}
});
// One of this params is required
// The payKey
var params = {
payKey: 'AP-1234567890',
};
// Or the transactionId
var params = {
transactionId: 'AP-1234567890',
};
// Or the trackingId
var params = {
trackingId: 'AP-1234567890',
};
paypalSdk.paymentDetails(params, function (err, response) {
if (err) {
console.log(err);
} else {
// payments details for this payKey, transactionId or trackingId
console.log(response);
}
});
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 {
// Response will have the original Paypal API response
console.log(response);
// But also a paymentApprovalUrl, so you can redirect the sender to checkout easily
console.log('Redirect to %s', response.paymentApprovalUrl);
}
});
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 {
// Response will have the original Paypal API response
console.log(response);
// But also a preapprovalUrl, so you can redirect the sender to approve the payment easily
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',
},
// another data required by API method
};
var callback = function (err, response) {
if (err) {
// Handle error
console.log(err);
} else {
// Paypal response
console.log(response);
}
};
// For Adaptive Payments
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);
// For Adaptive Accounts
paypalSdk.addBankAccount(payload, callback);
paypalSdk.addPaymentCard(payload, callback);
paypalSdk.checkComplianceStatus(payload, callback);
paypalSdk.createAccount(payload, callback);
// To use this method you can set X-PAYPAL-SANDBOX-EMAIL-ADDRESS and X-PAYPAL-DEVICE-IPADDRESS headers passing 'sandboxEmailAddress' and 'deviceIpAddress' properties on config
paypalSdk.getUserAgreement(payload, callback);
paypalSdk.getVerifiedStatus(payload, callback);
paypalSdk.setFundingSourceConfirmed(payload, callback);
paypalSdk.updateComplianceStatus(payload, callback);
Tests can be ran with:
npm test
To release a new version, you need to:
npm version patch (or minor or major)npm publishhttps://developer.paypal.com/api/nvp-soap/adaptive-platform/
Copyright (c) 2024 Open Collective. Copyright (c) 2014 Gonzalo Aguirre. See the LICENSE file for license rights and limitations (MIT).
FAQs
Paypal Adaptive (Payments & Accounts) SDK in node.js
We found that @opencollective/paypal-adaptive demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.

Product
Bringing supply chain security to the next generation of JavaScript package managers

Product
A safer, faster way to eliminate vulnerabilities without updating dependencies