@aglyn/plugins-commerce 1.15.0 → 1.15.2
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/package.json +13 -13
- package/src/lib/components/cart.js +8 -3
- package/src/lib/components/cart.js.map +1 -1
- package/src/lib/components/console/payments-settings-card.component.js +1 -1
- package/src/lib/components/console/payments-settings-card.component.js.map +1 -1
- package/src/lib/components/console/subscription-detail-dialog.component.js +2 -2
- package/src/lib/components/console/subscription-detail-dialog.component.js.map +1 -1
- package/src/lib/components/console/subscriptions-card.component.js +4 -2
- package/src/lib/components/console/subscriptions-card.component.js.map +1 -1
- package/src/lib/components/product-detail.js +7 -3
- package/src/lib/components/product-detail.js.map +1 -1
- package/src/lib/components/quote-page-body.js +7 -3
- package/src/lib/components/quote-page-body.js.map +1 -1
- package/src/lib/components/related-products.js +6 -3
- package/src/lib/components/related-products.js.map +1 -1
- package/src/lib/components/storefront-payment-element.d.ts +7 -1
- package/src/lib/components/storefront-payment-element.js +11 -7
- package/src/lib/components/storefront-payment-element.js.map +1 -1
- package/src/lib/model/commerce-payment-methods.d.ts +26 -39
- package/src/lib/model/commerce-payment-methods.js +11 -118
- package/src/lib/model/commerce-payment-methods.js.map +1 -1
- package/src/lib/server/billing-webhook.d.ts +23 -0
- package/src/lib/server/billing-webhook.js +162 -30
- package/src/lib/server/billing-webhook.js.map +1 -1
- package/src/lib/server/cancel-order.js +4 -3
- package/src/lib/server/cancel-order.js.map +1 -1
- package/src/lib/server/cart-checkout.js +61 -14
- package/src/lib/server/cart-checkout.js.map +1 -1
- package/src/lib/server/catalog.js +58 -22
- package/src/lib/server/catalog.js.map +1 -1
- package/src/lib/server/checkout-session-expiry.d.ts +1 -1
- package/src/lib/server/checkout-session-expiry.js +19 -5
- package/src/lib/server/checkout-session-expiry.js.map +1 -1
- package/src/lib/server/checkout-status.js +4 -3
- package/src/lib/server/checkout-status.js.map +1 -1
- package/src/lib/server/checkout.js +42 -12
- package/src/lib/server/checkout.js.map +1 -1
- package/src/lib/server/connect.js +42 -11
- package/src/lib/server/connect.js.map +1 -1
- package/src/lib/server/draft-order.js +37 -12
- package/src/lib/server/draft-order.js.map +1 -1
- package/src/lib/server/manual-tax-rate.d.ts +11 -3
- package/src/lib/server/manual-tax-rate.js +10 -6
- package/src/lib/server/manual-tax-rate.js.map +1 -1
- package/src/lib/server/native-checkout.d.ts +10 -3
- package/src/lib/server/native-checkout.js +8 -3
- package/src/lib/server/native-checkout.js.map +1 -1
- package/src/lib/server/payment-method-domains.d.ts +50 -9
- package/src/lib/server/payment-method-domains.js +150 -51
- package/src/lib/server/payment-method-domains.js.map +1 -1
- package/src/lib/server/payment-methods.js +3 -2
- package/src/lib/server/payment-methods.js.map +1 -1
- package/src/lib/server/pos-order.js +5 -1
- package/src/lib/server/pos-order.js.map +1 -1
- package/src/lib/server/pos-stripe.d.ts +7 -7
- package/src/lib/server/pos-stripe.js +15 -13
- package/src/lib/server/pos-stripe.js.map +1 -1
- package/src/lib/server/pos-terminal.js +11 -3
- package/src/lib/server/pos-terminal.js.map +1 -1
- package/src/lib/server/quote-pay.d.ts +23 -1
- package/src/lib/server/quote-pay.js +112 -32
- package/src/lib/server/quote-pay.js.map +1 -1
- package/src/lib/server/quote.d.ts +2 -1
- package/src/lib/server/quote.js +12 -11
- package/src/lib/server/quote.js.map +1 -1
- package/src/lib/server/refund.js +13 -6
- package/src/lib/server/refund.js.map +1 -1
- package/src/lib/server/related.js +10 -3
- package/src/lib/server/related.js.map +1 -1
- package/src/lib/server/reserve.js +19 -6
- package/src/lib/server/reserve.js.map +1 -1
- package/src/lib/server/revenue-source.d.ts +6 -0
- package/src/lib/server/revenue-source.js +25 -9
- package/src/lib/server/revenue-source.js.map +1 -1
- package/src/lib/server/seller-stripe-account.d.ts +45 -0
- package/src/lib/server/seller-stripe-account.js +99 -0
- package/src/lib/server/seller-stripe-account.js.map +1 -0
- package/src/lib/server/storefront-tax-record.js +6 -1
- package/src/lib/server/storefront-tax-record.js.map +1 -1
- package/src/lib/server/storefront-tax.d.ts +33 -2
- package/src/lib/server/storefront-tax.js +39 -3
- package/src/lib/server/storefront-tax.js.map +1 -1
- package/src/lib/server/stripe-refund.d.ts +15 -0
- package/src/lib/server/stripe-refund.js +54 -26
- package/src/lib/server/stripe-refund.js.map +1 -1
- package/src/lib/server/subscription-portal.js +8 -3
- package/src/lib/server/subscription-portal.js.map +1 -1
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
+
import { type BuyNowPayLaterPaymentMethodType } from '@aglyn/aglyn/app-utils/buy-now-pay-later';
|
|
17
18
|
/**
|
|
18
19
|
* The storefront payment methods a merchant chooses between (AGL-3629).
|
|
19
20
|
*
|
|
@@ -37,28 +38,29 @@
|
|
|
37
38
|
* reaches the hosted page; Apple Pay and Google Pay on a hosted Stripe page
|
|
38
39
|
* follow the device and cannot be hidden per merchant.
|
|
39
40
|
*
|
|
40
|
-
* ##
|
|
41
|
+
* ## Buy-now-pay-later is never offered (AGL-4198)
|
|
41
42
|
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
43
|
+
* Klarna, Afterpay and Affirm are not in this catalog and are excluded on every
|
|
44
|
+
* session (`BUY_NOW_PAY_LATER_PAYMENT_METHOD_TYPES`), whatever a store chose
|
|
45
|
+
* before. They cost Stripe about 6% + 30¢ against 2.9% + 30¢ for a card, and
|
|
46
|
+
* the platform's fee is fixed before the shopper picks how to pay, so offering
|
|
47
|
+
* them would size every fee for the dearest method.
|
|
47
48
|
*
|
|
48
|
-
* ##
|
|
49
|
+
* ## Why toggling a method never moves a fee
|
|
49
50
|
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
* being placed on one side or the other.
|
|
51
|
+
* `application_fee_amount` is priced at the card rate
|
|
52
|
+
* (`SALE_PROCESSING_PERCENT`). Every method in this catalog costs Stripe that
|
|
53
|
+
* much or less (Apple Pay, Google Pay, Link, Cash App Pay and Amazon Pay are
|
|
54
|
+
* 2.9% + 30¢ on Stripe's US pricing, stablecoins 1.5%), so turning one off or
|
|
55
|
+
* on changes what a shopper may choose and never what the platform recovers.
|
|
56
|
+
* A method added here must cost no more than a card; the catalog spec holds
|
|
57
|
+
* the list.
|
|
58
58
|
*/
|
|
59
59
|
/** A method the merchant may switch off (or, for crypto, on). */
|
|
60
|
-
export type StorefrontPaymentMethodId = 'apple_pay' | 'google_pay' | 'link' | '
|
|
61
|
-
export type StorefrontPaymentMethodKind = 'wallet' | '
|
|
60
|
+
export type StorefrontPaymentMethodId = 'apple_pay' | 'google_pay' | 'link' | 'cashapp' | 'amazon_pay' | 'crypto';
|
|
61
|
+
export type StorefrontPaymentMethodKind = 'wallet' | 'crypto';
|
|
62
|
+
/** A method a session excludes: one the merchant switched off, or buy-now-pay-later. */
|
|
63
|
+
export type ExcludedPaymentMethodType = StorefrontPaymentMethodId | BuyNowPayLaterPaymentMethodType;
|
|
62
64
|
/** How a toggle reaches Stripe. */
|
|
63
65
|
export type StorefrontPaymentMethodControl =
|
|
64
66
|
/** The Payment Element's `wallets` option (and, for Link, the session). */
|
|
@@ -126,8 +128,8 @@ export interface StorefrontCheckoutWallets {
|
|
|
126
128
|
link: StorefrontWalletDisplay;
|
|
127
129
|
}
|
|
128
130
|
export interface StorefrontPaymentMethodControls {
|
|
129
|
-
/** Sent as `excluded_payment_method_types[n]
|
|
130
|
-
excluded:
|
|
131
|
+
/** Sent as `excluded_payment_method_types[n]`: buy-now-pay-later, then the merchant's, in catalog order. */
|
|
132
|
+
excluded: ExcludedPaymentMethodType[];
|
|
131
133
|
/** Handed to the Payment Element. */
|
|
132
134
|
wallets: StorefrontCheckoutWallets;
|
|
133
135
|
}
|
|
@@ -135,31 +137,16 @@ export interface StorefrontPaymentMethodControls {
|
|
|
135
137
|
* What one checkout session sends Stripe for the merchant's choices.
|
|
136
138
|
*
|
|
137
139
|
* A method the merchant left on is NOT added anywhere: dynamic payment methods
|
|
138
|
-
* already offer it when the platform does and the order qualifies.
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
* excluded until chosen, and was never offered by the platform before either.
|
|
140
|
+
* already offer it when the platform does and the order qualifies. Named are
|
|
141
|
+
* buy-now-pay-later, always (AGL-4198), then the methods turned off, which
|
|
142
|
+
* include crypto until it is chosen.
|
|
142
143
|
*/
|
|
143
144
|
export declare function resolveStorefrontPaymentMethodControls(settings: StorefrontPaymentMethodSettings | null | undefined): StorefrontPaymentMethodControls;
|
|
144
145
|
/**
|
|
145
|
-
* Write the controls onto a Checkout Session param set
|
|
146
|
-
*
|
|
147
|
-
* apart from the crypto opt-in — sends what it always sent.
|
|
146
|
+
* Write the controls onto a Checkout Session param set: every exclusion in
|
|
147
|
+
* order, and Link hidden on the session when the merchant hid it.
|
|
148
148
|
*/
|
|
149
149
|
export declare function appendStorefrontPaymentMethodParams(params: URLSearchParams, controls: StorefrontPaymentMethodControls): void;
|
|
150
|
-
/**
|
|
151
|
-
* The methods a quote's or an invoice's pay link may still offer, each of
|
|
152
|
-
* which Stripe prices at the card rate or below (see the note at the top of
|
|
153
|
-
* this file). Every other catalog method is excluded from a pay link.
|
|
154
|
-
*/
|
|
155
|
-
export declare const PAY_LINK_METHOD_IDS: readonly StorefrontPaymentMethodId[];
|
|
156
|
-
/**
|
|
157
|
-
* The store's choices as a quote's or an invoice's pay link sends them: what
|
|
158
|
-
* the store turned off, plus every method that is not on `PAY_LINK_METHOD_IDS`
|
|
159
|
-
* (Klarna, Afterpay and Affirm), excluded however the store set it. Catalog
|
|
160
|
-
* order, so the params read the same as a storefront session's.
|
|
161
|
-
*/
|
|
162
|
-
export declare function payLinkPaymentMethodControls(controls: StorefrontPaymentMethodControls): StorefrontPaymentMethodControls;
|
|
163
150
|
/** True when the browser has to be told about a hidden wallet at all. */
|
|
164
151
|
export declare function storefrontWalletsHideAny(wallets: StorefrontCheckoutWallets): boolean;
|
|
165
152
|
/**
|
|
@@ -13,48 +13,8 @@
|
|
|
13
13
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
*
|
|
19
|
-
* ## Who decides what a shopper sees
|
|
20
|
-
*
|
|
21
|
-
* Every storefront charge is a DESTINATION charge with no `on_behalf_of`, so
|
|
22
|
-
* the PLATFORM is the merchant of record and Stripe offers the methods the
|
|
23
|
-
* platform's payment method configuration turns on ("dynamic payment
|
|
24
|
-
* methods"), filtered by currency, amount, the shopper's country and device.
|
|
25
|
-
* No session pins `payment_method_types`. A merchant therefore cannot ADD a
|
|
26
|
-
* method the platform does not offer — they can only take one away, and that
|
|
27
|
-
* is what the two levers below do:
|
|
28
|
-
*
|
|
29
|
-
* - `excluded_payment_method_types` on the Checkout Session, for every method
|
|
30
|
-
* Stripe lets a session exclude. Measured accepted at both the account
|
|
31
|
-
* default API version and the native checkout's pinned dahlia version, so
|
|
32
|
-
* it applies to the in-page checkout AND the hosted Stripe page alike.
|
|
33
|
-
* - The Payment Element's `wallets` option for Apple Pay, Google Pay and
|
|
34
|
-
* Link, which Stripe documents as NOT excludable per session. Link is also
|
|
35
|
-
* hidden on the session with `wallet_options[link][display]=never`, which
|
|
36
|
-
* reaches the hosted page; Apple Pay and Google Pay on a hosted Stripe page
|
|
37
|
-
* follow the device and cannot be hidden per merchant.
|
|
38
|
-
*
|
|
39
|
-
* ## Why toggling a method never moves a fee
|
|
40
|
-
*
|
|
41
|
-
* `application_fee_amount` is priced against the dearest method the platform
|
|
42
|
-
* could offer (`SALE_PROCESSING_PERCENT`, the BNPL rate), because the shopper
|
|
43
|
-
* picks how to pay after the fee is fixed. Every method here costs Stripe that
|
|
44
|
-
* much or less, so turning one off or on changes what a shopper may choose and
|
|
45
|
-
* never what the platform recovers.
|
|
46
|
-
*
|
|
47
|
-
* ## Quotes and invoices pay by card, never buy-now-pay-later
|
|
48
|
-
*
|
|
49
|
-
* A quote's or an invoice's pay link always excludes every `bnpl` method,
|
|
50
|
-
* whatever the store chose (`payLinkPaymentMethodControls`), and its fee is
|
|
51
|
-
* priced at the card rate (`PAY_LINK_PROCESSING_PERCENT`). That holds only
|
|
52
|
-
* while every method a pay link can still offer costs Stripe no more than a
|
|
53
|
-
* card: Apple Pay, Google Pay, Link, Cash App Pay and Amazon Pay are 2.9% +
|
|
54
|
-
* 30¢ on Stripe's US pricing, and stablecoins 1.5%. `PAY_LINK_METHOD_IDS`
|
|
55
|
-
* lists them, and a spec fails when a method is added to the catalog without
|
|
56
|
-
* being placed on one side or the other.
|
|
57
|
-
*/ /** A method the merchant may switch off (or, for crypto, on). */ /**
|
|
16
|
+
*/ import { BUY_NOW_PAY_LATER_PAYMENT_METHOD_TYPES } from "@aglyn/aglyn/app-utils/buy-now-pay-later";
|
|
17
|
+
/**
|
|
58
18
|
* The catalog, in the order the settings card lists it. Limits are Stripe's
|
|
59
19
|
* published US figures (docs.stripe.com/payments/buy-now-pay-later and each
|
|
60
20
|
* method's page, read 2026-10-07); Stripe applies them itself, and they are
|
|
@@ -96,50 +56,6 @@
|
|
|
96
56
|
subscriptions: true,
|
|
97
57
|
needsDomain: true
|
|
98
58
|
},
|
|
99
|
-
{
|
|
100
|
-
id: 'klarna',
|
|
101
|
-
label: 'Klarna',
|
|
102
|
-
kind: 'bnpl',
|
|
103
|
-
control: 'exclude',
|
|
104
|
-
defaultOn: true,
|
|
105
|
-
capability: 'klarna_payments',
|
|
106
|
-
configurationKey: 'klarna',
|
|
107
|
-
requirements: 'US shoppers paying in USD. Pay in full, in 30 days, in 4, or monthly financing.',
|
|
108
|
-
limits: 'From $10; the highest amount depends on the shopper (financing up to $10,000).',
|
|
109
|
-
minCents: 1000,
|
|
110
|
-
subscriptions: true,
|
|
111
|
-
needsDomain: false
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
id: 'afterpay_clearpay',
|
|
115
|
-
label: 'Afterpay',
|
|
116
|
-
kind: 'bnpl',
|
|
117
|
-
control: 'exclude',
|
|
118
|
-
defaultOn: true,
|
|
119
|
-
capability: 'afterpay_clearpay_payments',
|
|
120
|
-
configurationKey: 'afterpay_clearpay',
|
|
121
|
-
requirements: 'US shoppers paying in USD. Pay in 4 interest-free installments.',
|
|
122
|
-
limits: '$1 to $4,000. One-time purchases only.',
|
|
123
|
-
minCents: 100,
|
|
124
|
-
maxCents: 400000,
|
|
125
|
-
subscriptions: false,
|
|
126
|
-
needsDomain: false
|
|
127
|
-
},
|
|
128
|
-
{
|
|
129
|
-
id: 'affirm',
|
|
130
|
-
label: 'Affirm',
|
|
131
|
-
kind: 'bnpl',
|
|
132
|
-
control: 'exclude',
|
|
133
|
-
defaultOn: true,
|
|
134
|
-
capability: 'affirm_payments',
|
|
135
|
-
configurationKey: 'affirm',
|
|
136
|
-
requirements: 'US shoppers paying in USD. Pay in 4, or monthly installments up to 36 months.',
|
|
137
|
-
limits: '$50 to $30,000. One-time purchases only.',
|
|
138
|
-
minCents: 5000,
|
|
139
|
-
maxCents: 3000000,
|
|
140
|
-
subscriptions: false,
|
|
141
|
-
needsDomain: false
|
|
142
|
-
},
|
|
143
59
|
{
|
|
144
60
|
id: 'cashapp',
|
|
145
61
|
label: 'Cash App Pay',
|
|
@@ -209,12 +125,14 @@ export function storefrontPaymentMethodSpec(id) {
|
|
|
209
125
|
* What one checkout session sends Stripe for the merchant's choices.
|
|
210
126
|
*
|
|
211
127
|
* A method the merchant left on is NOT added anywhere: dynamic payment methods
|
|
212
|
-
* already offer it when the platform does and the order qualifies.
|
|
213
|
-
*
|
|
214
|
-
*
|
|
215
|
-
* excluded until chosen, and was never offered by the platform before either.
|
|
128
|
+
* already offer it when the platform does and the order qualifies. Named are
|
|
129
|
+
* buy-now-pay-later, always (AGL-4198), then the methods turned off, which
|
|
130
|
+
* include crypto until it is chosen.
|
|
216
131
|
*/ export function resolveStorefrontPaymentMethodControls(settings) {
|
|
217
|
-
const excluded =
|
|
132
|
+
const excluded = [
|
|
133
|
+
...BUY_NOW_PAY_LATER_PAYMENT_METHOD_TYPES,
|
|
134
|
+
...STOREFRONT_PAYMENT_METHODS.filter((method)=>method.control === 'exclude' && !isStorefrontPaymentMethodOn(settings, method.id)).map((method)=>method.id)
|
|
135
|
+
];
|
|
218
136
|
const display = (id)=>isStorefrontPaymentMethodOn(settings, id) ? 'auto' : 'never';
|
|
219
137
|
return {
|
|
220
138
|
excluded,
|
|
@@ -226,9 +144,8 @@ export function storefrontPaymentMethodSpec(id) {
|
|
|
226
144
|
};
|
|
227
145
|
}
|
|
228
146
|
/**
|
|
229
|
-
* Write the controls onto a Checkout Session param set
|
|
230
|
-
*
|
|
231
|
-
* apart from the crypto opt-in — sends what it always sent.
|
|
147
|
+
* Write the controls onto a Checkout Session param set: every exclusion in
|
|
148
|
+
* order, and Link hidden on the session when the merchant hid it.
|
|
232
149
|
*/ export function appendStorefrontPaymentMethodParams(params, controls) {
|
|
233
150
|
controls.excluded.forEach((id, index)=>{
|
|
234
151
|
params.set(`excluded_payment_method_types[${index}]`, id);
|
|
@@ -237,30 +154,6 @@ export function storefrontPaymentMethodSpec(id) {
|
|
|
237
154
|
params.set('wallet_options[link][display]', 'never');
|
|
238
155
|
}
|
|
239
156
|
}
|
|
240
|
-
/**
|
|
241
|
-
* The methods a quote's or an invoice's pay link may still offer, each of
|
|
242
|
-
* which Stripe prices at the card rate or below (see the note at the top of
|
|
243
|
-
* this file). Every other catalog method is excluded from a pay link.
|
|
244
|
-
*/ export const PAY_LINK_METHOD_IDS = [
|
|
245
|
-
'apple_pay',
|
|
246
|
-
'google_pay',
|
|
247
|
-
'link',
|
|
248
|
-
'cashapp',
|
|
249
|
-
'amazon_pay',
|
|
250
|
-
'crypto'
|
|
251
|
-
];
|
|
252
|
-
/**
|
|
253
|
-
* The store's choices as a quote's or an invoice's pay link sends them: what
|
|
254
|
-
* the store turned off, plus every method that is not on `PAY_LINK_METHOD_IDS`
|
|
255
|
-
* (Klarna, Afterpay and Affirm), excluded however the store set it. Catalog
|
|
256
|
-
* order, so the params read the same as a storefront session's.
|
|
257
|
-
*/ export function payLinkPaymentMethodControls(controls) {
|
|
258
|
-
const excluded = STOREFRONT_PAYMENT_METHODS.filter((method)=>method.control === 'exclude' && (controls.excluded.includes(method.id) || !PAY_LINK_METHOD_IDS.includes(method.id))).map((method)=>method.id);
|
|
259
|
-
return {
|
|
260
|
-
excluded,
|
|
261
|
-
wallets: controls.wallets
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
157
|
/** True when the browser has to be told about a hidden wallet at all. */ export function storefrontWalletsHideAny(wallets) {
|
|
265
158
|
return wallets.applePay === 'never' || wallets.googlePay === 'never' || wallets.link === 'never';
|
|
266
159
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/model/commerce-payment-methods.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * The storefront payment methods a merchant chooses between (AGL-3629).\n *\n * ## Who decides what a shopper sees\n *\n * Every storefront charge is a DESTINATION charge with no `on_behalf_of`, so\n * the PLATFORM is the merchant of record and Stripe offers the methods the\n * platform's payment method configuration turns on (\"dynamic payment\n * methods\"), filtered by currency, amount, the shopper's country and device.\n * No session pins `payment_method_types`. A merchant therefore cannot ADD a\n * method the platform does not offer — they can only take one away, and that\n * is what the two levers below do:\n *\n * - `excluded_payment_method_types` on the Checkout Session, for every method\n * Stripe lets a session exclude. Measured accepted at both the account\n * default API version and the native checkout's pinned dahlia version, so\n * it applies to the in-page checkout AND the hosted Stripe page alike.\n * - The Payment Element's `wallets` option for Apple Pay, Google Pay and\n * Link, which Stripe documents as NOT excludable per session. Link is also\n * hidden on the session with `wallet_options[link][display]=never`, which\n * reaches the hosted page; Apple Pay and Google Pay on a hosted Stripe page\n * follow the device and cannot be hidden per merchant.\n *\n * ## Why toggling a method never moves a fee\n *\n * `application_fee_amount` is priced against the dearest method the platform\n * could offer (`SALE_PROCESSING_PERCENT`, the BNPL rate), because the shopper\n * picks how to pay after the fee is fixed. Every method here costs Stripe that\n * much or less, so turning one off or on changes what a shopper may choose and\n * never what the platform recovers.\n *\n * ## Quotes and invoices pay by card, never buy-now-pay-later\n *\n * A quote's or an invoice's pay link always excludes every `bnpl` method,\n * whatever the store chose (`payLinkPaymentMethodControls`), and its fee is\n * priced at the card rate (`PAY_LINK_PROCESSING_PERCENT`). That holds only\n * while every method a pay link can still offer costs Stripe no more than a\n * card: Apple Pay, Google Pay, Link, Cash App Pay and Amazon Pay are 2.9% +\n * 30¢ on Stripe's US pricing, and stablecoins 1.5%. `PAY_LINK_METHOD_IDS`\n * lists them, and a spec fails when a method is added to the catalog without\n * being placed on one side or the other.\n */\n\n/** A method the merchant may switch off (or, for crypto, on). */\nexport type StorefrontPaymentMethodId =\n | 'apple_pay'\n | 'google_pay'\n | 'link'\n | 'klarna'\n | 'afterpay_clearpay'\n | 'affirm'\n | 'cashapp'\n | 'amazon_pay'\n | 'crypto'\n\nexport type StorefrontPaymentMethodKind = 'wallet' | 'bnpl' | 'crypto'\n\n/** How a toggle reaches Stripe. */\nexport type StorefrontPaymentMethodControl =\n /** The Payment Element's `wallets` option (and, for Link, the session). */\n | 'wallet'\n /** `excluded_payment_method_types` on the Checkout Session. */\n | 'exclude'\n\nexport interface StorefrontPaymentMethodSpec {\n id: StorefrontPaymentMethodId\n label: string\n kind: StorefrontPaymentMethodKind\n control: StorefrontPaymentMethodControl\n /**\n * On when the merchant has never chosen. Every method that was already\n * reaching shoppers before AGL-3629 defaults on, so saving nothing changes\n * nothing; crypto, which settles differently and cannot be disputed,\n * defaults off and is the merchant's to opt into.\n */\n defaultOn: boolean\n /**\n * The connected-account capability Stripe asks platforms to request before\n * the method is accepted for that account. Absent for the card wallets,\n * which ride `card_payments`.\n */\n capability?: string\n /** The platform payment method configuration's key for this method. */\n configurationKey: string\n /** What a shopper needs, in a sentence the settings card shows. */\n requirements: string\n /** Amount and currency limits, as Stripe publishes them for US accounts. */\n limits: string\n /** Lowest charge Stripe offers it for, in USD cents, when published. */\n minCents?: number\n /** Highest charge Stripe offers it for, in USD cents, when published. */\n maxCents?: number\n /** False where Stripe does not offer it in a subscription-mode session. */\n subscriptions: boolean\n /** Shown on a registered domain only (Apple Pay must be; the rest benefit). */\n needsDomain: boolean\n}\n\n/**\n * The catalog, in the order the settings card lists it. Limits are Stripe's\n * published US figures (docs.stripe.com/payments/buy-now-pay-later and each\n * method's page, read 2026-10-07); Stripe applies them itself, and they are\n * here so a merchant can read why a method did not appear on an order.\n */\nexport const STOREFRONT_PAYMENT_METHODS: readonly StorefrontPaymentMethodSpec[] = [\n {\n id: 'apple_pay',\n label: 'Apple Pay',\n kind: 'wallet',\n control: 'wallet',\n defaultOn: true,\n configurationKey: 'apple_pay',\n requirements:\n 'Safari on a Mac, iPhone or iPad with a card in Apple Wallet. Your site’s domain is registered with Apple Pay for you.',\n limits: 'Same as cards.',\n subscriptions: true,\n needsDomain: true,\n },\n {\n id: 'google_pay',\n label: 'Google Pay',\n kind: 'wallet',\n control: 'wallet',\n defaultOn: true,\n configurationKey: 'google_pay',\n requirements:\n 'Chrome or an Android device with a card saved to Google Pay. With Stripe Tax on, Google Pay shows when the checkout collects a shipping address.',\n limits: 'Same as cards.',\n subscriptions: true,\n needsDomain: true,\n },\n {\n id: 'link',\n label: 'Link',\n kind: 'wallet',\n control: 'wallet',\n defaultOn: true,\n configurationKey: 'link',\n requirements: 'Shoppers who saved a card or bank with Link check out in one step.',\n limits: 'Same as cards.',\n subscriptions: true,\n needsDomain: true,\n },\n {\n id: 'klarna',\n label: 'Klarna',\n kind: 'bnpl',\n control: 'exclude',\n defaultOn: true,\n capability: 'klarna_payments',\n configurationKey: 'klarna',\n requirements:\n 'US shoppers paying in USD. Pay in full, in 30 days, in 4, or monthly financing.',\n limits: 'From $10; the highest amount depends on the shopper (financing up to $10,000).',\n minCents: 1000,\n subscriptions: true,\n needsDomain: false,\n },\n {\n id: 'afterpay_clearpay',\n label: 'Afterpay',\n kind: 'bnpl',\n control: 'exclude',\n defaultOn: true,\n capability: 'afterpay_clearpay_payments',\n configurationKey: 'afterpay_clearpay',\n requirements: 'US shoppers paying in USD. Pay in 4 interest-free installments.',\n limits: '$1 to $4,000. One-time purchases only.',\n minCents: 100,\n maxCents: 400_000,\n subscriptions: false,\n needsDomain: false,\n },\n {\n id: 'affirm',\n label: 'Affirm',\n kind: 'bnpl',\n control: 'exclude',\n defaultOn: true,\n capability: 'affirm_payments',\n configurationKey: 'affirm',\n requirements:\n 'US shoppers paying in USD. Pay in 4, or monthly installments up to 36 months.',\n limits: '$50 to $30,000. One-time purchases only.',\n minCents: 5_000,\n maxCents: 3_000_000,\n subscriptions: false,\n needsDomain: false,\n },\n {\n id: 'cashapp',\n label: 'Cash App Pay',\n kind: 'wallet',\n control: 'exclude',\n defaultOn: true,\n capability: 'cashapp_payments',\n configurationKey: 'cashapp',\n requirements: 'US shoppers with Cash App, paying in USD.',\n limits: 'USD only.',\n subscriptions: true,\n needsDomain: false,\n },\n {\n id: 'amazon_pay',\n label: 'Amazon Pay',\n kind: 'wallet',\n control: 'exclude',\n defaultOn: true,\n capability: 'amazon_pay_payments',\n configurationKey: 'amazon_pay',\n requirements: 'Shoppers pay with the card and address saved to their Amazon account.',\n limits: 'USD only.',\n subscriptions: true,\n needsDomain: true,\n },\n {\n id: 'crypto',\n label: 'Stablecoins (crypto)',\n kind: 'crypto',\n control: 'exclude',\n defaultOn: false,\n capability: 'crypto_payments',\n configurationKey: 'crypto',\n requirements:\n 'Shoppers pay in USDC or another supported stablecoin from their crypto wallet; you are paid in USD. Refunds go back to the shopper’s wallet as stablecoins, and these payments cannot be disputed.',\n limits: 'USD only, up to $10,000 per payment.',\n maxCents: 1_000_000,\n subscriptions: true,\n needsDomain: false,\n },\n]\n\n/** The merchant's choices, as stored on `hosts/{hostId}/settings/store`. */\nexport type StorefrontPaymentMethodSettings = Partial<\n Record<StorefrontPaymentMethodId, boolean>\n>\n\nexport const STOREFRONT_PAYMENT_METHOD_IDS: readonly StorefrontPaymentMethodId[] =\n STOREFRONT_PAYMENT_METHODS.map((method) => method.id)\n\nexport function storefrontPaymentMethodSpec(\n id: string,\n): StorefrontPaymentMethodSpec | undefined {\n return STOREFRONT_PAYMENT_METHODS.find((method) => method.id === id)\n}\n\n/**\n * Keep only booleans under known ids. The settings document is written by the\n * console, so anything else on it — a string, a removed method, a typo — is\n * read as \"never chosen\" rather than trusted.\n */\nexport function normalizeStorefrontPaymentMethodSettings(\n raw: unknown,\n): StorefrontPaymentMethodSettings {\n const out: StorefrontPaymentMethodSettings = {}\n if (!raw || typeof raw !== 'object') return out\n for (const id of STOREFRONT_PAYMENT_METHOD_IDS) {\n const value = (raw as Record<string, unknown>)[id]\n if (typeof value === 'boolean') out[id] = value\n }\n return out\n}\n\n/** Whether the merchant offers a method: their choice, else its default. */\nexport function isStorefrontPaymentMethodOn(\n settings: StorefrontPaymentMethodSettings | null | undefined,\n id: StorefrontPaymentMethodId,\n): boolean {\n const chosen = settings?.[id]\n if (typeof chosen === 'boolean') return chosen\n return storefrontPaymentMethodSpec(id)?.defaultOn ?? false\n}\n\n/** `auto` lets Stripe decide from the device; `never` hides the wallet. */\nexport type StorefrontWalletDisplay = 'auto' | 'never'\n\n/** The Payment Element's `wallets` option, as the browser receives it. */\nexport interface StorefrontCheckoutWallets {\n applePay: StorefrontWalletDisplay\n googlePay: StorefrontWalletDisplay\n link: StorefrontWalletDisplay\n}\n\nexport interface StorefrontPaymentMethodControls {\n /** Sent as `excluded_payment_method_types[n]`, in catalog order. */\n excluded: StorefrontPaymentMethodId[]\n /** Handed to the Payment Element. */\n wallets: StorefrontCheckoutWallets\n}\n\n/**\n * What one checkout session sends Stripe for the merchant's choices.\n *\n * A method the merchant left on is NOT added anywhere: dynamic payment methods\n * already offer it when the platform does and the order qualifies. Only the\n * methods turned off are named, which is why a merchant who never opened the\n * card produces the same session as before AGL-3629 — except crypto, which is\n * excluded until chosen, and was never offered by the platform before either.\n */\nexport function resolveStorefrontPaymentMethodControls(\n settings: StorefrontPaymentMethodSettings | null | undefined,\n): StorefrontPaymentMethodControls {\n const excluded = STOREFRONT_PAYMENT_METHODS.filter(\n (method) =>\n method.control === 'exclude' && !isStorefrontPaymentMethodOn(settings, method.id),\n ).map((method) => method.id)\n const display = (id: StorefrontPaymentMethodId): StorefrontWalletDisplay =>\n isStorefrontPaymentMethodOn(settings, id) ? 'auto' : 'never'\n return {\n excluded,\n wallets: {\n applePay: display('apple_pay'),\n googlePay: display('google_pay'),\n link: display('link'),\n },\n }\n}\n\n/**\n * Write the controls onto a Checkout Session param set. Leaves the params\n * untouched when the merchant hid nothing, so a store with default settings —\n * apart from the crypto opt-in — sends what it always sent.\n */\nexport function appendStorefrontPaymentMethodParams(\n params: URLSearchParams,\n controls: StorefrontPaymentMethodControls,\n): void {\n controls.excluded.forEach((id, index) => {\n params.set(`excluded_payment_method_types[${index}]`, id)\n })\n if (controls.wallets.link === 'never') {\n params.set('wallet_options[link][display]', 'never')\n }\n}\n\n/**\n * The methods a quote's or an invoice's pay link may still offer, each of\n * which Stripe prices at the card rate or below (see the note at the top of\n * this file). Every other catalog method is excluded from a pay link.\n */\nexport const PAY_LINK_METHOD_IDS: readonly StorefrontPaymentMethodId[] = [\n 'apple_pay',\n 'google_pay',\n 'link',\n 'cashapp',\n 'amazon_pay',\n 'crypto',\n]\n\n/**\n * The store's choices as a quote's or an invoice's pay link sends them: what\n * the store turned off, plus every method that is not on `PAY_LINK_METHOD_IDS`\n * (Klarna, Afterpay and Affirm), excluded however the store set it. Catalog\n * order, so the params read the same as a storefront session's.\n */\nexport function payLinkPaymentMethodControls(\n controls: StorefrontPaymentMethodControls,\n): StorefrontPaymentMethodControls {\n const excluded = STOREFRONT_PAYMENT_METHODS.filter(\n (method) =>\n method.control === 'exclude' &&\n (controls.excluded.includes(method.id) || !PAY_LINK_METHOD_IDS.includes(method.id)),\n ).map((method) => method.id)\n return { excluded, wallets: controls.wallets }\n}\n\n/** True when the browser has to be told about a hidden wallet at all. */\nexport function storefrontWalletsHideAny(wallets: StorefrontCheckoutWallets): boolean {\n return (\n wallets.applePay === 'never' ||\n wallets.googlePay === 'never' ||\n wallets.link === 'never'\n )\n}\n\n/**\n * The `wallets` a checkout response carries, as the browser reads it. Anything\n * that is not exactly `'auto'` or `'never'` is dropped, so a malformed or old\n * response shows every wallet rather than breaking the payment form.\n */\nexport function readStorefrontCheckoutWallets(\n raw: unknown,\n): StorefrontCheckoutWallets | undefined {\n if (!raw || typeof raw !== 'object') return undefined\n const value = (key: string): StorefrontWalletDisplay =>\n (raw as Record<string, unknown>)[key] === 'never' ? 'never' : 'auto'\n const wallets: StorefrontCheckoutWallets = {\n applePay: value('applePay'),\n googlePay: value('googlePay'),\n link: value('link'),\n }\n return storefrontWalletsHideAny(wallets) ? wallets : undefined\n}\n"],"names":["STOREFRONT_PAYMENT_METHODS","id","label","kind","control","defaultOn","configurationKey","requirements","limits","subscriptions","needsDomain","capability","minCents","maxCents","STOREFRONT_PAYMENT_METHOD_IDS","map","method","storefrontPaymentMethodSpec","find","normalizeStorefrontPaymentMethodSettings","raw","out","value","isStorefrontPaymentMethodOn","settings","chosen","resolveStorefrontPaymentMethodControls","excluded","filter","display","wallets","applePay","googlePay","link","appendStorefrontPaymentMethodParams","params","controls","forEach","index","set","PAY_LINK_METHOD_IDS","payLinkPaymentMethodControls","includes","storefrontWalletsHideAny","readStorefrontCheckoutWallets","undefined","key"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyCC,GAED,+DAA+D,GAuD/D;;;;;CAKC,GACD,OAAO,MAAMA,6BAAqE;IAChF;QACEC,IAAI;QACJC,OAAO;QACPC,MAAM;QACNC,SAAS;QACTC,WAAW;QACXC,kBAAkB;QAClBC,cACE;QACFC,QAAQ;QACRC,eAAe;QACfC,aAAa;IACf;IACA;QACET,IAAI;QACJC,OAAO;QACPC,MAAM;QACNC,SAAS;QACTC,WAAW;QACXC,kBAAkB;QAClBC,cACE;QACFC,QAAQ;QACRC,eAAe;QACfC,aAAa;IACf;IACA;QACET,IAAI;QACJC,OAAO;QACPC,MAAM;QACNC,SAAS;QACTC,WAAW;QACXC,kBAAkB;QAClBC,cAAc;QACdC,QAAQ;QACRC,eAAe;QACfC,aAAa;IACf;IACA;QACET,IAAI;QACJC,OAAO;QACPC,MAAM;QACNC,SAAS;QACTC,WAAW;QACXM,YAAY;QACZL,kBAAkB;QAClBC,cACE;QACFC,QAAQ;QACRI,UAAU;QACVH,eAAe;QACfC,aAAa;IACf;IACA;QACET,IAAI;QACJC,OAAO;QACPC,MAAM;QACNC,SAAS;QACTC,WAAW;QACXM,YAAY;QACZL,kBAAkB;QAClBC,cAAc;QACdC,QAAQ;QACRI,UAAU;QACVC,UAAU;QACVJ,eAAe;QACfC,aAAa;IACf;IACA;QACET,IAAI;QACJC,OAAO;QACPC,MAAM;QACNC,SAAS;QACTC,WAAW;QACXM,YAAY;QACZL,kBAAkB;QAClBC,cACE;QACFC,QAAQ;QACRI,UAAU;QACVC,UAAU;QACVJ,eAAe;QACfC,aAAa;IACf;IACA;QACET,IAAI;QACJC,OAAO;QACPC,MAAM;QACNC,SAAS;QACTC,WAAW;QACXM,YAAY;QACZL,kBAAkB;QAClBC,cAAc;QACd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MvB,QAAQ,CAACwB,MACb,AAAC1B,GAA+B,CAAC0B,IAAI,KAAK,UAAU,UAAU;IAChE,MAAMhB,UAAqC;QACzCC,UAAUT,MAAM;QAChBU,WAAWV,MAAM;QACjBW,MAAMX,MAAM;IACd;IACA,OAAOqB,yBAAyBb,WAAWA,UAAUe;AACvD"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/model/commerce-payment-methods.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n BUY_NOW_PAY_LATER_PAYMENT_METHOD_TYPES,\n type BuyNowPayLaterPaymentMethodType,\n} from '@aglyn/aglyn/app-utils/buy-now-pay-later'\n\n/**\n * The storefront payment methods a merchant chooses between (AGL-3629).\n *\n * ## Who decides what a shopper sees\n *\n * Every storefront charge is a DESTINATION charge with no `on_behalf_of`, so\n * the PLATFORM is the merchant of record and Stripe offers the methods the\n * platform's payment method configuration turns on (\"dynamic payment\n * methods\"), filtered by currency, amount, the shopper's country and device.\n * No session pins `payment_method_types`. A merchant therefore cannot ADD a\n * method the platform does not offer — they can only take one away, and that\n * is what the two levers below do:\n *\n * - `excluded_payment_method_types` on the Checkout Session, for every method\n * Stripe lets a session exclude. Measured accepted at both the account\n * default API version and the native checkout's pinned dahlia version, so\n * it applies to the in-page checkout AND the hosted Stripe page alike.\n * - The Payment Element's `wallets` option for Apple Pay, Google Pay and\n * Link, which Stripe documents as NOT excludable per session. Link is also\n * hidden on the session with `wallet_options[link][display]=never`, which\n * reaches the hosted page; Apple Pay and Google Pay on a hosted Stripe page\n * follow the device and cannot be hidden per merchant.\n *\n * ## Buy-now-pay-later is never offered (AGL-4198)\n *\n * Klarna, Afterpay and Affirm are not in this catalog and are excluded on every\n * session (`BUY_NOW_PAY_LATER_PAYMENT_METHOD_TYPES`), whatever a store chose\n * before. They cost Stripe about 6% + 30¢ against 2.9% + 30¢ for a card, and\n * the platform's fee is fixed before the shopper picks how to pay, so offering\n * them would size every fee for the dearest method.\n *\n * ## Why toggling a method never moves a fee\n *\n * `application_fee_amount` is priced at the card rate\n * (`SALE_PROCESSING_PERCENT`). Every method in this catalog costs Stripe that\n * much or less (Apple Pay, Google Pay, Link, Cash App Pay and Amazon Pay are\n * 2.9% + 30¢ on Stripe's US pricing, stablecoins 1.5%), so turning one off or\n * on changes what a shopper may choose and never what the platform recovers.\n * A method added here must cost no more than a card; the catalog spec holds\n * the list.\n */\n\n/** A method the merchant may switch off (or, for crypto, on). */\nexport type StorefrontPaymentMethodId =\n | 'apple_pay'\n | 'google_pay'\n | 'link'\n | 'cashapp'\n | 'amazon_pay'\n | 'crypto'\n\nexport type StorefrontPaymentMethodKind = 'wallet' | 'crypto'\n\n/** A method a session excludes: one the merchant switched off, or buy-now-pay-later. */\nexport type ExcludedPaymentMethodType = StorefrontPaymentMethodId | BuyNowPayLaterPaymentMethodType\n\n/** How a toggle reaches Stripe. */\nexport type StorefrontPaymentMethodControl =\n /** The Payment Element's `wallets` option (and, for Link, the session). */\n | 'wallet'\n /** `excluded_payment_method_types` on the Checkout Session. */\n | 'exclude'\n\nexport interface StorefrontPaymentMethodSpec {\n id: StorefrontPaymentMethodId\n label: string\n kind: StorefrontPaymentMethodKind\n control: StorefrontPaymentMethodControl\n /**\n * On when the merchant has never chosen. Every method that was already\n * reaching shoppers before AGL-3629 defaults on, so saving nothing changes\n * nothing; crypto, which settles differently and cannot be disputed,\n * defaults off and is the merchant's to opt into.\n */\n defaultOn: boolean\n /**\n * The connected-account capability Stripe asks platforms to request before\n * the method is accepted for that account. Absent for the card wallets,\n * which ride `card_payments`.\n */\n capability?: string\n /** The platform payment method configuration's key for this method. */\n configurationKey: string\n /** What a shopper needs, in a sentence the settings card shows. */\n requirements: string\n /** Amount and currency limits, as Stripe publishes them for US accounts. */\n limits: string\n /** Lowest charge Stripe offers it for, in USD cents, when published. */\n minCents?: number\n /** Highest charge Stripe offers it for, in USD cents, when published. */\n maxCents?: number\n /** False where Stripe does not offer it in a subscription-mode session. */\n subscriptions: boolean\n /** Shown on a registered domain only (Apple Pay must be; the rest benefit). */\n needsDomain: boolean\n}\n\n/**\n * The catalog, in the order the settings card lists it. Limits are Stripe's\n * published US figures (docs.stripe.com/payments/buy-now-pay-later and each\n * method's page, read 2026-10-07); Stripe applies them itself, and they are\n * here so a merchant can read why a method did not appear on an order.\n */\nexport const STOREFRONT_PAYMENT_METHODS: readonly StorefrontPaymentMethodSpec[] = [\n {\n id: 'apple_pay',\n label: 'Apple Pay',\n kind: 'wallet',\n control: 'wallet',\n defaultOn: true,\n configurationKey: 'apple_pay',\n requirements:\n 'Safari on a Mac, iPhone or iPad with a card in Apple Wallet. Your site’s domain is registered with Apple Pay for you.',\n limits: 'Same as cards.',\n subscriptions: true,\n needsDomain: true,\n },\n {\n id: 'google_pay',\n label: 'Google Pay',\n kind: 'wallet',\n control: 'wallet',\n defaultOn: true,\n configurationKey: 'google_pay',\n requirements:\n 'Chrome or an Android device with a card saved to Google Pay. With Stripe Tax on, Google Pay shows when the checkout collects a shipping address.',\n limits: 'Same as cards.',\n subscriptions: true,\n needsDomain: true,\n },\n {\n id: 'link',\n label: 'Link',\n kind: 'wallet',\n control: 'wallet',\n defaultOn: true,\n configurationKey: 'link',\n requirements: 'Shoppers who saved a card or bank with Link check out in one step.',\n limits: 'Same as cards.',\n subscriptions: true,\n needsDomain: true,\n },\n {\n id: 'cashapp',\n label: 'Cash App Pay',\n kind: 'wallet',\n control: 'exclude',\n defaultOn: true,\n capability: 'cashapp_payments',\n configurationKey: 'cashapp',\n requirements: 'US shoppers with Cash App, paying in USD.',\n limits: 'USD only.',\n subscriptions: true,\n needsDomain: false,\n },\n {\n id: 'amazon_pay',\n label: 'Amazon Pay',\n kind: 'wallet',\n control: 'exclude',\n defaultOn: true,\n capability: 'amazon_pay_payments',\n configurationKey: 'amazon_pay',\n requirements: 'Shoppers pay with the card and address saved to their Amazon account.',\n limits: 'USD only.',\n subscriptions: true,\n needsDomain: true,\n },\n {\n id: 'crypto',\n label: 'Stablecoins (crypto)',\n kind: 'crypto',\n control: 'exclude',\n defaultOn: false,\n capability: 'crypto_payments',\n configurationKey: 'crypto',\n requirements:\n 'Shoppers pay in USDC or another supported stablecoin from their crypto wallet; you are paid in USD. Refunds go back to the shopper’s wallet as stablecoins, and these payments cannot be disputed.',\n limits: 'USD only, up to $10,000 per payment.',\n maxCents: 1_000_000,\n subscriptions: true,\n needsDomain: false,\n },\n]\n\n/** The merchant's choices, as stored on `hosts/{hostId}/settings/store`. */\nexport type StorefrontPaymentMethodSettings = Partial<\n Record<StorefrontPaymentMethodId, boolean>\n>\n\nexport const STOREFRONT_PAYMENT_METHOD_IDS: readonly StorefrontPaymentMethodId[] =\n STOREFRONT_PAYMENT_METHODS.map((method) => method.id)\n\nexport function storefrontPaymentMethodSpec(\n id: string,\n): StorefrontPaymentMethodSpec | undefined {\n return STOREFRONT_PAYMENT_METHODS.find((method) => method.id === id)\n}\n\n/**\n * Keep only booleans under known ids. The settings document is written by the\n * console, so anything else on it — a string, a removed method, a typo — is\n * read as \"never chosen\" rather than trusted.\n */\nexport function normalizeStorefrontPaymentMethodSettings(\n raw: unknown,\n): StorefrontPaymentMethodSettings {\n const out: StorefrontPaymentMethodSettings = {}\n if (!raw || typeof raw !== 'object') return out\n for (const id of STOREFRONT_PAYMENT_METHOD_IDS) {\n const value = (raw as Record<string, unknown>)[id]\n if (typeof value === 'boolean') out[id] = value\n }\n return out\n}\n\n/** Whether the merchant offers a method: their choice, else its default. */\nexport function isStorefrontPaymentMethodOn(\n settings: StorefrontPaymentMethodSettings | null | undefined,\n id: StorefrontPaymentMethodId,\n): boolean {\n const chosen = settings?.[id]\n if (typeof chosen === 'boolean') return chosen\n return storefrontPaymentMethodSpec(id)?.defaultOn ?? false\n}\n\n/** `auto` lets Stripe decide from the device; `never` hides the wallet. */\nexport type StorefrontWalletDisplay = 'auto' | 'never'\n\n/** The Payment Element's `wallets` option, as the browser receives it. */\nexport interface StorefrontCheckoutWallets {\n applePay: StorefrontWalletDisplay\n googlePay: StorefrontWalletDisplay\n link: StorefrontWalletDisplay\n}\n\nexport interface StorefrontPaymentMethodControls {\n /** Sent as `excluded_payment_method_types[n]`: buy-now-pay-later, then the merchant's, in catalog order. */\n excluded: ExcludedPaymentMethodType[]\n /** Handed to the Payment Element. */\n wallets: StorefrontCheckoutWallets\n}\n\n/**\n * What one checkout session sends Stripe for the merchant's choices.\n *\n * A method the merchant left on is NOT added anywhere: dynamic payment methods\n * already offer it when the platform does and the order qualifies. Named are\n * buy-now-pay-later, always (AGL-4198), then the methods turned off, which\n * include crypto until it is chosen.\n */\nexport function resolveStorefrontPaymentMethodControls(\n settings: StorefrontPaymentMethodSettings | null | undefined,\n): StorefrontPaymentMethodControls {\n const excluded: ExcludedPaymentMethodType[] = [\n ...BUY_NOW_PAY_LATER_PAYMENT_METHOD_TYPES,\n ...STOREFRONT_PAYMENT_METHODS.filter(\n (method) =>\n method.control === 'exclude' && !isStorefrontPaymentMethodOn(settings, method.id),\n ).map((method) => method.id),\n ]\n const display = (id: StorefrontPaymentMethodId): StorefrontWalletDisplay =>\n isStorefrontPaymentMethodOn(settings, id) ? 'auto' : 'never'\n return {\n excluded,\n wallets: {\n applePay: display('apple_pay'),\n googlePay: display('google_pay'),\n link: display('link'),\n },\n }\n}\n\n/**\n * Write the controls onto a Checkout Session param set: every exclusion in\n * order, and Link hidden on the session when the merchant hid it.\n */\nexport function appendStorefrontPaymentMethodParams(\n params: URLSearchParams,\n controls: StorefrontPaymentMethodControls,\n): void {\n controls.excluded.forEach((id, index) => {\n params.set(`excluded_payment_method_types[${index}]`, id)\n })\n if (controls.wallets.link === 'never') {\n params.set('wallet_options[link][display]', 'never')\n }\n}\n\n/** True when the browser has to be told about a hidden wallet at all. */\nexport function storefrontWalletsHideAny(wallets: StorefrontCheckoutWallets): boolean {\n return (\n wallets.applePay === 'never' ||\n wallets.googlePay === 'never' ||\n wallets.link === 'never'\n )\n}\n\n/**\n * The `wallets` a checkout response carries, as the browser reads it. Anything\n * that is not exactly `'auto'` or `'never'` is dropped, so a malformed or old\n * response shows every wallet rather than breaking the payment form.\n */\nexport function readStorefrontCheckoutWallets(\n raw: unknown,\n): StorefrontCheckoutWallets | undefined {\n if (!raw || typeof raw !== 'object') return undefined\n const value = (key: string): StorefrontWalletDisplay =>\n (raw as Record<string, unknown>)[key] === 'never' ? 'never' : 'auto'\n const wallets: StorefrontCheckoutWallets = {\n applePay: value('applePay'),\n googlePay: value('googlePay'),\n link: value('link'),\n }\n return storefrontWalletsHideAny(wallets) ? wallets : undefined\n}\n"],"names":["BUY_NOW_PAY_LATER_PAYMENT_METHOD_TYPES","STOREFRONT_PAYMENT_METHODS","id","label","kind","control","defaultOn","configurationKey","requirements","limits","subscriptions","needsDomain","capability","maxCents","STOREFRONT_PAYMENT_METHOD_IDS","map","method","storefrontPaymentMethodSpec","find","normalizeStorefrontPaymentMethodSettings","raw","out","value","isStorefrontPaymentMethodOn","settings","chosen","resolveStorefrontPaymentMethodControls","excluded","filter","display","wallets","applePay","googlePay","link","appendStorefrontPaymentMethodParams","params","controls","forEach","index","set","storefrontWalletsHideAny","readStorefrontCheckoutWallets","undefined","key"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACEA,sCAAsC,QAEjC,2CAA0C;AAmGjD;;;;;CAKC,GACD,OAAO,MAAMC,6BAAqE;IAChF;QACEC,IAAI;QACJC,OAAO;QACPC,MAAM;QACNC,SAAS;QACTC,WAAW;QACXC,kBAAkB;QAClBC,cACE;QACFC,QAAQ;QACRC,eAAe;QACfC,aAAa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IAAI,KAAK,UAAU,UAAU;IAChE,MAAMb,UAAqC;QACzCC,UAAUT,MAAM;QAChBU,WAAWV,MAAM;QACjBW,MAAMX,MAAM;IACd;IACA,OAAOkB,yBAAyBV,WAAWA,UAAUY;AACvD"}
|
|
@@ -21,4 +21,27 @@ import type { BillingWebhookHandler } from '@aglyn/aglyn/server';
|
|
|
21
21
|
* Exported for the spec.
|
|
22
22
|
*/
|
|
23
23
|
export declare function subscriptionPeriodEnd(object: any): number | null;
|
|
24
|
+
/**
|
|
25
|
+
* The connected account a Connect-delivered event belongs to, or null for an
|
|
26
|
+
* event on the platform's own account. Direct-charge sales are created ON the
|
|
27
|
+
* seller's account, so their events arrive through the Connect destination
|
|
28
|
+
* with the seller named at the top level.
|
|
29
|
+
*/
|
|
30
|
+
export declare function connectEventAccount(event: unknown): string | null;
|
|
31
|
+
/**
|
|
32
|
+
* Whether this handler should act on the event at all, as far as WHOSE
|
|
33
|
+
* account it came from can say. A platform event always passes. A
|
|
34
|
+
* Connect-delivered one passes only when its object says it was sold by
|
|
35
|
+
* direct charge, or when it is a charge-level event the order lookup will
|
|
36
|
+
* judge ({@link connectEventOrderIsDirect}). Exported for the spec.
|
|
37
|
+
*/
|
|
38
|
+
export declare function connectEventIsForDirectSale(type: unknown, object: unknown, event: unknown): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* The fields a direct sale's records carry so every later reader can tell it
|
|
41
|
+
* apart without asking Stripe: `refund.ts` refunds on the seller's account,
|
|
42
|
+
* the revenue report counts the application fee as Aglyn's whole take, and
|
|
43
|
+
* the dispute branch leaves the transfer reversal out. Empty for a
|
|
44
|
+
* destination sale, so those documents are written exactly as before.
|
|
45
|
+
*/
|
|
46
|
+
export declare function directChargeRecordFields(direct: boolean, account: string | null): Record<string, string>;
|
|
24
47
|
export declare const commerceBillingWebhookHandler: BillingWebhookHandler;
|