Skip to content

Commit

Permalink
Add resource request (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
andersonku authored Jul 25, 2024
1 parent 34f1a08 commit 3c824d1
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zai-payments",
"version": "0.2.2",
"version": "0.2.3",
"description": "Zai API Typescript/Javascript Bindings",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import walletAccounts from './resources/wallet_accounts';
import tools from './resources/tools';
import tokens from './resources/tokens';
import users from './resources/users';
import request from './resources/request';

export * from './types';

Expand Down Expand Up @@ -62,6 +63,7 @@ export function createClient({
walletAccounts: walletAccounts(client),
transactions: transactions(client),
tokenAuths: tokenAuths(client),
request: request(client),
};
return api;
}
Expand Down
19 changes: 18 additions & 1 deletion src/resources/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
SingleUser,
ListBatchTransactions,
AccountIdRequestBody,
SingleItem,
SingleItem, AsyncMakePaymentBody,
} from '../types';

export default (client: Client) => ({
Expand Down Expand Up @@ -237,6 +237,23 @@ export default (client: Client) => ({
secure: true,
}),

/**
* @description Make a payment for an **Item**. Pass the `:account_id` of a **Bank Account** or a **Card Account** associated with the **Item’s** buyer. The **Item** state will transition to one of `payment_held`, `payment_pending` or `completed` for an **Express** or **Approve** payment type.
*
* @tags Item Actions
* @name AsyncMakePaymentBody
* @summary Make Payment (async)
* @request PATCH:/items/{id}/make_payment
* @secure
*/
makeAsyncPayment: (id: string, data: AccountIdRequestBody) =>
client.request<AsyncMakePaymentBody>({
url: `/items/${id}/make_payment`,
method: 'PATCH',
data,
secure: true,
}),

/**
* @description Cancel an **Item**. This will transition the **Item** state to `cancelled`. **Items** can only be cancelled if they haven’t been actioned in any other way.
*
Expand Down
51 changes: 51 additions & 0 deletions src/resources/request.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { Client } from '../client';

export default (client: Client) => ({
/**
* @description Show request status for async payment using a given `:id`.
*
* @tags Request
* @name showRequestStatus
* @summary Show request status for async payment
* @request GET:/request/${id}/status
* @secure
*/
showRequestStatus: (id: string) =>
client.request<any>({
url: `/request/${id}/status`,
method: 'GET',
secure: true,
}),

/**
* @description Show callbacks registered for async payment using a given `:id`.
*
* @tags Request
* @name showRequestCallbacks
* @summary Show callbacks for async payment
* @request GET:/request/${id}/callbacks
* @secure
*/
showRequestCallbacks: (id: string) =>
client.request<any>({
url: `/request/${id}/callbacks`,
method: 'GET',
secure: true,
}),

/**
* @description Used for checking zai callbacks with the path they provided`.
*
* @tags Request
* @name showRequestCallbacks
* @summary GET using the path provided
* @request GET:/${path}
* @secure
*/
getWithPath: (path: string) =>
client.request<any>({
url: path,
method: 'GET',
secure: true,
}),
});
10 changes: 10 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2209,3 +2209,13 @@ export interface ReleasePaymentRequestBody {
*/
flag_release?: boolean;
}

export interface AsyncMakePaymentBody {
last_updated?: string;
submission_count?: number;
message?: string;
links?: {
status?: string;
callbacks?: string;
}
}

0 comments on commit 3c824d1

Please sign in to comment.