@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
|
@@ -22,7 +22,7 @@ import { planLabelGrantingFeature } from "@aglyn/aglyn/app-utils/plan-entitlemen
|
|
|
22
22
|
import * as CommerceModel from "../model/index.js";
|
|
23
23
|
import { claimAttempt, deriveStripeObjectKey } from "@aglyn/aglyn/server";
|
|
24
24
|
import { firebaseAdmin, getOrgForHost } from "@aglyn/tenant-data-admin";
|
|
25
|
-
import { merchantAccountIsReady } from "@aglyn/tenant-data-admin/server/payment-provider";
|
|
25
|
+
import { connectedAccountHeader, directChargeParams, merchantAccountIsReady, saleChargeModel } from "@aglyn/tenant-data-admin/server/payment-provider";
|
|
26
26
|
import { checkoutSessionCardAuthenticationParams } from "@aglyn/tenant-data-admin/server/stripe-card-authentication";
|
|
27
27
|
import { CARRIER_POSTAL_CODE_MESSAGE, planCheckoutShippingWithCarriers } from "./carrier-shipping.js";
|
|
28
28
|
import { readActiveMemberSession } from "./membership.js";
|
|
@@ -39,6 +39,7 @@ import { holdStock, stockHoldKey } from "./stock-hold.js";
|
|
|
39
39
|
import { appendLocalFulfillmentMetadata, localFulfillmentLocationId, localStockRefusalMessage, planLocalFulfillment, readLocalFulfillmentRequest, readLocalFulfillmentStore } from "./local-fulfillment.js";
|
|
40
40
|
import { applyNativeCheckoutParams, nativeCheckoutStripeHeaders, readCheckoutSessionPayload, resolveNativeCheckoutMode } from "./native-checkout.js";
|
|
41
41
|
import { ensureCheckoutDomain } from "./payment-method-domains.js";
|
|
42
|
+
import { SELLER_STRIPE_TAX_NOT_SET_UP_MESSAGE, sellerStripeTaxActive } from "./seller-stripe-account.js";
|
|
42
43
|
/**
|
|
43
44
|
* Commerce Starter checkout (AGL-90): a site visitor buys a product. The
|
|
44
45
|
* price ALWAYS comes from the host's product doc (never the request), the
|
|
@@ -376,6 +377,14 @@ export const checkoutHandler = async (req, res)=>{
|
|
|
376
377
|
error: 'This site has not enabled payments yet'
|
|
377
378
|
});
|
|
378
379
|
}
|
|
380
|
+
// WHO SELLS (direct charges). A seller on their own full Stripe account
|
|
381
|
+
// is the merchant of record: the session is created ON that account and
|
|
382
|
+
// Aglyn keeps its take as an application fee. Express accounts from
|
|
383
|
+
// before the switch stay destination charges, and so does Aglyn's own
|
|
384
|
+
// card-reader hardware, which Aglyn sells and taxes itself.
|
|
385
|
+
const chargeModel = hardware.hardware ? 'destination' : saleChargeModel(ownerProfile.get('stripeChargeModel'));
|
|
386
|
+
const direct = chargeModel === 'direct';
|
|
387
|
+
const sellerAccountHeader = connectedAccountHeader(chargeModel, accountId);
|
|
379
388
|
// The list price per unit, before any coupon (AGL-1711). This is what the
|
|
380
389
|
// order's line-item snapshot records, and it is carried in the session
|
|
381
390
|
// metadata so the webhook never has to re-price from the product doc.
|
|
@@ -547,6 +556,13 @@ export const checkoutHandler = async (req, res)=>{
|
|
|
547
556
|
});
|
|
548
557
|
}
|
|
549
558
|
const useStripeTax = taxDecision.kind === 'stripe-automatic';
|
|
559
|
+
// A direct-charge store's Stripe Tax runs on ITS account, against its
|
|
560
|
+
// registrations, and Stripe refuses the session where it is not set up.
|
|
561
|
+
if (direct && useStripeTax && !await sellerStripeTaxActive(String(accountId))) {
|
|
562
|
+
return res.status(409).json({
|
|
563
|
+
error: SELLER_STRIPE_TAX_NOT_SET_UP_MESSAGE
|
|
564
|
+
});
|
|
565
|
+
}
|
|
550
566
|
let taxCents = 0;
|
|
551
567
|
let taxLabel = '';
|
|
552
568
|
let taxPct = 0;
|
|
@@ -736,12 +752,14 @@ export const checkoutHandler = async (req, res)=>{
|
|
|
736
752
|
let recurringTaxRateId = '';
|
|
737
753
|
if (isSubscription && taxCents > 0) {
|
|
738
754
|
var _ref10;
|
|
739
|
-
recurringTaxRateId = (_ref10 = await resolveManualTaxRateId({
|
|
755
|
+
recurringTaxRateId = (_ref10 = await resolveManualTaxRateId(_extends({
|
|
740
756
|
hostRef,
|
|
741
757
|
taxPct,
|
|
742
758
|
taxLabel,
|
|
743
759
|
headers: stripeKeyHeader('tax-rate')
|
|
744
|
-
}
|
|
760
|
+
}, direct ? {
|
|
761
|
+
stripeAccount: String(accountId)
|
|
762
|
+
} : {}))) != null ? _ref10 : '';
|
|
745
763
|
if (!recurringTaxRateId) {
|
|
746
764
|
// Nothing was sold — hand the key back so the same button works
|
|
747
765
|
// once Stripe does (AGL-1697).
|
|
@@ -932,8 +950,14 @@ export const checkoutHandler = async (req, res)=>{
|
|
|
932
950
|
// out on `subscription_data` further down, and `feeCents` here is what
|
|
933
951
|
// that percent takes of the opening cycle's goods — the figure
|
|
934
952
|
// `metadata[feeCents]` records as what Aglyn keeps.
|
|
935
|
-
const subscriptionFeePercent = isSubscription ? Aglyn.resolveSubscriptionFeePercent(ownerOrg.org, (_lifted_type2 = lifted.type) != null ? _lifted_type2 : 'physical', amountCents
|
|
936
|
-
|
|
953
|
+
const subscriptionFeePercent = isSubscription ? Aglyn.resolveSubscriptionFeePercent(ownerOrg.org, (_lifted_type2 = lifted.type) != null ? _lifted_type2 : 'physical', amountCents, {
|
|
954
|
+
stripeTax: useStripeTax,
|
|
955
|
+
direct
|
|
956
|
+
}) : 0;
|
|
957
|
+
const feeCents = isSubscription ? subscriptionFeePercent > 0 ? Math.max(1, Math.round(amountCents * subscriptionFeePercent / 100)) : 0 : Aglyn.resolveTransactionFeeCents(ownerOrg.org, (_lifted_type3 = lifted.type) != null ? _lifted_type3 : 'physical', amountCents, amountCents + taxCents + shippingCeilingCents, {
|
|
958
|
+
stripeTax: useStripeTax,
|
|
959
|
+
direct
|
|
960
|
+
});
|
|
937
961
|
// The unit price Stripe actually charges — the coupon is priced INTO it
|
|
938
962
|
// rather than sent as a Stripe discount, which is why `amount_discount` is
|
|
939
963
|
// 0 on every buy-now session and the discount has to ride the metadata
|
|
@@ -989,7 +1013,9 @@ export const checkoutHandler = async (req, res)=>{
|
|
|
989
1013
|
'line_items[0][price_data][recurring][interval]': lifted.subscription.interval
|
|
990
1014
|
}, lifted.subscription.trialDays ? {
|
|
991
1015
|
'subscription_data[trial_period_days]': String(lifted.subscription.trialDays)
|
|
992
|
-
} : {}, {
|
|
1016
|
+
} : {}, direct ? {
|
|
1017
|
+
'subscription_data[metadata][chargeModel]': 'direct'
|
|
1018
|
+
} : {
|
|
993
1019
|
'subscription_data[transfer_data][destination]': String(accountId)
|
|
994
1020
|
}, subscriptionFeePercent > 0 ? {
|
|
995
1021
|
'subscription_data[application_fee_percent]': String(subscriptionFeePercent)
|
|
@@ -1009,7 +1035,9 @@ export const checkoutHandler = async (req, res)=>{
|
|
|
1009
1035
|
'line_items[0][tax_rates][0]': recurringTaxRateId
|
|
1010
1036
|
} : {}, useStripeTax ? {
|
|
1011
1037
|
'automatic_tax[enabled]': 'true'
|
|
1012
|
-
} : {}, !isSubscription ?
|
|
1038
|
+
} : {}, direct && !isSubscription ? directChargeParams(feeCents) : {}, direct ? {
|
|
1039
|
+
'metadata[chargeModel]': 'direct'
|
|
1040
|
+
} : {}, !isSubscription && !direct ? CommerceModel.destinationChargeParams({
|
|
1013
1041
|
accountId: String(accountId),
|
|
1014
1042
|
feeCents,
|
|
1015
1043
|
taxOwner: useStripeTax ? 'platform' : 'merchant',
|
|
@@ -1035,7 +1063,7 @@ export const checkoutHandler = async (req, res)=>{
|
|
|
1035
1063
|
'metadata[feeCents]': String(feeCents)
|
|
1036
1064
|
}, hardwareParams, shippingPlan.quotedPostalCode ? {
|
|
1037
1065
|
'metadata[shippingQuotePostalCode]': shippingPlan.quotedPostalCode
|
|
1038
|
-
} : {}, useStripeTax && !isSubscription ? {
|
|
1066
|
+
} : {}, useStripeTax && !isSubscription && !direct ? {
|
|
1039
1067
|
'metadata[transferCents]': String(CommerceModel.platformLiableTransferCents({
|
|
1040
1068
|
feeCents,
|
|
1041
1069
|
merchantGoodsCents: amountCents,
|
|
@@ -1126,17 +1154,19 @@ export const checkoutHandler = async (req, res)=>{
|
|
|
1126
1154
|
// Apple Pay shows on a registered domain only (AGL-3629). Started beside
|
|
1127
1155
|
// the session create rather than before it, inside a fixed budget, and
|
|
1128
1156
|
// never throws: a sale does not wait on, or fail for, a registration.
|
|
1129
|
-
const domainRegistration = nativeMode.native ? ensureCheckoutDomain({
|
|
1157
|
+
const domainRegistration = nativeMode.native ? ensureCheckoutDomain(_extends({
|
|
1130
1158
|
pageUrl: backUrl,
|
|
1131
1159
|
site: hostSnapshot.data == null ? void 0 : hostSnapshot.data.call(hostSnapshot),
|
|
1132
1160
|
hostId
|
|
1133
|
-
}
|
|
1161
|
+
}, direct ? {
|
|
1162
|
+
stripeAccount: String(accountId)
|
|
1163
|
+
} : {})).catch(()=>null) : Promise.resolve(null);
|
|
1134
1164
|
const response = await fetch('https://api.stripe.com/v1/checkout/sessions', {
|
|
1135
1165
|
method: 'POST',
|
|
1136
1166
|
headers: _extends({
|
|
1137
1167
|
Authorization: `Bearer ${process.env.STRIPE_SECRET_KEY}`,
|
|
1138
1168
|
'Content-Type': 'application/x-www-form-urlencoded'
|
|
1139
|
-
}, stripeKeyHeader(engineTax.stamp ? `session-tax-${taxCents}-${engineTax.stamp.status}` : 'session'), nativeCheckoutStripeHeaders(nativeMode)),
|
|
1169
|
+
}, stripeKeyHeader(engineTax.stamp ? `session-tax-${taxCents}-${engineTax.stamp.status}` : 'session'), nativeCheckoutStripeHeaders(nativeMode), sellerAccountHeader),
|
|
1140
1170
|
body: params.toString()
|
|
1141
1171
|
});
|
|
1142
1172
|
const session = await response.json();
|
|
@@ -1144,7 +1174,7 @@ export const checkoutHandler = async (req, res)=>{
|
|
|
1144
1174
|
// url — so the check moves with the mode rather than staying behind and
|
|
1145
1175
|
// reading every successful native session as a Stripe failure (AGL-1944).
|
|
1146
1176
|
await domainRegistration;
|
|
1147
|
-
const payload = response.ok ? readCheckoutSessionPayload(session, nativeMode, paymentMethodControls.wallets) : null;
|
|
1177
|
+
const payload = response.ok ? readCheckoutSessionPayload(session, nativeMode, paymentMethodControls.wallets, direct ? String(accountId) : undefined) : null;
|
|
1148
1178
|
if (!payload) {
|
|
1149
1179
|
console.error('Stripe checkout error', session.error);
|
|
1150
1180
|
// Nothing was sold — hand the key back so one flaky moment does not
|