-
Notifications
You must be signed in to change notification settings - Fork 57
Add authorization requests to unit class #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
axshani
merged 9 commits into
unit-finance:main
from
obando777:feat/programmatic-authorization-of-card-purchases
Jul 20, 2021
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e91a320
feat(authorization requests): add authorization requests in unit class
obando777 18be07b
feat(authorization requests): constraint reason type
obando777 f93f4db
feat(authorization requests): cosmetic formatting
obando777 92c214e
Merge branch 'main' of github.com:obando777/unit-node-sdk into feat/p…
obando777 90f7b2c
Merge branch 'main' of github.com:obando777/unit-node-sdk into feat/p…
obando777 04963a8
Merge branch 'main' of github.com:obando777/unit-node-sdk into feat/p…
obando777 2b4fe93
Merge branch 'main' of github.com:obando777/unit-node-sdk into feat/p…
obando777 434b6e9
Merge branch 'main' of github.com:obando777/unit-node-sdk into feat/p…
obando777 2d5d24b
Update resources/authorizationRequest.ts
Elroie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
|
|
||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.