Skip to content

Commit 58aec23

Browse files
authored
Cancel payment (#127)
* added cancel payment * create and cancel test
1 parent e8aa467 commit 58aec23

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

resources/payments.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ export class Payments extends BaseResource {
1818
return this.httpPatch<UnitResponse<Payment>>(`/${id}`, {data: request})
1919
}
2020

21+
public async cancel(id: string) : Promise<UnitResponse<Payment>> {
22+
return this.httpPost<UnitResponse<Payment>>(`/${id}/cancel`)
23+
}
24+
2125
/**
2226
* Optional. A comma-separated list of related resources to include in the response.
2327
* Related resources include: customer, account, transaction. See Getting Related Resources

tests/payments.spec.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,10 @@ describe("Create BookPayment", () => {
6060
})
6161
})
6262

63-
describe("Create Linkedayment", () => {
64-
test("create linked payment", async () => {
65-
const createCounterpartRes = await createCounterpartyForTest("22603")
66-
67-
const req: CreateLinkedPaymentRequest = {
63+
async function createPayment() : Promise<CreateLinkedPaymentRequest> {
64+
const createCounterpartRes = await createCounterpartyForTest("22603")
65+
66+
return {
6867
"type": "achPayment",
6968
"attributes": {
7069
"amount": 200,
@@ -85,10 +84,29 @@ describe("Create Linkedayment", () => {
8584
}
8685
}
8786
}
88-
}
87+
}
88+
}
89+
90+
describe("Create LinkedPayment", () => {
91+
test("create linked payment", async () => {
92+
93+
94+
const req: CreateLinkedPaymentRequest = (await createPayment())
8995

9096
const createPaymentRes = await unit.payments.create(req)
9197
const res = await unit.payments.get(createPaymentRes.data.id)
9298
expect(res.data.type === "achPayment").toBeTruthy()
9399
})
94100
})
101+
102+
describe("Create and cancel LinkedPayment", () => {
103+
test("create and cancel linked payment", async () => {
104+
105+
106+
const req: CreateLinkedPaymentRequest = (await createPayment())
107+
108+
const createPaymentRes = await unit.payments.create(req)
109+
const res = await unit.payments.cancel(createPaymentRes.data.id)
110+
expect(res.data.type === "achPayment").toBeTruthy()
111+
})
112+
})

0 commit comments

Comments
 (0)