@dime-technology/dime-js-sdk 1.0.0 → 1.2.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 +118 -30
- package/dist/index.cjs +732 -50
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +289 -54
- package/dist/index.d.ts +289 -54
- package/dist/index.js +724 -50
- package/dist/index.js.map +1 -1
- package/package.json +9 -1
package/dist/index.cjs
CHANGED
|
@@ -34,12 +34,20 @@ __export(index_exports, {
|
|
|
34
34
|
DepositWithTransactions: () => DepositWithTransactions,
|
|
35
35
|
DimeException: () => DimeException,
|
|
36
36
|
FormLink: () => FormLink,
|
|
37
|
+
Invoice: () => Invoice,
|
|
38
|
+
InvoiceCustomer: () => InvoiceCustomer,
|
|
39
|
+
InvoiceEvent: () => InvoiceEvent,
|
|
40
|
+
InvoiceItem: () => InvoiceItem,
|
|
41
|
+
InvoiceLineItem: () => InvoiceLineItem,
|
|
42
|
+
InvoiceLink: () => InvoiceLink,
|
|
43
|
+
InvoicePayment: () => InvoicePayment,
|
|
37
44
|
Merchant: () => Merchant,
|
|
38
45
|
MessageResult: () => MessageResult,
|
|
39
46
|
NotFoundException: () => NotFoundException,
|
|
40
47
|
PaymentMethod: () => PaymentMethod,
|
|
41
48
|
PermissionDeniedException: () => PermissionDeniedException,
|
|
42
49
|
RateLimitException: () => RateLimitException,
|
|
50
|
+
RecurringInvoice: () => RecurringInvoice,
|
|
43
51
|
RecurringPayment: () => RecurringPayment,
|
|
44
52
|
RecurringPaymentMethod: () => RecurringPaymentMethod,
|
|
45
53
|
ServerException: () => ServerException,
|
|
@@ -53,7 +61,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
53
61
|
|
|
54
62
|
// src/config.ts
|
|
55
63
|
var DEFAULT_BASE_URL = "https://app.dimepayments.com";
|
|
56
|
-
var VERSION = "1.
|
|
64
|
+
var VERSION = "1.2.0";
|
|
57
65
|
var Config = class {
|
|
58
66
|
token;
|
|
59
67
|
baseUrl;
|
|
@@ -222,25 +230,31 @@ var Transport = class {
|
|
|
222
230
|
/**
|
|
223
231
|
* Execute a request and return the decoded JSON body.
|
|
224
232
|
*
|
|
225
|
-
* The Dime API
|
|
226
|
-
*
|
|
227
|
-
*
|
|
233
|
+
* The Dime API reads the same `{ data, filters }` envelope whether it arrives
|
|
234
|
+
* as a JSON body or as nested query parameters. The Fetch standard forbids a
|
|
235
|
+
* body on GET/HEAD (undici throws), so for those methods the envelope is
|
|
236
|
+
* serialised into the query string (`data[sid]=…&filters[status]=…`) and no
|
|
237
|
+
* body is sent; every other method sends the envelope as a JSON body.
|
|
228
238
|
*/
|
|
229
239
|
async request(method, path, body = {}, query = {}) {
|
|
230
240
|
let url = `${this.config.baseUri()}${path.replace(/^\//, "")}`;
|
|
231
|
-
|
|
232
|
-
|
|
241
|
+
const bodyless = method.toUpperCase() === "GET" || method.toUpperCase() === "HEAD";
|
|
242
|
+
const params = { ...query };
|
|
243
|
+
if (bodyless) Object.assign(params, flattenParams(body));
|
|
244
|
+
if (Object.keys(params).length > 0) {
|
|
245
|
+
url += "?" + new URLSearchParams(params).toString();
|
|
233
246
|
}
|
|
234
|
-
const
|
|
247
|
+
const sendBody = !bodyless && Object.keys(body).length > 0;
|
|
248
|
+
const headers = {
|
|
249
|
+
Authorization: `Bearer ${this.config.token}`,
|
|
250
|
+
Accept: "application/json",
|
|
251
|
+
"X-Dime-Sdk": `dime-js-sdk/${VERSION}`
|
|
252
|
+
};
|
|
253
|
+
if (sendBody) headers["Content-Type"] = "application/json";
|
|
235
254
|
const init = {
|
|
236
255
|
method,
|
|
237
|
-
headers
|
|
238
|
-
|
|
239
|
-
Accept: "application/json",
|
|
240
|
-
"Content-Type": "application/json",
|
|
241
|
-
"X-Dime-Sdk": `dime-js-sdk/${VERSION}`
|
|
242
|
-
},
|
|
243
|
-
...hasBody ? { body: JSON.stringify(body) } : {}
|
|
256
|
+
headers,
|
|
257
|
+
...sendBody ? { body: JSON.stringify(body) } : {}
|
|
244
258
|
};
|
|
245
259
|
return this.attempt(url, init, 0);
|
|
246
260
|
}
|
|
@@ -280,6 +294,23 @@ var Transport = class {
|
|
|
280
294
|
await this.sleepFn(ms);
|
|
281
295
|
}
|
|
282
296
|
};
|
|
297
|
+
function flattenParams(obj, prefix = "") {
|
|
298
|
+
const out = {};
|
|
299
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
300
|
+
if (value === null || value === void 0) continue;
|
|
301
|
+
const name = prefix ? `${prefix}[${key}]` : key;
|
|
302
|
+
if (Array.isArray(value)) {
|
|
303
|
+
value.forEach((item, i) => {
|
|
304
|
+
Object.assign(out, flattenParams({ [i]: item }, name));
|
|
305
|
+
});
|
|
306
|
+
} else if (typeof value === "object") {
|
|
307
|
+
Object.assign(out, flattenParams(value, name));
|
|
308
|
+
} else {
|
|
309
|
+
out[name] = typeof value === "boolean" ? value ? "1" : "0" : String(value);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
return out;
|
|
313
|
+
}
|
|
283
314
|
function parseRetryAfter(response) {
|
|
284
315
|
const header = response.headers.get("Retry-After");
|
|
285
316
|
if (header !== null && /^\d+$/.test(header)) return parseInt(header, 10);
|
|
@@ -325,6 +356,11 @@ function arrObjectFrom(data, keys) {
|
|
|
325
356
|
}
|
|
326
357
|
return {};
|
|
327
358
|
}
|
|
359
|
+
function arrArrayFrom(data, key) {
|
|
360
|
+
const value = data[key];
|
|
361
|
+
if (Array.isArray(value)) return value;
|
|
362
|
+
return [];
|
|
363
|
+
}
|
|
328
364
|
|
|
329
365
|
// src/data-objects/address.ts
|
|
330
366
|
var Address = class _Address {
|
|
@@ -454,9 +490,7 @@ function extractCursor(meta, key) {
|
|
|
454
490
|
return typeof v === "string" && v !== "" ? v : void 0;
|
|
455
491
|
}
|
|
456
492
|
function pruneNulls(obj) {
|
|
457
|
-
return Object.fromEntries(
|
|
458
|
-
Object.entries(obj).filter(([, v]) => v !== null && v !== void 0)
|
|
459
|
-
);
|
|
493
|
+
return Object.fromEntries(Object.entries(obj).filter(([, v]) => v !== null && v !== void 0));
|
|
460
494
|
}
|
|
461
495
|
|
|
462
496
|
// src/resources/addresses.ts
|
|
@@ -465,19 +499,35 @@ var Addresses = class extends AbstractResource {
|
|
|
465
499
|
return this.paginate("GET", "address/list", this.envelope({ sid, uuid }), Address.fromRaw);
|
|
466
500
|
}
|
|
467
501
|
async show(sid, uuid, addressId) {
|
|
468
|
-
const raw = await this.transport.request(
|
|
502
|
+
const raw = await this.transport.request(
|
|
503
|
+
"GET",
|
|
504
|
+
"address/show",
|
|
505
|
+
this.envelope({ sid, uuid, address_id: addressId })
|
|
506
|
+
);
|
|
469
507
|
return Address.fromRaw(raw["data"] ?? {});
|
|
470
508
|
}
|
|
471
509
|
async create(sid, uuid, attributes) {
|
|
472
|
-
const raw = await this.transport.request(
|
|
510
|
+
const raw = await this.transport.request(
|
|
511
|
+
"POST",
|
|
512
|
+
"address/create",
|
|
513
|
+
this.envelope({ sid, uuid, ...attributes })
|
|
514
|
+
);
|
|
473
515
|
return Address.fromRaw(raw["data"] ?? {});
|
|
474
516
|
}
|
|
475
517
|
async update(sid, uuid, addressId, attributes) {
|
|
476
|
-
const raw = await this.transport.request(
|
|
518
|
+
const raw = await this.transport.request(
|
|
519
|
+
"PATCH",
|
|
520
|
+
"address/update",
|
|
521
|
+
this.envelope({ sid, uuid, address_id: addressId, ...attributes })
|
|
522
|
+
);
|
|
477
523
|
return Address.fromRaw(raw["data"] ?? {});
|
|
478
524
|
}
|
|
479
525
|
async delete(sid, uuid, addressId) {
|
|
480
|
-
const raw = await this.transport.request(
|
|
526
|
+
const raw = await this.transport.request(
|
|
527
|
+
"POST",
|
|
528
|
+
"address/delete",
|
|
529
|
+
this.envelope({ sid, uuid, address_id: addressId })
|
|
530
|
+
);
|
|
481
531
|
return MessageResult.fromRaw(raw["data"] ?? raw);
|
|
482
532
|
}
|
|
483
533
|
};
|
|
@@ -534,19 +584,35 @@ var Customers = class extends AbstractResource {
|
|
|
534
584
|
return this.paginate("GET", "customer/list", this.envelope({ sid }, filters), Customer.fromRaw);
|
|
535
585
|
}
|
|
536
586
|
async show(sid, filters) {
|
|
537
|
-
const raw = await this.transport.request(
|
|
587
|
+
const raw = await this.transport.request(
|
|
588
|
+
"GET",
|
|
589
|
+
"customer/show",
|
|
590
|
+
this.envelope({ sid }, filters)
|
|
591
|
+
);
|
|
538
592
|
return Customer.fromRaw(raw["data"] ?? {});
|
|
539
593
|
}
|
|
540
594
|
async create(sid, attributes) {
|
|
541
|
-
const raw = await this.transport.request(
|
|
595
|
+
const raw = await this.transport.request(
|
|
596
|
+
"POST",
|
|
597
|
+
"customer/create",
|
|
598
|
+
this.envelope({ sid, ...attributes })
|
|
599
|
+
);
|
|
542
600
|
return Customer.fromRaw(raw["data"] ?? {});
|
|
543
601
|
}
|
|
544
602
|
async update(sid, filters, attributes) {
|
|
545
|
-
const raw = await this.transport.request(
|
|
603
|
+
const raw = await this.transport.request(
|
|
604
|
+
"PATCH",
|
|
605
|
+
"customer/update",
|
|
606
|
+
this.envelope({ sid, ...attributes }, filters)
|
|
607
|
+
);
|
|
546
608
|
return Customer.fromRaw(raw["data"] ?? {});
|
|
547
609
|
}
|
|
548
610
|
async delete(sid, filters) {
|
|
549
|
-
const raw = await this.transport.request(
|
|
611
|
+
const raw = await this.transport.request(
|
|
612
|
+
"POST",
|
|
613
|
+
"customer/delete",
|
|
614
|
+
this.envelope({ sid }, filters)
|
|
615
|
+
);
|
|
550
616
|
return MessageResult.fromRaw(raw["data"] ?? raw);
|
|
551
617
|
}
|
|
552
618
|
};
|
|
@@ -755,15 +821,414 @@ var Deposits = class extends AbstractResource {
|
|
|
755
821
|
return this.paginate("GET", "deposit/list", this.envelope({ sid }, filters), Deposit.fromRaw);
|
|
756
822
|
}
|
|
757
823
|
async listWithTransactions(sid, filters) {
|
|
758
|
-
const raw = await this.transport.request(
|
|
824
|
+
const raw = await this.transport.request(
|
|
825
|
+
"GET",
|
|
826
|
+
"deposit/list-with-trans",
|
|
827
|
+
this.envelope({ sid }, filters)
|
|
828
|
+
);
|
|
759
829
|
return DepositGroup.fromRaw(raw["data"] ?? {});
|
|
760
830
|
}
|
|
761
831
|
async show(sid, identifier) {
|
|
762
|
-
const raw = await this.transport.request(
|
|
832
|
+
const raw = await this.transport.request(
|
|
833
|
+
"GET",
|
|
834
|
+
"deposit/show",
|
|
835
|
+
this.envelope({ sid, ...identifier })
|
|
836
|
+
);
|
|
763
837
|
return DepositWithTransactions.fromRaw(raw["data"] ?? {});
|
|
764
838
|
}
|
|
765
839
|
};
|
|
766
840
|
|
|
841
|
+
// src/data-objects/invoice-customer.ts
|
|
842
|
+
var InvoiceCustomer = class _InvoiceCustomer {
|
|
843
|
+
constructor(id, name, email) {
|
|
844
|
+
this.id = id;
|
|
845
|
+
this.name = name;
|
|
846
|
+
this.email = email;
|
|
847
|
+
}
|
|
848
|
+
id;
|
|
849
|
+
name;
|
|
850
|
+
email;
|
|
851
|
+
static fromRaw(data) {
|
|
852
|
+
return new _InvoiceCustomer(
|
|
853
|
+
arrInt(data, "id"),
|
|
854
|
+
arrString(data, "name"),
|
|
855
|
+
arrString(data, "email")
|
|
856
|
+
);
|
|
857
|
+
}
|
|
858
|
+
};
|
|
859
|
+
|
|
860
|
+
// src/data-objects/invoice-event.ts
|
|
861
|
+
var InvoiceEvent = class _InvoiceEvent {
|
|
862
|
+
constructor(type, label, description, createdAt) {
|
|
863
|
+
this.type = type;
|
|
864
|
+
this.label = label;
|
|
865
|
+
this.description = description;
|
|
866
|
+
this.createdAt = createdAt;
|
|
867
|
+
}
|
|
868
|
+
type;
|
|
869
|
+
label;
|
|
870
|
+
description;
|
|
871
|
+
createdAt;
|
|
872
|
+
static fromRaw(data) {
|
|
873
|
+
return new _InvoiceEvent(
|
|
874
|
+
arrString(data, "type"),
|
|
875
|
+
arrString(data, "label"),
|
|
876
|
+
arrString(data, "description"),
|
|
877
|
+
arrString(data, "created_at")
|
|
878
|
+
);
|
|
879
|
+
}
|
|
880
|
+
};
|
|
881
|
+
|
|
882
|
+
// src/data-objects/invoice-line-item.ts
|
|
883
|
+
var InvoiceLineItem = class _InvoiceLineItem {
|
|
884
|
+
constructor(id, itemId, name, description, quantity, unitPrice, amount) {
|
|
885
|
+
this.id = id;
|
|
886
|
+
this.itemId = itemId;
|
|
887
|
+
this.name = name;
|
|
888
|
+
this.description = description;
|
|
889
|
+
this.quantity = quantity;
|
|
890
|
+
this.unitPrice = unitPrice;
|
|
891
|
+
this.amount = amount;
|
|
892
|
+
}
|
|
893
|
+
id;
|
|
894
|
+
itemId;
|
|
895
|
+
name;
|
|
896
|
+
description;
|
|
897
|
+
quantity;
|
|
898
|
+
unitPrice;
|
|
899
|
+
amount;
|
|
900
|
+
static fromRaw(data) {
|
|
901
|
+
return new _InvoiceLineItem(
|
|
902
|
+
arrInt(data, "id"),
|
|
903
|
+
arrInt(data, "item_id"),
|
|
904
|
+
arrString(data, "name"),
|
|
905
|
+
arrString(data, "description"),
|
|
906
|
+
arrString(data, "quantity"),
|
|
907
|
+
arrString(data, "unit_price"),
|
|
908
|
+
arrString(data, "amount")
|
|
909
|
+
);
|
|
910
|
+
}
|
|
911
|
+
};
|
|
912
|
+
|
|
913
|
+
// src/data-objects/invoice-payment.ts
|
|
914
|
+
var InvoicePayment = class _InvoicePayment {
|
|
915
|
+
constructor(amount, paidAt, method, transactionId) {
|
|
916
|
+
this.amount = amount;
|
|
917
|
+
this.paidAt = paidAt;
|
|
918
|
+
this.method = method;
|
|
919
|
+
this.transactionId = transactionId;
|
|
920
|
+
}
|
|
921
|
+
amount;
|
|
922
|
+
paidAt;
|
|
923
|
+
method;
|
|
924
|
+
transactionId;
|
|
925
|
+
static fromRaw(data) {
|
|
926
|
+
return new _InvoicePayment(
|
|
927
|
+
arrString(data, "amount"),
|
|
928
|
+
arrString(data, "paid_at"),
|
|
929
|
+
arrString(data, "method"),
|
|
930
|
+
arrString(data, "transaction_id")
|
|
931
|
+
);
|
|
932
|
+
}
|
|
933
|
+
};
|
|
934
|
+
|
|
935
|
+
// src/data-objects/invoice.ts
|
|
936
|
+
var Invoice = class _Invoice {
|
|
937
|
+
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 = []) {
|
|
938
|
+
this.id = id;
|
|
939
|
+
this.invoiceNumber = invoiceNumber;
|
|
940
|
+
this.status = status;
|
|
941
|
+
this.token = token;
|
|
942
|
+
this.paymentTerms = paymentTerms;
|
|
943
|
+
this.issueDate = issueDate;
|
|
944
|
+
this.dueDate = dueDate;
|
|
945
|
+
this.isOverdue = isOverdue;
|
|
946
|
+
this.subtotal = subtotal;
|
|
947
|
+
this.total = total;
|
|
948
|
+
this.amountPaid = amountPaid;
|
|
949
|
+
this.balance = balance;
|
|
950
|
+
this.allowPartialPayment = allowPartialPayment;
|
|
951
|
+
this.thankYouNote = thankYouNote;
|
|
952
|
+
this.customerName = customerName;
|
|
953
|
+
this.customerEmail = customerEmail;
|
|
954
|
+
this.publicUrl = publicUrl;
|
|
955
|
+
this.customer = customer;
|
|
956
|
+
this.items = items;
|
|
957
|
+
this.payments = payments;
|
|
958
|
+
this.events = events;
|
|
959
|
+
}
|
|
960
|
+
id;
|
|
961
|
+
invoiceNumber;
|
|
962
|
+
status;
|
|
963
|
+
token;
|
|
964
|
+
paymentTerms;
|
|
965
|
+
issueDate;
|
|
966
|
+
dueDate;
|
|
967
|
+
isOverdue;
|
|
968
|
+
subtotal;
|
|
969
|
+
total;
|
|
970
|
+
amountPaid;
|
|
971
|
+
balance;
|
|
972
|
+
allowPartialPayment;
|
|
973
|
+
thankYouNote;
|
|
974
|
+
customerName;
|
|
975
|
+
customerEmail;
|
|
976
|
+
publicUrl;
|
|
977
|
+
customer;
|
|
978
|
+
items;
|
|
979
|
+
payments;
|
|
980
|
+
events;
|
|
981
|
+
static fromRaw(data) {
|
|
982
|
+
return new _Invoice(
|
|
983
|
+
arrInt(data, "id"),
|
|
984
|
+
arrString(data, "invoice_number"),
|
|
985
|
+
arrString(data, "status"),
|
|
986
|
+
arrString(data, "token"),
|
|
987
|
+
arrString(data, "payment_terms"),
|
|
988
|
+
arrString(data, "issue_date"),
|
|
989
|
+
arrString(data, "due_date"),
|
|
990
|
+
arrBool(data, "is_overdue"),
|
|
991
|
+
arrString(data, "subtotal"),
|
|
992
|
+
arrString(data, "total"),
|
|
993
|
+
arrString(data, "amount_paid"),
|
|
994
|
+
arrString(data, "balance"),
|
|
995
|
+
arrBool(data, "allow_partial_payment"),
|
|
996
|
+
arrString(data, "thank_you_note"),
|
|
997
|
+
arrString(data, "customer_name"),
|
|
998
|
+
arrString(data, "customer_email"),
|
|
999
|
+
arrString(data, "public_url"),
|
|
1000
|
+
InvoiceCustomer.fromRaw(arrObjectFrom(data, ["customer"])),
|
|
1001
|
+
arrArrayFrom(data, "items").map(InvoiceLineItem.fromRaw),
|
|
1002
|
+
arrArrayFrom(data, "payments").map(InvoicePayment.fromRaw),
|
|
1003
|
+
arrArrayFrom(data, "events").map(InvoiceEvent.fromRaw)
|
|
1004
|
+
);
|
|
1005
|
+
}
|
|
1006
|
+
};
|
|
1007
|
+
|
|
1008
|
+
// src/data-objects/invoice-item.ts
|
|
1009
|
+
var InvoiceItem = class _InvoiceItem {
|
|
1010
|
+
constructor(id, name, description, price, taxDeductible = false) {
|
|
1011
|
+
this.id = id;
|
|
1012
|
+
this.name = name;
|
|
1013
|
+
this.description = description;
|
|
1014
|
+
this.price = price;
|
|
1015
|
+
this.taxDeductible = taxDeductible;
|
|
1016
|
+
}
|
|
1017
|
+
id;
|
|
1018
|
+
name;
|
|
1019
|
+
description;
|
|
1020
|
+
price;
|
|
1021
|
+
taxDeductible;
|
|
1022
|
+
static fromRaw(data) {
|
|
1023
|
+
return new _InvoiceItem(
|
|
1024
|
+
arrInt(data, "id"),
|
|
1025
|
+
arrString(data, "name"),
|
|
1026
|
+
arrString(data, "description"),
|
|
1027
|
+
arrString(data, "price"),
|
|
1028
|
+
arrBool(data, "tax_deductible")
|
|
1029
|
+
);
|
|
1030
|
+
}
|
|
1031
|
+
};
|
|
1032
|
+
|
|
1033
|
+
// src/data-objects/invoice-link.ts
|
|
1034
|
+
var InvoiceLink = class _InvoiceLink {
|
|
1035
|
+
constructor(publicUrl, token) {
|
|
1036
|
+
this.publicUrl = publicUrl;
|
|
1037
|
+
this.token = token;
|
|
1038
|
+
}
|
|
1039
|
+
publicUrl;
|
|
1040
|
+
token;
|
|
1041
|
+
static fromRaw(data) {
|
|
1042
|
+
return new _InvoiceLink(arrString(data, "public_url"), arrString(data, "token"));
|
|
1043
|
+
}
|
|
1044
|
+
};
|
|
1045
|
+
|
|
1046
|
+
// src/resources/invoices.ts
|
|
1047
|
+
var Invoices = class extends AbstractResource {
|
|
1048
|
+
/**
|
|
1049
|
+
* List invoices for a merchant.
|
|
1050
|
+
*
|
|
1051
|
+
* @param filters `status` — draft | sent | paid | partial | void | overdue
|
|
1052
|
+
*/
|
|
1053
|
+
async list(sid, filters = {}) {
|
|
1054
|
+
return this.paginate("GET", "invoices", this.envelope({ sid }, filters), Invoice.fromRaw);
|
|
1055
|
+
}
|
|
1056
|
+
async show(sid, invoiceId) {
|
|
1057
|
+
const raw = await this.transport.request(
|
|
1058
|
+
"GET",
|
|
1059
|
+
"invoice",
|
|
1060
|
+
this.envelope({ sid, invoice_id: invoiceId })
|
|
1061
|
+
);
|
|
1062
|
+
return Invoice.fromRaw(raw["data"] ?? {});
|
|
1063
|
+
}
|
|
1064
|
+
/**
|
|
1065
|
+
* Create a draft invoice with its line items. Every line must reference a
|
|
1066
|
+
* Merchant `item_id`; the line name and unit price are snapshotted.
|
|
1067
|
+
*
|
|
1068
|
+
* @param attributes
|
|
1069
|
+
* `customer_uuid` (or `customer_id`), `customer_name`, `customer_email`,
|
|
1070
|
+
* `payment_terms` (`due_on_receipt` | `net_15` | `net_30` | `net_60`) and
|
|
1071
|
+
* `lines` are required. `lines[]` takes `item_id`, `name`, `quantity`,
|
|
1072
|
+
* `unit_price` and optional `description`. Optional: `invoice_number`,
|
|
1073
|
+
* `issue_date` (Y-m-d, defaults to today — `due_date` is derived from
|
|
1074
|
+
* `payment_terms`), `thank_you_note`, `allow_partial_payment`,
|
|
1075
|
+
* `reminder_settings`.
|
|
1076
|
+
*/
|
|
1077
|
+
async create(sid, attributes) {
|
|
1078
|
+
const raw = await this.transport.request(
|
|
1079
|
+
"POST",
|
|
1080
|
+
"invoice/create",
|
|
1081
|
+
this.envelope({ sid, ...attributes })
|
|
1082
|
+
);
|
|
1083
|
+
return Invoice.fromRaw(raw["data"] ?? {});
|
|
1084
|
+
}
|
|
1085
|
+
/**
|
|
1086
|
+
* Update a draft invoice. Only drafts can be edited, and passing `lines`
|
|
1087
|
+
* replaces the existing line items.
|
|
1088
|
+
*
|
|
1089
|
+
* @param attributes same shape as {@link Invoices.create}
|
|
1090
|
+
*/
|
|
1091
|
+
async update(sid, invoiceId, attributes) {
|
|
1092
|
+
const raw = await this.transport.request(
|
|
1093
|
+
"PATCH",
|
|
1094
|
+
"invoice/update",
|
|
1095
|
+
this.envelope({ sid, invoice_id: invoiceId, ...attributes })
|
|
1096
|
+
);
|
|
1097
|
+
return Invoice.fromRaw(raw["data"] ?? {});
|
|
1098
|
+
}
|
|
1099
|
+
async delete(sid, invoiceId) {
|
|
1100
|
+
const raw = await this.transport.request(
|
|
1101
|
+
"POST",
|
|
1102
|
+
"invoice/delete",
|
|
1103
|
+
this.envelope({ sid, invoice_id: invoiceId })
|
|
1104
|
+
);
|
|
1105
|
+
return MessageResult.fromRaw(raw["data"] ?? raw);
|
|
1106
|
+
}
|
|
1107
|
+
/** Email the invoice to the customer and advance it to Sent. */
|
|
1108
|
+
async send(sid, invoiceId) {
|
|
1109
|
+
const raw = await this.transport.request(
|
|
1110
|
+
"POST",
|
|
1111
|
+
"invoice/send",
|
|
1112
|
+
this.envelope({ sid, invoice_id: invoiceId })
|
|
1113
|
+
);
|
|
1114
|
+
return Invoice.fromRaw(raw["data"] ?? {});
|
|
1115
|
+
}
|
|
1116
|
+
/** Activate a draft invoice for payment without emailing it. */
|
|
1117
|
+
async markSent(sid, invoiceId) {
|
|
1118
|
+
const raw = await this.transport.request(
|
|
1119
|
+
"POST",
|
|
1120
|
+
"invoice/mark-sent",
|
|
1121
|
+
this.envelope({ sid, invoice_id: invoiceId })
|
|
1122
|
+
);
|
|
1123
|
+
return Invoice.fromRaw(raw["data"] ?? {});
|
|
1124
|
+
}
|
|
1125
|
+
async void(sid, invoiceId) {
|
|
1126
|
+
const raw = await this.transport.request(
|
|
1127
|
+
"PATCH",
|
|
1128
|
+
"invoice/void",
|
|
1129
|
+
this.envelope({ sid, invoice_id: invoiceId })
|
|
1130
|
+
);
|
|
1131
|
+
return Invoice.fromRaw(raw["data"] ?? {});
|
|
1132
|
+
}
|
|
1133
|
+
/** Clone any invoice into a new draft with a freshly allocated number. */
|
|
1134
|
+
async duplicate(sid, invoiceId) {
|
|
1135
|
+
const raw = await this.transport.request(
|
|
1136
|
+
"POST",
|
|
1137
|
+
"invoice/duplicate",
|
|
1138
|
+
this.envelope({ sid, invoice_id: invoiceId })
|
|
1139
|
+
);
|
|
1140
|
+
return Invoice.fromRaw(raw["data"] ?? {});
|
|
1141
|
+
}
|
|
1142
|
+
/**
|
|
1143
|
+
* Record a merchant-initiated (MOTO) card or ACH payment against an open
|
|
1144
|
+
* invoice.
|
|
1145
|
+
*
|
|
1146
|
+
* @param attributes
|
|
1147
|
+
* `payment_type` is required and is `cc` or `ach`. For a card, pass a stored
|
|
1148
|
+
* `token` or raw `cardholder_name` / `card_number` / `expiration_date` (m/Y)
|
|
1149
|
+
* plus optional `cvv`; for ACH, pass `routing_number` / `account_number` /
|
|
1150
|
+
* `account_type` (Checking | Savings) / `account_name`. Omit `amount` to pay
|
|
1151
|
+
* the full balance — partial amounts require the invoice to allow them.
|
|
1152
|
+
* Optional: `memo`, `billing_address`.
|
|
1153
|
+
*/
|
|
1154
|
+
async pay(sid, invoiceId, attributes) {
|
|
1155
|
+
const raw = await this.transport.request(
|
|
1156
|
+
"POST",
|
|
1157
|
+
"invoice/pay",
|
|
1158
|
+
this.envelope({ sid, invoice_id: invoiceId, ...attributes })
|
|
1159
|
+
);
|
|
1160
|
+
return Invoice.fromRaw(raw["data"] ?? {});
|
|
1161
|
+
}
|
|
1162
|
+
/** Get the public pay link (and token) for an invoice. */
|
|
1163
|
+
async getLink(sid, invoiceId) {
|
|
1164
|
+
const raw = await this.transport.request(
|
|
1165
|
+
"GET",
|
|
1166
|
+
"invoice/link",
|
|
1167
|
+
this.envelope({ sid, invoice_id: invoiceId })
|
|
1168
|
+
);
|
|
1169
|
+
return InvoiceLink.fromRaw(raw["data"] ?? {});
|
|
1170
|
+
}
|
|
1171
|
+
/**
|
|
1172
|
+
* Append a single line item to a draft invoice.
|
|
1173
|
+
*
|
|
1174
|
+
* @param attributes `item_id`, `name`, `quantity` and `unit_price` are
|
|
1175
|
+
* required; `description` is optional.
|
|
1176
|
+
*/
|
|
1177
|
+
async addLineItem(sid, invoiceId, attributes) {
|
|
1178
|
+
const raw = await this.transport.request(
|
|
1179
|
+
"POST",
|
|
1180
|
+
"invoice/line-item/add",
|
|
1181
|
+
this.envelope({ sid, invoice_id: invoiceId, ...attributes })
|
|
1182
|
+
);
|
|
1183
|
+
return Invoice.fromRaw(raw["data"] ?? {});
|
|
1184
|
+
}
|
|
1185
|
+
/**
|
|
1186
|
+
* Update a single line item on a draft invoice.
|
|
1187
|
+
*
|
|
1188
|
+
* @param attributes any of `item_id`, `name`, `description`, `quantity`,
|
|
1189
|
+
* `unit_price`
|
|
1190
|
+
*/
|
|
1191
|
+
async updateLineItem(sid, invoiceId, lineItemId, attributes) {
|
|
1192
|
+
const raw = await this.transport.request(
|
|
1193
|
+
"PATCH",
|
|
1194
|
+
"invoice/line-item/update",
|
|
1195
|
+
this.envelope({ sid, invoice_id: invoiceId, line_item_id: lineItemId, ...attributes })
|
|
1196
|
+
);
|
|
1197
|
+
return Invoice.fromRaw(raw["data"] ?? {});
|
|
1198
|
+
}
|
|
1199
|
+
/** Remove a single line item from a draft invoice. */
|
|
1200
|
+
async deleteLineItem(sid, invoiceId, lineItemId) {
|
|
1201
|
+
const raw = await this.transport.request(
|
|
1202
|
+
"POST",
|
|
1203
|
+
"invoice/line-item/delete",
|
|
1204
|
+
this.envelope({ sid, invoice_id: invoiceId, line_item_id: lineItemId })
|
|
1205
|
+
);
|
|
1206
|
+
return Invoice.fromRaw(raw["data"] ?? {});
|
|
1207
|
+
}
|
|
1208
|
+
/** List the Merchant's items (funds/designations) available as invoice line items. */
|
|
1209
|
+
async listItems(sid) {
|
|
1210
|
+
const raw = await this.transport.request("GET", "invoice/items", this.envelope({ sid }));
|
|
1211
|
+
const items = Array.isArray(raw["data"]) ? raw["data"] : [];
|
|
1212
|
+
return items.map(InvoiceItem.fromRaw);
|
|
1213
|
+
}
|
|
1214
|
+
/**
|
|
1215
|
+
* Create an invoicing-only item (fund/designation) for the Merchant. The item
|
|
1216
|
+
* is hidden from public giving pages and can be referenced as a line's
|
|
1217
|
+
* `item_id`.
|
|
1218
|
+
*
|
|
1219
|
+
* @param attributes `name` is required; `description`, `price` and
|
|
1220
|
+
* `tax_deductible` are optional.
|
|
1221
|
+
*/
|
|
1222
|
+
async createItem(sid, attributes) {
|
|
1223
|
+
const raw = await this.transport.request(
|
|
1224
|
+
"POST",
|
|
1225
|
+
"invoice/item/create",
|
|
1226
|
+
this.envelope({ sid, ...attributes })
|
|
1227
|
+
);
|
|
1228
|
+
return InvoiceItem.fromRaw(raw["data"] ?? {});
|
|
1229
|
+
}
|
|
1230
|
+
};
|
|
1231
|
+
|
|
767
1232
|
// src/data-objects/form-link.ts
|
|
768
1233
|
var FormLink = class _FormLink {
|
|
769
1234
|
constructor(link) {
|
|
@@ -862,11 +1327,19 @@ var Merchants = class extends AbstractResource {
|
|
|
862
1327
|
return Merchant.fromRaw(raw["data"] ?? {});
|
|
863
1328
|
}
|
|
864
1329
|
async update(sid, attributes) {
|
|
865
|
-
const raw = await this.transport.request(
|
|
1330
|
+
const raw = await this.transport.request(
|
|
1331
|
+
"PATCH",
|
|
1332
|
+
"merchant/update",
|
|
1333
|
+
this.envelope({ sid, ...attributes })
|
|
1334
|
+
);
|
|
866
1335
|
return Merchant.fromRaw(raw["data"] ?? {});
|
|
867
1336
|
}
|
|
868
1337
|
async getFormLink(sid) {
|
|
869
|
-
const raw = await this.transport.request(
|
|
1338
|
+
const raw = await this.transport.request(
|
|
1339
|
+
"GET",
|
|
1340
|
+
"merchant/get-form-link",
|
|
1341
|
+
this.envelope({ sid })
|
|
1342
|
+
);
|
|
870
1343
|
return FormLink.fromRaw(raw["data"] ?? {});
|
|
871
1344
|
}
|
|
872
1345
|
};
|
|
@@ -959,26 +1432,153 @@ var PaymentMethod = class _PaymentMethod {
|
|
|
959
1432
|
// src/resources/payment-methods.ts
|
|
960
1433
|
var PaymentMethods = class extends AbstractResource {
|
|
961
1434
|
async list(sid, filters) {
|
|
962
|
-
return this.paginate(
|
|
1435
|
+
return this.paginate(
|
|
1436
|
+
"GET",
|
|
1437
|
+
"payment-method/list",
|
|
1438
|
+
this.envelope({ sid }, filters),
|
|
1439
|
+
PaymentMethod.fromRaw
|
|
1440
|
+
);
|
|
963
1441
|
}
|
|
964
1442
|
async show(sid, paymentMethodId, filters) {
|
|
965
|
-
const raw = await this.transport.request(
|
|
1443
|
+
const raw = await this.transport.request(
|
|
1444
|
+
"GET",
|
|
1445
|
+
"payment-method/show",
|
|
1446
|
+
this.envelope({ sid, payment_method_id: paymentMethodId }, filters)
|
|
1447
|
+
);
|
|
966
1448
|
return PaymentMethod.fromRaw(raw["data"] ?? {});
|
|
967
1449
|
}
|
|
968
1450
|
async create(sid, attributes) {
|
|
969
|
-
const raw = await this.transport.request(
|
|
1451
|
+
const raw = await this.transport.request(
|
|
1452
|
+
"POST",
|
|
1453
|
+
"payment-method/create",
|
|
1454
|
+
this.envelope({ sid, ...attributes })
|
|
1455
|
+
);
|
|
970
1456
|
return PaymentMethod.fromRaw(raw["data"] ?? {});
|
|
971
1457
|
}
|
|
972
1458
|
async update(sid, attributes) {
|
|
973
|
-
const raw = await this.transport.request(
|
|
1459
|
+
const raw = await this.transport.request(
|
|
1460
|
+
"PATCH",
|
|
1461
|
+
"payment-method/update",
|
|
1462
|
+
this.envelope({ sid, ...attributes })
|
|
1463
|
+
);
|
|
974
1464
|
return PaymentMethod.fromRaw(raw["data"] ?? {});
|
|
975
1465
|
}
|
|
976
1466
|
async delete(sid, paymentMethodId, uuid) {
|
|
977
|
-
const raw = await this.transport.request(
|
|
1467
|
+
const raw = await this.transport.request(
|
|
1468
|
+
"POST",
|
|
1469
|
+
"payment-method/delete",
|
|
1470
|
+
this.envelope({ sid, payment_method_id: paymentMethodId, uuid })
|
|
1471
|
+
);
|
|
978
1472
|
return MessageResult.fromRaw(raw["data"] ?? raw);
|
|
979
1473
|
}
|
|
980
1474
|
};
|
|
981
1475
|
|
|
1476
|
+
// src/data-objects/recurring-invoice.ts
|
|
1477
|
+
var RecurringInvoice = class _RecurringInvoice {
|
|
1478
|
+
constructor(id, status, recurrenceSchedule, paymentTerms, startDate, endDate, nextRunDate, lastRunDate, customerName, thankYouNote, customer = new InvoiceCustomer(), items = [], upcomingRunDates = [], invoices = []) {
|
|
1479
|
+
this.id = id;
|
|
1480
|
+
this.status = status;
|
|
1481
|
+
this.recurrenceSchedule = recurrenceSchedule;
|
|
1482
|
+
this.paymentTerms = paymentTerms;
|
|
1483
|
+
this.startDate = startDate;
|
|
1484
|
+
this.endDate = endDate;
|
|
1485
|
+
this.nextRunDate = nextRunDate;
|
|
1486
|
+
this.lastRunDate = lastRunDate;
|
|
1487
|
+
this.customerName = customerName;
|
|
1488
|
+
this.thankYouNote = thankYouNote;
|
|
1489
|
+
this.customer = customer;
|
|
1490
|
+
this.items = items;
|
|
1491
|
+
this.upcomingRunDates = upcomingRunDates;
|
|
1492
|
+
this.invoices = invoices;
|
|
1493
|
+
}
|
|
1494
|
+
id;
|
|
1495
|
+
status;
|
|
1496
|
+
recurrenceSchedule;
|
|
1497
|
+
paymentTerms;
|
|
1498
|
+
startDate;
|
|
1499
|
+
endDate;
|
|
1500
|
+
nextRunDate;
|
|
1501
|
+
lastRunDate;
|
|
1502
|
+
customerName;
|
|
1503
|
+
thankYouNote;
|
|
1504
|
+
customer;
|
|
1505
|
+
items;
|
|
1506
|
+
upcomingRunDates;
|
|
1507
|
+
invoices;
|
|
1508
|
+
static fromRaw(data) {
|
|
1509
|
+
const runDates = data["upcoming_run_dates"];
|
|
1510
|
+
return new _RecurringInvoice(
|
|
1511
|
+
arrInt(data, "id"),
|
|
1512
|
+
arrString(data, "status"),
|
|
1513
|
+
arrString(data, "recurrence_schedule"),
|
|
1514
|
+
arrString(data, "payment_terms"),
|
|
1515
|
+
arrString(data, "start_date"),
|
|
1516
|
+
arrString(data, "end_date"),
|
|
1517
|
+
arrString(data, "next_run_date"),
|
|
1518
|
+
arrString(data, "last_run_date"),
|
|
1519
|
+
arrString(data, "customer_name"),
|
|
1520
|
+
arrString(data, "thank_you_note"),
|
|
1521
|
+
InvoiceCustomer.fromRaw(arrObjectFrom(data, ["customer"])),
|
|
1522
|
+
arrArrayFrom(data, "items").map(InvoiceLineItem.fromRaw),
|
|
1523
|
+
Array.isArray(runDates) ? runDates.map((d) => String(d)) : [],
|
|
1524
|
+
arrArrayFrom(data, "invoices").map(Invoice.fromRaw)
|
|
1525
|
+
);
|
|
1526
|
+
}
|
|
1527
|
+
};
|
|
1528
|
+
|
|
1529
|
+
// src/resources/recurring-invoices.ts
|
|
1530
|
+
var RecurringInvoices = class extends AbstractResource {
|
|
1531
|
+
/**
|
|
1532
|
+
* List recurring-invoice templates.
|
|
1533
|
+
*
|
|
1534
|
+
* @param filters `status` — Active | Paused | Cancelled | Completed
|
|
1535
|
+
*/
|
|
1536
|
+
async list(sid, filters = {}) {
|
|
1537
|
+
return this.paginate(
|
|
1538
|
+
"GET",
|
|
1539
|
+
"recurring-invoices",
|
|
1540
|
+
this.envelope({ sid }, filters),
|
|
1541
|
+
RecurringInvoice.fromRaw
|
|
1542
|
+
);
|
|
1543
|
+
}
|
|
1544
|
+
async show(sid, recurringInvoiceId) {
|
|
1545
|
+
const raw = await this.transport.request(
|
|
1546
|
+
"GET",
|
|
1547
|
+
"recurring-invoice",
|
|
1548
|
+
this.envelope({ sid, recurring_invoice_id: recurringInvoiceId })
|
|
1549
|
+
);
|
|
1550
|
+
return RecurringInvoice.fromRaw(raw["data"] ?? {});
|
|
1551
|
+
}
|
|
1552
|
+
/**
|
|
1553
|
+
* Create a recurring-invoice template. When `recurring_start_date` is today the
|
|
1554
|
+
* first invoice is generated and sent immediately.
|
|
1555
|
+
*
|
|
1556
|
+
* @param attributes
|
|
1557
|
+
* `customer_uuid` (or `customer_id`), `payment_terms` (`due_on_receipt` |
|
|
1558
|
+
* `net_15` | `net_30` | `net_60`), `recurring_frequency` (`Weekly` |
|
|
1559
|
+
* `Biweekly` | `FirstFifteenth` | `Monthly` | `Yearly`),
|
|
1560
|
+
* `recurring_start_date` (Y-m-d) and `lines` are required. Optional:
|
|
1561
|
+
* `recurring_end_date` (Y-m-d, on or after the start date),
|
|
1562
|
+
* `thank_you_note`.
|
|
1563
|
+
*/
|
|
1564
|
+
async create(sid, attributes) {
|
|
1565
|
+
const raw = await this.transport.request(
|
|
1566
|
+
"POST",
|
|
1567
|
+
"recurring-invoice/create",
|
|
1568
|
+
this.envelope({ sid, ...attributes })
|
|
1569
|
+
);
|
|
1570
|
+
return RecurringInvoice.fromRaw(raw["data"] ?? {});
|
|
1571
|
+
}
|
|
1572
|
+
async cancel(sid, recurringInvoiceId) {
|
|
1573
|
+
const raw = await this.transport.request(
|
|
1574
|
+
"POST",
|
|
1575
|
+
"recurring-invoice/cancel",
|
|
1576
|
+
this.envelope({ sid, recurring_invoice_id: recurringInvoiceId })
|
|
1577
|
+
);
|
|
1578
|
+
return RecurringInvoice.fromRaw(raw["data"] ?? {});
|
|
1579
|
+
}
|
|
1580
|
+
};
|
|
1581
|
+
|
|
982
1582
|
// src/data-objects/recurring-payment-method.ts
|
|
983
1583
|
var RecurringPaymentMethod = class _RecurringPaymentMethod {
|
|
984
1584
|
constructor(id, type, lastFour, expiration, zip, nameOnCard, bankAccountName, routingNumber, accountNumber, ownershipType, accountType, bankName) {
|
|
@@ -1089,34 +1689,71 @@ var RecurringPayment = class _RecurringPayment {
|
|
|
1089
1689
|
// src/resources/recurring-payments.ts
|
|
1090
1690
|
var RecurringPayments = class extends AbstractResource {
|
|
1091
1691
|
async list(sid, filters = {}) {
|
|
1092
|
-
return this.paginate(
|
|
1692
|
+
return this.paginate(
|
|
1693
|
+
"GET",
|
|
1694
|
+
"recurring-payment/list",
|
|
1695
|
+
this.envelope({ sid }, filters),
|
|
1696
|
+
RecurringPayment.fromRaw
|
|
1697
|
+
);
|
|
1093
1698
|
}
|
|
1094
1699
|
async show(sid, recurringPaymentId) {
|
|
1095
|
-
const raw = await this.transport.request(
|
|
1700
|
+
const raw = await this.transport.request(
|
|
1701
|
+
"GET",
|
|
1702
|
+
"recurring-payment/show",
|
|
1703
|
+
this.envelope({ sid, recurring_payment_id: recurringPaymentId })
|
|
1704
|
+
);
|
|
1096
1705
|
return RecurringPayment.fromRaw(raw["data"] ?? {});
|
|
1097
1706
|
}
|
|
1098
1707
|
async create(sid, attributes) {
|
|
1099
|
-
const raw = await this.transport.request(
|
|
1708
|
+
const raw = await this.transport.request(
|
|
1709
|
+
"POST",
|
|
1710
|
+
"recurring-payment/create",
|
|
1711
|
+
this.envelope({ sid, ...attributes })
|
|
1712
|
+
);
|
|
1100
1713
|
return RecurringPayment.fromRaw(raw["data"] ?? {});
|
|
1101
1714
|
}
|
|
1102
1715
|
async edit(sid, recurringPaymentId, attributes) {
|
|
1103
|
-
const raw = await this.transport.request(
|
|
1716
|
+
const raw = await this.transport.request(
|
|
1717
|
+
"PATCH",
|
|
1718
|
+
"recurring-payment/edit",
|
|
1719
|
+
this.envelope({ sid, recurring_payment_id: recurringPaymentId, ...attributes })
|
|
1720
|
+
);
|
|
1104
1721
|
return RecurringPayment.fromRaw(raw["data"] ?? {});
|
|
1105
1722
|
}
|
|
1106
1723
|
async pause(sid, recurringPaymentId, pauseUntilDate) {
|
|
1107
|
-
const raw = await this.transport.request(
|
|
1724
|
+
const raw = await this.transport.request(
|
|
1725
|
+
"PATCH",
|
|
1726
|
+
"recurring-payment/pause",
|
|
1727
|
+
this.envelope({
|
|
1728
|
+
sid,
|
|
1729
|
+
recurring_payment_id: recurringPaymentId,
|
|
1730
|
+
pause_until_date: pauseUntilDate
|
|
1731
|
+
})
|
|
1732
|
+
);
|
|
1108
1733
|
return RecurringPayment.fromRaw(raw["data"] ?? {});
|
|
1109
1734
|
}
|
|
1110
1735
|
async cancel(sid, recurringPaymentId) {
|
|
1111
|
-
const raw = await this.transport.request(
|
|
1736
|
+
const raw = await this.transport.request(
|
|
1737
|
+
"PATCH",
|
|
1738
|
+
"recurring-payment/cancel",
|
|
1739
|
+
this.envelope({ sid, recurring_payment_id: recurringPaymentId })
|
|
1740
|
+
);
|
|
1112
1741
|
return RecurringPayment.fromRaw(raw["data"] ?? {});
|
|
1113
1742
|
}
|
|
1114
1743
|
async activate(sid, recurringPaymentId) {
|
|
1115
|
-
const raw = await this.transport.request(
|
|
1744
|
+
const raw = await this.transport.request(
|
|
1745
|
+
"PATCH",
|
|
1746
|
+
"recurring-payment/activate",
|
|
1747
|
+
this.envelope({ sid, recurring_payment_id: recurringPaymentId })
|
|
1748
|
+
);
|
|
1116
1749
|
return RecurringPayment.fromRaw(raw["data"] ?? {});
|
|
1117
1750
|
}
|
|
1118
1751
|
async delete(sid, recurringPaymentId) {
|
|
1119
|
-
const raw = await this.transport.request(
|
|
1752
|
+
const raw = await this.transport.request(
|
|
1753
|
+
"POST",
|
|
1754
|
+
"recurring-payment/delete",
|
|
1755
|
+
this.envelope({ sid, recurring_payment_id: recurringPaymentId })
|
|
1756
|
+
);
|
|
1120
1757
|
return MessageResult.fromRaw(raw["data"] ?? raw);
|
|
1121
1758
|
}
|
|
1122
1759
|
};
|
|
@@ -1135,35 +1772,68 @@ var TokenizeResult = class _TokenizeResult {
|
|
|
1135
1772
|
// src/resources/transactions.ts
|
|
1136
1773
|
var Transactions = class extends AbstractResource {
|
|
1137
1774
|
async list(sid, filters = {}) {
|
|
1138
|
-
return this.paginate(
|
|
1775
|
+
return this.paginate(
|
|
1776
|
+
"GET",
|
|
1777
|
+
"transactions",
|
|
1778
|
+
this.envelope({ sid }, filters),
|
|
1779
|
+
Transaction.fromRaw
|
|
1780
|
+
);
|
|
1139
1781
|
}
|
|
1140
1782
|
async show(sid, identifier) {
|
|
1141
|
-
const raw = await this.transport.request(
|
|
1783
|
+
const raw = await this.transport.request(
|
|
1784
|
+
"GET",
|
|
1785
|
+
"transaction",
|
|
1786
|
+
this.envelope({ sid, ...identifier })
|
|
1787
|
+
);
|
|
1142
1788
|
return Transaction.fromRaw(raw["data"] ?? {});
|
|
1143
1789
|
}
|
|
1144
1790
|
async chargeCard(sid, attributes) {
|
|
1145
|
-
const raw = await this.transport.request(
|
|
1791
|
+
const raw = await this.transport.request(
|
|
1792
|
+
"POST",
|
|
1793
|
+
"transaction/charge-card",
|
|
1794
|
+
this.envelope({ sid, ...attributes })
|
|
1795
|
+
);
|
|
1146
1796
|
return Transaction.fromRaw(raw["data"] ?? {});
|
|
1147
1797
|
}
|
|
1148
1798
|
/** @deprecated The API marks this deprecated; prefer chargeCard() with a token. */
|
|
1149
1799
|
async chargeCardToken(sid, attributes) {
|
|
1150
|
-
const raw = await this.transport.request(
|
|
1800
|
+
const raw = await this.transport.request(
|
|
1801
|
+
"POST",
|
|
1802
|
+
"transaction/charge-card-token",
|
|
1803
|
+
this.envelope({ sid, ...attributes })
|
|
1804
|
+
);
|
|
1151
1805
|
return Transaction.fromRaw(raw["data"] ?? {});
|
|
1152
1806
|
}
|
|
1153
1807
|
async chargeAch(sid, attributes) {
|
|
1154
|
-
const raw = await this.transport.request(
|
|
1808
|
+
const raw = await this.transport.request(
|
|
1809
|
+
"POST",
|
|
1810
|
+
"transaction/charge-ach",
|
|
1811
|
+
this.envelope({ sid, ...attributes })
|
|
1812
|
+
);
|
|
1155
1813
|
return Transaction.fromRaw(raw["data"] ?? {});
|
|
1156
1814
|
}
|
|
1157
1815
|
async tokenizeCard(sid, attributes) {
|
|
1158
|
-
const raw = await this.transport.request(
|
|
1816
|
+
const raw = await this.transport.request(
|
|
1817
|
+
"POST",
|
|
1818
|
+
"transaction/tokenize-card",
|
|
1819
|
+
this.envelope({ sid, ...attributes })
|
|
1820
|
+
);
|
|
1159
1821
|
return TokenizeResult.fromRaw(raw["data"] ?? {});
|
|
1160
1822
|
}
|
|
1161
1823
|
async refund(sid, attributes) {
|
|
1162
|
-
const raw = await this.transport.request(
|
|
1824
|
+
const raw = await this.transport.request(
|
|
1825
|
+
"POST",
|
|
1826
|
+
"transaction/refund",
|
|
1827
|
+
this.envelope({ sid, ...attributes })
|
|
1828
|
+
);
|
|
1163
1829
|
return MessageResult.fromRaw(raw["data"] ?? raw);
|
|
1164
1830
|
}
|
|
1165
1831
|
async void(sid, transactionType, transactionId) {
|
|
1166
|
-
const raw = await this.transport.request(
|
|
1832
|
+
const raw = await this.transport.request(
|
|
1833
|
+
"PATCH",
|
|
1834
|
+
"transaction/void",
|
|
1835
|
+
this.envelope({ sid, transaction_type: transactionType, transaction_id: transactionId })
|
|
1836
|
+
);
|
|
1167
1837
|
return MessageResult.fromRaw(raw["data"] ?? raw);
|
|
1168
1838
|
}
|
|
1169
1839
|
};
|
|
@@ -1177,6 +1847,8 @@ var Client = class {
|
|
|
1177
1847
|
addresses;
|
|
1178
1848
|
deposits;
|
|
1179
1849
|
recurringPayments;
|
|
1850
|
+
invoices;
|
|
1851
|
+
recurringInvoices;
|
|
1180
1852
|
_config;
|
|
1181
1853
|
constructor(token, baseUrl = DEFAULT_BASE_URL) {
|
|
1182
1854
|
this._config = token instanceof Config ? token : new Config(token, baseUrl);
|
|
@@ -1188,6 +1860,8 @@ var Client = class {
|
|
|
1188
1860
|
this.addresses = new Addresses(transport);
|
|
1189
1861
|
this.deposits = new Deposits(transport);
|
|
1190
1862
|
this.recurringPayments = new RecurringPayments(transport);
|
|
1863
|
+
this.invoices = new Invoices(transport);
|
|
1864
|
+
this.recurringInvoices = new RecurringInvoices(transport);
|
|
1191
1865
|
}
|
|
1192
1866
|
config() {
|
|
1193
1867
|
return this._config;
|
|
@@ -1209,12 +1883,20 @@ var Client = class {
|
|
|
1209
1883
|
DepositWithTransactions,
|
|
1210
1884
|
DimeException,
|
|
1211
1885
|
FormLink,
|
|
1886
|
+
Invoice,
|
|
1887
|
+
InvoiceCustomer,
|
|
1888
|
+
InvoiceEvent,
|
|
1889
|
+
InvoiceItem,
|
|
1890
|
+
InvoiceLineItem,
|
|
1891
|
+
InvoiceLink,
|
|
1892
|
+
InvoicePayment,
|
|
1212
1893
|
Merchant,
|
|
1213
1894
|
MessageResult,
|
|
1214
1895
|
NotFoundException,
|
|
1215
1896
|
PaymentMethod,
|
|
1216
1897
|
PermissionDeniedException,
|
|
1217
1898
|
RateLimitException,
|
|
1899
|
+
RecurringInvoice,
|
|
1218
1900
|
RecurringPayment,
|
|
1219
1901
|
RecurringPaymentMethod,
|
|
1220
1902
|
ServerException,
|