@foxtware/mineral 0.1.29 → 0.1.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.creds.yml.sample +21 -0
- package/api/dpd/docs.md +6 -0
- package/api/dpd/dpd.constants.js +9 -0
- package/api/dpd/dpd.utils.js +145 -0
- package/api/dpd/dpdTrackingGet.js +64 -0
- package/api/fedex/docs.md +6 -0
- package/api/fedex/fedex.constants.js +11 -0
- package/api/fedex/fedex.utils.js +151 -0
- package/api/fedex/fedexTrackingGet.js +76 -0
- package/api/paypal/docs.md +14 -0
- package/api/paypal/paypal.constants.js +13 -0
- package/api/paypal/paypal.utils.js +166 -0
- package/api/paypal/paypalAccessTokenGet.js +81 -0
- package/api/paypal/paypalAuthorizationCapture.js +75 -0
- package/api/paypal/paypalAuthorizationGet.js +57 -0
- package/api/paypal/paypalBalancesGet.js +65 -0
- package/api/paypal/paypalCaptureGet.js +57 -0
- package/api/paypal/paypalCaptureRefund.js +78 -0
- package/api/paypal/paypalOrderAuthorize.js +69 -0
- package/api/paypal/paypalOrderCapture.js +69 -0
- package/api/paypal/paypalOrderCreate.js +81 -0
- package/api/paypal/paypalOrderGet.js +57 -0
- package/api/paypal/paypalRefundGet.js +57 -0
- package/api/paypal/paypalTransactionsGet.js +101 -0
- package/api/paypal/paypalUserInfoGet.js +62 -0
- package/api/royalmail/docs.md +6 -0
- package/api/royalmail/royalmail.constants.js +7 -0
- package/api/royalmail/royalmail.utils.js +55 -0
- package/api/royalmail/royalmailTrackingGet.js +70 -0
- package/api/shopify/shopify.utils.js +12 -0
- package/api/starshipit/starshipitProductUpdate.js +102 -0
- package/api/starshipit/starshipitProductsGet.js +2 -2
- package/api/stylearcade/stylearcadeGet.js +5 -2
- package/api/utils.js +44 -0
- package/package.json +1 -1
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// https://developer.paypal.com/api/rest/authentication/
|
|
2
|
+
|
|
3
|
+
const { credsValidator } = require('../validators');
|
|
4
|
+
const { ArgsWarden } = require('../utils');
|
|
5
|
+
const {
|
|
6
|
+
resolveAccessToken,
|
|
7
|
+
baseUrlForCreds,
|
|
8
|
+
getClientCredentialsToken,
|
|
9
|
+
} = require('../paypal/paypal.utils');
|
|
10
|
+
const { resolveCreds } = require('../pipelineSteps');
|
|
11
|
+
const { credsFromPayload } = require('../utils');
|
|
12
|
+
|
|
13
|
+
const argsWarden = new ArgsWarden([
|
|
14
|
+
['credsPayload', credsValidator],
|
|
15
|
+
]);
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Resolve (and cache) a PayPal access token for the given creds.
|
|
19
|
+
* Useful for debugging auth or for callers that need the raw token.
|
|
20
|
+
*/
|
|
21
|
+
const paypalAccessTokenGet = async (
|
|
22
|
+
credsPayload,
|
|
23
|
+
{
|
|
24
|
+
forceRefresh = false,
|
|
25
|
+
} = {},
|
|
26
|
+
) => {
|
|
27
|
+
|
|
28
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
29
|
+
credsPayload,
|
|
30
|
+
});
|
|
31
|
+
if (rejectResponse) {
|
|
32
|
+
return rejectResponse;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
const creds = await credsFromPayload(credsPayload);
|
|
37
|
+
|
|
38
|
+
if (forceRefresh && creds?.CLIENT_ID) {
|
|
39
|
+
const { clientCredentialsTokenCache } = require('../paypal/paypal.utils');
|
|
40
|
+
const env = (creds.SANDBOX === true || creds.SANDBOX === 'true'
|
|
41
|
+
|| creds.ENVIRONMENT === 'sandbox' || creds.MODE === 'sandbox')
|
|
42
|
+
? 'sandbox'
|
|
43
|
+
: 'live';
|
|
44
|
+
clientCredentialsTokenCache.delete(`${ env }:${ creds.CLIENT_ID }`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const accessToken = await resolveAccessToken(creds);
|
|
48
|
+
return {
|
|
49
|
+
ok: true,
|
|
50
|
+
data: {
|
|
51
|
+
access_token: accessToken,
|
|
52
|
+
base_url: baseUrlForCreds(creds),
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
} catch (err) {
|
|
56
|
+
return {
|
|
57
|
+
ok: false,
|
|
58
|
+
error: {
|
|
59
|
+
code: 'PAYPAL_AUTH_FAILED',
|
|
60
|
+
message: err.message || String(err),
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const funcApiConfig = {
|
|
67
|
+
argsWarden,
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
module.exports = {
|
|
71
|
+
paypalAccessTokenGet,
|
|
72
|
+
funcApiConfig,
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/*
|
|
76
|
+
curl -X POST "http://localhost:8000/paypalAccessTokenGet" \
|
|
77
|
+
-H "Content-Type: application/json" \
|
|
78
|
+
-d '{
|
|
79
|
+
"credsPayload": { "credsPath": "paypal" }
|
|
80
|
+
}'
|
|
81
|
+
*/
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// https://developer.paypal.com/docs/api/payments/v2/#authorizations_capture
|
|
2
|
+
|
|
3
|
+
const { credsValidator } = require('../validators');
|
|
4
|
+
const { ArgsWarden } = require('../utils');
|
|
5
|
+
const { paypalClient } = require('../paypal/paypal.utils');
|
|
6
|
+
|
|
7
|
+
const argsWarden = new ArgsWarden([
|
|
8
|
+
['credsPayload', credsValidator],
|
|
9
|
+
['authorizationId'],
|
|
10
|
+
]);
|
|
11
|
+
|
|
12
|
+
const paypalAuthorizationCapture = async (
|
|
13
|
+
credsPayload,
|
|
14
|
+
authorizationId,
|
|
15
|
+
{
|
|
16
|
+
capture,
|
|
17
|
+
prefer = 'return=representation',
|
|
18
|
+
requestId,
|
|
19
|
+
fetchClient = paypalClient,
|
|
20
|
+
} = {},
|
|
21
|
+
) => {
|
|
22
|
+
|
|
23
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
24
|
+
credsPayload,
|
|
25
|
+
authorizationId,
|
|
26
|
+
});
|
|
27
|
+
if (rejectResponse) {
|
|
28
|
+
return rejectResponse;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const headers = {
|
|
32
|
+
Prefer: prefer,
|
|
33
|
+
};
|
|
34
|
+
if (requestId) {
|
|
35
|
+
headers['PayPal-Request-Id'] = requestId;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const response = await fetchClient.fetch({
|
|
39
|
+
requestPayload: {
|
|
40
|
+
method: 'post',
|
|
41
|
+
url: `/v2/payments/authorizations/${ encodeURIComponent(authorizationId) }/capture`,
|
|
42
|
+
headers,
|
|
43
|
+
body: capture !== undefined ? capture : {},
|
|
44
|
+
},
|
|
45
|
+
context: {
|
|
46
|
+
credsPayload,
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
return response;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const funcApiConfig = {
|
|
54
|
+
argsWarden,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
module.exports = {
|
|
58
|
+
paypalAuthorizationCapture,
|
|
59
|
+
funcApiConfig,
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/*
|
|
63
|
+
curl -X POST "http://localhost:8000/paypalAuthorizationCapture" \
|
|
64
|
+
-H "Content-Type: application/json" \
|
|
65
|
+
-d '{
|
|
66
|
+
"credsPayload": { "credsPath": "paypal" },
|
|
67
|
+
"authorizationId": "0VF52814937998046",
|
|
68
|
+
"options": {
|
|
69
|
+
"capture": {
|
|
70
|
+
"amount": { "value": "10.00", "currency_code": "USD" },
|
|
71
|
+
"final_capture": true
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}'
|
|
75
|
+
*/
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// https://developer.paypal.com/docs/api/payments/v2/#authorizations_get
|
|
2
|
+
|
|
3
|
+
const { credsValidator } = require('../validators');
|
|
4
|
+
const { ArgsWarden } = require('../utils');
|
|
5
|
+
const { paypalClient } = require('../paypal/paypal.utils');
|
|
6
|
+
|
|
7
|
+
const argsWarden = new ArgsWarden([
|
|
8
|
+
['credsPayload', credsValidator],
|
|
9
|
+
['authorizationId'],
|
|
10
|
+
]);
|
|
11
|
+
|
|
12
|
+
const paypalAuthorizationGet = async (
|
|
13
|
+
credsPayload,
|
|
14
|
+
authorizationId,
|
|
15
|
+
{
|
|
16
|
+
fetchClient = paypalClient,
|
|
17
|
+
} = {},
|
|
18
|
+
) => {
|
|
19
|
+
|
|
20
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
21
|
+
credsPayload,
|
|
22
|
+
authorizationId,
|
|
23
|
+
});
|
|
24
|
+
if (rejectResponse) {
|
|
25
|
+
return rejectResponse;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const response = await fetchClient.fetch({
|
|
29
|
+
requestPayload: {
|
|
30
|
+
method: 'get',
|
|
31
|
+
url: `/v2/payments/authorizations/${ encodeURIComponent(authorizationId) }`,
|
|
32
|
+
},
|
|
33
|
+
context: {
|
|
34
|
+
credsPayload,
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
return response;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const funcApiConfig = {
|
|
42
|
+
argsWarden,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
module.exports = {
|
|
46
|
+
paypalAuthorizationGet,
|
|
47
|
+
funcApiConfig,
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/*
|
|
51
|
+
curl -X POST "http://localhost:8000/paypalAuthorizationGet" \
|
|
52
|
+
-H "Content-Type: application/json" \
|
|
53
|
+
-d '{
|
|
54
|
+
"credsPayload": { "credsPath": "paypal" },
|
|
55
|
+
"authorizationId": "0VF52814937998046"
|
|
56
|
+
}'
|
|
57
|
+
*/
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// https://developer.paypal.com/docs/api/transaction-search/v1/#balances_get
|
|
2
|
+
|
|
3
|
+
const { credsValidator } = require('../validators');
|
|
4
|
+
const { ArgsWarden } = require('../utils');
|
|
5
|
+
const { paypalClient } = require('../paypal/paypal.utils');
|
|
6
|
+
|
|
7
|
+
const argsWarden = new ArgsWarden([
|
|
8
|
+
['credsPayload', credsValidator],
|
|
9
|
+
]);
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* List balances for the account. Optional asOfTime is ISO-8601.
|
|
13
|
+
*/
|
|
14
|
+
const paypalBalancesGet = async (
|
|
15
|
+
credsPayload,
|
|
16
|
+
{
|
|
17
|
+
asOfTime,
|
|
18
|
+
currencyCode,
|
|
19
|
+
fetchClient = paypalClient,
|
|
20
|
+
} = {},
|
|
21
|
+
) => {
|
|
22
|
+
|
|
23
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
24
|
+
credsPayload,
|
|
25
|
+
});
|
|
26
|
+
if (rejectResponse) {
|
|
27
|
+
return rejectResponse;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const response = await fetchClient.fetch({
|
|
31
|
+
requestPayload: {
|
|
32
|
+
method: 'get',
|
|
33
|
+
url: '/v1/reporting/balances',
|
|
34
|
+
params: {
|
|
35
|
+
...(asOfTime ? { as_of_time: asOfTime } : {}),
|
|
36
|
+
...(currencyCode ? { currency_code: currencyCode } : {}),
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
context: {
|
|
40
|
+
credsPayload,
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
return response;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const funcApiConfig = {
|
|
48
|
+
argsWarden,
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
module.exports = {
|
|
52
|
+
paypalBalancesGet,
|
|
53
|
+
funcApiConfig,
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/*
|
|
57
|
+
curl -X POST "http://localhost:8000/paypalBalancesGet" \
|
|
58
|
+
-H "Content-Type: application/json" \
|
|
59
|
+
-d '{
|
|
60
|
+
"credsPayload": { "credsPath": "paypal" },
|
|
61
|
+
"options": {
|
|
62
|
+
"currencyCode": "USD"
|
|
63
|
+
}
|
|
64
|
+
}'
|
|
65
|
+
*/
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// https://developer.paypal.com/docs/api/payments/v2/#captures_get
|
|
2
|
+
|
|
3
|
+
const { credsValidator } = require('../validators');
|
|
4
|
+
const { ArgsWarden } = require('../utils');
|
|
5
|
+
const { paypalClient } = require('../paypal/paypal.utils');
|
|
6
|
+
|
|
7
|
+
const argsWarden = new ArgsWarden([
|
|
8
|
+
['credsPayload', credsValidator],
|
|
9
|
+
['captureId'],
|
|
10
|
+
]);
|
|
11
|
+
|
|
12
|
+
const paypalCaptureGet = async (
|
|
13
|
+
credsPayload,
|
|
14
|
+
captureId,
|
|
15
|
+
{
|
|
16
|
+
fetchClient = paypalClient,
|
|
17
|
+
} = {},
|
|
18
|
+
) => {
|
|
19
|
+
|
|
20
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
21
|
+
credsPayload,
|
|
22
|
+
captureId,
|
|
23
|
+
});
|
|
24
|
+
if (rejectResponse) {
|
|
25
|
+
return rejectResponse;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const response = await fetchClient.fetch({
|
|
29
|
+
requestPayload: {
|
|
30
|
+
method: 'get',
|
|
31
|
+
url: `/v2/payments/captures/${ encodeURIComponent(captureId) }`,
|
|
32
|
+
},
|
|
33
|
+
context: {
|
|
34
|
+
credsPayload,
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
return response;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const funcApiConfig = {
|
|
42
|
+
argsWarden,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
module.exports = {
|
|
46
|
+
paypalCaptureGet,
|
|
47
|
+
funcApiConfig,
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/*
|
|
51
|
+
curl -X POST "http://localhost:8000/paypalCaptureGet" \
|
|
52
|
+
-H "Content-Type: application/json" \
|
|
53
|
+
-d '{
|
|
54
|
+
"credsPayload": { "credsPath": "paypal" },
|
|
55
|
+
"captureId": "2GG279541U471931P"
|
|
56
|
+
}'
|
|
57
|
+
*/
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// https://developer.paypal.com/docs/api/payments/v2/#captures_refund
|
|
2
|
+
|
|
3
|
+
const { credsValidator } = require('../validators');
|
|
4
|
+
const { ArgsWarden } = require('../utils');
|
|
5
|
+
const { paypalClient } = require('../paypal/paypal.utils');
|
|
6
|
+
|
|
7
|
+
const argsWarden = new ArgsWarden([
|
|
8
|
+
['credsPayload', credsValidator],
|
|
9
|
+
['captureId'],
|
|
10
|
+
]);
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Refund a captured payment. Optional `refund` body can include amount,
|
|
14
|
+
* invoice_id, note_to_payer, etc. Omit body (or pass {}) for a full refund.
|
|
15
|
+
*/
|
|
16
|
+
const paypalCaptureRefund = async (
|
|
17
|
+
credsPayload,
|
|
18
|
+
captureId,
|
|
19
|
+
{
|
|
20
|
+
refund,
|
|
21
|
+
prefer = 'return=representation',
|
|
22
|
+
requestId,
|
|
23
|
+
fetchClient = paypalClient,
|
|
24
|
+
} = {},
|
|
25
|
+
) => {
|
|
26
|
+
|
|
27
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
28
|
+
credsPayload,
|
|
29
|
+
captureId,
|
|
30
|
+
});
|
|
31
|
+
if (rejectResponse) {
|
|
32
|
+
return rejectResponse;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const headers = {
|
|
36
|
+
Prefer: prefer,
|
|
37
|
+
};
|
|
38
|
+
if (requestId) {
|
|
39
|
+
headers['PayPal-Request-Id'] = requestId;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const response = await fetchClient.fetch({
|
|
43
|
+
requestPayload: {
|
|
44
|
+
method: 'post',
|
|
45
|
+
url: `/v2/payments/captures/${ encodeURIComponent(captureId) }/refund`,
|
|
46
|
+
headers,
|
|
47
|
+
body: refund !== undefined ? refund : {},
|
|
48
|
+
},
|
|
49
|
+
context: {
|
|
50
|
+
credsPayload,
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
return response;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const funcApiConfig = {
|
|
58
|
+
argsWarden,
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
module.exports = {
|
|
62
|
+
paypalCaptureRefund,
|
|
63
|
+
funcApiConfig,
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/*
|
|
67
|
+
curl -X POST "http://localhost:8000/paypalCaptureRefund" \
|
|
68
|
+
-H "Content-Type: application/json" \
|
|
69
|
+
-d '{
|
|
70
|
+
"credsPayload": { "credsPath": "paypal" },
|
|
71
|
+
"captureId": "2GG279541U471931P",
|
|
72
|
+
"options": {
|
|
73
|
+
"refund": {
|
|
74
|
+
"amount": { "value": "10.00", "currency_code": "USD" }
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}'
|
|
78
|
+
*/
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// https://developer.paypal.com/docs/api/orders/v2/#orders_authorize
|
|
2
|
+
|
|
3
|
+
const { credsValidator } = require('../validators');
|
|
4
|
+
const { ArgsWarden } = require('../utils');
|
|
5
|
+
const { paypalClient } = require('../paypal/paypal.utils');
|
|
6
|
+
|
|
7
|
+
const argsWarden = new ArgsWarden([
|
|
8
|
+
['credsPayload', credsValidator],
|
|
9
|
+
['orderId'],
|
|
10
|
+
]);
|
|
11
|
+
|
|
12
|
+
const paypalOrderAuthorize = async (
|
|
13
|
+
credsPayload,
|
|
14
|
+
orderId,
|
|
15
|
+
{
|
|
16
|
+
body,
|
|
17
|
+
prefer = 'return=representation',
|
|
18
|
+
requestId,
|
|
19
|
+
fetchClient = paypalClient,
|
|
20
|
+
} = {},
|
|
21
|
+
) => {
|
|
22
|
+
|
|
23
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
24
|
+
credsPayload,
|
|
25
|
+
orderId,
|
|
26
|
+
});
|
|
27
|
+
if (rejectResponse) {
|
|
28
|
+
return rejectResponse;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const headers = {
|
|
32
|
+
Prefer: prefer,
|
|
33
|
+
};
|
|
34
|
+
if (requestId) {
|
|
35
|
+
headers['PayPal-Request-Id'] = requestId;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const response = await fetchClient.fetch({
|
|
39
|
+
requestPayload: {
|
|
40
|
+
method: 'post',
|
|
41
|
+
url: `/v2/checkout/orders/${ encodeURIComponent(orderId) }/authorize`,
|
|
42
|
+
headers,
|
|
43
|
+
...(body !== undefined ? { body } : { body: {} }),
|
|
44
|
+
},
|
|
45
|
+
context: {
|
|
46
|
+
credsPayload,
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
return response;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const funcApiConfig = {
|
|
54
|
+
argsWarden,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
module.exports = {
|
|
58
|
+
paypalOrderAuthorize,
|
|
59
|
+
funcApiConfig,
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/*
|
|
63
|
+
curl -X POST "http://localhost:8000/paypalOrderAuthorize" \
|
|
64
|
+
-H "Content-Type: application/json" \
|
|
65
|
+
-d '{
|
|
66
|
+
"credsPayload": { "credsPath": "paypal" },
|
|
67
|
+
"orderId": "5O190127TN364715T"
|
|
68
|
+
}'
|
|
69
|
+
*/
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// https://developer.paypal.com/docs/api/orders/v2/#orders_capture
|
|
2
|
+
|
|
3
|
+
const { credsValidator } = require('../validators');
|
|
4
|
+
const { ArgsWarden } = require('../utils');
|
|
5
|
+
const { paypalClient } = require('../paypal/paypal.utils');
|
|
6
|
+
|
|
7
|
+
const argsWarden = new ArgsWarden([
|
|
8
|
+
['credsPayload', credsValidator],
|
|
9
|
+
['orderId'],
|
|
10
|
+
]);
|
|
11
|
+
|
|
12
|
+
const paypalOrderCapture = async (
|
|
13
|
+
credsPayload,
|
|
14
|
+
orderId,
|
|
15
|
+
{
|
|
16
|
+
body,
|
|
17
|
+
prefer = 'return=representation',
|
|
18
|
+
requestId,
|
|
19
|
+
fetchClient = paypalClient,
|
|
20
|
+
} = {},
|
|
21
|
+
) => {
|
|
22
|
+
|
|
23
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
24
|
+
credsPayload,
|
|
25
|
+
orderId,
|
|
26
|
+
});
|
|
27
|
+
if (rejectResponse) {
|
|
28
|
+
return rejectResponse;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const headers = {
|
|
32
|
+
Prefer: prefer,
|
|
33
|
+
};
|
|
34
|
+
if (requestId) {
|
|
35
|
+
headers['PayPal-Request-Id'] = requestId;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const response = await fetchClient.fetch({
|
|
39
|
+
requestPayload: {
|
|
40
|
+
method: 'post',
|
|
41
|
+
url: `/v2/checkout/orders/${ encodeURIComponent(orderId) }/capture`,
|
|
42
|
+
headers,
|
|
43
|
+
...(body !== undefined ? { body } : { body: {} }),
|
|
44
|
+
},
|
|
45
|
+
context: {
|
|
46
|
+
credsPayload,
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
return response;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const funcApiConfig = {
|
|
54
|
+
argsWarden,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
module.exports = {
|
|
58
|
+
paypalOrderCapture,
|
|
59
|
+
funcApiConfig,
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/*
|
|
63
|
+
curl -X POST "http://localhost:8000/paypalOrderCapture" \
|
|
64
|
+
-H "Content-Type: application/json" \
|
|
65
|
+
-d '{
|
|
66
|
+
"credsPayload": { "credsPath": "paypal" },
|
|
67
|
+
"orderId": "5O190127TN364715T"
|
|
68
|
+
}'
|
|
69
|
+
*/
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// https://developer.paypal.com/docs/api/orders/v2/#orders_create
|
|
2
|
+
|
|
3
|
+
const { credsValidator } = require('../validators');
|
|
4
|
+
const { ArgsWarden } = require('../utils');
|
|
5
|
+
const { paypalClient } = require('../paypal/paypal.utils');
|
|
6
|
+
|
|
7
|
+
const argsWarden = new ArgsWarden([
|
|
8
|
+
['credsPayload', credsValidator],
|
|
9
|
+
['order'],
|
|
10
|
+
]);
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Create a PayPal order.
|
|
14
|
+
* `order` is the full Orders v2 create payload, e.g.:
|
|
15
|
+
* {
|
|
16
|
+
* intent: 'CAPTURE',
|
|
17
|
+
* purchase_units: [{ amount: { currency_code: 'USD', value: '10.00' } }],
|
|
18
|
+
* }
|
|
19
|
+
*/
|
|
20
|
+
const paypalOrderCreate = async (
|
|
21
|
+
credsPayload,
|
|
22
|
+
order,
|
|
23
|
+
{
|
|
24
|
+
prefer = 'return=representation',
|
|
25
|
+
requestId,
|
|
26
|
+
fetchClient = paypalClient,
|
|
27
|
+
} = {},
|
|
28
|
+
) => {
|
|
29
|
+
|
|
30
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
31
|
+
credsPayload,
|
|
32
|
+
order,
|
|
33
|
+
});
|
|
34
|
+
if (rejectResponse) {
|
|
35
|
+
return rejectResponse;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const headers = {
|
|
39
|
+
Prefer: prefer,
|
|
40
|
+
};
|
|
41
|
+
if (requestId) {
|
|
42
|
+
headers['PayPal-Request-Id'] = requestId;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const response = await fetchClient.fetch({
|
|
46
|
+
requestPayload: {
|
|
47
|
+
method: 'post',
|
|
48
|
+
url: '/v2/checkout/orders',
|
|
49
|
+
headers,
|
|
50
|
+
body: order,
|
|
51
|
+
},
|
|
52
|
+
context: {
|
|
53
|
+
credsPayload,
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
return response;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const funcApiConfig = {
|
|
61
|
+
argsWarden,
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
module.exports = {
|
|
65
|
+
paypalOrderCreate,
|
|
66
|
+
funcApiConfig,
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/*
|
|
70
|
+
curl -X POST "http://localhost:8000/paypalOrderCreate" \
|
|
71
|
+
-H "Content-Type: application/json" \
|
|
72
|
+
-d '{
|
|
73
|
+
"credsPayload": { "credsPath": "paypal" },
|
|
74
|
+
"order": {
|
|
75
|
+
"intent": "CAPTURE",
|
|
76
|
+
"purchase_units": [{
|
|
77
|
+
"amount": { "currency_code": "USD", "value": "10.00" }
|
|
78
|
+
}]
|
|
79
|
+
}
|
|
80
|
+
}'
|
|
81
|
+
*/
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// https://developer.paypal.com/docs/api/orders/v2/#orders_get
|
|
2
|
+
|
|
3
|
+
const { credsValidator } = require('../validators');
|
|
4
|
+
const { ArgsWarden } = require('../utils');
|
|
5
|
+
const { paypalClient } = require('../paypal/paypal.utils');
|
|
6
|
+
|
|
7
|
+
const argsWarden = new ArgsWarden([
|
|
8
|
+
['credsPayload', credsValidator],
|
|
9
|
+
['orderId'],
|
|
10
|
+
]);
|
|
11
|
+
|
|
12
|
+
const paypalOrderGet = async (
|
|
13
|
+
credsPayload,
|
|
14
|
+
orderId,
|
|
15
|
+
{
|
|
16
|
+
fetchClient = paypalClient,
|
|
17
|
+
} = {},
|
|
18
|
+
) => {
|
|
19
|
+
|
|
20
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
21
|
+
credsPayload,
|
|
22
|
+
orderId,
|
|
23
|
+
});
|
|
24
|
+
if (rejectResponse) {
|
|
25
|
+
return rejectResponse;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const response = await fetchClient.fetch({
|
|
29
|
+
requestPayload: {
|
|
30
|
+
method: 'get',
|
|
31
|
+
url: `/v2/checkout/orders/${ encodeURIComponent(orderId) }`,
|
|
32
|
+
},
|
|
33
|
+
context: {
|
|
34
|
+
credsPayload,
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
return response;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const funcApiConfig = {
|
|
42
|
+
argsWarden,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
module.exports = {
|
|
46
|
+
paypalOrderGet,
|
|
47
|
+
funcApiConfig,
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/*
|
|
51
|
+
curl -X POST "http://localhost:8000/paypalOrderGet" \
|
|
52
|
+
-H "Content-Type: application/json" \
|
|
53
|
+
-d '{
|
|
54
|
+
"credsPayload": { "credsPath": "paypal" },
|
|
55
|
+
"orderId": "5O190127TN364715T"
|
|
56
|
+
}'
|
|
57
|
+
*/
|