@aglyn/plugins-commerce 1.0.0-beta.287 → 1.0.0-beta.289
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 +2 -2
- package/package.json +13 -13
- package/src/lib/components/commerce-console-page.js +29 -2
- package/src/lib/components/commerce-console-page.js.map +1 -1
- package/src/lib/components/console/commerce-analytics-card.component.js +4 -2
- package/src/lib/components/console/commerce-analytics-card.component.js.map +1 -1
- package/src/lib/components/console/host-orders-card.component.js +5 -1
- package/src/lib/components/console/host-orders-card.component.js.map +1 -1
- package/src/lib/components/console/host-quotes-card.component.d.ts +34 -0
- package/src/lib/components/console/host-quotes-card.component.js +247 -0
- package/src/lib/components/console/host-quotes-card.component.js.map +1 -0
- package/src/lib/components/console/order-webhooks-card.component.js +1 -1
- package/src/lib/components/console/order-webhooks-card.component.js.map +1 -1
- package/src/lib/components/console/pos-ops/pos-check-ins-card.component.js +33 -28
- package/src/lib/components/console/pos-ops/pos-check-ins-card.component.js.map +1 -1
- package/src/lib/components/console/quote-editor-dialog.component.d.ts +45 -0
- package/src/lib/components/console/quote-editor-dialog.component.js +1266 -0
- package/src/lib/components/console/quote-editor-dialog.component.js.map +1 -0
- package/src/lib/components/console/quote-pay-link.component.d.ts +38 -0
- package/src/lib/components/console/quote-pay-link.component.js +213 -0
- package/src/lib/components/console/quote-pay-link.component.js.map +1 -0
- package/src/lib/components/console/quote-settings-card.component.d.ts +29 -0
- package/src/lib/components/console/quote-settings-card.component.js +121 -0
- package/src/lib/components/console/quote-settings-card.component.js.map +1 -0
- package/src/lib/components/console/tax-settings-card.component.js +4 -1
- package/src/lib/components/console/tax-settings-card.component.js.map +1 -1
- package/src/lib/components/quote-page-body.d.ts +33 -0
- package/src/lib/components/quote-page-body.js +696 -0
- package/src/lib/components/quote-page-body.js.map +1 -0
- package/src/lib/components/quote-page.d.ts +29 -0
- package/src/lib/components/quote-page.js +96 -0
- package/src/lib/components/quote-page.js.map +1 -0
- package/src/lib/components/storefront-payment-element.d.ts +7 -1
- package/src/lib/components/storefront-payment-element.js +8 -3
- package/src/lib/components/storefront-payment-element.js.map +1 -1
- package/src/lib/constants/orders-list-query.js +6 -1
- package/src/lib/constants/orders-list-query.js.map +1 -1
- package/src/lib/constants/quote-page.d.ts +30 -0
- package/src/lib/constants/quote-page.js +35 -0
- package/src/lib/constants/quote-page.js.map +1 -0
- package/src/lib/declarations.js +5 -1
- package/src/lib/declarations.js.map +1 -1
- package/src/lib/model/commerce-orders.d.ts +25 -2
- package/src/lib/model/commerce-orders.js +10 -1
- package/src/lib/model/commerce-orders.js.map +1 -1
- package/src/lib/model/commerce-quote-pay.d.ts +229 -0
- package/src/lib/model/commerce-quote-pay.js +393 -0
- package/src/lib/model/commerce-quote-pay.js.map +1 -0
- package/src/lib/model/commerce-quotes.d.ts +279 -0
- package/src/lib/model/commerce-quotes.js +522 -0
- package/src/lib/model/commerce-quotes.js.map +1 -0
- 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/plugin-permissions.d.ts +8 -1
- package/src/lib/model/plugin-permissions.js +21 -1
- package/src/lib/model/plugin-permissions.js.map +1 -1
- package/src/lib/model/workspace-site-permissions.d.ts +26 -0
- package/src/lib/model/workspace-site-permissions.js +81 -0
- package/src/lib/model/workspace-site-permissions.js.map +1 -0
- package/src/lib/server/api-v1/orders-and-products.js +6 -2
- package/src/lib/server/api-v1/orders-and-products.js.map +1 -1
- package/src/lib/server/billing-webhook.js +127 -52
- package/src/lib/server/billing-webhook.js.map +1 -1
- package/src/lib/server/checkout-session-expiry.d.ts +36 -0
- package/src/lib/server/checkout-session-expiry.js +63 -0
- package/src/lib/server/checkout-session-expiry.js.map +1 -0
- package/src/lib/server/commerce-site-keys.d.ts +19 -0
- package/src/lib/server/commerce-site-keys.js +23 -2
- package/src/lib/server/commerce-site-keys.js.map +1 -1
- package/src/lib/server/draft-order.js +16 -8
- package/src/lib/server/draft-order.js.map +1 -1
- package/src/lib/server/order-webhooks.js +8 -8
- package/src/lib/server/order-webhooks.js.map +1 -1
- package/src/lib/server/person-eraser.d.ts +7 -0
- package/src/lib/server/person-eraser.js +24 -2
- package/src/lib/server/person-eraser.js.map +1 -1
- package/src/lib/server/pos-ops-gate.d.ts +13 -5
- package/src/lib/server/pos-ops-gate.js +12 -14
- package/src/lib/server/pos-ops-gate.js.map +1 -1
- package/src/lib/server/pos-refund-authority.d.ts +3 -1
- package/src/lib/server/pos-refund-authority.js +3 -2
- package/src/lib/server/pos-refund-authority.js.map +1 -1
- package/src/lib/server/pos-return.js +6 -7
- package/src/lib/server/pos-return.js.map +1 -1
- package/src/lib/server/pos-staff-pin.js +7 -7
- package/src/lib/server/pos-staff-pin.js.map +1 -1
- package/src/lib/server/quote-link-token.d.ts +39 -0
- package/src/lib/server/quote-link-token.js +97 -0
- package/src/lib/server/quote-link-token.js.map +1 -0
- package/src/lib/server/quote-pay.d.ts +83 -0
- package/src/lib/server/quote-pay.js +606 -0
- package/src/lib/server/quote-pay.js.map +1 -0
- package/src/lib/server/quote.d.ts +49 -0
- package/src/lib/server/quote.js +513 -0
- package/src/lib/server/quote.js.map +1 -0
- package/src/lib/server/refund.js +26 -36
- package/src/lib/server/refund.js.map +1 -1
- package/src/lib/server/related.js +2 -0
- package/src/lib/server/related.js.map +1 -1
- package/src/lib/server/site-page-resolver.d.ts +2 -0
- package/src/lib/server/site-page-resolver.js +75 -0
- package/src/lib/server/site-page-resolver.js.map +1 -1
- package/src/lib/server.js +14 -0
- package/src/lib/server.js.map +1 -1
- package/src/lib/site.js +6 -0
- package/src/lib/site.js.map +1 -1
- package/src/lib/transfer/tracking.server.js +6 -0
- package/src/lib/transfer/tracking.server.js.map +1 -1
|
@@ -3553,7 +3553,10 @@ async function findOrderForDispute(paymentIntentId) {
|
|
|
3553
3553
|
}
|
|
3554
3554
|
}
|
|
3555
3555
|
// Draft orders (AGL-287): the console pre-created the doc; completion
|
|
3556
|
-
// flips it to paid, stamps the intent, and decrements stock.
|
|
3556
|
+
// flips it to paid, stamps the intent, and decrements stock. A quote paid
|
|
3557
|
+
// through its pay link (AGL-4094) completes here too: its session carries
|
|
3558
|
+
// this type and the quote's own id as `orderId`, and the quote document is
|
|
3559
|
+
// what becomes the order.
|
|
3557
3560
|
if (type === 'checkout.session.completed' && (object == null ? void 0 : (_object_metadata3 = object.metadata) == null ? void 0 : _object_metadata3.type) === 'commerce-draft' && (object == null ? void 0 : object.payment_status) === 'paid') {
|
|
3558
3561
|
var _object_metadata27;
|
|
3559
3562
|
const { hostId, orderId, productId } = (_object_metadata27 = object.metadata) != null ? _object_metadata27 : {};
|
|
@@ -3625,12 +3628,74 @@ async function findOrderForDispute(paymentIntentId) {
|
|
|
3625
3628
|
let paidAfterCancel = false;
|
|
3626
3629
|
// The canceled order's number, for the notice below (AGL-3432).
|
|
3627
3630
|
let canceledOrderLabel = '';
|
|
3631
|
+
// A payment a quote could not take (AGL-4094), reported below.
|
|
3632
|
+
let quoteUnmatched = null;
|
|
3633
|
+
let quoteLabel = '';
|
|
3628
3634
|
const flipped = await firestore.runTransaction(async (transaction)=>{
|
|
3629
|
-
var _snapshot_data, _snapshot_data1, _ref, _ref1, _ref2, _ref3, _ref4, _ref5, _lifted_totals, _ref6, _shipTo_name, _shipTo_address_line1, _shipTo_address_line2, _shipTo_address_city, _shipTo_address_state, _shipTo_address_postal_code, _shipTo_address_country;
|
|
3635
|
+
var _snapshot_data, _snapshot_data1, _snapshot_data2, _ref, _ref1, _ref2, _ref3, _ref4, _ref5, _lifted_totals, _ref6, _shipTo_name, _shipTo_address_line1, _shipTo_address_line2, _shipTo_address_city, _shipTo_address_state, _shipTo_address_postal_code, _shipTo_address_country;
|
|
3630
3636
|
var _object_customer_details, _object_metadata, _object_customer_details1, _lifted_totals1;
|
|
3631
3637
|
const snapshot = await transaction.get(orderRef);
|
|
3632
3638
|
if (!snapshot.exists) return false;
|
|
3633
|
-
const
|
|
3639
|
+
const raw = (_snapshot_data = snapshot.data()) != null ? _snapshot_data : null;
|
|
3640
|
+
// A QUOTE (AGL-4094). Paid as it stands, the same document becomes
|
|
3641
|
+
// the order with every field order readers ask (`paidQuoteOrder`).
|
|
3642
|
+
// A payment through a replaced link, for an earlier edit, or after
|
|
3643
|
+
// the quote was paid is not fulfilled: it is recorded on the quote
|
|
3644
|
+
// and the business is told, as a paid-after-cancel payment is.
|
|
3645
|
+
if (raw && CommerceModel.isQuote(raw) && raw.quote) {
|
|
3646
|
+
var _ref7, _ref8, _ref9, _ref10, _ref11, _ref12, _ref13, _ref14;
|
|
3647
|
+
var _object_metadata1, _object_metadata2, _object_customer_details2, _object_customer_details3, _object_metadata3, _object_metadata4;
|
|
3648
|
+
const facts = {
|
|
3649
|
+
sessionId: String((_ref7 = object == null ? void 0 : object.id) != null ? _ref7 : ''),
|
|
3650
|
+
paymentIntentId: String((_ref8 = object == null ? void 0 : object.payment_intent) != null ? _ref8 : '') || null,
|
|
3651
|
+
linkVersion: (_ref9 = object == null ? void 0 : (_object_metadata1 = object.metadata) == null ? void 0 : _object_metadata1.quoteLinkVersion) != null ? _ref9 : null,
|
|
3652
|
+
quoteUpdatedAtMs: (_ref10 = object == null ? void 0 : (_object_metadata2 = object.metadata) == null ? void 0 : _object_metadata2.quoteUpdatedAtMs) != null ? _ref10 : null,
|
|
3653
|
+
paidAtMs: Date.now(),
|
|
3654
|
+
email: (_ref11 = object == null ? void 0 : (_object_customer_details2 = object.customer_details) == null ? void 0 : _object_customer_details2.email) != null ? _ref11 : null,
|
|
3655
|
+
name: (_ref12 = object == null ? void 0 : (_object_customer_details3 = object.customer_details) == null ? void 0 : _object_customer_details3.name) != null ? _ref12 : null,
|
|
3656
|
+
amountTotalCents: Number.isFinite(chargedTotalCents) ? chargedTotalCents : null,
|
|
3657
|
+
shippingCents,
|
|
3658
|
+
taxCents: stripeTaxCents,
|
|
3659
|
+
feeCents: Number((_ref13 = object == null ? void 0 : (_object_metadata3 = object.metadata) == null ? void 0 : _object_metadata3.feeCents) != null ? _ref13 : 0) || 0,
|
|
3660
|
+
taxMode: storefrontTaxModeOf(object, Number((_ref14 = object == null ? void 0 : (_object_metadata4 = object.metadata) == null ? void 0 : _object_metadata4.taxCents) != null ? _ref14 : 0)),
|
|
3661
|
+
shippingAddress: (shipTo == null ? void 0 : shipTo.address) ? Object.fromEntries(Object.entries({
|
|
3662
|
+
name: shipTo.name,
|
|
3663
|
+
line1: shipTo.address.line1,
|
|
3664
|
+
line2: shipTo.address.line2,
|
|
3665
|
+
city: shipTo.address.city,
|
|
3666
|
+
state: shipTo.address.state,
|
|
3667
|
+
postalCode: shipTo.address.postal_code,
|
|
3668
|
+
country: shipTo.address.country
|
|
3669
|
+
}).filter(([, value])=>typeof value === 'string' && value !== '')) : null
|
|
3670
|
+
};
|
|
3671
|
+
const disposition = CommerceModel.quotePaymentDisposition(raw, facts);
|
|
3672
|
+
if (disposition === 'redelivery') return false;
|
|
3673
|
+
if (disposition !== 'pay') {
|
|
3674
|
+
var _raw_quote_unmatchedPayments;
|
|
3675
|
+
const entry = CommerceModel.quoteUnmatchedPayment(facts, disposition);
|
|
3676
|
+
quoteUnmatched = entry;
|
|
3677
|
+
quoteLabel = CommerceModel.formatQuoteNumber(raw, String(orderId));
|
|
3678
|
+
transaction.set(orderRef, {
|
|
3679
|
+
quote: _extends({}, raw.quote, {
|
|
3680
|
+
unmatchedPayments: [
|
|
3681
|
+
...(_raw_quote_unmatchedPayments = raw.quote.unmatchedPayments) != null ? _raw_quote_unmatchedPayments : [],
|
|
3682
|
+
entry
|
|
3683
|
+
]
|
|
3684
|
+
}),
|
|
3685
|
+
timeline: CommerceModel.appendOrderEvent(raw, 'quote-payment-unmatched', CommerceModel.quoteUnmatchedPaymentDetail(entry), facts.paidAtMs)
|
|
3686
|
+
}, {
|
|
3687
|
+
merge: true
|
|
3688
|
+
});
|
|
3689
|
+
return false;
|
|
3690
|
+
}
|
|
3691
|
+
const paidQuote = CommerceModel.paidQuoteOrder(raw, String(orderId), facts);
|
|
3692
|
+
paidOrder = paidQuote;
|
|
3693
|
+
transaction.set(orderRef, _extends({}, paidQuote, {
|
|
3694
|
+
createdAt: firebaseAdmin.firestore.FieldValue.serverTimestamp()
|
|
3695
|
+
}));
|
|
3696
|
+
return true;
|
|
3697
|
+
}
|
|
3698
|
+
const lifted = CommerceModel.liftLegacyOrder((_snapshot_data1 = snapshot.data()) != null ? _snapshot_data1 : {});
|
|
3634
3699
|
if (lifted.status !== 'pending') {
|
|
3635
3700
|
var _lifted_timeline;
|
|
3636
3701
|
// NOT ALL NON-`pending` ORDERS ARE REDELIVERIES (AGL-2244), and
|
|
@@ -3665,7 +3730,7 @@ async function findOrderForDispute(paymentIntentId) {
|
|
|
3665
3730
|
return false;
|
|
3666
3731
|
}
|
|
3667
3732
|
paidOrder = lifted;
|
|
3668
|
-
transaction.set(orderRef, _extends({}, CommerceModel.orderListFields(_extends({}, (
|
|
3733
|
+
transaction.set(orderRef, _extends({}, CommerceModel.orderListFields(_extends({}, (_snapshot_data2 = snapshot.data()) != null ? _snapshot_data2 : {}, {
|
|
3669
3734
|
status: 'paid',
|
|
3670
3735
|
customerEmail: (_ref = (_ref1 = object == null ? void 0 : (_object_customer_details = object.customer_details) == null ? void 0 : _object_customer_details.email) != null ? _ref1 : lifted.customerEmail) != null ? _ref : null
|
|
3671
3736
|
}), orderRef.id), {
|
|
@@ -3721,6 +3786,15 @@ async function findOrderForDispute(paymentIntentId) {
|
|
|
3721
3786
|
// timeline line above is only findable by someone already looking at
|
|
3722
3787
|
// the order they have no reason to open; this is money sitting in
|
|
3723
3788
|
// Stripe against a sale the product does not have.
|
|
3789
|
+
if (quoteUnmatched && hostId) {
|
|
3790
|
+
const unmatched = quoteUnmatched;
|
|
3791
|
+
await notifyHostManagers(String(hostId), {
|
|
3792
|
+
type: 'content.order',
|
|
3793
|
+
title: unmatched.reason === 'already-paid' ? `${quoteLabel} was paid twice` : `A replaced link for ${quoteLabel} was paid`,
|
|
3794
|
+
body: `${quoteLabel} on {site}: ${CommerceModel.quoteUnmatchedPaymentDetail(unmatched)}`,
|
|
3795
|
+
link: `/${hostId}/products/orders`
|
|
3796
|
+
});
|
|
3797
|
+
}
|
|
3724
3798
|
if (paidAfterCancel && hostId) {
|
|
3725
3799
|
await notifyHostManagers(String(hostId), {
|
|
3726
3800
|
type: 'content.order',
|
|
@@ -3770,11 +3844,12 @@ async function findOrderForDispute(paymentIntentId) {
|
|
|
3770
3844
|
const draftLabel = CommerceModel.formatOrderNumber(order, String(orderId));
|
|
3771
3845
|
const draftPayer = (_ref62 = (_ref63 = object == null ? void 0 : (_object_customer_details15 = object.customer_details) == null ? void 0 : _object_customer_details15.email) != null ? _ref63 : order.customerEmail) != null ? _ref62 : null;
|
|
3772
3846
|
const draftPaidCents = Number((_ref64 = object == null ? void 0 : object.amount_total) != null ? _ref64 : 0) || Number((_ref65 = (_order_totals = order.totals) == null ? void 0 : _order_totals.totalCents) != null ? _ref65 : 0);
|
|
3847
|
+
const isQuotePayment = CommerceModel.isQuote(order);
|
|
3773
3848
|
void notifyHostManagers(String(hostId), {
|
|
3774
3849
|
type: 'content.order',
|
|
3775
|
-
title: `Draft order paid — ${draftLabel}`,
|
|
3850
|
+
title: isQuotePayment ? `Quote paid — ${CommerceModel.formatQuoteNumber(order, String(orderId))}` : `Draft order paid — ${draftLabel}`,
|
|
3776
3851
|
// Who paid what, and where (AGL-3432).
|
|
3777
|
-
body: `${draftPayer != null ? draftPayer : 'The buyer'} paid draft order ${draftLabel} ` + `on {site}: $${(draftPaidCents / 100).toFixed(2)}.`,
|
|
3852
|
+
body: isQuotePayment ? `${draftPayer != null ? draftPayer : 'The customer'} paid ${CommerceModel.formatQuoteNumber(order, String(orderId))} ` + `on {site}: $${(draftPaidCents / 100).toFixed(2)}. It is order ${draftLabel} now.` : `${draftPayer != null ? draftPayer : 'The buyer'} paid draft order ${draftLabel} ` + `on {site}: $${(draftPaidCents / 100).toFixed(2)}.`,
|
|
3778
3853
|
link: `/${hostId}/products`
|
|
3779
3854
|
});
|
|
3780
3855
|
// Contacts ingestion (AGL-1748): this branch flipped the order,
|
|
@@ -3791,7 +3866,7 @@ async function findOrderForDispute(paymentIntentId) {
|
|
|
3791
3866
|
// the fallback for a session shape that reports no total.
|
|
3792
3867
|
const draftEmail = (_ref66 = (_ref67 = object == null ? void 0 : (_object_customer_details16 = object.customer_details) == null ? void 0 : _object_customer_details16.email) != null ? _ref67 : order.customerEmail) != null ? _ref66 : null;
|
|
3793
3868
|
if (draftEmail) {
|
|
3794
|
-
var _ref69, _ref70, _ref71;
|
|
3869
|
+
var _ref69, _ref70, _ref71, _ref72;
|
|
3795
3870
|
var _order_totals1, _object_customer_details17;
|
|
3796
3871
|
const chargedCents = Number((_ref69 = object == null ? void 0 : object.amount_total) != null ? _ref69 : 0) || Number((_ref70 = (_order_totals1 = order.totals) == null ? void 0 : _order_totals1.totalCents) != null ? _ref70 : 0);
|
|
3797
3872
|
await recordCapturedContact(_extends({
|
|
@@ -3799,7 +3874,7 @@ async function findOrderForDispute(paymentIntentId) {
|
|
|
3799
3874
|
hostId: String(hostId),
|
|
3800
3875
|
identity: {
|
|
3801
3876
|
email: draftEmail,
|
|
3802
|
-
name: (_ref71 = object == null ? void 0 : (_object_customer_details17 = object.customer_details) == null ? void 0 : _object_customer_details17.name) != null ? _ref71 : null
|
|
3877
|
+
name: (_ref71 = (_ref72 = object == null ? void 0 : (_object_customer_details17 = object.customer_details) == null ? void 0 : _object_customer_details17.name) != null ? _ref72 : order.customerName) != null ? _ref71 : null
|
|
3803
3878
|
},
|
|
3804
3879
|
surface: 'relationship',
|
|
3805
3880
|
lifecycleFloor: 'customer'
|
|
@@ -3826,15 +3901,15 @@ async function findOrderForDispute(paymentIntentId) {
|
|
|
3826
3901
|
key: 'paid'
|
|
3827
3902
|
});
|
|
3828
3903
|
if (productId) {
|
|
3829
|
-
var _productSnapshot_data,
|
|
3904
|
+
var _productSnapshot_data, _ref73, _ref74;
|
|
3830
3905
|
var _object_metadata30, _lifted_variants_, _order_lineItems_, _order_lineItems;
|
|
3831
3906
|
const productRef = hostRef.collection('products').doc(String(productId));
|
|
3832
3907
|
const productSnapshot = await productRef.get();
|
|
3833
3908
|
const lifted = CommerceModel.liftLegacyProduct((_productSnapshot_data = productSnapshot.data()) != null ? _productSnapshot_data : {
|
|
3834
3909
|
name: 'Product'
|
|
3835
3910
|
});
|
|
3836
|
-
const soldVariantId = String((
|
|
3837
|
-
const quantity = (
|
|
3911
|
+
const soldVariantId = String((_ref73 = (_object_metadata30 = object.metadata) == null ? void 0 : _object_metadata30.variantId) != null ? _ref73 : '') || ((_lifted_variants_ = lifted.variants[0]) == null ? void 0 : _lifted_variants_.id);
|
|
3912
|
+
const quantity = (_ref74 = (_order_lineItems = order.lineItems) == null ? void 0 : (_order_lineItems_ = _order_lineItems[0]) == null ? void 0 : _order_lineItems_.quantity) != null ? _ref74 : 1;
|
|
3838
3913
|
if (soldVariantId) {
|
|
3839
3914
|
// Atomic since AGL-2320.
|
|
3840
3915
|
const moved = await decrementVariantStock({
|
|
@@ -3886,10 +3961,10 @@ async function findOrderForDispute(paymentIntentId) {
|
|
|
3886
3961
|
// would decrement it twice.
|
|
3887
3962
|
const paidProducts = new Map();
|
|
3888
3963
|
for (const line of (_order_lineItems1 = order.lineItems) != null ? _order_lineItems1 : []){
|
|
3889
|
-
var
|
|
3964
|
+
var _ref75, _ref76, _line_variantId1;
|
|
3890
3965
|
var _lineProduct_variants_;
|
|
3891
|
-
const lineProductId = String((
|
|
3892
|
-
const soldQty = Math.round(Number((
|
|
3966
|
+
const lineProductId = String((_ref75 = line == null ? void 0 : line.productId) != null ? _ref75 : '');
|
|
3967
|
+
const soldQty = Math.round(Number((_ref76 = line == null ? void 0 : line.quantity) != null ? _ref76 : 0));
|
|
3893
3968
|
if (!lineProductId || !(soldQty > 0)) continue;
|
|
3894
3969
|
// Firestore reserves `__…__` ids and `.doc()` throws
|
|
3895
3970
|
// synchronously on one; a corrupt line must not fail the
|
|
@@ -3952,7 +4027,7 @@ async function findOrderForDispute(paymentIntentId) {
|
|
|
3952
4027
|
var _object_metadata31;
|
|
3953
4028
|
const { hostId, productId, feeCents, couponCode } = (_object_metadata31 = object.metadata) != null ? _object_metadata31 : {};
|
|
3954
4029
|
if (hostId && productId) {
|
|
3955
|
-
var
|
|
4030
|
+
var _ref77, _productForSnapshot_get2, _productForSnapshot_data1, _ref78, _ref79, _object_shipping_details_address_postal_code1, _object_shipping_details_address_country1, _ref80, _ref81, _ref82, _ref83, _ref84;
|
|
3956
4031
|
var _object_metadata32, _buyNowLineItems_, _object_shipping_details1, _object_customer_details18, _object_customer_details19, _object_customer_details20, _object_metadata33;
|
|
3957
4032
|
const firestore = firebaseAdmin.app().firestore();
|
|
3958
4033
|
const hostRef = firestore.collection('hosts').doc(String(hostId));
|
|
@@ -3963,7 +4038,7 @@ async function findOrderForDispute(paymentIntentId) {
|
|
|
3963
4038
|
// is bounded to Stripe's at-least-once edge).
|
|
3964
4039
|
const orderRef = hostRef.collection('orders').doc(String(object.id));
|
|
3965
4040
|
const counterRef = hostRef.collection('counters').doc('orders');
|
|
3966
|
-
const amountCents = Number((
|
|
4041
|
+
const amountCents = Number((_ref77 = object == null ? void 0 : object.amount_total) != null ? _ref77 : 0);
|
|
3967
4042
|
const productForSnapshot = await hostRef.collection('products').doc(String(productId)).get();
|
|
3968
4043
|
const snapshotName = String((_productForSnapshot_get2 = productForSnapshot.get('name')) != null ? _productForSnapshot_get2 : 'Product');
|
|
3969
4044
|
// AGL-1711: the line item and totals used to be fabricated from
|
|
@@ -3976,7 +4051,7 @@ async function findOrderForDispute(paymentIntentId) {
|
|
|
3976
4051
|
name: snapshotName
|
|
3977
4052
|
});
|
|
3978
4053
|
const soldVariant = ((_object_metadata32 = object.metadata) == null ? void 0 : _object_metadata32.variantId) ? liftedForSnapshot.variants.find((item)=>item.id === String(object.metadata.variantId)) : liftedForSnapshot.variants[0];
|
|
3979
|
-
const variantOptions = Object.values((
|
|
4054
|
+
const variantOptions = Object.values((_ref78 = soldVariant == null ? void 0 : soldVariant.options) != null ? _ref78 : {});
|
|
3980
4055
|
const { lineItems: buyNowLineItems, totals: buyNowTotals } = CommerceModel.computeBuyNowOrder(object, _extends({
|
|
3981
4056
|
name: snapshotName
|
|
3982
4057
|
}, variantOptions.length ? {
|
|
@@ -3988,7 +4063,7 @@ async function findOrderForDispute(paymentIntentId) {
|
|
|
3988
4063
|
} : {}, liftedForSnapshot.supplierId ? {
|
|
3989
4064
|
supplierId: liftedForSnapshot.supplierId
|
|
3990
4065
|
} : {}));
|
|
3991
|
-
const soldQuantity = (
|
|
4066
|
+
const soldQuantity = (_ref79 = (_buyNowLineItems_ = buyNowLineItems[0]) == null ? void 0 : _buyNowLineItems_.quantity) != null ? _ref79 : 1;
|
|
3992
4067
|
// The number the merchant knows this order by, for the notices below
|
|
3993
4068
|
// (AGL-3432).
|
|
3994
4069
|
let buyNowOrderNumber;
|
|
@@ -4089,7 +4164,7 @@ async function findOrderForDispute(paymentIntentId) {
|
|
|
4089
4164
|
// In-app order notification (wave v6): host managers see sales
|
|
4090
4165
|
// in the bell, not just the owner's email: what came in, from whom
|
|
4091
4166
|
// and where (AGL-3432).
|
|
4092
|
-
const buyNowTotal = `$${(Number((
|
|
4167
|
+
const buyNowTotal = `$${(Number((_ref80 = object == null ? void 0 : object.amount_total) != null ? _ref80 : 0) / 100).toFixed(2)}`;
|
|
4093
4168
|
void notifyHostManagers(String(hostId), {
|
|
4094
4169
|
type: 'content.order',
|
|
4095
4170
|
title: `New order on {site} — ${buyNowTotal}`,
|
|
@@ -4238,15 +4313,15 @@ async function findOrderForDispute(paymentIntentId) {
|
|
|
4238
4313
|
hostId: String(hostId),
|
|
4239
4314
|
identity: {
|
|
4240
4315
|
email: object == null ? void 0 : (_object_customer_details19 = object.customer_details) == null ? void 0 : _object_customer_details19.email,
|
|
4241
|
-
name: (
|
|
4316
|
+
name: (_ref81 = object == null ? void 0 : (_object_customer_details20 = object.customer_details) == null ? void 0 : _object_customer_details20.name) != null ? _ref81 : null
|
|
4242
4317
|
},
|
|
4243
4318
|
surface: 'relationship',
|
|
4244
4319
|
lifecycleFloor: 'customer',
|
|
4245
|
-
purchaseCents: Number((
|
|
4320
|
+
purchaseCents: Number((_ref82 = object == null ? void 0 : object.amount_total) != null ? _ref82 : 0),
|
|
4246
4321
|
interaction: {
|
|
4247
4322
|
source: 'order',
|
|
4248
4323
|
refId: String(object.id),
|
|
4249
|
-
summary: `Placed an order ($${(Number((
|
|
4324
|
+
summary: `Placed an order ($${(Number((_ref83 = object == null ? void 0 : object.amount_total) != null ? _ref83 : 0) / 100).toFixed(2)})`
|
|
4250
4325
|
}
|
|
4251
4326
|
});
|
|
4252
4327
|
const productRef = hostRef.collection('products').doc(String(productId));
|
|
@@ -4264,12 +4339,12 @@ async function findOrderForDispute(paymentIntentId) {
|
|
|
4264
4339
|
// serialize; the snapshot above is still read, for the product NAME on
|
|
4265
4340
|
// the receipt below, and no longer decides any count.
|
|
4266
4341
|
{
|
|
4267
|
-
var _productSnapshot_data2,
|
|
4342
|
+
var _productSnapshot_data2, _ref85;
|
|
4268
4343
|
var _object_metadata34, _lifted_variants_1;
|
|
4269
4344
|
const lifted = CommerceModel.liftLegacyProduct((_productSnapshot_data2 = productSnapshot.data()) != null ? _productSnapshot_data2 : {
|
|
4270
4345
|
name: 'Product'
|
|
4271
4346
|
});
|
|
4272
|
-
const soldVariantId = String((
|
|
4347
|
+
const soldVariantId = String((_ref85 = (_object_metadata34 = object.metadata) == null ? void 0 : _object_metadata34.variantId) != null ? _ref85 : '') || ((_lifted_variants_1 = lifted.variants[0]) == null ? void 0 : _lifted_variants_1.id);
|
|
4273
4348
|
if (soldVariantId) {
|
|
4274
4349
|
// AGL-1711: `-1` regardless of how many units were bought, so a
|
|
4275
4350
|
// 3-unit buy-now sale decremented stock by one and the difference
|
|
@@ -4302,14 +4377,14 @@ async function findOrderForDispute(paymentIntentId) {
|
|
|
4302
4377
|
// Settlement, the same way round and for the same reason as the cart
|
|
4303
4378
|
// branch above (AGL-2356): the decrement lands first, then the
|
|
4304
4379
|
// reservation is dropped.
|
|
4305
|
-
await releaseStockHold(hostRef, String((
|
|
4380
|
+
await releaseStockHold(hostRef, String((_ref84 = (_object_metadata33 = object.metadata) == null ? void 0 : _object_metadata33.stockHoldKey) != null ? _ref84 : ''));
|
|
4306
4381
|
if (couponCode) {
|
|
4307
|
-
var
|
|
4382
|
+
var _ref86;
|
|
4308
4383
|
var _object_metadata35;
|
|
4309
4384
|
await settleRedemption({
|
|
4310
4385
|
firestore,
|
|
4311
4386
|
ref: hostRef.collection('coupons').doc(String(couponCode)),
|
|
4312
|
-
holdKey: String((
|
|
4387
|
+
holdKey: String((_ref86 = (_object_metadata35 = object.metadata) == null ? void 0 : _object_metadata35.couponHoldKey) != null ? _ref86 : ''),
|
|
4313
4388
|
orderRef,
|
|
4314
4389
|
label: `coupon ${couponCode}`,
|
|
4315
4390
|
detail: `Coupon ${couponCode} was applied to this order but no longer ` + 'exists, so the redemption is uncounted against its limit.'
|
|
@@ -4324,19 +4399,19 @@ async function findOrderForDispute(paymentIntentId) {
|
|
|
4324
4399
|
// Receipt + seller notification (AGL-96): env-gated like every
|
|
4325
4400
|
// other outbound email; failures never fail the webhook.
|
|
4326
4401
|
if (isEmailConfigured()) {
|
|
4327
|
-
var _productSnapshot_get,
|
|
4402
|
+
var _productSnapshot_get, _ref87;
|
|
4328
4403
|
var _object_customer_details21, _org, _this3;
|
|
4329
4404
|
const productName = String((_productSnapshot_get = productSnapshot.get('name')) != null ? _productSnapshot_get : 'your purchase');
|
|
4330
|
-
const amount = (Number((
|
|
4405
|
+
const amount = (Number((_ref87 = object == null ? void 0 : object.amount_total) != null ? _ref87 : 0) / 100).toFixed(2);
|
|
4331
4406
|
const buyerEmail = object == null ? void 0 : (_object_customer_details21 = object.customer_details) == null ? void 0 : _object_customer_details21.email;
|
|
4332
4407
|
const orderTotal = `$${amount}`;
|
|
4333
4408
|
// The store's receipt switch and the status link (AGL-3610).
|
|
4334
4409
|
const receiptExtras = await onlineReceiptExtras(String(hostId), String(object.id));
|
|
4335
4410
|
if (buyerEmail && receiptExtras.enabled) {
|
|
4336
|
-
var
|
|
4411
|
+
var _ref88, _ref89;
|
|
4337
4412
|
// The store's own Receipt footer, as the cart receipt carries it
|
|
4338
4413
|
// (AGL-3432).
|
|
4339
|
-
const receiptFooter = String((
|
|
4414
|
+
const receiptFooter = String((_ref88 = await hostRef.collection('settings').doc('store').get().then((snapshot)=>snapshot.get('receiptFooter')).catch(()=>'')) != null ? _ref88 : '');
|
|
4340
4415
|
// The quantity with the name (AGL-3432), so a three-unit sale
|
|
4341
4416
|
// does not read as one item at the whole total.
|
|
4342
4417
|
const receiptLine = `${soldQuantity}× ${productName}` + // Where to collect it, or when it is coming (AGL-3624).
|
|
@@ -4351,7 +4426,7 @@ async function findOrderForDispute(paymentIntentId) {
|
|
|
4351
4426
|
}, receiptExtras.tokens));
|
|
4352
4427
|
await sendEmail(_extends({
|
|
4353
4428
|
to: String(buyerEmail),
|
|
4354
|
-
subject: (
|
|
4429
|
+
subject: (_ref89 = designed == null ? void 0 : designed.subject) != null ? _ref89 : `Receipt: ${productName}`,
|
|
4355
4430
|
text: (designed == null ? void 0 : designed.text) || fallbackText
|
|
4356
4431
|
}, (designed == null ? void 0 : designed.html) ? {
|
|
4357
4432
|
html: designed.html
|
|
@@ -4385,7 +4460,7 @@ async function findOrderForDispute(paymentIntentId) {
|
|
|
4385
4460
|
// SSO.
|
|
4386
4461
|
const seller = (_this4 = await findUserByUidAcrossPools(sellerUid).catch(()=>null)) == null ? void 0 : _this4.record;
|
|
4387
4462
|
if (seller == null ? void 0 : seller.email) {
|
|
4388
|
-
var _hostSnapshot_get,
|
|
4463
|
+
var _hostSnapshot_get, _ref90;
|
|
4389
4464
|
const siteName = String((_hostSnapshot_get = hostSnapshot.get('displayName')) != null ? _hostSnapshot_get : hostId);
|
|
4390
4465
|
const fallbackText = `You made a sale on ${siteName}!\n\n${productName} — $${amount}` + (buyerEmail ? `\nBuyer: ${buyerEmail}` : '') + `\nOrder reference: ${object.id}`;
|
|
4391
4466
|
// Site-owner-designed template when published (AGL-771).
|
|
@@ -4399,7 +4474,7 @@ async function findOrderForDispute(paymentIntentId) {
|
|
|
4399
4474
|
});
|
|
4400
4475
|
await sendEmail(_extends({
|
|
4401
4476
|
to: seller.email,
|
|
4402
|
-
subject: (
|
|
4477
|
+
subject: (_ref90 = designed == null ? void 0 : designed.subject) != null ? _ref90 : `New order: ${productName}`,
|
|
4403
4478
|
text: (designed == null ? void 0 : designed.text) || fallbackText
|
|
4404
4479
|
}, (designed == null ? void 0 : designed.html) ? {
|
|
4405
4480
|
html: designed.html
|
|
@@ -4429,28 +4504,28 @@ async function findOrderForDispute(paymentIntentId) {
|
|
|
4429
4504
|
// the refund is written on the order's timeline. Nothing else is moved: a
|
|
4430
4505
|
// Dashboard refund is staff's act, and they chose its transfer reversal.
|
|
4431
4506
|
if (type === 'charge.refunded') {
|
|
4432
|
-
var
|
|
4507
|
+
var _ref91, _ref92;
|
|
4433
4508
|
var _object_payment_intent, _snapshot_ref_parent_parent;
|
|
4434
|
-
const paymentIntentId = typeof (object == null ? void 0 : object.payment_intent) === 'string' ? object.payment_intent : String((
|
|
4509
|
+
const paymentIntentId = typeof (object == null ? void 0 : object.payment_intent) === 'string' ? object.payment_intent : String((_ref91 = object == null ? void 0 : (_object_payment_intent = object.payment_intent) == null ? void 0 : _object_payment_intent.id) != null ? _ref91 : '');
|
|
4435
4510
|
const lookup = paymentIntentId ? await findOrderForDispute(paymentIntentId) : {
|
|
4436
4511
|
kind: 'not-ours'
|
|
4437
4512
|
};
|
|
4438
4513
|
if (lookup.kind !== 'order') return;
|
|
4439
4514
|
const snapshot = lookup.snapshot;
|
|
4440
|
-
const hostId = String((
|
|
4515
|
+
const hostId = String((_ref92 = (_snapshot_ref_parent_parent = snapshot.ref.parent.parent) == null ? void 0 : _snapshot_ref_parent_parent.id) != null ? _ref92 : '');
|
|
4441
4516
|
const external = await recordExternalRefund(snapshot.ref, object);
|
|
4442
4517
|
if (external && hostId) {
|
|
4443
|
-
var
|
|
4518
|
+
var _ref93, _ref94, _ref95;
|
|
4444
4519
|
var _object_refunds;
|
|
4445
4520
|
// A Stripe Dashboard refund is a refund to every subscriber too
|
|
4446
4521
|
// (AGL-3645): accounting books it and the merchant's webhooks hear it,
|
|
4447
4522
|
// as they do a console refund. Keyed by the charge's refunded total,
|
|
4448
4523
|
// which the record above only ever advances once per amount.
|
|
4449
|
-
const latestRefund = ((
|
|
4524
|
+
const latestRefund = ((_ref93 = object == null ? void 0 : (_object_refunds = object.refunds) == null ? void 0 : _object_refunds.data) != null ? _ref93 : [])[0];
|
|
4450
4525
|
await raiseOrderEvent(ORDER_REFUNDED_EVENT, {
|
|
4451
4526
|
hostId,
|
|
4452
4527
|
orderId: snapshot.id,
|
|
4453
|
-
key: `external-refund:${String((
|
|
4528
|
+
key: `external-refund:${String((_ref94 = object == null ? void 0 : object.id) != null ? _ref94 : paymentIntentId)}:${Number((_ref95 = object == null ? void 0 : object.amount_refunded) != null ? _ref95 : 0)}`,
|
|
4454
4529
|
extra: {
|
|
4455
4530
|
refund: {
|
|
4456
4531
|
id: (latestRefund == null ? void 0 : latestRefund.id) ? String(latestRefund.id) : null,
|
|
@@ -4500,16 +4575,16 @@ async function findOrderForDispute(paymentIntentId) {
|
|
|
4500
4575
|
// merchant; both report the site so the seller's fraud ledger can name it.
|
|
4501
4576
|
const risk = paymentRiskEventFrom(type, object);
|
|
4502
4577
|
if (risk && risk.signal.kind !== 'dispute') {
|
|
4503
|
-
var
|
|
4578
|
+
var _ref96, _snapshot_data1, _ref97, _ref98;
|
|
4504
4579
|
var _snapshot_ref_parent_parent1, _order_totals2;
|
|
4505
4580
|
const lookup = risk.paymentIntentId ? await findOrderForDispute(risk.paymentIntentId) : {
|
|
4506
4581
|
kind: 'not-ours'
|
|
4507
4582
|
};
|
|
4508
4583
|
if (lookup.kind !== 'order') return;
|
|
4509
4584
|
const snapshot = lookup.snapshot;
|
|
4510
|
-
const hostId = String((
|
|
4585
|
+
const hostId = String((_ref96 = (_snapshot_ref_parent_parent1 = snapshot.ref.parent.parent) == null ? void 0 : _snapshot_ref_parent_parent1.id) != null ? _ref96 : '');
|
|
4511
4586
|
const order = CommerceModel.liftLegacyOrder((_snapshot_data1 = snapshot.data()) != null ? _snapshot_data1 : {});
|
|
4512
|
-
const orderCents = Number((
|
|
4587
|
+
const orderCents = Number((_ref97 = (_ref98 = (_order_totals2 = order.totals) == null ? void 0 : _order_totals2.totalCents) != null ? _ref98 : order.amountCents) != null ? _ref97 : 0);
|
|
4513
4588
|
await recordPaymentRiskOnRecord({
|
|
4514
4589
|
ref: snapshot.ref,
|
|
4515
4590
|
signal: risk.signal,
|
|
@@ -4572,7 +4647,7 @@ async function findOrderForDispute(paymentIntentId) {
|
|
|
4572
4647
|
// finds). AGL-1554 will add its own `closed` branch for the marketplace
|
|
4573
4648
|
// side; the two coexist because each self-selects by finding its own record.
|
|
4574
4649
|
if (type === 'charge.dispute.created' || type === 'charge.dispute.closed') {
|
|
4575
|
-
var _dispute_payment_intent,
|
|
4650
|
+
var _dispute_payment_intent, _ref99;
|
|
4576
4651
|
var _snapshot_ref_parent_parent2;
|
|
4577
4652
|
const dispute = object != null ? object : {};
|
|
4578
4653
|
const paymentIntentId = String((_dispute_payment_intent = dispute.payment_intent) != null ? _dispute_payment_intent : '');
|
|
@@ -4598,9 +4673,9 @@ async function findOrderForDispute(paymentIntentId) {
|
|
|
4598
4673
|
const claimed = lookup.kind === 'order' || lookup.kind === 'unresolved';
|
|
4599
4674
|
const snapshot = lookup.kind === 'order' ? lookup.snapshot : null;
|
|
4600
4675
|
if (snapshot) {
|
|
4601
|
-
var
|
|
4676
|
+
var _ref100;
|
|
4602
4677
|
var _snapshot_ref_parent_parent3;
|
|
4603
|
-
const hostId = String((
|
|
4678
|
+
const hostId = String((_ref100 = (_snapshot_ref_parent_parent3 = snapshot.ref.parent.parent) == null ? void 0 : _snapshot_ref_parent_parent3.id) != null ? _ref100 : '');
|
|
4604
4679
|
if (type === 'charge.dispute.created') {
|
|
4605
4680
|
var _snapshot_data2;
|
|
4606
4681
|
// A chargeback's gift cards are frozen while it is open (AGL-3363).
|
|
@@ -4618,7 +4693,7 @@ async function findOrderForDispute(paymentIntentId) {
|
|
|
4618
4693
|
}, notifyRiskEvent);
|
|
4619
4694
|
const { opened, record } = await recordDisputeOpened(snapshot, dispute);
|
|
4620
4695
|
if (opened && hostId) {
|
|
4621
|
-
var _snapshot_data3, _record_evidenceDueByMs,
|
|
4696
|
+
var _snapshot_data3, _record_evidenceDueByMs, _ref101;
|
|
4622
4697
|
// Time-critical — Stripe's evidence window is days, not weeks — so
|
|
4623
4698
|
// this is awaited rather than fired off with `void`: the handler is
|
|
4624
4699
|
// serverless and work left running past the response is work the
|
|
@@ -4637,16 +4712,16 @@ async function findOrderForDispute(paymentIntentId) {
|
|
|
4637
4712
|
},
|
|
4638
4713
|
amount: `$${(record.amountCents / 100).toFixed(2)}`,
|
|
4639
4714
|
evidenceDueByMs: (_record_evidenceDueByMs = record.evidenceDueByMs) != null ? _record_evidenceDueByMs : null,
|
|
4640
|
-
dedupeKey: `sale:${String((
|
|
4715
|
+
dedupeKey: `sale:${String((_ref101 = dispute == null ? void 0 : dispute.id) != null ? _ref101 : snapshot.id)}`,
|
|
4641
4716
|
staffEvidence: record.reason ? `Reason: ${record.reason.replace(/_/g, ' ')}.` : null
|
|
4642
4717
|
});
|
|
4643
4718
|
}
|
|
4644
4719
|
} else {
|
|
4645
|
-
var
|
|
4720
|
+
var _ref102, _snapshot_data4, _ref103;
|
|
4646
4721
|
// Lost: the money went back, so the cards it bought are voided. Won
|
|
4647
4722
|
// (or closed on a warning): the dispute's freeze lifts; a freeze a
|
|
4648
4723
|
// fraud warning or review put on stays for the merchant (AGL-3363).
|
|
4649
|
-
await applyOrderGiftCardRisk(snapshot, String((
|
|
4724
|
+
await applyOrderGiftCardRisk(snapshot, String((_ref102 = dispute == null ? void 0 : dispute.status) != null ? _ref102 : '') === 'lost' ? {
|
|
4650
4725
|
kind: 'void',
|
|
4651
4726
|
reason: 'dispute-lost'
|
|
4652
4727
|
} : {
|
|
@@ -4717,7 +4792,7 @@ async function findOrderForDispute(paymentIntentId) {
|
|
|
4717
4792
|
// transiently-failed reversal gets its retry — and gated inside on
|
|
4718
4793
|
// the order's own `reversedTransferCents` marker, so it runs at most
|
|
4719
4794
|
// once per dispute however many times Stripe delivers.
|
|
4720
|
-
if (String((
|
|
4795
|
+
if (String((_ref103 = dispute == null ? void 0 : dispute.status) != null ? _ref103 : '') === 'lost') {
|
|
4721
4796
|
const pulledBackCents = await reverseSellerShare(snapshot.ref, dispute);
|
|
4722
4797
|
// The merchant-experience half of the AGL-1794 decision, and not an
|
|
4723
4798
|
// optional extra: the reversal takes money out of the connected
|
|
@@ -4747,7 +4822,7 @@ async function findOrderForDispute(paymentIntentId) {
|
|
|
4747
4822
|
return _extends({
|
|
4748
4823
|
claimed
|
|
4749
4824
|
}, snapshot ? {
|
|
4750
|
-
hostId: String((
|
|
4825
|
+
hostId: String((_ref99 = (_snapshot_ref_parent_parent2 = snapshot.ref.parent.parent) == null ? void 0 : _snapshot_ref_parent_parent2.id) != null ? _ref99 : '')
|
|
4751
4826
|
} : {});
|
|
4752
4827
|
}
|
|
4753
4828
|
};
|