paystack-sdk 1.0.14 → 1.0.18
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 +8 -1
- package/dist/customer/customer.d.ts +60 -0
- package/dist/customer/customer.js +102 -0
- package/dist/customer/interface.d.ts +177 -0
- package/dist/customer/interface.js +13 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -2
- package/dist/paystack.d.ts +2 -0
- package/dist/paystack.js +2 -0
- package/dist/plan/plan.js +2 -2
- package/dist/transaction/interface.d.ts +4 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
# Paystack SDK
|
|
2
2
|
|
|
3
3
|
#### Why Another [Paystack](https://paystack.com) Package?
|
|
4
|
+
|
|
4
5
|
Other packages are either outdated or don't support types.
|
|
5
6
|
|
|
6
7
|
### Installation
|
|
8
|
+
|
|
7
9
|
For Yarn
|
|
8
10
|
`yarn add paystack-sdk`
|
|
9
11
|
|
|
@@ -11,7 +13,9 @@ For NPM
|
|
|
11
13
|
`npm install paystack-sdk`
|
|
12
14
|
|
|
13
15
|
### Usage
|
|
16
|
+
|
|
14
17
|
For Typescript
|
|
18
|
+
|
|
15
19
|
```
|
|
16
20
|
import Paystack from 'paystack-sdk';
|
|
17
21
|
|
|
@@ -19,6 +23,7 @@ const paystack = new Paystack("secret_key);
|
|
|
19
23
|
```
|
|
20
24
|
|
|
21
25
|
For Javscript
|
|
26
|
+
|
|
22
27
|
```
|
|
23
28
|
const Paystack = require('paystack-sdk');
|
|
24
29
|
const paystack = new Paystack("secret_key");
|
|
@@ -26,7 +31,9 @@ const paystack = new Paystack("secret_key");
|
|
|
26
31
|
|
|
27
32
|
All methods use promise meaning you can either use the `async...await` or `then...catch` or `try...catch`
|
|
28
33
|
|
|
29
|
-
### Available
|
|
34
|
+
### Available Functions
|
|
35
|
+
|
|
30
36
|
- [Charge](https://github.com/en1tan/paystack-node/blob/main/src/charge/README.md)
|
|
31
37
|
- [Transaction](https://github.com/en1tan/paystack-node/blob/main/src/transaction/README.md)
|
|
32
38
|
- [Plan](https://github.com/en1tan/paystack-node/blob/main/src/plan/README.md)
|
|
39
|
+
- [Customer](https://github.com/en1tan/paystack-node/blob/main/src/customer/README.md)
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Axios } from 'axios';
|
|
2
|
+
import { Meta } from '../transaction';
|
|
3
|
+
import { CreateCustomer, CustomerCreated, CustomerData, ListCustomerQueryParams, ListCustomers, Response, SetRiskAction, UpdateCustomer, ValidateCustomer } from './interface';
|
|
4
|
+
interface BadRequest {
|
|
5
|
+
status: boolean;
|
|
6
|
+
message: string;
|
|
7
|
+
data: null;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* # Customers
|
|
11
|
+
* The Customers API allows you create and manage
|
|
12
|
+
* customers on your integration
|
|
13
|
+
*/
|
|
14
|
+
export declare class Customer {
|
|
15
|
+
private http;
|
|
16
|
+
constructor(http: Axios);
|
|
17
|
+
/**
|
|
18
|
+
* ## Create Customer
|
|
19
|
+
* Create a customer on your integration
|
|
20
|
+
* @param {CreateCustomer} data
|
|
21
|
+
*/
|
|
22
|
+
create(data: CreateCustomer): Promise<CustomerCreated | BadRequest>;
|
|
23
|
+
/**
|
|
24
|
+
* ## List Customers
|
|
25
|
+
* List customers available on your integration
|
|
26
|
+
* @param {ListCustomerQueryParams} queryParams
|
|
27
|
+
*/
|
|
28
|
+
list(queryParams?: ListCustomerQueryParams): Promise<(Response & ListCustomers[] & Meta) | BadRequest>;
|
|
29
|
+
/**
|
|
30
|
+
* ## Fetch Customer
|
|
31
|
+
* Get details of a customer on your integration
|
|
32
|
+
* @param {String} email_or_code
|
|
33
|
+
*/
|
|
34
|
+
fetch(emailCode: string): Promise<CustomerData | BadRequest>;
|
|
35
|
+
/**
|
|
36
|
+
* ## Update CUstomer
|
|
37
|
+
* Update a customer's details on your integration
|
|
38
|
+
*/
|
|
39
|
+
update(code: string, data: UpdateCustomer): Promise<CustomerData | BadRequest>;
|
|
40
|
+
/**
|
|
41
|
+
* ## Validate Customer
|
|
42
|
+
* Validate a customer's identity
|
|
43
|
+
* @param {String} customer_code
|
|
44
|
+
* @param {ValidateCustomer} data
|
|
45
|
+
*/
|
|
46
|
+
validate(customerCode: string, data: ValidateCustomer): Promise<Response | BadRequest>;
|
|
47
|
+
/**
|
|
48
|
+
* ## Whitelist/Blacklist Customer
|
|
49
|
+
* Whitelist or black a customer on your integration
|
|
50
|
+
* @param {SetRiskAction} data
|
|
51
|
+
*/
|
|
52
|
+
setRiskAction(data: SetRiskAction): Promise<CustomerData | BadRequest>;
|
|
53
|
+
/**
|
|
54
|
+
* ## Deactivate Authorization
|
|
55
|
+
* Deactivate an authorization when the card needs to be forgotten
|
|
56
|
+
* @param {String} authorizaion_code
|
|
57
|
+
*/
|
|
58
|
+
deactivateAutorization(authorizationCode: string): Promise<Response>;
|
|
59
|
+
}
|
|
60
|
+
export {};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Customer = void 0;
|
|
13
|
+
/**
|
|
14
|
+
* # Customers
|
|
15
|
+
* The Customers API allows you create and manage
|
|
16
|
+
* customers on your integration
|
|
17
|
+
*/
|
|
18
|
+
class Customer {
|
|
19
|
+
constructor(http) {
|
|
20
|
+
this.http = http;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* ## Create Customer
|
|
24
|
+
* Create a customer on your integration
|
|
25
|
+
* @param {CreateCustomer} data
|
|
26
|
+
*/
|
|
27
|
+
create(data) {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
const response = yield this.http.post('/customer', JSON.stringify(data));
|
|
30
|
+
return JSON.parse(response.data);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* ## List Customers
|
|
35
|
+
* List customers available on your integration
|
|
36
|
+
* @param {ListCustomerQueryParams} queryParams
|
|
37
|
+
*/
|
|
38
|
+
list(queryParams) {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
const response = yield this.http.get('/customer', {
|
|
41
|
+
params: Object.assign({}, queryParams),
|
|
42
|
+
});
|
|
43
|
+
return JSON.parse(response.data);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* ## Fetch Customer
|
|
48
|
+
* Get details of a customer on your integration
|
|
49
|
+
* @param {String} email_or_code
|
|
50
|
+
*/
|
|
51
|
+
fetch(emailCode) {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
const response = yield this.http.get(`/customer/${emailCode}`);
|
|
54
|
+
return JSON.parse(response.data);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* ## Update CUstomer
|
|
59
|
+
* Update a customer's details on your integration
|
|
60
|
+
*/
|
|
61
|
+
update(code, data) {
|
|
62
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
const response = yield this.http.put(`/customer/${code}`, JSON.stringify(data));
|
|
64
|
+
return JSON.parse(response.data);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* ## Validate Customer
|
|
69
|
+
* Validate a customer's identity
|
|
70
|
+
* @param {String} customer_code
|
|
71
|
+
* @param {ValidateCustomer} data
|
|
72
|
+
*/
|
|
73
|
+
validate(customerCode, data) {
|
|
74
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
const response = yield this.http.post(`/customer/${customerCode}/identification`, JSON.stringify(data));
|
|
76
|
+
return JSON.parse(response.data);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* ## Whitelist/Blacklist Customer
|
|
81
|
+
* Whitelist or black a customer on your integration
|
|
82
|
+
* @param {SetRiskAction} data
|
|
83
|
+
*/
|
|
84
|
+
setRiskAction(data) {
|
|
85
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
const response = yield this.http.post('/customer/set_risk_action', JSON.stringify(data));
|
|
87
|
+
return JSON.parse(response.data);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* ## Deactivate Authorization
|
|
92
|
+
* Deactivate an authorization when the card needs to be forgotten
|
|
93
|
+
* @param {String} authorizaion_code
|
|
94
|
+
*/
|
|
95
|
+
deactivateAutorization(authorizationCode) {
|
|
96
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
97
|
+
const response = yield this.http.post('/customer/deactivate_authorization', JSON.stringify({ authorizaion_code: authorizationCode }));
|
|
98
|
+
return JSON.parse(response.data);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.Customer = Customer;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { Authorization } from '../charge';
|
|
2
|
+
import { Subscription, TransactionData } from '../transaction';
|
|
3
|
+
export interface CreateCustomer {
|
|
4
|
+
email: string;
|
|
5
|
+
first_name: string;
|
|
6
|
+
last_name: string;
|
|
7
|
+
phone: string;
|
|
8
|
+
metadata: Record<string, any>;
|
|
9
|
+
}
|
|
10
|
+
export interface Response {
|
|
11
|
+
status: boolean;
|
|
12
|
+
message: string;
|
|
13
|
+
}
|
|
14
|
+
export interface CustomerCreated extends Response {
|
|
15
|
+
email: string;
|
|
16
|
+
integration: number;
|
|
17
|
+
domain: string;
|
|
18
|
+
customer_code: string;
|
|
19
|
+
id: number;
|
|
20
|
+
identified: boolean;
|
|
21
|
+
identifications: null;
|
|
22
|
+
createdAt: Date;
|
|
23
|
+
updatedAt: Date;
|
|
24
|
+
}
|
|
25
|
+
export interface CustomerData extends Response {
|
|
26
|
+
integration: number;
|
|
27
|
+
first_name: string;
|
|
28
|
+
last_name: string;
|
|
29
|
+
email: string;
|
|
30
|
+
phone: string | null;
|
|
31
|
+
dedicated_account: DedicatedAccount | null;
|
|
32
|
+
identified: boolean;
|
|
33
|
+
identifications: CustomerIdentification[] | null;
|
|
34
|
+
metadata: Record<string, any> | null;
|
|
35
|
+
domain: string;
|
|
36
|
+
customer_code: string;
|
|
37
|
+
id: string;
|
|
38
|
+
transactions: TransactionData[];
|
|
39
|
+
subscriptions: Subscription[];
|
|
40
|
+
authorizations: Authorization[];
|
|
41
|
+
createdAt: Date;
|
|
42
|
+
updatedAt: Date;
|
|
43
|
+
}
|
|
44
|
+
export interface ListCustomers {
|
|
45
|
+
integration: number;
|
|
46
|
+
first_name: string;
|
|
47
|
+
last_name: string;
|
|
48
|
+
email: string;
|
|
49
|
+
phone: string | null;
|
|
50
|
+
metadata: Record<string, any> | null;
|
|
51
|
+
domain: string;
|
|
52
|
+
customer_code: string;
|
|
53
|
+
id: number;
|
|
54
|
+
createdAt: Date;
|
|
55
|
+
updatedAt: Date;
|
|
56
|
+
}
|
|
57
|
+
export interface ListCustomerQueryParams {
|
|
58
|
+
/**
|
|
59
|
+
* Specify how many records you want to retrieve per page.
|
|
60
|
+
* If not specify we use a default value of 50.
|
|
61
|
+
*/
|
|
62
|
+
perPage?: number;
|
|
63
|
+
/**
|
|
64
|
+
* Specify exactly what page you want to retrieve.
|
|
65
|
+
* If not specify we use a default value of 1.
|
|
66
|
+
*/
|
|
67
|
+
page?: number;
|
|
68
|
+
/**
|
|
69
|
+
* Specify an ID for the customer whose transactions
|
|
70
|
+
* you want to retrieve
|
|
71
|
+
*/
|
|
72
|
+
customer?: number;
|
|
73
|
+
/**
|
|
74
|
+
* Filter transactions by status ('failed', 'success', 'abandoned')
|
|
75
|
+
*/
|
|
76
|
+
status?: string;
|
|
77
|
+
/**
|
|
78
|
+
* A timestamp from which to start listing transaction
|
|
79
|
+
* e.g `2021-10-25T00.00.05.000z`, `2021-12-25`
|
|
80
|
+
*/
|
|
81
|
+
from?: Date;
|
|
82
|
+
/**
|
|
83
|
+
* A timestamp from which to stop listing transaction
|
|
84
|
+
* e.g `2021-10-25T00.00.05.000z`, `2021-12-25`
|
|
85
|
+
*/
|
|
86
|
+
to?: Date;
|
|
87
|
+
}
|
|
88
|
+
export interface SplitConfig {
|
|
89
|
+
id: number;
|
|
90
|
+
name: string;
|
|
91
|
+
type: string;
|
|
92
|
+
currency: string;
|
|
93
|
+
integration: number;
|
|
94
|
+
domain: string;
|
|
95
|
+
split_code: string;
|
|
96
|
+
active: boolean;
|
|
97
|
+
bearer_type: string;
|
|
98
|
+
bearer_subaccount: string | null;
|
|
99
|
+
createdAt: Date;
|
|
100
|
+
updatedAt: Date;
|
|
101
|
+
is_dynamic: boolean;
|
|
102
|
+
subaccounts: SubAccount[];
|
|
103
|
+
total_subaccounts: number;
|
|
104
|
+
}
|
|
105
|
+
export interface SubAccount {
|
|
106
|
+
subaccount: {
|
|
107
|
+
id: number;
|
|
108
|
+
sunaccount_code: string;
|
|
109
|
+
business_name: string;
|
|
110
|
+
description: string;
|
|
111
|
+
primary_contact_name: string | null;
|
|
112
|
+
primary_contact_email: string | null;
|
|
113
|
+
primary_contact_phone: string | null;
|
|
114
|
+
metadata: Record<string, any>;
|
|
115
|
+
settlement_bank: string;
|
|
116
|
+
currency: string;
|
|
117
|
+
account_number: string;
|
|
118
|
+
};
|
|
119
|
+
share: number;
|
|
120
|
+
}
|
|
121
|
+
export interface CustomerIdentification {
|
|
122
|
+
country: string;
|
|
123
|
+
type: string;
|
|
124
|
+
value: string;
|
|
125
|
+
}
|
|
126
|
+
export interface DedicatedAccount {
|
|
127
|
+
bank: {
|
|
128
|
+
name: string;
|
|
129
|
+
id: number;
|
|
130
|
+
slug: string;
|
|
131
|
+
};
|
|
132
|
+
id: number;
|
|
133
|
+
account_name: string;
|
|
134
|
+
account_number: string;
|
|
135
|
+
created_at: Date;
|
|
136
|
+
updated_at: Date;
|
|
137
|
+
currency: string;
|
|
138
|
+
split_config: SplitConfig;
|
|
139
|
+
active: boolean;
|
|
140
|
+
assigned: boolean;
|
|
141
|
+
assignment: {
|
|
142
|
+
assignee_id: number;
|
|
143
|
+
assignee_type: string;
|
|
144
|
+
account_type: string;
|
|
145
|
+
integration: number;
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
export interface UpdateCustomer {
|
|
149
|
+
first_name: string;
|
|
150
|
+
last_name: string;
|
|
151
|
+
phone: string;
|
|
152
|
+
metadata: Record<string, any>;
|
|
153
|
+
}
|
|
154
|
+
export interface SetRiskAction {
|
|
155
|
+
customer: string;
|
|
156
|
+
risk_action: RiskAction;
|
|
157
|
+
}
|
|
158
|
+
export interface ValidateCustomer {
|
|
159
|
+
first_name: string;
|
|
160
|
+
last_name: string;
|
|
161
|
+
type: ValidationType;
|
|
162
|
+
value: string;
|
|
163
|
+
country: string;
|
|
164
|
+
bvn: string;
|
|
165
|
+
bank_code: string;
|
|
166
|
+
account_number: string;
|
|
167
|
+
}
|
|
168
|
+
declare enum RiskAction {
|
|
169
|
+
default = 0,
|
|
170
|
+
allow = 1,
|
|
171
|
+
deny = 2
|
|
172
|
+
}
|
|
173
|
+
declare enum ValidationType {
|
|
174
|
+
bvn = 0,
|
|
175
|
+
bank_account = 1
|
|
176
|
+
}
|
|
177
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var RiskAction;
|
|
4
|
+
(function (RiskAction) {
|
|
5
|
+
RiskAction[RiskAction["default"] = 0] = "default";
|
|
6
|
+
RiskAction[RiskAction["allow"] = 1] = "allow";
|
|
7
|
+
RiskAction[RiskAction["deny"] = 2] = "deny";
|
|
8
|
+
})(RiskAction || (RiskAction = {}));
|
|
9
|
+
var ValidationType;
|
|
10
|
+
(function (ValidationType) {
|
|
11
|
+
ValidationType[ValidationType["bvn"] = 0] = "bvn";
|
|
12
|
+
ValidationType[ValidationType["bank_account"] = 1] = "bank_account";
|
|
13
|
+
})(ValidationType || (ValidationType = {}));
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export { Paystack } from './paystack';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
exports.Paystack = void 0;
|
|
4
|
+
var paystack_1 = require("./paystack");
|
|
5
|
+
Object.defineProperty(exports, "Paystack", { enumerable: true, get: function () { return paystack_1.Paystack; } });
|
package/dist/paystack.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Charge } from './charge';
|
|
2
|
+
import { Customer } from './customer/customer';
|
|
2
3
|
import { Plan } from './plan';
|
|
3
4
|
import { Transaction } from './transaction';
|
|
4
5
|
/**
|
|
@@ -11,5 +12,6 @@ export declare class Paystack {
|
|
|
11
12
|
charge: Charge;
|
|
12
13
|
transaction: Transaction;
|
|
13
14
|
plan: Plan;
|
|
15
|
+
customer: Customer;
|
|
14
16
|
constructor(key: string);
|
|
15
17
|
}
|
package/dist/paystack.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Paystack = void 0;
|
|
4
4
|
const axios_1 = require("axios");
|
|
5
5
|
const charge_1 = require("./charge");
|
|
6
|
+
const customer_1 = require("./customer/customer");
|
|
6
7
|
const plan_1 = require("./plan");
|
|
7
8
|
const transaction_1 = require("./transaction");
|
|
8
9
|
/**
|
|
@@ -21,6 +22,7 @@ class Paystack {
|
|
|
21
22
|
this.charge = new charge_1.Charge(this.http);
|
|
22
23
|
this.transaction = new transaction_1.Transaction(this.http);
|
|
23
24
|
this.plan = new plan_1.Plan(this.http);
|
|
25
|
+
this.customer = new customer_1.Customer(this.http);
|
|
24
26
|
}
|
|
25
27
|
}
|
|
26
28
|
exports.Paystack = Paystack;
|
package/dist/plan/plan.js
CHANGED
|
@@ -28,8 +28,8 @@ class Plan {
|
|
|
28
28
|
*/
|
|
29
29
|
create(data) {
|
|
30
30
|
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
-
const response = yield this.http.post('/plan', data);
|
|
32
|
-
return response.data;
|
|
31
|
+
const response = yield this.http.post('/plan', JSON.stringify(data));
|
|
32
|
+
return JSON.parse(response.data);
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
@@ -83,7 +83,7 @@ interface TransactionInitializedOk {
|
|
|
83
83
|
access_code: string;
|
|
84
84
|
reference: string;
|
|
85
85
|
}
|
|
86
|
-
interface TransactionData {
|
|
86
|
+
export interface TransactionData {
|
|
87
87
|
amount: number;
|
|
88
88
|
currency: string;
|
|
89
89
|
transaction_date: Date;
|
|
@@ -92,7 +92,7 @@ interface TransactionData {
|
|
|
92
92
|
domain: string;
|
|
93
93
|
metadata: number;
|
|
94
94
|
gateway_response: string;
|
|
95
|
-
message?:
|
|
95
|
+
message?: any;
|
|
96
96
|
channel: string;
|
|
97
97
|
ip_address: string;
|
|
98
98
|
log: {
|
|
@@ -292,4 +292,6 @@ export interface PartialDebit {
|
|
|
292
292
|
*/
|
|
293
293
|
at_least: string;
|
|
294
294
|
}
|
|
295
|
+
export interface Subscription {
|
|
296
|
+
}
|
|
295
297
|
export {};
|