Skip to content

Commit 54a825e

Browse files
axshaniilyamerman
andauthored
feat: CreateRecurringDebitAchPayment (#372)
* CreateRecurringDebitAchPaymentRequest * lint-fix --------- Co-authored-by: Ilya Merman <[email protected]>
1 parent 284b574 commit 54a825e

File tree

2 files changed

+117
-21
lines changed

2 files changed

+117
-21
lines changed

tests/recurringPayments.spec.ts

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
import { Unit } from "../unit"
2-
import { createIndividualAccount } from "./testHelpers"
2+
import { createCounterparty, createIndividualAccount } from "./testHelpers"
33

44
import dotenv from "dotenv"
5-
import { CreateRecurringCreditAchPaymentRequest, CreateRecurringCreditBookPaymentRequest, CreateRecurringPaymentRequest, RecurringCreditAchPayment, RecurringCreditBookPayment } from "../types/recurringPayment"
6-
import { createCounterpartyForTest } from "./counterparties.spec"
5+
import { CreateRecurringCreditAchPaymentRequest, CreateRecurringCreditBookPaymentRequest, CreateRecurringDebitAchPaymentRequest, RecurringCreditAchPayment, RecurringCreditBookPayment } from "../types/recurringPayment"
76
dotenv.config()
87
const unit = new Unit(process.env.UNIT_TOKEN || "test", process.env.UNIT_API_URL || "test")
98

109
describe("Create", () => {
1110
test("create CreateRecurringCreditAchPayment", async () => {
1211
const createDepositAccountRes = await createIndividualAccount(unit)
13-
const createCounterpartRes = await createCounterpartyForTest("22603")
12+
const counterpartyId = await createCounterparty(unit)
1413

15-
const req: CreateRecurringPaymentRequest = {
14+
const req: CreateRecurringCreditAchPaymentRequest = {
1615
"type": "recurringCreditAchPayment",
1716
"attributes": {
1817
"schedule": {
@@ -32,7 +31,7 @@ describe("Create", () => {
3231
"counterparty": {
3332
"data": {
3433
"type": "counterparty",
35-
"id": createCounterpartRes.data.id
34+
"id": counterpartyId
3635
}
3736
}
3837
}
@@ -224,3 +223,40 @@ describe("Request recurringCreditAchPayment", () => {
224223
expect(req.type).toBe("recurringCreditAchPayment")
225224
})
226225
})
226+
227+
describe("Create RecurringDebitAchPayment Test", () => {
228+
test("Create CreateRecurringDebitAchPayment", async () => {
229+
const accountId = (await createIndividualAccount(unit)).data.id
230+
const counterpartyId = await createCounterparty(unit)
231+
232+
const req: CreateRecurringDebitAchPaymentRequest = {
233+
"type": "recurringDebitAchPayment",
234+
"attributes": {
235+
"schedule": {
236+
"interval": "Monthly",
237+
"dayOfMonth": 16,
238+
"totalNumberOfPayments": 12
239+
},
240+
"amount": 1000,
241+
"description": "Rent-Apt15"
242+
},
243+
"relationships": {
244+
"account": {
245+
"data": {
246+
"type": "depositAccount",
247+
"id": accountId
248+
}
249+
},
250+
"counterparty": {
251+
"data": {
252+
"type": "counterparty",
253+
"id": counterpartyId
254+
}
255+
}
256+
}
257+
}
258+
259+
const res = await unit.recurringPayments.create(req)
260+
expect(res.data.type).toBe("recurringDebitAchPayment")
261+
})
262+
})

types/recurringPayment.ts

Lines changed: 75 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export type RecurringPaymentStatus = "Active" | "Completed" | "Disabled"
55

66
export type Interval = "Monthly"
77

8-
export type RecurringPayment = RecurringCreditAchPayment | RecurringCreditBookPayment
8+
export type RecurringPayment = RecurringCreditAchPayment | RecurringCreditBookPayment | RecurringDebitAchPayment
99

1010
interface RecurringPaymentAttributes {
1111
/**
@@ -53,7 +53,7 @@ interface RecurringPaymentAttributes {
5353

5454
interface RecurringPaymentRelationships {
5555
/**
56-
* The Deposit Account originating the recurring payment.
56+
* The [Deposit Account](https://docs.unit.co/deposit-accounts/) originating the recurring payment.
5757
*/
5858
account: Relationship
5959

@@ -63,7 +63,7 @@ interface RecurringPaymentRelationships {
6363
org: Relationship
6464

6565
/**
66-
* The Customer the deposit account belongs to. This relationship is only available if the account belongs to a single customer, business or individual.
66+
* The [Customer](https://docs.unit.co/customers/) the deposit account belongs to. This relationship is only available if the account belongs to a single customer, business or individual.
6767
*/
6868
customer?: Relationship
6969
}
@@ -132,6 +132,38 @@ export interface RecurringCreditBookPayment {
132132
} & RecurringPaymentRelationships
133133
}
134134

135+
export interface RecurringDebitAchPayment {
136+
/**
137+
* Identifier of the recurring credit book payment resource.
138+
*/
139+
id: string
140+
141+
/**
142+
* Type of the payment resource. The value is always recurringDebitAchPayment.
143+
*/
144+
type: "recurringDebitAchPayment"
145+
146+
/**
147+
* JSON object representing the recurring payment resource.
148+
*/
149+
attributes: {
150+
/**
151+
* Optional, additional payment description (maximum of 80 characters), not all institutions present that.
152+
*/
153+
addenda?: string
154+
} & RecurringPaymentAttributes
155+
156+
/**
157+
* Describes relationships between the Recurring Debit ACH payment and the originating deposit account and org.
158+
*/
159+
relationships: {
160+
/**
161+
* The [Counterparty](https://docs.unit.co/payments-counterparties) the payment to be made to.
162+
*/
163+
counterparty: Relationship
164+
} & RecurringPaymentRelationships
165+
}
166+
135167
interface BaseSchedule {
136168
/**
137169
* RFC3339 format. For more information: https://en.wikipedia.org/wiki/ISO_8601#RFCs
@@ -172,7 +204,7 @@ export interface Schedule extends BaseSchedule {
172204
nextScheduledAction: string
173205
}
174206

175-
export type CreateRecurringPaymentRequest = CreateRecurringCreditAchPaymentRequest | CreateRecurringCreditBookPaymentRequest
207+
export type CreateRecurringPaymentRequest = CreateRecurringCreditAchPaymentRequest | CreateRecurringCreditBookPaymentRequest | CreateRecurringDebitAchPaymentRequest
176208

177209
interface CreateRecurringRequestAttributes {
178210
/**
@@ -201,6 +233,18 @@ interface CreateRecurringRequestAttributes {
201233
tags?: object
202234
}
203235

236+
interface CreateRecurringRequestRelationships {
237+
/**
238+
* The Deposit Account originating the recurring payment.
239+
*/
240+
account: Relationship
241+
242+
/**
243+
* The Counterparty account to which the payment will be made.
244+
*/
245+
counterparty: Relationship
246+
}
247+
204248
export interface CreateRecurringCreditAchPaymentRequest {
205249
type: "recurringCreditAchPayment"
206250

@@ -217,17 +261,7 @@ export interface CreateRecurringCreditAchPaymentRequest {
217261
/**
218262
* JSON:API Relationships. Describes relationships between the Recurring Credit ACH payment and the originating deposit account and org.
219263
*/
220-
relationships: {
221-
/**
222-
* The Deposit Account originating the recurring payment.
223-
*/
224-
account: Relationship
225-
226-
/**
227-
* The Counterparty the payment to be made to.
228-
*/
229-
counterparty: Relationship
230-
}
264+
relationships: CreateRecurringRequestRelationships
231265
}
232266

233267
export interface CreateRecurringCreditBookPaymentRequest {
@@ -259,3 +293,29 @@ export interface CreateRecurringCreditBookPaymentRequest {
259293
}
260294
}
261295

296+
export interface CreateRecurringDebitAchPaymentRequest {
297+
type: "recurringDebitAchPayment"
298+
299+
/**
300+
* JSON object representing the recurring payment resource.
301+
*/
302+
attributes: {
303+
/**
304+
* Optional, additional payment description (maximum of 50 characters), not all institutions present that.
305+
*/
306+
addenda?: string
307+
308+
/**
309+
* Optional, default is false. Verify the counterparty balance, if balance verification fails the payment will be rejected with reason set to CounterpartyInsufficientFunds.
310+
*/
311+
verifyCounterpartyBalance?: boolean
312+
313+
/**
314+
* Optional, default is false. See Same Day ACH.
315+
*/
316+
sameDay?: boolean
317+
} & CreateRecurringRequestAttributes
318+
319+
relationships: CreateRecurringRequestRelationships
320+
}
321+

0 commit comments

Comments
 (0)