@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,113 @@
1
+ import { GatewayCheckout, GatewayDispute, GatewayEventData, GatewayInvoice, GatewayPayment, GatewayPaymentMethod, GatewayRefund, GatewaySubscription, PaymentEventRecord, PaymentEventType, PaymentInvoiceRecord, PaymentMethodRecord, PaymentRecord, PaymentSubscriptionRecord, PaymentTransactionRecord } from '../types';
2
+ import { PaymentStore } from './payment-store';
3
+ /** The key of the metadata of a gateway payment naming its payment record. */
4
+ export declare const PAYMENT_METADATA_KEY = "appweaverPaymentId";
5
+ /** The key of the metadata of a gateway subscription naming its subscription record. */
6
+ export declare const SUBSCRIPTION_METADATA_KEY = "appweaverSubscriptionId";
7
+ /** The records an event of the payments is about, by their IDs. */
8
+ type EventRefs = Partial<Pick<PaymentEventRecord, 'userId' | 'paymentId' | 'transactionId' | 'paymentMethodId' | 'subscriptionId' | 'invoiceId'>>;
9
+ /** What applying an object of a gateway changed: its record, and the events to deliver once it is committed. */
10
+ export type Applied<T> = {
11
+ record: T | null;
12
+ events: PaymentEventRecord[];
13
+ };
14
+ /**
15
+ * Applies the objects of the gateways to the records, the only place moving their state: the answer of a call to a
16
+ * gateway, a webhook event and the reconciliation all go through it. An object is applied in a transaction with the
17
+ * events telling of the change, and applying it again changes nothing, so the events delivered twice or out of order
18
+ * are harmless. A state moves with a compare-and-set, so of two calls applying the same change only one records it.
19
+ */
20
+ export declare class PaymentSync {
21
+ private readonly _store;
22
+ constructor(_store: PaymentStore);
23
+ /**
24
+ * Applies the object of a webhook event.
25
+ *
26
+ * @param {string} provider - The name of the gateway.
27
+ * @param {GatewayEventData} data - The object of the event.
28
+ * @return {Promise<PaymentEventRecord[]>} The events to deliver.
29
+ */
30
+ apply(provider: string, data: GatewayEventData): Promise<PaymentEventRecord[]>;
31
+ /**
32
+ * Applies a payment of a gateway to its record: the one with its ID, the one its metadata or the given ID names,
33
+ * or a new one when the payment belongs to a known customer, i.e. the renewal of a subscription.
34
+ *
35
+ * @param {string} provider - The name of the gateway.
36
+ * @param {GatewayPayment} payment - The payment of the gateway.
37
+ * @param {string} [recordId] - The ID of the record of the payment, when the caller knows it.
38
+ * @return {Promise<Applied<PaymentRecord>>} The record, `null` for a payment of no known customer, and the events.
39
+ */
40
+ applyPayment(provider: string, payment: GatewayPayment, recordId?: string): Promise<Applied<PaymentRecord>>;
41
+ /**
42
+ * Applies a refund of a gateway to the ledger of its payment and to the refunded amount of the payment.
43
+ *
44
+ * @param {string} provider - The name of the gateway.
45
+ * @param {GatewayRefund} refund - The refund of the gateway.
46
+ * @return {Promise<Applied<PaymentTransactionRecord>>} The ledger entry, `null` for an unknown payment, and the
47
+ * events.
48
+ */
49
+ applyRefund(provider: string, refund: GatewayRefund): Promise<Applied<PaymentTransactionRecord>>;
50
+ /**
51
+ * Applies a dispute of a gateway to the ledger of its payment, and marks the payment as disputed while it is open
52
+ * or lost.
53
+ *
54
+ * @param {string} provider - The name of the gateway.
55
+ * @param {GatewayDispute} dispute - The dispute of the gateway.
56
+ * @return {Promise<Applied<PaymentTransactionRecord>>} The ledger entry, `null` for an unknown payment, and the
57
+ * events.
58
+ */
59
+ applyDispute(provider: string, dispute: GatewayDispute): Promise<Applied<PaymentTransactionRecord>>;
60
+ /**
61
+ * Applies a payment method of a gateway: saves it to the customer it is attached to, the first one as their
62
+ * default, or removes a detached one.
63
+ *
64
+ * @param {string} provider - The name of the gateway.
65
+ * @param {GatewayPaymentMethod} method - The payment method of the gateway.
66
+ * @param {boolean} [detached=false] - Whether the method was removed from its customer.
67
+ * @return {Promise<Applied<PaymentMethodRecord>>} The record, `null` for a method of no known customer, and the
68
+ * events.
69
+ */
70
+ applyPaymentMethod(provider: string, method: GatewayPaymentMethod, detached?: boolean): Promise<Applied<PaymentMethodRecord>>;
71
+ /**
72
+ * Applies a subscription of a gateway to its record: the one with its ID, the one its metadata or the given ID
73
+ * names, or a new one for a known customer. A canceled subscription never changes again.
74
+ *
75
+ * @param {string} provider - The name of the gateway.
76
+ * @param {GatewaySubscription} subscription - The subscription of the gateway.
77
+ * @param {Object} [options] - The ID of the record when the caller knows it, and whether the gateway announces
78
+ * the end of the trial.
79
+ * @return {Promise<Applied<PaymentSubscriptionRecord>>} The record, `null` for a subscription of no known
80
+ * customer, and the events.
81
+ */
82
+ applySubscription(provider: string, subscription: GatewaySubscription, options?: {
83
+ recordId?: string;
84
+ trialWillEnd?: boolean;
85
+ }): Promise<Applied<PaymentSubscriptionRecord>>;
86
+ /**
87
+ * Applies an invoice of a gateway to its record, linked to its subscription and to the payment collecting it.
88
+ *
89
+ * @param {string} provider - The name of the gateway.
90
+ * @param {GatewayInvoice} invoice - The invoice of the gateway.
91
+ * @return {Promise<Applied<PaymentInvoiceRecord>>} The record, `null` for an invoice of no known customer, and
92
+ * the events.
93
+ */
94
+ applyInvoice(provider: string, invoice: GatewayInvoice): Promise<Applied<PaymentInvoiceRecord>>;
95
+ /**
96
+ * Applies a hosted checkout that expired unpaid: cancels the payment or the subscription waiting for it.
97
+ *
98
+ * @param {string} provider - The name of the gateway.
99
+ * @param {GatewayCheckout} checkout - The expired checkout of the gateway.
100
+ * @return {Promise<PaymentEventRecord[]>} The events to deliver.
101
+ */
102
+ expireCheckout(provider: string, checkout: GatewayCheckout): Promise<PaymentEventRecord[]>;
103
+ /**
104
+ * Records an event of the payments, delivered to the handlers once the transaction writing it commits.
105
+ *
106
+ * @param {PaymentEventType} type - The type of the event.
107
+ * @param {string} provider - The name of the gateway of its records.
108
+ * @param {EventRefs} refs - The records the event is about.
109
+ * @return {Promise<PaymentEventRecord>} The stored event.
110
+ */
111
+ event(type: PaymentEventType, provider: string, refs: EventRefs): Promise<PaymentEventRecord>;
112
+ }
113
+ export {};