Skip to content

Commit 45d228d

Browse files
Add optional authorization relationship to CardTransaction type (#382)
* Add increase card authorization simulation * Add authorization relationship to CardTransaction
1 parent a32bb97 commit 45d228d

File tree

3 files changed

+78
-3
lines changed

3 files changed

+78
-3
lines changed

resources/simulations.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import {
88
CreateAchReceivedPaymentSimulation,
99
ReceiveAchPaymentSimulation,
1010
CreateCardPurchaseSimulation,
11+
CreateCardAuthorizationSimulation,
12+
IncreaseCardAuthorizationSimulation,
13+
CancelCardAuthorizationSimulation,
1114
CardTransaction,
1215
} from "../types"
1316

@@ -104,4 +107,36 @@ export class Simulations extends BaseResource {
104107
data: request,
105108
})
106109
}
107-
}
110+
111+
public async createCardAuthorization(
112+
request: CreateCardAuthorizationSimulation
113+
): Promise<UnitResponse<CardTransaction>> {
114+
return this.httpPost<UnitResponse<CardTransaction>>("/authorizations", {
115+
data: request,
116+
})
117+
}
118+
119+
public async increaseCardAuthorization(
120+
request: IncreaseCardAuthorizationSimulation,
121+
authorizationId: string
122+
): Promise<UnitResponse<CardTransaction>> {
123+
return this.httpPost<UnitResponse<CardTransaction>>(
124+
`/authorizations/${authorizationId}/increase`,
125+
{
126+
data: request,
127+
}
128+
)
129+
}
130+
131+
public async cancelCardAuthorization(
132+
request: CancelCardAuthorizationSimulation,
133+
authorizationId: string
134+
): Promise<UnitResponse<CardTransaction>> {
135+
return this.httpPost<UnitResponse<CardTransaction>>(
136+
`/authorizations/${authorizationId}/cancel`,
137+
{
138+
data: request,
139+
}
140+
)
141+
}
142+
}

types/simulations.ts

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,39 @@ export interface CreateCardAuthorizationSimulation {
9595
* The 4-digit ISO 18245 merchant category code (MCC). Use any number (e.g. 1000 for testing).
9696
*/
9797
merchantType: number
98-
merchantLocation: string
98+
merchantLocation?: string
99+
merchantId?: string
99100
recurring?: boolean
101+
status?: "Authorized" | "Declined"
102+
};
103+
relationships: {
104+
account: {
105+
data: {
106+
type: "depositAccount"
107+
id: string
108+
}
109+
}
110+
}
111+
}
112+
113+
export interface IncreaseCardAuthorizationSimulation {
114+
type: "authorization"
115+
attributes: {
116+
amount: number
117+
cardLast4Digits: string
118+
recurring: boolean
119+
};
120+
relationships: {
121+
account: {
122+
data: {
123+
type: "depositAccount"
124+
id: string
125+
}
126+
}
100127
}
128+
}
129+
130+
export interface CancelCardAuthorizationSimulation {
101131
relationships: {
102132
account: {
103133
data: {
@@ -134,6 +164,12 @@ export interface CreateCardPurchaseSimulation {
134164
id: string
135165
}
136166
}
167+
authorization?: {
168+
data: {
169+
type: "authorization"
170+
id: string
171+
}
172+
}
137173
}
138174
}
139175

@@ -166,4 +202,4 @@ export interface CreateCheckPaymentSimulation {
166202
relationships: {
167203
account: Relationship
168204
}
169-
}
205+
}

types/transactions.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,10 @@ export type CardTransaction = BaseTransaction & {
586586
* The debit card involved in the transaction.
587587
*/
588588
card: Relationship
589+
/**
590+
* Optional. The [Authorization](https://developers.unit.co/#authorization) request made by the merchant, if present (see [Authorizations](https://developers.unit.co/#authorizations)).
591+
*/
592+
authorization?: Relationship
589593
} & BaseTransactionRelationships
590594
}
591595

0 commit comments

Comments
 (0)