Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Project update #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: CI

on:
push:
branches:
- main
pull_request:
types:
- opened
- synchronize
- reopened

jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [14.x, 16.x, 18.x, 20.x]

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run test
282 changes: 155 additions & 127 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,151 +1,164 @@
## 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.
```js
var Paypal = require('paypal-adaptive');

var paypalSdk = new Paypal({
userId: 'userId',
password: 'password',
signature: 'signature',
sandbox: true //defaults to false
});
```
* 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.
```js
var requestData = {
requestEnvelope: {
errorLanguage: 'en_US',
detailLevel: 'ReturnAll'
},
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);
}
});
```
# Adaptive Payments and Adaptive Accounts SDK

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 CI and security fixes. Backward compatible with the original sdk.

## Usage

- Add dependency 'paypal-adaptive' in your package.json file.
- Require 'paypal-adaptive' in your file.

```js
var Paypal = require("paypal-adaptive");

var paypalSdk = new Paypal({
userId: "userId",
password: "password",
signature: "signature",
sandbox: true, //defaults to false
});
```

- 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.

```js
var requestData = {
requestEnvelope: {
errorLanguage: "en_US",
detailLevel: "ReturnAll",
},
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);
}
}
);
```

### API

#### GetPaymentOptions

```js
var payKey = 'AP-1234567890';
var payKey = "AP-1234567890";

paypalSdk.getPaymentOptions(payKey, function (err, response) {
if (err) {
console.log(err);
} else {
// payments options for this payKey
console.log(response);
}
if (err) {
console.log(err);
} else {
// payments options for this payKey
console.log(response);
}
});
```

#### PaymentDetails

```js
// One of this params is required
// The payKey
var params = {
payKey: 'AP-1234567890'
payKey: "AP-1234567890",
};
// Or the transactionId
var params = {
transactionId: 'AP-1234567890'
transactionId: "AP-1234567890",
};
// Or the trackingId
var params = {
trackingId: 'AP-1234567890'
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);
}
if (err) {
console.log(err);
} else {
// payments details for this payKey, transactionId or trackingId
console.log(response);
}
});
```

#### Pay

```js
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: '[email protected]',
amount: '100.00',
primary:'true'
},
{
email: '[email protected]',
amount: '10.00',
primary:'false'
}
]
}
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: "[email protected]",
amount: "100.00",
primary: "true",
},
{
email: "[email protected]",
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);
}
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);
}
});
```

#### Preapproval

```js
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'
}
}
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);
}
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);
}
});
```

Expand All @@ -154,20 +167,20 @@ The other API methods has default behavior by now: you send a payload and obtain

```js
var payload = {
requestEnvelope: {
errorLanguage: 'en_US'
},
// another data required by API method
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)
}
if (err) {
// Handle error
console.log(err);
} else {
// Paypal response
console.log(response);
}
};

// For Adaptive Payments
Expand Down Expand Up @@ -204,16 +217,31 @@ paypalSdk.setFundingSourceConfirmed(payload, callback);
paypalSdk.updateComplianceStatus(payload, callback);
```

## Development

### Tests
Tests can be ran with:

```sh
mocha
```
Tests can be ran with:

```sh
npm test
```

### Release

To release a new version, you need to:

1. Increment version with `npm version patch` (or minor or major)
2. Push changes to the repository
3. Publish the new version to npm with `npm publish`

## Reference

PayPal adaptive documentation is mostly down by now, but you can check:

- https://developer.paypal.com/api/nvp-soap/adaptive-platform/
- http://web.archive.org/web/20150905135740/https://developer.paypal.com/webapps/developer/docs/classic/api/

### Reference
<a href="https://developer.paypal.com/webapps/developer/docs/classic/api/#ap" target="_blank">Paypal Adaptive Payments</a>
<a href="https://developer.paypal.com/webapps/developer/docs/classic/api/#aa" target="_blank">Paypal Adaptive Accounts</a>
## License

### License
Copyright (c) 2014 Gonzalo Aguirre. See the LICENSE file for license rights and limitations (MIT).
Copyright (c) 2014 Gonzalo Aguirre. See the LICENSE file for license rights and limitations (MIT).
Loading
Loading