@curless/shopify-adapter 0.2.0 → 0.4.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 CHANGED
@@ -47,9 +47,12 @@ await writebackShopifyOrder(shopify, {
47
47
  });
48
48
  ```
49
49
 
50
- No money moves in Shopify the order is marked **paid via an external transaction**
51
- and tagged `agentbank` + `protocol:…` + the agentbank order id, so it's traceable and
52
- never mistaken for a Shopify Payments sale.
50
+ No money moves in Shopify. The order is booked with a **SALE transaction on the
51
+ `agentbank` gateway** (not just `financialStatus: PAID`, which paints the label and
52
+ creates no transaction — such an order can never be refunded) and tagged `agentbank` +
53
+ `protocol:…` + the agentbank order id, so it's traceable and never mistaken for a
54
+ Shopify Payments sale. Pass `unitPriceMinor` + `currency` or there is no total to book
55
+ the transaction with, and the order won't be reversible.
53
56
 
54
57
  **3. Refund** — when agentbank refunds the sale, stop the Shopify order reading as paid:
55
58
 
@@ -62,11 +65,15 @@ await refundShopifyOrder(shopify, {
62
65
  // → { refunded: true, id } | { refunded: false, reason }
63
66
  ```
64
67
 
65
- Like the writeback, this **records** the reversal rather than processing one: Shopify
66
- never held this money, so the refund is created with no `transactions` and the order
67
- goes to REFUNDED without Shopify trying to return funds it never took. Full-order only
68
- agentbank refunds the whole captured amount, and inventing a partial here would let
69
- you record a reversal that doesn't match the money that actually went back.
68
+ It **records** the reversal rather than processing one — the sale was booked on our
69
+ own gateway, so the matching REFUND transaction moves no real money. It does have to
70
+ BE a transaction, though: a refund with none attached is a 0.00 refund and the order
71
+ goes on reading PAID. An order written back before this adapter recorded a sale
72
+ transaction has no parent to refund against and comes back
73
+ `{refunded:false, reason:'…no SALE transaction…'}` — reverse those in the admin once.
74
+
75
+ Full-order only — agentbank refunds the whole captured amount, and inventing a partial
76
+ here would let you record a reversal that doesn't match the money that actually went back.
70
77
 
71
78
  ## Notes
72
79
 
@@ -1 +1 @@
1
- {"version":3,"file":"orders.d.ts","sourceRoot":"","sources":["../src/orders.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EACV,WAAW,EACX,cAAc,EACd,YAAY,EACZ,aAAa,EACb,eAAe,EAChB,MAAM,YAAY,CAAC;AAMpB,eAAO,MAAM,qBAAqB,GAChC,QAAQ,aAAa,EACrB,OAAO,cAAc,EACrB,YAAW,OAAO,KAAa,KAC9B,OAAO,CAAC,eAAe,CA6DzB,CAAC;AAeF,eAAO,MAAM,kBAAkB,GAC7B,QAAQ,aAAa,EACrB,OAAO,WAAW,EAClB,YAAW,OAAO,KAAa,KAC9B,OAAO,CAAC,YAAY,CAkEtB,CAAC"}
1
+ {"version":3,"file":"orders.d.ts","sourceRoot":"","sources":["../src/orders.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EACV,WAAW,EACX,cAAc,EACd,YAAY,EACZ,aAAa,EACb,eAAe,EAChB,MAAM,YAAY,CAAC;AAUpB,eAAO,MAAM,qBAAqB,GAChC,QAAQ,aAAa,EACrB,OAAO,cAAc,EACrB,YAAW,OAAO,KAAa,KAC9B,OAAO,CAAC,eAAe,CA6FzB,CAAC;AAiBF,eAAO,MAAM,kBAAkB,GAC7B,QAAQ,aAAa,EACrB,OAAO,WAAW,EAClB,YAAW,OAAO,KAAa,KAC9B,OAAO,CAAC,YAAY,CA+FtB,CAAC"}
package/dist/orders.js CHANGED
@@ -14,6 +14,10 @@
14
14
  import { exchangeToken, shopifyGraphql } from './client.js';
15
15
  import { toMajorString } from './money.js';
16
16
  const FIND_BY_TAG = 'query($q:String!){ orders(first:1, query:$q){ nodes{ id name } } }';
17
+ // The gateway name on the transactions we write. Shopify shows it verbatim in the
18
+ // order's payment section and in finance reports, so it says where the money
19
+ // actually is rather than implying a Shopify Payments sale.
20
+ const SALE_GATEWAY = 'agentbank';
17
21
  const ORDER_CREATE = 'mutation($o:OrderCreateOrderInput!){ orderCreate(order:$o){ order{ id name } userErrors{ field message } } }';
18
22
  export const writebackShopifyOrder = async (config, input, fetchImpl = fetch) => {
19
23
  const token = await exchangeToken(config, fetchImpl);
@@ -36,7 +40,7 @@ export const writebackShopifyOrder = async (config, input, fetchImpl = fetch) =>
36
40
  const tags = ['agentbank', `protocol:${input.protocol}`];
37
41
  if (idemTag)
38
42
  tags.push(idemTag);
39
- const note = `Paid via agentbank · protocol ${input.protocol}${input.agentbankOrderId ? ` · order ${input.agentbankOrderId}` : ''}`;
43
+ const note = `Paid via agentbank · protocol ${input.protocol}${input.agentbankOrderId ? ` · order ${input.agentbankOrderId}` : ''}${input.buyer?.name ? ` · buyer ${input.buyer.name}` : ''}`;
40
44
  const lineItem = {
41
45
  variantId: `gid://shopify/ProductVariant/${input.variantId}`,
42
46
  quantity: input.quantity,
@@ -45,13 +49,45 @@ export const writebackShopifyOrder = async (config, input, fetchImpl = fetch) =>
45
49
  // records what was really paid rather than Shopify re-deriving it from the
46
50
  // variant's current price. Omitting unitPriceMinor/currency keeps the variant
47
51
  // price (Shopify's default).
52
+ const transactions = [];
48
53
  if (input.unitPriceMinor != null && input.currency) {
49
54
  const currencyCode = input.currency.toUpperCase(); // Shopify's CurrencyCode enum is upper-case
50
55
  lineItem.priceSet = {
51
56
  shopMoney: { amount: toMajorString(input.unitPriceMinor, currencyCode), currencyCode },
52
57
  };
58
+ // A SALE transaction on our own gateway, not just financialStatus:'PAID'.
59
+ //
60
+ // `financialStatus` alone paints the label and creates NO transaction, and an
61
+ // order with no transaction cannot be refunded: Shopify requires a REFUND
62
+ // transaction to carry a parent, so the reversal has nothing to attach to and
63
+ // records a 0.00 refund that leaves the order reading PAID forever. It is also
64
+ // simply more truthful — the sale really was collected on an external gateway,
65
+ // which is what the store's own finance reporting needs to see.
66
+ transactions.push({
67
+ kind: 'SALE',
68
+ status: 'SUCCESS',
69
+ gateway: SALE_GATEWAY,
70
+ amountSet: {
71
+ shopMoney: {
72
+ amount: toMajorString(input.unitPriceMinor * input.quantity, currencyCode),
73
+ currencyCode,
74
+ },
75
+ },
76
+ });
53
77
  }
54
- const data = await shopifyGraphql(config, token, ORDER_CREATE, { o: { lineItems: [lineItem], financialStatus: 'PAID', note, tags } }, fetchImpl);
78
+ const data = await shopifyGraphql(config, token, ORDER_CREATE, {
79
+ o: {
80
+ lineItems: [lineItem],
81
+ financialStatus: 'PAID',
82
+ note,
83
+ tags,
84
+ ...(transactions.length ? { transactions } : {}),
85
+ // Shopify resolves `email` to an existing customer or creates one, so
86
+ // the sale lands under a person instead of being anonymous. Only sent
87
+ // when the caller actually has the buyer's address.
88
+ ...(input.buyer?.email ? { email: input.buyer.email } : {}),
89
+ },
90
+ }, fetchImpl);
55
91
  const errs = data.orderCreate?.userErrors ?? [];
56
92
  if (errs.length)
57
93
  return { created: false, reason: errs.map((e) => e.message).join('; ') };
@@ -61,6 +97,8 @@ export const writebackShopifyOrder = async (config, input, fetchImpl = fetch) =>
61
97
  return { created: true, name: order.name, id: order.id };
62
98
  };
63
99
  const FIND_FOR_REFUND = 'query($q:String!){ orders(first:1, query:$q){ nodes{ id name displayFinancialStatus ' +
100
+ 'totalPriceSet{ shopMoney{ amount currencyCode } } ' +
101
+ 'transactions{ id kind status gateway amountSet{ shopMoney{ amount } } } ' +
64
102
  'lineItems(first:50){ nodes{ id quantity } } } } }';
65
103
  const REFUND_CREATE = 'mutation($i:RefundInput!){ refundCreate(input:$i){ refund{ id } userErrors{ field message } } }';
66
104
  // Mark an agentbank-settled Shopify order as refunded. See OrderRefund for why
@@ -95,12 +133,36 @@ export const refundShopifyOrder = async (config, input, fetchImpl = fetch) => {
95
133
  if (/REFUNDED/i.test(order.displayFinancialStatus)) {
96
134
  return { refunded: false, reason: `already refunded (${order.name})` };
97
135
  }
136
+ // The transaction the refund attaches to. Shopify rejects a REFUND transaction
137
+ // with no `parentId` on any gateway but store-credit/exchange-credit/cash, and
138
+ // a refund with NO transactions at all is a 0.00 refund: it files a refund
139
+ // record and leaves the order reading PAID. So a missing sale transaction is a
140
+ // hard stop, not something to paper over — say so instead of writing a reversal
141
+ // that reverses nothing.
142
+ const sale = order.transactions.find((t) => t.kind?.toUpperCase() === 'SALE' && t.status?.toUpperCase() === 'SUCCESS');
143
+ if (!sale) {
144
+ return {
145
+ refunded: false,
146
+ reason: `Shopify order ${order.name} has no SALE transaction to refund against (written back before the adapter recorded one) — reverse it in the Shopify admin`,
147
+ };
148
+ }
98
149
  const data = await shopifyGraphql(config, token, REFUND_CREATE, {
99
150
  i: {
100
151
  orderId: order.id,
101
152
  note: input.reason ? `Refunded via agentbank · ${input.reason}` : 'Refunded via agentbank',
102
- // NO `transactions`. That is what makes this a record rather than a
103
- // paymentsee OrderRefund.
153
+ // A REFUND transaction against the sale, for the full order total. This
154
+ // moves no real money the gateway is ours, and Shopify never held the
155
+ // funds — but it is what actually flips the order to REFUNDED, which
156
+ // refundLineItems alone does not do.
157
+ transactions: [
158
+ {
159
+ orderId: order.id,
160
+ parentId: sale.id,
161
+ gateway: sale.gateway,
162
+ kind: 'REFUND',
163
+ amount: order.totalPriceSet.shopMoney.amount,
164
+ },
165
+ ],
104
166
  refundLineItems: order.lineItems.nodes.map((li) => ({
105
167
  lineItemId: li.id,
106
168
  quantity: li.quantity,
@@ -1 +1 @@
1
- {"version":3,"file":"orders.js","sourceRoot":"","sources":["../src/orders.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,gFAAgF;AAChF,+EAA+E;AAC/E,gFAAgF;AAChF,+DAA+D;AAC/D,EAAE;AACF,+EAA+E;AAC/E,gFAAgF;AAChF,iFAAiF;AACjF,gFAAgF;AAChF,kFAAkF;AAClF,6EAA6E;AAC7E,mCAAmC;AACnC,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAS3C,MAAM,WAAW,GAAG,oEAAoE,CAAC;AACzF,MAAM,YAAY,GAChB,8GAA8G,CAAC;AAEjH,MAAM,CAAC,MAAM,qBAAqB,GAAG,KAAK,EACxC,MAAqB,EACrB,KAAqB,EACrB,YAA0B,KA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
  agentbankOrderId?: string;
35
35
  unitPriceMinor?: number;
36
36
  currency?: string;
37
+ /**
38
+ * Who bought it, when the protocol supplied one. `email` puts the order under
39
+ * a customer in the Shopify admin (Shopify matches or creates one), which is
40
+ * the difference between "an agent paid" and "Robin bought a holiday".
41
+ *
42
+ * Pass ONLY a buyer the merchant really received. An invented address would
43
+ * attach a real sale to a person who did not make it — and Shopify would then
44
+ * email them about it.
45
+ */
46
+ buyer?: {
47
+ name?: string;
48
+ email?: string;
49
+ };
37
50
  };
38
51
  export type WritebackResult = {
39
52
  created: true;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,WAAW,GAAG;IACxB,oFAAoF;IACpF,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,uFAAuF;IACvF,UAAU,EAAE,MAAM,CAAC;IACnB,4EAA4E;IAC5E,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,sGAAsG;IACtG,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,2FAA2F;IAC3F,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,4FAA4F;IAC5F,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,sCAAsC;IACtC,UAAU,EAAE,MAAM,CAAC;IACnB,6CAA6C;IAC7C,QAAQ,EAAE,MAAM,CAAC;IACjB,+EAA+E;IAC/E,YAAY,EAAE,MAAM,CAAC;IACrB,gGAAgG;IAChG,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAKF,MAAM,MAAM,cAAc,GAAG;IAC3B,0DAA0D;IAC1D,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,8FAA8F;IAC9F,QAAQ,EAAE,MAAM,CAAC;IACjB,2EAA2E;IAC3E,gB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2
  "name": "@curless/shopify-adapter",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "Use a Shopify store as an agentbank catalog source, and record agent-settled sales back as paid Shopify orders. Maps Shopify Admin products → a generic CatalogItem your merchant backend prices from, writes an order back after an agent pays through agentbank, and records the reversal when that sale is refunded. Zero runtime dependencies (uses the platform fetch).",
5
5
  "license": "MIT",
6
6
  "type": "module",