@adonis-agora/payments 0.2.0 → 0.4.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.
- package/CHANGELOG.md +2375 -0
- package/dist/assets/spa/assets/index-B7rU8eIL.css +2 -0
- package/dist/assets/spa/assets/index-BcM2VH5k.js +10 -0
- package/dist/assets/spa/assets/index-BcM2VH5k.js.map +1 -0
- package/dist/assets/spa/index.html +20 -0
- package/dist/commands/main.d.ts +4 -3
- package/dist/commands/main.d.ts.map +1 -1
- package/dist/commands/main.js +9 -2
- package/dist/commands/main.js.map +1 -1
- package/dist/commands/make_billable.d.ts.map +1 -1
- package/dist/commands/make_billable.js +1 -1
- package/dist/commands/make_billable.js.map +1 -1
- package/dist/commands/make_webhook_handler.d.ts.map +1 -1
- package/dist/commands/make_webhook_handler.js +1 -1
- package/dist/commands/make_webhook_handler.js.map +1 -1
- package/dist/commands/payments_health.d.ts +31 -0
- package/dist/commands/payments_health.d.ts.map +1 -0
- package/dist/commands/payments_health.js +113 -0
- package/dist/commands/payments_health.js.map +1 -0
- package/dist/commands/payments_sync.d.ts +18 -4
- package/dist/commands/payments_sync.d.ts.map +1 -1
- package/dist/commands/payments_sync.js +136 -40
- package/dist/commands/payments_sync.js.map +1 -1
- package/dist/commands/payments_webhook.d.ts.map +1 -1
- package/dist/commands/payments_webhook.js.map +1 -1
- package/dist/configure.d.ts +12 -5
- package/dist/configure.d.ts.map +1 -1
- package/dist/configure.js +18 -5
- package/dist/configure.js.map +1 -1
- package/dist/providers/dashboard_provider.d.ts +97 -0
- package/dist/providers/dashboard_provider.d.ts.map +1 -0
- package/dist/providers/dashboard_provider.js +430 -0
- package/dist/providers/dashboard_provider.js.map +1 -0
- package/dist/providers/payments_client_provider.d.ts +41 -0
- package/dist/providers/payments_client_provider.d.ts.map +1 -0
- package/dist/providers/payments_client_provider.js +95 -0
- package/dist/providers/payments_client_provider.js.map +1 -0
- package/dist/providers/payments_provider.d.ts +35 -0
- package/dist/providers/payments_provider.d.ts.map +1 -1
- package/dist/providers/payments_provider.js +250 -36
- package/dist/providers/payments_provider.js.map +1 -1
- package/dist/src/billing/billing_health.d.ts +85 -0
- package/dist/src/billing/billing_health.d.ts.map +1 -0
- package/dist/src/billing/billing_health.js +155 -0
- package/dist/src/billing/billing_health.js.map +1 -0
- package/dist/src/billing/billing_overview.d.ts +4 -3
- package/dist/src/billing/billing_overview.d.ts.map +1 -1
- package/dist/src/billing/billing_overview.js +14 -5
- package/dist/src/billing/billing_overview.js.map +1 -1
- package/dist/src/billing/billing_store.d.ts +634 -5
- package/dist/src/billing/billing_store.d.ts.map +1 -1
- package/dist/src/billing/billing_store.js +18 -1
- package/dist/src/billing/billing_store.js.map +1 -1
- package/dist/src/billing/index.d.ts +4 -3
- package/dist/src/billing/index.d.ts.map +1 -1
- package/dist/src/billing/index.js +2 -1
- package/dist/src/billing/index.js.map +1 -1
- package/dist/src/billing/list_query.d.ts +16 -0
- package/dist/src/billing/list_query.d.ts.map +1 -0
- package/dist/src/billing/list_query.js +28 -0
- package/dist/src/billing/list_query.js.map +1 -0
- package/dist/src/billing/lucid_billing_store.d.ts +122 -4
- package/dist/src/billing/lucid_billing_store.d.ts.map +1 -1
- package/dist/src/billing/lucid_billing_store.js +811 -13
- package/dist/src/billing/lucid_billing_store.js.map +1 -1
- package/dist/src/billing/mixins/index.d.ts +5 -2
- package/dist/src/billing/mixins/index.d.ts.map +1 -1
- package/dist/src/billing/mixins/index.js +5 -2
- package/dist/src/billing/mixins/index.js.map +1 -1
- package/dist/src/billing/mixins/with_audit_event.d.ts +48 -0
- package/dist/src/billing/mixins/with_audit_event.d.ts.map +1 -0
- package/dist/src/billing/mixins/with_audit_event.js +77 -0
- package/dist/src/billing/mixins/with_audit_event.js.map +1 -0
- package/dist/src/billing/mixins/with_billable.d.ts.map +1 -1
- package/dist/src/billing/mixins/with_customer.d.ts +39 -0
- package/dist/src/billing/mixins/with_customer.d.ts.map +1 -0
- package/dist/src/billing/mixins/with_customer.js +68 -0
- package/dist/src/billing/mixins/with_customer.js.map +1 -0
- package/dist/src/billing/mixins/with_dispute.d.ts +68 -0
- package/dist/src/billing/mixins/with_dispute.d.ts.map +1 -0
- package/dist/src/billing/mixins/with_dispute.js +83 -0
- package/dist/src/billing/mixins/with_dispute.js.map +1 -0
- package/dist/src/billing/mixins/with_payment.d.ts +42 -0
- package/dist/src/billing/mixins/with_payment.d.ts.map +1 -1
- package/dist/src/billing/mixins/with_payment.js +29 -3
- package/dist/src/billing/mixins/with_payment.js.map +1 -1
- package/dist/src/billing/mixins/with_subscription.d.ts +7 -0
- package/dist/src/billing/mixins/with_subscription.d.ts.map +1 -1
- package/dist/src/billing/mixins/with_subscription.js +15 -1
- package/dist/src/billing/mixins/with_subscription.js.map +1 -1
- package/dist/src/billing/mixins/with_usage_event.d.ts +7 -0
- package/dist/src/billing/mixins/with_usage_event.d.ts.map +1 -1
- package/dist/src/billing/mixins/with_usage_event.js +15 -1
- package/dist/src/billing/mixins/with_usage_event.js.map +1 -1
- package/dist/src/billing/mixins/with_webhook_event.d.ts +18 -0
- package/dist/src/billing/mixins/with_webhook_event.d.ts.map +1 -1
- package/dist/src/billing/mixins/with_webhook_event.js +18 -1
- package/dist/src/billing/mixins/with_webhook_event.js.map +1 -1
- package/dist/src/billing/resolve_dispatch.d.ts +22 -0
- package/dist/src/billing/resolve_dispatch.d.ts.map +1 -0
- package/dist/src/billing/resolve_dispatch.js +44 -0
- package/dist/src/billing/resolve_dispatch.js.map +1 -0
- package/dist/src/billing/resolve_store.d.ts +18 -0
- package/dist/src/billing/resolve_store.d.ts.map +1 -0
- package/dist/src/billing/resolve_store.js +35 -0
- package/dist/src/billing/resolve_store.js.map +1 -0
- package/dist/src/billing/schema.d.ts +108 -0
- package/dist/src/billing/schema.d.ts.map +1 -0
- package/dist/src/billing/schema.js +350 -0
- package/dist/src/billing/schema.js.map +1 -0
- package/dist/src/billing/webhook_dispatcher.d.ts +95 -16
- package/dist/src/billing/webhook_dispatcher.d.ts.map +1 -1
- package/dist/src/billing/webhook_dispatcher.js +186 -33
- package/dist/src/billing/webhook_dispatcher.js.map +1 -1
- package/dist/src/billing/webhook_events.d.ts +67 -1
- package/dist/src/billing/webhook_events.d.ts.map +1 -1
- package/dist/src/billing/webhook_events.js +15 -0
- package/dist/src/billing/webhook_events.js.map +1 -1
- package/dist/src/billing/webhook_processor.d.ts.map +1 -1
- package/dist/src/billing/webhook_processor.js +325 -5
- package/dist/src/billing/webhook_processor.js.map +1 -1
- package/dist/src/client/define_config.d.ts +150 -0
- package/dist/src/client/define_config.d.ts.map +1 -0
- package/dist/src/client/define_config.js +98 -0
- package/dist/src/client/define_config.js.map +1 -0
- package/dist/src/client/handlers.d.ts +71 -0
- package/dist/src/client/handlers.d.ts.map +1 -0
- package/dist/src/client/handlers.js +119 -0
- package/dist/src/client/handlers.js.map +1 -0
- package/dist/src/client/index.d.ts +15 -0
- package/dist/src/client/index.d.ts.map +1 -0
- package/dist/src/client/index.js +12 -0
- package/dist/src/client/index.js.map +1 -0
- package/dist/src/client/statuses.d.ts +38 -0
- package/dist/src/client/statuses.d.ts.map +1 -0
- package/dist/src/client/statuses.js +42 -0
- package/dist/src/client/statuses.js.map +1 -0
- package/dist/src/dashboard/actions.d.ts +143 -0
- package/dist/src/dashboard/actions.d.ts.map +1 -0
- package/dist/src/dashboard/actions.js +112 -0
- package/dist/src/dashboard/actions.js.map +1 -0
- package/dist/src/dashboard/auth.d.ts +136 -0
- package/dist/src/dashboard/auth.d.ts.map +1 -0
- package/dist/src/dashboard/auth.js +152 -0
- package/dist/src/dashboard/auth.js.map +1 -0
- package/dist/src/dashboard/define_config.d.ts +80 -0
- package/dist/src/dashboard/define_config.d.ts.map +1 -0
- package/dist/src/dashboard/define_config.js +83 -0
- package/dist/src/dashboard/define_config.js.map +1 -0
- package/dist/src/dashboard/handlers.d.ts +281 -0
- package/dist/src/dashboard/handlers.d.ts.map +1 -0
- package/dist/src/dashboard/handlers.js +960 -0
- package/dist/src/dashboard/handlers.js.map +1 -0
- package/dist/src/dashboard/index.d.ts +17 -0
- package/dist/src/dashboard/index.d.ts.map +1 -0
- package/dist/src/dashboard/index.js +13 -0
- package/dist/src/dashboard/index.js.map +1 -0
- package/dist/src/dashboard/login_page.d.ts +23 -0
- package/dist/src/dashboard/login_page.d.ts.map +1 -0
- package/dist/src/dashboard/login_page.js +170 -0
- package/dist/src/dashboard/login_page.js.map +1 -0
- package/dist/src/dashboard/period.d.ts +31 -0
- package/dist/src/dashboard/period.d.ts.map +1 -0
- package/dist/src/dashboard/period.js +44 -0
- package/dist/src/dashboard/period.js.map +1 -0
- package/dist/src/dashboard/session_cookie.d.ts +42 -0
- package/dist/src/dashboard/session_cookie.d.ts.map +1 -0
- package/dist/src/dashboard/session_cookie.js +97 -0
- package/dist/src/dashboard/session_cookie.js.map +1 -0
- package/dist/src/dashboard/spa.d.ts +24 -0
- package/dist/src/dashboard/spa.d.ts.map +1 -0
- package/dist/src/dashboard/spa.js +52 -0
- package/dist/src/dashboard/spa.js.map +1 -0
- package/dist/src/define_config.d.ts +245 -10
- package/dist/src/define_config.d.ts.map +1 -1
- package/dist/src/define_config.js +97 -1
- package/dist/src/define_config.js.map +1 -1
- package/dist/src/diagnostics.d.ts +287 -7
- package/dist/src/diagnostics.d.ts.map +1 -1
- package/dist/src/diagnostics.js +317 -1
- package/dist/src/diagnostics.js.map +1 -1
- package/dist/src/driver.d.ts +139 -5
- package/dist/src/driver.d.ts.map +1 -1
- package/dist/src/drivers/abacate.d.ts +13 -3
- package/dist/src/drivers/abacate.d.ts.map +1 -1
- package/dist/src/drivers/abacate.js +112 -19
- package/dist/src/drivers/abacate.js.map +1 -1
- package/dist/src/drivers/adyen.d.ts +164 -0
- package/dist/src/drivers/adyen.d.ts.map +1 -0
- package/dist/src/drivers/adyen.js +678 -0
- package/dist/src/drivers/adyen.js.map +1 -0
- package/dist/src/drivers/asaas.d.ts +53 -3
- package/dist/src/drivers/asaas.d.ts.map +1 -1
- package/dist/src/drivers/asaas.js +364 -29
- package/dist/src/drivers/asaas.js.map +1 -1
- package/dist/src/drivers/dodo.d.ts +135 -0
- package/dist/src/drivers/dodo.d.ts.map +1 -0
- package/dist/src/drivers/dodo.js +864 -0
- package/dist/src/drivers/dodo.js.map +1 -0
- package/dist/src/drivers/efi.d.ts +98 -0
- package/dist/src/drivers/efi.d.ts.map +1 -0
- package/dist/src/drivers/efi.js +628 -0
- package/dist/src/drivers/efi.js.map +1 -0
- package/dist/src/drivers/infinitepay.d.ts +156 -0
- package/dist/src/drivers/infinitepay.d.ts.map +1 -0
- package/dist/src/drivers/infinitepay.js +321 -0
- package/dist/src/drivers/infinitepay.js.map +1 -0
- package/dist/src/drivers/lemonsqueezy.d.ts +125 -0
- package/dist/src/drivers/lemonsqueezy.d.ts.map +1 -0
- package/dist/src/drivers/lemonsqueezy.js +632 -0
- package/dist/src/drivers/lemonsqueezy.js.map +1 -0
- package/dist/src/drivers/mercadopago.d.ts +97 -0
- package/dist/src/drivers/mercadopago.d.ts.map +1 -0
- package/dist/src/drivers/mercadopago.js +844 -0
- package/dist/src/drivers/mercadopago.js.map +1 -0
- package/dist/src/drivers/mollie.d.ts +125 -0
- package/dist/src/drivers/mollie.d.ts.map +1 -0
- package/dist/src/drivers/mollie.js +812 -0
- package/dist/src/drivers/mollie.js.map +1 -0
- package/dist/src/drivers/paddle.d.ts +148 -0
- package/dist/src/drivers/paddle.d.ts.map +1 -0
- package/dist/src/drivers/paddle.js +738 -0
- package/dist/src/drivers/paddle.js.map +1 -0
- package/dist/src/drivers/pagarme.d.ts +97 -0
- package/dist/src/drivers/pagarme.d.ts.map +1 -0
- package/dist/src/drivers/pagarme.js +829 -0
- package/dist/src/drivers/pagarme.js.map +1 -0
- package/dist/src/drivers/pagbank.d.ts +57 -0
- package/dist/src/drivers/pagbank.d.ts.map +1 -0
- package/dist/src/drivers/pagbank.js +499 -0
- package/dist/src/drivers/pagbank.js.map +1 -0
- package/dist/src/drivers/paypal.d.ts +120 -0
- package/dist/src/drivers/paypal.d.ts.map +1 -0
- package/dist/src/drivers/paypal.js +891 -0
- package/dist/src/drivers/paypal.js.map +1 -0
- package/dist/src/drivers/polar.d.ts +118 -0
- package/dist/src/drivers/polar.d.ts.map +1 -0
- package/dist/src/drivers/polar.js +604 -0
- package/dist/src/drivers/polar.js.map +1 -0
- package/dist/src/drivers/razorpay.d.ts +103 -0
- package/dist/src/drivers/razorpay.d.ts.map +1 -0
- package/dist/src/drivers/razorpay.js +867 -0
- package/dist/src/drivers/razorpay.js.map +1 -0
- package/dist/src/drivers/shared.d.ts +33 -0
- package/dist/src/drivers/shared.d.ts.map +1 -0
- package/dist/src/drivers/shared.js +37 -0
- package/dist/src/drivers/shared.js.map +1 -0
- package/dist/src/drivers/square.d.ts +133 -0
- package/dist/src/drivers/square.d.ts.map +1 -0
- package/dist/src/drivers/square.js +905 -0
- package/dist/src/drivers/square.js.map +1 -0
- package/dist/src/drivers/stripe.d.ts +41 -4
- package/dist/src/drivers/stripe.d.ts.map +1 -1
- package/dist/src/drivers/stripe.js +823 -26
- package/dist/src/drivers/stripe.js.map +1 -1
- package/dist/src/drivers/woovi.d.ts +11 -4
- package/dist/src/drivers/woovi.d.ts.map +1 -1
- package/dist/src/drivers/woovi.js +162 -29
- package/dist/src/drivers/woovi.js.map +1 -1
- package/dist/src/ensure_customer.d.ts +34 -1
- package/dist/src/ensure_customer.d.ts.map +1 -1
- package/dist/src/ensure_customer.js +29 -4
- package/dist/src/ensure_customer.js.map +1 -1
- package/dist/src/hooks/webhook_handlers.d.ts.map +1 -1
- package/dist/src/hooks/webhook_handlers.js.map +1 -1
- package/dist/src/http.d.ts +37 -3
- package/dist/src/http.d.ts.map +1 -1
- package/dist/src/http.js +69 -5
- package/dist/src/http.js.map +1 -1
- package/dist/src/index.d.ts +54 -26
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +29 -12
- package/dist/src/index.js.map +1 -1
- package/dist/src/invoice/drivers/asaas.d.ts.map +1 -1
- package/dist/src/invoice/drivers/asaas.js.map +1 -1
- package/dist/src/invoice/drivers/enotas.d.ts.map +1 -1
- package/dist/src/invoice/drivers/enotas.js.map +1 -1
- package/dist/src/invoice/drivers/focus.d.ts.map +1 -1
- package/dist/src/invoice/drivers/focus.js.map +1 -1
- package/dist/src/invoice/drivers/plugnotas.d.ts.map +1 -1
- package/dist/src/invoice/drivers/plugnotas.js.map +1 -1
- package/dist/src/invoice/drivers/tecnospeed.d.ts.map +1 -1
- package/dist/src/invoice/drivers/tecnospeed.js.map +1 -1
- package/dist/src/invoice/emit_invoice.d.ts.map +1 -1
- package/dist/src/invoice/emit_invoice.js +31 -11
- package/dist/src/invoice/emit_invoice.js.map +1 -1
- package/dist/src/invoice/invoice_manager.d.ts.map +1 -1
- package/dist/src/money.d.ts +23 -5
- package/dist/src/money.d.ts.map +1 -1
- package/dist/src/money.js +72 -7
- package/dist/src/money.js.map +1 -1
- package/dist/src/payments_manager.d.ts +8 -1
- package/dist/src/payments_manager.d.ts.map +1 -1
- package/dist/src/payments_manager.js +168 -6
- package/dist/src/payments_manager.js.map +1 -1
- package/dist/src/services/main.d.ts +38 -0
- package/dist/src/services/main.d.ts.map +1 -1
- package/dist/src/services/main.js +130 -0
- package/dist/src/services/main.js.map +1 -1
- package/dist/src/telescope/index.d.ts +2 -0
- package/dist/src/telescope/index.d.ts.map +1 -1
- package/dist/src/telescope/index.js +1 -0
- package/dist/src/telescope/index.js.map +1 -1
- package/dist/src/telescope/payments_watcher.d.ts +10 -4
- package/dist/src/telescope/payments_watcher.d.ts.map +1 -1
- package/dist/src/telescope/payments_watcher.js +66 -14
- package/dist/src/telescope/payments_watcher.js.map +1 -1
- package/dist/src/telescope/register.d.ts +62 -0
- package/dist/src/telescope/register.d.ts.map +1 -0
- package/dist/src/telescope/register.js +48 -0
- package/dist/src/telescope/register.js.map +1 -0
- package/dist/src/testing/fake_payments.d.ts +62 -0
- package/dist/src/testing/fake_payments.d.ts.map +1 -0
- package/dist/src/testing/fake_payments.js +82 -0
- package/dist/src/testing/fake_payments.js.map +1 -0
- package/dist/src/testing/fake_payments_driver.d.ts +1 -1
- package/dist/src/testing/fake_payments_driver.d.ts.map +1 -1
- package/dist/src/testing/fake_payments_driver.js.map +1 -1
- package/dist/src/testing/in_memory_billing_store.d.ts +151 -2
- package/dist/src/testing/in_memory_billing_store.d.ts.map +1 -1
- package/dist/src/testing/in_memory_billing_store.js +517 -4
- package/dist/src/testing/in_memory_billing_store.js.map +1 -1
- package/dist/src/testing/index.d.ts +3 -2
- package/dist/src/testing/index.d.ts.map +1 -1
- package/dist/src/testing/index.js +1 -0
- package/dist/src/testing/index.js.map +1 -1
- package/dist/src/testing/mutable_clock.d.ts.map +1 -1
- package/dist/src/types.d.ts +161 -5
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js +30 -1
- package/dist/src/types.js.map +1 -1
- package/dist/src/webhook_handlers.d.ts +96 -2
- package/dist/src/webhook_handlers.d.ts.map +1 -1
- package/dist/src/webhook_handlers.js +91 -10
- package/dist/src/webhook_handlers.js.map +1 -1
- package/dist/src/webhook_security.d.ts +94 -3
- package/dist/src/webhook_security.d.ts.map +1 -1
- package/dist/src/webhook_security.js +173 -9
- package/dist/src/webhook_security.js.map +1 -1
- package/dist/stubs/config/payments.stub +13 -0
- package/dist/stubs/config/payments_client.stub +42 -0
- package/dist/stubs/config/payments_dashboard.stub +38 -0
- package/dist/stubs/database/migrations/create_billing_tables.stub +35 -77
- package/dist/stubs/main.js.map +1 -1
- package/dist/stubs/make/webhook_handler/main.stub +29 -11
- package/package.json +67 -32
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"invoice_manager.d.ts","sourceRoot":"","sources":["../../../src/invoice/invoice_manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D,yFAAyF;AACzF,qBAAa,cAAc;;
|
|
1
|
+
{"version":3,"file":"invoice_manager.d.ts","sourceRoot":"","sources":["../../../src/invoice/invoice_manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D,yFAAyF;AACzF,qBAAa,cAAc;;IAGzB,YAAY,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,EAElD;IAED,+FAA+F;IAC/F,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,eAAe,CAUvC;CAWF;AAED,kDAAkD;AAClD,wBAAsB,uBAAuB,CAC3C,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC,CAQvC"}
|
package/dist/src/money.d.ts
CHANGED
|
@@ -1,11 +1,29 @@
|
|
|
1
1
|
import type { Money } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* How many decimal places a currency has. Defaults to 2 — the case for every currency not
|
|
4
|
+
* listed above, including BRL, USD and EUR.
|
|
5
|
+
*/
|
|
6
|
+
export declare function currencyExponent(currency: string | undefined): number;
|
|
2
7
|
/**
|
|
3
8
|
* Money helpers shared by the fetch-based drivers.
|
|
4
9
|
*
|
|
5
|
-
* The billing layer and the `PaymentsDriver` contract work in the currency's smallest
|
|
6
|
-
*
|
|
7
|
-
*
|
|
10
|
+
* The billing layer and the `PaymentsDriver` contract work in the currency's smallest unit;
|
|
11
|
+
* many gateway APIs (the Brazilian ones, Mollie, PayPal, Mercado Pago) want a decimal. This
|
|
12
|
+
* is the only place that mapping lives.
|
|
13
|
+
*
|
|
14
|
+
* `currency` is optional so the BRL-only drivers can keep calling these with one argument —
|
|
15
|
+
* but a **multi-currency** driver that omits it is asking for the ¥ bug above. Prefer
|
|
16
|
+
* {@link formatDecimal} when the gateway wants a string.
|
|
17
|
+
*/
|
|
18
|
+
export declare function toDecimal(amount: Money, currency?: string): number;
|
|
19
|
+
export declare function fromDecimal(value: number, currency?: string): Money;
|
|
20
|
+
/**
|
|
21
|
+
* The decimal string a gateway's JSON wants — `"19.90"`, `"1990"`, `"19.900"` — built from
|
|
22
|
+
* the integer without ever dividing.
|
|
23
|
+
*
|
|
24
|
+
* `toDecimal(x).toFixed(2)` goes through a binary float on the way to a decimal string,
|
|
25
|
+
* which is the classic way to ship `"19.89"`. Shifting the digits of an integer cannot
|
|
26
|
+
* round anywhere, so this is what drivers should use on the wire.
|
|
8
27
|
*/
|
|
9
|
-
export declare function
|
|
10
|
-
export declare function fromDecimal(value: number): Money;
|
|
28
|
+
export declare function formatDecimal(amount: Money, currency?: string): string;
|
|
11
29
|
//# sourceMappingURL=money.d.ts.map
|
package/dist/src/money.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"money.d.ts","sourceRoot":"","sources":["../../src/money.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"money.d.ts","sourceRoot":"","sources":["../../src/money.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAqCxC;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAGrE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAGlE;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,KAAK,CAGnE;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAOtE"}
|
package/dist/src/money.js
CHANGED
|
@@ -1,14 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ISO 4217 minor units, for the currencies where it is not 2.
|
|
3
|
+
*
|
|
4
|
+
* Dividing by 100 is right for most of the world and wrong in a way that succeeds for the
|
|
5
|
+
* rest: a ¥1990 charge sent as `19.90` is accepted by the gateway and bills a hundredth of
|
|
6
|
+
* what it should. Lowercase keys, because currencies travel lowercase through this package.
|
|
7
|
+
*/
|
|
8
|
+
const MINOR_UNITS = {
|
|
9
|
+
// Zero-decimal — the amount IS the integer; there is nothing to shift.
|
|
10
|
+
bif: 0,
|
|
11
|
+
clp: 0,
|
|
12
|
+
djf: 0,
|
|
13
|
+
gnf: 0,
|
|
14
|
+
isk: 0,
|
|
15
|
+
jpy: 0,
|
|
16
|
+
kmf: 0,
|
|
17
|
+
krw: 0,
|
|
18
|
+
pyg: 0,
|
|
19
|
+
rwf: 0,
|
|
20
|
+
ugx: 0,
|
|
21
|
+
vnd: 0,
|
|
22
|
+
vuv: 0,
|
|
23
|
+
xaf: 0,
|
|
24
|
+
xof: 0,
|
|
25
|
+
xpf: 0,
|
|
26
|
+
// Three-decimal.
|
|
27
|
+
bhd: 3,
|
|
28
|
+
iqd: 3,
|
|
29
|
+
jod: 3,
|
|
30
|
+
kwd: 3,
|
|
31
|
+
lyd: 3,
|
|
32
|
+
omr: 3,
|
|
33
|
+
tnd: 3,
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* How many decimal places a currency has. Defaults to 2 — the case for every currency not
|
|
37
|
+
* listed above, including BRL, USD and EUR.
|
|
38
|
+
*/
|
|
39
|
+
export function currencyExponent(currency) {
|
|
40
|
+
if (currency === undefined)
|
|
41
|
+
return 2;
|
|
42
|
+
return MINOR_UNITS[currency.toLowerCase()] ?? 2;
|
|
43
|
+
}
|
|
1
44
|
/**
|
|
2
45
|
* Money helpers shared by the fetch-based drivers.
|
|
3
46
|
*
|
|
4
|
-
* The billing layer and the `PaymentsDriver` contract work in the currency's smallest
|
|
5
|
-
*
|
|
6
|
-
*
|
|
47
|
+
* The billing layer and the `PaymentsDriver` contract work in the currency's smallest unit;
|
|
48
|
+
* many gateway APIs (the Brazilian ones, Mollie, PayPal, Mercado Pago) want a decimal. This
|
|
49
|
+
* is the only place that mapping lives.
|
|
50
|
+
*
|
|
51
|
+
* `currency` is optional so the BRL-only drivers can keep calling these with one argument —
|
|
52
|
+
* but a **multi-currency** driver that omits it is asking for the ¥ bug above. Prefer
|
|
53
|
+
* {@link formatDecimal} when the gateway wants a string.
|
|
7
54
|
*/
|
|
8
|
-
export function toDecimal(amount) {
|
|
9
|
-
|
|
55
|
+
export function toDecimal(amount, currency) {
|
|
56
|
+
const exponent = currencyExponent(currency);
|
|
57
|
+
return exponent === 0 ? amount : amount / 10 ** exponent;
|
|
58
|
+
}
|
|
59
|
+
export function fromDecimal(value, currency) {
|
|
60
|
+
const exponent = currencyExponent(currency);
|
|
61
|
+
return exponent === 0 ? Math.round(value) : Math.round(value * 10 ** exponent);
|
|
10
62
|
}
|
|
11
|
-
|
|
12
|
-
|
|
63
|
+
/**
|
|
64
|
+
* The decimal string a gateway's JSON wants — `"19.90"`, `"1990"`, `"19.900"` — built from
|
|
65
|
+
* the integer without ever dividing.
|
|
66
|
+
*
|
|
67
|
+
* `toDecimal(x).toFixed(2)` goes through a binary float on the way to a decimal string,
|
|
68
|
+
* which is the classic way to ship `"19.89"`. Shifting the digits of an integer cannot
|
|
69
|
+
* round anywhere, so this is what drivers should use on the wire.
|
|
70
|
+
*/
|
|
71
|
+
export function formatDecimal(amount, currency) {
|
|
72
|
+
const exponent = currencyExponent(currency);
|
|
73
|
+
const negative = amount < 0;
|
|
74
|
+
const digits = String(Math.abs(Math.trunc(amount))).padStart(exponent + 1, '0');
|
|
75
|
+
const whole = digits.slice(0, digits.length - exponent);
|
|
76
|
+
const fraction = exponent === 0 ? '' : `.${digits.slice(digits.length - exponent)}`;
|
|
77
|
+
return `${negative ? '-' : ''}${whole}${fraction}`;
|
|
13
78
|
}
|
|
14
79
|
//# sourceMappingURL=money.js.map
|
package/dist/src/money.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"money.js","sourceRoot":"","sources":["../../src/money.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CAAC,
|
|
1
|
+
{"version":3,"file":"money.js","sourceRoot":"","sources":["../../src/money.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,WAAW,GAA2B;IAC1C,uEAAuE;IACvE,GAAG,EAAE,CAAC;IACN,GAAG,EAAE,CAAC;IACN,GAAG,EAAE,CAAC;IACN,GAAG,EAAE,CAAC;IACN,GAAG,EAAE,CAAC;IACN,GAAG,EAAE,CAAC;IACN,GAAG,EAAE,CAAC;IACN,GAAG,EAAE,CAAC;IACN,GAAG,EAAE,CAAC;IACN,GAAG,EAAE,CAAC;IACN,GAAG,EAAE,CAAC;IACN,GAAG,EAAE,CAAC;IACN,GAAG,EAAE,CAAC;IACN,GAAG,EAAE,CAAC;IACN,GAAG,EAAE,CAAC;IACN,GAAG,EAAE,CAAC;IACN,iBAAiB;IACjB,GAAG,EAAE,CAAC;IACN,GAAG,EAAE,CAAC;IACN,GAAG,EAAE,CAAC;IACN,GAAG,EAAE,CAAC;IACN,GAAG,EAAE,CAAC;IACN,GAAG,EAAE,CAAC;IACN,GAAG,EAAE,CAAC;CACP,CAAC;AAEF;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,QAA4B;IAC3D,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO,CAAC,CAAC;IACrC,OAAO,WAAW,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,IAAI,CAAC,CAAC;AAClD,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,SAAS,CAAC,MAAa,EAAE,QAAiB;IACxD,MAAM,QAAQ,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IAC5C,OAAO,QA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private;
|
|
15
15
|
constructor(options: PaymentsManagerOptions);
|
|
16
|
+
/**
|
|
17
|
+
* Every configured driver, by the name it was configured under.
|
|
18
|
+
*
|
|
19
|
+
* Read-only, and there for the checks that have to look at all of them at once — the
|
|
20
|
+
* boot-time webhook-verification refusal is the one that needed it.
|
|
21
|
+
*/
|
|
22
|
+
get drivers(): ReadonlyMap<string, PaymentsDriver>;
|
|
16
23
|
/**
|
|
17
24
|
* Resolve a driver by payment method (e.g. `'pix'`), by provider name, or by the
|
|
18
25
|
* configured default when nothing is given.
|
|
@@ -33,7 +40,7 @@ export declare class PaymentsManager {
|
|
|
33
40
|
* Check a driver capability before delegating, so callers discover the limitation
|
|
34
41
|
* early (e.g. Woovi/OpenPix has no refunds) instead of at the gateway.
|
|
35
42
|
*/
|
|
36
|
-
assertCapability(driver: PaymentsDriver, capability: 'refunds' | 'invoices' | 'subscriptions'): void;
|
|
43
|
+
assertCapability(driver: PaymentsDriver, capability: 'refunds' | 'invoices' | 'subscriptions' | 'disputes'): void;
|
|
37
44
|
}
|
|
38
45
|
/** Build the driver map from config, resolving every configured factory. */
|
|
39
46
|
export declare function resolveDrivers(config: PaymentsConfig, invoices?: InvoiceManager): Promise<Map<string, PaymentsDriver>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"payments_manager.d.ts","sourceRoot":"","sources":["../../src/payments_manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"payments_manager.d.ts","sourceRoot":"","sources":["../../src/payments_manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,C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
+
/**
|
|
8
|
+
* Method-bound driver proxies, so repeated `driver('pix')` calls return the same object.
|
|
9
|
+
* Keyed by `name:method`, not method alone: the proxy closes over the name the routing
|
|
10
|
+
* check compares against, so caching by method would hand a second provider the first
|
|
11
|
+
* one's identity.
|
|
12
|
+
*/
|
|
13
|
+
#boundDrivers = new Map();
|
|
6
14
|
constructor(options) {
|
|
7
15
|
this.#drivers = options.drivers;
|
|
8
16
|
this.#invoices = options.invoices;
|
|
@@ -13,6 +21,15 @@ export class PaymentsManager {
|
|
|
13
21
|
}
|
|
14
22
|
this.#defaultName = options.defaultName ?? names[0];
|
|
15
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Every configured driver, by the name it was configured under.
|
|
26
|
+
*
|
|
27
|
+
* Read-only, and there for the checks that have to look at all of them at once — the
|
|
28
|
+
* boot-time webhook-verification refusal is the one that needed it.
|
|
29
|
+
*/
|
|
30
|
+
get drivers() {
|
|
31
|
+
return this.#drivers;
|
|
32
|
+
}
|
|
16
33
|
/**
|
|
17
34
|
* Resolve a driver by payment method (e.g. `'pix'`), by provider name, or by the
|
|
18
35
|
* configured default when nothing is given.
|
|
@@ -24,7 +41,7 @@ export class PaymentsManager {
|
|
|
24
41
|
* ```
|
|
25
42
|
*/
|
|
26
43
|
driver(methodOrName) {
|
|
27
|
-
const { name: resolved, method } = this.#resolveName(methodOrName);
|
|
44
|
+
const { name: resolved, method, unrouted } = this.#resolveName(methodOrName);
|
|
28
45
|
const driver = this.#drivers.get(resolved);
|
|
29
46
|
if (!driver) {
|
|
30
47
|
throw new Error(`[payments] Driver "${resolved}" is not configured. ` +
|
|
@@ -37,8 +54,118 @@ export class PaymentsManager {
|
|
|
37
54
|
`Supported methods: ${[...driver.supportedMethods].join(', ')}. ` +
|
|
38
55
|
`Route "${method}" to a different provider in config.methods.`);
|
|
39
56
|
}
|
|
57
|
+
// Routing picked the provider; it must also reach the charge. Without this the method
|
|
58
|
+
// is only ever set when the CALLER repeats it — `driver('pix').charge({ method: 'pix' })`
|
|
59
|
+
// — and every driver that varies by method (Stripe's `payment_method_types`, Asaas' and
|
|
60
|
+
// AbacatePay's `billingType`) silently fell back to the gateway's dashboard default. A
|
|
61
|
+
// charge routed as Pix could come back a card.
|
|
62
|
+
// `resolved` is the CONFIG KEY, not `driver.provider` — `config.methods` is written in
|
|
63
|
+
// terms of the keys under `config.providers`, and the two differ whenever an app names a
|
|
64
|
+
// provider something of its own (`providers: { primary: payments.stripe(…) }`). Passing
|
|
65
|
+
// the driver's own name here made the routing check compare "stripe" against "primary"
|
|
66
|
+
// and refuse a charge that was routed exactly right.
|
|
67
|
+
if (method !== undefined)
|
|
68
|
+
return this.#bound(driver, method, resolved);
|
|
69
|
+
// `driver()` with no argument used to skip `config.methods` entirely, which is the same
|
|
70
|
+
// trap one level up: an app that configured pix/credit_card/boleto routing and then
|
|
71
|
+
// calls `driver()` got a driver bound to NOTHING, and every charge fell back to the
|
|
72
|
+
// gateway's dashboard default unless the caller happened to repeat `method:`.
|
|
73
|
+
if (unrouted !== undefined)
|
|
74
|
+
return this.#unrouted(driver, resolved, unrouted);
|
|
75
|
+
// (`method === undefined` and no routing map entry: nothing to bind, nothing to check.)
|
|
40
76
|
return driver;
|
|
41
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* The default driver when `config.methods` is configured but this call named no method.
|
|
80
|
+
*
|
|
81
|
+
* Three cases, and only the first can be answered silently:
|
|
82
|
+
*
|
|
83
|
+
* - **Exactly one method routes here.** The routing is unambiguous, so it is applied — the
|
|
84
|
+
* same binding `driver('pix')` would have produced.
|
|
85
|
+
* - **Several methods route here.** There is no honest answer: `methods` says this provider
|
|
86
|
+
* takes pix AND boleto AND card, and picking one would be inventing the charge's payment
|
|
87
|
+
* method. The charge is refused with the two ways to say what you meant. It refuses at
|
|
88
|
+
* `charge`/`createSubscription` rather than at `driver()`, so the app that already passes
|
|
89
|
+
* `method:` on every call — which is what makes this correct today — keeps working
|
|
90
|
+
* unchanged.
|
|
91
|
+
* - **A method is passed that `methods` routes ELSEWHERE.** The routing map and the call
|
|
92
|
+
* disagree about where the money goes; that is a config error either way, and running it
|
|
93
|
+
* would send a card charge to the provider configured for Pix.
|
|
94
|
+
*/
|
|
95
|
+
#unrouted(driver, name, candidates) {
|
|
96
|
+
if (candidates.length === 1) {
|
|
97
|
+
return this.#bound(driver, candidates[0], name);
|
|
98
|
+
}
|
|
99
|
+
return new Proxy(driver, {
|
|
100
|
+
get: (target, property, _receiver) => {
|
|
101
|
+
const value = Reflect.get(target, property, target);
|
|
102
|
+
if (typeof value !== 'function')
|
|
103
|
+
return value;
|
|
104
|
+
if (property !== 'charge' && property !== 'createSubscription') {
|
|
105
|
+
return value.bind(target);
|
|
106
|
+
}
|
|
107
|
+
// `async`, so the refusal below is a rejected promise rather than a synchronous
|
|
108
|
+
// throw: every caller of `charge` awaits it, and a sync throw out of an awaited call
|
|
109
|
+
// skips a `.catch()` the caller reasonably attached.
|
|
110
|
+
return async (input, ...rest) => {
|
|
111
|
+
const method = input?.method;
|
|
112
|
+
if (method === undefined) {
|
|
113
|
+
throw new Error([
|
|
114
|
+
`[payments] driver() resolved "${name}", and config.methods routes`,
|
|
115
|
+
`${candidates.join(', ')} to it — so this ${String(property)} has no payment`,
|
|
116
|
+
'method and would fall back to whatever the gateway dashboard defaults to.',
|
|
117
|
+
`Name it: driver('${candidates[0]}') or`,
|
|
118
|
+
`${String(property)}({ method: '${candidates[0]}' }).`,
|
|
119
|
+
].join(' '));
|
|
120
|
+
}
|
|
121
|
+
this.#assertRoutedHere(method, name, String(property));
|
|
122
|
+
return value.call(target, input, ...rest);
|
|
123
|
+
};
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* The driver, with the routed method filled in on the inputs that carry one.
|
|
129
|
+
*
|
|
130
|
+
* A Proxy rather than a hand-written wrapper for one reason: the driver contract has
|
|
131
|
+
* optional members (`findDispute`, `submitDisputeEvidence`, `capabilities`), and callers
|
|
132
|
+
* test for them with `typeof driver.x === 'function'`. A wrapper that defines every method
|
|
133
|
+
* turns "this gateway cannot do that" into "it can, until you call it" — which is the class
|
|
134
|
+
* of bug this package keeps finding. A Proxy passes absence through as absence.
|
|
135
|
+
*
|
|
136
|
+
* Cached per method so `driver('pix') === driver('pix')` still holds. Note that a driver
|
|
137
|
+
* resolved by NAME is returned untouched: `driver('stripe')` routed nothing, so there is no
|
|
138
|
+
* method to thread and no reason to wrap.
|
|
139
|
+
*/
|
|
140
|
+
#bound(driver, method, name) {
|
|
141
|
+
const cacheKey = `${name ?? driver.provider}:${method}`;
|
|
142
|
+
const cached = this.#boundDrivers.get(cacheKey);
|
|
143
|
+
if (cached !== undefined)
|
|
144
|
+
return cached;
|
|
145
|
+
const bound = new Proxy(driver, {
|
|
146
|
+
// An arrow, so `this` is still the manager: the routing check below is its business.
|
|
147
|
+
get: (target, property, _receiver) => {
|
|
148
|
+
// Bound to `target`, never to the proxy: driver methods read `#private` fields, and
|
|
149
|
+
// a proxy is not the instance those belong to.
|
|
150
|
+
const value = Reflect.get(target, property, target);
|
|
151
|
+
if (typeof value !== 'function')
|
|
152
|
+
return value;
|
|
153
|
+
if (property !== 'charge' && property !== 'createSubscription') {
|
|
154
|
+
return value.bind(target);
|
|
155
|
+
}
|
|
156
|
+
return async (input, ...rest) => {
|
|
157
|
+
// An explicit method on the input wins. Routing is a default, not an override:
|
|
158
|
+
// `driver('pix')` picks the provider, and a caller who then names a method meant it
|
|
159
|
+
// — as long as the routing map does not send that method somewhere else.
|
|
160
|
+
const chosen = input?.method ?? method;
|
|
161
|
+
this.#assertRoutedHere(chosen, name ?? driver.provider, String(property));
|
|
162
|
+
return value.call(target, { ...input, method: chosen }, ...rest);
|
|
163
|
+
};
|
|
164
|
+
},
|
|
165
|
+
});
|
|
166
|
+
this.#boundDrivers.set(cacheKey, bound);
|
|
167
|
+
return bound;
|
|
168
|
+
}
|
|
42
169
|
/**
|
|
43
170
|
* Resolve an invoice provider by name (falls back to the configured default). Throws
|
|
44
171
|
* when no invoice provider is configured — a charge with `invoice: true` needs one.
|
|
@@ -56,14 +183,26 @@ export class PaymentsManager {
|
|
|
56
183
|
assertCapability(driver, capability) {
|
|
57
184
|
if (driver.capabilities?.[capability] === false ||
|
|
58
185
|
driver.capabilities?.[capability] === undefined) {
|
|
186
|
+
// Only the capabilities actually set to `true`. Listing every KEY meant a driver that
|
|
187
|
+
// spells out `{ invoices: false }` — as the newer ones do — had the capability it was
|
|
188
|
+
// just refused named back to it as supported.
|
|
189
|
+
const supported = Object.entries(driver.capabilities ?? {})
|
|
190
|
+
.filter(([, enabled]) => enabled === true)
|
|
191
|
+
.map(([name]) => name);
|
|
59
192
|
throw new Error(`[payments] Driver "${driver.provider}" does not support ${capability}. ` +
|
|
60
|
-
`Supported capabilities: ${
|
|
193
|
+
`Supported capabilities: ${supported.join(', ') || '(none)'}.`);
|
|
61
194
|
}
|
|
62
195
|
}
|
|
63
196
|
#resolveName(methodOrName) {
|
|
64
|
-
if (methodOrName === undefined)
|
|
65
|
-
|
|
66
|
-
|
|
197
|
+
if (methodOrName === undefined) {
|
|
198
|
+
const candidates = this.#methodsRoutedTo(this.#defaultName);
|
|
199
|
+
return candidates.length > 0
|
|
200
|
+
? { name: this.#defaultName, unrouted: candidates }
|
|
201
|
+
: { name: this.#defaultName };
|
|
202
|
+
}
|
|
203
|
+
// If it names a configured provider, use it directly. Naming the provider is an
|
|
204
|
+
// explicit choice, so `config.methods` is deliberately not consulted — it says which
|
|
205
|
+
// provider a METHOD goes to, and this call already answered that question.
|
|
67
206
|
if (this.#drivers.has(methodOrName))
|
|
68
207
|
return { name: methodOrName };
|
|
69
208
|
// Otherwise treat it as a payment method and route via config.methods.
|
|
@@ -73,7 +212,30 @@ export class PaymentsManager {
|
|
|
73
212
|
return { name: routed, method };
|
|
74
213
|
// Unknown method/name: throw a helpful error pointing at the routing config.
|
|
75
214
|
const providers = [...this.#drivers.keys()].join(', ') || '(none)';
|
|
76
|
-
throw new Error(`[payments] "${methodOrName}" is neither a configured provider nor a method routed in config.methods. Configured providers: ${providers}. Known methods:
|
|
215
|
+
throw new Error(`[payments] "${methodOrName}" is neither a configured provider nor a method routed in config.methods. Configured providers: ${providers}. Known methods: ${PAYMENT_METHOD_NAMES.join(', ')}.`);
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Refuse a call whose payment method `config.methods` routes to a DIFFERENT provider.
|
|
219
|
+
*
|
|
220
|
+
* The routing map and the call disagree about where the money goes. Running it anyway sends
|
|
221
|
+
* a card charge to the provider configured for Pix — the same class of silence as an
|
|
222
|
+
* unbound driver, one level up.
|
|
223
|
+
*/
|
|
224
|
+
#assertRoutedHere(method, name, operation) {
|
|
225
|
+
const routed = this.#methods[method];
|
|
226
|
+
if (routed === undefined || routed === name)
|
|
227
|
+
return;
|
|
228
|
+
throw new Error([
|
|
229
|
+
`[payments] config.methods routes "${method}" to "${routed}", but this ${operation} is`,
|
|
230
|
+
`going to "${name}". Call driver('${method}') to use the routed provider, or name the`,
|
|
231
|
+
`provider explicitly (driver('${name}')) if the override is deliberate.`,
|
|
232
|
+
].join(' '));
|
|
233
|
+
}
|
|
234
|
+
/** Which payment methods `config.methods` routes to a given provider. */
|
|
235
|
+
#methodsRoutedTo(name) {
|
|
236
|
+
return Object.entries(this.#methods)
|
|
237
|
+
.filter(([, provider]) => provider === name)
|
|
238
|
+
.map(([method]) => method);
|
|
77
239
|
}
|
|
78
240
|
}
|
|
79
241
|
/** Build the driver map from config, resolving every configured factory. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"payments_manager.js","sourceRoot":"","sources":["../../src/payments_manager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"payments_manager.js","sourceRoot":"","sources":["../../src/payments_manager.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAWlD,MAAM,OAAO,eAAe;IAC1B,QAAQ,CAA8B;IACtC,SAAS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5E,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,MAAsB,EACtB,QAAyB;IAEzB,MAAM,SAAS,GAAG,MAAM,CAAC,SAAS,IAAI,EAAE,CAAC;IACzC,MAAM,GAAG,GAAG;QACV,MAAM,EAAE,GAAG,EAAE,CAAC,MAAM;QACpB,qFAAqF;QACrF,sFAAsF;QACtF,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,IAAa,EAAE,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC3F,CAAC;IACF,MAAM,GAAG,GAAG,IAAI,GAAG,EAA0B,CAAC;IAC9C,KAAK,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;QACxD,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;IACpC,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -1,6 +1,44 @@
|
|
|
1
|
+
import type { BillingStore } from '../billing/billing_store.js';
|
|
2
|
+
import type { WebhookDispatcher } from '../billing/webhook_dispatcher.js';
|
|
3
|
+
import type { PaymentsDriver } from '../driver.js';
|
|
1
4
|
import { PaymentsManager } from '../payments_manager.js';
|
|
5
|
+
import type { PaymentMethodName } from '../types.js';
|
|
2
6
|
export declare function getPayments(): PaymentsManager;
|
|
7
|
+
/** The manager if there is one, without the throw — for callers that can handle absence. */
|
|
8
|
+
export declare function findPayments(): PaymentsManager | undefined;
|
|
3
9
|
/** Set by the provider once the manager is built. */
|
|
4
10
|
export declare function setPayments(manager: PaymentsManager): void;
|
|
11
|
+
export declare function getBillingStore(): BillingStore;
|
|
12
|
+
/** The store if there is one, without the throw. */
|
|
13
|
+
export declare function findBillingStore(): BillingStore | undefined;
|
|
14
|
+
/** Set by the provider once the store is resolved. */
|
|
15
|
+
export declare function setBillingStore(store: BillingStore): void;
|
|
16
|
+
export declare function getWebhookDispatcher(): WebhookDispatcher;
|
|
17
|
+
/** The dispatcher if there is one, without throwing — for callers that can do nothing. */
|
|
18
|
+
export declare function findWebhookDispatcher(): WebhookDispatcher | undefined;
|
|
19
|
+
/** Set by the provider once the billing layer is built. */
|
|
20
|
+
export declare function setWebhookDispatcher(dispatcher: WebhookDispatcher | undefined): void;
|
|
21
|
+
/** A {@link PaymentsManager} that resolves on first use. Safe in a field initializer. */
|
|
22
|
+
export declare function lazyPayments(): PaymentsManager;
|
|
23
|
+
/** The billing store, resolved on first use. Safe in a field initializer. */
|
|
24
|
+
export declare function lazyBillingStore(): BillingStore;
|
|
25
|
+
/**
|
|
26
|
+
* One driver — by method or by provider name — resolved on first use.
|
|
27
|
+
*
|
|
28
|
+
* The shape the ecosystem app actually wanted: `private driver = lazyPaymentsDriver('pix')`.
|
|
29
|
+
* Note the routing is resolved lazily too, so a driver named in `config.methods` does not
|
|
30
|
+
* have to exist yet when the field is initialized.
|
|
31
|
+
*/
|
|
32
|
+
export declare function lazyPaymentsDriver(methodOrName?: PaymentMethodName | string): PaymentsDriver;
|
|
33
|
+
/**
|
|
34
|
+
* Forget the resolved singletons.
|
|
35
|
+
*
|
|
36
|
+
* Exists for tests: `@adonis-agora/payments/testing`'s `swapPayments()` restores what was
|
|
37
|
+
* there before, and "before" is legitimately *nothing at all* — the app under test may never
|
|
38
|
+
* have booted a provider. Without this, a restore had to call `setPayments` with a value it
|
|
39
|
+
* did not have.
|
|
40
|
+
*/
|
|
41
|
+
export declare function resetPayments(): void;
|
|
42
|
+
export declare function resetBillingStore(): void;
|
|
5
43
|
export default getPayments;
|
|
6
44
|
//# sourceMappingURL=main.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../../src/services/main.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe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AAED,wBAAgB,iBAAiB,IAAI,IAAI,CAExC;eAEc,WAAW"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PaymentsManager } from '../payments_manager.js';
|
|
1
2
|
/**
|
|
2
3
|
* Lazy singleton accessor for the payments manager. Set by the provider when it builds
|
|
3
4
|
* the manager; importing this module never triggers the app boot (media/authkit pattern).
|
|
@@ -9,9 +10,138 @@ export function getPayments() {
|
|
|
9
10
|
}
|
|
10
11
|
return payments;
|
|
11
12
|
}
|
|
13
|
+
/** The manager if there is one, without the throw — for callers that can handle absence. */
|
|
14
|
+
export function findPayments() {
|
|
15
|
+
return payments;
|
|
16
|
+
}
|
|
12
17
|
/** Set by the provider once the manager is built. */
|
|
13
18
|
export function setPayments(manager) {
|
|
14
19
|
payments = manager;
|
|
15
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* The billing store the provider resolved from `config.billing.store` — the Lucid
|
|
23
|
+
* store over the published tables unless the app configured another one.
|
|
24
|
+
*
|
|
25
|
+
* `@inject()`-ing `LucidBillingStore` covers the default case; this accessor is what
|
|
26
|
+
* reaches a **custom** store, which has no class to use as a DI token.
|
|
27
|
+
*/
|
|
28
|
+
let billingStore;
|
|
29
|
+
export function getBillingStore() {
|
|
30
|
+
if (!billingStore) {
|
|
31
|
+
throw new Error('[payments] The billing store is not ready yet. Make sure the PaymentsProvider is registered, the app has booted, and `billing.enabled` is not false.');
|
|
32
|
+
}
|
|
33
|
+
return billingStore;
|
|
34
|
+
}
|
|
35
|
+
/** The store if there is one, without the throw. */
|
|
36
|
+
export function findBillingStore() {
|
|
37
|
+
return billingStore;
|
|
38
|
+
}
|
|
39
|
+
/** Set by the provider once the store is resolved. */
|
|
40
|
+
export function setBillingStore(store) {
|
|
41
|
+
billingStore = store;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The webhook dispatcher the provider built for this app, when the billing layer is on.
|
|
45
|
+
*
|
|
46
|
+
* Published for the same reason as the store: it is built inside the provider from config
|
|
47
|
+
* nothing else can reconstruct, and tests need to reach it — `flushWebhooks()` in
|
|
48
|
+
* `@adonis-agora/payments/testing` is the whole reason it is here.
|
|
49
|
+
*/
|
|
50
|
+
let webhookDispatcher;
|
|
51
|
+
export function getWebhookDispatcher() {
|
|
52
|
+
if (!webhookDispatcher) {
|
|
53
|
+
throw new Error('[payments] The webhook dispatcher is not ready yet. Make sure the PaymentsProvider is ' +
|
|
54
|
+
'registered, the app has booted, and `billing.enabled` is not false.');
|
|
55
|
+
}
|
|
56
|
+
return webhookDispatcher;
|
|
57
|
+
}
|
|
58
|
+
/** The dispatcher if there is one, without throwing — for callers that can do nothing. */
|
|
59
|
+
export function findWebhookDispatcher() {
|
|
60
|
+
return webhookDispatcher;
|
|
61
|
+
}
|
|
62
|
+
/** Set by the provider once the billing layer is built. */
|
|
63
|
+
export function setWebhookDispatcher(dispatcher) {
|
|
64
|
+
webhookDispatcher = dispatcher;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* A stand-in that resolves the real singleton on FIRST PROPERTY ACCESS, not when it is
|
|
68
|
+
* built.
|
|
69
|
+
*
|
|
70
|
+
* `getPayments()` throws until the provider's `booted()` hook runs, and providers that
|
|
71
|
+
* registered earlier boot first — `@adonis-agora/durable` boots workflows whose services are
|
|
72
|
+
* constructed before payments has set anything. So `private payments = getPayments()` in a
|
|
73
|
+
* constructor throws, and every app hits it: the ecosystem app that found this had the SAME
|
|
74
|
+
* four-line comment copy-pasted into four files explaining why it could not resolve in a
|
|
75
|
+
* constructor.
|
|
76
|
+
*
|
|
77
|
+
* These accessors make the field initializer safe. Nothing is resolved until the service
|
|
78
|
+
* actually CALLS something, which by definition happens after boot.
|
|
79
|
+
*
|
|
80
|
+
* ```ts
|
|
81
|
+
* export default class GrantAccess {
|
|
82
|
+
* #payments = lazyPayments() // safe in a field initializer
|
|
83
|
+
* #store = lazyBillingStore()
|
|
84
|
+
* #pix = lazyPaymentsDriver('pix')
|
|
85
|
+
* }
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* `getPayments()`/`getBillingStore()` are unchanged for callers that WANT the eager throw —
|
|
89
|
+
* a `start/` file asserting the wiring is right is a legitimate use of it.
|
|
90
|
+
*/
|
|
91
|
+
function lazyProxy(resolve, prototype) {
|
|
92
|
+
// `Object.create(prototype)` rather than `{}`: `instanceof PaymentsManager` and
|
|
93
|
+
// `Object.getPrototypeOf` then answer what a caller expects, and a Proxy may not lie about
|
|
94
|
+
// an invariant its target does not have.
|
|
95
|
+
return new Proxy(Object.create(prototype), {
|
|
96
|
+
get(_target, property) {
|
|
97
|
+
const instance = resolve();
|
|
98
|
+
const value = Reflect.get(instance, property, instance);
|
|
99
|
+
// Bound to the instance, never to the proxy: these classes read `#private` fields, and
|
|
100
|
+
// a proxy is not the object those belong to.
|
|
101
|
+
return typeof value === 'function' ? value.bind(instance) : value;
|
|
102
|
+
},
|
|
103
|
+
set(_target, property, value) {
|
|
104
|
+
return Reflect.set(resolve(), property, value);
|
|
105
|
+
},
|
|
106
|
+
has(_target, property) {
|
|
107
|
+
return Reflect.has(resolve(), property);
|
|
108
|
+
},
|
|
109
|
+
getPrototypeOf() {
|
|
110
|
+
return prototype;
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
/** A {@link PaymentsManager} that resolves on first use. Safe in a field initializer. */
|
|
115
|
+
export function lazyPayments() {
|
|
116
|
+
return lazyProxy(getPayments, PaymentsManager.prototype);
|
|
117
|
+
}
|
|
118
|
+
/** The billing store, resolved on first use. Safe in a field initializer. */
|
|
119
|
+
export function lazyBillingStore() {
|
|
120
|
+
return lazyProxy(getBillingStore, Object.prototype);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* One driver — by method or by provider name — resolved on first use.
|
|
124
|
+
*
|
|
125
|
+
* The shape the ecosystem app actually wanted: `private driver = lazyPaymentsDriver('pix')`.
|
|
126
|
+
* Note the routing is resolved lazily too, so a driver named in `config.methods` does not
|
|
127
|
+
* have to exist yet when the field is initialized.
|
|
128
|
+
*/
|
|
129
|
+
export function lazyPaymentsDriver(methodOrName) {
|
|
130
|
+
return lazyProxy(() => getPayments().driver(methodOrName), Object.prototype);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Forget the resolved singletons.
|
|
134
|
+
*
|
|
135
|
+
* Exists for tests: `@adonis-agora/payments/testing`'s `swapPayments()` restores what was
|
|
136
|
+
* there before, and "before" is legitimately *nothing at all* — the app under test may never
|
|
137
|
+
* have booted a provider. Without this, a restore had to call `setPayments` with a value it
|
|
138
|
+
* did not have.
|
|
139
|
+
*/
|
|
140
|
+
export function resetPayments() {
|
|
141
|
+
payments = undefined;
|
|
142
|
+
}
|
|
143
|
+
export function resetBillingStore() {
|
|
144
|
+
billingStore = undefined;
|
|
145
|
+
}
|
|
16
146
|
export default getPayments;
|
|
17
147
|
//# sourceMappingURL=main.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../../src/services/main.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../../src/services/main.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAGzD;;;GAGG;AACH,IAAI,QAAqC,CAAC;AAE1C,MAAM,UAAU,WAAW;IACzB,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CACb,mHAAmH,CACpH,CAAC;IACJ,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,4FAA4F;AAC5F,MAAM,UAAU,YAAY;IAC1B,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,qDAAqD;AACrD,MAAM,UAAU,WAAW,CAAC,OAAwB;IAClD,QAAQ,GAAG,OAAO,CAAC;AACrB,CAAC;AAED;;;;;;GAMG;AACH,IAAI,YAAsC,CAAC;AAE3C,MAAM,UAAU,eAAe;IAC7B,IAAI,C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AC;QACD,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,KAAK;YAC1B,OAAO,OAAO,CAAC,GAAG,CAAC,OAAO,EAAY,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;QAC3D,CAAC;QACD,GAAG,CAAC,OAAO,EAAE,QAAQ;YACnB,OAAO,OAAO,CAAC,GAAG,CAAC,OAAO,EAAY,EAAE,QAAQ,CAAC,CAAC;QACpD,CAAC;QACD,cAAc;YACZ,OAAO,SAAS,CAAC;QACnB,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAED,yFAAyF;AACzF,MAAM,UAAU,YAAY;IAC1B,OAAO,SAAS,CAAC,WAAW,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC;AAC3D,CAAC;AAED,6EAA6E;AAC7E,MAAM,UAAU,gBAAgB;IAC9B,OAAO,SAAS,CAAC,eAAe,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC;AACtD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAC,YAAyC;IAC1E,OAAO,SAAS,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC;AAC/E,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa;IAC3B,QAAQ,GAAG,SAAS,CAAC;AACvB,CAAC;AAED,MAAM,UAAU,iBAAiB;IAC/B,YAAY,GAAG,SAAS,CAAC;AAC3B,CAAC;AAED,eAAe,WAAW,CAAC"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export { PaymentsWatcher } from './payments_watcher.js';
|
|
2
|
+
export type { RegisteredWatcher, TelescopeRecorder } from './register.js';
|
|
3
|
+
export { registerPaymentsWatcher } from './register.js';
|
|
2
4
|
export type { WatcherContext } from './telescope-sdk.js';
|
|
3
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/telescope/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,YAAY,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/telescope/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,YAAY,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAC1E,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AACxD,YAAY,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC"}
|