@owlmeans/server-payment 0.1.21 → 0.2.0-alpha.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 (296) hide show
  1. package/README.md +52 -54
  2. package/agent-meta/manifest.json +2 -2
  3. package/agent-meta/skills/server-payment/SKILL.md +272 -330
  4. package/agent-meta/skills/server-payment/parts/reference.md +3 -3
  5. package/build/access/types.d.ts +7 -16
  6. package/build/access/types.d.ts.map +1 -1
  7. package/build/access.d.ts.map +1 -1
  8. package/build/access.js +6 -8
  9. package/build/access.js.map +1 -1
  10. package/build/actions/resync.d.ts +3 -3
  11. package/build/actions/resync.js +5 -5
  12. package/build/actions/resync.js.map +1 -1
  13. package/build/actions/webhook.d.ts +4 -1
  14. package/build/actions/webhook.d.ts.map +1 -1
  15. package/build/actions/webhook.js +8 -4
  16. package/build/actions/webhook.js.map +1 -1
  17. package/build/bootstrap/types.d.ts +13 -7
  18. package/build/bootstrap/types.d.ts.map +1 -1
  19. package/build/bootstrap.d.ts +4 -4
  20. package/build/bootstrap.d.ts.map +1 -1
  21. package/build/bootstrap.js +19 -10
  22. package/build/bootstrap.js.map +1 -1
  23. package/build/catalogue/types.d.ts +3 -3
  24. package/build/catalogue/types.d.ts.map +1 -1
  25. package/build/catalogue.d.ts.map +1 -1
  26. package/build/catalogue.js +4 -8
  27. package/build/catalogue.js.map +1 -1
  28. package/build/checkout/types.d.ts +21 -0
  29. package/build/checkout/types.d.ts.map +1 -0
  30. package/build/{plugins/stripe → checkout}/types.js.map +1 -1
  31. package/build/checkout.d.ts +6 -0
  32. package/build/checkout.d.ts.map +1 -0
  33. package/build/checkout.js +374 -0
  34. package/build/checkout.js.map +1 -0
  35. package/build/config.d.ts +10 -16
  36. package/build/config.d.ts.map +1 -1
  37. package/build/config.js +18 -59
  38. package/build/config.js.map +1 -1
  39. package/build/consts.d.ts +3 -49
  40. package/build/consts.d.ts.map +1 -1
  41. package/build/consts.js +3 -61
  42. package/build/consts.js.map +1 -1
  43. package/build/consumer/cancellation/types.d.ts +6 -4
  44. package/build/consumer/cancellation/types.d.ts.map +1 -1
  45. package/build/consumer/cancellation.d.ts.map +1 -1
  46. package/build/consumer/cancellation.js +11 -5
  47. package/build/consumer/cancellation.js.map +1 -1
  48. package/build/consumer/capture/types.d.ts +8 -12
  49. package/build/consumer/capture/types.d.ts.map +1 -1
  50. package/build/consumer/capture.d.ts.map +1 -1
  51. package/build/consumer/capture.js +48 -53
  52. package/build/consumer/capture.js.map +1 -1
  53. package/build/consumer/index.d.ts +4 -0
  54. package/build/consumer/index.d.ts.map +1 -1
  55. package/build/consumer/index.js +2 -0
  56. package/build/consumer/index.js.map +1 -1
  57. package/build/consumer/reconcile.d.ts.map +1 -1
  58. package/build/consumer/reconcile.js +82 -72
  59. package/build/consumer/reconcile.js.map +1 -1
  60. package/build/consumer/records/types.d.ts +4 -4
  61. package/build/consumer/records/types.d.ts.map +1 -1
  62. package/build/consumer/records.d.ts.map +1 -1
  63. package/build/consumer/records.js +16 -13
  64. package/build/consumer/records.js.map +1 -1
  65. package/build/consumer/service.d.ts +2 -2
  66. package/build/consumer/service.d.ts.map +1 -1
  67. package/build/consumer/service.js +28 -21
  68. package/build/consumer/service.js.map +1 -1
  69. package/build/consumer/types.d.ts +1 -4
  70. package/build/consumer/types.d.ts.map +1 -1
  71. package/build/consumer/types.local.d.ts +1 -9
  72. package/build/consumer/types.local.d.ts.map +1 -1
  73. package/build/consumer/withdrawal/types.d.ts +14 -12
  74. package/build/consumer/withdrawal/types.d.ts.map +1 -1
  75. package/build/consumer/withdrawal.d.ts.map +1 -1
  76. package/build/consumer/withdrawal.js +55 -71
  77. package/build/consumer/withdrawal.js.map +1 -1
  78. package/build/index.d.ts +12 -6
  79. package/build/index.d.ts.map +1 -1
  80. package/build/index.js +7 -4
  81. package/build/index.js.map +1 -1
  82. package/build/paygate/providers.d.ts +13 -0
  83. package/build/paygate/providers.d.ts.map +1 -0
  84. package/build/paygate/providers.js +38 -0
  85. package/build/paygate/providers.js.map +1 -0
  86. package/build/paygate/registry.d.ts +6 -0
  87. package/build/paygate/registry.d.ts.map +1 -0
  88. package/build/paygate/registry.js +37 -0
  89. package/build/paygate/registry.js.map +1 -0
  90. package/build/paygate/types.d.ts +577 -0
  91. package/build/paygate/types.d.ts.map +1 -0
  92. package/build/{plugins/session → paygate}/types.js.map +1 -1
  93. package/build/plan/types.d.ts +6 -1
  94. package/build/plan/types.d.ts.map +1 -1
  95. package/build/plan.d.ts.map +1 -1
  96. package/build/plan.js +16 -2
  97. package/build/plan.js.map +1 -1
  98. package/build/plugins/checkout-policy/types.d.ts +5 -3
  99. package/build/plugins/checkout-policy/types.d.ts.map +1 -1
  100. package/build/plugins/checkout-policy.d.ts.map +1 -1
  101. package/build/plugins/checkout-policy.js +5 -3
  102. package/build/plugins/checkout-policy.js.map +1 -1
  103. package/build/plugins/consts.local.d.ts +8 -10
  104. package/build/plugins/consts.local.d.ts.map +1 -1
  105. package/build/plugins/consts.local.js +2 -19
  106. package/build/plugins/consts.local.js.map +1 -1
  107. package/build/plugins/customer-lock/types.d.ts +2 -2
  108. package/build/plugins/customer-lock/types.d.ts.map +1 -1
  109. package/build/plugins/customer-lock.js +2 -2
  110. package/build/plugins/customer-lock.js.map +1 -1
  111. package/build/plugins/estimate/cache.js +1 -1
  112. package/build/plugins/estimate/cache.js.map +1 -1
  113. package/build/plugins/estimate/types.d.ts +10 -10
  114. package/build/plugins/estimate/types.d.ts.map +1 -1
  115. package/build/plugins/estimate.d.ts.map +1 -1
  116. package/build/plugins/estimate.js +48 -122
  117. package/build/plugins/estimate.js.map +1 -1
  118. package/build/plugins/events/types.d.ts +17 -10
  119. package/build/plugins/events/types.d.ts.map +1 -1
  120. package/build/plugins/events.d.ts +6 -5
  121. package/build/plugins/events.d.ts.map +1 -1
  122. package/build/plugins/events.js +162 -173
  123. package/build/plugins/events.js.map +1 -1
  124. package/build/plugins/fx/types.d.ts +10 -21
  125. package/build/plugins/fx/types.d.ts.map +1 -1
  126. package/build/plugins/fx.d.ts +1 -1
  127. package/build/plugins/fx.d.ts.map +1 -1
  128. package/build/plugins/fx.js +17 -54
  129. package/build/plugins/fx.js.map +1 -1
  130. package/build/plugins/portal/types.d.ts +8 -37
  131. package/build/plugins/portal/types.d.ts.map +1 -1
  132. package/build/plugins/portal.d.ts.map +1 -1
  133. package/build/plugins/portal.js +38 -208
  134. package/build/plugins/portal.js.map +1 -1
  135. package/build/plugins/refunds/types.d.ts +11 -11
  136. package/build/plugins/refunds/types.d.ts.map +1 -1
  137. package/build/plugins/refunds.d.ts.map +1 -1
  138. package/build/plugins/refunds.js +14 -39
  139. package/build/plugins/refunds.js.map +1 -1
  140. package/build/plugins/snapshot/types.d.ts +11 -0
  141. package/build/plugins/snapshot/types.d.ts.map +1 -0
  142. package/build/plugins/snapshot/types.js +2 -0
  143. package/build/plugins/snapshot/types.js.map +1 -0
  144. package/build/plugins/snapshot.d.ts +4 -0
  145. package/build/plugins/snapshot.d.ts.map +1 -0
  146. package/build/plugins/snapshot.js +19 -0
  147. package/build/plugins/snapshot.js.map +1 -0
  148. package/build/plugins/subscriptions/types.d.ts +17 -17
  149. package/build/plugins/subscriptions/types.d.ts.map +1 -1
  150. package/build/plugins/subscriptions.d.ts +4 -4
  151. package/build/plugins/subscriptions.d.ts.map +1 -1
  152. package/build/plugins/subscriptions.js +69 -77
  153. package/build/plugins/subscriptions.js.map +1 -1
  154. package/build/plugins/types.local.d.ts +9 -43
  155. package/build/plugins/types.local.d.ts.map +1 -1
  156. package/build/plugins/webhook-manager/types.d.ts +15 -43
  157. package/build/plugins/webhook-manager/types.d.ts.map +1 -1
  158. package/build/plugins/webhook-manager.d.ts +3 -3
  159. package/build/plugins/webhook-manager.d.ts.map +1 -1
  160. package/build/plugins/webhook-manager.js +21 -199
  161. package/build/plugins/webhook-manager.js.map +1 -1
  162. package/build/protocol.d.ts +1 -1
  163. package/build/protocol.d.ts.map +1 -1
  164. package/build/protocol.js +1 -1
  165. package/build/protocol.js.map +1 -1
  166. package/build/service.d.ts +11 -11
  167. package/build/service.d.ts.map +1 -1
  168. package/build/service.js +59 -23
  169. package/build/service.js.map +1 -1
  170. package/build/sync/types.d.ts +17 -13
  171. package/build/sync/types.d.ts.map +1 -1
  172. package/build/sync.d.ts.map +1 -1
  173. package/build/sync.js +22 -122
  174. package/build/sync.js.map +1 -1
  175. package/build/types.d.ts +46 -101
  176. package/build/types.d.ts.map +1 -1
  177. package/build/utils/types.d.ts +0 -8
  178. package/build/utils/types.d.ts.map +1 -1
  179. package/build/utils.d.ts +1 -4
  180. package/build/utils.d.ts.map +1 -1
  181. package/build/utils.js +1 -15
  182. package/build/utils.js.map +1 -1
  183. package/package.json +20 -22
  184. package/src/access/types.ts +7 -16
  185. package/src/access.ts +7 -15
  186. package/src/actions/resync.ts +5 -5
  187. package/src/actions/webhook.ts +8 -4
  188. package/src/bootstrap/types.ts +13 -7
  189. package/src/bootstrap.ts +23 -13
  190. package/src/catalogue/types.ts +3 -3
  191. package/src/catalogue.ts +4 -8
  192. package/src/checkout/types.ts +21 -0
  193. package/src/checkout.ts +414 -0
  194. package/src/config.ts +19 -66
  195. package/src/consts.ts +3 -69
  196. package/src/consumer/cancellation/types.ts +6 -4
  197. package/src/consumer/cancellation.ts +13 -7
  198. package/src/consumer/capture/types.ts +8 -12
  199. package/src/consumer/capture.ts +50 -59
  200. package/src/consumer/index.ts +4 -0
  201. package/src/consumer/reconcile.ts +69 -68
  202. package/src/consumer/records/types.ts +4 -4
  203. package/src/consumer/records.ts +19 -14
  204. package/src/consumer/service.ts +35 -22
  205. package/src/consumer/types.local.ts +1 -8
  206. package/src/consumer/types.ts +1 -4
  207. package/src/consumer/withdrawal/types.ts +14 -12
  208. package/src/consumer/withdrawal.ts +61 -77
  209. package/src/index.ts +12 -6
  210. package/src/paygate/providers.ts +48 -0
  211. package/src/paygate/registry.ts +53 -0
  212. package/src/paygate/types.ts +640 -0
  213. package/src/plan/types.ts +6 -1
  214. package/src/plan.ts +21 -3
  215. package/src/plugins/checkout-policy/types.ts +5 -3
  216. package/src/plugins/checkout-policy.ts +6 -5
  217. package/src/plugins/consts.local.ts +2 -26
  218. package/src/plugins/customer-lock/types.ts +2 -2
  219. package/src/plugins/customer-lock.ts +2 -2
  220. package/src/plugins/estimate/cache.ts +1 -1
  221. package/src/plugins/estimate/types.ts +10 -10
  222. package/src/plugins/estimate.ts +52 -128
  223. package/src/plugins/events/types.ts +17 -9
  224. package/src/plugins/events.ts +172 -190
  225. package/src/plugins/fx/types.ts +10 -23
  226. package/src/plugins/fx.ts +28 -64
  227. package/src/plugins/portal/types.ts +8 -38
  228. package/src/plugins/portal.ts +48 -229
  229. package/src/plugins/refunds/types.ts +11 -11
  230. package/src/plugins/refunds.ts +16 -40
  231. package/src/plugins/snapshot/types.ts +11 -0
  232. package/src/plugins/snapshot.ts +22 -0
  233. package/src/plugins/subscriptions/types.ts +17 -17
  234. package/src/plugins/subscriptions.ts +81 -81
  235. package/src/plugins/types.local.ts +9 -33
  236. package/src/plugins/webhook-manager/types.ts +15 -43
  237. package/src/plugins/webhook-manager.ts +24 -220
  238. package/src/protocol.ts +1 -1
  239. package/src/service.ts +66 -30
  240. package/src/sync/types.ts +17 -13
  241. package/src/sync.ts +25 -143
  242. package/src/types.ts +47 -97
  243. package/src/utils/types.ts +0 -9
  244. package/src/utils.ts +2 -20
  245. package/tests/capabilities.spec.ts +219 -0
  246. package/tests/entitlement.spec.ts +4 -4
  247. package/tests/gate-handlers.spec.ts +6 -6
  248. package/tests/gate.spec.ts +2 -2
  249. package/tests/grants.spec.ts +2 -2
  250. package/tests/internal-plan.spec.ts +2 -2
  251. package/tests/limit-gate.spec.ts +2 -2
  252. package/tests/paygates.spec.ts +132 -0
  253. package/tests/protocol.spec.ts +4 -5
  254. package/tests/usage.spec.ts +2 -2
  255. package/tests/webhook.spec.ts +137 -0
  256. package/build/plugins/session/types.d.ts +0 -34
  257. package/build/plugins/session/types.d.ts.map +0 -1
  258. package/build/plugins/session.d.ts +0 -4
  259. package/build/plugins/session.d.ts.map +0 -1
  260. package/build/plugins/session.js +0 -71
  261. package/build/plugins/session.js.map +0 -1
  262. package/build/plugins/status.d.ts +0 -8
  263. package/build/plugins/status.d.ts.map +0 -1
  264. package/build/plugins/status.js +0 -21
  265. package/build/plugins/status.js.map +0 -1
  266. package/build/plugins/stripe/types.d.ts +0 -20
  267. package/build/plugins/stripe/types.d.ts.map +0 -1
  268. package/build/plugins/stripe.d.ts +0 -6
  269. package/build/plugins/stripe.d.ts.map +0 -1
  270. package/build/plugins/stripe.js +0 -518
  271. package/build/plugins/stripe.js.map +0 -1
  272. package/src/plugins/session/types.ts +0 -30
  273. package/src/plugins/session.ts +0 -86
  274. package/src/plugins/status.ts +0 -22
  275. package/src/plugins/stripe/types.ts +0 -20
  276. package/src/plugins/stripe.ts +0 -571
  277. package/tests/checkout-consumer.spec.ts +0 -366
  278. package/tests/checkout-locks.spec.ts +0 -161
  279. package/tests/checkout-plugins.spec.ts +0 -164
  280. package/tests/checkout.spec.ts +0 -313
  281. package/tests/consumer-events.spec.ts +0 -215
  282. package/tests/consumer-fixtures.ts +0 -141
  283. package/tests/consumer-ops.spec.ts +0 -361
  284. package/tests/consumer-rights.integration.spec.ts +0 -147
  285. package/tests/consumer-rights.spec.ts +0 -606
  286. package/tests/context.ts +0 -110
  287. package/tests/estimate.spec.ts +0 -350
  288. package/tests/events.spec.ts +0 -367
  289. package/tests/fake-stripe.ts +0 -1004
  290. package/tests/gateway-options.spec.ts +0 -180
  291. package/tests/portal.spec.ts +0 -202
  292. package/tests/sync.spec.ts +0 -114
  293. package/tests/usage.integration.spec.ts +0 -165
  294. package/tests/webhook-manager.spec.ts +0 -149
  295. /package/build/{plugins/session → checkout}/types.js +0 -0
  296. /package/build/{plugins/stripe → paygate}/types.js +0 -0
@@ -1,16 +1,5 @@
1
- import type Stripe from 'stripe'
2
-
3
- export interface StripeFxRate {
4
- fromCurrency: string
5
- toCurrency: string
6
- /** Stripe's fee-inclusive conversion rate (`base_rate × (1 − fx_fee_rate)`). */
7
- exchangeRate: number
8
- /** The rate before any fee (Stripe's `base_rate`; derived from `exchangeRate` and `fxFeeRate` when absent). */
9
- baseRate: number
10
- /** Market/reference rate used to translate catalogue value into settlement value. */
11
- referenceRate: number
12
- fxFeeRate?: number
13
- }
1
+ import type { Paygate } from '../../paygate/types.js'
2
+ import type { FxQuoteCache } from '../types.local.js'
14
3
 
15
4
  export interface SettlementAmount {
16
5
  amountMinor: number
@@ -20,21 +9,19 @@ export interface SettlementAmount {
20
9
  referenceRate: number
21
10
  }
22
11
 
23
- export type StripeFxRateCache = Map<string, Promise<StripeFxRate | null>>
24
-
25
- /** Currency conversion through Stripe's FX Quotes, under a context's pricing settings. */
12
+ /** Currency conversion through a paygate's FX quotes, under its settlement currency. */
26
13
  export interface FxHelper {
27
- /** One unlocked Stripe FX quote. `toCurrency` units per one `fromCurrency` unit. */
28
- stripeFxRate: (stripe: Stripe, fromCurrency: string, toCurrency: string, apiVersion: string) => Promise<StripeFxRate | null>
29
14
  /**
30
- * A catalogue amount in the currency the buyer is charged in: unchanged — no FX call — when the
31
- * currencies are equal; otherwise converted at Stripe's FX reference rate, rounded up.
15
+ * A catalogue amount in the currency the buyer is charged in: unchanged — no quote — when the
16
+ * currencies are equal; otherwise converted at the paygate's reference rate, rounded up.
17
+ *
18
+ * @throws PaygateError('fx-rate:<from>:<to>') when the paygate quotes no rate (or has no `fx`)
32
19
  */
33
20
  chargeAmount: (
34
- stripe: Stripe, sourceAmountMinor: number, sourceCurrency: string, chargeCurrency: string, cache?: StripeFxRateCache,
21
+ paygate: Paygate, sourceAmountMinor: number, sourceCurrency: string, chargeCurrency: string, cache?: FxQuoteCache,
35
22
  ) => Promise<SettlementAmount>
36
- /** Translate a catalogue amount into the configured Stripe settlement currency. */
23
+ /** Translate a catalogue amount into the paygate's settlement currency (unchanged when it declares none). */
37
24
  settlementAmount: (
38
- stripe: Stripe, sourceAmountMinor: number, sourceCurrency: string, cache?: StripeFxRateCache,
25
+ paygate: Paygate, sourceAmountMinor: number, sourceCurrency: string, cache?: FxQuoteCache,
39
26
  ) => Promise<SettlementAmount>
40
27
  }
package/src/plugins/fx.ts CHANGED
@@ -1,11 +1,9 @@
1
- import type Stripe from 'stripe'
2
1
  import { PaygateError } from '@owlmeans/payment'
3
2
  import type { Context as ApiContext } from '@owlmeans/server-api'
4
3
  import { memoHelper } from '@owlmeans/context'
5
- import { STRIPE_FX_QUOTES_API_VERSION } from '../consts.js'
6
- import type { FxQuoteResponse } from './types.local.js'
7
- import type { SettlementAmount, StripeFxRate, StripeFxRateCache, FxHelper } from './fx/types.js'
8
- import { paymentAccessOf } from '../access.js'
4
+ import type { FxQuote, Paygate } from '../paygate/types.js'
5
+ import type { FxQuoteCache } from './types.local.js'
6
+ import type { SettlementAmount, FxHelper } from './fx/types.js'
9
7
 
10
8
  /** Convert whole source minor units at the reference rate, rounding up so value is never lost. */
11
9
  const convertMinor = (amountMinor: number, rate: number): number => {
@@ -17,50 +15,28 @@ const convertMinor = (amountMinor: number, rate: number): number => {
17
15
  return converted
18
16
  }
19
17
 
20
- export const makeFxHelper = (ctx: ApiContext): FxHelper => {
21
- const access = paymentAccessOf(ctx)
22
-
23
- const stripeFxRate = async (
24
- stripe: Stripe, fromCurrency: string, toCurrency: string, apiVersion: string,
25
- ): Promise<StripeFxRate | null> => {
26
- const from = fromCurrency.toLowerCase()
27
- const to = toCurrency.toLowerCase()
28
- if (from === to) return { fromCurrency: from, toCurrency: to, exchangeRate: 1, baseRate: 1, referenceRate: 1 }
29
- const response = await stripe.rawRequest(
30
- 'POST', '/v1/fx_quotes',
31
- { to_currency: to, 'from_currencies[]': from, lock_duration: 'none' },
32
- { apiVersion },
33
- ) as Stripe.Response<FxQuoteResponse>
34
- const rate = response.rates?.[from]
35
- if (rate?.exchange_rate == null) return null
36
- return {
37
- fromCurrency: from,
38
- toCurrency: to,
39
- exchangeRate: rate.exchange_rate,
40
- baseRate: rate.rate_details?.base_rate ?? rate.exchange_rate / (1 - (rate.rate_details?.fx_fee_rate ?? 0)),
41
- referenceRate: rate.rate_details?.reference_rate ?? rate.rate_details?.base_rate ?? rate.exchange_rate,
42
- ...(rate.rate_details?.fx_fee_rate != null ? { fxFeeRate: rate.rate_details.fx_fee_rate } : {}),
18
+ export const makeFxHelper = (_ctx: ApiContext): FxHelper => {
19
+ /** One quote per (from, to) within a run that shares `cache`; a paygate without `fx`, or without a rate, refuses. */
20
+ const quoteOf = async (paygate: Paygate, from: string, to: string, cache?: FxQuoteCache): Promise<FxQuote> => {
21
+ const key = `${from}:${to}`
22
+ let pending = cache?.get(key)
23
+ if (pending == null) {
24
+ pending = paygate.fx != null ? paygate.fx.quote(from, to) : Promise.resolve(null)
25
+ cache?.set(key, pending)
43
26
  }
27
+ const quote = await pending
28
+ if (quote == null) throw new PaygateError(`fx-rate:${from}:${to}`)
29
+
30
+ return quote
44
31
  }
45
32
 
46
- const chargeAmount = async (
47
- stripe: Stripe, sourceAmountMinor: number, sourceCurrency: string, chargeCurrency: string,
48
- cache?: StripeFxRateCache,
33
+ const converted = async (
34
+ paygate: Paygate, sourceAmountMinor: number, source: string, currency: string, cache?: FxQuoteCache,
49
35
  ): Promise<SettlementAmount> => {
50
- const source = sourceCurrency.toLowerCase()
51
- const currency = chargeCurrency.toLowerCase()
52
36
  if (currency === source) {
53
37
  return { amountMinor: sourceAmountMinor, currency, sourceAmountMinor, sourceCurrency: source, referenceRate: 1 }
54
38
  }
55
- const apiVersion = (await access.stripePricingConfig())?.fxApiVersion ?? STRIPE_FX_QUOTES_API_VERSION
56
- const key = `${source}:${currency}:${apiVersion}`
57
- let pending = cache?.get(key)
58
- if (pending == null) {
59
- pending = stripeFxRate(stripe, source, currency, apiVersion)
60
- cache?.set(key, pending)
61
- }
62
- const quote = await pending
63
- if (quote == null) throw new PaygateError(`fx-rate:${source}:${currency}`)
39
+ const quote = await quoteOf(paygate, source, currency, cache)
64
40
 
65
41
  return {
66
42
  amountMinor: convertMinor(sourceAmountMinor, quote.referenceRate), currency,
@@ -68,33 +44,21 @@ export const makeFxHelper = (ctx: ApiContext): FxHelper => {
68
44
  }
69
45
  }
70
46
 
47
+ const chargeAmount = async (
48
+ paygate: Paygate, sourceAmountMinor: number, sourceCurrency: string, chargeCurrency: string, cache?: FxQuoteCache,
49
+ ): Promise<SettlementAmount> =>
50
+ await converted(paygate, sourceAmountMinor, sourceCurrency.toLowerCase(), chargeCurrency.toLowerCase(), cache)
51
+
71
52
  const settlementAmount = async (
72
- stripe: Stripe, sourceAmountMinor: number, sourceCurrency: string, cache?: StripeFxRateCache,
53
+ paygate: Paygate, sourceAmountMinor: number, sourceCurrency: string, cache?: FxQuoteCache,
73
54
  ): Promise<SettlementAmount> => {
74
55
  const source = sourceCurrency.toLowerCase()
75
- const pricing = await access.stripePricingConfig()
76
- const currency = pricing?.settlementCurrency?.toLowerCase() ?? source
77
- if (currency === source) {
78
- return {
79
- amountMinor: sourceAmountMinor, currency, sourceAmountMinor, sourceCurrency: source, referenceRate: 1,
80
- }
81
- }
82
- const apiVersion = pricing?.fxApiVersion ?? STRIPE_FX_QUOTES_API_VERSION
83
- const key = `${source}:${currency}:${apiVersion}`
84
- let pending = cache?.get(key)
85
- if (pending == null) {
86
- pending = stripeFxRate(stripe, source, currency, apiVersion)
87
- cache?.set(key, pending)
88
- }
89
- const quote = await pending
90
- if (quote == null) throw new PaygateError(`fx-rate:${source}:${currency}`)
91
- return {
92
- amountMinor: convertMinor(sourceAmountMinor, quote.referenceRate), currency,
93
- sourceAmountMinor, sourceCurrency: source, referenceRate: quote.referenceRate,
94
- }
56
+ const currency = (await paygate.settlementCurrency())?.toLowerCase() ?? source
57
+
58
+ return await converted(paygate, sourceAmountMinor, source, currency, cache)
95
59
  }
96
60
 
97
- return { stripeFxRate, chargeAmount, settlementAmount }
61
+ return { chargeAmount, settlementAmount }
98
62
  }
99
63
 
100
64
  /** The FX conversion of a context — one per context. */
@@ -1,45 +1,15 @@
1
- import type Stripe from 'stripe'
2
1
  import type { PortalLinkOptions } from '../../types.js'
3
2
 
4
- export interface EnsurePortalOptions {
5
- force?: boolean
6
- }
7
-
8
- /** The Stripe customer portal of a deployment: its configuration and its sessions. */
3
+ /** The customer portal of a context: which paygate, customer and subscription a portal session opens on. */
9
4
  export interface PortalHelper {
10
- /** The fingerprint sku of an owner's portal configuration: `portal:<owner>`. */
11
- portalFingerprintSku: (owner: string) => string
12
- /**
13
- * Keep this deployment's own Stripe customer-portal configuration: customer, invoice and payment
14
- * method self-service, cancellation at period end, and switching between the active recurring
15
- * prices of every product sold through Stripe (both subscription features off when there are none).
16
- * The customer may edit their tax id always, their e-mail unless `stripe.lockCustomerEmail`, their
17
- * address unless the consumer-rights `countryLock` or `stripe.lockCustomerCountry`.
18
- *
19
- * A deployment's identity is its webhook URL (`webhookUrlOf`, on the gateway's `webhookService`) —
20
- * also when that URL is undeliverable, as on a local run; its fingerprint row and label carry the
21
- * gateway's `owner` (`gatewayOwnerOf`). Several deployments of one application may share a Stripe
22
- * account, so each owns a configuration of its own, tagged
23
- * `{ owlmeans: 'payment', service: <owner>, deployment: <webhook URL> }`.
24
- *
25
- * - An unchanged declaration (catalogue, branding, deployment key) makes no paygate call.
26
- * - The configuration the `portal:<owner>` fingerprint row names is updated in place — unless its
27
- * metadata tags it for another deployment (a moved webhook URL included), which is never
28
- * overwritten; this deployment then proceeds as though it held no row.
29
- * - Without a usable row, an active configuration tagged with exactly this owner and deployment
30
- * key is adopted. Nothing else is: not an untagged one, not one carrying only the owner label,
31
- * not one tagged for another deployment.
32
- * - Otherwise a new configuration is created. Stripe cannot delete a portal configuration, so one
33
- * this deployment can no longer identify stays in the account, and a lost row creates a new one
34
- * unless its tagged configuration is found.
35
- */
36
- ensurePortalConfiguration: (stripe: Stripe, opts?: EnsurePortalOptions) => Promise<string | null>
37
5
  /**
38
- * A Stripe customer-portal session for one entity. `Manage` opens the portal home and
39
- * `PaymentMethod` the payment method form; `Cancel`, `Update` and `Change` act on the entity's
40
- * entitling Stripe subscription (`Change` confirms a switch of its one item to `planSku`'s price).
6
+ * A customer-portal session for one entity, through `opts.paygate`, else the paygate of the
7
+ * entity's entitling subscription, else the first registered paygate holding a customer of the
8
+ * entity. `Manage` opens the portal home and `PaymentMethod` the payment method form; `Cancel`,
9
+ * `Update` and `Change` act on the entity's entitling subscription of that paygate (`Change`
10
+ * confirms a switch of its one item to `planSku`'s price).
41
11
  *
42
- * @throws PortalUnavailable('customer' | 'subscription' | 'plan' | 'item')
12
+ * @throws PortalUnavailable('customer' | 'paygate' | 'subscription' | 'plan' | 'item') | UnknownPlan
43
13
  */
44
- createPortalLink: (stripe: Stripe, entityId: string, opts: PortalLinkOptions) => Promise<string>
14
+ createPortalLink: (entityId: string, opts: PortalLinkOptions) => Promise<string>
45
15
  }
@@ -1,239 +1,78 @@
1
- import { createHash } from 'node:crypto'
2
- import type Stripe from 'stripe'
3
- import { ENTITLING_STATUSES, PortalFlow, PortalUnavailable, ProductError, UnknownPlan } from '@owlmeans/payment'
1
+ import { ENTITLING_STATUSES, INTERNAL_PAYGATE, PortalFlow, PortalUnavailable, UnknownPlan } from '@owlmeans/payment'
4
2
  import type { Context as ApiContext } from '@owlmeans/server-api'
5
3
  import { memoHelper } from '@owlmeans/context'
6
- import {
7
- FINGERPRINT_PORTAL, STRIPE_DEPLOYMENT_KEY, STRIPE_OWNER_KEY, STRIPE_OWNER_VALUE, STRIPE_PAYGATE_ALIAS,
8
- } from '../consts.js'
9
- import type { PaymentProduct, PaymentSubscriptionRecord, PortalLinkOptions } from '../types.js'
10
- import { log } from '../log.js'
11
- import type { Claim, ConfigurationParams } from './types.local.js'
12
- import type { EnsurePortalOptions, PortalHelper } from './portal/types.js'
4
+ import type { PaygateCustomerRecord, PaymentSubscriptionRecord, PortalLinkOptions } from '../types.js'
5
+ import type { Paygate, PortalSessionInput } from '../paygate/types.js'
6
+ import type { PortalHelper } from './portal/types.js'
13
7
  import { paymentAccessOf } from '../access.js'
14
- import { paymentUtils } from '../utils.js'
15
8
  import { catalogueOf } from '../catalogue.js'
16
9
  import { planHelper } from '../plan.js'
10
+ import { paygatesOf } from '../paygate/registry.js'
17
11
  import { webhookOf } from './webhook-manager.js'
18
-
19
- /** The fingerprint sku of an owner's portal configuration: `portal:<owner>`. */
20
- const portalFingerprintSku = (owner: string): string => `${FINGERPRINT_PORTAL}:${owner}`
21
-
22
- /**
23
- * Whose a configuration is by its metadata: `ours` carries this owner AND this deployment's key;
24
- * `foreign` is tagged for another deployment or another owner; `unclaimed` names no deployment.
25
- */
26
- const claimOf = (metadata: Stripe.Metadata | null | undefined, owner: string, deployment: string): Claim => {
27
- const owned = metadata?.[STRIPE_OWNER_KEY] === STRIPE_OWNER_VALUE
28
- const tagged = metadata?.[STRIPE_DEPLOYMENT_KEY]
29
- if (owned && metadata?.service === owner && tagged === deployment) {
30
- return 'ours'
31
- }
32
- if ((owned && metadata?.service !== owner) || (tagged != null && tagged !== '')) {
33
- return 'foreign'
34
- }
35
-
36
- return 'unclaimed'
37
- }
12
+ import { ENTITLING_SORT } from './consts.local.js'
38
13
 
39
14
  export const makePortalHelper = (ctx: ApiContext): PortalHelper => {
40
15
  const access = paymentAccessOf(ctx)
41
16
 
42
- /** The recurring plans sold through Stripe, per product — what the portal may switch between. */
43
- const recurringCatalog = async (): Promise<Array<{ product: PaymentProduct, lookupKeys: string[], hashable: unknown[] }>> => {
44
- // The declared tax behavior decides which Stripe price id `sync.ts` keeps for a plan (an
45
- // in-place `unspecified` update keeps it, an opposite behavior replaces it) — hashed here too,
46
- // so a behavior change refreshes this configuration's `products[].prices` to the new ids.
47
- const behavior = (await access.payment().pricingPolicy()).tax.behavior ?? null
48
- const result: Array<{ product: PaymentProduct, lookupKeys: string[], hashable: unknown[] }> = []
49
- for (const { product, plans } of await catalogueOf(ctx).stripePlansOf()) {
50
- const recurring = plans.filter(plan => plan.recurring != null)
51
- if (recurring.length === 0) {
52
- continue
53
- }
54
- result.push({
55
- product,
56
- lookupKeys: recurring.map(plan => planHelper.planLookupKey(product, plan)),
57
- hashable: recurring.map(plan => ({
58
- sku: plan.sku, price: plan.price, currency: plan.currency ?? 'usd', interval: plan.recurring?.interval,
59
- rank: planHelper.planRank(plan), behavior,
60
- // A changed currency option replaces the Price — the portal's price list must follow it.
61
- ...(plan.currencyPrices != null ? { currencyPrices: plan.currencyPrices } : {}),
62
- })).sort((a, b) => a.sku.localeCompare(b.sku)),
63
- })
64
- }
65
-
66
- return result.sort((a, b) => a.product.sku.localeCompare(b.product.sku))
67
- }
68
-
69
- const activeRecurringPrices = async (stripe: Stripe, productSku: string): Promise<Stripe.Price[]> =>
70
- (await stripe.prices.list({ product: productSku, active: true, limit: 100 })).data
71
- .filter(price => price.recurring != null)
72
-
73
- const listActiveConfigurations = async (stripe: Stripe): Promise<Stripe.BillingPortal.Configuration[]> => {
74
- const configurations: Stripe.BillingPortal.Configuration[] = []
75
- let startingAfter: string | undefined
76
- for (;;) {
77
- const page = await stripe.billingPortal.configurations.list({
78
- active: true, limit: 100, ...(startingAfter != null ? { starting_after: startingAfter } : {}),
79
- })
80
- configurations.push(...page.data)
81
- if (!page.has_more || page.data.length === 0) {
82
- return configurations
83
- }
84
- startingAfter = page.data[page.data.length - 1].id
85
- }
86
- }
87
-
88
- const ensurePortalConfiguration = async (stripe: Stripe, opts: EnsurePortalOptions = {}): Promise<string | null> => {
89
- const owner = webhookOf(ctx).gatewayOwnerOf()
90
- const deployment = webhookOf(ctx).webhookUrlOf()
91
- const sku = portalFingerprintSku(owner)
92
- const branding = await access.portalBrandingConfig()
93
- const catalog = await recurringCatalog()
94
- const rights = await access.payment().consumerRightsPolicy()
95
- // A locked billing country is never edited in the portal: tax follows the saved address.
96
- const stripeConfig = await access.stripePricingConfig()
97
- const countryLock = rights?.mechanisms.countryLock === true
98
- // A pinned country and a locked customer e-mail are the application's: never edited in the portal.
99
- const countryPin = stripeConfig?.lockCustomerCountry === true
100
- const emailLock = stripeConfig?.lockCustomerEmail === true
101
- const regionCurrencies = Object.values(rights?.currencies ?? {}).filter(code => code != null).sort()
102
- const hash = createHash('sha256').update(JSON.stringify({
103
- service: owner,
104
- deployment,
105
- ...(countryLock ? { countryLock } : {}),
106
- ...(countryPin ? { countryPin } : {}),
107
- ...(emailLock ? { emailLock } : {}),
108
- ...(regionCurrencies.length > 0 ? { regionCurrencies } : {}),
109
- branding: branding != null ? {
110
- headline: branding.headline ?? null, privacyPolicyUrl: branding.privacyPolicyUrl ?? null,
111
- termsOfServiceUrl: branding.termsOfServiceUrl ?? null, returnUrl: branding.returnUrl ?? null,
112
- } : null,
113
- products: catalog.map(entry => ({ product: entry.product.sku, plans: entry.hashable })),
114
- })).digest('hex')
115
-
116
- const stored = await access.fingerprints().bySku(sku)
117
- if (stored != null && stored.hash === hash && stored.externalId != null && opts.force !== true) {
118
- return stored.externalId
119
- }
120
-
121
- const products: Array<{ product: string, prices: string[] }> = []
122
- for (const entry of catalog) {
123
- const prices = (await activeRecurringPrices(stripe, entry.product.sku)).map(price => price.id)
124
- if (prices.length > 0) {
125
- products.push({ product: entry.product.sku, prices })
126
- }
17
+ /** The entity's highest-ranked entitling subscription of a paygate (any paygate but the internal one), or `null`. */
18
+ const entitlingSubscription = async (entityId: string, paygate?: string): Promise<PaymentSubscriptionRecord | null> =>
19
+ await access.subscriptions().load(
20
+ { entityId, paygate: paygate ?? { $ne: INTERNAL_PAYGATE }, status: [...ENTITLING_STATUSES] },
21
+ { sort: [...ENTITLING_SORT] as never },
22
+ )
23
+
24
+ /** The paygate a portal opens on and the entity's live customer there. */
25
+ const customerOf = async (
26
+ entityId: string, requested?: string,
27
+ ): Promise<{ paygate: Paygate | null, customer: PaygateCustomerRecord | null }> => {
28
+ const paygates = paygatesOf(ctx)
29
+ const live = async (paygate: Paygate): Promise<PaygateCustomerRecord | null> => {
30
+ const customer = await access.paygateCustomers().byEntity(entityId, paygate.id)
31
+ return customer != null && customer.deletedAt == null ? customer : null
127
32
  }
128
- const cancelable = catalog.length > 0
129
- const switchable = products.length > 0
130
- const metadata = { [STRIPE_OWNER_KEY]: STRIPE_OWNER_VALUE, service: owner, [STRIPE_DEPLOYMENT_KEY]: deployment }
131
- const allowedUpdates: Stripe.BillingPortal.ConfigurationCreateParams.Features.CustomerUpdate.AllowedUpdate[] = [
132
- ...(emailLock ? [] : ['email' as const]), ...(countryLock || countryPin ? [] : ['address' as const]), 'tax_id',
133
- ]
134
- const params: ConfigurationParams = {
135
- features: {
136
- customer_update: { enabled: true, allowed_updates: allowedUpdates },
137
- invoice_history: { enabled: true },
138
- payment_method_update: { enabled: true },
139
- subscription_cancel: cancelable
140
- ? { enabled: true, mode: 'at_period_end', proration_behavior: 'none' }
141
- : { enabled: false },
142
- subscription_update: switchable
143
- ? {
144
- enabled: true, default_allowed_updates: ['price'], products,
145
- proration_behavior: 'create_prorations',
146
- }
147
- : { enabled: false },
148
- },
149
- ...(branding != null ? {
150
- business_profile: {
151
- ...(branding.headline != null ? { headline: branding.headline } : {}),
152
- ...(branding.privacyPolicyUrl != null ? { privacy_policy_url: branding.privacyPolicyUrl } : {}),
153
- ...(branding.termsOfServiceUrl != null ? { terms_of_service_url: branding.termsOfServiceUrl } : {}),
154
- },
155
- default_return_url: branding.returnUrl,
156
- } : {}),
157
- metadata,
33
+ if (requested != null) {
34
+ const paygate = paygates.find(requested)
35
+ return { paygate, customer: paygate != null ? await live(paygate) : null }
158
36
  }
159
-
160
- let configurationId: string | null = null
161
- if (stored?.externalId != null) {
162
- try {
163
- const current = await stripe.billingPortal.configurations.retrieve(stored.externalId)
164
- if (claimOf(current.metadata, owner, deployment) !== 'foreign') {
165
- await stripe.billingPortal.configurations.update(current.id, params)
166
- configurationId = current.id
167
- }
168
- } catch (error) {
169
- if (!paymentUtils.isMissingObject(error)) {
170
- throw error
171
- }
172
- }
173
- }
174
- if (configurationId == null) {
175
- const existing = (await listActiveConfigurations(stripe))
176
- .find(configuration => claimOf(configuration.metadata, owner, deployment) === 'ours')
177
- if (existing != null) {
178
- await stripe.billingPortal.configurations.update(existing.id, params)
179
- configurationId = existing.id
180
- } else {
181
- configurationId = (await stripe.billingPortal.configurations.create(params)).id
37
+ const subscribed = (await entitlingSubscription(entityId))?.paygate
38
+ const preferred = subscribed != null ? paygates.find(subscribed) : null
39
+ for (const paygate of preferred != null ? [preferred, ...paygates.all().filter(item => item !== preferred)] : paygates.all()) {
40
+ const customer = await live(paygate)
41
+ if (customer != null) {
42
+ return { paygate, customer }
182
43
  }
183
44
  }
184
45
 
185
- const now = new Date()
186
- if (stored != null) {
187
- await access.fingerprints().update({ ...stored, hash, externalId: configurationId, updatedAt: now })
188
- } else {
189
- await access.fingerprints().create({ sku, hash, externalId: configurationId, updatedAt: now })
190
- }
191
-
192
- return configurationId
46
+ return { paygate: preferred, customer: null }
193
47
  }
194
48
 
195
- /** The entity's highest-ranked entitling Stripe subscription, or `null`. */
196
- const entitlingStripeSubscription = async (
197
- entityId: string,
198
- ): Promise<PaymentSubscriptionRecord | null> => await access.subscriptions().load(
199
- { entityId, paygate: STRIPE_PAYGATE_ALIAS, status: [...ENTITLING_STATUSES] },
200
- { sort: [{ field: 'rank', order: 'desc' }, { field: 'createdAt', order: 'desc' }] },
201
- )
202
-
203
- const createPortalLink = async (stripe: Stripe, entityId: string, opts: PortalLinkOptions): Promise<string> => {
204
- const customer = await access.paygateCustomers().byEntity(entityId, STRIPE_PAYGATE_ALIAS)
205
- if (customer == null || customer.deletedAt != null) {
49
+ const createPortalLink = async (entityId: string, opts: PortalLinkOptions): Promise<string> => {
50
+ const { paygate, customer } = await customerOf(entityId, opts.paygate)
51
+ if (paygate == null || customer == null) {
206
52
  throw new PortalUnavailable('customer')
207
53
  }
208
-
209
- const sku = portalFingerprintSku(webhookOf(ctx).gatewayOwnerOf())
210
- let configuration = (await access.fingerprints().bySku(sku))?.externalId ?? null
211
- if (configuration == null) {
212
- await ensurePortalConfiguration(stripe).catch(error => {
213
- log.error('Portal configuration unavailable', error)
214
- })
215
- configuration = (await access.fingerprints().bySku(sku))?.externalId ?? null
54
+ const portal = paygate.portal
55
+ if (portal == null) {
56
+ throw new PortalUnavailable('paygate')
216
57
  }
217
58
 
218
- let flowData: Stripe.BillingPortal.SessionCreateParams.FlowData | undefined
59
+ const input: PortalSessionInput = {
60
+ customerId: customer.externalId, flow: opts.flow, returnUrl: opts.returnUrl,
61
+ owner: webhookOf(ctx).gatewayOwnerOf(), deployment: () => webhookOf(ctx).deploymentOf(paygate.id),
62
+ }
219
63
  switch (opts.flow) {
220
64
  case PortalFlow.Manage:
221
- break
222
65
  case PortalFlow.PaymentMethod:
223
- flowData = { type: 'payment_method_update' }
224
66
  break
225
67
  case PortalFlow.Cancel:
226
68
  case PortalFlow.Update:
227
69
  case PortalFlow.Change: {
228
- const subscription = await entitlingStripeSubscription(entityId)
70
+ const subscription = await entitlingSubscription(entityId, paygate.id)
229
71
  if (subscription == null) {
230
72
  throw new PortalUnavailable('subscription')
231
73
  }
232
- if (opts.flow === PortalFlow.Cancel) {
233
- flowData = { type: 'subscription_cancel', subscription_cancel: { subscription: subscription.externalId } }
234
- } else if (opts.flow === PortalFlow.Update) {
235
- flowData = { type: 'subscription_update', subscription_update: { subscription: subscription.externalId } }
236
- } else {
74
+ input.subscriptionId = subscription.externalId
75
+ if (opts.flow === PortalFlow.Change) {
237
76
  if (opts.planSku == null || opts.planSku === '') {
238
77
  throw new PortalUnavailable('plan')
239
78
  }
@@ -245,39 +84,19 @@ export const makePortalHelper = (ctx: ApiContext): PortalHelper => {
245
84
  if (subscription.itemId == null) {
246
85
  throw new PortalUnavailable('item')
247
86
  }
248
- const lookupKey = planHelper.planLookupKey(product, plan)
249
- const [price] = (await stripe.prices.list({ lookup_keys: [lookupKey], active: true, limit: 1 })).data
250
- if (price == null) {
251
- throw new ProductError(`price:${lookupKey}`)
252
- }
253
- flowData = {
254
- type: 'subscription_update_confirm',
255
- subscription_update_confirm: {
256
- subscription: subscription.externalId,
257
- items: [{ id: subscription.itemId, price: price.id, quantity: 1 }],
258
- },
259
- }
87
+ input.itemId = subscription.itemId
88
+ input.lookupKey = planHelper.planLookupKey(product, plan)
260
89
  }
261
90
  break
262
91
  }
263
92
  default:
264
93
  throw new PortalUnavailable(`flow:${String(opts.flow)}`)
265
94
  }
266
- if (flowData != null) {
267
- flowData.after_completion = { type: 'redirect', redirect: { return_url: opts.returnUrl } }
268
- }
269
-
270
- const session = await stripe.billingPortal.sessions.create({
271
- customer: customer.externalId,
272
- return_url: opts.returnUrl,
273
- ...(configuration != null ? { configuration } : {}),
274
- ...(flowData != null ? { flow_data: flowData } : {}),
275
- })
276
95
 
277
- return session.url
96
+ return await portal.createSession(input)
278
97
  }
279
98
 
280
- return { portalFingerprintSku, ensurePortalConfiguration, createPortalLink }
99
+ return { createPortalLink }
281
100
  }
282
101
 
283
102
  /** The customer portal of a context — one per context. */
@@ -1,11 +1,11 @@
1
- import type Stripe from 'stripe'
2
1
  import type { PaymentFulfillmentRecord, PaymentSubscriptionRecord } from '../../types.js'
2
+ import type { Paygate, PaygateCharge } from '../../paygate/types.js'
3
3
 
4
4
  /** What a refund or a dispute is about: a one-time fulfillment, or one invoice of a subscription. */
5
5
  export type PaymentTarget =
6
- | { kind: 'fulfillment', record: PaymentFulfillmentRecord, charge: Stripe.Charge | null, paymentIntentId?: string }
6
+ | { kind: 'fulfillment', record: PaymentFulfillmentRecord, charge: PaygateCharge | null, paymentIntentId?: string }
7
7
  | {
8
- kind: 'subscription', record: PaymentSubscriptionRecord, charge: Stripe.Charge | null,
8
+ kind: 'subscription', record: PaymentSubscriptionRecord, charge: PaygateCharge | null,
9
9
  paymentIntentId?: string, invoiceId: string,
10
10
  }
11
11
 
@@ -14,18 +14,18 @@ export interface PaymentReference {
14
14
  chargeId?: string
15
15
  invoiceId?: string
16
16
  /** The charge, when the event already carries it. */
17
- charge?: Stripe.Charge | null
17
+ charge?: PaygateCharge | null
18
18
  }
19
19
 
20
20
  /** What a refund or a dispute of a context is about. */
21
21
  export interface PaymentTargetHelper {
22
- /** A charge by id, or `null` when the paygate has none. */
23
- retrieveCharge: (stripe: Stripe, chargeId: string) => Promise<Stripe.Charge | null>
22
+ /** A charge by id, or `null` when the paygate has none (or reads no payments). */
23
+ retrieveCharge: (paygate: Paygate, chargeId: string) => Promise<PaygateCharge | null>
24
24
  /**
25
- * Resolve a refund or a dispute to the record it is about: by payment intent to a fulfillment;
26
- * by charge to a fulfillment (stored charge, else the charge's payment intent — whose charge id is
27
- * then remembered), else the charge's invoice; by invoice to the subscription whose latest invoice
28
- * it is, else the invoice's subscription. `null` when nothing here paid for it.
25
+ * Resolve a refund or a dispute to the record it is about: by payment to a fulfillment; by charge
26
+ * to a fulfillment (stored charge, else the charge's payment — whose charge id is then remembered),
27
+ * else the charge's invoice; by invoice to the subscription whose latest invoice it is, else the
28
+ * invoice's subscription. `null` when nothing here paid for it.
29
29
  */
30
- resolvePaymentTarget: (stripe: Stripe, ref: PaymentReference) => Promise<PaymentTarget | null>
30
+ resolvePaymentTarget: (paygate: Paygate, ref: PaymentReference) => Promise<PaymentTarget | null>
31
31
  }