@easypayment/medusa-payment-paypal 1.0.2 → 1.1.0
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/.medusa/server/src/admin/index.js +7 -7
- package/.medusa/server/src/admin/index.mjs +7 -7
- package/.medusa/server/src/api/admin/paypal/onboard-complete/route.d.ts +2 -2
- package/.medusa/server/src/api/admin/paypal/onboard-complete/route.d.ts.map +1 -1
- package/.medusa/server/src/api/admin/paypal/onboard-complete/route.js +4 -0
- package/.medusa/server/src/api/admin/paypal/onboard-complete/route.js.map +1 -1
- package/.medusa/server/src/api/middlewares.d.ts.map +1 -1
- package/.medusa/server/src/api/middlewares.js +16 -1
- package/.medusa/server/src/api/middlewares.js.map +1 -1
- package/.medusa/server/src/api/store/paypal/capture-order/route.d.ts.map +1 -1
- package/.medusa/server/src/api/store/paypal/capture-order/route.js +45 -16
- package/.medusa/server/src/api/store/paypal/capture-order/route.js.map +1 -1
- package/.medusa/server/src/api/store/paypal/config/route.d.ts.map +1 -1
- package/.medusa/server/src/api/store/paypal/config/route.js +7 -1
- package/.medusa/server/src/api/store/paypal/config/route.js.map +1 -1
- package/.medusa/server/src/api/store/paypal/onboard-return/route.d.ts.map +1 -1
- package/.medusa/server/src/api/store/paypal/onboard-return/route.js +24 -2
- package/.medusa/server/src/api/store/paypal/onboard-return/route.js.map +1 -1
- package/.medusa/server/src/api/store/paypal/webhook/route.d.ts.map +1 -1
- package/.medusa/server/src/api/store/paypal/webhook/route.js +22 -48
- package/.medusa/server/src/api/store/paypal/webhook/route.js.map +1 -1
- package/.medusa/server/src/api/utils/rate-limit.d.ts +3 -0
- package/.medusa/server/src/api/utils/rate-limit.d.ts.map +1 -0
- package/.medusa/server/src/api/utils/rate-limit.js +92 -0
- package/.medusa/server/src/api/utils/rate-limit.js.map +1 -0
- package/.medusa/server/src/jobs/paypal-webhook-retry.d.ts.map +1 -1
- package/.medusa/server/src/jobs/paypal-webhook-retry.js +115 -90
- package/.medusa/server/src/jobs/paypal-webhook-retry.js.map +1 -1
- package/.medusa/server/src/modules/paypal/payment-provider/base-provider.d.ts +48 -0
- package/.medusa/server/src/modules/paypal/payment-provider/base-provider.d.ts.map +1 -0
- package/.medusa/server/src/modules/paypal/payment-provider/base-provider.js +159 -0
- package/.medusa/server/src/modules/paypal/payment-provider/base-provider.js.map +1 -0
- package/.medusa/server/src/modules/paypal/payment-provider/card-service.d.ts +5 -20
- package/.medusa/server/src/modules/paypal/payment-provider/card-service.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/payment-provider/card-service.js +27 -160
- package/.medusa/server/src/modules/paypal/payment-provider/card-service.js.map +1 -1
- package/.medusa/server/src/modules/paypal/payment-provider/service.d.ts +5 -20
- package/.medusa/server/src/modules/paypal/payment-provider/service.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/payment-provider/service.js +21 -138
- package/.medusa/server/src/modules/paypal/payment-provider/service.js.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/amounts.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/amounts.js +10 -0
- package/.medusa/server/src/modules/paypal/utils/amounts.js.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/credential-resolver.d.ts +1 -1
- package/.medusa/server/src/modules/paypal/utils/credential-resolver.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/credential-resolver.js +27 -26
- package/.medusa/server/src/modules/paypal/utils/credential-resolver.js.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/partner.d.ts +9 -0
- package/.medusa/server/src/modules/paypal/utils/partner.d.ts.map +1 -0
- package/.medusa/server/src/modules/paypal/utils/partner.js +12 -0
- package/.medusa/server/src/modules/paypal/utils/partner.js.map +1 -0
- package/.medusa/server/src/modules/paypal/utils/payment-session.d.ts +0 -5
- package/.medusa/server/src/modules/paypal/utils/payment-session.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/payment-session.js +37 -18
- package/.medusa/server/src/modules/paypal/utils/payment-session.js.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/secret-crypto.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/secret-crypto.js +30 -1
- package/.medusa/server/src/modules/paypal/utils/secret-crypto.js.map +1 -1
- package/.medusa/server/src/subscribers/paypal-webhook-process.d.ts +19 -0
- package/.medusa/server/src/subscribers/paypal-webhook-process.d.ts.map +1 -0
- package/.medusa/server/src/subscribers/paypal-webhook-process.js +107 -0
- package/.medusa/server/src/subscribers/paypal-webhook-process.js.map +1 -0
- package/CHANGELOG.md +73 -0
- package/package.json +2 -1
- package/src/api/admin/paypal/onboard-complete/route.ts +10 -2
- package/src/api/middlewares.ts +16 -1
- package/src/api/store/paypal/capture-order/route.ts +60 -22
- package/src/api/store/paypal/config/route.ts +8 -1
- package/src/api/store/paypal/onboard-return/route.ts +31 -6
- package/src/api/store/paypal/webhook/route.ts +24 -60
- package/src/api/utils/rate-limit.ts +105 -0
- package/src/jobs/paypal-webhook-retry.ts +132 -94
- package/src/modules/paypal/payment-provider/base-provider.ts +192 -0
- package/src/modules/paypal/payment-provider/card-service.ts +28 -196
- package/src/modules/paypal/payment-provider/service.ts +23 -164
- package/src/modules/paypal/utils/amounts.ts +10 -0
- package/src/modules/paypal/utils/credential-resolver.ts +32 -27
- package/src/modules/paypal/utils/partner.ts +8 -0
- package/src/modules/paypal/utils/payment-session.ts +44 -19
- package/src/modules/paypal/utils/secret-crypto.ts +36 -1
- package/src/subscribers/paypal-webhook-process.ts +127 -0
- package/.medusa/server/src/modules/paypal/clients/paypal-seller.client.d.ts +0 -15
- package/.medusa/server/src/modules/paypal/clients/paypal-seller.client.d.ts.map +0 -1
- package/.medusa/server/src/modules/paypal/clients/paypal-seller.client.js +0 -68
- package/.medusa/server/src/modules/paypal/clients/paypal-seller.client.js.map +0 -1
- package/src/modules/paypal/clients/paypal-seller.client.ts +0 -64
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export declare class PayPalSellerClient {
|
|
2
|
-
private opts;
|
|
3
|
-
private static readonly BN_CODE;
|
|
4
|
-
constructor(opts: {
|
|
5
|
-
environment: "sandbox" | "live";
|
|
6
|
-
accessToken: string;
|
|
7
|
-
});
|
|
8
|
-
private baseUrl;
|
|
9
|
-
private headers;
|
|
10
|
-
createOrder(body: any): Promise<any>;
|
|
11
|
-
getOrder(orderId: string): Promise<any>;
|
|
12
|
-
captureOrder(orderId: string): Promise<any>;
|
|
13
|
-
refundCapture(captureId: string, body?: any): Promise<any>;
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=paypal-seller.client.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"paypal-seller.client.d.ts","sourceRoot":"","sources":["../../../../../../src/modules/paypal/clients/paypal-seller.client.ts"],"names":[],"mappings":"AAEA,qBAAa,kBAAkB;IAGjB,OAAO,CAAC,IAAI;IAFxB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAyB;gBAEpC,IAAI,EAAE;QAAE,WAAW,EAAE,SAAS,GAAG,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE;IAElF,OAAO,CAAC,OAAO;IAMf,OAAO,CAAC,OAAO;IAST,WAAW,CAAC,IAAI,EAAE,GAAG;IAWrB,QAAQ,CAAC,OAAO,EAAE,MAAM;IAUxB,YAAY,CAAC,OAAO,EAAE,MAAM;IAU5B,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG;CAUlD"}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PayPalSellerClient = void 0;
|
|
4
|
-
const paypal_fetch_1 = require("../utils/paypal-fetch");
|
|
5
|
-
class PayPalSellerClient {
|
|
6
|
-
opts;
|
|
7
|
-
static BN_CODE = "MBJTechnolabs_SI_SPB";
|
|
8
|
-
constructor(opts) {
|
|
9
|
-
this.opts = opts;
|
|
10
|
-
}
|
|
11
|
-
baseUrl() {
|
|
12
|
-
return this.opts.environment === "live"
|
|
13
|
-
? "https://api-m.paypal.com"
|
|
14
|
-
: "https://api-m.sandbox.paypal.com";
|
|
15
|
-
}
|
|
16
|
-
headers(extra) {
|
|
17
|
-
return {
|
|
18
|
-
"Content-Type": "application/json",
|
|
19
|
-
Authorization: `Bearer ${this.opts.accessToken}`,
|
|
20
|
-
"PayPal-Partner-Attribution-Id": PayPalSellerClient.BN_CODE,
|
|
21
|
-
...(extra ?? {}),
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
async createOrder(body) {
|
|
25
|
-
const res = await (0, paypal_fetch_1.paypalFetch)(`${this.baseUrl()}/v2/checkout/orders`, {
|
|
26
|
-
method: "POST",
|
|
27
|
-
headers: this.headers(),
|
|
28
|
-
body: JSON.stringify(body),
|
|
29
|
-
});
|
|
30
|
-
const json = await res.json().catch(() => ({}));
|
|
31
|
-
if (!res.ok)
|
|
32
|
-
throw new Error(`PayPal createOrder failed (${res.status}): ${JSON.stringify(json)}`);
|
|
33
|
-
return json;
|
|
34
|
-
}
|
|
35
|
-
async getOrder(orderId) {
|
|
36
|
-
const res = await (0, paypal_fetch_1.paypalFetch)(`${this.baseUrl()}/v2/checkout/orders/${encodeURIComponent(orderId)}`, {
|
|
37
|
-
method: "GET",
|
|
38
|
-
headers: this.headers(),
|
|
39
|
-
});
|
|
40
|
-
const json = await res.json().catch(() => ({}));
|
|
41
|
-
if (!res.ok)
|
|
42
|
-
throw new Error(`PayPal getOrder failed (${res.status}): ${JSON.stringify(json)}`);
|
|
43
|
-
return json;
|
|
44
|
-
}
|
|
45
|
-
async captureOrder(orderId) {
|
|
46
|
-
const res = await (0, paypal_fetch_1.paypalFetch)(`${this.baseUrl()}/v2/checkout/orders/${encodeURIComponent(orderId)}/capture`, {
|
|
47
|
-
method: "POST",
|
|
48
|
-
headers: this.headers(),
|
|
49
|
-
});
|
|
50
|
-
const json = await res.json().catch(() => ({}));
|
|
51
|
-
if (!res.ok)
|
|
52
|
-
throw new Error(`PayPal captureOrder failed (${res.status}): ${JSON.stringify(json)}`);
|
|
53
|
-
return json;
|
|
54
|
-
}
|
|
55
|
-
async refundCapture(captureId, body) {
|
|
56
|
-
const res = await (0, paypal_fetch_1.paypalFetch)(`${this.baseUrl()}/v2/payments/captures/${encodeURIComponent(captureId)}/refund`, {
|
|
57
|
-
method: "POST",
|
|
58
|
-
headers: this.headers(),
|
|
59
|
-
body: body ? JSON.stringify(body) : "{}",
|
|
60
|
-
});
|
|
61
|
-
const json = await res.json().catch(() => ({}));
|
|
62
|
-
if (!res.ok)
|
|
63
|
-
throw new Error(`PayPal refund failed (${res.status}): ${JSON.stringify(json)}`);
|
|
64
|
-
return json;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
exports.PayPalSellerClient = PayPalSellerClient;
|
|
68
|
-
//# sourceMappingURL=paypal-seller.client.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"paypal-seller.client.js","sourceRoot":"","sources":["../../../../../../src/modules/paypal/clients/paypal-seller.client.ts"],"names":[],"mappings":";;;AAAA,wDAAmD;AAEnD,MAAa,kBAAkB;IAGT;IAFZ,MAAM,CAAU,OAAO,GAAG,sBAAsB,CAAA;IAExD,YAAoB,IAA8D;QAA9D,SAAI,GAAJ,IAAI,CAA0D;IAAG,CAAC;IAE9E,OAAO;QACb,OAAO,IAAI,CAAC,IAAI,CAAC,WAAW,KAAK,MAAM;YACrC,CAAC,CAAC,0BAA0B;YAC5B,CAAC,CAAC,kCAAkC,CAAA;IACxC,CAAC;IAEO,OAAO,CAAC,KAA8B;QAC5C,OAAO;YACL,cAAc,EAAE,kBAAkB;YAClC,aAAa,EAAE,UAAU,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;YAChD,+BAA+B,EAAE,kBAAkB,CAAC,OAAO;YAC3D,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC;SACjB,CAAA;IACH,CAAC;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-
export class PayPalSellerClient {
|
|
4
|
-
private static readonly BN_CODE = "MBJTechnolabs_SI_SPB"
|
|
5
|
-
|
|
6
|
-
constructor(private opts: { environment: "sandbox" | "live"; accessToken: string }) {}
|
|
7
|
-
|
|
8
|
-
private baseUrl() {
|
|
9
|
-
return this.opts.environment === "live"
|
|
10
|
-
? "https://api-m.paypal.com"
|
|
11
|
-
: "https://api-m.sandbox.paypal.com"
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
private headers(extra?: Record<string, string>) {
|
|
15
|
-
return {
|
|
16
|
-
"Content-Type": "application/json",
|
|
17
|
-
Authorization: `Bearer ${this.opts.accessToken}`,
|
|
18
|
-
"PayPal-Partner-Attribution-Id": PayPalSellerClient.BN_CODE,
|
|
19
|
-
...(extra ?? {}),
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
async createOrder(body: any) {
|
|
24
|
-
const res = await paypalFetch(`${this.baseUrl()}/v2/checkout/orders`, {
|
|
25
|
-
method: "POST",
|
|
26
|
-
headers: this.headers(),
|
|
27
|
-
body: JSON.stringify(body),
|
|
28
|
-
})
|
|
29
|
-
const json = await res.json().catch(() => ({}))
|
|
30
|
-
if (!res.ok) throw new Error(`PayPal createOrder failed (${res.status}): ${JSON.stringify(json)}`)
|
|
31
|
-
return json
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
async getOrder(orderId: string) {
|
|
35
|
-
const res = await paypalFetch(`${this.baseUrl()}/v2/checkout/orders/${encodeURIComponent(orderId)}`, {
|
|
36
|
-
method: "GET",
|
|
37
|
-
headers: this.headers(),
|
|
38
|
-
})
|
|
39
|
-
const json = await res.json().catch(() => ({}))
|
|
40
|
-
if (!res.ok) throw new Error(`PayPal getOrder failed (${res.status}): ${JSON.stringify(json)}`)
|
|
41
|
-
return json
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async captureOrder(orderId: string) {
|
|
45
|
-
const res = await paypalFetch(`${this.baseUrl()}/v2/checkout/orders/${encodeURIComponent(orderId)}/capture`, {
|
|
46
|
-
method: "POST",
|
|
47
|
-
headers: this.headers(),
|
|
48
|
-
})
|
|
49
|
-
const json = await res.json().catch(() => ({}))
|
|
50
|
-
if (!res.ok) throw new Error(`PayPal captureOrder failed (${res.status}): ${JSON.stringify(json)}`)
|
|
51
|
-
return json
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
async refundCapture(captureId: string, body?: any) {
|
|
55
|
-
const res = await paypalFetch(`${this.baseUrl()}/v2/payments/captures/${encodeURIComponent(captureId)}/refund`, {
|
|
56
|
-
method: "POST",
|
|
57
|
-
headers: this.headers(),
|
|
58
|
-
body: body ? JSON.stringify(body) : "{}",
|
|
59
|
-
})
|
|
60
|
-
const json = await res.json().catch(() => ({}))
|
|
61
|
-
if (!res.ok) throw new Error(`PayPal refund failed (${res.status}): ${JSON.stringify(json)}`)
|
|
62
|
-
return json
|
|
63
|
-
}
|
|
64
|
-
}
|