@sixtyninecommerce/admin 0.10.0 → 0.11.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 +4347 -171
- package/dist/catalog/assets.d.ts +120 -8
- package/dist/catalog/assets.js +98 -12
- package/dist/catalog/collections.d.ts +279 -14
- package/dist/catalog/collections.js +246 -15
- package/dist/catalog/index.d.ts +9 -2
- package/dist/catalog/index.js +4 -0
- package/dist/catalog/products.d.ts +159 -19
- package/dist/catalog/products.js +88 -13
- package/dist/catalog/properties.d.ts +102 -14
- package/dist/catalog/properties.js +13 -0
- package/dist/catalog/recommendations.d.ts +261 -0
- package/dist/catalog/recommendations.js +145 -0
- package/dist/catalog/reviews.d.ts +368 -0
- package/dist/catalog/reviews.js +318 -0
- package/dist/catalog/types.d.ts +17 -1
- package/dist/catalog/types.js +10 -0
- package/dist/catalog/variant-find.d.ts +136 -0
- package/dist/catalog/variant-find.js +239 -0
- package/dist/catalog/variants.d.ts +233 -26
- package/dist/catalog/variants.js +125 -7
- package/dist/catalog/visibility.d.ts +20 -5
- package/dist/catalog/visibility.js +19 -1
- package/dist/client.d.ts +95 -9
- package/dist/client.js +35 -7
- package/dist/content/assets.d.ts +286 -0
- package/dist/content/assets.js +181 -0
- package/dist/content/items.d.ts +269 -0
- package/dist/content/items.js +170 -0
- package/dist/content/types.d.ts +282 -0
- package/dist/content/types.js +100 -0
- package/dist/customers/age-verification.d.ts +66 -0
- package/dist/customers/age-verification.js +79 -0
- package/dist/customers/credit.d.ts +263 -0
- package/dist/customers/credit.js +244 -0
- package/dist/customers/delivery-preferences.d.ts +120 -0
- package/dist/customers/delivery-preferences.js +97 -0
- package/dist/customers/groups.d.ts +207 -0
- package/dist/customers/groups.js +438 -0
- package/dist/customers/index.d.ts +447 -37
- package/dist/customers/index.js +313 -40
- package/dist/customers/invitation-status.d.ts +57 -0
- package/dist/customers/invitation-status.js +21 -0
- package/dist/customers/notes.d.ts +67 -0
- package/dist/customers/notes.js +51 -0
- package/dist/customers/notification-recipients.d.ts +97 -0
- package/dist/customers/notification-recipients.js +84 -0
- package/dist/customers/saved-lists.d.ts +42 -0
- package/dist/customers/saved-lists.js +61 -0
- package/dist/customers/vat.d.ts +83 -0
- package/dist/customers/vat.js +46 -0
- package/dist/customers/wire.d.ts +20 -0
- package/dist/customers/wire.js +35 -0
- package/dist/documents/ar.d.ts +307 -0
- package/dist/documents/ar.js +254 -0
- package/dist/documents/index.d.ts +731 -21
- package/dist/documents/index.js +436 -24
- package/dist/documents/pdf.d.ts +2 -0
- package/dist/documents/pdf.js +11 -0
- package/dist/fulfillments/create.d.ts +167 -0
- package/dist/fulfillments/create.js +216 -0
- package/dist/fulfillments/index.d.ts +44 -10
- package/dist/fulfillments/index.js +11 -2
- package/dist/fulfillments/payment-policy.d.ts +64 -0
- package/dist/fulfillments/payment-policy.js +140 -0
- package/dist/fulfillments/warehouse.d.ts +724 -0
- package/dist/fulfillments/warehouse.js +914 -0
- package/dist/geo/index.d.ts +119 -0
- package/dist/geo/index.js +107 -0
- package/dist/index.d.ts +123 -35
- package/dist/index.js +45 -12
- package/dist/integrations/afas-actions.d.ts +234 -0
- package/dist/integrations/afas-actions.js +310 -0
- package/dist/integrations/afas-types.d.ts +483 -0
- package/dist/integrations/afas-types.js +5 -0
- package/dist/integrations/afas.d.ts +234 -0
- package/dist/integrations/afas.js +290 -0
- package/dist/integrations/connections.d.ts +103 -0
- package/dist/integrations/connections.js +55 -0
- package/dist/integrations/esp.d.ts +313 -0
- package/dist/integrations/esp.js +169 -0
- package/dist/integrations/exact-online-types.d.ts +423 -0
- package/dist/integrations/exact-online-types.js +6 -0
- package/dist/integrations/exact-online.d.ts +248 -0
- package/dist/integrations/exact-online.js +376 -0
- package/dist/integrations/index.d.ts +29 -3
- package/dist/integrations/index.js +18 -3
- package/dist/integrations/pipeline-keys.d.ts +13 -0
- package/dist/integrations/pipeline-keys.js +22 -0
- package/dist/integrations/pipelines.d.ts +15 -14
- package/dist/integrations/pipelines.js +6 -22
- package/dist/integrations/types.d.ts +146 -0
- package/dist/locations/index.d.ts +66 -0
- package/dist/locations/index.js +31 -0
- package/dist/meta/index.d.ts +162 -0
- package/dist/orders/cancel-with-money.d.ts +227 -0
- package/dist/orders/cancel-with-money.js +153 -0
- package/dist/orders/commit-edit.d.ts +7 -1
- package/dist/orders/commit-edit.js +5 -1
- package/dist/orders/drafts.d.ts +800 -0
- package/dist/orders/drafts.js +771 -0
- package/dist/orders/fields.d.ts +245 -0
- package/dist/orders/fields.js +188 -0
- package/dist/orders/get.d.ts +29 -19
- package/dist/orders/get.js +17 -8
- package/dist/orders/index.d.ts +49 -9
- package/dist/orders/index.js +22 -2
- package/dist/orders/lifecycle.d.ts +128 -0
- package/dist/orders/lifecycle.js +158 -0
- package/dist/orders/line-price-preview.d.ts +7 -2
- package/dist/orders/list.d.ts +222 -0
- package/dist/orders/list.js +377 -0
- package/dist/orders/manual-pricing.d.ts +5 -0
- package/dist/orders/order-entry.d.ts +20 -7
- package/dist/orders/plan-edit.d.ts +1 -1
- package/dist/orders/plan-edit.js +4 -1
- package/dist/orders/settings.d.ts +201 -0
- package/dist/orders/settings.js +325 -0
- package/dist/orders/status.d.ts +159 -13
- package/dist/orders/status.js +21 -0
- package/dist/orders/surcharges.d.ts +8 -1
- package/dist/orders/surcharges.js +3 -2
- package/dist/payments/account-credit.d.ts +30 -0
- package/dist/payments/account-credit.js +19 -0
- package/dist/payments/ar.d.ts +292 -0
- package/dist/payments/ar.js +223 -0
- package/dist/payments/connected-account.d.ts +47 -0
- package/dist/payments/connected-account.js +61 -0
- package/dist/payments/credit-noted-fields.d.ts +12 -0
- package/dist/payments/credit-noted-fields.js +37 -0
- package/dist/payments/index.d.ts +257 -11
- package/dist/payments/index.js +131 -1
- package/dist/payments/methods.d.ts +303 -8
- package/dist/payments/methods.js +337 -7
- package/dist/payments/mollie-methods.d.ts +159 -0
- package/dist/payments/mollie-methods.js +141 -0
- package/dist/payments/payment-links.d.ts +180 -0
- package/dist/payments/payment-links.js +97 -0
- package/dist/payments/provider-keys.d.ts +150 -0
- package/dist/payments/provider-keys.js +118 -0
- package/dist/payments/providers.d.ts +86 -11
- package/dist/payments/providers.js +29 -0
- package/dist/payments/requests.d.ts +144 -0
- package/dist/payments/requests.js +92 -0
- package/dist/payments/store-credit-fields.d.ts +15 -0
- package/dist/payments/store-credit-fields.js +51 -0
- package/dist/pickups/index.d.ts +104 -0
- package/dist/pickups/index.js +105 -0
- package/dist/platform/channels.d.ts +132 -0
- package/dist/platform/channels.js +128 -0
- package/dist/platform/geo.d.ts +123 -0
- package/dist/platform/geo.js +144 -0
- package/dist/platform/tax.d.ts +154 -0
- package/dist/platform/tax.js +139 -0
- package/dist/pos/anomalies.d.ts +158 -0
- package/dist/pos/anomalies.js +64 -0
- package/dist/pos/assisted-selling.d.ts +79 -0
- package/dist/pos/assisted-selling.js +38 -0
- package/dist/pos/exchanges.d.ts +103 -0
- package/dist/pos/exchanges.js +22 -0
- package/dist/pos/gift-cards.d.ts +135 -0
- package/dist/pos/gift-cards.js +47 -0
- package/dist/pos/index.d.ts +2125 -32
- package/dist/pos/index.js +742 -4
- package/dist/pos/no-receipt.d.ts +94 -0
- package/dist/pos/no-receipt.js +25 -0
- package/dist/pos/offline-sales.d.ts +187 -0
- package/dist/pos/offline-sales.js +116 -0
- package/dist/pos/pay-by-link.d.ts +143 -0
- package/dist/pos/pay-by-link.js +57 -0
- package/dist/pos/quick-keys.d.ts +103 -0
- package/dist/pos/quick-keys.js +45 -0
- package/dist/pos/reports.d.ts +360 -0
- package/dist/pos/reports.js +62 -0
- package/dist/pos/returns.d.ts +217 -0
- package/dist/pos/returns.js +53 -0
- package/dist/pricing/bulk-coupons.d.ts +139 -0
- package/dist/pricing/bulk-coupons.js +112 -0
- package/dist/pricing/index.d.ts +174 -4
- package/dist/pricing/index.js +174 -1
- package/dist/pricing/price-lists.d.ts +604 -0
- package/dist/pricing/price-lists.js +600 -0
- package/dist/purchasing/alerts.d.ts +89 -0
- package/dist/purchasing/alerts.js +62 -0
- package/dist/purchasing/cost.d.ts +110 -0
- package/dist/purchasing/cost.js +86 -0
- package/dist/purchasing/index.d.ts +36 -0
- package/dist/purchasing/index.js +16 -0
- package/dist/purchasing/purchase-orders.d.ts +548 -0
- package/dist/purchasing/purchase-orders.js +491 -0
- package/dist/purchasing/replenishment.d.ts +281 -0
- package/dist/purchasing/replenishment.js +240 -0
- package/dist/purchasing/settings.d.ts +152 -0
- package/dist/purchasing/settings.js +181 -0
- package/dist/purchasing/suppliers.d.ts +476 -0
- package/dist/purchasing/suppliers.js +438 -0
- package/dist/quotes/index.d.ts +501 -0
- package/dist/quotes/index.js +439 -0
- package/dist/reports/index.d.ts +71 -8
- package/dist/reports/index.js +74 -11
- package/dist/returns/index.d.ts +614 -21
- package/dist/returns/index.js +695 -11
- package/dist/search/index.d.ts +76 -1
- package/dist/search/index.js +63 -0
- package/dist/shipping/definitions.d.ts +29 -0
- package/dist/shipping/definitions.js +47 -0
- package/dist/shipping/fulfillment-profiles.d.ts +174 -0
- package/dist/shipping/fulfillment-profiles.js +104 -0
- package/dist/shipping/hendriks.d.ts +97 -0
- package/dist/shipping/hendriks.js +50 -0
- package/dist/shipping/index.d.ts +48 -0
- package/dist/shipping/index.js +25 -0
- package/dist/shipping/methods.d.ts +198 -0
- package/dist/shipping/methods.js +240 -0
- package/dist/shipping/myparcel.d.ts +254 -0
- package/dist/shipping/myparcel.js +178 -0
- package/dist/shipping/parcel-count-suggestion.d.ts +2 -0
- package/dist/shipping/parcel-rule.d.ts +6 -5
- package/dist/shipping/parcel-rule.js +21 -23
- package/dist/shipping/rate-tables.d.ts +179 -0
- package/dist/shipping/rate-tables.js +184 -0
- package/dist/stock/index.d.ts +10 -3
- package/dist/stock/index.js +3 -0
- package/dist/stock/locations.d.ts +144 -0
- package/dist/stock/locations.js +168 -0
- package/dist/stock/transfers.d.ts +216 -43
- package/dist/stock/transfers.js +140 -13
- package/dist/stored-value/index.d.ts +214 -4
- package/dist/stored-value/index.js +152 -0
- package/dist/subscriptions/index.d.ts +682 -0
- package/dist/subscriptions/index.js +815 -0
- package/dist/tax/index.d.ts +76 -1
- package/dist/tax/index.js +50 -0
- package/dist/tenant/email-style.d.ts +102 -0
- package/dist/tenant/email-style.js +72 -0
- package/dist/tenant/email-templates.d.ts +66 -0
- package/dist/tenant/email-templates.js +54 -0
- package/dist/tenant/notifications.d.ts +23 -17
- package/dist/tenant/settings-sources.d.ts +1 -1
- package/dist/tenant/time-zone.d.ts +17 -0
- package/dist/tenant/time-zone.js +11 -0
- package/dist/types.d.ts +50 -3
- package/dist/users/index.d.ts +3 -0
- package/dist/users/index.js +2 -0
- package/dist/users/warehouses.d.ts +50 -0
- package/dist/users/warehouses.js +51 -0
- package/package.json +2 -2
package/dist/payments/index.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Transport } from '@sixtyninecommerce/core';
|
|
2
|
+
import type { InvoiceCorrectionLedger } from '../documents/index.js';
|
|
2
3
|
import type { Call } from '../types.js';
|
|
3
4
|
import { type AccountCreditModule } from './account-credit.js';
|
|
5
|
+
import { type ArPaymentsModule } from './ar.js';
|
|
4
6
|
import { type PaymentMethodsModule } from './methods.js';
|
|
7
|
+
import { type PaymentLinksModule } from './payment-links.js';
|
|
5
8
|
import { type ProvidersModule } from './providers.js';
|
|
9
|
+
import { type PaymentRequestsModule } from './requests.js';
|
|
6
10
|
/**
|
|
7
11
|
* What an order has actually been paid, in minor units of its own currency.
|
|
8
12
|
*
|
|
@@ -10,7 +14,11 @@ import { type ProvidersModule } from './providers.js';
|
|
|
10
14
|
* is a second source of truth that drifts the first time a refund lands.
|
|
11
15
|
*/
|
|
12
16
|
export interface OrderPaymentPosition {
|
|
13
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* The order's own gross total, carrying the order's rounding rule. 0 for a `Cancelled` order:
|
|
19
|
+
* a cancelled order bills nothing. A credit note does not change it: see `creditNoted` and
|
|
20
|
+
* `owed`.
|
|
21
|
+
*/
|
|
14
22
|
total: number;
|
|
15
23
|
/** Settled plus authorized, less refunds: what is accounted for. */
|
|
16
24
|
covered: number;
|
|
@@ -24,13 +32,38 @@ export interface OrderPaymentPosition {
|
|
|
24
32
|
* counted here, though it is taken off `settled` like one.
|
|
25
33
|
*/
|
|
26
34
|
refunded: number;
|
|
27
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* What the order's credit notes took off what it bills: `total` less what its invoices bill net
|
|
37
|
+
* of their credit notes (a part credited, an invoice voided with no replacement), never more
|
|
38
|
+
* than `total`; 0 for an order with no invoice. A correction never restates the order, so
|
|
39
|
+
* `total` keeps reading what it first billed. Taken off `owed` only.
|
|
40
|
+
*
|
|
41
|
+
* Read by {@link PaymentsModule.position}, `orders.paymentPosition` and the cancel-with-money
|
|
42
|
+
* preview and answer. Against an engine that does not serve it those calls resend their document
|
|
43
|
+
* without it (`creditNotedAware`), so it is absent and reads as zero; absent from a settlement's
|
|
44
|
+
* position too.
|
|
45
|
+
*/
|
|
46
|
+
creditNoted?: number;
|
|
47
|
+
/**
|
|
48
|
+
* What the customer still owes once the credit notes are counted: `total - creditNoted -
|
|
49
|
+
* covered`, floored at zero. A refund that went back with a credit note is owed by nobody.
|
|
50
|
+
* Equals `outstanding` when nothing was credited. Read by the same calls as `creditNoted`; where
|
|
51
|
+
* it is absent, the customer owes `outstanding`.
|
|
52
|
+
*/
|
|
53
|
+
owed?: number;
|
|
54
|
+
/**
|
|
55
|
+
* `total - covered`, floored at zero: what the payments are short of the order's total, and
|
|
56
|
+
* what `record` caps a payment at. On an order whose credit notes took part of its bill off,
|
|
57
|
+
* `owed` is what the customer still owes.
|
|
58
|
+
*/
|
|
28
59
|
outstanding: number;
|
|
29
60
|
/**
|
|
30
61
|
* `covered - total`, floored at zero. Over-payment is refused at the door, so
|
|
31
62
|
* this is non-zero only for imported history, rows predating the guard, a
|
|
32
|
-
* refund that landed after a second payment,
|
|
33
|
-
* total of a paid order
|
|
63
|
+
* refund that landed after a second payment, an edit that lowered the
|
|
64
|
+
* total of a paid order, or money kept on a cancelled order (a cancelled
|
|
65
|
+
* order bills nothing; `orders.cancelWithMoney` with `retain`), which can
|
|
66
|
+
* still be credited to the account. Money moved to the customer's account
|
|
34
67
|
* (`payments.accountCredit.creditOverpayment`) no longer counts here.
|
|
35
68
|
*/
|
|
36
69
|
overpaid: number;
|
|
@@ -81,7 +114,10 @@ export interface RefundablePayment {
|
|
|
81
114
|
/**
|
|
82
115
|
* `amount - refunded`, less what of this payment is on the customer's account
|
|
83
116
|
* (`payments.accountCredit.onOrder`), when this payment took money; floored
|
|
84
|
-
* at zero, else zero.
|
|
117
|
+
* at zero, else zero. Less, too, this payment's share of what the gift cards
|
|
118
|
+
* sold on the order hold: a live card's value, and a voided card's spent (or
|
|
119
|
+
* expired) value, which stays held for good. How much, and on which payment:
|
|
120
|
+
* {@link PaymentsModule.refundGiftCardHold}.
|
|
85
121
|
*/
|
|
86
122
|
refundable: number;
|
|
87
123
|
/**
|
|
@@ -118,11 +154,43 @@ export interface OrderRefundPosition {
|
|
|
118
154
|
* Money moved to the customer's account as unapplied cash IS deducted: it is
|
|
119
155
|
* paid back from the account (`payments.accountCredit.refund`), never from
|
|
120
156
|
* the order a second time.
|
|
157
|
+
*
|
|
158
|
+
* What the gift cards sold on the order hold is deducted too: a live card's
|
|
159
|
+
* value, and a voided card's spent (or expired) value, which stays held for
|
|
160
|
+
* good. A refund of it is refused `REFUND_HELD_BY_GIFT_CARD`;
|
|
161
|
+
* {@link PaymentsModule.refundGiftCardHold} says how much, and on which payment.
|
|
121
162
|
*/
|
|
122
163
|
refundable: number;
|
|
123
164
|
/** Every payment on the order, NEWEST FIRST, with its own headroom. */
|
|
124
165
|
perPayment: RefundablePayment[];
|
|
125
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* What the gift cards sold on an order hold of its money: why its refund position's `refundable`
|
|
169
|
+
* is lower than what its payments took ({@link PaymentsModule.refundGiftCardHold}).
|
|
170
|
+
*/
|
|
171
|
+
export interface RefundGiftCardHold {
|
|
172
|
+
/** The order's currency. Every amount here is in its minor units. */
|
|
173
|
+
currencyCode: string;
|
|
174
|
+
/**
|
|
175
|
+
* What the cards hold: each card its face value less what a void released, and a void releases
|
|
176
|
+
* at most what the card had not spent, so a card's spent (or expired) value stays held for good.
|
|
177
|
+
* Already counted out of `refundable`, so `refundable` plus this is what the payments would hand
|
|
178
|
+
* back with no card. A refund of it is refused `REFUND_HELD_BY_GIFT_CARD`. 0 when no card holds
|
|
179
|
+
* any.
|
|
180
|
+
*/
|
|
181
|
+
giftCardHold: number;
|
|
182
|
+
/**
|
|
183
|
+
* How many of the cards sold on the order are still live (not voided); null while
|
|
184
|
+
* `giftCardHold` is 0. Above 0, voiding a card releases what it has not spent; 0 means every
|
|
185
|
+
* card is voided, and what they hold is spent value that stays with the store.
|
|
186
|
+
*/
|
|
187
|
+
liveGiftCards: number | null;
|
|
188
|
+
/** Each payment's share of the hold, NEWEST FIRST, as `refundPosition` lists them. */
|
|
189
|
+
perPayment: Array<{
|
|
190
|
+
paymentId: string;
|
|
191
|
+
giftCardHold: number;
|
|
192
|
+
}>;
|
|
193
|
+
}
|
|
126
194
|
/**
|
|
127
195
|
* A refund whose outcome is unknown: it reached its payment provider and was
|
|
128
196
|
* never confirmed (a timeout, a dropped connection, a server error), so the
|
|
@@ -139,6 +207,30 @@ export interface UnreconciledRefund {
|
|
|
139
207
|
/** ISO-8601 with offset. */
|
|
140
208
|
createdAt: string | null;
|
|
141
209
|
}
|
|
210
|
+
/**
|
|
211
|
+
* The invoice a refund of an order must go through, so a credit note says what the money was for
|
|
212
|
+
* (see {@link PaymentsModule.refundCreditNoteRequirement}).
|
|
213
|
+
*/
|
|
214
|
+
export interface RefundCreditNoteRequirement {
|
|
215
|
+
/** The live invoice billing the order: plan and commit the correction on it. */
|
|
216
|
+
invoiceId: string;
|
|
217
|
+
/** As printed on the invoice. */
|
|
218
|
+
invoiceNumber: string;
|
|
219
|
+
/**
|
|
220
|
+
* The ledger to plan the correction on (`documents.planCorrection({ ledger, invoiceId })`).
|
|
221
|
+
* `RETAIL` is named first when the order has both: its correction can carry the refund.
|
|
222
|
+
*/
|
|
223
|
+
ledger: InvoiceCorrectionLedger;
|
|
224
|
+
/**
|
|
225
|
+
* Minor units of the order's currency: what its payments hold over what it bills (a duplicate
|
|
226
|
+
* payment, say), net of every refund. "What it bills" is the larger of the order's total and
|
|
227
|
+
* what its live invoices bill. {@link PaymentsModule.refund} gives back up to this much
|
|
228
|
+
* without a credit note, recorded as an overpayment refund (the invoice never billed it); a
|
|
229
|
+
* larger refund goes through the correction. `0` when the order is not overpaid. Only payments
|
|
230
|
+
* that took money count, and a refund of unknown outcome stays reserved.
|
|
231
|
+
*/
|
|
232
|
+
refundableOverpayment: number;
|
|
233
|
+
}
|
|
142
234
|
/** What the payment provider says happened to a refund whose outcome was unknown. */
|
|
143
235
|
export type RefundProviderOutcome = 'MADE' | 'NOT_MADE';
|
|
144
236
|
/** The provider's answer for a refund whose outcome is unknown. */
|
|
@@ -202,6 +294,18 @@ export interface PaidOrder {
|
|
|
202
294
|
total: number;
|
|
203
295
|
totalWithTax: number;
|
|
204
296
|
}
|
|
297
|
+
/** A payment, as {@link PaymentsModule.settle} and {@link PaymentsModule.cancel} answer it. */
|
|
298
|
+
export interface OrderPaymentRecord {
|
|
299
|
+
id: string;
|
|
300
|
+
/** Vendure's payment state: `Settled` after a capture, `Cancelled` after a void. */
|
|
301
|
+
state: string;
|
|
302
|
+
/** The payment method code. */
|
|
303
|
+
method: string;
|
|
304
|
+
/** Minor units of the order's currency. */
|
|
305
|
+
amount: number;
|
|
306
|
+
/** The provider's reference for the payment, when it gave one. */
|
|
307
|
+
transactionId: string | null;
|
|
308
|
+
}
|
|
205
309
|
/** What a payment app reports happened to a payment it took (`reportAppPayment`). */
|
|
206
310
|
export type AppPaymentReportState = 'Authorized' | 'Settled' | 'Declined' | 'Cancelled';
|
|
207
311
|
/** An app's report on one of its payments. */
|
|
@@ -285,11 +389,27 @@ export interface PaymentsModule {
|
|
|
285
389
|
* to an invoice, pay it back.
|
|
286
390
|
*/
|
|
287
391
|
accountCredit: AccountCreditModule;
|
|
392
|
+
/**
|
|
393
|
+
* Money on the accounts-receivable ledger: customer payments against AR invoices, the ledger,
|
|
394
|
+
* prepaid drawdowns and SEPA direct debit collection.
|
|
395
|
+
*/
|
|
396
|
+
ar: ArPaymentsModule;
|
|
288
397
|
/**
|
|
289
398
|
* The store's payment methods, as staff choose one: the `method` code
|
|
290
399
|
* {@link PaymentsModule.record} takes, and the codes a deposit policy names.
|
|
291
400
|
*/
|
|
292
401
|
methods: PaymentMethodsModule;
|
|
402
|
+
/**
|
|
403
|
+
* Hosted payment requests: ask the customer to pay a chosen amount of a held
|
|
404
|
+
* order or a committed draft through a stable link that opens the payment
|
|
405
|
+
* provider's checkout. See {@link PaymentRequestsModule}.
|
|
406
|
+
*/
|
|
407
|
+
requests: PaymentRequestsModule;
|
|
408
|
+
/**
|
|
409
|
+
* The store's payment links (Tikkie): the connection's settings and checks, and the links an
|
|
410
|
+
* order was sent by invoice e-mail. See {@link PaymentLinksModule}.
|
|
411
|
+
*/
|
|
412
|
+
paymentLinks: PaymentLinksModule;
|
|
293
413
|
/**
|
|
294
414
|
* Record part (or all) of what an order owes, and return the order.
|
|
295
415
|
*
|
|
@@ -303,9 +423,16 @@ export interface PaymentsModule {
|
|
|
303
423
|
* store that has not turned deposits on; paying the whole outstanding balance
|
|
304
424
|
* is not a deposit and always works — `METADATA_KEY_RESERVED`,
|
|
305
425
|
* `PAYMENT_METHOD_NOT_FOUND`, `ORDER_NOT_FOUND`.
|
|
426
|
+
*
|
|
427
|
+
* @effect money
|
|
306
428
|
*/
|
|
307
429
|
record(orderId: string, input: RecordPaymentInput, options?: Call): Promise<PaidOrder>;
|
|
308
|
-
/**
|
|
430
|
+
/**
|
|
431
|
+
* Read an order's payment position: what it bills, what was paid and refunded, what its credit
|
|
432
|
+
* notes took off (`creditNoted`) and what the customer still owes after them (`owed`).
|
|
433
|
+
*
|
|
434
|
+
* @effect read
|
|
435
|
+
*/
|
|
309
436
|
position(orderId: string, options?: Call): Promise<OrderPaymentPosition>;
|
|
310
437
|
/**
|
|
311
438
|
* Hand money back to a customer, never more than the order took.
|
|
@@ -379,10 +506,118 @@ export interface PaymentsModule {
|
|
|
379
506
|
* order has been read carries that order's position in
|
|
380
507
|
* `extensions.refundPosition`, so a till can correct itself without a second
|
|
381
508
|
* round trip.
|
|
509
|
+
*
|
|
510
|
+
* **An invoiced order is refunded through its invoice, not here.** While the
|
|
511
|
+
* order has a live invoice, this refuses `REFUND_REQUIRES_CREDIT_NOTE` (a
|
|
512
|
+
* `ConflictError`, 409) before anything else: a refund made here issues no
|
|
513
|
+
* document, and the invoice would stand with no credit note for the money.
|
|
514
|
+
* Ask {@link refundCreditNoteRequirement} first; it names the invoice, and
|
|
515
|
+
* `documents.commitCorrection` on it issues the credit note and then refunds.
|
|
516
|
+
* Not refused: an amount within the order's overpayment
|
|
517
|
+
* (`refundableOverpayment`, money the invoice never billed), refunded here
|
|
518
|
+
* and recorded as an overpayment refund; and a customer with a credit
|
|
519
|
+
* account on a store that keeps the accounts-receivable ledger, whose refund
|
|
520
|
+
* is documented when it settles: by an AR credit note for what an invoice
|
|
521
|
+
* billed, and by none for money no invoice billed (a duplicate payment given
|
|
522
|
+
* back), which is recorded as an overpayment refund. The refusal's `details`
|
|
523
|
+
* name the invoice and the overpayment still refundable. Needs an engine that knows
|
|
524
|
+
* the rule (vendure-server deployed first); an older one refunds as before.
|
|
525
|
+
*
|
|
526
|
+
* @effect money
|
|
382
527
|
*/
|
|
383
528
|
refund(input: RefundPaymentInput, options?: Call): Promise<IssuedRefund>;
|
|
529
|
+
/**
|
|
530
|
+
* Capture an authorized payment at its provider ("mark as paid"), and return the payment.
|
|
531
|
+
*
|
|
532
|
+
* At most once per payment, whoever asks and however often: the engine keys every capture of a
|
|
533
|
+
* payment under ONE key of its own (`payment:<id>:capture`), so this method takes no
|
|
534
|
+
* `idempotencyKey`. A repeat while the payment is `Settled` captures nothing and is refused
|
|
535
|
+
* `PAYMENT_STATE_TRANSITION_ERROR` ("already settled"); a repeat while the first capture is
|
|
536
|
+
* still running is refused `IDEMPOTENCY_IN_PROGRESS`. A capture whose answer was lost after it
|
|
537
|
+
* reached the provider is refused `IDEMPOTENCY_OUTCOME_UNKNOWN` (`error.outcomeUnknown`) on
|
|
538
|
+
* that call and on every capture for the key's retention (24 hours): check the payment with the
|
|
539
|
+
* provider before doing anything else with it, and never retry this blind. Once the key is
|
|
540
|
+
* swept a capture asks the provider again, so an automatic retry after a day can capture a
|
|
541
|
+
* second time; the provider's own report (`reportAppPayment`) still settles it meanwhile.
|
|
542
|
+
*
|
|
543
|
+
* Refusals, as coded errors (the Admin API answers some as a result union; this method throws
|
|
544
|
+
* every one):
|
|
545
|
+
* - `PAYMENT_SETTLE_DECLINED` (`BusinessRuleError`, 422): the provider declined the capture.
|
|
546
|
+
* The message is the provider's reason. Nothing was captured, and a later capture may be
|
|
547
|
+
* tried.
|
|
548
|
+
* - `PAYMENT_STATE_TRANSITION_ERROR` (422): the payment is not `Authorized` (settled, cancelled
|
|
549
|
+
* or declined already). The message says which.
|
|
550
|
+
* - `ORDER_STATE_TRANSITION_ERROR` (422): the capture went through the provider's gate but the
|
|
551
|
+
* order could not move on as it stands.
|
|
552
|
+
* - `ORDER_CANCELLED_PAYMENT_CONFLICT` (409): the payment's order is cancelled, and a cancelled
|
|
553
|
+
* order is never paid. Cancel the payment instead to release it.
|
|
554
|
+
* - `PAYMENT_SETTLE_CONFLICT` (409): the payment moved while it was being captured. Read it
|
|
555
|
+
* again.
|
|
556
|
+
* - `ENTITY_NOT_FOUND` (404): no payment of an order of this store has that id.
|
|
557
|
+
*
|
|
558
|
+
* Needs `UpdateOrder`.
|
|
559
|
+
*
|
|
560
|
+
* @effect money
|
|
561
|
+
*/
|
|
562
|
+
settle(paymentId: string, options?: Call): Promise<OrderPaymentRecord>;
|
|
563
|
+
/**
|
|
564
|
+
* Void an authorized payment (release the hold), and return the payment.
|
|
565
|
+
*
|
|
566
|
+
* A cancel takes turns with the payment's capture: one that reaches a payment that is no
|
|
567
|
+
* longer authorized, or one whose capture may have reached its provider with no answer, is
|
|
568
|
+
* refused `PAYMENT_CANCEL_CONFLICT` (409) and nothing is asked of the provider. A `Settled`
|
|
569
|
+
* payment is never voided: its money was taken, so it is refunded ({@link refund}).
|
|
570
|
+
*
|
|
571
|
+
* Other refusals, as coded errors:
|
|
572
|
+
* - `PAYMENT_CANCEL_DECLINED` (`BusinessRuleError`, 422): the provider refused the void. The
|
|
573
|
+
* message is the provider's reason; the hold may still stand at the provider.
|
|
574
|
+
* - `PAYMENT_STATE_TRANSITION_ERROR` (422): the payment cannot move to `Cancelled` from where
|
|
575
|
+
* it is.
|
|
576
|
+
* - `ENTITY_NOT_FOUND` (404): no payment of an order of this store has that id.
|
|
577
|
+
*
|
|
578
|
+
* Needs `UpdateOrder`.
|
|
579
|
+
*
|
|
580
|
+
* @effect money
|
|
581
|
+
*/
|
|
582
|
+
cancel(paymentId: string, options?: Call): Promise<OrderPaymentRecord>;
|
|
583
|
+
/**
|
|
584
|
+
* Whether {@link refund} (and core's `refundOrder`, and the till's refund) is
|
|
585
|
+
* refused for this order with `REFUND_REQUIRES_CREDIT_NOTE`, and which invoice
|
|
586
|
+
* the refund goes through instead; `null` when a plain refund may go ahead.
|
|
587
|
+
*
|
|
588
|
+
* The order has a live invoice in this store, so a refund needs a credit note
|
|
589
|
+
* saying what it is for, beyond `refundableOverpayment` (what the order was
|
|
590
|
+
* paid over what it bills, which {@link refund} still gives back). Plan the
|
|
591
|
+
* correction with
|
|
592
|
+
* `documents.planCorrection({ ledger, invoiceId, outcome, refundPaymentId })` and
|
|
593
|
+
* issue it with `documents.commitCorrection`: the credit note is issued, then
|
|
594
|
+
* the money refunded. `null` for an order with no live invoice, and for a
|
|
595
|
+
* customer with a credit account on a store that keeps the
|
|
596
|
+
* accounts-receivable ledger (their refunds are documented when they settle:
|
|
597
|
+
* by an AR credit note, except the part no invoice billed, which gets none).
|
|
598
|
+
* Needs `ReadOrder`.
|
|
599
|
+
*
|
|
600
|
+
* Its own query rather than a field of {@link refundPosition}, so a release of
|
|
601
|
+
* this SDK reading an older engine fails only this call. The answer is read
|
|
602
|
+
* without a lock: the refund doors judge again when they run.
|
|
603
|
+
*
|
|
604
|
+
* @effect read
|
|
605
|
+
*/
|
|
606
|
+
refundCreditNoteRequirement(orderId: string, options?: Call): Promise<RefundCreditNoteRequirement | null>;
|
|
384
607
|
/** Read what an order may still hand back. */
|
|
385
608
|
refundPosition(orderId: string, options?: Call): Promise<OrderRefundPosition>;
|
|
609
|
+
/**
|
|
610
|
+
* What the gift cards sold on an order hold of its money, on the order and per payment, and
|
|
611
|
+
* how many of them are still live: why {@link refundPosition}'s `refundable` is lower than the
|
|
612
|
+
* money taken. Needs `ReadOrder`.
|
|
613
|
+
*
|
|
614
|
+
* Its own query rather than fields of {@link refundPosition}, so a release of this SDK reading
|
|
615
|
+
* an older engine fails only this call. Needs an engine that serves
|
|
616
|
+
* `OrderRefundPosition.giftCardHold`.
|
|
617
|
+
*
|
|
618
|
+
* @effect read
|
|
619
|
+
*/
|
|
620
|
+
refundGiftCardHold(orderId: string, options?: Call): Promise<RefundGiftCardHold>;
|
|
386
621
|
/**
|
|
387
622
|
* The order's refunds whose outcome is unknown, oldest first — the ones
|
|
388
623
|
* {@link reconcileRefund} resolves. Each one's amount is already reserved in
|
|
@@ -418,6 +653,8 @@ export interface PaymentsModule {
|
|
|
418
653
|
*
|
|
419
654
|
* `options.idempotencyKey` is honoured: a repeat under the same key returns
|
|
420
655
|
* the first call's refund.
|
|
656
|
+
*
|
|
657
|
+
* @effect money
|
|
421
658
|
*/
|
|
422
659
|
reconcileRefund(input: ReconcileRefundInput, options?: Call): Promise<IssuedRefund>;
|
|
423
660
|
/**
|
|
@@ -463,14 +700,23 @@ export interface PaymentsModule {
|
|
|
463
700
|
appPayments(orderId: string, options?: Call): Promise<AppPayment[]>;
|
|
464
701
|
}
|
|
465
702
|
export declare const RECORD_ORDER_PAYMENT_MUTATION = "\n mutation RecordOrderPayment($orderId: ID!, $input: RecordPaymentInput!, $idempotencyKey: String) {\n recordOrderPayment(orderId: $orderId, input: $input, idempotencyKey: $idempotencyKey) {\n \n id\n code\n state\n currencyCode\n total\n totalWithTax\n\n }\n }\n";
|
|
466
|
-
export declare const ORDER_PAYMENT_POSITION_QUERY = "\n query OrderPaymentPosition($orderId: ID!) {\n orderPaymentPosition(orderId: $orderId) {\n \n total\n covered\n settled\n authorized\n refunded\n outstanding\n overpaid\n availableToCharge\n\n }\n }\n";
|
|
703
|
+
export declare const ORDER_PAYMENT_POSITION_QUERY = "\n query OrderPaymentPosition($orderId: ID!) {\n orderPaymentPosition(orderId: $orderId) {\n \n total\n covered\n settled\n authorized\n refunded\n creditNoted\n owed\n outstanding\n overpaid\n availableToCharge\n\n }\n }\n";
|
|
467
704
|
export declare const ORDER_REFUND_POSITION_QUERY = "\n query OrderRefundPosition($orderId: ID!) {\n orderRefundPosition(orderId: $orderId) {\n \n currencyCode\n refunded\n refundable\n perPayment {\n paymentId\n state\n method\n amount\n refunded\n refundable\n tookMoney\n }\n\n }\n }\n";
|
|
468
705
|
export declare const REFUND_ORDER_PAYMENT_MUTATION = "\n mutation RefundOrderPayment($input: RefundPaymentInput!, $idempotencyKey: String) {\n refundOrderPayment(input: $input, idempotencyKey: $idempotencyKey) {\n id\n total\n state\n method\n transactionId\n reason\n }\n }\n";
|
|
469
706
|
export declare const UNRECONCILED_REFUNDS_QUERY = "\n query UnreconciledRefunds($orderId: ID!) {\n orderRefundPosition(orderId: $orderId) {\n unreconciled {\n refundId\n paymentId\n amount\n createdAt\n }\n }\n }\n";
|
|
707
|
+
export declare const REFUND_GIFT_CARD_HOLD_QUERY = "\n query RefundGiftCardHold($orderId: ID!) {\n orderRefundPosition(orderId: $orderId) {\n currencyCode\n giftCardHold\n liveGiftCards\n perPayment {\n paymentId\n giftCardHold\n }\n }\n }\n";
|
|
708
|
+
export declare const REFUND_CREDIT_NOTE_REQUIREMENT_QUERY = "\n query RefundCreditNoteRequirement($orderId: ID!) {\n orderRefundPosition(orderId: $orderId) {\n creditNoteRequired {\n invoiceId\n invoiceNumber\n ledger\n refundableOverpayment\n }\n }\n }\n";
|
|
470
709
|
export declare const RECONCILE_REFUND_OUTCOME_MUTATION = "\n mutation ReconcileRefundOutcome($input: ReconcileRefundOutcomeInput!, $idempotencyKey: String) {\n reconcileRefundOutcome(input: $input, idempotencyKey: $idempotencyKey) {\n id\n total\n state\n method\n transactionId\n reason\n }\n }\n";
|
|
710
|
+
export declare const SETTLE_PAYMENT_MUTATION = "\n mutation SettlePayment($id: ID!) {\n settlePayment(id: $id) {\n __typename\n ... on Payment {\n \n id\n state\n method\n amount\n transactionId\n\n }\n ... on SettlePaymentError {\n paymentErrorMessage\n }\n ... on PaymentStateTransitionError {\n transitionError\n }\n ... on OrderStateTransitionError {\n transitionError\n }\n ... on ErrorResult {\n errorCode\n message\n }\n }\n }\n";
|
|
711
|
+
export declare const CANCEL_PAYMENT_MUTATION = "\n mutation CancelPayment($id: ID!) {\n cancelPayment(id: $id) {\n __typename\n ... on Payment {\n \n id\n state\n method\n amount\n transactionId\n\n }\n ... on CancelPaymentError {\n paymentErrorMessage\n }\n ... on PaymentStateTransitionError {\n transitionError\n }\n ... on ErrorResult {\n errorCode\n message\n }\n }\n }\n";
|
|
471
712
|
export declare const REPORT_APP_PAYMENT_MUTATION = "\n mutation ReportAppPayment(\n $paymentId: ID!\n $input: ReportAppPaymentInput!\n $idempotencyKey: String!\n ) {\n reportAppPayment(paymentId: $paymentId, input: $input, idempotencyKey: $idempotencyKey) {\n id\n state\n amount\n method\n transactionId\n }\n }\n";
|
|
472
713
|
export declare const APP_PAYMENTS_QUERY = "\n query AppPayments($orderId: ID!) {\n appPayments(orderId: $orderId) {\n id\n orderId\n orderCode\n state\n amount\n currencyCode\n providerReference\n methodCode\n outcomeUnknown\n createdAt\n }\n }\n";
|
|
473
714
|
export declare function createPaymentsModule(transport: Transport): PaymentsModule;
|
|
474
|
-
export type { AccountCreditModule, ApplyUnappliedCashInput, CreditOverpaymentInput, OrderMoneyOnAccount, RefundUnappliedCashInput, UnappliedCash, UnappliedCashRefund, } from './account-credit.js';
|
|
475
|
-
export type {
|
|
476
|
-
export type {
|
|
715
|
+
export type { AccountCreditModule, ApplyUnappliedCashInput, CreditOverpaymentInput, OrderMoneyOnAccount, RefundUnappliedCashInput, StoreCreditMove, UnappliedCash, UnappliedCashRefund, } from './account-credit.js';
|
|
716
|
+
export type { ConnectedAccountModule, StripeConnectedAccount, } from './connected-account.js';
|
|
717
|
+
export type { CreatePaymentMethodInput, PaymentMethod, PaymentMethodCredential, PaymentMethodCredentialPath, PaymentMethodsModule, PaymentMethodTranslation, PaymentMethodTranslationInput, UpdatePaymentMethodInput, } from './methods.js';
|
|
718
|
+
export type { MollieDiagnosis, MollieDiagnosisMethod, MollieDiagnosisVerdict, MollieDirectDebitDiagnosis, MollieMethod, MollieMethodList, MollieMethodsModule, MollieProbeError, MollieProbeErrorKind, SetMollieMethodsInput, } from './mollie-methods.js';
|
|
719
|
+
export type { PaymentProviderKey, ProviderKeyProvider, ProviderKeysModule, ProviderKeyTest, SetProviderKeyInput, } from './provider-keys.js';
|
|
720
|
+
export type { PaymentProviderAccount, ProviderConnection, ProviderCredentialPath, ProviderOnboardingStart, ProviderReadiness, ProvidersModule, ProviderTerminal, ProviderTerminalsModule, ProvisionTerminalInput, ReadinessOptions, } from './providers.js';
|
|
721
|
+
export type { CreatePaymentRequestInput, PaymentRequest, PaymentRequestCloseReason, PaymentRequestStatus, PaymentRequestsModule, } from './requests.js';
|
|
722
|
+
export { PAYMENT_REQUEST_CLOSE_REASONS, PAYMENT_REQUEST_DEFAULT_EXPIRY_DAYS, PAYMENT_REQUEST_MAX_EXPIRY_DAYS, PAYMENT_REQUEST_STATUSES, } from './requests.js';
|
package/dist/payments/index.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
import { BusinessRuleError, errorFromErrorResult, isErrorResult, } from '@sixtyninecommerce/core';
|
|
1
2
|
import { createAccountCreditModule } from './account-credit.js';
|
|
3
|
+
import { createArPaymentsModule } from './ar.js';
|
|
4
|
+
import { creditNotedAware } from './credit-noted-fields.js';
|
|
2
5
|
import { createPaymentMethodsModule } from './methods.js';
|
|
6
|
+
import { createPaymentLinksModule } from './payment-links.js';
|
|
3
7
|
import { createProvidersModule } from './providers.js';
|
|
8
|
+
import { createPaymentRequestsModule } from './requests.js';
|
|
4
9
|
const PAID_ORDER_FIELDS = /* GraphQL */ `
|
|
5
10
|
id
|
|
6
11
|
code
|
|
@@ -15,6 +20,8 @@ const POSITION_FIELDS = /* GraphQL */ `
|
|
|
15
20
|
settled
|
|
16
21
|
authorized
|
|
17
22
|
refunded
|
|
23
|
+
creditNoted
|
|
24
|
+
owed
|
|
18
25
|
outstanding
|
|
19
26
|
overpaid
|
|
20
27
|
availableToCharge
|
|
@@ -78,6 +85,31 @@ export const UNRECONCILED_REFUNDS_QUERY = /* GraphQL */ `
|
|
|
78
85
|
}
|
|
79
86
|
}
|
|
80
87
|
`;
|
|
88
|
+
export const REFUND_GIFT_CARD_HOLD_QUERY = /* GraphQL */ `
|
|
89
|
+
query RefundGiftCardHold($orderId: ID!) {
|
|
90
|
+
orderRefundPosition(orderId: $orderId) {
|
|
91
|
+
currencyCode
|
|
92
|
+
giftCardHold
|
|
93
|
+
liveGiftCards
|
|
94
|
+
perPayment {
|
|
95
|
+
paymentId
|
|
96
|
+
giftCardHold
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
`;
|
|
101
|
+
export const REFUND_CREDIT_NOTE_REQUIREMENT_QUERY = /* GraphQL */ `
|
|
102
|
+
query RefundCreditNoteRequirement($orderId: ID!) {
|
|
103
|
+
orderRefundPosition(orderId: $orderId) {
|
|
104
|
+
creditNoteRequired {
|
|
105
|
+
invoiceId
|
|
106
|
+
invoiceNumber
|
|
107
|
+
ledger
|
|
108
|
+
refundableOverpayment
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
`;
|
|
81
113
|
export const RECONCILE_REFUND_OUTCOME_MUTATION = /* GraphQL */ `
|
|
82
114
|
mutation ReconcileRefundOutcome($input: ReconcileRefundOutcomeInput!, $idempotencyKey: String) {
|
|
83
115
|
reconcileRefundOutcome(input: $input, idempotencyKey: $idempotencyKey) {
|
|
@@ -90,6 +122,81 @@ export const RECONCILE_REFUND_OUTCOME_MUTATION = /* GraphQL */ `
|
|
|
90
122
|
}
|
|
91
123
|
}
|
|
92
124
|
`;
|
|
125
|
+
const PAYMENT_RECORD_FIELDS = /* GraphQL */ `
|
|
126
|
+
id
|
|
127
|
+
state
|
|
128
|
+
method
|
|
129
|
+
amount
|
|
130
|
+
transactionId
|
|
131
|
+
`;
|
|
132
|
+
// The concrete members are selected for their sentences: the `ErrorResult` interface carries
|
|
133
|
+
// only a generic per-code `message`, and the provider's reason and the refusing gate's live on
|
|
134
|
+
// the concrete type alone.
|
|
135
|
+
export const SETTLE_PAYMENT_MUTATION = /* GraphQL */ `
|
|
136
|
+
mutation SettlePayment($id: ID!) {
|
|
137
|
+
settlePayment(id: $id) {
|
|
138
|
+
__typename
|
|
139
|
+
... on Payment {
|
|
140
|
+
${PAYMENT_RECORD_FIELDS}
|
|
141
|
+
}
|
|
142
|
+
... on SettlePaymentError {
|
|
143
|
+
paymentErrorMessage
|
|
144
|
+
}
|
|
145
|
+
... on PaymentStateTransitionError {
|
|
146
|
+
transitionError
|
|
147
|
+
}
|
|
148
|
+
... on OrderStateTransitionError {
|
|
149
|
+
transitionError
|
|
150
|
+
}
|
|
151
|
+
... on ErrorResult {
|
|
152
|
+
errorCode
|
|
153
|
+
message
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
`;
|
|
158
|
+
export const CANCEL_PAYMENT_MUTATION = /* GraphQL */ `
|
|
159
|
+
mutation CancelPayment($id: ID!) {
|
|
160
|
+
cancelPayment(id: $id) {
|
|
161
|
+
__typename
|
|
162
|
+
... on Payment {
|
|
163
|
+
${PAYMENT_RECORD_FIELDS}
|
|
164
|
+
}
|
|
165
|
+
... on CancelPaymentError {
|
|
166
|
+
paymentErrorMessage
|
|
167
|
+
}
|
|
168
|
+
... on PaymentStateTransitionError {
|
|
169
|
+
transitionError
|
|
170
|
+
}
|
|
171
|
+
... on ErrorResult {
|
|
172
|
+
errorCode
|
|
173
|
+
message
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
`;
|
|
178
|
+
/** The union members that mean "the provider said no", renamed so a caller branches on intent. */
|
|
179
|
+
const DECLINE_CODES = {
|
|
180
|
+
SETTLE_PAYMENT_ERROR: 'PAYMENT_SETTLE_DECLINED',
|
|
181
|
+
CANCEL_PAYMENT_ERROR: 'PAYMENT_CANCEL_DECLINED',
|
|
182
|
+
};
|
|
183
|
+
/**
|
|
184
|
+
* Throw a refusal member as a coded error, carrying the concrete type's sentence (the provider's
|
|
185
|
+
* reason, the gate's reason) rather than Vendure's per-code template.
|
|
186
|
+
*/
|
|
187
|
+
function paymentOrThrow(result) {
|
|
188
|
+
if (!isErrorResult(result)) {
|
|
189
|
+
const { __typename: _typename, ...payment } = result;
|
|
190
|
+
return payment;
|
|
191
|
+
}
|
|
192
|
+
const reason = result.paymentErrorMessage ?? result.transitionError;
|
|
193
|
+
const message = typeof reason === 'string' && reason.trim() !== '' ? reason : result.message;
|
|
194
|
+
const declined = DECLINE_CODES[result.errorCode];
|
|
195
|
+
if (declined) {
|
|
196
|
+
throw new BusinessRuleError({ code: declined, message, status: 422, service: 'vendure' });
|
|
197
|
+
}
|
|
198
|
+
throw errorFromErrorResult({ ...result, message });
|
|
199
|
+
}
|
|
93
200
|
export const REPORT_APP_PAYMENT_MUTATION = /* GraphQL */ `
|
|
94
201
|
mutation ReportAppPayment(
|
|
95
202
|
$paymentId: ID!
|
|
@@ -125,7 +232,10 @@ export function createPaymentsModule(transport) {
|
|
|
125
232
|
return {
|
|
126
233
|
providers: createProvidersModule(transport),
|
|
127
234
|
accountCredit: createAccountCreditModule(transport),
|
|
235
|
+
ar: createArPaymentsModule(transport),
|
|
128
236
|
methods: createPaymentMethodsModule(transport),
|
|
237
|
+
requests: createPaymentRequestsModule(transport),
|
|
238
|
+
paymentLinks: createPaymentLinksModule(transport),
|
|
129
239
|
async record(orderId, input, options) {
|
|
130
240
|
const data = await transport.graphql({
|
|
131
241
|
api: 'admin',
|
|
@@ -140,7 +250,8 @@ export function createPaymentsModule(transport) {
|
|
|
140
250
|
return data.recordOrderPayment;
|
|
141
251
|
},
|
|
142
252
|
async position(orderId, options) {
|
|
143
|
-
|
|
253
|
+
// The credit fields fall away on an engine before them: the position itself still reads.
|
|
254
|
+
const data = await creditNotedAware(transport).graphql({ api: 'admin', query: ORDER_PAYMENT_POSITION_QUERY, variables: { orderId } }, options);
|
|
144
255
|
return data.orderPaymentPosition;
|
|
145
256
|
},
|
|
146
257
|
async refund(input, options) {
|
|
@@ -154,10 +265,28 @@ export function createPaymentsModule(transport) {
|
|
|
154
265
|
}, options);
|
|
155
266
|
return data.refundOrderPayment;
|
|
156
267
|
},
|
|
268
|
+
async settle(paymentId, options) {
|
|
269
|
+
const data = await transport.graphql({ api: 'admin', query: SETTLE_PAYMENT_MUTATION, variables: { id: paymentId } }, options);
|
|
270
|
+
return paymentOrThrow(data.settlePayment);
|
|
271
|
+
},
|
|
272
|
+
async cancel(paymentId, options) {
|
|
273
|
+
const data = await transport.graphql({ api: 'admin', query: CANCEL_PAYMENT_MUTATION, variables: { id: paymentId } }, options);
|
|
274
|
+
return paymentOrThrow(data.cancelPayment);
|
|
275
|
+
},
|
|
157
276
|
async refundPosition(orderId, options) {
|
|
158
277
|
const data = await transport.graphql({ api: 'admin', query: ORDER_REFUND_POSITION_QUERY, variables: { orderId } }, options);
|
|
159
278
|
return data.orderRefundPosition;
|
|
160
279
|
},
|
|
280
|
+
// Its own query rather than fields on `refundPosition`'s: an SDK released ahead of an engine
|
|
281
|
+
// without them must not break that read.
|
|
282
|
+
async refundGiftCardHold(orderId, options) {
|
|
283
|
+
const data = await transport.graphql({ api: 'admin', query: REFUND_GIFT_CARD_HOLD_QUERY, variables: { orderId } }, options);
|
|
284
|
+
return data.orderRefundPosition;
|
|
285
|
+
},
|
|
286
|
+
async refundCreditNoteRequirement(orderId, options) {
|
|
287
|
+
const data = await transport.graphql({ api: 'admin', query: REFUND_CREDIT_NOTE_REQUIREMENT_QUERY, variables: { orderId } }, options);
|
|
288
|
+
return data.orderRefundPosition.creditNoteRequired;
|
|
289
|
+
},
|
|
161
290
|
// Its own query rather than a field on `refundPosition`'s: an SDK released
|
|
162
291
|
// ahead of a server without `unreconciled` must not break that read.
|
|
163
292
|
async unreconciledRefunds(orderId, options) {
|
|
@@ -193,3 +322,4 @@ export function createPaymentsModule(transport) {
|
|
|
193
322
|
},
|
|
194
323
|
};
|
|
195
324
|
}
|
|
325
|
+
export { PAYMENT_REQUEST_CLOSE_REASONS, PAYMENT_REQUEST_DEFAULT_EXPIRY_DAYS, PAYMENT_REQUEST_MAX_EXPIRY_DAYS, PAYMENT_REQUEST_STATUSES, } from './requests.js';
|