@aglyn/plugins-commerce 1.31.0 → 1.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/package.json +13 -13
- package/src/lib/components/cart.js +35 -15
- package/src/lib/components/cart.js.map +1 -1
- package/src/lib/components/commerce-console-page.js +6 -0
- package/src/lib/components/commerce-console-page.js.map +1 -1
- package/src/lib/components/console/currencies-card.component.d.ts +21 -0
- package/src/lib/components/console/currencies-card.component.js +408 -0
- package/src/lib/components/console/currencies-card.component.js.map +1 -0
- package/src/lib/components/console/product-add-ons-fields.component.d.ts +13 -0
- package/src/lib/components/console/product-add-ons-fields.component.js +74 -2
- package/src/lib/components/console/product-add-ons-fields.component.js.map +1 -1
- package/src/lib/components/console/product-editor-dialog.component.js +42 -1
- package/src/lib/components/console/product-editor-dialog.component.js.map +1 -1
- package/src/lib/components/console/product-fixed-prices-fields.component.d.ts +25 -0
- package/src/lib/components/console/product-fixed-prices-fields.component.js +112 -0
- package/src/lib/components/console/product-fixed-prices-fields.component.js.map +1 -0
- package/src/lib/components/console/reservations-card.component.js +32 -15
- package/src/lib/components/console/reservations-card.component.js.map +1 -1
- package/src/lib/components/console/shipping-settings-card.component.js +100 -1
- package/src/lib/components/console/shipping-settings-card.component.js.map +1 -1
- package/src/lib/components/console/store-settings-card.component.js +1 -1
- package/src/lib/components/console/store-settings-card.component.js.map +1 -1
- package/src/lib/components/console/use-currency-setup.d.ts +20 -0
- package/src/lib/components/console/use-currency-setup.js +61 -0
- package/src/lib/components/console/use-currency-setup.js.map +1 -0
- package/src/lib/components/currency-selector.d.ts +36 -0
- package/src/lib/components/currency-selector.js +157 -0
- package/src/lib/components/currency-selector.js.map +1 -0
- package/src/lib/components/product-add-ons.d.ts +9 -1
- package/src/lib/components/product-add-ons.js +8 -4
- package/src/lib/components/product-add-ons.js.map +1 -1
- package/src/lib/components/product-choice-cards.d.ts +13 -1
- package/src/lib/components/product-choice-cards.js +5 -4
- package/src/lib/components/product-choice-cards.js.map +1 -1
- package/src/lib/components/product-detail.d.ts +8 -0
- package/src/lib/components/product-detail.js +38 -11
- package/src/lib/components/product-detail.js.map +1 -1
- package/src/lib/components/product-grid.d.ts +2 -0
- package/src/lib/components/product-grid.js +22 -9
- package/src/lib/components/product-grid.js.map +1 -1
- package/src/lib/components/related-products.js +6 -2
- package/src/lib/components/related-products.js.map +1 -1
- package/src/lib/components/shopper-currency.d.ts +108 -0
- package/src/lib/components/shopper-currency.js +262 -0
- package/src/lib/components/shopper-currency.js.map +1 -0
- package/src/lib/components/wishlist.js +7 -1
- package/src/lib/components/wishlist.js.map +1 -1
- package/src/lib/declarations.server.js +39 -0
- package/src/lib/declarations.server.js.map +1 -1
- package/src/lib/model/commerce-currency-setup.d.ts +79 -0
- package/src/lib/model/commerce-currency-setup.js +124 -0
- package/src/lib/model/commerce-currency-setup.js.map +1 -0
- package/src/lib/model/commerce-currency.d.ts +215 -0
- package/src/lib/model/commerce-currency.js +511 -0
- package/src/lib/model/commerce-currency.js.map +1 -0
- package/src/lib/model/commerce-orders.d.ts +17 -0
- package/src/lib/model/commerce-orders.js +10 -5
- package/src/lib/model/commerce-orders.js.map +1 -1
- package/src/lib/model/commerce-record-routes.js +26 -1
- package/src/lib/model/commerce-record-routes.js.map +1 -1
- package/src/lib/model/commerce-reservations.d.ts +6 -0
- package/src/lib/model/commerce-reservations.js.map +1 -1
- package/src/lib/model/commerce-shipping.d.ts +22 -1
- package/src/lib/model/commerce-shipping.js +31 -2
- package/src/lib/model/commerce-shipping.js.map +1 -1
- package/src/lib/model/commerce.d.ts +6 -0
- package/src/lib/model/commerce.js.map +1 -1
- package/src/lib/model/index.d.ts +2 -0
- package/src/lib/model/index.js +2 -0
- package/src/lib/model/index.js.map +1 -1
- package/src/lib/model/order-figures.js +9 -2
- package/src/lib/model/order-figures.js.map +1 -1
- package/src/lib/model/product-modifiers.d.ts +5 -0
- package/src/lib/model/product-modifiers.js.map +1 -1
- package/src/lib/server/billing-webhook.js +37 -24
- package/src/lib/server/billing-webhook.js.map +1 -1
- package/src/lib/server/cart-checkout.js +67 -11
- package/src/lib/server/cart-checkout.js.map +1 -1
- package/src/lib/server/cart.d.ts +12 -0
- package/src/lib/server/cart.js +50 -4
- package/src/lib/server/cart.js.map +1 -1
- package/src/lib/server/catalog.d.ts +5 -0
- package/src/lib/server/catalog.js +7 -0
- package/src/lib/server/catalog.js.map +1 -1
- package/src/lib/server/checkout.js +48 -12
- package/src/lib/server/checkout.js.map +1 -1
- package/src/lib/server/currency.d.ts +93 -0
- package/src/lib/server/currency.js +182 -0
- package/src/lib/server/currency.js.map +1 -0
- package/src/lib/server/order-notifications.js +4 -2
- package/src/lib/server/order-notifications.js.map +1 -1
- package/src/lib/server/product.d.ts +9 -0
- package/src/lib/server/product.js +12 -0
- package/src/lib/server/product.js.map +1 -1
- package/src/lib/server/refund.js +3 -3
- package/src/lib/server/refund.js.map +1 -1
- package/src/lib/server/site-chat-tools.d.ts +22 -0
- package/src/lib/server/site-chat-tools.js +369 -0
- package/src/lib/server/site-chat-tools.js.map +1 -0
- package/src/lib/server/site-chat-visitor.d.ts +24 -0
- package/src/lib/server/site-chat-visitor.js +39 -0
- package/src/lib/server/site-chat-visitor.js.map +1 -0
- package/src/lib/server/site-offers.d.ts +31 -0
- package/src/lib/server/site-offers.js +91 -0
- package/src/lib/server/site-offers.js.map +1 -0
- package/src/lib/server/stays-site-search.d.ts +20 -0
- package/src/lib/server/stays-site-search.js +78 -0
- package/src/lib/server/stays-site-search.js.map +1 -0
- package/src/lib/server.js +20 -0
- package/src/lib/server.js.map +1 -1
- package/src/lib/site-chat-tool-definitions.d.ts +26 -0
- package/src/lib/site-chat-tool-definitions.js +141 -0
- package/src/lib/site-chat-tool-definitions.js.map +1 -0
- package/src/lib/site.js +8 -0
- package/src/lib/site.js.map +1 -1
- package/src/lib/subprocessors.js +7 -0
- package/src/lib/subprocessors.js.map +1 -1
|
@@ -43,6 +43,7 @@ import { appendLocalFulfillmentMetadata, localFulfillmentLocationId, localStockR
|
|
|
43
43
|
import { applyNativeCheckoutParams, nativeCheckoutStripeHeaders, readCheckoutSessionPayload, resolveNativeCheckoutMode } from "./native-checkout.js";
|
|
44
44
|
import { ensureCheckoutDomain } from "./payment-method-domains.js";
|
|
45
45
|
import { raiseCheckoutStarted } from "./order-events.js";
|
|
46
|
+
import { checkoutAmountMinor, checkoutLineMinor, loadFxRates, resolveCheckoutCurrency, storeCurrencyContextFrom, stripeCurrency } from "./currency.js";
|
|
46
47
|
import { checkoutExtrasCents, encodeCheckoutExtrasMetadata, readChosenCheckoutExtras } from "@aglyn/aglyn/plugin-manager/plugin-checkout-extras";
|
|
47
48
|
import { quoteCartExtras } from "./checkout-extras.js";
|
|
48
49
|
import { boundedCreditCents, checkoutCreditProviderForCode, encodeCheckoutCreditMetadata, normalizeCheckoutCreditAccount, normalizeCheckoutCreditCode } from "@aglyn/aglyn/plugin-manager/plugin-checkout-credits";
|
|
@@ -173,6 +174,27 @@ import { boundedCreditCents, checkoutCreditProviderForCode, encodeCheckoutCredit
|
|
|
173
174
|
snapshot.id,
|
|
174
175
|
snapshot.exists ? CommerceModel.liftLegacyProduct(snapshot.data()) : null
|
|
175
176
|
]));
|
|
177
|
+
/**
|
|
178
|
+
* The currency the shopper is charged in (AGL-4248). Everything below is
|
|
179
|
+
* priced and checked in the store currency as before; only the amounts
|
|
180
|
+
* handed to Stripe are converted, at the emission. A direct sale only: a
|
|
181
|
+
* destination sale's split and platform tax are store-currency figures.
|
|
182
|
+
* A cart that sells a gift card stays in the store currency, because a
|
|
183
|
+
* card's balance is.
|
|
184
|
+
*/ let checkoutCurrency;
|
|
185
|
+
if (body.currency && direct) {
|
|
186
|
+
const currencyStore = await hostRef.collection('settings').doc('store').get();
|
|
187
|
+
const resolved = resolveCheckoutCurrency(storeCurrencyContextFrom(currencyStore.data(), await loadFxRates()), body.currency);
|
|
188
|
+
const sellsGiftCard = cart.lines.some((line)=>{
|
|
189
|
+
var _productsById_get;
|
|
190
|
+
return (_productsById_get = productsById.get(line.productId)) == null ? void 0 : _productsById_get.giftCard;
|
|
191
|
+
});
|
|
192
|
+
if (resolved.foreign && !sellsGiftCard) checkoutCurrency = resolved;
|
|
193
|
+
}
|
|
194
|
+
const chargeCurrency = checkoutCurrency ? stripeCurrency(checkoutCurrency) : 'usd';
|
|
195
|
+
/** The goods in the charge currency, as Stripe will total them. */ let itemsChargeMinor = 0;
|
|
196
|
+
/** Each line's store-currency unit, for the tax engine (it prices in the store currency). */ const baseUnitByIndex = new Map();
|
|
197
|
+
/** Each line's charge-currency unit, in cart order, for the order the webhook writes. */ const chargeUnits = [];
|
|
176
198
|
let itemsCents = 0;
|
|
177
199
|
/** Per-line values for scoped discount pricing. */ const discountLines = [];
|
|
178
200
|
// Gift-card value in the basket, for the cash-out ceiling (AGL-3363).
|
|
@@ -331,8 +353,19 @@ import { boundedCreditCents, checkoutCreditProviderForCode, encodeCheckoutCredit
|
|
|
331
353
|
if (feePct > 0) feeApplies = true;
|
|
332
354
|
feeCents += Math.round(unitCents * line.quantity * feePct / 100);
|
|
333
355
|
params.set(`line_items[${index}][quantity]`, String(line.quantity));
|
|
334
|
-
|
|
335
|
-
|
|
356
|
+
// The charge-currency unit: the variant's fixed price there or its
|
|
357
|
+
// store price converted, plus each add-on's (AGL-4248).
|
|
358
|
+
const chargeUnit = checkoutCurrency ? checkoutLineMinor(checkoutCurrency, product, variant, chosen.modifiers) : unitCents;
|
|
359
|
+
itemsChargeMinor += chargeUnit * line.quantity;
|
|
360
|
+
baseUnitByIndex.set(index, unitCents);
|
|
361
|
+
chargeUnits[index] = chargeUnit;
|
|
362
|
+
params.set(`line_items[${index}][price_data][currency]`, chargeCurrency);
|
|
363
|
+
params.set(`line_items[${index}][price_data][unit_amount]`, String(chargeUnit));
|
|
364
|
+
// Pinned whenever the charge is not in USD (AGL-1956 invariant 5):
|
|
365
|
+
// Stripe infers tax-inclusive pricing from some currencies otherwise.
|
|
366
|
+
if (checkoutCurrency) {
|
|
367
|
+
params.set(`line_items[${index}][price_data][tax_behavior]`, checkoutCurrency.entry.pricesIncludeTax ? 'inclusive' : 'exclusive');
|
|
368
|
+
}
|
|
336
369
|
// The variant, then the add-ons, as the order line will print them.
|
|
337
370
|
const lineLabel = CommerceModel.lineLabelWithModifiers(Object.keys((_variant_options = variant.options) != null ? _variant_options : {}).length ? Object.values((_variant_options1 = variant.options) != null ? _variant_options1 : {}).join(' / ') : undefined, chosen.modifiers);
|
|
338
371
|
const lineName = `${product.name}${lineLabel ? ` (${lineLabel})` : ''}`;
|
|
@@ -549,8 +582,8 @@ import { boundedCreditCents, checkoutCreditProviderForCode, encodeCheckoutCredit
|
|
|
549
582
|
chargedExtras.forEach((extra, offset)=>{
|
|
550
583
|
const index = cart.lines.length + offset;
|
|
551
584
|
params.set(`line_items[${index}][quantity]`, '1');
|
|
552
|
-
params.set(`line_items[${index}][price_data][currency]`,
|
|
553
|
-
params.set(`line_items[${index}][price_data][unit_amount]`, String(extra.amountCents));
|
|
585
|
+
params.set(`line_items[${index}][price_data][currency]`, chargeCurrency);
|
|
586
|
+
params.set(`line_items[${index}][price_data][unit_amount]`, String(checkoutCurrency ? checkoutAmountMinor(checkoutCurrency, extra.amountCents) : extra.amountCents));
|
|
554
587
|
params.set(`line_items[${index}][price_data][product_data][name]`, extra.label.slice(0, 120));
|
|
555
588
|
params.set(`line_items[${index}][price_data][product_data][tax_code]`, 'txcd_00000000');
|
|
556
589
|
});
|
|
@@ -993,10 +1026,12 @@ import { boundedCreditCents, checkoutCreditProviderForCode, encodeCheckoutCredit
|
|
|
993
1026
|
headers: _extends({
|
|
994
1027
|
Authorization: `Bearer ${process.env.STRIPE_SECRET_KEY}`,
|
|
995
1028
|
'Content-Type': 'application/x-www-form-urlencoded'
|
|
996
|
-
}, stripeKeyHeader(creditHeldCents > 0 ? `coupon-c${creditHeldCents}` : 'coupon'), sellerAccountHeader),
|
|
1029
|
+
}, stripeKeyHeader(`${creditHeldCents > 0 ? `coupon-c${creditHeldCents}` : 'coupon'}${checkoutCurrency ? `-${chargeCurrency}` : ''}`), sellerAccountHeader),
|
|
997
1030
|
body: new URLSearchParams({
|
|
998
|
-
|
|
999
|
-
currency
|
|
1031
|
+
// In the charge currency, as the same share of the goods it is of
|
|
1032
|
+
// the store-currency goods, so a 10% discount stays 10% (AGL-4248).
|
|
1033
|
+
amount_off: String(checkoutCurrency ? Math.min(itemsChargeMinor, Math.round(Math.min(totalOffCents, itemsCents) * itemsChargeMinor / Math.max(1, itemsCents))) : Math.min(totalOffCents, itemsCents)),
|
|
1034
|
+
currency: chargeCurrency,
|
|
1000
1035
|
duration: 'once'
|
|
1001
1036
|
}).toString()
|
|
1002
1037
|
}).then((response)=>response.json());
|
|
@@ -1051,8 +1086,8 @@ import { boundedCreditCents, checkoutCreditProviderForCode, encodeCheckoutCredit
|
|
|
1051
1086
|
// this session exists. When the service does not answer, the store's
|
|
1052
1087
|
// rate stands and the order says so.
|
|
1053
1088
|
const cartEngineLines = cart.lines.map((line, index)=>{
|
|
1054
|
-
var _params_get;
|
|
1055
|
-
const unitCents = Number((_params_get = params.get(`line_items[${index}][price_data][unit_amount]`)) != null ? _params_get : NaN);
|
|
1089
|
+
var _baseUnitByIndex_get, _params_get;
|
|
1090
|
+
const unitCents = (_baseUnitByIndex_get = baseUnitByIndex.get(index)) != null ? _baseUnitByIndex_get : Number((_params_get = params.get(`line_items[${index}][price_data][unit_amount]`)) != null ? _params_get : NaN);
|
|
1056
1091
|
return {
|
|
1057
1092
|
index,
|
|
1058
1093
|
line,
|
|
@@ -1123,7 +1158,13 @@ import { boundedCreditCents, checkoutCreditProviderForCode, encodeCheckoutCredit
|
|
|
1123
1158
|
// destinations the declared rates were resolved for. The emission is
|
|
1124
1159
|
// shared with buy-now (AGL-1720).
|
|
1125
1160
|
CommerceModel.appendShippingAddressCollectionParams(params, shippingPlan.countries);
|
|
1126
|
-
CommerceModel.appendCheckoutShippingParams(params, shippingOptions)
|
|
1161
|
+
CommerceModel.appendCheckoutShippingParams(params, checkoutCurrency ? CommerceModel.shippingOptionsInCurrency(shippingOptions, storeSettings.get('shipping'), {
|
|
1162
|
+
code: checkoutCurrency.code,
|
|
1163
|
+
subtotalMinor: itemsChargeMinor,
|
|
1164
|
+
convert: (cents, fixed)=>checkoutAmountMinor(checkoutCurrency, cents, fixed)
|
|
1165
|
+
}) : shippingOptions, chargeCurrency, (checkoutCurrency == null ? void 0 : checkoutCurrency.entry.pricesIncludeTax) ? {
|
|
1166
|
+
taxBehavior: 'inclusive'
|
|
1167
|
+
} : {});
|
|
1127
1168
|
// Taxes (AGL-1953). This block used to be the `stripe` line alone, and a
|
|
1128
1169
|
// `manual`-mode store — the mode the AGL-285 zone editor leaves a merchant
|
|
1129
1170
|
// in by default — collected tax on a buy-now sale and NOTHING on a cart
|
|
@@ -1325,7 +1366,9 @@ import { boundedCreditCents, checkoutCreditProviderForCode, encodeCheckoutCredit
|
|
|
1325
1366
|
// to hold back. The split is the take as `application_fee_amount`.
|
|
1326
1367
|
const cartTaxOwner = !direct && taxDecision.kind === 'stripe-automatic' ? 'platform' : 'merchant';
|
|
1327
1368
|
const cartShippingFloorCents = CommerceModel.shippingFloorCents(shippingOptions);
|
|
1328
|
-
Object.entries(direct ? directChargeParams(
|
|
1369
|
+
Object.entries(direct ? directChargeParams(// The take in the charge currency (AGL-4248): Stripe reads
|
|
1370
|
+
// `application_fee_amount` in the session's currency.
|
|
1371
|
+
checkoutCurrency ? checkoutAmountMinor(checkoutCurrency, feeCents) : feeCents) : CommerceModel.destinationChargeParams({
|
|
1329
1372
|
accountId: String(accountId),
|
|
1330
1373
|
feeCents,
|
|
1331
1374
|
taxOwner: cartTaxOwner,
|
|
@@ -1351,6 +1394,19 @@ import { boundedCreditCents, checkoutCreditProviderForCode, encodeCheckoutCredit
|
|
|
1351
1394
|
params.set('metadata[hostId]', hostId);
|
|
1352
1395
|
params.set('metadata[cartId]', cartId);
|
|
1353
1396
|
params.set('metadata[feeCents]', String(Math.max(0, feeCents)));
|
|
1397
|
+
// What the order records about the currency (AGL-4248). `feeCents` above
|
|
1398
|
+
// stays the store-currency take; the order's figures are in the charge
|
|
1399
|
+
// currency, with the store-currency equivalents beside them.
|
|
1400
|
+
if (checkoutCurrency) {
|
|
1401
|
+
for (const [key, value] of Object.entries(CommerceModel.encodeChargeUnitsMetadata(chargeUnits))){
|
|
1402
|
+
params.set(`metadata[${key}]`, value);
|
|
1403
|
+
}
|
|
1404
|
+
params.set('metadata[chargeFeeCents]', String(checkoutAmountMinor(checkoutCurrency, Math.max(0, feeCents))));
|
|
1405
|
+
params.set('metadata[chargeExtrasCents]', String(chargedExtras.reduce((sum, extra)=>sum + checkoutAmountMinor(checkoutCurrency, extra.amountCents), 0)));
|
|
1406
|
+
params.set('metadata[currency]', chargeCurrency);
|
|
1407
|
+
params.set('metadata[baseCurrency]', checkoutCurrency.base.toLowerCase());
|
|
1408
|
+
params.set('metadata[fxRate]', String(checkoutCurrency.rate));
|
|
1409
|
+
}
|
|
1354
1410
|
// Only on the shape where `transfer.amount` is no longer `charge.amount`,
|
|
1355
1411
|
// so the merchant's actual payout stops being derivable from the charge
|
|
1356
1412
|
// (AGL-1956). The shipping baseline is the other half: the difference
|