@unchainedshop/core-payment 2.0.0-beta8 → 2.0.0-beta9
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/jest.config.js +9 -0
- package/lib/db/PaymentProvidersSchema.js +0 -1
- package/lib/db/PaymentProvidersSchema.js.map +1 -1
- package/lib/director/PaymentDirector.js +3 -3
- package/lib/director/PaymentDirector.js.map +1 -1
- package/lib/director/PaymentPricingDirector.js +9 -9
- package/lib/director/PaymentPricingDirector.js.map +1 -1
- package/lib/module/configurePaymentCredentialsModule.js +0 -2
- package/lib/module/configurePaymentCredentialsModule.js.map +1 -1
- package/lib/module/configurePaymentModule.js +20 -2
- package/lib/module/configurePaymentModule.js.map +1 -1
- package/lib/module/configurePaymentProvidersModule.d.ts +5 -1
- package/lib/module/configurePaymentProvidersModule.js +36 -36
- package/lib/module/configurePaymentProvidersModule.js.map +1 -1
- package/lib/payment-index.d.ts +0 -1
- package/lib/payment-index.js +0 -1
- package/lib/payment-index.js.map +1 -1
- package/package.json +10 -9
- package/src/db/PaymentProvidersSchema.js +0 -1
- package/src/director/PaymentDirector.ts +3 -3
- package/src/director/PaymentPricingDirector.ts +9 -9
- package/src/module/configurePaymentCredentialsModule.ts +0 -2
- package/src/module/configurePaymentModule.ts +32 -2
- package/src/module/configurePaymentProvidersModule.ts +40 -44
- package/src/payment-index.ts +0 -1
- package/tests/payment-index.test.ts +12 -43
- package/lib/service/cancelService.d.ts +0 -2
- package/lib/service/cancelService.js +0 -13
- package/lib/service/cancelService.js.map +0 -1
- package/lib/service/chargeService.d.ts +0 -2
- package/lib/service/chargeService.js +0 -33
- package/lib/service/chargeService.js.map +0 -1
- package/lib/service/confirmService.d.ts +0 -2
- package/lib/service/confirmService.js +0 -13
- package/lib/service/confirmService.js.map +0 -1
- package/lib/service/paymentServices.d.ts +0 -2
- package/lib/service/paymentServices.js +0 -11
- package/lib/service/paymentServices.js.map +0 -1
- package/lib/service/registerPaymentCredentialsService.d.ts +0 -2
- package/lib/service/registerPaymentCredentialsService.js +0 -17
- package/lib/service/registerPaymentCredentialsService.js.map +0 -1
- package/src/service/cancelService.ts +0 -24
- package/src/service/chargeService.ts +0 -47
- package/src/service/confirmService.ts +0 -24
- package/src/service/paymentServices.ts +0 -12
- package/src/service/registerPaymentCredentialsService.ts +0 -28
package/jest.config.js
CHANGED
|
@@ -3,7 +3,6 @@ import SimpleSchema from 'simpl-schema';
|
|
|
3
3
|
export const PaymentProvidersSchema = new SimpleSchema({
|
|
4
4
|
type: { type: String, required: true },
|
|
5
5
|
adapterKey: { type: String, required: true },
|
|
6
|
-
authorId: { type: String, required: true },
|
|
7
6
|
configuration: { type: Array },
|
|
8
7
|
'configuration.$': { type: Object },
|
|
9
8
|
'configuration.$.key': { type: String },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PaymentProvidersSchema.js","sourceRoot":"","sources":["../../src/db/PaymentProvidersSchema.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,YAAY,MAAM,cAAc,CAAC;AAExC,MAAM,CAAC,MAAM,sBAAsB,GAAG,IAAI,YAAY,CACpD;IACE,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;IACtC,UAAU,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;IAC5C,
|
|
1
|
+
{"version":3,"file":"PaymentProvidersSchema.js","sourceRoot":"","sources":["../../src/db/PaymentProvidersSchema.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,YAAY,MAAM,cAAc,CAAC;AAExC,MAAM,CAAC,MAAM,sBAAsB,GAAG,IAAI,YAAY,CACpD;IACE,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;IACtC,UAAU,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;IAC5C,aAAa,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE;IAC9B,iBAAiB,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;IACnC,qBAAqB,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;IACvC,uBAAuB,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;IACzC,GAAG,OAAO,CAAC,eAAe;CAC3B,EACD,EAAE,iBAAiB,EAAE,KAAK,EAAE,CAC7B,CAAC"}
|
|
@@ -5,7 +5,7 @@ const logger = createLogger('unchained:core-payment');
|
|
|
5
5
|
const baseDirector = BaseDirector('PaymentDirector');
|
|
6
6
|
export const PaymentDirector = {
|
|
7
7
|
...baseDirector,
|
|
8
|
-
actions: async (paymentProvider, paymentContext,
|
|
8
|
+
actions: async (paymentProvider, paymentContext, unchainedAPI) => {
|
|
9
9
|
const Adapter = baseDirector.getAdapter(paymentProvider.adapterKey);
|
|
10
10
|
if (!Adapter) {
|
|
11
11
|
throw new Error(`Payment Plugin ${paymentProvider.adapterKey} not available`);
|
|
@@ -14,7 +14,7 @@ export const PaymentDirector = {
|
|
|
14
14
|
...paymentContext,
|
|
15
15
|
};
|
|
16
16
|
if (paymentContext?.orderPayment) {
|
|
17
|
-
const { modules } =
|
|
17
|
+
const { modules } = unchainedAPI;
|
|
18
18
|
const { orderId } = paymentContext.orderPayment;
|
|
19
19
|
const order = paymentContext?.order ||
|
|
20
20
|
(await modules.orders.findOrder({
|
|
@@ -29,7 +29,7 @@ export const PaymentDirector = {
|
|
|
29
29
|
paymentProviderId: paymentProvider._id,
|
|
30
30
|
...newPaymentContext,
|
|
31
31
|
},
|
|
32
|
-
context:
|
|
32
|
+
context: unchainedAPI,
|
|
33
33
|
});
|
|
34
34
|
return {
|
|
35
35
|
configurationError: () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PaymentDirector.js","sourceRoot":"","sources":["../../src/director/PaymentDirector.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,MAAM,MAAM,GAAG,YAAY,CAAC,wBAAwB,CAAC,CAAC;AACtD,MAAM,YAAY,GAAG,YAAY,CAAkB,iBAAiB,CAAC,CAAC;AAEtE,MAAM,CAAC,MAAM,eAAe,GAAqB;IAC/C,GAAG,YAAY;IAEf,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"PaymentDirector.js","sourceRoot":"","sources":["../../src/director/PaymentDirector.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,MAAM,MAAM,GAAG,YAAY,CAAC,wBAAwB,CAAC,CAAC;AACtD,MAAM,YAAY,GAAG,YAAY,CAAkB,iBAAiB,CAAC,CAAC;AAEtE,MAAM,CAAC,MAAM,eAAe,GAAqB;IAC/C,GAAG,YAAY;IAEf,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,YAAY,EAAE,EAAE;QAC/D,MAAM,OAAO,GAAG,YAAY,CAAC,UAAU,CAAC,eAAe,CAAC,UAAU,CAAoB,CAAC;QAEvF,IAAI,CAAC,OAAO,EAAE;YACZ,MAAM,IAAI,KAAK,CAAC,kBAAkB,eAAe,CAAC,UAAU,gBAAgB,CAAC,CAAC;SAC/E;QAED,MAAM,iBAAiB,GAAmB;YACxC,GAAG,cAAc;SAClB,CAAC;QAEF,IAAI,cAAc,EAAE,YAAY,EAAE;YAChC,MAAM,EAAE,OAAO,EAAE,GAAG,YAAY,CAA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gBACjB,OAAO,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC,kBAAkB,CAAC,CAAC;YAC3D,CAAC;YAED,QAAQ,EAAE,KAAK,IAAI,EAAE;gBACnB,OAAO,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC,kBAAkB,CAAC,CAAC;YAC7D,CAAC;YAED,IAAI,EAAE,KAAK,IAAI,EAAE;gBACf,OAAO,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,kBAAkB,CAAC,CAAC;YACzD,CAAC;YAED,QAAQ,EAAE,KAAK,IAAI,EAAE;gBACnB,MAAM,SAAS,GAAG,MAAM,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;gBAC/D,OAAO,CAAC,CAAC,SAAS,CAAC;YACrB,CAAC;YAED,MAAM,EAAE,KAAK,IAAI,EAAE;gBACjB,OAAO,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC,kBAAkB,CAAC,CAAC;YAC3D,CAAC;YAED,OAAO,EAAE,KAAK,IAAI,EAAE;gBAClB,OAAO,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,kBAAkB,CAAC,CAAC;YAC5D,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC"}
|
|
@@ -3,28 +3,28 @@ import { PaymentPricingSheet } from './PaymentPricingSheet';
|
|
|
3
3
|
const baseDirector = BasePricingDirector('PaymentPricingDirector');
|
|
4
4
|
export const PaymentPricingDirector = {
|
|
5
5
|
...baseDirector,
|
|
6
|
-
async buildPricingContext({ item, ...context },
|
|
6
|
+
async buildPricingContext({ item, ...context }, unchainedAPI) {
|
|
7
7
|
if (!item)
|
|
8
8
|
return {
|
|
9
9
|
discounts: [],
|
|
10
10
|
...context,
|
|
11
|
-
...
|
|
11
|
+
...unchainedAPI,
|
|
12
12
|
};
|
|
13
|
-
const order = await
|
|
13
|
+
const order = await unchainedAPI.modules.orders.findOrder({
|
|
14
14
|
orderId: item.orderId,
|
|
15
15
|
});
|
|
16
|
-
const provider = await
|
|
16
|
+
const provider = await unchainedAPI.modules.payment.paymentProviders.findProvider({
|
|
17
17
|
paymentProviderId: item.paymentProviderId,
|
|
18
18
|
});
|
|
19
|
-
const user = await
|
|
20
|
-
const discounts = await
|
|
19
|
+
const user = await unchainedAPI.modules.users.findUserById(order.userId);
|
|
20
|
+
const discounts = await unchainedAPI.modules.orders.discounts.findOrderDiscounts({
|
|
21
21
|
orderId: item.orderId,
|
|
22
22
|
});
|
|
23
23
|
return {
|
|
24
24
|
country: order.countryCode,
|
|
25
25
|
currency: order.currency,
|
|
26
26
|
...context,
|
|
27
|
-
...
|
|
27
|
+
...unchainedAPI,
|
|
28
28
|
order,
|
|
29
29
|
orderPayment: item,
|
|
30
30
|
provider,
|
|
@@ -32,8 +32,8 @@ export const PaymentPricingDirector = {
|
|
|
32
32
|
discounts,
|
|
33
33
|
};
|
|
34
34
|
},
|
|
35
|
-
async actions(pricingContext,
|
|
36
|
-
const actions = await baseDirector.actions(pricingContext,
|
|
35
|
+
async actions(pricingContext, unchainedAPI) {
|
|
36
|
+
const actions = await baseDirector.actions(pricingContext, unchainedAPI, this.buildPricingContext);
|
|
37
37
|
return {
|
|
38
38
|
...actions,
|
|
39
39
|
calculationSheet() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PaymentPricingDirector.js","sourceRoot":"","sources":["../../src/director/PaymentPricingDirector.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,MAAM,YAAY,GAAG,mBAAmB,CAKtC,wBAAwB,CAAC,CAAC;AAE5B,MAAM,CAAC,MAAM,sBAAsB,GAA4B;IAC7D,GAAG,YAAY;IAEf,KAAK,CAAC,mBAAmB,CAAC,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,EAAE,
|
|
1
|
+
{"version":3,"file":"PaymentPricingDirector.js","sourceRoot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AAC,OAAO,CAAC,cAAc,EAAE,YAAY;QACxC,MAAM,OAAO,GAAG,MAAM,YAAY,CAAC,OAAO,CAAC,cAAc,EAAE,YAAY,EAAE,IAAI,CAAC,mBAAmB,CAAC,CAAC;QACnG,OAAO;YACL,GAAG,OAAO;YACV,gBAAgB;gBACd,MAAM,OAAO,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;gBACrC,OAAO,mBAAmB,CAAC;oBACzB,WAAW,EAAE,OAAO,CAAC,cAAc,EAAE;oBACrC,QAAQ,EAAE,OAAO,CAAC,QAAQ;iBAC3B,CAAC,CAAC;YACL,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC"}
|
|
@@ -46,11 +46,9 @@ export const configurePaymentCredentialsModule = (PaymentCredentials) => {
|
|
|
46
46
|
paymentProviderId,
|
|
47
47
|
isPreferred: false,
|
|
48
48
|
created: new Date(),
|
|
49
|
-
createdBy: userId,
|
|
50
49
|
},
|
|
51
50
|
$set: {
|
|
52
51
|
updated: new Date(),
|
|
53
|
-
updatedBy: userId,
|
|
54
52
|
token,
|
|
55
53
|
meta,
|
|
56
54
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configurePaymentCredentialsModule.js","sourceRoot":"","sources":["../../src/module/configurePaymentCredentialsModule.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAEhF,MAAM,CAAC,MAAM,iCAAiC,GAAG,CAC/C,kBAAsD,EACjB,EAAE;IACvC,MAAM,aAAa,GAAG,KAAK,EAAE,EAAE,MAAM,EAAE,oBAAoB,EAAE,EAAE,EAAE;QAC/D,MAAM,kBAAkB,CAAC,SAAS,CAChC;YACE,GAAG,EAAE,oBAAoB;SAC1B,EACD;YACE,IAAI,EAAE;gBACJ,WAAW,EAAE,IAAI;aAClB;SACF,CACF,CAAC;QACF,MAAM,kBAAkB,CAAC,UAAU,CACjC;YACE,GAAG,EAAE,E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B;iBAClB,EACL;gBACE,YAAY,EAAE;oBACZ,GAAG,EAAE,UAAU;oBACf,MAAM;oBACN,iBAAiB;oBACjB,WAAW,EAAE,KAAK;oBAClB,OAAO,EAAE,IAAI,IAAI,EAAE;
|
|
1
|
+
{"version":3,"file":"configurePaymentCredentialsModule.js","sourceRoot":"","sources":["../../src/module/configurePaymentCredentialsModule.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAEhF,MAAM,CAAC,MAAM,iCAAiC,GAAG,CAC/C,kBAAsD,EACjB,EAAE;IACvC,MAAM,aAAa,GAAG,KAAK,EAAE,EAAE,MAAM,EAAE,oBAAoB,EAAE,EAAE,EAAE;QAC/D,MAAM,kBAAkB,CAAC,SAAS,CAChC;YACE,GAAG,EAAE,oBAAoB;SAC1B,EACD;YACE,IAAI,EAAE;gBACJ,WAAW,EAAE,IAAI;aAClB;SACF,CACF,CAAC;QACF,MAAM,kBAAkB,CAAC,UAAU,CACjC;YACE,GAAG,EAAE,EAAE,GAAG,EAAE,oBAAoB,EAAE;YAClC,MAAM;SACP,EACD;YACE,IAAI,EAAE;gBACJ,WAAW,EAAE,KAAK;aACnB;SACF,CACF,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO;QACL,aAAa;QAEb,iBAAiB,EAAE,KAAK,EAAE,EAAE,oBAAoB,EAAE,EAAE,EAAE;YACpD,MAAM,gBAAgB,GAAG,MAAM,kBAAkB,CAAC,cAAc,CAC9D,oBAAoB,CAAC,oBAAoB,CAAC,EAC1C,EAAE,KAAK,EAAE,CAAC,EAAE,CACb,CAAC;YACF,OAAO,CAAC,CAAC,gBAAgB,CAAC;QAC5B,CAAC;QAED,qBAAqB,EAAE,KAAK,EAAE,EAAE,oBAAoB,EAAE,MAAM,EAAE,iBAAiB,EAAE,EAAE,OAAO,EAAE,EAAE;YAC5F,OAAO,kBAAkB,CAAC,OAAO,CAC/B,oBAAoB;gBAClB,CA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,CAAC,oBAAoB,CAAC,CAAC;YAC5D,MAAM,kBAAkB,GAAG,MAAM,kBAAkB,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;YAC1E,MAAM,kBAAkB,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;YAC7C,OAAO,kBAAkB,CAAC;QAC5B,CAAC;KACF,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -7,9 +7,27 @@ export const configurePaymentModule = async ({ db, options: paymentOptions = {},
|
|
|
7
7
|
const PaymentProviders = await PaymentProvidersCollection(db);
|
|
8
8
|
const PaymentCredentials = await PaymentCredentialsCollection(db);
|
|
9
9
|
paymentSettings.configureSettings(paymentOptions);
|
|
10
|
+
const paymentProviders = configurePaymentProvidersModule(PaymentProviders);
|
|
11
|
+
const paymentCredentials = configurePaymentCredentialsModule(PaymentCredentials);
|
|
12
|
+
const registerCredentials = async (paymentProviderId, paymentContext, unchainedAPI) => {
|
|
13
|
+
const registration = await paymentProviders.register(paymentProviderId, paymentContext, unchainedAPI);
|
|
14
|
+
if (!registration)
|
|
15
|
+
return null;
|
|
16
|
+
const paymentCredentialsId = await paymentCredentials.upsertCredentials({
|
|
17
|
+
userId: paymentContext.userId,
|
|
18
|
+
paymentProviderId,
|
|
19
|
+
...registration,
|
|
20
|
+
});
|
|
21
|
+
return paymentCredentials.findPaymentCredential({
|
|
22
|
+
paymentCredentialsId,
|
|
23
|
+
userId: paymentContext.userId,
|
|
24
|
+
paymentProviderId,
|
|
25
|
+
});
|
|
26
|
+
};
|
|
10
27
|
return {
|
|
11
|
-
paymentProviders
|
|
12
|
-
paymentCredentials
|
|
28
|
+
paymentProviders,
|
|
29
|
+
paymentCredentials,
|
|
30
|
+
registerCredentials,
|
|
13
31
|
};
|
|
14
32
|
};
|
|
15
33
|
//# sourceMappingURL=configurePaymentModule.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configurePaymentModule.js","sourceRoot":"","sources":["../../src/module/configurePaymentModule.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,4BAA4B,EAAE,MAAM,oCAAoC,CAAC;AAClF,OAAO,EAAE,0BAA0B,EAAE,MAAM,kCAAkC,CAAC;AAC9E,OAAO,EAAE,iCAAiC,EAAE,MAAM,qCAAqC,CAAC;AACxF,OAAO,EAAE,+BAA+B,EAAE,MAAM,mCAAmC,CAAC;AACpF,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,MAAM,CAAC,MAAM,sBAAsB,GAAG,KAAK,EAAE,EAC3C,EAAE,EACF,OAAO,EAAE,cAAc,GAAG,EAAE,GACQ,EAA0B,EAAE;IAChE,MAAM,gBAAgB,GAAG,MAAM,0BAA0B,CAAC,EAAE,CAAC,CAAC;IAC9D,MAAM,kBAAkB,GAAG,MAAM,4BAA4B,CAAC,EAAE,CAAC,CAAC;IAElE,eAAe,CAAC,iBAAiB,CAAC,cAAc,CAAC,CAAC;IAElD,
|
|
1
|
+
{"version":3,"file":"configurePaymentModule.js","sourceRoot":"","sources":["../../src/module/configurePaymentModule.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,4BAA4B,EAAE,MAAM,oCAAoC,CAAC;AAClF,OAAO,EAAE,0BAA0B,EAAE,MAAM,kCAAkC,CAAC;AAC9E,OAAO,EAAE,iCAAiC,EAAE,MAAM,qCAAqC,CAAC;AACxF,OAAO,EAAE,+BAA+B,EAAE,MAAM,mCAAmC,CAAC;AACpF,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,MAAM,CAAC,MAAM,sBAAsB,GAAG,KAAK,EAAE,EAC3C,EAAE,EACF,OAAO,EAAE,cAAc,GAAG,EAAE,GACQ,EAA0B,EAAE;IAChE,MAAM,gBAAgB,GAAG,MAAM,0BAA0B,CAAC,EAAE,CAAC,CAAC;IAC9D,MAAM,kBAAkB,GAAG,MAAM,4BAA4B,CAAC,EAAE,CAAC,CAAC;IAElE,eAAe,CAAC,iBAAiB,CAAC,cAAc,CAAC,CAAC;IAElD,MAAM,gBAAgB,GAAG,+BAA+B,CAAC,gBAAgB,CAAC,CAAC;IAC3E,MAAM,kBAAkB,GAAG,iCAAiC,CAAC,kBAAkB,CAAC,CAAC;IAEjF,MAAM,mBAAmB,GAAyC,KAAK,EACrE,iBAAiB,EACjB,cAAc,EACd,YAAY,EACZ,EAAE;QACF,MAAM,YAAY,GAAG,MAAM,gBAAgB,CAAC,QAAQ,CAClD,iBAAiB,EACjB,cAAc,EACd,YAAY,CACb,CAAC;QAEF,IAAI,CAAC,YAAY;YAAE,OAAO,IAAI,CAAC;QAE/B,MAAM,oBAAoB,GAAG,MAAM,kBAAkB,CAAC,iBAAiB,CAAC;YACtE,MAAM,EAAE,cAAc,CAAC,MAAM;YAC7B,iBAAiB;YACjB,GAAG,YAAY;SAChB,CAAC,CAAC;QAEH,OAAO,kBAAkB,CAAC,qBAAqB,CAAC;YAC9C,oBAAoB;YACpB,MAAM,EAAE,cAAc,CAAC,MAAM;YAC7B,iBAAiB;SAClB,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,OAAO;QACL,gBAAgB;QAChB,kBAAkB;QAClB,mBAAmB;KACpB,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import { Collection } from '@unchainedshop/types/common';
|
|
2
|
-
import { PaymentModule, PaymentProvider } from '@unchainedshop/types/payments';
|
|
2
|
+
import { PaymentModule, PaymentProvider, PaymentProviderQuery } from '@unchainedshop/types/payments';
|
|
3
|
+
export declare const buildFindSelector: ({ type }?: PaymentProviderQuery) => {
|
|
4
|
+
deleted: any;
|
|
5
|
+
type?: import("@unchainedshop/types/payments").PaymentProviderType;
|
|
6
|
+
};
|
|
3
7
|
export declare const configurePaymentProvidersModule: (PaymentProviders: Collection<PaymentProvider>) => PaymentModule['paymentProviders'];
|
|
@@ -10,7 +10,7 @@ const PAYMENT_PROVIDER_EVENTS = [
|
|
|
10
10
|
'PAYMENT_PROVIDER_UPDATE',
|
|
11
11
|
'PAYMENT_PROVIDER_REMOVE',
|
|
12
12
|
];
|
|
13
|
-
const buildFindSelector = ({ type } = {}) => {
|
|
13
|
+
export const buildFindSelector = ({ type } = {}) => {
|
|
14
14
|
return { ...(type ? { type } : {}), deleted: null };
|
|
15
15
|
};
|
|
16
16
|
const asyncFilter = async (arr, predicate) => {
|
|
@@ -20,9 +20,9 @@ const asyncFilter = async (arr, predicate) => {
|
|
|
20
20
|
export const configurePaymentProvidersModule = (PaymentProviders) => {
|
|
21
21
|
registerEvents(PAYMENT_PROVIDER_EVENTS);
|
|
22
22
|
const mutations = generateDbMutations(PaymentProviders, PaymentProvidersSchema);
|
|
23
|
-
const getPaymentAdapter = async (paymentProviderId, paymentContext,
|
|
23
|
+
const getPaymentAdapter = async (paymentProviderId, paymentContext, unchainedAPI) => {
|
|
24
24
|
const provider = await PaymentProviders.findOne(generateDbFilterById(paymentProviderId), {});
|
|
25
|
-
return PaymentDirector.actions(provider, paymentContext,
|
|
25
|
+
return PaymentDirector.actions(provider, paymentContext, unchainedAPI);
|
|
26
26
|
};
|
|
27
27
|
return {
|
|
28
28
|
// Queries
|
|
@@ -63,11 +63,11 @@ export const configurePaymentProvidersModule = (PaymentProviders) => {
|
|
|
63
63
|
version: Adapter.version,
|
|
64
64
|
}));
|
|
65
65
|
},
|
|
66
|
-
findSupported: async (paymentContext,
|
|
66
|
+
findSupported: async (paymentContext, unchainedAPI) => {
|
|
67
67
|
const allProviders = await PaymentProviders.find({ deleted: null }).toArray();
|
|
68
68
|
const providers = await asyncFilter(allProviders, async (provider) => {
|
|
69
69
|
try {
|
|
70
|
-
const director = await PaymentDirector.actions(provider, paymentContext,
|
|
70
|
+
const director = await PaymentDirector.actions(provider, paymentContext, unchainedAPI);
|
|
71
71
|
return director.isActive();
|
|
72
72
|
}
|
|
73
73
|
catch {
|
|
@@ -77,83 +77,83 @@ export const configurePaymentProvidersModule = (PaymentProviders) => {
|
|
|
77
77
|
return paymentSettings.filterSupportedProviders({
|
|
78
78
|
providers,
|
|
79
79
|
order: paymentContext.order,
|
|
80
|
-
},
|
|
80
|
+
}, unchainedAPI);
|
|
81
81
|
},
|
|
82
|
-
determineDefault: async (paymentProviders, deliveryContext,
|
|
82
|
+
determineDefault: async (paymentProviders, deliveryContext, unchainedAPI) => {
|
|
83
83
|
return paymentSettings.determineDefaultProvider({
|
|
84
84
|
providers: paymentProviders,
|
|
85
85
|
...deliveryContext,
|
|
86
|
-
},
|
|
86
|
+
}, unchainedAPI);
|
|
87
87
|
},
|
|
88
88
|
// Payment Adapter
|
|
89
|
-
configurationError: async (paymentProvider,
|
|
90
|
-
const actions = await PaymentDirector.actions(paymentProvider, {},
|
|
89
|
+
configurationError: async (paymentProvider, unchainedAPI) => {
|
|
90
|
+
const actions = await PaymentDirector.actions(paymentProvider, {}, unchainedAPI);
|
|
91
91
|
return actions.configurationError();
|
|
92
92
|
},
|
|
93
|
-
calculate: async (pricingContext,
|
|
94
|
-
const pricing = await PaymentPricingDirector.actions(pricingContext,
|
|
93
|
+
calculate: async (pricingContext, unchainedAPI) => {
|
|
94
|
+
const pricing = await PaymentPricingDirector.actions(pricingContext, unchainedAPI);
|
|
95
95
|
return pricing.calculate();
|
|
96
96
|
},
|
|
97
|
-
isActive: async (paymentProvider,
|
|
98
|
-
const actions = await PaymentDirector.actions(paymentProvider, {},
|
|
97
|
+
isActive: async (paymentProvider, unchainedAPI) => {
|
|
98
|
+
const actions = await PaymentDirector.actions(paymentProvider, {}, unchainedAPI);
|
|
99
99
|
return actions.isActive();
|
|
100
100
|
},
|
|
101
|
-
isPayLaterAllowed: async (paymentProvider,
|
|
102
|
-
const actions = await PaymentDirector.actions(paymentProvider, {},
|
|
101
|
+
isPayLaterAllowed: async (paymentProvider, unchainedAPI) => {
|
|
102
|
+
const actions = await PaymentDirector.actions(paymentProvider, {}, unchainedAPI);
|
|
103
103
|
return actions.isPayLaterAllowed();
|
|
104
104
|
},
|
|
105
|
-
charge: async (paymentProviderId, paymentContext,
|
|
106
|
-
const adapter = await getPaymentAdapter(paymentProviderId, paymentContext,
|
|
105
|
+
charge: async (paymentProviderId, paymentContext, unchainedAPI) => {
|
|
106
|
+
const adapter = await getPaymentAdapter(paymentProviderId, paymentContext, unchainedAPI);
|
|
107
107
|
return adapter.charge();
|
|
108
108
|
},
|
|
109
|
-
register: async (paymentProviderId, paymentContext,
|
|
110
|
-
const adapter = await getPaymentAdapter(paymentProviderId, paymentContext,
|
|
109
|
+
register: async (paymentProviderId, paymentContext, unchainedAPI) => {
|
|
110
|
+
const adapter = await getPaymentAdapter(paymentProviderId, paymentContext, unchainedAPI);
|
|
111
111
|
return adapter.register();
|
|
112
112
|
},
|
|
113
|
-
sign: async (paymentProviderId, paymentContext,
|
|
114
|
-
const adapter = await getPaymentAdapter(paymentProviderId, paymentContext,
|
|
113
|
+
sign: async (paymentProviderId, paymentContext, unchainedAPI) => {
|
|
114
|
+
const adapter = await getPaymentAdapter(paymentProviderId, paymentContext, unchainedAPI);
|
|
115
115
|
return adapter.sign();
|
|
116
116
|
},
|
|
117
|
-
validate: async (paymentProviderId, paymentContext,
|
|
118
|
-
const adapter = await getPaymentAdapter(paymentProviderId, paymentContext,
|
|
117
|
+
validate: async (paymentProviderId, paymentContext, unchainedAPI) => {
|
|
118
|
+
const adapter = await getPaymentAdapter(paymentProviderId, paymentContext, unchainedAPI);
|
|
119
119
|
return adapter.validate();
|
|
120
120
|
},
|
|
121
|
-
cancel: async (paymentProviderId, paymentContext,
|
|
122
|
-
const adapter = await getPaymentAdapter(paymentProviderId, paymentContext,
|
|
121
|
+
cancel: async (paymentProviderId, paymentContext, unchainedAPI) => {
|
|
122
|
+
const adapter = await getPaymentAdapter(paymentProviderId, paymentContext, unchainedAPI);
|
|
123
123
|
return adapter.cancel();
|
|
124
124
|
},
|
|
125
|
-
confirm: async (paymentProviderId, paymentContext,
|
|
126
|
-
const adapter = await getPaymentAdapter(paymentProviderId, paymentContext,
|
|
125
|
+
confirm: async (paymentProviderId, paymentContext, unchainedAPI) => {
|
|
126
|
+
const adapter = await getPaymentAdapter(paymentProviderId, paymentContext, unchainedAPI);
|
|
127
127
|
return adapter.confirm();
|
|
128
128
|
},
|
|
129
129
|
// Mutations
|
|
130
|
-
create: async (doc
|
|
130
|
+
create: async (doc) => {
|
|
131
131
|
const Adapter = PaymentDirector.getAdapter(doc.adapterKey);
|
|
132
132
|
if (!Adapter)
|
|
133
133
|
return null;
|
|
134
134
|
const paymentProviderId = await mutations.create({
|
|
135
135
|
configuration: Adapter.initialConfiguration,
|
|
136
136
|
...doc,
|
|
137
|
-
}
|
|
137
|
+
});
|
|
138
138
|
const paymentProvider = await PaymentProviders.findOne(generateDbFilterById(paymentProviderId), {});
|
|
139
139
|
await emit('PAYMENT_PROVIDER_CREATE', { paymentProvider });
|
|
140
140
|
return paymentProvider;
|
|
141
141
|
},
|
|
142
|
-
update: async (_id, doc
|
|
143
|
-
await mutations.update(_id, doc
|
|
142
|
+
update: async (_id, doc) => {
|
|
143
|
+
await mutations.update(_id, doc);
|
|
144
144
|
const paymentProvider = await PaymentProviders.findOne(generateDbFilterById(_id), {});
|
|
145
145
|
await emit('PAYMENT_PROVIDER_UPDATE', { paymentProvider });
|
|
146
146
|
return paymentProvider;
|
|
147
147
|
},
|
|
148
|
-
delete: async (_id
|
|
149
|
-
await mutations.delete(_id
|
|
148
|
+
delete: async (_id) => {
|
|
149
|
+
await mutations.delete(_id);
|
|
150
150
|
const paymentProvider = await PaymentProviders.findOne(generateDbFilterById(_id), {});
|
|
151
151
|
await emit('PAYMENT_PROVIDER_REMOVE', { paymentProvider });
|
|
152
152
|
return paymentProvider;
|
|
153
153
|
},
|
|
154
|
-
deletePermanently: async (_id
|
|
154
|
+
deletePermanently: async (_id) => {
|
|
155
155
|
const deliveryProvider = await PaymentProviders.findOne(generateDbFilterById(_id), {});
|
|
156
|
-
await mutations.deletePermanently(_id
|
|
156
|
+
await mutations.deletePermanently(_id);
|
|
157
157
|
return deliveryProvider;
|
|
158
158
|
},
|
|
159
159
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configurePaymentProvidersModule.js","sourceRoot":"","sources":["../../src/module/configurePaymentProvidersModule.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"configurePaymentProvidersModule.js","sourceRoot":"","sources":["../../src/module/configurePaymentProvidersModule.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AACjF,OAAO,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AAC5E,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,MAAM,uBAAuB,GAAa;IACxC,yBAAyB;IACzB,yBAAyB;IACzB,yBAAyB;CAC1B,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,EAAE,IAAI,KAA2B,EAAE,EAAE,EAAE;IACvE,OAAO,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AACtD,CAAC,CAAC;AAEF,MAAM,WAAW,GAAG,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE;IAC3C,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC;IAEtD,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CA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,EAAE;YACpB,MAAM,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAC5B,MAAM,eAAe,GAAG,MAAM,gBAAgB,CAAC,OAAO,CAAC,oBAAoB,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC;YACtF,MAAM,IAAI,CAAC,yBAAyB,EAAE,EAAE,eAAe,EAAE,CAAC,CAAC;YAC3D,OAAO,eAAe,CAAC;QACzB,CAAC;QAED,iBAAiB,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;YAC/B,MAAM,gBAAgB,GAAG,MAAM,gBAAgB,CAAC,OAAO,CAAC,oBAAoB,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC;YACvF,MAAM,SAAS,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC;YACvC,OAAO,gBAAgB,CAAC;QAC1B,CAAC;KACF,CAAC;AACJ,CAAC,CAAC"}
|
package/lib/payment-index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export { configurePaymentModule } from './module/configurePaymentModule';
|
|
2
|
-
export { paymentServices } from './service/paymentServices';
|
|
3
2
|
export { paymentSettings } from './payment-settings';
|
|
4
3
|
export { PaymentDirector } from './director/PaymentDirector';
|
|
5
4
|
export { PaymentAdapter } from './director/PaymentAdapter';
|
package/lib/payment-index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export { configurePaymentModule } from './module/configurePaymentModule';
|
|
2
|
-
export { paymentServices } from './service/paymentServices';
|
|
3
2
|
export { paymentSettings } from './payment-settings';
|
|
4
3
|
export { PaymentDirector } from './director/PaymentDirector';
|
|
5
4
|
export { PaymentAdapter } from './director/PaymentAdapter';
|
package/lib/payment-index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"payment-index.js","sourceRoot":"","sources":["../src/payment-index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAEzE,OAAO,EAAE,eAAe,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"payment-index.js","sourceRoot":"","sources":["../src/payment-index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAEzE,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAErE,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AACzE,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/core-payment",
|
|
3
|
-
"version": "2.0.0-
|
|
3
|
+
"version": "2.0.0-beta9",
|
|
4
4
|
"main": "lib/payment-index.js",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./lib/payment-index.js",
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"clean": "rm -rf lib",
|
|
13
13
|
"build": "npm run clean && tsc",
|
|
14
14
|
"watch": "tsc -w",
|
|
15
|
-
"test": "jest --
|
|
15
|
+
"test": "NODE_OPTIONS=--experimental-vm-modules jest --detectOpenHandles --forceExit",
|
|
16
|
+
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch --detectOpenHandles --forceExit"
|
|
16
17
|
},
|
|
17
18
|
"repository": {
|
|
18
19
|
"type": "git",
|
|
@@ -30,16 +31,16 @@
|
|
|
30
31
|
},
|
|
31
32
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
32
33
|
"dependencies": {
|
|
33
|
-
"@unchainedshop/events": "^2.0.0-
|
|
34
|
-
"@unchainedshop/logger": "^2.0.0-
|
|
35
|
-
"@unchainedshop/utils": "^2.0.0-
|
|
36
|
-
"simpl-schema": "^3.0
|
|
34
|
+
"@unchainedshop/events": "^2.0.0-beta9",
|
|
35
|
+
"@unchainedshop/logger": "^2.0.0-beta9",
|
|
36
|
+
"@unchainedshop/utils": "^2.0.0-beta9",
|
|
37
|
+
"simpl-schema": "^3.2.0"
|
|
37
38
|
},
|
|
38
39
|
"devDependencies": {
|
|
39
|
-
"@types/node": "^18.11.
|
|
40
|
-
"@unchainedshop/types": "^2.0.0-
|
|
40
|
+
"@types/node": "^18.11.12",
|
|
41
|
+
"@unchainedshop/types": "^2.0.0-beta9",
|
|
41
42
|
"jest": "^29.3.1",
|
|
42
43
|
"ts-jest": "^29.0.3",
|
|
43
|
-
"typescript": "^4.9.
|
|
44
|
+
"typescript": "^4.9.4"
|
|
44
45
|
}
|
|
45
46
|
}
|
|
@@ -5,7 +5,6 @@ export const PaymentProvidersSchema = new SimpleSchema(
|
|
|
5
5
|
{
|
|
6
6
|
type: { type: String, required: true },
|
|
7
7
|
adapterKey: { type: String, required: true },
|
|
8
|
-
authorId: { type: String, required: true },
|
|
9
8
|
configuration: { type: Array },
|
|
10
9
|
'configuration.$': { type: Object },
|
|
11
10
|
'configuration.$.key': { type: String },
|
|
@@ -9,7 +9,7 @@ const baseDirector = BaseDirector<IPaymentAdapter>('PaymentDirector');
|
|
|
9
9
|
export const PaymentDirector: IPaymentDirector = {
|
|
10
10
|
...baseDirector,
|
|
11
11
|
|
|
12
|
-
actions: async (paymentProvider, paymentContext,
|
|
12
|
+
actions: async (paymentProvider, paymentContext, unchainedAPI) => {
|
|
13
13
|
const Adapter = baseDirector.getAdapter(paymentProvider.adapterKey) as IPaymentAdapter;
|
|
14
14
|
|
|
15
15
|
if (!Adapter) {
|
|
@@ -21,7 +21,7 @@ export const PaymentDirector: IPaymentDirector = {
|
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
if (paymentContext?.orderPayment) {
|
|
24
|
-
const { modules } =
|
|
24
|
+
const { modules } = unchainedAPI;
|
|
25
25
|
const { orderId } = paymentContext.orderPayment;
|
|
26
26
|
const order =
|
|
27
27
|
paymentContext?.order ||
|
|
@@ -39,7 +39,7 @@ export const PaymentDirector: IPaymentDirector = {
|
|
|
39
39
|
paymentProviderId: paymentProvider._id,
|
|
40
40
|
...newPaymentContext,
|
|
41
41
|
},
|
|
42
|
-
context:
|
|
42
|
+
context: unchainedAPI,
|
|
43
43
|
});
|
|
44
44
|
|
|
45
45
|
return {
|
|
@@ -18,22 +18,22 @@ const baseDirector = BasePricingDirector<
|
|
|
18
18
|
export const PaymentPricingDirector: IPaymentPricingDirector = {
|
|
19
19
|
...baseDirector,
|
|
20
20
|
|
|
21
|
-
async buildPricingContext({ item, ...context },
|
|
21
|
+
async buildPricingContext({ item, ...context }, unchainedAPI) {
|
|
22
22
|
if (!item)
|
|
23
23
|
return {
|
|
24
24
|
discounts: [],
|
|
25
25
|
...context,
|
|
26
|
-
...
|
|
26
|
+
...unchainedAPI,
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
-
const order = await
|
|
29
|
+
const order = await unchainedAPI.modules.orders.findOrder({
|
|
30
30
|
orderId: item.orderId,
|
|
31
31
|
});
|
|
32
|
-
const provider = await
|
|
32
|
+
const provider = await unchainedAPI.modules.payment.paymentProviders.findProvider({
|
|
33
33
|
paymentProviderId: item.paymentProviderId,
|
|
34
34
|
});
|
|
35
|
-
const user = await
|
|
36
|
-
const discounts = await
|
|
35
|
+
const user = await unchainedAPI.modules.users.findUserById(order.userId);
|
|
36
|
+
const discounts = await unchainedAPI.modules.orders.discounts.findOrderDiscounts({
|
|
37
37
|
orderId: item.orderId,
|
|
38
38
|
});
|
|
39
39
|
|
|
@@ -41,7 +41,7 @@ export const PaymentPricingDirector: IPaymentPricingDirector = {
|
|
|
41
41
|
country: order.countryCode,
|
|
42
42
|
currency: order.currency,
|
|
43
43
|
...context,
|
|
44
|
-
...
|
|
44
|
+
...unchainedAPI,
|
|
45
45
|
order,
|
|
46
46
|
orderPayment: item,
|
|
47
47
|
provider,
|
|
@@ -50,8 +50,8 @@ export const PaymentPricingDirector: IPaymentPricingDirector = {
|
|
|
50
50
|
};
|
|
51
51
|
},
|
|
52
52
|
|
|
53
|
-
async actions(pricingContext,
|
|
54
|
-
const actions = await baseDirector.actions(pricingContext,
|
|
53
|
+
async actions(pricingContext, unchainedAPI) {
|
|
54
|
+
const actions = await baseDirector.actions(pricingContext, unchainedAPI, this.buildPricingContext);
|
|
55
55
|
return {
|
|
56
56
|
...actions,
|
|
57
57
|
calculationSheet() {
|
|
@@ -15,8 +15,38 @@ export const configurePaymentModule = async ({
|
|
|
15
15
|
|
|
16
16
|
paymentSettings.configureSettings(paymentOptions);
|
|
17
17
|
|
|
18
|
+
const paymentProviders = configurePaymentProvidersModule(PaymentProviders);
|
|
19
|
+
const paymentCredentials = configurePaymentCredentialsModule(PaymentCredentials);
|
|
20
|
+
|
|
21
|
+
const registerCredentials: PaymentModule['registerCredentials'] = async (
|
|
22
|
+
paymentProviderId,
|
|
23
|
+
paymentContext,
|
|
24
|
+
unchainedAPI,
|
|
25
|
+
) => {
|
|
26
|
+
const registration = await paymentProviders.register(
|
|
27
|
+
paymentProviderId,
|
|
28
|
+
paymentContext,
|
|
29
|
+
unchainedAPI,
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
if (!registration) return null;
|
|
33
|
+
|
|
34
|
+
const paymentCredentialsId = await paymentCredentials.upsertCredentials({
|
|
35
|
+
userId: paymentContext.userId,
|
|
36
|
+
paymentProviderId,
|
|
37
|
+
...registration,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
return paymentCredentials.findPaymentCredential({
|
|
41
|
+
paymentCredentialsId,
|
|
42
|
+
userId: paymentContext.userId,
|
|
43
|
+
paymentProviderId,
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
|
|
18
47
|
return {
|
|
19
|
-
paymentProviders
|
|
20
|
-
paymentCredentials
|
|
48
|
+
paymentProviders,
|
|
49
|
+
paymentCredentials,
|
|
50
|
+
registerCredentials,
|
|
21
51
|
};
|
|
22
52
|
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { Context } from '@unchainedshop/types/api';
|
|
2
1
|
import { Collection } from '@unchainedshop/types/common';
|
|
3
|
-
import { ModuleMutations } from '@unchainedshop/types/core';
|
|
2
|
+
import { ModuleMutations, UnchainedCore } from '@unchainedshop/types/core';
|
|
4
3
|
import {
|
|
5
4
|
PaymentContext,
|
|
6
5
|
PaymentModule,
|
|
@@ -21,7 +20,7 @@ const PAYMENT_PROVIDER_EVENTS: string[] = [
|
|
|
21
20
|
'PAYMENT_PROVIDER_REMOVE',
|
|
22
21
|
];
|
|
23
22
|
|
|
24
|
-
const buildFindSelector = ({ type }: PaymentProviderQuery = {}) => {
|
|
23
|
+
export const buildFindSelector = ({ type }: PaymentProviderQuery = {}) => {
|
|
25
24
|
return { ...(type ? { type } : {}), deleted: null };
|
|
26
25
|
};
|
|
27
26
|
|
|
@@ -44,11 +43,11 @@ export const configurePaymentProvidersModule = (
|
|
|
44
43
|
const getPaymentAdapter = async (
|
|
45
44
|
paymentProviderId: string,
|
|
46
45
|
paymentContext: PaymentContext,
|
|
47
|
-
|
|
46
|
+
unchainedAPI: UnchainedCore,
|
|
48
47
|
) => {
|
|
49
48
|
const provider = await PaymentProviders.findOne(generateDbFilterById(paymentProviderId), {});
|
|
50
49
|
|
|
51
|
-
return PaymentDirector.actions(provider, paymentContext,
|
|
50
|
+
return PaymentDirector.actions(provider, paymentContext, unchainedAPI);
|
|
52
51
|
};
|
|
53
52
|
|
|
54
53
|
return {
|
|
@@ -102,13 +101,13 @@ export const configurePaymentProvidersModule = (
|
|
|
102
101
|
}));
|
|
103
102
|
},
|
|
104
103
|
|
|
105
|
-
findSupported: async (paymentContext,
|
|
104
|
+
findSupported: async (paymentContext, unchainedAPI) => {
|
|
106
105
|
const allProviders = await PaymentProviders.find({ deleted: null }).toArray();
|
|
107
106
|
const providers: PaymentProvider[] = await asyncFilter(
|
|
108
107
|
allProviders,
|
|
109
108
|
async (provider: PaymentProvider) => {
|
|
110
109
|
try {
|
|
111
|
-
const director = await PaymentDirector.actions(provider, paymentContext,
|
|
110
|
+
const director = await PaymentDirector.actions(provider, paymentContext, unchainedAPI);
|
|
112
111
|
return director.isActive();
|
|
113
112
|
} catch {
|
|
114
113
|
return false;
|
|
@@ -121,84 +120,81 @@ export const configurePaymentProvidersModule = (
|
|
|
121
120
|
providers,
|
|
122
121
|
order: paymentContext.order,
|
|
123
122
|
},
|
|
124
|
-
|
|
123
|
+
unchainedAPI,
|
|
125
124
|
);
|
|
126
125
|
},
|
|
127
126
|
|
|
128
|
-
determineDefault: async (paymentProviders, deliveryContext,
|
|
127
|
+
determineDefault: async (paymentProviders, deliveryContext, unchainedAPI) => {
|
|
129
128
|
return paymentSettings.determineDefaultProvider(
|
|
130
129
|
{
|
|
131
130
|
providers: paymentProviders,
|
|
132
131
|
...deliveryContext,
|
|
133
132
|
},
|
|
134
|
-
|
|
133
|
+
unchainedAPI,
|
|
135
134
|
);
|
|
136
135
|
},
|
|
137
136
|
|
|
138
137
|
// Payment Adapter
|
|
139
138
|
|
|
140
|
-
configurationError: async (paymentProvider,
|
|
141
|
-
const actions = await PaymentDirector.actions(paymentProvider, {},
|
|
139
|
+
configurationError: async (paymentProvider, unchainedAPI) => {
|
|
140
|
+
const actions = await PaymentDirector.actions(paymentProvider, {}, unchainedAPI);
|
|
142
141
|
return actions.configurationError();
|
|
143
142
|
},
|
|
144
143
|
|
|
145
|
-
calculate: async (pricingContext,
|
|
146
|
-
const pricing = await PaymentPricingDirector.actions(pricingContext,
|
|
144
|
+
calculate: async (pricingContext, unchainedAPI) => {
|
|
145
|
+
const pricing = await PaymentPricingDirector.actions(pricingContext, unchainedAPI);
|
|
147
146
|
return pricing.calculate();
|
|
148
147
|
},
|
|
149
148
|
|
|
150
|
-
isActive: async (paymentProvider,
|
|
151
|
-
const actions = await PaymentDirector.actions(paymentProvider, {},
|
|
149
|
+
isActive: async (paymentProvider, unchainedAPI) => {
|
|
150
|
+
const actions = await PaymentDirector.actions(paymentProvider, {}, unchainedAPI);
|
|
152
151
|
return actions.isActive();
|
|
153
152
|
},
|
|
154
153
|
|
|
155
|
-
isPayLaterAllowed: async (paymentProvider,
|
|
156
|
-
const actions = await PaymentDirector.actions(paymentProvider, {},
|
|
154
|
+
isPayLaterAllowed: async (paymentProvider, unchainedAPI) => {
|
|
155
|
+
const actions = await PaymentDirector.actions(paymentProvider, {}, unchainedAPI);
|
|
157
156
|
return actions.isPayLaterAllowed();
|
|
158
157
|
},
|
|
159
158
|
|
|
160
|
-
charge: async (paymentProviderId, paymentContext,
|
|
161
|
-
const adapter = await getPaymentAdapter(paymentProviderId, paymentContext,
|
|
159
|
+
charge: async (paymentProviderId, paymentContext, unchainedAPI) => {
|
|
160
|
+
const adapter = await getPaymentAdapter(paymentProviderId, paymentContext, unchainedAPI);
|
|
162
161
|
return adapter.charge();
|
|
163
162
|
},
|
|
164
163
|
|
|
165
|
-
register: async (paymentProviderId, paymentContext,
|
|
166
|
-
const adapter = await getPaymentAdapter(paymentProviderId, paymentContext,
|
|
164
|
+
register: async (paymentProviderId, paymentContext, unchainedAPI) => {
|
|
165
|
+
const adapter = await getPaymentAdapter(paymentProviderId, paymentContext, unchainedAPI);
|
|
167
166
|
return adapter.register();
|
|
168
167
|
},
|
|
169
168
|
|
|
170
|
-
sign: async (paymentProviderId, paymentContext,
|
|
171
|
-
const adapter = await getPaymentAdapter(paymentProviderId, paymentContext,
|
|
169
|
+
sign: async (paymentProviderId, paymentContext, unchainedAPI) => {
|
|
170
|
+
const adapter = await getPaymentAdapter(paymentProviderId, paymentContext, unchainedAPI);
|
|
172
171
|
return adapter.sign();
|
|
173
172
|
},
|
|
174
173
|
|
|
175
|
-
validate: async (paymentProviderId, paymentContext,
|
|
176
|
-
const adapter = await getPaymentAdapter(paymentProviderId, paymentContext,
|
|
174
|
+
validate: async (paymentProviderId, paymentContext, unchainedAPI) => {
|
|
175
|
+
const adapter = await getPaymentAdapter(paymentProviderId, paymentContext, unchainedAPI);
|
|
177
176
|
return adapter.validate();
|
|
178
177
|
},
|
|
179
178
|
|
|
180
|
-
cancel: async (paymentProviderId, paymentContext,
|
|
181
|
-
const adapter = await getPaymentAdapter(paymentProviderId, paymentContext,
|
|
179
|
+
cancel: async (paymentProviderId, paymentContext, unchainedAPI) => {
|
|
180
|
+
const adapter = await getPaymentAdapter(paymentProviderId, paymentContext, unchainedAPI);
|
|
182
181
|
return adapter.cancel();
|
|
183
182
|
},
|
|
184
183
|
|
|
185
|
-
confirm: async (paymentProviderId, paymentContext,
|
|
186
|
-
const adapter = await getPaymentAdapter(paymentProviderId, paymentContext,
|
|
184
|
+
confirm: async (paymentProviderId, paymentContext, unchainedAPI) => {
|
|
185
|
+
const adapter = await getPaymentAdapter(paymentProviderId, paymentContext, unchainedAPI);
|
|
187
186
|
return adapter.confirm();
|
|
188
187
|
},
|
|
189
188
|
|
|
190
189
|
// Mutations
|
|
191
|
-
create: async (doc
|
|
190
|
+
create: async (doc) => {
|
|
192
191
|
const Adapter = PaymentDirector.getAdapter(doc.adapterKey);
|
|
193
192
|
if (!Adapter) return null;
|
|
194
193
|
|
|
195
|
-
const paymentProviderId = await mutations.create(
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
},
|
|
200
|
-
userId,
|
|
201
|
-
);
|
|
194
|
+
const paymentProviderId = await mutations.create({
|
|
195
|
+
configuration: Adapter.initialConfiguration,
|
|
196
|
+
...doc,
|
|
197
|
+
});
|
|
202
198
|
|
|
203
199
|
const paymentProvider = await PaymentProviders.findOne(
|
|
204
200
|
generateDbFilterById(paymentProviderId),
|
|
@@ -208,23 +204,23 @@ export const configurePaymentProvidersModule = (
|
|
|
208
204
|
return paymentProvider;
|
|
209
205
|
},
|
|
210
206
|
|
|
211
|
-
update: async (_id: string, doc: PaymentProvider
|
|
212
|
-
await mutations.update(_id, doc
|
|
207
|
+
update: async (_id: string, doc: PaymentProvider) => {
|
|
208
|
+
await mutations.update(_id, doc);
|
|
213
209
|
const paymentProvider = await PaymentProviders.findOne(generateDbFilterById(_id), {});
|
|
214
210
|
await emit('PAYMENT_PROVIDER_UPDATE', { paymentProvider });
|
|
215
211
|
return paymentProvider;
|
|
216
212
|
},
|
|
217
213
|
|
|
218
|
-
delete: async (_id
|
|
219
|
-
await mutations.delete(_id
|
|
214
|
+
delete: async (_id) => {
|
|
215
|
+
await mutations.delete(_id);
|
|
220
216
|
const paymentProvider = await PaymentProviders.findOne(generateDbFilterById(_id), {});
|
|
221
217
|
await emit('PAYMENT_PROVIDER_REMOVE', { paymentProvider });
|
|
222
218
|
return paymentProvider;
|
|
223
219
|
},
|
|
224
220
|
|
|
225
|
-
deletePermanently: async (_id
|
|
221
|
+
deletePermanently: async (_id) => {
|
|
226
222
|
const deliveryProvider = await PaymentProviders.findOne(generateDbFilterById(_id), {});
|
|
227
|
-
await mutations.deletePermanently(_id
|
|
223
|
+
await mutations.deletePermanently(_id);
|
|
228
224
|
return deliveryProvider;
|
|
229
225
|
},
|
|
230
226
|
};
|
package/src/payment-index.ts
CHANGED
|
@@ -1,47 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { configurePaymentModule } from '@unchainedshop/core-payment';
|
|
1
|
+
import { PaymentProviderType } from "../src/director/PaymentProviderType";
|
|
2
|
+
import { buildFindSelector } from "../src/module/configurePaymentProvidersModule";
|
|
4
3
|
|
|
5
|
-
describe('Test exports', () => {
|
|
6
|
-
let module;
|
|
7
4
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
describe('Payment', () => {
|
|
6
|
+
describe('buildFindSelector', () => {
|
|
7
|
+
it('Return correct filter object when passed no argument', async () => {
|
|
8
|
+
expect(buildFindSelector({})).toEqual({ deleted: null })
|
|
9
|
+
});
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
assert.isFunction(module.create);
|
|
19
|
-
assert.isFunction(module.update);
|
|
20
|
-
assert.isFunction(module.delete);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('Mutate currency', async () => {
|
|
24
|
-
const currencyId = await module.create(
|
|
25
|
-
{
|
|
26
|
-
authorId: 'Test-User-1',
|
|
27
|
-
isoCode: 'CHF',
|
|
28
|
-
},
|
|
29
|
-
'Test-User-1'
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
assert.ok(currencyId);
|
|
33
|
-
const currency = await module.findCurrency(currencyId);
|
|
34
|
-
|
|
35
|
-
assert.ok(currency);
|
|
36
|
-
assert.equal(currency._id, currencyId);
|
|
37
|
-
assert.equal(currency.isoCode, 'CHF');
|
|
38
|
-
assert.equal(currency.userId, 'Test-User-1');
|
|
39
|
-
assert.isDefined(currency.created);
|
|
40
|
-
assert.isUndefined(currency.updated);
|
|
41
|
-
assert.isUndefined(currency.updatedBy);
|
|
42
|
-
assert.equal(currency.createdBy, 'Test-User-1');
|
|
43
|
-
|
|
44
|
-
const deletedCount = await module.delete(currencyId);
|
|
45
|
-
assert.equal(deletedCount, 1);
|
|
46
|
-
});
|
|
11
|
+
it('Return correct filter object when passed no argument', async () => {
|
|
12
|
+
expect(buildFindSelector({type: PaymentProviderType.GENERIC})).toEqual({ type: "GENERIC", deleted: null })
|
|
13
|
+
});
|
|
14
|
+
})
|
|
15
|
+
|
|
47
16
|
});
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export const cancelService = async ({ paymentContext, paymentProviderId }, requestContext) => {
|
|
2
|
-
const { modules, userId } = requestContext;
|
|
3
|
-
const normalizedContext = {
|
|
4
|
-
...paymentContext,
|
|
5
|
-
userId,
|
|
6
|
-
paymentProviderId,
|
|
7
|
-
};
|
|
8
|
-
const result = await modules.payment.paymentProviders.cancel(paymentProviderId, normalizedContext, requestContext);
|
|
9
|
-
if (!result)
|
|
10
|
-
return false;
|
|
11
|
-
return result;
|
|
12
|
-
};
|
|
13
|
-
//# sourceMappingURL=cancelService.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cancelService.js","sourceRoot":"","sources":["../../src/service/cancelService.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,aAAa,GAAkB,KAAK,EAC/C,EAAE,cAAc,EAAE,iBAAiB,EAAE,EACrC,cAAc,EACd,EAAE;IACF,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,cAAc,CAAC;IAE3C,MAAM,iBAAiB,GAAG;QACxB,GAAG,cAAc;QACjB,MAAM;QACN,iBAAiB;KAClB,CAAC;IAEF,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,gBAAgB,CAAC,MAAM,CAC1D,iBAAiB,EACjB,iBAAiB,EACjB,cAAc,CACf,CAAC;IAEF,IAAI,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IAE1B,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC"}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
export const chargeService = async ({ paymentContext, paymentProviderId }, requestContext) => {
|
|
2
|
-
const { modules, userId } = requestContext;
|
|
3
|
-
const paymentCredentials = paymentContext.transactionContext?.paymentCredentials ||
|
|
4
|
-
(await modules.payment.paymentCredentials.findPaymentCredential({
|
|
5
|
-
userId,
|
|
6
|
-
paymentProviderId,
|
|
7
|
-
isPreferred: true,
|
|
8
|
-
}));
|
|
9
|
-
const normalizedContext = {
|
|
10
|
-
...paymentContext,
|
|
11
|
-
userId,
|
|
12
|
-
paymentProviderId,
|
|
13
|
-
transactionContext: {
|
|
14
|
-
...paymentContext.transactionContext,
|
|
15
|
-
paymentCredentials,
|
|
16
|
-
},
|
|
17
|
-
};
|
|
18
|
-
const result = await modules.payment.paymentProviders.charge(paymentProviderId, normalizedContext, requestContext);
|
|
19
|
-
if (!result)
|
|
20
|
-
return false;
|
|
21
|
-
const { credentials, ...strippedResult } = result;
|
|
22
|
-
if (credentials) {
|
|
23
|
-
const { token, ...meta } = credentials;
|
|
24
|
-
await modules.payment.paymentCredentials.upsertCredentials({
|
|
25
|
-
userId,
|
|
26
|
-
paymentProviderId,
|
|
27
|
-
token,
|
|
28
|
-
...meta,
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
return strippedResult;
|
|
32
|
-
};
|
|
33
|
-
//# sourceMappingURL=chargeService.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"chargeService.js","sourceRoot":"","sources":["../../src/service/chargeService.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,aAAa,GAAkB,KAAK,EAC/C,EAAE,cAAc,EAAE,iBAAiB,EAAE,EACrC,cAAc,EACd,EAAE;IACF,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,cAAc,CAAC;IAE3C,MAAM,kBAAkB,GACtB,cAAc,CAAC,kBAAkB,EAAE,kBAAkB;QACrD,CAAC,MAAM,OAAO,CAAC,OAAO,CAAC,kBAAkB,CAAC,qBAAqB,CAAC;YAC9D,MAAM;YACN,iBAAiB;YACjB,WAAW,EAAE,IAAI;SAClB,CAAC,CAAC,CAAC;IAEN,MAAM,iBAAiB,GAAG;QACxB,GAAG,cAAc;QACjB,MAAM;QACN,iBAAiB;QACjB,kBAAkB,EAAE;YAClB,GAAG,cAAc,CAAC,kBAAkB;YACpC,kBAAkB;SACnB;KACF,CAAC;IAEF,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,gBAAgB,CAAC,MAAM,CAC1D,iBAAiB,EACjB,iBAAiB,EACjB,cAAc,CACf,CAAC;IAEF,IAAI,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IAE1B,MAAM,EAAE,WAAW,EAAE,GAAG,cAAc,EAAE,GAAG,MAAM,CAAC;IAElD,IAAI,WAAW,EAAE;QACf,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,EAAE,GAAG,WAAW,CAAC;QACvC,MAAM,OAAO,CAAC,OAAO,CAAC,kBAAkB,CAAC,iBAAiB,CAAC;YACzD,MAAM;YACN,iBAAiB;YACjB,KAAK;YACL,GAAG,IAAI;SACR,CAAC,CAAC;KACJ;IACD,OAAO,cAAc,CAAC;AACxB,CAAC,CAAC"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export const confirmService = async ({ paymentContext, paymentProviderId }, requestContext) => {
|
|
2
|
-
const { modules, userId } = requestContext;
|
|
3
|
-
const normalizedContext = {
|
|
4
|
-
...paymentContext,
|
|
5
|
-
userId,
|
|
6
|
-
paymentProviderId,
|
|
7
|
-
};
|
|
8
|
-
const result = await modules.payment.paymentProviders.confirm(paymentProviderId, normalizedContext, requestContext);
|
|
9
|
-
if (!result)
|
|
10
|
-
return false;
|
|
11
|
-
return result;
|
|
12
|
-
};
|
|
13
|
-
//# sourceMappingURL=confirmService.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"confirmService.js","sourceRoot":"","sources":["../../src/service/confirmService.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,cAAc,GAAmB,KAAK,EACjD,EAAE,cAAc,EAAE,iBAAiB,EAAE,EACrC,cAAc,EACd,EAAE;IACF,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,cAAc,CAAC;IAE3C,MAAM,iBAAiB,GAAG;QACxB,GAAG,cAAc;QACjB,MAAM;QACN,iBAAiB;KAClB,CAAC;IAEF,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,gBAAgB,CAAC,OAAO,CAC3D,iBAAiB,EACjB,iBAAiB,EACjB,cAAc,CACf,CAAC;IAEF,IAAI,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IAE1B,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { chargeService } from './chargeService';
|
|
2
|
-
import { cancelService } from './cancelService';
|
|
3
|
-
import { confirmService } from './confirmService';
|
|
4
|
-
import { registerPaymentCredentialsService } from './registerPaymentCredentialsService';
|
|
5
|
-
export const paymentServices = {
|
|
6
|
-
charge: chargeService,
|
|
7
|
-
registerPaymentCredentials: registerPaymentCredentialsService,
|
|
8
|
-
cancel: cancelService,
|
|
9
|
-
confirm: confirmService,
|
|
10
|
-
};
|
|
11
|
-
//# sourceMappingURL=paymentServices.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"paymentServices.js","sourceRoot":"","sources":["../../src/service/paymentServices.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,iCAAiC,EAAE,MAAM,qCAAqC,CAAC;AAExF,MAAM,CAAC,MAAM,eAAe,GAAoB;IAC9C,MAAM,EAAE,aAAa;IACrB,0BAA0B,EAAE,iCAAiC;IAC7D,MAAM,EAAE,aAAa;IACrB,OAAO,EAAE,cAAc;CACxB,CAAC"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export const registerPaymentCredentialsService = async (paymentProviderId, paymentContext, requestContext) => {
|
|
2
|
-
const { modules, userId } = requestContext;
|
|
3
|
-
const registration = await modules.payment.paymentProviders.register(paymentProviderId, paymentContext, requestContext);
|
|
4
|
-
if (!registration)
|
|
5
|
-
return null;
|
|
6
|
-
const paymentCredentialsId = await modules.payment.paymentCredentials.upsertCredentials({
|
|
7
|
-
userId,
|
|
8
|
-
paymentProviderId,
|
|
9
|
-
...registration,
|
|
10
|
-
});
|
|
11
|
-
return modules.payment.paymentCredentials.findPaymentCredential({
|
|
12
|
-
paymentCredentialsId,
|
|
13
|
-
userId,
|
|
14
|
-
paymentProviderId,
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
//# sourceMappingURL=registerPaymentCredentialsService.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"registerPaymentCredentialsService.js","sourceRoot":"","sources":["../../src/service/registerPaymentCredentialsService.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,iCAAiC,GAAsC,KAAK,EACvF,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,EAAE;IACF,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,cAAc,CAAC;IAC3C,MAAM,YAAY,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,gBAAgB,CAAC,QAAQ,CAClE,iBAAiB,EACjB,cAAc,EACd,cAAc,CACf,CAAC;IAEF,IAAI,CAAC,YAAY;QAAE,OAAO,IAAI,CAAC;IAE/B,MAAM,oBAAoB,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,kBAAkB,CAAC,iBAAiB,CAAC;QACtF,MAAM;QACN,iBAAiB;QACjB,GAAG,YAAY;KAChB,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC,OAAO,CAAC,kBAAkB,CAAC,qBAAqB,CAAC;QAC9D,oBAAoB;QACpB,MAAM;QACN,iBAAiB;KAClB,CAAC,CAAC;AACL,CAAC,CAAC"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { CancelService } from '@unchainedshop/types/payments';
|
|
2
|
-
|
|
3
|
-
export const cancelService: CancelService = async (
|
|
4
|
-
{ paymentContext, paymentProviderId },
|
|
5
|
-
requestContext,
|
|
6
|
-
) => {
|
|
7
|
-
const { modules, userId } = requestContext;
|
|
8
|
-
|
|
9
|
-
const normalizedContext = {
|
|
10
|
-
...paymentContext,
|
|
11
|
-
userId,
|
|
12
|
-
paymentProviderId,
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const result = await modules.payment.paymentProviders.cancel(
|
|
16
|
-
paymentProviderId,
|
|
17
|
-
normalizedContext,
|
|
18
|
-
requestContext,
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
if (!result) return false;
|
|
22
|
-
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { ChargeService } from '@unchainedshop/types/payments';
|
|
2
|
-
|
|
3
|
-
export const chargeService: ChargeService = async (
|
|
4
|
-
{ paymentContext, paymentProviderId },
|
|
5
|
-
requestContext,
|
|
6
|
-
) => {
|
|
7
|
-
const { modules, userId } = requestContext;
|
|
8
|
-
|
|
9
|
-
const paymentCredentials =
|
|
10
|
-
paymentContext.transactionContext?.paymentCredentials ||
|
|
11
|
-
(await modules.payment.paymentCredentials.findPaymentCredential({
|
|
12
|
-
userId,
|
|
13
|
-
paymentProviderId,
|
|
14
|
-
isPreferred: true,
|
|
15
|
-
}));
|
|
16
|
-
|
|
17
|
-
const normalizedContext = {
|
|
18
|
-
...paymentContext,
|
|
19
|
-
userId,
|
|
20
|
-
paymentProviderId,
|
|
21
|
-
transactionContext: {
|
|
22
|
-
...paymentContext.transactionContext,
|
|
23
|
-
paymentCredentials,
|
|
24
|
-
},
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const result = await modules.payment.paymentProviders.charge(
|
|
28
|
-
paymentProviderId,
|
|
29
|
-
normalizedContext,
|
|
30
|
-
requestContext,
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
if (!result) return false;
|
|
34
|
-
|
|
35
|
-
const { credentials, ...strippedResult } = result;
|
|
36
|
-
|
|
37
|
-
if (credentials) {
|
|
38
|
-
const { token, ...meta } = credentials;
|
|
39
|
-
await modules.payment.paymentCredentials.upsertCredentials({
|
|
40
|
-
userId,
|
|
41
|
-
paymentProviderId,
|
|
42
|
-
token,
|
|
43
|
-
...meta,
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
return strippedResult;
|
|
47
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { ConfirmService } from '@unchainedshop/types/payments';
|
|
2
|
-
|
|
3
|
-
export const confirmService: ConfirmService = async (
|
|
4
|
-
{ paymentContext, paymentProviderId },
|
|
5
|
-
requestContext,
|
|
6
|
-
) => {
|
|
7
|
-
const { modules, userId } = requestContext;
|
|
8
|
-
|
|
9
|
-
const normalizedContext = {
|
|
10
|
-
...paymentContext,
|
|
11
|
-
userId,
|
|
12
|
-
paymentProviderId,
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const result = await modules.payment.paymentProviders.confirm(
|
|
16
|
-
paymentProviderId,
|
|
17
|
-
normalizedContext,
|
|
18
|
-
requestContext,
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
if (!result) return false;
|
|
22
|
-
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { PaymentServices } from '@unchainedshop/types/payments';
|
|
2
|
-
import { chargeService } from './chargeService';
|
|
3
|
-
import { cancelService } from './cancelService';
|
|
4
|
-
import { confirmService } from './confirmService';
|
|
5
|
-
import { registerPaymentCredentialsService } from './registerPaymentCredentialsService';
|
|
6
|
-
|
|
7
|
-
export const paymentServices: PaymentServices = {
|
|
8
|
-
charge: chargeService,
|
|
9
|
-
registerPaymentCredentials: registerPaymentCredentialsService,
|
|
10
|
-
cancel: cancelService,
|
|
11
|
-
confirm: confirmService,
|
|
12
|
-
};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { RegisterPaymentCredentialsService } from '@unchainedshop/types/payments';
|
|
2
|
-
|
|
3
|
-
export const registerPaymentCredentialsService: RegisterPaymentCredentialsService = async (
|
|
4
|
-
paymentProviderId,
|
|
5
|
-
paymentContext,
|
|
6
|
-
requestContext,
|
|
7
|
-
) => {
|
|
8
|
-
const { modules, userId } = requestContext;
|
|
9
|
-
const registration = await modules.payment.paymentProviders.register(
|
|
10
|
-
paymentProviderId,
|
|
11
|
-
paymentContext,
|
|
12
|
-
requestContext,
|
|
13
|
-
);
|
|
14
|
-
|
|
15
|
-
if (!registration) return null;
|
|
16
|
-
|
|
17
|
-
const paymentCredentialsId = await modules.payment.paymentCredentials.upsertCredentials({
|
|
18
|
-
userId,
|
|
19
|
-
paymentProviderId,
|
|
20
|
-
...registration,
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
return modules.payment.paymentCredentials.findPaymentCredential({
|
|
24
|
-
paymentCredentialsId,
|
|
25
|
-
userId,
|
|
26
|
-
paymentProviderId,
|
|
27
|
-
});
|
|
28
|
-
};
|