Skip to content

Commit 22f9e90

Browse files
authored
Add support for (a subset of) sandbox simulations (#207)
1 parent 617960b commit 22f9e90

File tree

5 files changed

+240
-0
lines changed

5 files changed

+240
-0
lines changed

resources/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export * from "./fee"
1414
export * from "./payments"
1515
export * from "./receivedPayments"
1616
export * from "./returns"
17+
export * from "./simulations"
1718
export * from "./statements"
1819
export * from "./transactions"
1920
export * from "./webhooks"

resources/simulations.ts

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { BaseResource } from "."
2+
import { UnitConfig, UnitResponse } from "../types"
3+
import { AchReceivedPayment, Application, ApplicationDocument } from "../types"
4+
import {
5+
ApproveApplicationSimulation,
6+
DenyApplicationSimulation,
7+
RejectDocumentSimulation,
8+
CreateAchReceivedPaymentSimulation,
9+
} from "../types"
10+
11+
export class Simulations extends BaseResource {
12+
constructor(token: string, basePath: string, config?: UnitConfig) {
13+
super(token, basePath + "/sandbox", config)
14+
}
15+
16+
public async approveApplication(
17+
applicationId: string,
18+
request: ApproveApplicationSimulation
19+
): Promise<UnitResponse<Application>> {
20+
return this.httpPost<UnitResponse<Application>>(
21+
`/applications/${applicationId}/approve`,
22+
{
23+
data: request,
24+
}
25+
)
26+
}
27+
28+
public async denyApplication(
29+
applicationId: string,
30+
request: DenyApplicationSimulation
31+
): Promise<UnitResponse<Application>> {
32+
return this.httpPost<UnitResponse<Application>>(
33+
`/applications/${applicationId}/deny`,
34+
{
35+
data: request,
36+
}
37+
)
38+
}
39+
40+
public async approveDocument(
41+
applicationId: string,
42+
documentId: string
43+
): Promise<UnitResponse<ApplicationDocument>> {
44+
return this.httpPost<UnitResponse<ApplicationDocument>>(
45+
`/applications/${applicationId}/documents/${documentId}/approve`,
46+
undefined
47+
)
48+
}
49+
50+
public async rejectDocument(
51+
applicationId: string,
52+
documentId: string,
53+
request: RejectDocumentSimulation
54+
): Promise<UnitResponse<ApplicationDocument>> {
55+
return this.httpPost<UnitResponse<ApplicationDocument>>(
56+
`/applications/${applicationId}/documents/${documentId}/reject`,
57+
{
58+
data: request,
59+
}
60+
)
61+
}
62+
63+
public async createAchReceivedPayment(
64+
request: CreateAchReceivedPaymentSimulation
65+
): Promise<UnitResponse<AchReceivedPayment>> {
66+
return this.httpPost<UnitResponse<AchReceivedPayment>>(
67+
"/received-payments",
68+
{
69+
data: request,
70+
}
71+
)
72+
}
73+
74+
public async completeAchReceivedPayment(
75+
id: string,
76+
): Promise<UnitResponse<AchReceivedPayment>> {
77+
return this.httpPost<UnitResponse<AchReceivedPayment>>(
78+
`/received-payments/${id}/complete`,
79+
)
80+
}
81+
}

types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export * from "./events"
1313
export * from "./fee"
1414
export * from "./payments"
1515
export * from "./returns"
16+
export * from "./simulations"
1617
export * from "./transactions"
1718
export * from "./webhooks"
1819
export * from "./billPay"

types/simulations.ts

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
import { ReasonCode } from "."
2+
3+
export interface ApproveApplicationSimulation {
4+
type: "applicationApprove"
5+
attributes: {
6+
reason: string
7+
}
8+
}
9+
10+
export interface DenyApplicationSimulation {
11+
type: "applicationDeny"
12+
attributes: {
13+
reason: string
14+
}
15+
}
16+
17+
export interface RejectDocumentSimulation {
18+
type: "documentReject"
19+
attributes: {
20+
reason: string
21+
reasonCode: ReasonCode
22+
}
23+
}
24+
25+
export interface ReceiveAchPaymentSimulation {
26+
type: "achPayment"
27+
attributes: {
28+
amount: number
29+
direction: "Credit" | "Debit"
30+
description: string
31+
}
32+
relationships: {
33+
account: {
34+
type: "depositAccount"
35+
id: string
36+
}
37+
}
38+
}
39+
40+
export interface TransmitAchPaymentSimulation {
41+
type: "transmitAchPayment"
42+
relationships: {
43+
payment: {
44+
type: "achPayment"
45+
id: string
46+
}
47+
}
48+
}
49+
50+
export interface ClearAchPaymentSimulation {
51+
type: "clearAchPayment"
52+
relationships: {
53+
payment: {
54+
type: "achPayment"
55+
id: string
56+
}
57+
}
58+
}
59+
60+
export interface ReturnAchPaymentSimulation {
61+
type: "returnAchPayment"
62+
relationships: {
63+
payment: {
64+
type: "achPayment"
65+
id: string
66+
}
67+
}
68+
}
69+
70+
export interface ReceiveWirePaymentSimulation {
71+
type: "wirePayment"
72+
attributes: {
73+
amount: number
74+
description: string
75+
}
76+
relationships: {
77+
account: {
78+
data: {
79+
type: "depositAccount"
80+
id: string
81+
}
82+
}
83+
}
84+
}
85+
86+
export interface CreateCardAuthorizationSimulation {
87+
type: "authorization"
88+
attributes: {
89+
amount: number
90+
cardLast4Digits: string
91+
merchantName: string
92+
/**
93+
* The 4-digit ISO 18245 merchant category code (MCC). Use any number (e.g. 1000 for testing).
94+
*/
95+
merchantType: number
96+
merchantLocation: string
97+
recurring?: boolean
98+
}
99+
relationships: {
100+
account: {
101+
data: {
102+
type: "depositAccount"
103+
id: string
104+
}
105+
}
106+
}
107+
}
108+
109+
export interface CreateCardPurchaseSimulation {
110+
type: "purchaseTransaction"
111+
attributes: {
112+
amount: number
113+
direction: string
114+
merchantName: string
115+
/**
116+
* The 4-digit ISO 18245 merchant category code (MCC). Use any number (e.g. 1000 for testing).
117+
*/
118+
merchantType: number
119+
merchantLocation: string
120+
coordinates?: {
121+
longitude: number
122+
latitude: number
123+
}
124+
last4Digits: string
125+
recurring: false
126+
}
127+
relationships: {
128+
account: {
129+
data: {
130+
type: "depositAccount"
131+
id: string
132+
}
133+
}
134+
}
135+
}
136+
137+
export interface CreateAchReceivedPaymentSimulation {
138+
type: "achReceivedPayment"
139+
attributes: {
140+
amount: number
141+
description: string
142+
companyName: string
143+
completionDate: string
144+
secCode: string
145+
}
146+
relationships: {
147+
account: {
148+
data: {
149+
type: "depositAccount"
150+
id: string
151+
}
152+
}
153+
}
154+
}

unit.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { CheckDeposits } from "./resources/checkDeposit"
2525
import { ReceivedPayments } from "./resources/receivedPayments"
2626
import { RecurringPayments } from "./resources/recurringPayments"
2727
import { OrgTokens } from "./resources/orgToken"
28+
import { Simulations } from "./resources/simulations"
2829

2930
export class Unit {
3031
public applications: Applications
@@ -54,6 +55,7 @@ export class Unit {
5455
public rewards: Rewards
5556
public recurringPayments: RecurringPayments
5657
public orgTokens: OrgTokens
58+
public simulations: Simulations
5759

5860
constructor(token: string, basePath: string, config?: UnitConfig) {
5961
// remove all trailing slashes from user-provided basePath
@@ -85,6 +87,7 @@ export class Unit {
8587
this.rewards = new Rewards(token, basePath, config)
8688
this.recurringPayments = new RecurringPayments(token, basePath, config)
8789
this.orgTokens = new OrgTokens(token, basePath, config)
90+
this.simulations = new Simulations(token, basePath, config)
8891
this.helpers = helpers
8992
}
9093

0 commit comments

Comments
 (0)