@appweaver/payments 0.0.0-stage → 3.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.
Files changed (91) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +212 -2
  3. package/config.d.ts +77 -0
  4. package/config.js +118 -0
  5. package/gateway/fake-gateway.d.ts +144 -0
  6. package/gateway/fake-gateway.js +805 -0
  7. package/gateway/gateway-registry.d.ts +99 -0
  8. package/gateway/gateway-registry.js +275 -0
  9. package/gateway/payment-gateway.d.ts +68 -0
  10. package/gateway/payment-gateway.js +82 -0
  11. package/index.d.ts +16 -0
  12. package/index.js +51 -0
  13. package/locales/en.json +47 -0
  14. package/maintenance/payment-maintenance-jobs.d.ts +5 -0
  15. package/maintenance/payment-maintenance-jobs.js +38 -0
  16. package/module.d.ts +8 -0
  17. package/module.js +85 -0
  18. package/package.json +67 -3
  19. package/resources/model-util.d.ts +40 -0
  20. package/resources/model-util.js +30 -0
  21. package/resources/payment/model.d.ts +2 -0
  22. package/resources/payment/model.js +106 -0
  23. package/resources/payment-customer/model.d.ts +2 -0
  24. package/resources/payment-customer/model.js +53 -0
  25. package/resources/payment-event/model.d.ts +2 -0
  26. package/resources/payment-event/model.js +31 -0
  27. package/resources/payment-invoice/model.d.ts +2 -0
  28. package/resources/payment-invoice/model.js +55 -0
  29. package/resources/payment-method/model.d.ts +2 -0
  30. package/resources/payment-method/model.js +37 -0
  31. package/resources/payment-plan/model.d.ts +2 -0
  32. package/resources/payment-plan/model.js +37 -0
  33. package/resources/payment-subscription/model.d.ts +2 -0
  34. package/resources/payment-subscription/model.js +82 -0
  35. package/resources/payment-transaction/model.d.ts +2 -0
  36. package/resources/payment-transaction/model.js +43 -0
  37. package/resources/payment-webhook-event/model.d.ts +2 -0
  38. package/resources/payment-webhook-event/model.js +32 -0
  39. package/resources/policies.d.ts +15 -0
  40. package/resources/policies.js +36 -0
  41. package/resources/services.d.ts +6 -0
  42. package/resources/services.js +19 -0
  43. package/resources/subscriptions.d.ts +9 -0
  44. package/resources/subscriptions.js +30 -0
  45. package/resources.d.ts +8 -0
  46. package/resources.js +34 -0
  47. package/service/payment-emails.d.ts +12 -0
  48. package/service/payment-emails.js +145 -0
  49. package/service/payment-events.d.ts +90 -0
  50. package/service/payment-events.js +472 -0
  51. package/service/payment-handlers.d.ts +26 -0
  52. package/service/payment-handlers.js +42 -0
  53. package/service/payment-store.d.ts +50 -0
  54. package/service/payment-store.js +95 -0
  55. package/service/payment-sync.d.ts +113 -0
  56. package/service/payment-sync.js +745 -0
  57. package/service/payments-service.d.ts +307 -0
  58. package/service/payments-service.js +747 -0
  59. package/service/subscriptions-service.d.ts +178 -0
  60. package/service/subscriptions-service.js +433 -0
  61. package/tasks/payments-replay.d.ts +10 -0
  62. package/tasks/payments-replay.js +36 -0
  63. package/tasks/payments-sync-plans.d.ts +10 -0
  64. package/tasks/payments-sync-plans.js +24 -0
  65. package/templates/emails/payment-action-required.html.hbs +28 -0
  66. package/templates/emails/payment-action-required.subject.hbs +1 -0
  67. package/templates/emails/payment-failed.html.hbs +37 -0
  68. package/templates/emails/payment-failed.subject.hbs +1 -0
  69. package/templates/emails/payment-receipt.html.hbs +45 -0
  70. package/templates/emails/payment-receipt.subject.hbs +1 -0
  71. package/templates/emails/payment-refunded.html.hbs +37 -0
  72. package/templates/emails/payment-refunded.subject.hbs +1 -0
  73. package/templates/emails/subscription-canceled.html.hbs +24 -0
  74. package/templates/emails/subscription-canceled.subject.hbs +1 -0
  75. package/templates/emails/subscription-trial-ending.html.hbs +25 -0
  76. package/templates/emails/subscription-trial-ending.subject.hbs +1 -0
  77. package/templates/layouts/email.html.hbs +36 -0
  78. package/templates/partials/email-button.html.hbs +15 -0
  79. package/tsconfig.build.tsbuildinfo +1 -0
  80. package/types.d.ts +488 -0
  81. package/types.js +2 -0
  82. package/utils/money-util.d.ts +61 -0
  83. package/utils/money-util.js +124 -0
  84. package/utils/status-util.d.ts +29 -0
  85. package/utils/status-util.js +93 -0
  86. package/utils/telemetry.d.ts +16 -0
  87. package/utils/telemetry.js +69 -0
  88. package/web/payment-routes.d.ts +7 -0
  89. package/web/payment-routes.js +410 -0
  90. package/web/payment-schemas.d.ts +70 -0
  91. package/web/payment-schemas.js +101 -0
@@ -0,0 +1,70 @@
1
+ import { TObject, Type } from 'typebox';
2
+ /**
3
+ * Builds the schemas of the routes. The bodies and the answers are models of the OpenAPI document, named
4
+ * `Payments<Name>`, which the generated client names its types after.
5
+ */
6
+ export declare function paymentRouteSchemas(): {
7
+ Id: TObject<{
8
+ id: Type.TString;
9
+ }>;
10
+ Record: TObject<{}>;
11
+ SetupBody: TObject<{
12
+ gateway: Type.TOptional<Type.TString>;
13
+ country: Type.TOptional<Type.TString>;
14
+ }>;
15
+ SetupResponse: TObject<{
16
+ nextAction: TObject<{
17
+ type: Type.TEnum<["none", "confirm", "redirect"]>;
18
+ clientSecret: Type.TOptional<Type.TString>;
19
+ publicKey: Type.TOptional<Type.TString>;
20
+ url: Type.TOptional<Type.TString>;
21
+ }>;
22
+ }>;
23
+ PortalBody: TObject<{
24
+ returnUrl: Type.TOptional<Type.TString>;
25
+ gateway: Type.TOptional<Type.TString>;
26
+ country: Type.TOptional<Type.TString>;
27
+ }>;
28
+ PortalResponse: TObject<{
29
+ url: Type.TString;
30
+ }>;
31
+ RefundBody: TObject<{
32
+ amount: Type.TOptional<Type.TInteger>;
33
+ reason: Type.TOptional<Type.TString>;
34
+ }>;
35
+ CaptureBody: TObject<{
36
+ amount: Type.TOptional<Type.TInteger>;
37
+ }>;
38
+ };
39
+ /** Builds the schemas of the routes of the subscriptions, models of the OpenAPI document as the other ones. */
40
+ export declare function subscriptionRouteSchemas(): {
41
+ SubscribeBody: TObject<{
42
+ plan: Type.TString;
43
+ quantity: Type.TOptional<Type.TInteger>;
44
+ paymentMethodId: Type.TOptional<Type.TString>;
45
+ gateway: Type.TOptional<Type.TString>;
46
+ country: Type.TOptional<Type.TString>;
47
+ }>;
48
+ SubscriptionCheckoutBody: TObject<{
49
+ plan: Type.TString;
50
+ quantity: Type.TOptional<Type.TInteger>;
51
+ gateway: Type.TOptional<Type.TString>;
52
+ country: Type.TOptional<Type.TString>;
53
+ }>;
54
+ SubscriptionResponse: TObject<{
55
+ subscription: TObject<{}>;
56
+ nextAction: TObject<{
57
+ type: Type.TEnum<["none", "confirm", "redirect"]>;
58
+ clientSecret: Type.TOptional<Type.TString>;
59
+ publicKey: Type.TOptional<Type.TString>;
60
+ url: Type.TOptional<Type.TString>;
61
+ }>;
62
+ }>;
63
+ CancelSubscriptionBody: TObject<{
64
+ atPeriodEnd: Type.TOptional<Type.TBoolean>;
65
+ }>;
66
+ ChangePlanBody: TObject<{
67
+ plan: Type.TString;
68
+ quantity: Type.TOptional<Type.TInteger>;
69
+ }>;
70
+ };
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.paymentRouteSchemas = paymentRouteSchemas;
4
+ exports.subscriptionRouteSchemas = subscriptionRouteSchemas;
5
+ const typebox_1 = require("typebox");
6
+ const core_1 = require("@appweaver/core");
7
+ const Id = typebox_1.Type.Object({
8
+ id: typebox_1.Type.String({ description: 'The ID of the record' })
9
+ });
10
+ const GatewayChoice = {
11
+ gateway: typebox_1.Type.Optional(typebox_1.Type.String({
12
+ description: 'The name of the gateway. Default: by country, then the default one.'
13
+ })),
14
+ country: typebox_1.Type.Optional(typebox_1.Type.String({
15
+ description: 'The country of the customer, an ISO 3166-1 alpha-2 code, selecting the gateway',
16
+ minLength: 2,
17
+ maxLength: 2
18
+ }))
19
+ };
20
+ const NextAction = typebox_1.Type.Object({
21
+ type: typebox_1.Type.Enum(['none', 'confirm', 'redirect']),
22
+ clientSecret: typebox_1.Type.Optional(typebox_1.Type.String({
23
+ description: 'Confirmed by the client library of the gateway, for `confirm`'
24
+ })),
25
+ publicKey: typebox_1.Type.Optional(typebox_1.Type.String({
26
+ description: 'The public key of the gateway, for `confirm`'
27
+ })),
28
+ url: typebox_1.Type.Optional(typebox_1.Type.String({
29
+ description: 'The page of the gateway to open, for `redirect`'
30
+ }))
31
+ }, {
32
+ $id: 'PaymentsNextAction',
33
+ description: 'What the client does next to complete the payment'
34
+ });
35
+ const Record = typebox_1.Type.Object({}, { additionalProperties: true });
36
+ /** A body or an answer as a model of the OpenAPI document, named `Payments<Name>`. */
37
+ const model = (name, schema) => (0, core_1.createSchemaModel)(schema, { name: `Payments${name}` });
38
+ /**
39
+ * Builds the schemas of the routes. The bodies and the answers are models of the OpenAPI document, named
40
+ * `Payments<Name>`, which the generated client names its types after.
41
+ */
42
+ function paymentRouteSchemas() {
43
+ const nextAction = (0, core_1.createSchemaModel)(NextAction);
44
+ return {
45
+ Id,
46
+ Record,
47
+ SetupBody: model('SetupRequest', typebox_1.Type.Object(GatewayChoice)),
48
+ SetupResponse: model('SetupResponse', typebox_1.Type.Object({ nextAction })),
49
+ PortalBody: model('PortalRequest', typebox_1.Type.Object({
50
+ ...GatewayChoice,
51
+ returnUrl: typebox_1.Type.Optional(typebox_1.Type.String({
52
+ description: 'Where the page sends the user back',
53
+ format: 'uri'
54
+ }))
55
+ })),
56
+ PortalResponse: model('PortalResponse', typebox_1.Type.Object({ url: typebox_1.Type.String() })),
57
+ RefundBody: model('RefundRequest', typebox_1.Type.Object({
58
+ amount: typebox_1.Type.Optional(typebox_1.Type.Integer({
59
+ description: 'The amount in minor units. Default: what is left of the payment.',
60
+ minimum: 1
61
+ })),
62
+ reason: typebox_1.Type.Optional(typebox_1.Type.String({ maxLength: 500 }))
63
+ })),
64
+ CaptureBody: model('CaptureRequest', typebox_1.Type.Object({
65
+ amount: typebox_1.Type.Optional(typebox_1.Type.Integer({
66
+ description: 'A part of the authorized amount, in minor units. Default: all.',
67
+ minimum: 1
68
+ }))
69
+ }))
70
+ };
71
+ }
72
+ /** Builds the schemas of the routes of the subscriptions, models of the OpenAPI document as the other ones. */
73
+ function subscriptionRouteSchemas() {
74
+ const nextAction = (0, core_1.createSchemaModel)(NextAction);
75
+ return {
76
+ SubscribeBody: model('SubscribeRequest', typebox_1.Type.Object({
77
+ ...GatewayChoice,
78
+ plan: typebox_1.Type.String({ description: 'The key of the plan' }),
79
+ quantity: typebox_1.Type.Optional(typebox_1.Type.Integer({ minimum: 1 })),
80
+ paymentMethodId: typebox_1.Type.Optional(typebox_1.Type.String({
81
+ description: 'A saved payment method. Default: the default one of the customer.'
82
+ }))
83
+ })),
84
+ SubscriptionCheckoutBody: model('CheckoutRequest', typebox_1.Type.Object({
85
+ ...GatewayChoice,
86
+ plan: typebox_1.Type.String({ description: 'The key of the plan' }),
87
+ quantity: typebox_1.Type.Optional(typebox_1.Type.Integer({ minimum: 1 }))
88
+ })),
89
+ SubscriptionResponse: model('SubscriptionResponse', typebox_1.Type.Object({ subscription: Record, nextAction })),
90
+ CancelSubscriptionBody: model('CancelSubscriptionRequest', typebox_1.Type.Object({
91
+ atPeriodEnd: typebox_1.Type.Optional(typebox_1.Type.Boolean({
92
+ description: 'Keep the subscription until the end of its period',
93
+ default: true
94
+ }))
95
+ })),
96
+ ChangePlanBody: model('ChangePlanRequest', typebox_1.Type.Object({
97
+ plan: typebox_1.Type.String({ description: 'The key of the new plan' }),
98
+ quantity: typebox_1.Type.Optional(typebox_1.Type.Integer({ minimum: 1 }))
99
+ }))
100
+ };
101
+ }