Skip to content
Merged
78 changes: 78 additions & 0 deletions resources/authorizationRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import {
ApproveAuthorizationRequest,
DeclineAuthorizationRequest,
PurchaseAuthorizationRequest
} from "../types/authorizationRequest"
import { UnitResponse, UnitError } from "../types/common"
import { BaseResource } from "./baseResource"


export class AuthorizationRequests extends BaseResource {

constructor(token: string, basePath: string) {
super(token, basePath + "/authorization-requests")
}

public async get(id: string): Promise<UnitResponse<PurchaseAuthorizationRequest> | UnitError> {
return this.httpGet<UnitResponse<PurchaseAuthorizationRequest>>(`/${id}`)
}

public async list(params?: AuthorizationRequestQueryParams): Promise<UnitResponse<PurchaseAuthorizationRequest[]> | UnitError> {
const parameters = {
"page[limit]": (params?.limit ? params?.limit : 100),
"page[offset]": (params?.offset ? params?.offset : 0),
...(params?.accountId && { "filter[accountId]": params?.accountId }),
...(params?.customerId && { "filter[customerId]": params?.customerId })
}

return this.httpGet<UnitResponse<PurchaseAuthorizationRequest[]>>("", { params: parameters })
}

public async approve(request: ApproveAuthorizationRequest): Promise<UnitResponse<PurchaseAuthorizationRequest> | UnitError> {
const path = `/${request.id}/approve`
const data = {
type: "approveAuthorizationRequest",
attributes: {
amount: request.amount
}
}
return await this.httpPost<UnitResponse<PurchaseAuthorizationRequest>>(path, { data })
}

public async decline(request: DeclineAuthorizationRequest): Promise<UnitResponse<PurchaseAuthorizationRequest> | UnitError> {
const path = `/${request.id}/decline`
const data = {
type: "declineAuthorizationRequest",
attributes: {
reason: request.reason
}
}
return await this.httpPost<UnitResponse<PurchaseAuthorizationRequest>>(path, { data })
}
}

interface AuthorizationRequestQueryParams {
/**
* Maximum number of resources that will be returned. Maximum is 1000 resources. [See Pagination](https://developers.unit.co/#intro-pagination).
* default: 100
*/
limit?: number

/**
* Number of resources to skip. [See Pagination](https://developers.unit.co/#intro-pagination).
* default: 0
*/
offset?: number

/**
* Optional. Filters the results by the specified account id.
* default: empty
*/
accountId?: string

/**
* Optional. Filters the results by the specified customer id.
* default: empty
*/
customerId?: string
}
1 change: 1 addition & 0 deletions resources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export * from "./account"
export * from "./application"
export * from "./applicationForm"
export * from "./authorization"
export * from "./authorizationRequest"
export * from "./baseResource"
export * from "./batchAccounts"
export * from "./cards"
Expand Down
145 changes: 145 additions & 0 deletions types/authorizationRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import {Relationship} from "./common"

export interface PurchaseAuthorizationRequest {
/**
* Identifier of the authorization resource.
*/
id: string

/**
* Type of the authorization resource. The value is always authorization.
*/
type: "purchaseAuthorizationRequest"

/**
* JSON object representing the authorization data.
*/
attributes: {
/**
* RFC3339 Date string The date the authorization was created.
*/
createdAt: string

/**
* The amount (cents) of the authorization.
*/
amount: number

/**
* The status of the authorization request. Either Pending, Approved or Declined.
*/
status: string

/**
* Indicates whether the authorization request supports partial amount approval.
*/
partialApprovalAllowed: boolean

/**
* Optional. The amount (cents) that was approved. Available only when status is Approved.
*/
approvedAmount?: number

/**
* Optional. The reason the authorization request was declined.
* One of AccountClosed,
* CardExceedsAmountLimit,
* DoNotHonor,
* InsufficientFunds,
* InvalidMerchant,
* ReferToCardIssuer,
* RestrictedCard,
* Timeout,
* TransactionNotPermittedToCardholder.
* Available only when status is Declined
*/
declineReason?: "AccountClosed"
| "CardExceedsAmountLimit"
| "DoNotHonor"
| "InsufficientFunds"
| "InvalidMerchant"
| "ReferToCardIssuer"
| "RestrictedCard"
| "Timeout"
| "TransactionNotPermittedToCardholder"


merchant: {
/**
* The name of the merchant.
*/
name: string

/**
* The 4-digit ISO 18245 merchant category code (MCC).
*/
type: number

/**
* The merchant category, described by the MCC code (see this reference for the list of category descriptions).
*/
category: string

/**
* Optional. The location (city, state, etc.) of the merchant.
*/
location?: string
}

/**
* Indicates whether the authorization is recurring
*/
recurring: boolean
}

/**
* Describes relationships between the authorization resource and other resources (account and customer).
*/
relationships: {
/**
* The Deposit Account of the customer.
*/
account: Relationship

/**
* The customer the deposit account belongs to. The customer is either a business or a individual.
*/
customer: Relationship

/**
* The debit card used in the purchase.
*/
card: Relationship
}
}

export interface ApproveAuthorizationRequest {
id: string
amount?: number
}


export interface DeclineAuthorizationRequest {
id: string
/**
* The reason for declining the authorization request.
* One of AccountClosed,
* CardExceedsAmountLimit,
* DoNotHonor,
* InsufficientFunds,
* InvalidMerchant,
* ReferToCardIssuer,
* RestrictedCard,
* TransactionNotPermittedToCardholder.
*/
reason: "AccountClosed"
| "CardExceedsAmountLimit"
| "DoNotHonor"
| "InsufficientFunds"
| "InvalidMerchant"
| "ReferToCardIssuer"
| "RestrictedCard"
| "TransactionNotPermittedToCardholder"

}

1 change: 1 addition & 0 deletions types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export * from "./account"
export * from "./application"
export * from "./applicationForm"
export * from "./authorization"
export * from "./authorizationRequest"
export * from "./batchAccount"
export * from "./cards"
export * from "./common"
Expand Down
3 changes: 3 additions & 0 deletions unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Counterparties } from "./resources/counterparty"
import { Events } from "./resources/events"
import { Payments } from "./resources/payments"
import { Authorizations } from "./resources/authorization"
import { AuthorizationRequests } from "./resources/authorizationRequest"
import { Statments } from "./resources/statements"
import { ApplicationForms } from "./resources/applicationForm"

Expand All @@ -29,6 +30,7 @@ export class Unit {
public counterparties: Counterparties
public payments: Payments
public authorizations: Authorizations
public authorizationRequests: AuthorizationRequests
public helpers: typeof helpers
public statements: Statments
public events: Events
Expand All @@ -52,6 +54,7 @@ export class Unit {
this.events = new Events(token, basePath, config)
this.payments = new Payments(token, basePath, config)
this.authorizations = new Authorizations(token, basePath, config)
this.authorizationRequests = new AuthorizationRequests(token, basePath)
this.statements = new Statments(token, basePath, config)
this.applicationForms = new ApplicationForms(token, basePath, config)
this.helpers = helpers
Expand Down