Skip to content

Commit c5d72dd

Browse files
author
Sourav Sarkar
committed
feat: add nodejs to standard-integration
1 parent b94c66b commit c5d72dd

File tree

4 files changed

+215
-117
lines changed

4 files changed

+215
-117
lines changed

advanced-integration/v2/server/node/.env

Lines changed: 0 additions & 5 deletions
This file was deleted.

advanced-integration/v2/server/node/server/server.js

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
Environment,
88
LogLevel,
99
OrdersController,
10-
} from '@paypal/paypal-server-sdk';
10+
} from "@paypal/paypal-server-sdk";
1111
import bodyParser from "body-parser";
1212

1313
const app = express();
@@ -18,18 +18,18 @@ const { PAYPAL_CLIENT_ID, PAYPAL_CLIENT_SECRET, PORT = 8080 } = process.env;
1818
const client = new Client({
1919
clientCredentialsAuthCredentials: {
2020
oAuthClientId: PAYPAL_CLIENT_ID,
21-
oAuthClientSecret: PAYPAL_CLIENT_SECRET
21+
oAuthClientSecret: PAYPAL_CLIENT_SECRET,
2222
},
2323
timeout: 0,
2424
environment: Environment.Sandbox,
2525
logging: {
2626
logLevel: LogLevel.Info,
2727
logRequest: {
28-
logBody: true
28+
logBody: true,
2929
},
3030
logResponse: {
31-
logHeaders: true
32-
}
31+
logHeaders: true,
32+
},
3333
},
3434
});
3535

@@ -46,17 +46,18 @@ const createOrder = async (cart) => {
4646
purchaseUnits: [
4747
{
4848
amount: {
49-
currencyCode: 'USD',
50-
value: '100.00',
49+
currencyCode: "USD",
50+
value: "100.00",
5151
},
52-
}
52+
},
5353
],
5454
},
55-
prefer: 'return=minimal'
56-
}
57-
55+
prefer: "return=minimal",
56+
};
57+
5858
try {
59-
const { body, ...httpResponse } = await ordersController.ordersCreate(collect);
59+
const { body, ...httpResponse } =
60+
await ordersController.ordersCreate(collect);
6061
// Get more response info...
6162
// const { statusCode, headers } = httpResponse;
6263
return {
@@ -66,7 +67,7 @@ const createOrder = async (cart) => {
6667
} catch (error) {
6768
if (error instanceof ApiError) {
6869
// const { statusCode, headers } = error;
69-
throw new Error(error.message);
70+
throw new Error(error.message);
7071
}
7172
}
7273
};
@@ -76,14 +77,14 @@ const createOrder = async (cart) => {
7677
* @see https://developer.paypal.com/docs/api/orders/v2/#orders_capture
7778
*/
7879
const captureOrder = async (orderID) => {
79-
8080
const collect = {
8181
id: orderID,
82-
prefer: 'return=minimal'
83-
}
84-
82+
prefer: "return=minimal",
83+
};
84+
8585
try {
86-
const { body, ...httpResponse } = await ordersController.ordersCapture(collect);
86+
const { body, ...httpResponse } =
87+
await ordersController.ordersCapture(collect);
8788
// Get more response info...
8889
// const { statusCode, headers } = httpResponse;
8990
return {
@@ -93,7 +94,7 @@ const captureOrder = async (orderID) => {
9394
} catch (error) {
9495
if (error instanceof ApiError) {
9596
// const { statusCode, headers } = error;
96-
throw new Error(error.message);
97+
throw new Error(error.message);
9798
}
9899
}
99100
};

standard-integration/server/node/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
"private": true,
55
"type": "module",
66
"dependencies": {
7+
"@paypal/paypal-server-sdk": "^0.5.1",
8+
"body-parser": "^1.20.3",
79
"dotenv": "^16.3.1",
810
"express": "^4.18.2",
911
"node-fetch": "^3.3.2"

0 commit comments

Comments
 (0)