7
7
Environment ,
8
8
LogLevel ,
9
9
OrdersController ,
10
- } from ' @paypal/paypal-server-sdk' ;
10
+ } from " @paypal/paypal-server-sdk" ;
11
11
import bodyParser from "body-parser" ;
12
12
13
13
const app = express ( ) ;
@@ -18,18 +18,18 @@ const { PAYPAL_CLIENT_ID, PAYPAL_CLIENT_SECRET, PORT = 8080 } = process.env;
18
18
const client = new Client ( {
19
19
clientCredentialsAuthCredentials : {
20
20
oAuthClientId : PAYPAL_CLIENT_ID ,
21
- oAuthClientSecret : PAYPAL_CLIENT_SECRET
21
+ oAuthClientSecret : PAYPAL_CLIENT_SECRET ,
22
22
} ,
23
23
timeout : 0 ,
24
24
environment : Environment . Sandbox ,
25
25
logging : {
26
26
logLevel : LogLevel . Info ,
27
27
logRequest : {
28
- logBody : true
28
+ logBody : true ,
29
29
} ,
30
30
logResponse : {
31
- logHeaders : true
32
- }
31
+ logHeaders : true ,
32
+ } ,
33
33
} ,
34
34
} ) ;
35
35
@@ -46,17 +46,18 @@ const createOrder = async (cart) => {
46
46
purchaseUnits : [
47
47
{
48
48
amount : {
49
- currencyCode : ' USD' ,
50
- value : ' 100.00' ,
49
+ currencyCode : " USD" ,
50
+ value : " 100.00" ,
51
51
} ,
52
- }
52
+ } ,
53
53
] ,
54
54
} ,
55
- prefer : ' return=minimal'
56
- }
57
-
55
+ prefer : " return=minimal" ,
56
+ } ;
57
+
58
58
try {
59
- const { body, ...httpResponse } = await ordersController . ordersCreate ( collect ) ;
59
+ const { body, ...httpResponse } =
60
+ await ordersController . ordersCreate ( collect ) ;
60
61
// Get more response info...
61
62
// const { statusCode, headers } = httpResponse;
62
63
return {
@@ -66,7 +67,7 @@ const createOrder = async (cart) => {
66
67
} catch ( error ) {
67
68
if ( error instanceof ApiError ) {
68
69
// const { statusCode, headers } = error;
69
- throw new Error ( error . message ) ;
70
+ throw new Error ( error . message ) ;
70
71
}
71
72
}
72
73
} ;
@@ -76,14 +77,14 @@ const createOrder = async (cart) => {
76
77
* @see https://developer.paypal.com/docs/api/orders/v2/#orders_capture
77
78
*/
78
79
const captureOrder = async ( orderID ) => {
79
-
80
80
const collect = {
81
81
id : orderID ,
82
- prefer : ' return=minimal'
83
- }
84
-
82
+ prefer : " return=minimal" ,
83
+ } ;
84
+
85
85
try {
86
- const { body, ...httpResponse } = await ordersController . ordersCapture ( collect ) ;
86
+ const { body, ...httpResponse } =
87
+ await ordersController . ordersCapture ( collect ) ;
87
88
// Get more response info...
88
89
// const { statusCode, headers } = httpResponse;
89
90
return {
@@ -93,7 +94,7 @@ const captureOrder = async (orderID) => {
93
94
} catch ( error ) {
94
95
if ( error instanceof ApiError ) {
95
96
// const { statusCode, headers } = error;
96
- throw new Error ( error . message ) ;
97
+ throw new Error ( error . message ) ;
97
98
}
98
99
}
99
100
} ;
0 commit comments