@unchainedshop/core-payment 2.14.2 → 3.0.0-alpha3

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.
Files changed (64) hide show
  1. package/lib/db/PaymentCredentialsCollection.d.ts +1 -1
  2. package/lib/db/PaymentCredentialsCollection.d.ts.map +1 -1
  3. package/lib/db/PaymentProvidersCollection.d.ts +1 -1
  4. package/lib/db/PaymentProvidersCollection.d.ts.map +1 -1
  5. package/lib/director/PaymentAdapter.d.ts +1 -1
  6. package/lib/director/PaymentAdapter.d.ts.map +1 -1
  7. package/lib/director/PaymentDirector.d.ts +1 -1
  8. package/lib/director/PaymentDirector.d.ts.map +1 -1
  9. package/lib/director/PaymentPricingAdapter.d.ts +44 -2
  10. package/lib/director/PaymentPricingAdapter.d.ts.map +1 -1
  11. package/lib/director/PaymentPricingAdapter.js.map +1 -1
  12. package/lib/director/PaymentPricingDirector.d.ts +17 -1
  13. package/lib/director/PaymentPricingDirector.d.ts.map +1 -1
  14. package/lib/director/PaymentPricingDirector.js.map +1 -1
  15. package/lib/director/PaymentPricingSheet.d.ts +8 -2
  16. package/lib/director/PaymentPricingSheet.d.ts.map +1 -1
  17. package/lib/director/PaymentPricingSheet.js +7 -1
  18. package/lib/director/PaymentPricingSheet.js.map +1 -1
  19. package/lib/module/configurePaymentCredentialsModule.d.ts +22 -2
  20. package/lib/module/configurePaymentCredentialsModule.d.ts.map +1 -1
  21. package/lib/module/configurePaymentCredentialsModule.js.map +1 -1
  22. package/lib/module/configurePaymentModule.d.ts +10 -2
  23. package/lib/module/configurePaymentModule.d.ts.map +1 -1
  24. package/lib/module/configurePaymentModule.js +2 -2
  25. package/lib/module/configurePaymentModule.js.map +1 -1
  26. package/lib/module/configurePaymentProvidersModule.d.ts +45 -3
  27. package/lib/module/configurePaymentProvidersModule.d.ts.map +1 -1
  28. package/lib/module/configurePaymentProvidersModule.js +15 -13
  29. package/lib/module/configurePaymentProvidersModule.js.map +1 -1
  30. package/lib/payment-index.d.ts +8 -6
  31. package/lib/payment-index.d.ts.map +1 -1
  32. package/lib/payment-index.js +8 -6
  33. package/lib/payment-index.js.map +1 -1
  34. package/lib/payment-settings.d.ts +22 -1
  35. package/lib/payment-settings.d.ts.map +1 -1
  36. package/lib/payment-settings.js.map +1 -1
  37. package/lib/types.d.ts +84 -0
  38. package/lib/types.d.ts.map +1 -0
  39. package/lib/types.js +17 -0
  40. package/lib/types.js.map +1 -0
  41. package/package.json +6 -8
  42. package/src/db/PaymentCredentialsCollection.ts +1 -1
  43. package/src/db/PaymentProvidersCollection.ts +1 -1
  44. package/src/director/PaymentAdapter.ts +1 -1
  45. package/src/director/PaymentDirector.ts +1 -1
  46. package/src/director/PaymentPricingAdapter.ts +51 -5
  47. package/src/director/PaymentPricingDirector.ts +28 -3
  48. package/src/director/PaymentPricingSheet.ts +9 -6
  49. package/src/module/configurePaymentCredentialsModule.ts +34 -5
  50. package/src/module/configurePaymentModule.ts +30 -5
  51. package/src/module/configurePaymentProvidersModule.ts +124 -22
  52. package/src/payment-index.ts +8 -7
  53. package/src/payment-settings.ts +31 -6
  54. package/src/types.ts +108 -0
  55. package/lib/db/PaymentCredentialsSchema.d.ts +0 -3
  56. package/lib/db/PaymentCredentialsSchema.d.ts.map +0 -1
  57. package/lib/db/PaymentCredentialsSchema.js +0 -11
  58. package/lib/db/PaymentCredentialsSchema.js.map +0 -1
  59. package/lib/db/PaymentProvidersSchema.d.ts +0 -3
  60. package/lib/db/PaymentProvidersSchema.d.ts.map +0 -1
  61. package/lib/db/PaymentProvidersSchema.js +0 -12
  62. package/lib/db/PaymentProvidersSchema.js.map +0 -1
  63. package/src/db/PaymentCredentialsSchema.ts +0 -14
  64. package/src/db/PaymentProvidersSchema.ts +0 -15
package/src/types.ts ADDED
@@ -0,0 +1,108 @@
1
+ import { IBaseAdapter, IBaseDirector } from '@unchainedshop/utils';
2
+ import type { TimestampFields } from '@unchainedshop/mongodb';
3
+ import { Order } from '@unchainedshop/core-orders';
4
+ import { OrderPayment } from '@unchainedshop/core-orders';
5
+ import { UnchainedCore } from '@unchainedshop/core';
6
+
7
+ export enum PaymentProviderType {
8
+ CARD = 'CARD',
9
+ INVOICE = 'INVOICE',
10
+ GENERIC = 'GENERIC',
11
+ }
12
+
13
+ export type PaymentConfiguration = Array<{
14
+ key: string;
15
+ value: string | null;
16
+ }>;
17
+
18
+ export type PaymentProvider = {
19
+ _id?: string;
20
+ type: PaymentProviderType;
21
+ adapterKey: string;
22
+ configuration: PaymentConfiguration;
23
+ } & TimestampFields;
24
+
25
+ export type PaymentCredentials = {
26
+ _id?: string;
27
+ paymentProviderId: string;
28
+ userId: string;
29
+ token?: string;
30
+ isPreferred?: boolean;
31
+ meta: any;
32
+ } & TimestampFields;
33
+
34
+ export enum PaymentError {
35
+ ADAPTER_NOT_FOUND = 'ADAPTER_NOT_FOUND',
36
+ NOT_IMPLEMENTED = 'NOT_IMPLEMENTED',
37
+ INCOMPLETE_CONFIGURATION = 'INCOMPLETE_CONFIGURATION',
38
+ WRONG_CREDENTIALS = 'WRONG_CREDENTIALS',
39
+ }
40
+
41
+ export interface PaymentContext {
42
+ userId?: string;
43
+ order?: Order;
44
+ orderPayment?: OrderPayment;
45
+ transactionContext?: any; // User for singing and charging a payment
46
+ token?: any; // Used for validation
47
+ meta?: any;
48
+ }
49
+
50
+ export type ChargeResult = {
51
+ transactionId?: string;
52
+ [key: string]: any;
53
+ };
54
+
55
+ export type PaymentChargeActionResult = ChargeResult & {
56
+ credentials?: {
57
+ token: string;
58
+ [key: string]: any;
59
+ };
60
+ };
61
+ export interface IPaymentActions {
62
+ charge: (transactionContext?: any) => Promise<PaymentChargeActionResult | false>;
63
+ configurationError: (transactionContext?: any) => PaymentError;
64
+ isActive: (transactionContext?: any) => boolean;
65
+ isPayLaterAllowed: (transactionContext?: any) => boolean;
66
+ register: (transactionContext?: any) => Promise<any>;
67
+ sign: (transactionContext?: any) => Promise<string>;
68
+ validate: (token?: any) => Promise<boolean>;
69
+ cancel: (transactionContext?: any) => Promise<boolean>;
70
+ confirm: (transactionContext?: any) => Promise<boolean>;
71
+ }
72
+
73
+ export type IPaymentAdapter = IBaseAdapter & {
74
+ initialConfiguration: PaymentConfiguration;
75
+
76
+ typeSupported: (type: PaymentProviderType) => boolean;
77
+
78
+ actions: (params: {
79
+ config: PaymentConfiguration;
80
+ paymentContext: PaymentContext & {
81
+ paymentProviderId: string;
82
+ paymentProvider: PaymentProvider;
83
+ };
84
+ context: UnchainedCore;
85
+ }) => IPaymentActions;
86
+ };
87
+
88
+ export type IPaymentDirector = IBaseDirector<IPaymentAdapter> & {
89
+ actions: (
90
+ paymentProvider: PaymentProvider,
91
+ paymentContext: PaymentContext,
92
+ unchainedAPI: UnchainedCore,
93
+ ) => Promise<IPaymentActions>;
94
+ };
95
+
96
+ /*
97
+ * Module
98
+ */
99
+
100
+ export interface PaymentInterface {
101
+ _id: string;
102
+ label: string;
103
+ version: string;
104
+ }
105
+
106
+ /*
107
+ * Settings
108
+ */
@@ -1,3 +0,0 @@
1
- import SimpleSchema from 'simpl-schema';
2
- export declare const PaymentCredentialsSchema: SimpleSchema;
3
- //# sourceMappingURL=PaymentCredentialsSchema.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PaymentCredentialsSchema.d.ts","sourceRoot":"","sources":["../../src/db/PaymentCredentialsSchema.ts"],"names":[],"mappings":"AACA,OAAO,YAAY,MAAM,cAAc,CAAC;AAExC,eAAO,MAAM,wBAAwB,cAUpC,CAAC"}
@@ -1,11 +0,0 @@
1
- import { Schemas } from '@unchainedshop/utils';
2
- import SimpleSchema from 'simpl-schema';
3
- export const PaymentCredentialsSchema = new SimpleSchema({
4
- paymentProviderId: { type: String, required: true },
5
- userId: { type: String, required: true },
6
- token: String,
7
- isPreferred: Boolean,
8
- meta: { type: Object, blackbox: true },
9
- ...Schemas.timestampFields,
10
- }, { requiredByDefault: false });
11
- //# sourceMappingURL=PaymentCredentialsSchema.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PaymentCredentialsSchema.js","sourceRoot":"","sources":["../../src/db/PaymentCredentialsSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,YAAY,MAAM,cAAc,CAAC;AAExC,MAAM,CAAC,MAAM,wBAAwB,GAAG,IAAI,YAAY,CACtD;IACE,iBAAiB,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;IACnD,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;IACxC,KAAK,EAAE,MAAM;IACb,WAAW,EAAE,OAAO;IACpB,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;IACtC,GAAG,OAAO,CAAC,eAAe;CAC3B,EACD,EAAE,iBAAiB,EAAE,KAAK,EAAE,CAC7B,CAAC"}
@@ -1,3 +0,0 @@
1
- import SimpleSchema from 'simpl-schema';
2
- export declare const PaymentProvidersSchema: SimpleSchema;
3
- //# sourceMappingURL=PaymentProvidersSchema.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PaymentProvidersSchema.d.ts","sourceRoot":"","sources":["../../src/db/PaymentProvidersSchema.ts"],"names":[],"mappings":"AACA,OAAO,YAAY,MAAM,cAAc,CAAC;AAExC,eAAO,MAAM,sBAAsB,cAWlC,CAAC"}
@@ -1,12 +0,0 @@
1
- import { Schemas } from '@unchainedshop/utils';
2
- import SimpleSchema from 'simpl-schema';
3
- export const PaymentProvidersSchema = new SimpleSchema({
4
- type: { type: String, required: true },
5
- adapterKey: { type: String, required: true },
6
- configuration: { type: Array },
7
- 'configuration.$': { type: Object },
8
- 'configuration.$.key': { type: String },
9
- 'configuration.$.value': { type: String },
10
- ...Schemas.timestampFields,
11
- }, { requiredByDefault: false });
12
- //# sourceMappingURL=PaymentProvidersSchema.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PaymentProvidersSchema.js","sourceRoot":"","sources":["../../src/db/PaymentProvidersSchema.ts"],"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"}
@@ -1,14 +0,0 @@
1
- import { Schemas } from '@unchainedshop/utils';
2
- import SimpleSchema from 'simpl-schema';
3
-
4
- export const PaymentCredentialsSchema = new SimpleSchema(
5
- {
6
- paymentProviderId: { type: String, required: true },
7
- userId: { type: String, required: true },
8
- token: String,
9
- isPreferred: Boolean,
10
- meta: { type: Object, blackbox: true },
11
- ...Schemas.timestampFields,
12
- },
13
- { requiredByDefault: false },
14
- );
@@ -1,15 +0,0 @@
1
- import { Schemas } from '@unchainedshop/utils';
2
- import SimpleSchema from 'simpl-schema';
3
-
4
- export const PaymentProvidersSchema = new SimpleSchema(
5
- {
6
- type: { type: String, required: true },
7
- adapterKey: { type: String, required: true },
8
- configuration: { type: Array },
9
- 'configuration.$': { type: Object },
10
- 'configuration.$.key': { type: String },
11
- 'configuration.$.value': { type: String },
12
- ...Schemas.timestampFields,
13
- },
14
- { requiredByDefault: false },
15
- );