paystackly
Version:
A Typescript/Javascript library written on top of paystack.
314 lines (313 loc) • 11.3 kB
TypeScript
export interface BasePaystackResponse {
status: boolean;
message: string;
}
export interface BasePaystackErrorResponse {
status: false;
message: string;
}
export interface BasePaystackSuccessResponse<T> {
status: true;
message: string;
data: T;
}
export type BaseResponse<T> = BasePaystackResponse & (BasePaystackErrorResponse | BasePaystackSuccessResponse<T>);
export interface PayStackQueryOptions {
hostname: string;
port?: 443 | number;
path: string;
method: HTTP_METHODS;
headers: {
Authorization: string;
};
body?: Record<string, string | number>;
}
export type BankType = "nuban";
export type PayStackCurrency = "NGN" | "GHS" | "ZAR" | "USD";
export type HTTP_METHODS = "GET" | "HEAD" | "POST" | "PUT" | "PATH" | "DELETE";
export type Country = "ghana" | "nigeria" | "south africa";
export type CardBrand = "American Express" | "Discover" | " Mastercard" | "Visa";
export type GhanaBankCodes = "030100" | "280100" | "080100" | "ATL" | "070101" | "210100" | "010100" | "300335" | "270100" | "140100" | "340100" | "130100" | "200100" | "240100" | "170100" | "330100" | "040100" | "230100" | "MTN" | "050100" | "360100" | "180100" | "110100" | "300361" | "090100" | "190100" | "020100" | "060100" | "100100" | "VOD" | "120100";
type NigerianBankCodes = "120001" | "801" | "51204" | "51312" | "044" | "063" | "602" | "50036" | "120004" | "51336" | "035A" | "090629" | "50926" | "51341" | "50083" | "401" | "MFB50094" | "51229" | "50117" | "50931" | "FC40163" | "565" | "865" | "50823" | "50171" | "312" | "023" | "50910" | "50204" | "559" | "FC40128" | "51297" | "50162" | "050" | "50263" | "098" | "50126" | "51318" | "070" | "51314" | "011" | "214" | "413" | "50315" | "501" | "812" | "00103" | "100022" | "50739" | "562" | "058" | "51251" | "50383" | "030" | "120002" | "51244" | "50439" | "50442" | "50453" | "50457" | "301" | "50502" | "082" | "50200" | "50211" | "90052" | "50549" | "031" | "303" | "50563" | "50304" | "50515" | "120003" | "107" | "100002" | "999991" | "104" | "311" | "999992" | "50743" | "51146" | "50746" | "268" | "076" | "50864" | "105" | "101" | "51293" | "502" | "90067" | "51286" | "50767" | "125" | "51113" | "951113" | "40165" | "50582" | "51062" | "50800" | "51310" | "221" | "068" | "51253" | "232" | "100" | "50968" | "302" | "090560" | "51269" | "51211" | "102" | "100039" | "50840" | "MFB51322" | "50870" | "50871" | "51316" | "032" | "033" | "215" | "566" | "51355" | "035" | "057";
type SouthAfricanBankCodes = "632005" | "430000" | "800000" | "888000" | "462005" | "470010" | "350005" | "679000" | "591000" | "589000" | "250655" | "201419" | "584000" | "587000" | "580105" | "432000" | "450105" | "198765" | "585001" | "261251" | "222026" | "683000" | "351005" | "410105" | "051001" | "730020" | "678910" | "431010" | "588000";
export type BankCodes = GhanaBankCodes | NigerianBankCodes | SouthAfricanBankCodes;
export interface BaseGetBankResponse {
name: string;
slug: string;
code: string;
longcode: string;
gateway: null | string;
pay_with_bank: boolean;
active: boolean;
is_deleted: boolean;
country: string;
currency: PayStackCurrency;
type: string;
id: number;
createdAt: Date;
updatedAt: Date;
}
export interface GetBanksQueryParams {
/**
* The country from which to obtain the list of supported banks. e.g country=ghana or country=nigeria:
*
* **Note**: Make sure country name is in lowercase
*/
country?: Country;
/**
* Flag to enable cursor pagination on the endpoint
*/
use_cursor?: boolean;
/**
*The number of objects to return per page. Defaults to 50, and limited to 100 records per page.
*/
perPage?: number;
/**
* A flag to filter for banks a customer can pay directly from
*/
pay_with_bank?: boolean;
/**
* A flag to filter for available banks a customer can make a transfer to complete a payment
*/
pay_with_bank_transfer?: boolean;
/**
*A cursor that indicates your place in the list. It can be used to fetch the next page of the list
*/
next?: string;
/**
*A cursor that indicates your place in the list. It should be used to fetch the previous page of the list after an intial next request
*/
previous?: string;
/**
* The gateway type of the bank. It can be one of these: [emandate, digitalbankmandate]
*
*/
gateway?: string;
/**
* Type of financial channel. For Ghanaian channels, please use either mobile_money for mobile money channels OR ghipps for bank channels
*/
type?: string;
/**
* Any of NGN, USD, GHS or ZAR
*/
currency?: PayStackCurrency;
}
export interface GetBanksResponse extends BasePaystackResponse {
data: BaseGetBankResponse[];
}
export interface GetCountriesResponse extends BasePaystackResponse {
id: number;
active_for_dashboard_onboarding: boolean;
name: string;
iso_code: string;
default_currency_code: PayStackCurrency;
integration_defaults: any;
calling_code: string;
pilot_mode: boolean;
relationships: {
currency: {
type: string;
data: PayStackCurrency[];
supported_currencies: {
NGN: {
bank: {
bank_type: BankType;
branch_code: boolean;
account_name: boolean;
account_verification_required: boolean;
account_number_label: string;
account_number_pattern: {
exact_match: boolean;
pattern: string;
};
documents: any[];
show_account_number_tooltip: boolean;
};
};
USD: {
bank: {
bank_type: BankType;
required_fields: string[];
branch_code: boolean;
account_name: boolean;
account_verification_required: true;
account_number_label: string;
account_number_pattern: {
exact_match: boolean;
pattern: string;
};
documents: any[];
notices: string[];
};
};
};
};
integration_feature: {
type: string;
data: any[];
};
integration_type: {
type: string;
data: string[];
};
payment_method: {
type: string;
data: string[];
};
};
}
export interface VerifyNumberQueryParams {
/**
* Account number
*/
account_number: string;
/**
* Bank code - you can use the **getBanks** method to retrieve a list of banks
*/
bank_code: BankCodes;
}
export type VerifyNumberResponse = (BasePaystackResponse & BasePaystackErrorResponse) | (BasePaystackSuccessResponse<{
data: {
account_number: string;
account_name: string;
bank_id: number;
};
}>);
export interface CardBINResponse extends BasePaystackResponse {
data: {
bin: string;
brand: CardBrand;
sub_brand: string;
country_code: string;
country_name: string;
card_type: string;
bank: string;
linked_bank_id: number;
};
}
export interface BaseTransactionPayload {
/**
* Customer's email address
*
*/
email: string;
/**
* The transaction currency (NGN, GHS, ZAR or USD). Defaults to your integration currency.
*
*/
currency?: PayStackCurrency;
/**
* Amount you're requesting from the client and it should be in kobo if currency is NGN, pesewas, if currency is GHS, and cents, if currency is ZAR
*
*/
amount: number;
/**
*Unique transaction reference. Only -, ., = and alphanumeric characters allowed.
*
*/
reference?: string | any;
/**
* Fully qualified url, e.g. https://example.com/ . Use this to override the callback url provided on the dashboard for this transaction
*
*/
metadata?: {
cart_id: number;
custom_fields: {
display_name: string;
variable_name: string;
value: number | string;
}[];
};
/**
* An array of payment channels to control what channels you want
* to make available to the user to make a payment with.
* Available channels include: ["card", "bank", "ussd", "qr", "mobile_money", "bank_transfer", "eft"]
*
*/
channels?: "card" | "bank" | "ussd" | "qr" | "mobile_money" | "bank_transfer" | "eft"[];
/**
* The code for the subaccount that owns the payment. e.g. ACCT_8f4s1eq7ml6rlzj
*
*/
subaccount?: string;
/**
*An amount used to override the split
configuration for a single split payment.
If set, the amount specified goes to the main
account regardless of the split configuration.
*/
transaction_charge?: number;
/**
* Who bears Paystack charges? account or subaccount (defaults to account).
*
*/
bearer?: string;
}
export interface BaseQuery {
/**
* Specify how many records you want to retrieve per page. If not specify we use a default value of 50.
*/
perPage?: number;
/**
* Specify exactly what page you want to retrieve. If not specify we use a default value of 1.
*/
page?: number;
/**
* A timestamp from which to start listing e.g. 2016-09-24T00:00:05.000Z, 2016-09-21
*/
from?: Date;
/**
* A timestamp from which to end listing e.g. 2016-09-24T00:00:05.000Z, 2016-09-21
*/
to?: Date;
}
export interface PaginationMetadata {
meta: {
total: number;
skipped: number;
perPage: number;
page: number;
pageCount: number;
};
}
export interface Authorization {
authorization_code: string;
bin: string;
last4: string;
exp_month: string;
exp_year: string;
channel: string;
card_type: string;
bank: string;
country_code: string;
brand: string;
reusable: boolean;
signature: string;
account_name: string | null;
}
export interface BaseCustomer {
id: number;
integration: number;
first_name: string | null;
last_name: string | null;
email: string;
phone: string | null;
metadata: Record<string, any>;
domain: string;
customer_code: string;
risk_action: string;
}
export interface ChargeAuthorizationPayload extends BaseTransactionPayload {
/**
* Valid authorization code to charge
*/
authorization_code: string;
/**
* If you are making a scheduled charge call,
* it is a good idea to queue them so the processing system does
* not get overloaded causing transaction processing errors.
* Send queue:true to take advantage of our queued charging.
*/
queue?: boolean;
}
export {};