@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,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const core_1 = require("@appweaver/core");
4
+ const subscriptions_service_1 = require("../service/subscriptions-service");
5
+ /**
6
+ * Reads the recurring prices of the gateways into the plans users subscribe to: `weaver run payments-sync-plans`,
7
+ * or `weaver run payments-sync-plans stripe` for one gateway.
8
+ */
9
+ exports.default = (0, core_1.createTask)({
10
+ description: 'Reads the recurring prices of the payment gateways into the plans.',
11
+ arguments: {
12
+ gateway: {
13
+ description: 'The name of a gateway, every gateway without one.'
14
+ }
15
+ },
16
+ run: async ({ args }) => {
17
+ const plans = await (0, core_1.inject)(subscriptions_service_1.SubscriptionsService).syncPlans(args.gateway);
18
+ for (const plan of plans) {
19
+ console.log(`${plan.provider} ${plan.key}: ${plan.amount} ${plan.currency} every ${plan.intervalCount} ${plan.interval}${plan.active ? '' : ' (inactive)'}`);
20
+ }
21
+ console.log(`${plans.length} plans read`);
22
+ return 0;
23
+ }
24
+ });
@@ -0,0 +1,28 @@
1
+ {{#> layouts/email.html title=(t "emails.payments.actionRequired.subject" amount=amount plan=plan date=date)}}
2
+ <p>{{t "emails.greeting"}}</p>
3
+ <p>{{t "emails.payments.actionRequired.message" amount=amount plan=plan date=date}}</p>
4
+ <table
5
+ role="presentation"
6
+ width="100%"
7
+ cellpadding="0"
8
+ cellspacing="0"
9
+ style="margin: 24px 0; border-top: 1px solid #e4e7eb; font-size: 14px; line-height: 20px"
10
+ >
11
+ {{#if description}}
12
+ <tr>
13
+ <td style="padding: 10px 0; border-bottom: 1px solid #e4e7eb; color: #52606d">{{t "emails.payments.labels.description"}}</td>
14
+ <td style="padding: 10px 0; border-bottom: 1px solid #e4e7eb; text-align: right; color: #1f2933">{{description}}</td>
15
+ </tr>
16
+ {{/if}}
17
+ {{#if plan}}
18
+ <tr>
19
+ <td style="padding: 10px 0; border-bottom: 1px solid #e4e7eb; color: #52606d">{{t "emails.payments.labels.plan"}}</td>
20
+ <td style="padding: 10px 0; border-bottom: 1px solid #e4e7eb; text-align: right; color: #1f2933">{{plan}}</td>
21
+ </tr>
22
+ {{/if}}
23
+ </table>
24
+ {{#if link}}
25
+ {{> partials/email-button.html href=link label=(t "emails.payments.actionRequired.action")}}
26
+ {{/if}}
27
+ <p>{{t "emails.payments.actionRequired.hint"}}</p>
28
+ {{/layouts/email.html}}
@@ -0,0 +1 @@
1
+ {{t "emails.payments.actionRequired.subject" amount=amount plan=plan date=date}}
@@ -0,0 +1,37 @@
1
+ {{#> layouts/email.html title=(t "emails.payments.failed.subject" amount=amount plan=plan date=date)}}
2
+ <p>{{t "emails.greeting"}}</p>
3
+ <p>{{t "emails.payments.failed.message" amount=amount plan=plan date=date}}</p>
4
+ <table
5
+ role="presentation"
6
+ width="100%"
7
+ cellpadding="0"
8
+ cellspacing="0"
9
+ style="margin: 24px 0; border-top: 1px solid #e4e7eb; font-size: 14px; line-height: 20px"
10
+ >
11
+ {{#if description}}
12
+ <tr>
13
+ <td style="padding: 10px 0; border-bottom: 1px solid #e4e7eb; color: #52606d">{{t "emails.payments.labels.description"}}</td>
14
+ <td style="padding: 10px 0; border-bottom: 1px solid #e4e7eb; text-align: right; color: #1f2933">{{description}}</td>
15
+ </tr>
16
+ {{/if}}
17
+ {{#if plan}}
18
+ <tr>
19
+ <td style="padding: 10px 0; border-bottom: 1px solid #e4e7eb; color: #52606d">{{t "emails.payments.labels.plan"}}</td>
20
+ <td style="padding: 10px 0; border-bottom: 1px solid #e4e7eb; text-align: right; color: #1f2933">{{plan}}</td>
21
+ </tr>
22
+ {{/if}}
23
+ {{#if reason}}
24
+ <tr>
25
+ <td style="padding: 10px 0; border-bottom: 1px solid #e4e7eb; color: #52606d">{{t "emails.payments.labels.reason"}}</td>
26
+ <td style="padding: 10px 0; border-bottom: 1px solid #e4e7eb; text-align: right; color: #1f2933">{{reason}}</td>
27
+ </tr>
28
+ {{/if}}
29
+ {{#if retry}}
30
+ <tr>
31
+ <td style="padding: 10px 0; border-bottom: 1px solid #e4e7eb; color: #52606d">{{t "emails.payments.labels.retry"}}</td>
32
+ <td style="padding: 10px 0; border-bottom: 1px solid #e4e7eb; text-align: right; color: #1f2933">{{retry}}</td>
33
+ </tr>
34
+ {{/if}}
35
+ </table>
36
+ <p>{{t "emails.payments.failed.hint"}}</p>
37
+ {{/layouts/email.html}}
@@ -0,0 +1 @@
1
+ {{t "emails.payments.failed.subject" amount=amount plan=plan date=date}}
@@ -0,0 +1,45 @@
1
+ {{#> layouts/email.html title=(t "emails.payments.receipt.subject" amount=amount plan=plan date=date)}}
2
+ <p>{{t "emails.greeting"}}</p>
3
+ <p>{{t "emails.payments.receipt.message" amount=amount plan=plan date=date}}</p>
4
+ <table
5
+ role="presentation"
6
+ width="100%"
7
+ cellpadding="0"
8
+ cellspacing="0"
9
+ style="margin: 24px 0; border-top: 1px solid #e4e7eb; font-size: 14px; line-height: 20px"
10
+ >
11
+ {{#if description}}
12
+ <tr>
13
+ <td style="padding: 10px 0; border-bottom: 1px solid #e4e7eb; color: #52606d">{{t "emails.payments.labels.description"}}</td>
14
+ <td style="padding: 10px 0; border-bottom: 1px solid #e4e7eb; text-align: right; color: #1f2933">{{description}}</td>
15
+ </tr>
16
+ {{/if}}
17
+ {{#if plan}}
18
+ <tr>
19
+ <td style="padding: 10px 0; border-bottom: 1px solid #e4e7eb; color: #52606d">{{t "emails.payments.labels.plan"}}</td>
20
+ <td style="padding: 10px 0; border-bottom: 1px solid #e4e7eb; text-align: right; color: #1f2933">{{plan}}</td>
21
+ </tr>
22
+ {{/if}}
23
+ {{#if reference}}
24
+ <tr>
25
+ <td style="padding: 10px 0; border-bottom: 1px solid #e4e7eb; color: #52606d">{{t "emails.payments.labels.reference"}}</td>
26
+ <td style="padding: 10px 0; border-bottom: 1px solid #e4e7eb; text-align: right; color: #1f2933">{{reference}}</td>
27
+ </tr>
28
+ {{/if}}
29
+ {{#if method}}
30
+ <tr>
31
+ <td style="padding: 10px 0; border-bottom: 1px solid #e4e7eb; color: #52606d">{{t "emails.payments.labels.method"}}</td>
32
+ <td style="padding: 10px 0; border-bottom: 1px solid #e4e7eb; text-align: right; color: #1f2933">{{method}}</td>
33
+ </tr>
34
+ {{/if}}
35
+ {{#if date}}
36
+ <tr>
37
+ <td style="padding: 10px 0; border-bottom: 1px solid #e4e7eb; color: #52606d">{{t "emails.payments.labels.date"}}</td>
38
+ <td style="padding: 10px 0; border-bottom: 1px solid #e4e7eb; text-align: right; color: #1f2933">{{date}}</td>
39
+ </tr>
40
+ {{/if}}
41
+ </table>
42
+ {{#if receipt}}
43
+ {{> partials/email-button.html href=receipt label=(t "emails.payments.receipt.receipt")}}
44
+ {{/if}}
45
+ {{/layouts/email.html}}
@@ -0,0 +1 @@
1
+ {{t "emails.payments.receipt.subject" amount=amount plan=plan date=date}}
@@ -0,0 +1,37 @@
1
+ {{#> layouts/email.html title=(t "emails.payments.refunded.subject" amount=amount plan=plan date=date)}}
2
+ <p>{{t "emails.greeting"}}</p>
3
+ <p>{{t "emails.payments.refunded.message" amount=amount plan=plan date=date}}</p>
4
+ <table
5
+ role="presentation"
6
+ width="100%"
7
+ cellpadding="0"
8
+ cellspacing="0"
9
+ style="margin: 24px 0; border-top: 1px solid #e4e7eb; font-size: 14px; line-height: 20px"
10
+ >
11
+ {{#if description}}
12
+ <tr>
13
+ <td style="padding: 10px 0; border-bottom: 1px solid #e4e7eb; color: #52606d">{{t "emails.payments.labels.description"}}</td>
14
+ <td style="padding: 10px 0; border-bottom: 1px solid #e4e7eb; text-align: right; color: #1f2933">{{description}}</td>
15
+ </tr>
16
+ {{/if}}
17
+ {{#if reference}}
18
+ <tr>
19
+ <td style="padding: 10px 0; border-bottom: 1px solid #e4e7eb; color: #52606d">{{t "emails.payments.labels.reference"}}</td>
20
+ <td style="padding: 10px 0; border-bottom: 1px solid #e4e7eb; text-align: right; color: #1f2933">{{reference}}</td>
21
+ </tr>
22
+ {{/if}}
23
+ {{#if method}}
24
+ <tr>
25
+ <td style="padding: 10px 0; border-bottom: 1px solid #e4e7eb; color: #52606d">{{t "emails.payments.labels.method"}}</td>
26
+ <td style="padding: 10px 0; border-bottom: 1px solid #e4e7eb; text-align: right; color: #1f2933">{{method}}</td>
27
+ </tr>
28
+ {{/if}}
29
+ {{#if date}}
30
+ <tr>
31
+ <td style="padding: 10px 0; border-bottom: 1px solid #e4e7eb; color: #52606d">{{t "emails.payments.labels.date"}}</td>
32
+ <td style="padding: 10px 0; border-bottom: 1px solid #e4e7eb; text-align: right; color: #1f2933">{{date}}</td>
33
+ </tr>
34
+ {{/if}}
35
+ </table>
36
+ <p>{{t "emails.payments.refunded.hint"}}</p>
37
+ {{/layouts/email.html}}
@@ -0,0 +1 @@
1
+ {{t "emails.payments.refunded.subject" amount=amount plan=plan date=date}}
@@ -0,0 +1,24 @@
1
+ {{#> layouts/email.html title=(t "emails.payments.subscriptionCanceled.subject" amount=amount plan=plan date=date)}}
2
+ <p>{{t "emails.greeting"}}</p>
3
+ <p>{{t "emails.payments.subscriptionCanceled.message" amount=amount plan=plan date=date}}</p>
4
+ <table
5
+ role="presentation"
6
+ width="100%"
7
+ cellpadding="0"
8
+ cellspacing="0"
9
+ style="margin: 24px 0; border-top: 1px solid #e4e7eb; font-size: 14px; line-height: 20px"
10
+ >
11
+ {{#if plan}}
12
+ <tr>
13
+ <td style="padding: 10px 0; border-bottom: 1px solid #e4e7eb; color: #52606d">{{t "emails.payments.labels.plan"}}</td>
14
+ <td style="padding: 10px 0; border-bottom: 1px solid #e4e7eb; text-align: right; color: #1f2933">{{plan}}</td>
15
+ </tr>
16
+ {{/if}}
17
+ {{#if date}}
18
+ <tr>
19
+ <td style="padding: 10px 0; border-bottom: 1px solid #e4e7eb; color: #52606d">{{t "emails.payments.labels.date"}}</td>
20
+ <td style="padding: 10px 0; border-bottom: 1px solid #e4e7eb; text-align: right; color: #1f2933">{{date}}</td>
21
+ </tr>
22
+ {{/if}}
23
+ </table>
24
+ {{/layouts/email.html}}
@@ -0,0 +1 @@
1
+ {{t "emails.payments.subscriptionCanceled.subject" amount=amount plan=plan date=date}}
@@ -0,0 +1,25 @@
1
+ {{#> layouts/email.html title=(t "emails.payments.trialEnding.subject" amount=amount plan=plan date=date)}}
2
+ <p>{{t "emails.greeting"}}</p>
3
+ <p>{{t "emails.payments.trialEnding.message" amount=amount plan=plan date=date}}</p>
4
+ <table
5
+ role="presentation"
6
+ width="100%"
7
+ cellpadding="0"
8
+ cellspacing="0"
9
+ style="margin: 24px 0; border-top: 1px solid #e4e7eb; font-size: 14px; line-height: 20px"
10
+ >
11
+ {{#if plan}}
12
+ <tr>
13
+ <td style="padding: 10px 0; border-bottom: 1px solid #e4e7eb; color: #52606d">{{t "emails.payments.labels.plan"}}</td>
14
+ <td style="padding: 10px 0; border-bottom: 1px solid #e4e7eb; text-align: right; color: #1f2933">{{plan}}</td>
15
+ </tr>
16
+ {{/if}}
17
+ {{#if date}}
18
+ <tr>
19
+ <td style="padding: 10px 0; border-bottom: 1px solid #e4e7eb; color: #52606d">{{t "emails.payments.labels.date"}}</td>
20
+ <td style="padding: 10px 0; border-bottom: 1px solid #e4e7eb; text-align: right; color: #1f2933">{{date}}</td>
21
+ </tr>
22
+ {{/if}}
23
+ </table>
24
+ <p>{{t "emails.payments.trialEnding.hint"}}</p>
25
+ {{/layouts/email.html}}
@@ -0,0 +1 @@
1
+ {{t "emails.payments.trialEnding.subject" amount=amount plan=plan date=date}}
@@ -0,0 +1,36 @@
1
+ <!DOCTYPE html>
2
+ <html lang="{{@locale}}">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <title>{{title}}</title>
7
+ </head>
8
+ <body style="margin: 0; padding: 0; background-color: #f4f5f7">
9
+ <table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="background-color: #f4f5f7">
10
+ <tr>
11
+ <td align="center" style="padding: 32px 16px">
12
+ <table
13
+ role="presentation"
14
+ width="100%"
15
+ cellpadding="0"
16
+ cellspacing="0"
17
+ style="max-width: 560px; background-color: #ffffff; border-radius: 8px"
18
+ >
19
+ <tr>
20
+ <td
21
+ style="padding: 32px; font-family: Arial, Helvetica, sans-serif; font-size: 16px; line-height: 24px; color: #1f2933"
22
+ >
23
+ {{> @partial-block}}
24
+ </td>
25
+ </tr>
26
+ </table>
27
+ <p
28
+ style="margin: 16px 0 0; font-family: Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18px; color: #7b8794"
29
+ >
30
+ {{t "emails.footer" appName=@app.name}}
31
+ </p>
32
+ </td>
33
+ </tr>
34
+ </table>
35
+ </body>
36
+ </html>
@@ -0,0 +1,15 @@
1
+ <table role="presentation" cellpadding="0" cellspacing="0" style="margin: 24px 0">
2
+ <tr>
3
+ <td style="border-radius: 6px; background-color: #2563eb">
4
+ <a
5
+ href="{{href}}"
6
+ target="_blank"
7
+ style="display: inline-block; padding: 12px 24px; font-family: Arial, Helvetica, sans-serif; font-size: 16px; font-weight: bold; color: #ffffff; text-decoration: none; border-radius: 6px"
8
+ >{{label}}</a>
9
+ </td>
10
+ </tr>
11
+ </table>
12
+ <p style="font-size: 13px; line-height: 20px; color: #52606d">
13
+ {{t "emails.linkHint"}}<br />
14
+ <a href="{{href}}" style="color: #2563eb; word-break: break-all">{{href}}</a>
15
+ </p>