paystack-sdk 1.0.4 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/charge/charge.d.ts +28 -0
- package/dist/charge/charge.js +36 -0
- package/dist/charge/index.d.ts +2 -0
- package/dist/charge/index.js +2 -0
- package/dist/charge/interface.d.ts +143 -0
- package/dist/charge/interface.js +1 -0
- package/dist/index.d.ts +1 -2
- package/dist/index.js +5 -6
- package/dist/paystack.d.ts +4 -2
- package/dist/paystack.js +10 -10
- package/dist/plan/index.d.ts +2 -0
- package/dist/plan/index.js +2 -0
- package/dist/plan/interface.d.ts +172 -0
- package/dist/plan/interface.js +2 -0
- package/dist/plan/plan.d.ts +53 -0
- package/dist/plan/plan.js +55 -0
- package/dist/transaction/index.d.ts +2 -0
- package/dist/transaction/index.js +2 -0
- package/dist/transaction/interface.d.ts +166 -0
- package/dist/transaction/interface.js +2 -0
- package/dist/transaction/transaction.d.ts +29 -0
- package/dist/transaction/transaction.js +31 -0
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -29,3 +29,4 @@ All methods use promise meaning you can either use the `async...await` or `then.
|
|
|
29
29
|
### Available Docs
|
|
30
30
|
- [Charge](https://github.com/en1tan/paystack-node/blob/main/src/charge/README.md)
|
|
31
31
|
- [Transaction](https://github.com/en1tan/paystack-node/blob/main/src/transaction/README.md)
|
|
32
|
+
- [Plan](https://github.com/en1tan/paystack-node/blob/main/src/plan/README.md)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Axios } from 'axios';
|
|
2
|
+
import { ChargeCreated, CreateCharge, SubmitAddress, SubmitBirthday, SubmitOTP, SubmitPhone, SubmitPIN } from '.';
|
|
3
|
+
interface BadRequest {
|
|
4
|
+
status: boolean;
|
|
5
|
+
message: string;
|
|
6
|
+
data: null;
|
|
7
|
+
}
|
|
8
|
+
export interface ICharge {
|
|
9
|
+
create(data: CreateCharge): Promise<ChargeCreated | BadRequest>;
|
|
10
|
+
submitPIN(data: SubmitPIN): Promise<ChargeCreated | BadRequest>;
|
|
11
|
+
submitOTP(data: SubmitOTP): Promise<ChargeCreated | BadRequest>;
|
|
12
|
+
submitPhone(data: SubmitPhone): Promise<ChargeCreated | BadRequest>;
|
|
13
|
+
submitBirthday(data: SubmitBirthday): Promise<ChargeCreated | BadRequest>;
|
|
14
|
+
submitAddress(data: SubmitAddress): Promise<ChargeCreated | BadRequest>;
|
|
15
|
+
checkPending(reference: string): Promise<ChargeCreated | BadRequest>;
|
|
16
|
+
}
|
|
17
|
+
export declare class Charge implements ICharge {
|
|
18
|
+
private http;
|
|
19
|
+
constructor(http: Axios);
|
|
20
|
+
create(data: CreateCharge): Promise<ChargeCreated | BadRequest>;
|
|
21
|
+
submitPIN(data: SubmitPIN): Promise<ChargeCreated | BadRequest>;
|
|
22
|
+
submitOTP(data: SubmitOTP): Promise<ChargeCreated | BadRequest>;
|
|
23
|
+
submitPhone(data: SubmitPhone): Promise<ChargeCreated | BadRequest>;
|
|
24
|
+
submitBirthday(data: SubmitBirthday): Promise<ChargeCreated | BadRequest>;
|
|
25
|
+
submitAddress(data: SubmitAddress): Promise<ChargeCreated | BadRequest>;
|
|
26
|
+
checkPending(reference: string): Promise<ChargeCreated | BadRequest>;
|
|
27
|
+
}
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export class Charge {
|
|
2
|
+
http;
|
|
3
|
+
constructor(http) {
|
|
4
|
+
this.http = http;
|
|
5
|
+
}
|
|
6
|
+
async create(data) {
|
|
7
|
+
const response = await this.http.post('/charge', JSON.stringify(data));
|
|
8
|
+
return JSON.parse(response.data);
|
|
9
|
+
}
|
|
10
|
+
async submitPIN(data) {
|
|
11
|
+
const response = await this.http.post('/charge/submit_pin', JSON.stringify(data));
|
|
12
|
+
return JSON.parse(response.data);
|
|
13
|
+
}
|
|
14
|
+
async submitOTP(data) {
|
|
15
|
+
const response = await this.http.post('/charge/submit_otp', JSON.stringify(data));
|
|
16
|
+
return JSON.parse(response.data);
|
|
17
|
+
}
|
|
18
|
+
async submitPhone(data) {
|
|
19
|
+
const response = await this.http.post('/charge/submit_phone', JSON.stringify(data));
|
|
20
|
+
return JSON.parse(response.data);
|
|
21
|
+
}
|
|
22
|
+
async submitBirthday(data) {
|
|
23
|
+
const response = await this.http.post('/charge/submit_birthday', JSON.stringify(data));
|
|
24
|
+
return JSON.parse(response.data);
|
|
25
|
+
}
|
|
26
|
+
async submitAddress(data) {
|
|
27
|
+
const response = await this.http.post('/charge/submit_address', JSON.stringify(data));
|
|
28
|
+
return JSON.parse(response.data);
|
|
29
|
+
}
|
|
30
|
+
async checkPending(reference) {
|
|
31
|
+
const response = await this.http.get('/charge/submit_address', {
|
|
32
|
+
params: { reference },
|
|
33
|
+
});
|
|
34
|
+
return JSON.parse(response.data);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
export interface CreateCharge {
|
|
2
|
+
email: string;
|
|
3
|
+
amount: string;
|
|
4
|
+
bank?: {
|
|
5
|
+
code: string;
|
|
6
|
+
account_number: string;
|
|
7
|
+
};
|
|
8
|
+
authorization_code?: string;
|
|
9
|
+
pin?: string;
|
|
10
|
+
metadata?: Record<string, unknown>;
|
|
11
|
+
reference?: string;
|
|
12
|
+
ussd?: string;
|
|
13
|
+
mobile_money?: string;
|
|
14
|
+
device_id?: string;
|
|
15
|
+
birthday?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface Submit {
|
|
18
|
+
reference: string;
|
|
19
|
+
}
|
|
20
|
+
export interface SubmitPIN extends Submit {
|
|
21
|
+
pin: string;
|
|
22
|
+
}
|
|
23
|
+
export interface SubmitOTP extends Submit {
|
|
24
|
+
otp: string;
|
|
25
|
+
}
|
|
26
|
+
export interface SubmitPhone extends Submit {
|
|
27
|
+
phone: string;
|
|
28
|
+
}
|
|
29
|
+
export interface SubmitBirthday extends Submit {
|
|
30
|
+
birthday: Date;
|
|
31
|
+
}
|
|
32
|
+
export interface SubmitAddress extends Submit {
|
|
33
|
+
address: string;
|
|
34
|
+
city: string;
|
|
35
|
+
state: string;
|
|
36
|
+
zip_code: string;
|
|
37
|
+
}
|
|
38
|
+
export interface ChargeCreated {
|
|
39
|
+
status: boolean;
|
|
40
|
+
message: string;
|
|
41
|
+
data: ChargeCreatedOk | ChargeCreatedResponseWithAddress | ChargeCreatedResponseWithPending | ChargeCreatedResponseWithBankAuth | ChargeCreatedResponseWithMobileMoney | ChargeCreatedResponseWithUSSD | ChargeCreatedResponseWithOTP | ChargeCreatedResponseWithPin | ChargeCreatedResponseWithPhone | ChargeFailed;
|
|
42
|
+
}
|
|
43
|
+
interface ChargeCreatedOk {
|
|
44
|
+
amount: number;
|
|
45
|
+
currency: string;
|
|
46
|
+
transaction_date: string;
|
|
47
|
+
status: string;
|
|
48
|
+
reference: string;
|
|
49
|
+
domain: string;
|
|
50
|
+
metadata: Record<string, unknown>;
|
|
51
|
+
gateway_response: string;
|
|
52
|
+
message: string;
|
|
53
|
+
channel: string;
|
|
54
|
+
ip_address: string;
|
|
55
|
+
log: any | null;
|
|
56
|
+
fees: number;
|
|
57
|
+
authorization: Authorization;
|
|
58
|
+
customer: Customer;
|
|
59
|
+
display_text: string;
|
|
60
|
+
plan: string | null;
|
|
61
|
+
}
|
|
62
|
+
interface ChargeCreatedResponseWithPending {
|
|
63
|
+
reference: string;
|
|
64
|
+
status: string;
|
|
65
|
+
}
|
|
66
|
+
interface ChargeCreatedResponseWithAddress {
|
|
67
|
+
display_text: string;
|
|
68
|
+
reference: string;
|
|
69
|
+
status: string;
|
|
70
|
+
country_code: string;
|
|
71
|
+
}
|
|
72
|
+
interface ChargeCreatedResponseWithMobileMoney {
|
|
73
|
+
amount: number;
|
|
74
|
+
channel: string;
|
|
75
|
+
created_at: Date;
|
|
76
|
+
currency: string;
|
|
77
|
+
domain: string;
|
|
78
|
+
fees: number;
|
|
79
|
+
gateway_response: string;
|
|
80
|
+
id: number;
|
|
81
|
+
ip_address: string;
|
|
82
|
+
message: string;
|
|
83
|
+
paid_at: Date;
|
|
84
|
+
reference: string;
|
|
85
|
+
status: string;
|
|
86
|
+
transaction_date: Date;
|
|
87
|
+
authorization: Authorization;
|
|
88
|
+
customer: Customer;
|
|
89
|
+
}
|
|
90
|
+
interface ChargeCreatedResponseWithUSSD {
|
|
91
|
+
reference: string;
|
|
92
|
+
status: string;
|
|
93
|
+
display_text: string;
|
|
94
|
+
ussd_code: string;
|
|
95
|
+
}
|
|
96
|
+
interface ChargeCreatedResponseWithBirthday {
|
|
97
|
+
reference: string;
|
|
98
|
+
status: string;
|
|
99
|
+
display_text: string;
|
|
100
|
+
}
|
|
101
|
+
interface ChargeCreatedResponseWithPhone extends ChargeCreatedResponseWithBirthday {
|
|
102
|
+
}
|
|
103
|
+
interface ChargeCreatedResponseWithBankAuth {
|
|
104
|
+
refernce: string;
|
|
105
|
+
uri: string;
|
|
106
|
+
status: string;
|
|
107
|
+
}
|
|
108
|
+
interface ChargeCreatedResponseWithPin extends ChargeCreatedResponseWithPending {
|
|
109
|
+
}
|
|
110
|
+
interface ChargeCreatedResponseWithOTP extends ChargeCreatedResponseWithPending {
|
|
111
|
+
display_text: string;
|
|
112
|
+
}
|
|
113
|
+
interface ChargeFailed {
|
|
114
|
+
refernce: string;
|
|
115
|
+
message: string;
|
|
116
|
+
status: string;
|
|
117
|
+
}
|
|
118
|
+
export interface Authorization {
|
|
119
|
+
authorization_code: string;
|
|
120
|
+
card_type: string;
|
|
121
|
+
bank: string;
|
|
122
|
+
bin: string;
|
|
123
|
+
brand: string;
|
|
124
|
+
channel: string;
|
|
125
|
+
country_code: string;
|
|
126
|
+
exp_month: string;
|
|
127
|
+
exp_year: string;
|
|
128
|
+
last4: string;
|
|
129
|
+
reusable: boolean;
|
|
130
|
+
signature: string;
|
|
131
|
+
account_name: string;
|
|
132
|
+
}
|
|
133
|
+
export interface Customer {
|
|
134
|
+
customer_code: string;
|
|
135
|
+
email: string;
|
|
136
|
+
id: number;
|
|
137
|
+
risk_action: string;
|
|
138
|
+
first_name?: string;
|
|
139
|
+
last_name?: string;
|
|
140
|
+
phone?: string | null;
|
|
141
|
+
metadata?: Record<string, unknown> | null;
|
|
142
|
+
}
|
|
143
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export = Paystack;
|
|
1
|
+
export {};
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
module.exports = paystack_1.default;
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
// @ts-ignore
|
|
3
|
+
import Paystack from './paystack';
|
|
4
|
+
// @ts-ignore
|
|
5
|
+
module.export = Paystack;
|
package/dist/paystack.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { ICharge } from './charge
|
|
1
|
+
import { ICharge } from './charge';
|
|
2
|
+
import { Plan } from './plan/plan';
|
|
2
3
|
import { ITransaction } from './transaction/transaction';
|
|
3
4
|
/**
|
|
4
5
|
* Paystack SDK
|
|
@@ -6,8 +7,9 @@ import { ITransaction } from './transaction/transaction';
|
|
|
6
7
|
*/
|
|
7
8
|
export default class Paystack {
|
|
8
9
|
readonly key: string;
|
|
9
|
-
private http;
|
|
10
|
+
private readonly http;
|
|
10
11
|
charge: ICharge;
|
|
11
12
|
transaction: ITransaction;
|
|
13
|
+
plan: Plan;
|
|
12
14
|
constructor(key: string);
|
|
13
15
|
}
|
package/dist/paystack.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const transaction_1 = require("./transaction/transaction");
|
|
1
|
+
import { Axios } from 'axios';
|
|
2
|
+
import { Charge } from './charge';
|
|
3
|
+
import { Plan } from './plan/plan';
|
|
4
|
+
import { Transaction } from './transaction/transaction';
|
|
6
5
|
/**
|
|
7
6
|
* Paystack SDK
|
|
8
7
|
* @author Asaju Enitan <@en1tan>
|
|
9
8
|
*/
|
|
10
|
-
class Paystack {
|
|
9
|
+
export default class Paystack {
|
|
11
10
|
key;
|
|
12
11
|
http;
|
|
13
12
|
charge;
|
|
14
13
|
transaction;
|
|
14
|
+
plan;
|
|
15
15
|
constructor(key) {
|
|
16
16
|
this.key = key;
|
|
17
|
-
this.http = new
|
|
17
|
+
this.http = new Axios({
|
|
18
18
|
baseURL: 'https://api.paystack.co',
|
|
19
19
|
headers: {
|
|
20
20
|
Authorization: `Bearer ${this.key}`,
|
|
@@ -22,8 +22,8 @@ class Paystack {
|
|
|
22
22
|
},
|
|
23
23
|
responseType: 'json',
|
|
24
24
|
});
|
|
25
|
-
this.charge = new
|
|
26
|
-
this.transaction = new
|
|
25
|
+
this.charge = new Charge(this.http);
|
|
26
|
+
this.transaction = new Transaction(this.http);
|
|
27
|
+
this.plan = new Plan(this.http);
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
|
-
exports.default = Paystack;
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { Authorization } from '../charge';
|
|
2
|
+
import { Meta } from '../transaction/interface';
|
|
3
|
+
export interface CreatePlan {
|
|
4
|
+
/**
|
|
5
|
+
* Name of plan
|
|
6
|
+
*/
|
|
7
|
+
name: string;
|
|
8
|
+
/**
|
|
9
|
+
* Amount should be in **kobo** if currency is
|
|
10
|
+
* `NGN`, **pesewas**, if currency is `GHS`, and
|
|
11
|
+
* **cents** if currency is `ZAR`
|
|
12
|
+
*/
|
|
13
|
+
amount: number;
|
|
14
|
+
/**
|
|
15
|
+
* Interval in words,
|
|
16
|
+
* Valid intervals are `daily`,`weekly`,`monthly`,`biannually`,`annually`
|
|
17
|
+
*/
|
|
18
|
+
interval?: string;
|
|
19
|
+
/**
|
|
20
|
+
* A description for this plan
|
|
21
|
+
*/
|
|
22
|
+
description?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Set to false if you don't want invoices to be sent
|
|
25
|
+
* to your custmers
|
|
26
|
+
*/
|
|
27
|
+
send_invoices?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Set to false if you don't want text messages to be sent
|
|
30
|
+
* to your customers
|
|
31
|
+
*/
|
|
32
|
+
send_sms?: string;
|
|
33
|
+
/**
|
|
34
|
+
* Currency in which amount is set. Allowed values are
|
|
35
|
+
* NGN, GHS, ZAR or USD
|
|
36
|
+
*/
|
|
37
|
+
currency?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Number of invoices to raise during subscription to this plan.
|
|
40
|
+
* Can be overriden by specifying an `invoice_limit` while subscribing
|
|
41
|
+
*/
|
|
42
|
+
invoice_limit?: number;
|
|
43
|
+
}
|
|
44
|
+
export interface PlanResponse {
|
|
45
|
+
status: boolean;
|
|
46
|
+
message: string;
|
|
47
|
+
data: PlanCreated | Plan | Plans;
|
|
48
|
+
meta?: Meta;
|
|
49
|
+
}
|
|
50
|
+
interface PlanCreated {
|
|
51
|
+
name: string;
|
|
52
|
+
amount: number;
|
|
53
|
+
interval: string;
|
|
54
|
+
integration: number;
|
|
55
|
+
domain: string;
|
|
56
|
+
plan_code: string;
|
|
57
|
+
description: any;
|
|
58
|
+
send_invoices: boolean;
|
|
59
|
+
send_sms: boolean;
|
|
60
|
+
hosted_page: boolean;
|
|
61
|
+
hosted_page_url: any;
|
|
62
|
+
hosted_page_summary: any;
|
|
63
|
+
currency: string;
|
|
64
|
+
migrate: boolean;
|
|
65
|
+
is_archived: boolean;
|
|
66
|
+
id: number;
|
|
67
|
+
createdAt: Date;
|
|
68
|
+
updatedAt: Date;
|
|
69
|
+
}
|
|
70
|
+
interface Plan extends PlanCreated {
|
|
71
|
+
subscriptions: Subscription[];
|
|
72
|
+
is_deleted: boolean;
|
|
73
|
+
pages_count: number;
|
|
74
|
+
subscribers_count: number;
|
|
75
|
+
subscriptions_count: number;
|
|
76
|
+
active_subscriptions_count: number;
|
|
77
|
+
total_revenue: number;
|
|
78
|
+
subscribers: Subscribers[];
|
|
79
|
+
}
|
|
80
|
+
interface Plans extends PlanCreated {
|
|
81
|
+
subscriptions: Subscription[];
|
|
82
|
+
}
|
|
83
|
+
interface Subscribers {
|
|
84
|
+
}
|
|
85
|
+
interface Subscription {
|
|
86
|
+
customer: number;
|
|
87
|
+
plan: number;
|
|
88
|
+
integration: number;
|
|
89
|
+
domain: string;
|
|
90
|
+
start: number;
|
|
91
|
+
status: string;
|
|
92
|
+
quantity: number;
|
|
93
|
+
amount: number;
|
|
94
|
+
subscription_code: string;
|
|
95
|
+
email_token: string;
|
|
96
|
+
authorization: Authorization;
|
|
97
|
+
easy_cron_id: any;
|
|
98
|
+
cron_expression: string;
|
|
99
|
+
next_payment_date: Date;
|
|
100
|
+
open_invoice: any;
|
|
101
|
+
id: number;
|
|
102
|
+
createdAt: Date;
|
|
103
|
+
updatedAt: Date;
|
|
104
|
+
}
|
|
105
|
+
export interface ListPlanQueryParams {
|
|
106
|
+
/**
|
|
107
|
+
* Specify how many records you want to retrieve per page.
|
|
108
|
+
* If not specify we use a default value of 50.
|
|
109
|
+
*/
|
|
110
|
+
perPage?: number;
|
|
111
|
+
/**
|
|
112
|
+
* Specify exactly what page you want to retrieve.
|
|
113
|
+
* If not specify we use a default value of 1.
|
|
114
|
+
*/
|
|
115
|
+
page?: number;
|
|
116
|
+
/**
|
|
117
|
+
* Filter transactions by status ('failed', 'success', 'abandoned')
|
|
118
|
+
*/
|
|
119
|
+
status?: string;
|
|
120
|
+
/**
|
|
121
|
+
* Filter transactions by amount.
|
|
122
|
+
* Specify the amount (in **kobo** if currency is `NGN`,
|
|
123
|
+
* **pesewas**, if currency is `GHS`,
|
|
124
|
+
* and **cents**, if currency is `ZAR`)
|
|
125
|
+
*/
|
|
126
|
+
amount: number;
|
|
127
|
+
/**
|
|
128
|
+
* Filter list by plans with specified interval
|
|
129
|
+
*/
|
|
130
|
+
interval?: number;
|
|
131
|
+
}
|
|
132
|
+
export interface UpdatePlan {
|
|
133
|
+
/**
|
|
134
|
+
* Name of plan
|
|
135
|
+
*/
|
|
136
|
+
name: string;
|
|
137
|
+
/**
|
|
138
|
+
* Amount should be in `kobo` if currency is
|
|
139
|
+
* NGN and `pesewas` for GHS
|
|
140
|
+
*/
|
|
141
|
+
amount: number;
|
|
142
|
+
/**
|
|
143
|
+
* Interval in words. Valid intervals are
|
|
144
|
+
* `hourly`,`daily`,weekly`,`monthly`,`biannually`,`annually`.
|
|
145
|
+
*/
|
|
146
|
+
interval: string;
|
|
147
|
+
/**
|
|
148
|
+
* A description for this plan
|
|
149
|
+
*/
|
|
150
|
+
description?: string;
|
|
151
|
+
/**
|
|
152
|
+
* Set to false if you don't want invoices to be sent
|
|
153
|
+
* to your custmers
|
|
154
|
+
*/
|
|
155
|
+
send_invoices?: boolean;
|
|
156
|
+
/**
|
|
157
|
+
* Set to false if you don't want text messages to be sent
|
|
158
|
+
* to your customers
|
|
159
|
+
*/
|
|
160
|
+
send_sms?: string;
|
|
161
|
+
/**
|
|
162
|
+
* Currency in which amount is set. Allowed values are
|
|
163
|
+
* NGN, GHS, ZAR or USD
|
|
164
|
+
*/
|
|
165
|
+
currency?: string;
|
|
166
|
+
/**
|
|
167
|
+
* Number of invoices to raise during subscription to this plan.
|
|
168
|
+
* Can be overriden by specifying an `invoice_limit` while subscribing
|
|
169
|
+
*/
|
|
170
|
+
invoice_limit?: number;
|
|
171
|
+
}
|
|
172
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Axios } from 'axios';
|
|
2
|
+
import { CreatePlan, ListPlanQueryParams, PlanResponse, UpdatePlan } from './interface';
|
|
3
|
+
interface BadRequest {
|
|
4
|
+
status: boolean;
|
|
5
|
+
message: string;
|
|
6
|
+
data: null;
|
|
7
|
+
}
|
|
8
|
+
export interface IPlan {
|
|
9
|
+
create(data: CreatePlan): Promise<PlanResponse | BadRequest>;
|
|
10
|
+
list(queryParams?: ListPlanQueryParams): Promise<PlanResponse | BadRequest>;
|
|
11
|
+
fetch(id: string): Promise<PlanResponse | BadRequest>;
|
|
12
|
+
update(id: string, data: UpdatePlan): Promise<PlanResponse | BadRequest>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* ## Plans
|
|
16
|
+
* The Plans API allows you create and manage installment
|
|
17
|
+
* payment options on your integration
|
|
18
|
+
* @class Plan
|
|
19
|
+
*/
|
|
20
|
+
export declare class Plan implements IPlan {
|
|
21
|
+
private http;
|
|
22
|
+
constructor(http: Axios);
|
|
23
|
+
/**
|
|
24
|
+
* ### Create Plan
|
|
25
|
+
* Create a plan on your integration
|
|
26
|
+
* @param {CreatePlan} data Body Param
|
|
27
|
+
* @returns {Promise<PlanResponse | BadRequest>}
|
|
28
|
+
*/
|
|
29
|
+
create(data: CreatePlan): Promise<PlanResponse | BadRequest>;
|
|
30
|
+
/**
|
|
31
|
+
* ### List Plans
|
|
32
|
+
* List plans available on your integration
|
|
33
|
+
* @param queryParams Query Parameters
|
|
34
|
+
* @returns {Promise<PlanResponse | BadRequest>}
|
|
35
|
+
*/
|
|
36
|
+
list(queryParams?: ListPlanQueryParams): Promise<PlanResponse | BadRequest>;
|
|
37
|
+
/**
|
|
38
|
+
* ### Fetch Plan
|
|
39
|
+
* Get details of a plan on your integration
|
|
40
|
+
* @param id The plan `ID` or `code` you want to fetch
|
|
41
|
+
* @returns {Promise<PlanResponse | BadRequest>}
|
|
42
|
+
*/
|
|
43
|
+
fetch(id: string): Promise<PlanResponse | BadRequest>;
|
|
44
|
+
/**
|
|
45
|
+
* ### Update Plan
|
|
46
|
+
* Update a plan details on your integration
|
|
47
|
+
* @param id Plans's `ID` or `code`
|
|
48
|
+
* @param {UpdatePlan} data Update Plan Data
|
|
49
|
+
* @returns {Promise<PlanResponse | BadRequest>}
|
|
50
|
+
*/
|
|
51
|
+
update(id: string, data: UpdatePlan): Promise<PlanResponse | BadRequest>;
|
|
52
|
+
}
|
|
53
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## Plans
|
|
3
|
+
* The Plans API allows you create and manage installment
|
|
4
|
+
* payment options on your integration
|
|
5
|
+
* @class Plan
|
|
6
|
+
*/
|
|
7
|
+
export class Plan {
|
|
8
|
+
http;
|
|
9
|
+
constructor(http) {
|
|
10
|
+
this.http = http;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* ### Create Plan
|
|
14
|
+
* Create a plan on your integration
|
|
15
|
+
* @param {CreatePlan} data Body Param
|
|
16
|
+
* @returns {Promise<PlanResponse | BadRequest>}
|
|
17
|
+
*/
|
|
18
|
+
async create(data) {
|
|
19
|
+
const response = await this.http.post('/plan', JSON.stringify(data));
|
|
20
|
+
return JSON.parse(response.data);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* ### List Plans
|
|
24
|
+
* List plans available on your integration
|
|
25
|
+
* @param queryParams Query Parameters
|
|
26
|
+
* @returns {Promise<PlanResponse | BadRequest>}
|
|
27
|
+
*/
|
|
28
|
+
async list(queryParams) {
|
|
29
|
+
const response = await this.http.get('/plan', {
|
|
30
|
+
params: { ...queryParams },
|
|
31
|
+
});
|
|
32
|
+
return JSON.parse(response.data);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* ### Fetch Plan
|
|
36
|
+
* Get details of a plan on your integration
|
|
37
|
+
* @param id The plan `ID` or `code` you want to fetch
|
|
38
|
+
* @returns {Promise<PlanResponse | BadRequest>}
|
|
39
|
+
*/
|
|
40
|
+
async fetch(id) {
|
|
41
|
+
const response = await this.http.get(`/plan/${id}`);
|
|
42
|
+
return JSON.parse(response.data);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* ### Update Plan
|
|
46
|
+
* Update a plan details on your integration
|
|
47
|
+
* @param id Plans's `ID` or `code`
|
|
48
|
+
* @param {UpdatePlan} data Update Plan Data
|
|
49
|
+
* @returns {Promise<PlanResponse | BadRequest>}
|
|
50
|
+
*/
|
|
51
|
+
async update(id, data) {
|
|
52
|
+
const response = await this.http.put(`/plan/${id}`, JSON.stringify(data));
|
|
53
|
+
return JSON.parse(response.data);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { Authorization, Customer } from '../charge';
|
|
2
|
+
export interface InitializeTransaction {
|
|
3
|
+
/**
|
|
4
|
+
* Amount should be in **kobo** if currency
|
|
5
|
+
* is `NGN`, **pesewas**, if the currency is `GHS` and
|
|
6
|
+
* **cents**, if currency is `ZAR`
|
|
7
|
+
*/
|
|
8
|
+
amount: string;
|
|
9
|
+
/**
|
|
10
|
+
* Customer's email address
|
|
11
|
+
*/
|
|
12
|
+
email: string;
|
|
13
|
+
/**
|
|
14
|
+
* The transaction currency (NGN, GHS, ZAR or USD).
|
|
15
|
+
* Defaults to your integration currency.
|
|
16
|
+
*/
|
|
17
|
+
currency?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Unique transaction reference. Only `-`,`.`,`_`
|
|
20
|
+
* and alphanumeric characters allowed
|
|
21
|
+
*/
|
|
22
|
+
reference?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Fully qualified url, e.g. https://example.com/.
|
|
25
|
+
* Use this to override the callback url provided on
|
|
26
|
+
* the dashboard for this transaction
|
|
27
|
+
*/
|
|
28
|
+
callback_url?: string;
|
|
29
|
+
/**
|
|
30
|
+
* If transaction is to create a subscription to a predefined plan,
|
|
31
|
+
* provide plan code here. This would invalidate the value provided
|
|
32
|
+
* in `amount`
|
|
33
|
+
*/
|
|
34
|
+
plan?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Number of times to charge customer during subscription to plan
|
|
37
|
+
*/
|
|
38
|
+
invoice_limit?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Stringified JSON object of custom data.
|
|
41
|
+
* Kindly check the [Metadata](https://paystack.com/docs/payments/metadata)
|
|
42
|
+
* page for more information.
|
|
43
|
+
*/
|
|
44
|
+
metadata?: Record<string, unknown>;
|
|
45
|
+
/**
|
|
46
|
+
* An array of payment channels to control what channels
|
|
47
|
+
* you want to make available to the user to make a payment
|
|
48
|
+
* with.
|
|
49
|
+
* @example ['card','bank','ussd','qr','mobile_money','bank_transfer']
|
|
50
|
+
*/
|
|
51
|
+
channels?: string[];
|
|
52
|
+
/**
|
|
53
|
+
* The split code of the transaction split.
|
|
54
|
+
* e.g `SPL_98WF13Eb3w`
|
|
55
|
+
*/
|
|
56
|
+
split_code?: string;
|
|
57
|
+
/**
|
|
58
|
+
* The code for the subaccount that owns the payment e.g `ACCT_8f4s1eq7m16rlzj`
|
|
59
|
+
*/
|
|
60
|
+
subaccount?: string;
|
|
61
|
+
/**
|
|
62
|
+
* A flat fee to charge the subaccount for this transaction ().
|
|
63
|
+
* This overrides the split percentage set when the subaccount
|
|
64
|
+
* was created. Ideally, you will need to use this if you are
|
|
65
|
+
* splitting in flat rates (since subaccount creation only allows
|
|
66
|
+
* for percentage split). e.g. `7000` for a 70 naira fiat fee.
|
|
67
|
+
*/
|
|
68
|
+
transaction_charge?: number;
|
|
69
|
+
/**
|
|
70
|
+
* Who bears Paystack charges?
|
|
71
|
+
* `account` or `subaccount` (defaults to `account`)
|
|
72
|
+
*/
|
|
73
|
+
bearer?: string;
|
|
74
|
+
}
|
|
75
|
+
export interface TransactionResponse {
|
|
76
|
+
status: boolean;
|
|
77
|
+
message: string;
|
|
78
|
+
data: TransactionInitializedOk | TransactionData | Transactions;
|
|
79
|
+
meta?: Meta;
|
|
80
|
+
}
|
|
81
|
+
interface TransactionInitializedOk {
|
|
82
|
+
authorization_url: string;
|
|
83
|
+
access_code: string;
|
|
84
|
+
reference: string;
|
|
85
|
+
}
|
|
86
|
+
interface TransactionData {
|
|
87
|
+
amount: number;
|
|
88
|
+
currency: string;
|
|
89
|
+
transaction_date: Date;
|
|
90
|
+
status: string;
|
|
91
|
+
reference: string;
|
|
92
|
+
domain: string;
|
|
93
|
+
metadata: number;
|
|
94
|
+
gateway_response: string;
|
|
95
|
+
message?: null;
|
|
96
|
+
channel: string;
|
|
97
|
+
ip_address: string;
|
|
98
|
+
log: {
|
|
99
|
+
time_spent: number;
|
|
100
|
+
attempt: number;
|
|
101
|
+
authentication: any;
|
|
102
|
+
errors: number;
|
|
103
|
+
success: boolean;
|
|
104
|
+
mobile: boolean;
|
|
105
|
+
input: [];
|
|
106
|
+
channel: any;
|
|
107
|
+
history: {
|
|
108
|
+
type: string;
|
|
109
|
+
message: string;
|
|
110
|
+
time: number;
|
|
111
|
+
}[];
|
|
112
|
+
};
|
|
113
|
+
fees: any;
|
|
114
|
+
authorization: Authorization;
|
|
115
|
+
customer: Customer;
|
|
116
|
+
pin: string;
|
|
117
|
+
required_amount: number;
|
|
118
|
+
}
|
|
119
|
+
interface Transactions extends TransactionData {
|
|
120
|
+
}
|
|
121
|
+
export interface ListTransactionQueryParams {
|
|
122
|
+
/**
|
|
123
|
+
* Specify how many records you want to retrieve per page.
|
|
124
|
+
* If not specify we use a default value of 50.
|
|
125
|
+
*/
|
|
126
|
+
perPage?: number;
|
|
127
|
+
/**
|
|
128
|
+
* Specify exactly what page you want to retrieve.
|
|
129
|
+
* If not specify we use a default value of 1.
|
|
130
|
+
*/
|
|
131
|
+
page?: number;
|
|
132
|
+
/**
|
|
133
|
+
* Specify an ID for the customer whose transactions
|
|
134
|
+
* you want to retrieve
|
|
135
|
+
*/
|
|
136
|
+
customer?: number;
|
|
137
|
+
/**
|
|
138
|
+
* Filter transactions by status ('failed', 'success', 'abandoned')
|
|
139
|
+
*/
|
|
140
|
+
status?: string;
|
|
141
|
+
/**
|
|
142
|
+
* A timestamp from which to start listing transaction
|
|
143
|
+
* e.g `2021-10-25T00.00.05.000z`, `2021-12-25`
|
|
144
|
+
*/
|
|
145
|
+
from: Date;
|
|
146
|
+
/**
|
|
147
|
+
* A timestamp from which to stop listing transaction
|
|
148
|
+
* e.g `2021-10-25T00.00.05.000z`, `2021-12-25`
|
|
149
|
+
*/
|
|
150
|
+
to: Date;
|
|
151
|
+
/**
|
|
152
|
+
* Filter transactions by amount.
|
|
153
|
+
* Specify the amount (in **kobo** if currency is `NGN`,
|
|
154
|
+
* **pesewas**, if currency is `GHS`,
|
|
155
|
+
* and **cents**, if currency is `ZAR`)
|
|
156
|
+
*/
|
|
157
|
+
amount: number;
|
|
158
|
+
}
|
|
159
|
+
export interface Meta {
|
|
160
|
+
total: number;
|
|
161
|
+
skipped: number;
|
|
162
|
+
perPage: number;
|
|
163
|
+
page: number;
|
|
164
|
+
pageCount: number;
|
|
165
|
+
}
|
|
166
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Axios } from 'axios';
|
|
2
|
+
import { InitializeTransaction, ListTransactionQueryParams, TransactionResponse } from './interface';
|
|
3
|
+
interface BadRequest {
|
|
4
|
+
status: boolean;
|
|
5
|
+
message: string;
|
|
6
|
+
data: null;
|
|
7
|
+
}
|
|
8
|
+
export interface ITransaction {
|
|
9
|
+
initialize(data: InitializeTransaction): Promise<TransactionResponse | BadRequest>;
|
|
10
|
+
verify(reference: string): Promise<TransactionResponse | BadRequest>;
|
|
11
|
+
list(queryParams: ListTransactionQueryParams): Promise<TransactionResponse | BadRequest>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* ## Tansactions
|
|
15
|
+
* The transaction API allows you create and manage
|
|
16
|
+
* payments on your integration
|
|
17
|
+
*/
|
|
18
|
+
export declare class Transaction implements ITransaction {
|
|
19
|
+
private http;
|
|
20
|
+
constructor(http: Axios);
|
|
21
|
+
/**
|
|
22
|
+
* Initialize a transaction
|
|
23
|
+
* @param {InitializeTransaction} data **Body Param**
|
|
24
|
+
*/
|
|
25
|
+
initialize(data: InitializeTransaction): Promise<TransactionResponse | BadRequest>;
|
|
26
|
+
verify(reference: string): Promise<TransactionResponse | BadRequest>;
|
|
27
|
+
list(queryParams: ListTransactionQueryParams): Promise<TransactionResponse | BadRequest>;
|
|
28
|
+
}
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## Tansactions
|
|
3
|
+
* The transaction API allows you create and manage
|
|
4
|
+
* payments on your integration
|
|
5
|
+
*/
|
|
6
|
+
export class Transaction {
|
|
7
|
+
http;
|
|
8
|
+
constructor(http) {
|
|
9
|
+
this.http = http;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Initialize a transaction
|
|
13
|
+
* @param {InitializeTransaction} data **Body Param**
|
|
14
|
+
*/
|
|
15
|
+
async initialize(data) {
|
|
16
|
+
const response = await this.http.post('/transaction/initialize', JSON.stringify(data));
|
|
17
|
+
return JSON.parse(response.data);
|
|
18
|
+
}
|
|
19
|
+
async verify(reference) {
|
|
20
|
+
const response = await this.http.get('/transaction/verify', {
|
|
21
|
+
params: { reference },
|
|
22
|
+
});
|
|
23
|
+
return JSON.parse(response.data);
|
|
24
|
+
}
|
|
25
|
+
async list(queryParams) {
|
|
26
|
+
const response = await this.http.get('/transaction', {
|
|
27
|
+
params: { ...queryParams },
|
|
28
|
+
});
|
|
29
|
+
return JSON.parse(response.data);
|
|
30
|
+
}
|
|
31
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "paystack-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "Paystack SDK written in Typescript",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"author": "Koderant",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"axios": "^0.24.0"
|
|
32
32
|
},
|
|
33
33
|
"files": [
|
|
34
|
-
"dist
|
|
34
|
+
"dist/**/*"
|
|
35
35
|
],
|
|
36
36
|
"keywords": [
|
|
37
37
|
"Paystack",
|
|
@@ -40,5 +40,6 @@
|
|
|
40
40
|
"repository": {
|
|
41
41
|
"type": "git",
|
|
42
42
|
"url": "git+https://github.com/en1tan/paystack-node.git"
|
|
43
|
-
}
|
|
43
|
+
},
|
|
44
|
+
"type": "module"
|
|
44
45
|
}
|