@dime-technology/dime-js-sdk 1.0.0 → 1.3.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/dist/index.cjs CHANGED
@@ -26,6 +26,7 @@ __export(index_exports, {
26
26
  Client: () => Client,
27
27
  Config: () => Config,
28
28
  ConnectionException: () => ConnectionException,
29
+ CoverFeeQuote: () => CoverFeeQuote,
29
30
  CursorPage: () => CursorPage,
30
31
  Customer: () => Customer,
31
32
  DEFAULT_BASE_URL: () => DEFAULT_BASE_URL,
@@ -34,12 +35,20 @@ __export(index_exports, {
34
35
  DepositWithTransactions: () => DepositWithTransactions,
35
36
  DimeException: () => DimeException,
36
37
  FormLink: () => FormLink,
38
+ Invoice: () => Invoice,
39
+ InvoiceCustomer: () => InvoiceCustomer,
40
+ InvoiceEvent: () => InvoiceEvent,
41
+ InvoiceItem: () => InvoiceItem,
42
+ InvoiceLineItem: () => InvoiceLineItem,
43
+ InvoiceLink: () => InvoiceLink,
44
+ InvoicePayment: () => InvoicePayment,
37
45
  Merchant: () => Merchant,
38
46
  MessageResult: () => MessageResult,
39
47
  NotFoundException: () => NotFoundException,
40
48
  PaymentMethod: () => PaymentMethod,
41
49
  PermissionDeniedException: () => PermissionDeniedException,
42
50
  RateLimitException: () => RateLimitException,
51
+ RecurringInvoice: () => RecurringInvoice,
43
52
  RecurringPayment: () => RecurringPayment,
44
53
  RecurringPaymentMethod: () => RecurringPaymentMethod,
45
54
  ServerException: () => ServerException,
@@ -53,7 +62,7 @@ module.exports = __toCommonJS(index_exports);
53
62
 
54
63
  // src/config.ts
55
64
  var DEFAULT_BASE_URL = "https://app.dimepayments.com";
56
- var VERSION = "1.0.0";
65
+ var VERSION = "1.3.0";
57
66
  var Config = class {
58
67
  token;
59
68
  baseUrl;
@@ -222,25 +231,31 @@ var Transport = class {
222
231
  /**
223
232
  * Execute a request and return the decoded JSON body.
224
233
  *
225
- * The Dime API expects request parameters in the JSON body even for GET
226
- * requests; this transport always sends the payload as a JSON body regardless
227
- * of HTTP method, matching the server's expectation.
234
+ * The Dime API reads the same `{ data, filters }` envelope whether it arrives
235
+ * as a JSON body or as nested query parameters. The Fetch standard forbids a
236
+ * body on GET/HEAD (undici throws), so for those methods the envelope is
237
+ * serialised into the query string (`data[sid]=…&filters[status]=…`) and no
238
+ * body is sent; every other method sends the envelope as a JSON body.
228
239
  */
229
240
  async request(method, path, body = {}, query = {}) {
230
241
  let url = `${this.config.baseUri()}${path.replace(/^\//, "")}`;
231
- if (Object.keys(query).length > 0) {
232
- url += "?" + new URLSearchParams(query).toString();
242
+ const bodyless = method.toUpperCase() === "GET" || method.toUpperCase() === "HEAD";
243
+ const params = { ...query };
244
+ if (bodyless) Object.assign(params, flattenParams(body));
245
+ if (Object.keys(params).length > 0) {
246
+ url += "?" + new URLSearchParams(params).toString();
233
247
  }
234
- const hasBody = Object.keys(body).length > 0;
248
+ const sendBody = !bodyless && Object.keys(body).length > 0;
249
+ const headers = {
250
+ Authorization: `Bearer ${this.config.token}`,
251
+ Accept: "application/json",
252
+ "X-Dime-Sdk": `dime-js-sdk/${VERSION}`
253
+ };
254
+ if (sendBody) headers["Content-Type"] = "application/json";
235
255
  const init = {
236
256
  method,
237
- headers: {
238
- Authorization: `Bearer ${this.config.token}`,
239
- Accept: "application/json",
240
- "Content-Type": "application/json",
241
- "X-Dime-Sdk": `dime-js-sdk/${VERSION}`
242
- },
243
- ...hasBody ? { body: JSON.stringify(body) } : {}
257
+ headers,
258
+ ...sendBody ? { body: JSON.stringify(body) } : {}
244
259
  };
245
260
  return this.attempt(url, init, 0);
246
261
  }
@@ -280,6 +295,23 @@ var Transport = class {
280
295
  await this.sleepFn(ms);
281
296
  }
282
297
  };
298
+ function flattenParams(obj, prefix = "") {
299
+ const out = {};
300
+ for (const [key, value] of Object.entries(obj)) {
301
+ if (value === null || value === void 0) continue;
302
+ const name = prefix ? `${prefix}[${key}]` : key;
303
+ if (Array.isArray(value)) {
304
+ value.forEach((item, i) => {
305
+ Object.assign(out, flattenParams({ [i]: item }, name));
306
+ });
307
+ } else if (typeof value === "object") {
308
+ Object.assign(out, flattenParams(value, name));
309
+ } else {
310
+ out[name] = typeof value === "boolean" ? value ? "1" : "0" : String(value);
311
+ }
312
+ }
313
+ return out;
314
+ }
283
315
  function parseRetryAfter(response) {
284
316
  const header = response.headers.get("Retry-After");
285
317
  if (header !== null && /^\d+$/.test(header)) return parseInt(header, 10);
@@ -325,6 +357,11 @@ function arrObjectFrom(data, keys) {
325
357
  }
326
358
  return {};
327
359
  }
360
+ function arrArrayFrom(data, key) {
361
+ const value = data[key];
362
+ if (Array.isArray(value)) return value;
363
+ return [];
364
+ }
328
365
 
329
366
  // src/data-objects/address.ts
330
367
  var Address = class _Address {
@@ -454,9 +491,7 @@ function extractCursor(meta, key) {
454
491
  return typeof v === "string" && v !== "" ? v : void 0;
455
492
  }
456
493
  function pruneNulls(obj) {
457
- return Object.fromEntries(
458
- Object.entries(obj).filter(([, v]) => v !== null && v !== void 0)
459
- );
494
+ return Object.fromEntries(Object.entries(obj).filter(([, v]) => v !== null && v !== void 0));
460
495
  }
461
496
 
462
497
  // src/resources/addresses.ts
@@ -465,19 +500,35 @@ var Addresses = class extends AbstractResource {
465
500
  return this.paginate("GET", "address/list", this.envelope({ sid, uuid }), Address.fromRaw);
466
501
  }
467
502
  async show(sid, uuid, addressId) {
468
- const raw = await this.transport.request("GET", "address/show", this.envelope({ sid, uuid, address_id: addressId }));
503
+ const raw = await this.transport.request(
504
+ "GET",
505
+ "address/show",
506
+ this.envelope({ sid, uuid, address_id: addressId })
507
+ );
469
508
  return Address.fromRaw(raw["data"] ?? {});
470
509
  }
471
510
  async create(sid, uuid, attributes) {
472
- const raw = await this.transport.request("POST", "address/create", this.envelope({ sid, uuid, ...attributes }));
511
+ const raw = await this.transport.request(
512
+ "POST",
513
+ "address/create",
514
+ this.envelope({ sid, uuid, ...attributes })
515
+ );
473
516
  return Address.fromRaw(raw["data"] ?? {});
474
517
  }
475
518
  async update(sid, uuid, addressId, attributes) {
476
- const raw = await this.transport.request("PATCH", "address/update", this.envelope({ sid, uuid, address_id: addressId, ...attributes }));
519
+ const raw = await this.transport.request(
520
+ "PATCH",
521
+ "address/update",
522
+ this.envelope({ sid, uuid, address_id: addressId, ...attributes })
523
+ );
477
524
  return Address.fromRaw(raw["data"] ?? {});
478
525
  }
479
526
  async delete(sid, uuid, addressId) {
480
- const raw = await this.transport.request("POST", "address/delete", this.envelope({ sid, uuid, address_id: addressId }));
527
+ const raw = await this.transport.request(
528
+ "POST",
529
+ "address/delete",
530
+ this.envelope({ sid, uuid, address_id: addressId })
531
+ );
481
532
  return MessageResult.fromRaw(raw["data"] ?? raw);
482
533
  }
483
534
  };
@@ -534,19 +585,35 @@ var Customers = class extends AbstractResource {
534
585
  return this.paginate("GET", "customer/list", this.envelope({ sid }, filters), Customer.fromRaw);
535
586
  }
536
587
  async show(sid, filters) {
537
- const raw = await this.transport.request("GET", "customer/show", this.envelope({ sid }, filters));
588
+ const raw = await this.transport.request(
589
+ "GET",
590
+ "customer/show",
591
+ this.envelope({ sid }, filters)
592
+ );
538
593
  return Customer.fromRaw(raw["data"] ?? {});
539
594
  }
540
595
  async create(sid, attributes) {
541
- const raw = await this.transport.request("POST", "customer/create", this.envelope({ sid, ...attributes }));
596
+ const raw = await this.transport.request(
597
+ "POST",
598
+ "customer/create",
599
+ this.envelope({ sid, ...attributes })
600
+ );
542
601
  return Customer.fromRaw(raw["data"] ?? {});
543
602
  }
544
603
  async update(sid, filters, attributes) {
545
- const raw = await this.transport.request("PATCH", "customer/update", this.envelope({ sid, ...attributes }, filters));
604
+ const raw = await this.transport.request(
605
+ "PATCH",
606
+ "customer/update",
607
+ this.envelope({ sid, ...attributes }, filters)
608
+ );
546
609
  return Customer.fromRaw(raw["data"] ?? {});
547
610
  }
548
611
  async delete(sid, filters) {
549
- const raw = await this.transport.request("POST", "customer/delete", this.envelope({ sid }, filters));
612
+ const raw = await this.transport.request(
613
+ "POST",
614
+ "customer/delete",
615
+ this.envelope({ sid }, filters)
616
+ );
550
617
  return MessageResult.fromRaw(raw["data"] ?? raw);
551
618
  }
552
619
  };
@@ -755,15 +822,465 @@ var Deposits = class extends AbstractResource {
755
822
  return this.paginate("GET", "deposit/list", this.envelope({ sid }, filters), Deposit.fromRaw);
756
823
  }
757
824
  async listWithTransactions(sid, filters) {
758
- const raw = await this.transport.request("GET", "deposit/list-with-trans", this.envelope({ sid }, filters));
825
+ const raw = await this.transport.request(
826
+ "GET",
827
+ "deposit/list-with-trans",
828
+ this.envelope({ sid }, filters)
829
+ );
759
830
  return DepositGroup.fromRaw(raw["data"] ?? {});
760
831
  }
761
832
  async show(sid, identifier) {
762
- const raw = await this.transport.request("GET", "deposit/show", this.envelope({ sid, ...identifier }));
833
+ const raw = await this.transport.request(
834
+ "GET",
835
+ "deposit/show",
836
+ this.envelope({ sid, ...identifier })
837
+ );
763
838
  return DepositWithTransactions.fromRaw(raw["data"] ?? {});
764
839
  }
765
840
  };
766
841
 
842
+ // src/data-objects/cover-fee-quote.ts
843
+ var CoverFeeQuote = class _CoverFeeQuote {
844
+ constructor(basis, base, ccFee, ccTotal, achFee, achTotal) {
845
+ this.basis = basis;
846
+ this.base = base;
847
+ this.ccFee = ccFee;
848
+ this.ccTotal = ccTotal;
849
+ this.achFee = achFee;
850
+ this.achTotal = achTotal;
851
+ }
852
+ basis;
853
+ base;
854
+ ccFee;
855
+ ccTotal;
856
+ achFee;
857
+ achTotal;
858
+ static fromRaw(data) {
859
+ const cc = arrObjectFrom(data, ["cc"]);
860
+ const ach = arrObjectFrom(data, ["ach"]);
861
+ return new _CoverFeeQuote(
862
+ arrString(data, "basis"),
863
+ arrString(data, "base"),
864
+ arrString(cc, "fee"),
865
+ arrString(cc, "total"),
866
+ arrString(ach, "fee"),
867
+ arrString(ach, "total")
868
+ );
869
+ }
870
+ };
871
+
872
+ // src/data-objects/invoice-customer.ts
873
+ var InvoiceCustomer = class _InvoiceCustomer {
874
+ constructor(id, name, email) {
875
+ this.id = id;
876
+ this.name = name;
877
+ this.email = email;
878
+ }
879
+ id;
880
+ name;
881
+ email;
882
+ static fromRaw(data) {
883
+ return new _InvoiceCustomer(
884
+ arrInt(data, "id"),
885
+ arrString(data, "name"),
886
+ arrString(data, "email")
887
+ );
888
+ }
889
+ };
890
+
891
+ // src/data-objects/invoice-event.ts
892
+ var InvoiceEvent = class _InvoiceEvent {
893
+ constructor(type, label, description, createdAt) {
894
+ this.type = type;
895
+ this.label = label;
896
+ this.description = description;
897
+ this.createdAt = createdAt;
898
+ }
899
+ type;
900
+ label;
901
+ description;
902
+ createdAt;
903
+ static fromRaw(data) {
904
+ return new _InvoiceEvent(
905
+ arrString(data, "type"),
906
+ arrString(data, "label"),
907
+ arrString(data, "description"),
908
+ arrString(data, "created_at")
909
+ );
910
+ }
911
+ };
912
+
913
+ // src/data-objects/invoice-line-item.ts
914
+ var InvoiceLineItem = class _InvoiceLineItem {
915
+ constructor(id, itemId, name, description, quantity, unitPrice, amount) {
916
+ this.id = id;
917
+ this.itemId = itemId;
918
+ this.name = name;
919
+ this.description = description;
920
+ this.quantity = quantity;
921
+ this.unitPrice = unitPrice;
922
+ this.amount = amount;
923
+ }
924
+ id;
925
+ itemId;
926
+ name;
927
+ description;
928
+ quantity;
929
+ unitPrice;
930
+ amount;
931
+ static fromRaw(data) {
932
+ return new _InvoiceLineItem(
933
+ arrInt(data, "id"),
934
+ arrInt(data, "item_id"),
935
+ arrString(data, "name"),
936
+ arrString(data, "description"),
937
+ arrString(data, "quantity"),
938
+ arrString(data, "unit_price"),
939
+ arrString(data, "amount")
940
+ );
941
+ }
942
+ };
943
+
944
+ // src/data-objects/invoice-payment.ts
945
+ var InvoicePayment = class _InvoicePayment {
946
+ constructor(amount, paidAt, method, transactionId, coverFee) {
947
+ this.amount = amount;
948
+ this.paidAt = paidAt;
949
+ this.method = method;
950
+ this.transactionId = transactionId;
951
+ this.coverFee = coverFee;
952
+ }
953
+ amount;
954
+ paidAt;
955
+ method;
956
+ transactionId;
957
+ coverFee;
958
+ static fromRaw(data) {
959
+ return new _InvoicePayment(
960
+ arrString(data, "amount"),
961
+ arrString(data, "paid_at"),
962
+ arrString(data, "method"),
963
+ arrString(data, "transaction_id"),
964
+ arrString(data, "cover_fee")
965
+ );
966
+ }
967
+ };
968
+
969
+ // src/data-objects/invoice.ts
970
+ var Invoice = class _Invoice {
971
+ constructor(id, invoiceNumber, status, token, paymentTerms, issueDate, dueDate, isOverdue = false, subtotal, total, amountPaid, balance, allowPartialPayment = false, thankYouNote, customerName, customerEmail, publicUrl, customer = new InvoiceCustomer(), items = [], payments = [], events = [], coverFeeRequired = false, coverFeeQuote) {
972
+ this.id = id;
973
+ this.invoiceNumber = invoiceNumber;
974
+ this.status = status;
975
+ this.token = token;
976
+ this.paymentTerms = paymentTerms;
977
+ this.issueDate = issueDate;
978
+ this.dueDate = dueDate;
979
+ this.isOverdue = isOverdue;
980
+ this.subtotal = subtotal;
981
+ this.total = total;
982
+ this.amountPaid = amountPaid;
983
+ this.balance = balance;
984
+ this.allowPartialPayment = allowPartialPayment;
985
+ this.thankYouNote = thankYouNote;
986
+ this.customerName = customerName;
987
+ this.customerEmail = customerEmail;
988
+ this.publicUrl = publicUrl;
989
+ this.customer = customer;
990
+ this.items = items;
991
+ this.payments = payments;
992
+ this.events = events;
993
+ this.coverFeeRequired = coverFeeRequired;
994
+ this.coverFeeQuote = coverFeeQuote;
995
+ }
996
+ id;
997
+ invoiceNumber;
998
+ status;
999
+ token;
1000
+ paymentTerms;
1001
+ issueDate;
1002
+ dueDate;
1003
+ isOverdue;
1004
+ subtotal;
1005
+ total;
1006
+ amountPaid;
1007
+ balance;
1008
+ allowPartialPayment;
1009
+ thankYouNote;
1010
+ customerName;
1011
+ customerEmail;
1012
+ publicUrl;
1013
+ customer;
1014
+ items;
1015
+ payments;
1016
+ events;
1017
+ coverFeeRequired;
1018
+ coverFeeQuote;
1019
+ static fromRaw(data) {
1020
+ return new _Invoice(
1021
+ arrInt(data, "id"),
1022
+ arrString(data, "invoice_number"),
1023
+ arrString(data, "status"),
1024
+ arrString(data, "token"),
1025
+ arrString(data, "payment_terms"),
1026
+ arrString(data, "issue_date"),
1027
+ arrString(data, "due_date"),
1028
+ arrBool(data, "is_overdue"),
1029
+ arrString(data, "subtotal"),
1030
+ arrString(data, "total"),
1031
+ arrString(data, "amount_paid"),
1032
+ arrString(data, "balance"),
1033
+ arrBool(data, "allow_partial_payment"),
1034
+ arrString(data, "thank_you_note"),
1035
+ arrString(data, "customer_name"),
1036
+ arrString(data, "customer_email"),
1037
+ arrString(data, "public_url"),
1038
+ InvoiceCustomer.fromRaw(arrObjectFrom(data, ["customer"])),
1039
+ arrArrayFrom(data, "items").map(InvoiceLineItem.fromRaw),
1040
+ arrArrayFrom(data, "payments").map(InvoicePayment.fromRaw),
1041
+ arrArrayFrom(data, "events").map(InvoiceEvent.fromRaw),
1042
+ arrBool(data, "cover_fee_required"),
1043
+ data["cover_fee_quote"] && typeof data["cover_fee_quote"] === "object" ? CoverFeeQuote.fromRaw(data["cover_fee_quote"]) : void 0
1044
+ );
1045
+ }
1046
+ };
1047
+
1048
+ // src/data-objects/invoice-item.ts
1049
+ var InvoiceItem = class _InvoiceItem {
1050
+ constructor(id, name, description, price, taxDeductible = false) {
1051
+ this.id = id;
1052
+ this.name = name;
1053
+ this.description = description;
1054
+ this.price = price;
1055
+ this.taxDeductible = taxDeductible;
1056
+ }
1057
+ id;
1058
+ name;
1059
+ description;
1060
+ price;
1061
+ taxDeductible;
1062
+ static fromRaw(data) {
1063
+ return new _InvoiceItem(
1064
+ arrInt(data, "id"),
1065
+ arrString(data, "name"),
1066
+ arrString(data, "description"),
1067
+ arrString(data, "price"),
1068
+ arrBool(data, "tax_deductible")
1069
+ );
1070
+ }
1071
+ };
1072
+
1073
+ // src/data-objects/invoice-link.ts
1074
+ var InvoiceLink = class _InvoiceLink {
1075
+ constructor(publicUrl, token) {
1076
+ this.publicUrl = publicUrl;
1077
+ this.token = token;
1078
+ }
1079
+ publicUrl;
1080
+ token;
1081
+ static fromRaw(data) {
1082
+ return new _InvoiceLink(arrString(data, "public_url"), arrString(data, "token"));
1083
+ }
1084
+ };
1085
+
1086
+ // src/resources/invoices.ts
1087
+ var Invoices = class extends AbstractResource {
1088
+ /**
1089
+ * List invoices for a merchant.
1090
+ *
1091
+ * @param filters `status` — draft | sent | paid | partial | void | overdue
1092
+ */
1093
+ async list(sid, filters = {}) {
1094
+ return this.paginate("GET", "invoices", this.envelope({ sid }, filters), Invoice.fromRaw);
1095
+ }
1096
+ async show(sid, invoiceId) {
1097
+ const raw = await this.transport.request(
1098
+ "GET",
1099
+ "invoice",
1100
+ this.envelope({ sid, invoice_id: invoiceId })
1101
+ );
1102
+ return Invoice.fromRaw(raw["data"] ?? {});
1103
+ }
1104
+ /**
1105
+ * Create a draft invoice with its line items. Every line must reference a
1106
+ * Merchant `item_id`; the line name and unit price are snapshotted.
1107
+ *
1108
+ * @param attributes
1109
+ * `customer_uuid` (or `customer_id`), `customer_name`, `customer_email`,
1110
+ * `payment_terms` (`due_on_receipt` | `net_15` | `net_30` | `net_60`) and
1111
+ * `lines` are required. `lines[]` takes `item_id`, `name`, `quantity`,
1112
+ * `unit_price` and optional `description`. Optional: `invoice_number`,
1113
+ * `issue_date` (Y-m-d, defaults to today — `due_date` is derived from
1114
+ * `payment_terms`), `thank_you_note`, `allow_partial_payment`,
1115
+ * `cover_fee_required`, `reminder_settings`.
1116
+ *
1117
+ * Set `cover_fee_required` to make the customer pay the processing fee. The
1118
+ * fee is added on top of the invoice at payment time rather than becoming a
1119
+ * line item, so `total` stays the amount owed to the merchant — read
1120
+ * `invoice.coverFeeQuote` for what the customer will actually be charged.
1121
+ * Omitting the field inherits the merchant's invoice setting.
1122
+ */
1123
+ async create(sid, attributes) {
1124
+ const raw = await this.transport.request(
1125
+ "POST",
1126
+ "invoice/create",
1127
+ this.envelope({ sid, ...attributes })
1128
+ );
1129
+ return Invoice.fromRaw(raw["data"] ?? {});
1130
+ }
1131
+ /**
1132
+ * Update a draft invoice. Only drafts can be edited, and passing `lines`
1133
+ * replaces the existing line items.
1134
+ *
1135
+ * @param attributes same shape as {@link Invoices.create}
1136
+ */
1137
+ async update(sid, invoiceId, attributes) {
1138
+ const raw = await this.transport.request(
1139
+ "PATCH",
1140
+ "invoice/update",
1141
+ this.envelope({ sid, invoice_id: invoiceId, ...attributes })
1142
+ );
1143
+ return Invoice.fromRaw(raw["data"] ?? {});
1144
+ }
1145
+ async delete(sid, invoiceId) {
1146
+ const raw = await this.transport.request(
1147
+ "POST",
1148
+ "invoice/delete",
1149
+ this.envelope({ sid, invoice_id: invoiceId })
1150
+ );
1151
+ return MessageResult.fromRaw(raw["data"] ?? raw);
1152
+ }
1153
+ /** Email the invoice to the customer and advance it to Sent. */
1154
+ async send(sid, invoiceId) {
1155
+ const raw = await this.transport.request(
1156
+ "POST",
1157
+ "invoice/send",
1158
+ this.envelope({ sid, invoice_id: invoiceId })
1159
+ );
1160
+ return Invoice.fromRaw(raw["data"] ?? {});
1161
+ }
1162
+ /** Activate a draft invoice for payment without emailing it. */
1163
+ async markSent(sid, invoiceId) {
1164
+ const raw = await this.transport.request(
1165
+ "POST",
1166
+ "invoice/mark-sent",
1167
+ this.envelope({ sid, invoice_id: invoiceId })
1168
+ );
1169
+ return Invoice.fromRaw(raw["data"] ?? {});
1170
+ }
1171
+ async void(sid, invoiceId) {
1172
+ const raw = await this.transport.request(
1173
+ "PATCH",
1174
+ "invoice/void",
1175
+ this.envelope({ sid, invoice_id: invoiceId })
1176
+ );
1177
+ return Invoice.fromRaw(raw["data"] ?? {});
1178
+ }
1179
+ /** Clone any invoice into a new draft with a freshly allocated number. */
1180
+ async duplicate(sid, invoiceId) {
1181
+ const raw = await this.transport.request(
1182
+ "POST",
1183
+ "invoice/duplicate",
1184
+ this.envelope({ sid, invoice_id: invoiceId })
1185
+ );
1186
+ return Invoice.fromRaw(raw["data"] ?? {});
1187
+ }
1188
+ /**
1189
+ * Record a merchant-initiated (MOTO) card or ACH payment against an open
1190
+ * invoice.
1191
+ *
1192
+ * @param attributes
1193
+ * `payment_type` is required and is `cc` or `ach`. For a card, pass a stored
1194
+ * `token` or raw `cardholder_name` / `card_number` / `expiration_date` (m/Y)
1195
+ * plus optional `cvv`; for ACH, pass `routing_number` / `account_number` /
1196
+ * `account_type` (Checking | Savings) / `account_name`. Omit `amount` to pay
1197
+ * the full balance — partial amounts require the invoice to allow them.
1198
+ * Optional: `memo`, `billing_address`.
1199
+ *
1200
+ * On a cover-fee invoice the processing fee for `payment_type` is charged on
1201
+ * top of `amount`, so the card or bank account is debited more than the
1202
+ * invoice is credited. The fee lands as `coverFee` on the matching entry in
1203
+ * `invoice.payments`. Card and ACH rates differ, so the same `amount` settles
1204
+ * differently per `payment_type`.
1205
+ */
1206
+ async pay(sid, invoiceId, attributes) {
1207
+ const raw = await this.transport.request(
1208
+ "POST",
1209
+ "invoice/pay",
1210
+ this.envelope({ sid, invoice_id: invoiceId, ...attributes })
1211
+ );
1212
+ return Invoice.fromRaw(raw["data"] ?? {});
1213
+ }
1214
+ /** Get the public pay link (and token) for an invoice. */
1215
+ async getLink(sid, invoiceId) {
1216
+ const raw = await this.transport.request(
1217
+ "GET",
1218
+ "invoice/link",
1219
+ this.envelope({ sid, invoice_id: invoiceId })
1220
+ );
1221
+ return InvoiceLink.fromRaw(raw["data"] ?? {});
1222
+ }
1223
+ /**
1224
+ * Append a single line item to a draft invoice.
1225
+ *
1226
+ * @param attributes `item_id`, `name`, `quantity` and `unit_price` are
1227
+ * required; `description` is optional.
1228
+ */
1229
+ async addLineItem(sid, invoiceId, attributes) {
1230
+ const raw = await this.transport.request(
1231
+ "POST",
1232
+ "invoice/line-item/add",
1233
+ this.envelope({ sid, invoice_id: invoiceId, ...attributes })
1234
+ );
1235
+ return Invoice.fromRaw(raw["data"] ?? {});
1236
+ }
1237
+ /**
1238
+ * Update a single line item on a draft invoice.
1239
+ *
1240
+ * @param attributes any of `item_id`, `name`, `description`, `quantity`,
1241
+ * `unit_price`
1242
+ */
1243
+ async updateLineItem(sid, invoiceId, lineItemId, attributes) {
1244
+ const raw = await this.transport.request(
1245
+ "PATCH",
1246
+ "invoice/line-item/update",
1247
+ this.envelope({ sid, invoice_id: invoiceId, line_item_id: lineItemId, ...attributes })
1248
+ );
1249
+ return Invoice.fromRaw(raw["data"] ?? {});
1250
+ }
1251
+ /** Remove a single line item from a draft invoice. */
1252
+ async deleteLineItem(sid, invoiceId, lineItemId) {
1253
+ const raw = await this.transport.request(
1254
+ "POST",
1255
+ "invoice/line-item/delete",
1256
+ this.envelope({ sid, invoice_id: invoiceId, line_item_id: lineItemId })
1257
+ );
1258
+ return Invoice.fromRaw(raw["data"] ?? {});
1259
+ }
1260
+ /** List the Merchant's items (funds/designations) available as invoice line items. */
1261
+ async listItems(sid) {
1262
+ const raw = await this.transport.request("GET", "invoice/items", this.envelope({ sid }));
1263
+ const items = Array.isArray(raw["data"]) ? raw["data"] : [];
1264
+ return items.map(InvoiceItem.fromRaw);
1265
+ }
1266
+ /**
1267
+ * Create an invoicing-only item (fund/designation) for the Merchant. The item
1268
+ * is hidden from public giving pages and can be referenced as a line's
1269
+ * `item_id`.
1270
+ *
1271
+ * @param attributes `name` is required; `description`, `price` and
1272
+ * `tax_deductible` are optional.
1273
+ */
1274
+ async createItem(sid, attributes) {
1275
+ const raw = await this.transport.request(
1276
+ "POST",
1277
+ "invoice/item/create",
1278
+ this.envelope({ sid, ...attributes })
1279
+ );
1280
+ return InvoiceItem.fromRaw(raw["data"] ?? {});
1281
+ }
1282
+ };
1283
+
767
1284
  // src/data-objects/form-link.ts
768
1285
  var FormLink = class _FormLink {
769
1286
  constructor(link) {
@@ -862,11 +1379,19 @@ var Merchants = class extends AbstractResource {
862
1379
  return Merchant.fromRaw(raw["data"] ?? {});
863
1380
  }
864
1381
  async update(sid, attributes) {
865
- const raw = await this.transport.request("PATCH", "merchant/update", this.envelope({ sid, ...attributes }));
1382
+ const raw = await this.transport.request(
1383
+ "PATCH",
1384
+ "merchant/update",
1385
+ this.envelope({ sid, ...attributes })
1386
+ );
866
1387
  return Merchant.fromRaw(raw["data"] ?? {});
867
1388
  }
868
1389
  async getFormLink(sid) {
869
- const raw = await this.transport.request("GET", "merchant/get-form-link", this.envelope({ sid }));
1390
+ const raw = await this.transport.request(
1391
+ "GET",
1392
+ "merchant/get-form-link",
1393
+ this.envelope({ sid })
1394
+ );
870
1395
  return FormLink.fromRaw(raw["data"] ?? {});
871
1396
  }
872
1397
  };
@@ -959,26 +1484,159 @@ var PaymentMethod = class _PaymentMethod {
959
1484
  // src/resources/payment-methods.ts
960
1485
  var PaymentMethods = class extends AbstractResource {
961
1486
  async list(sid, filters) {
962
- return this.paginate("GET", "payment-method/list", this.envelope({ sid }, filters), PaymentMethod.fromRaw);
1487
+ return this.paginate(
1488
+ "GET",
1489
+ "payment-method/list",
1490
+ this.envelope({ sid }, filters),
1491
+ PaymentMethod.fromRaw
1492
+ );
963
1493
  }
964
1494
  async show(sid, paymentMethodId, filters) {
965
- const raw = await this.transport.request("GET", "payment-method/show", this.envelope({ sid, payment_method_id: paymentMethodId }, filters));
1495
+ const raw = await this.transport.request(
1496
+ "GET",
1497
+ "payment-method/show",
1498
+ this.envelope({ sid, payment_method_id: paymentMethodId }, filters)
1499
+ );
966
1500
  return PaymentMethod.fromRaw(raw["data"] ?? {});
967
1501
  }
968
1502
  async create(sid, attributes) {
969
- const raw = await this.transport.request("POST", "payment-method/create", this.envelope({ sid, ...attributes }));
1503
+ const raw = await this.transport.request(
1504
+ "POST",
1505
+ "payment-method/create",
1506
+ this.envelope({ sid, ...attributes })
1507
+ );
970
1508
  return PaymentMethod.fromRaw(raw["data"] ?? {});
971
1509
  }
972
1510
  async update(sid, attributes) {
973
- const raw = await this.transport.request("PATCH", "payment-method/update", this.envelope({ sid, ...attributes }));
1511
+ const raw = await this.transport.request(
1512
+ "PATCH",
1513
+ "payment-method/update",
1514
+ this.envelope({ sid, ...attributes })
1515
+ );
974
1516
  return PaymentMethod.fromRaw(raw["data"] ?? {});
975
1517
  }
976
1518
  async delete(sid, paymentMethodId, uuid) {
977
- const raw = await this.transport.request("POST", "payment-method/delete", this.envelope({ sid, payment_method_id: paymentMethodId, uuid }));
1519
+ const raw = await this.transport.request(
1520
+ "POST",
1521
+ "payment-method/delete",
1522
+ this.envelope({ sid, payment_method_id: paymentMethodId, uuid })
1523
+ );
978
1524
  return MessageResult.fromRaw(raw["data"] ?? raw);
979
1525
  }
980
1526
  };
981
1527
 
1528
+ // src/data-objects/recurring-invoice.ts
1529
+ var RecurringInvoice = class _RecurringInvoice {
1530
+ constructor(id, status, recurrenceSchedule, paymentTerms, startDate, endDate, nextRunDate, lastRunDate, customerName, thankYouNote, customer = new InvoiceCustomer(), items = [], upcomingRunDates = [], invoices = [], coverFeeRequired = false) {
1531
+ this.id = id;
1532
+ this.status = status;
1533
+ this.recurrenceSchedule = recurrenceSchedule;
1534
+ this.paymentTerms = paymentTerms;
1535
+ this.startDate = startDate;
1536
+ this.endDate = endDate;
1537
+ this.nextRunDate = nextRunDate;
1538
+ this.lastRunDate = lastRunDate;
1539
+ this.customerName = customerName;
1540
+ this.thankYouNote = thankYouNote;
1541
+ this.customer = customer;
1542
+ this.items = items;
1543
+ this.upcomingRunDates = upcomingRunDates;
1544
+ this.invoices = invoices;
1545
+ this.coverFeeRequired = coverFeeRequired;
1546
+ }
1547
+ id;
1548
+ status;
1549
+ recurrenceSchedule;
1550
+ paymentTerms;
1551
+ startDate;
1552
+ endDate;
1553
+ nextRunDate;
1554
+ lastRunDate;
1555
+ customerName;
1556
+ thankYouNote;
1557
+ customer;
1558
+ items;
1559
+ upcomingRunDates;
1560
+ invoices;
1561
+ coverFeeRequired;
1562
+ static fromRaw(data) {
1563
+ const runDates = data["upcoming_run_dates"];
1564
+ return new _RecurringInvoice(
1565
+ arrInt(data, "id"),
1566
+ arrString(data, "status"),
1567
+ arrString(data, "recurrence_schedule"),
1568
+ arrString(data, "payment_terms"),
1569
+ arrString(data, "start_date"),
1570
+ arrString(data, "end_date"),
1571
+ arrString(data, "next_run_date"),
1572
+ arrString(data, "last_run_date"),
1573
+ arrString(data, "customer_name"),
1574
+ arrString(data, "thank_you_note"),
1575
+ InvoiceCustomer.fromRaw(arrObjectFrom(data, ["customer"])),
1576
+ arrArrayFrom(data, "items").map(InvoiceLineItem.fromRaw),
1577
+ Array.isArray(runDates) ? runDates.map((d) => String(d)) : [],
1578
+ arrArrayFrom(data, "invoices").map(Invoice.fromRaw),
1579
+ arrBool(data, "cover_fee_required")
1580
+ );
1581
+ }
1582
+ };
1583
+
1584
+ // src/resources/recurring-invoices.ts
1585
+ var RecurringInvoices = class extends AbstractResource {
1586
+ /**
1587
+ * List recurring-invoice templates.
1588
+ *
1589
+ * @param filters `status` — Active | Paused | Cancelled | Completed
1590
+ */
1591
+ async list(sid, filters = {}) {
1592
+ return this.paginate(
1593
+ "GET",
1594
+ "recurring-invoices",
1595
+ this.envelope({ sid }, filters),
1596
+ RecurringInvoice.fromRaw
1597
+ );
1598
+ }
1599
+ async show(sid, recurringInvoiceId) {
1600
+ const raw = await this.transport.request(
1601
+ "GET",
1602
+ "recurring-invoice",
1603
+ this.envelope({ sid, recurring_invoice_id: recurringInvoiceId })
1604
+ );
1605
+ return RecurringInvoice.fromRaw(raw["data"] ?? {});
1606
+ }
1607
+ /**
1608
+ * Create a recurring-invoice template. When `recurring_start_date` is today the
1609
+ * first invoice is generated and sent immediately.
1610
+ *
1611
+ * @param attributes
1612
+ * `customer_uuid` (or `customer_id`), `payment_terms` (`due_on_receipt` |
1613
+ * `net_15` | `net_30` | `net_60`), `recurring_frequency` (`Weekly` |
1614
+ * `Biweekly` | `FirstFifteenth` | `Monthly` | `Yearly`),
1615
+ * `recurring_start_date` (Y-m-d) and `lines` are required. Optional:
1616
+ * `recurring_end_date` (Y-m-d, on or after the start date),
1617
+ * `thank_you_note`.
1618
+ *
1619
+ * `cover_fee_required` makes the customer cover the processing fee on every
1620
+ * invoice this template generates.
1621
+ */
1622
+ async create(sid, attributes) {
1623
+ const raw = await this.transport.request(
1624
+ "POST",
1625
+ "recurring-invoice/create",
1626
+ this.envelope({ sid, ...attributes })
1627
+ );
1628
+ return RecurringInvoice.fromRaw(raw["data"] ?? {});
1629
+ }
1630
+ async cancel(sid, recurringInvoiceId) {
1631
+ const raw = await this.transport.request(
1632
+ "POST",
1633
+ "recurring-invoice/cancel",
1634
+ this.envelope({ sid, recurring_invoice_id: recurringInvoiceId })
1635
+ );
1636
+ return RecurringInvoice.fromRaw(raw["data"] ?? {});
1637
+ }
1638
+ };
1639
+
982
1640
  // src/data-objects/recurring-payment-method.ts
983
1641
  var RecurringPaymentMethod = class _RecurringPaymentMethod {
984
1642
  constructor(id, type, lastFour, expiration, zip, nameOnCard, bankAccountName, routingNumber, accountNumber, ownershipType, accountType, bankName) {
@@ -1089,34 +1747,71 @@ var RecurringPayment = class _RecurringPayment {
1089
1747
  // src/resources/recurring-payments.ts
1090
1748
  var RecurringPayments = class extends AbstractResource {
1091
1749
  async list(sid, filters = {}) {
1092
- return this.paginate("GET", "recurring-payment/list", this.envelope({ sid }, filters), RecurringPayment.fromRaw);
1750
+ return this.paginate(
1751
+ "GET",
1752
+ "recurring-payment/list",
1753
+ this.envelope({ sid }, filters),
1754
+ RecurringPayment.fromRaw
1755
+ );
1093
1756
  }
1094
1757
  async show(sid, recurringPaymentId) {
1095
- const raw = await this.transport.request("GET", "recurring-payment/show", this.envelope({ sid, recurring_payment_id: recurringPaymentId }));
1758
+ const raw = await this.transport.request(
1759
+ "GET",
1760
+ "recurring-payment/show",
1761
+ this.envelope({ sid, recurring_payment_id: recurringPaymentId })
1762
+ );
1096
1763
  return RecurringPayment.fromRaw(raw["data"] ?? {});
1097
1764
  }
1098
1765
  async create(sid, attributes) {
1099
- const raw = await this.transport.request("POST", "recurring-payment/create", this.envelope({ sid, ...attributes }));
1766
+ const raw = await this.transport.request(
1767
+ "POST",
1768
+ "recurring-payment/create",
1769
+ this.envelope({ sid, ...attributes })
1770
+ );
1100
1771
  return RecurringPayment.fromRaw(raw["data"] ?? {});
1101
1772
  }
1102
1773
  async edit(sid, recurringPaymentId, attributes) {
1103
- const raw = await this.transport.request("PATCH", "recurring-payment/edit", this.envelope({ sid, recurring_payment_id: recurringPaymentId, ...attributes }));
1774
+ const raw = await this.transport.request(
1775
+ "PATCH",
1776
+ "recurring-payment/edit",
1777
+ this.envelope({ sid, recurring_payment_id: recurringPaymentId, ...attributes })
1778
+ );
1104
1779
  return RecurringPayment.fromRaw(raw["data"] ?? {});
1105
1780
  }
1106
1781
  async pause(sid, recurringPaymentId, pauseUntilDate) {
1107
- const raw = await this.transport.request("PATCH", "recurring-payment/pause", this.envelope({ sid, recurring_payment_id: recurringPaymentId, pause_until_date: pauseUntilDate }));
1782
+ const raw = await this.transport.request(
1783
+ "PATCH",
1784
+ "recurring-payment/pause",
1785
+ this.envelope({
1786
+ sid,
1787
+ recurring_payment_id: recurringPaymentId,
1788
+ pause_until_date: pauseUntilDate
1789
+ })
1790
+ );
1108
1791
  return RecurringPayment.fromRaw(raw["data"] ?? {});
1109
1792
  }
1110
1793
  async cancel(sid, recurringPaymentId) {
1111
- const raw = await this.transport.request("PATCH", "recurring-payment/cancel", this.envelope({ sid, recurring_payment_id: recurringPaymentId }));
1794
+ const raw = await this.transport.request(
1795
+ "PATCH",
1796
+ "recurring-payment/cancel",
1797
+ this.envelope({ sid, recurring_payment_id: recurringPaymentId })
1798
+ );
1112
1799
  return RecurringPayment.fromRaw(raw["data"] ?? {});
1113
1800
  }
1114
1801
  async activate(sid, recurringPaymentId) {
1115
- const raw = await this.transport.request("PATCH", "recurring-payment/activate", this.envelope({ sid, recurring_payment_id: recurringPaymentId }));
1802
+ const raw = await this.transport.request(
1803
+ "PATCH",
1804
+ "recurring-payment/activate",
1805
+ this.envelope({ sid, recurring_payment_id: recurringPaymentId })
1806
+ );
1116
1807
  return RecurringPayment.fromRaw(raw["data"] ?? {});
1117
1808
  }
1118
1809
  async delete(sid, recurringPaymentId) {
1119
- const raw = await this.transport.request("POST", "recurring-payment/delete", this.envelope({ sid, recurring_payment_id: recurringPaymentId }));
1810
+ const raw = await this.transport.request(
1811
+ "POST",
1812
+ "recurring-payment/delete",
1813
+ this.envelope({ sid, recurring_payment_id: recurringPaymentId })
1814
+ );
1120
1815
  return MessageResult.fromRaw(raw["data"] ?? raw);
1121
1816
  }
1122
1817
  };
@@ -1135,35 +1830,68 @@ var TokenizeResult = class _TokenizeResult {
1135
1830
  // src/resources/transactions.ts
1136
1831
  var Transactions = class extends AbstractResource {
1137
1832
  async list(sid, filters = {}) {
1138
- return this.paginate("GET", "transactions", this.envelope({ sid }, filters), Transaction.fromRaw);
1833
+ return this.paginate(
1834
+ "GET",
1835
+ "transactions",
1836
+ this.envelope({ sid }, filters),
1837
+ Transaction.fromRaw
1838
+ );
1139
1839
  }
1140
1840
  async show(sid, identifier) {
1141
- const raw = await this.transport.request("GET", "transaction", this.envelope({ sid, ...identifier }));
1841
+ const raw = await this.transport.request(
1842
+ "GET",
1843
+ "transaction",
1844
+ this.envelope({ sid, ...identifier })
1845
+ );
1142
1846
  return Transaction.fromRaw(raw["data"] ?? {});
1143
1847
  }
1144
1848
  async chargeCard(sid, attributes) {
1145
- const raw = await this.transport.request("POST", "transaction/charge-card", this.envelope({ sid, ...attributes }));
1849
+ const raw = await this.transport.request(
1850
+ "POST",
1851
+ "transaction/charge-card",
1852
+ this.envelope({ sid, ...attributes })
1853
+ );
1146
1854
  return Transaction.fromRaw(raw["data"] ?? {});
1147
1855
  }
1148
1856
  /** @deprecated The API marks this deprecated; prefer chargeCard() with a token. */
1149
1857
  async chargeCardToken(sid, attributes) {
1150
- const raw = await this.transport.request("POST", "transaction/charge-card-token", this.envelope({ sid, ...attributes }));
1858
+ const raw = await this.transport.request(
1859
+ "POST",
1860
+ "transaction/charge-card-token",
1861
+ this.envelope({ sid, ...attributes })
1862
+ );
1151
1863
  return Transaction.fromRaw(raw["data"] ?? {});
1152
1864
  }
1153
1865
  async chargeAch(sid, attributes) {
1154
- const raw = await this.transport.request("POST", "transaction/charge-ach", this.envelope({ sid, ...attributes }));
1866
+ const raw = await this.transport.request(
1867
+ "POST",
1868
+ "transaction/charge-ach",
1869
+ this.envelope({ sid, ...attributes })
1870
+ );
1155
1871
  return Transaction.fromRaw(raw["data"] ?? {});
1156
1872
  }
1157
1873
  async tokenizeCard(sid, attributes) {
1158
- const raw = await this.transport.request("POST", "transaction/tokenize-card", this.envelope({ sid, ...attributes }));
1874
+ const raw = await this.transport.request(
1875
+ "POST",
1876
+ "transaction/tokenize-card",
1877
+ this.envelope({ sid, ...attributes })
1878
+ );
1159
1879
  return TokenizeResult.fromRaw(raw["data"] ?? {});
1160
1880
  }
1161
1881
  async refund(sid, attributes) {
1162
- const raw = await this.transport.request("POST", "transaction/refund", this.envelope({ sid, ...attributes }));
1882
+ const raw = await this.transport.request(
1883
+ "POST",
1884
+ "transaction/refund",
1885
+ this.envelope({ sid, ...attributes })
1886
+ );
1163
1887
  return MessageResult.fromRaw(raw["data"] ?? raw);
1164
1888
  }
1165
1889
  async void(sid, transactionType, transactionId) {
1166
- const raw = await this.transport.request("PATCH", "transaction/void", this.envelope({ sid, transaction_type: transactionType, transaction_id: transactionId }));
1890
+ const raw = await this.transport.request(
1891
+ "PATCH",
1892
+ "transaction/void",
1893
+ this.envelope({ sid, transaction_type: transactionType, transaction_id: transactionId })
1894
+ );
1167
1895
  return MessageResult.fromRaw(raw["data"] ?? raw);
1168
1896
  }
1169
1897
  };
@@ -1177,6 +1905,8 @@ var Client = class {
1177
1905
  addresses;
1178
1906
  deposits;
1179
1907
  recurringPayments;
1908
+ invoices;
1909
+ recurringInvoices;
1180
1910
  _config;
1181
1911
  constructor(token, baseUrl = DEFAULT_BASE_URL) {
1182
1912
  this._config = token instanceof Config ? token : new Config(token, baseUrl);
@@ -1188,6 +1918,8 @@ var Client = class {
1188
1918
  this.addresses = new Addresses(transport);
1189
1919
  this.deposits = new Deposits(transport);
1190
1920
  this.recurringPayments = new RecurringPayments(transport);
1921
+ this.invoices = new Invoices(transport);
1922
+ this.recurringInvoices = new RecurringInvoices(transport);
1191
1923
  }
1192
1924
  config() {
1193
1925
  return this._config;
@@ -1201,6 +1933,7 @@ var Client = class {
1201
1933
  Client,
1202
1934
  Config,
1203
1935
  ConnectionException,
1936
+ CoverFeeQuote,
1204
1937
  CursorPage,
1205
1938
  Customer,
1206
1939
  DEFAULT_BASE_URL,
@@ -1209,12 +1942,20 @@ var Client = class {
1209
1942
  DepositWithTransactions,
1210
1943
  DimeException,
1211
1944
  FormLink,
1945
+ Invoice,
1946
+ InvoiceCustomer,
1947
+ InvoiceEvent,
1948
+ InvoiceItem,
1949
+ InvoiceLineItem,
1950
+ InvoiceLink,
1951
+ InvoicePayment,
1212
1952
  Merchant,
1213
1953
  MessageResult,
1214
1954
  NotFoundException,
1215
1955
  PaymentMethod,
1216
1956
  PermissionDeniedException,
1217
1957
  RateLimitException,
1958
+ RecurringInvoice,
1218
1959
  RecurringPayment,
1219
1960
  RecurringPaymentMethod,
1220
1961
  ServerException,