paystack-sdk 1.0.15 → 1.0.19

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.
Files changed (37) hide show
  1. package/README.md +8 -1
  2. package/dist/charge/charge.d.ts +8 -18
  3. package/dist/charge/charge.js +7 -14
  4. package/dist/charge/interface.d.ts +104 -76
  5. package/dist/customer/customer.d.ts +60 -0
  6. package/dist/customer/customer.js +96 -0
  7. package/dist/customer/index.d.ts +2 -0
  8. package/dist/customer/index.js +14 -0
  9. package/dist/customer/interface.d.ts +215 -0
  10. package/dist/customer/interface.js +13 -0
  11. package/dist/interface.d.ts +7 -0
  12. package/dist/interface.js +2 -0
  13. package/dist/paystack.d.ts +10 -2
  14. package/dist/paystack.js +12 -2
  15. package/dist/plan/interface.d.ts +26 -28
  16. package/dist/plan/plan.js +2 -2
  17. package/dist/product/index.d.ts +0 -0
  18. package/dist/product/index.js +1 -0
  19. package/dist/product/interface.d.ts +87 -0
  20. package/dist/product/interface.js +2 -0
  21. package/dist/product/product.d.ts +21 -0
  22. package/dist/product/product.js +46 -0
  23. package/dist/subscription/index.d.ts +1 -0
  24. package/dist/subscription/index.js +13 -0
  25. package/dist/subscription/interface.d.ts +118 -0
  26. package/dist/subscription/interface.js +2 -0
  27. package/dist/subscription/subscription.d.ts +18 -0
  28. package/dist/subscription/subscription.js +54 -0
  29. package/dist/transaction/interface.d.ts +75 -61
  30. package/dist/transaction/interface.js +0 -1
  31. package/dist/transaction/transaction.d.ts +12 -11
  32. package/dist/transaction/transaction.js +10 -13
  33. package/dist/transfer/interface.d.ts +105 -0
  34. package/dist/transfer/interface.js +2 -0
  35. package/dist/transfer/transfer.d.ts +26 -0
  36. package/dist/transfer/transfer.js +59 -0
  37. package/package.json +15 -12
@@ -0,0 +1,215 @@
1
+ import { Authorization } from '../charge';
2
+ import { Meta } from '../interface';
3
+ import { Subscription } from '../subscription/interface';
4
+ import { TransactionData } from '../transaction';
5
+ export interface CreateCustomer {
6
+ email: string;
7
+ first_name: string;
8
+ last_name: string;
9
+ phone?: string;
10
+ metadata?: Record<string, any>;
11
+ }
12
+ export interface Response {
13
+ status: boolean;
14
+ message: string;
15
+ }
16
+ export interface CustomerCreated extends Response {
17
+ data: {
18
+ transactions: TransactionData[];
19
+ subscriptions: Subscription[];
20
+ authorizations: Authorization[];
21
+ first_name: string;
22
+ last_name: string;
23
+ email: string;
24
+ phone: string | null;
25
+ metadata: Record<string, any> | null;
26
+ domain: string;
27
+ customer_code: string;
28
+ risk_action: string;
29
+ id: number;
30
+ integration: number;
31
+ createdAt: Date;
32
+ updatedAt: Date;
33
+ identified: boolean;
34
+ identifications: null;
35
+ };
36
+ }
37
+ export interface CustomerData extends Response {
38
+ data: {
39
+ integration: number;
40
+ first_name: string;
41
+ last_name: string;
42
+ email: string;
43
+ phone: string | null;
44
+ dedicated_account: DedicatedAccount | null;
45
+ identified: boolean;
46
+ identifications: CustomerIdentification[] | null;
47
+ metadata: Record<string, any> | null;
48
+ domain: string;
49
+ customer_code: string;
50
+ id: string;
51
+ transactions: TransactionData[];
52
+ subscriptions: Subscription[];
53
+ authorizations: Authorization[];
54
+ createdAt: Date;
55
+ updatedAt: Date;
56
+ };
57
+ }
58
+ export interface ListCustomersResponse extends Response {
59
+ data: [
60
+ {
61
+ integration: number;
62
+ first_name: string;
63
+ last_name: string;
64
+ email: string;
65
+ phone: string | null;
66
+ metadata: Record<string, any> | null;
67
+ domain: string;
68
+ customer_code: string;
69
+ id: number;
70
+ createdAt: Date;
71
+ updatedAt: Date;
72
+ }
73
+ ];
74
+ meta: Meta;
75
+ }
76
+ export interface ListCustomerQueryParams {
77
+ /**
78
+ * Specify how many records you want to retrieve per page.
79
+ * If not specify we use a default value of 50.
80
+ */
81
+ perPage?: number;
82
+ /**
83
+ * Specify exactly what page you want to retrieve.
84
+ * If not specify we use a default value of 1.
85
+ */
86
+ page?: number;
87
+ /**
88
+ * Specify an ID for the customer whose transactions
89
+ * you want to retrieve
90
+ */
91
+ customer?: number;
92
+ /**
93
+ * Filter transactions by status ('failed', 'success', 'abandoned')
94
+ */
95
+ status?: string;
96
+ /**
97
+ * A timestamp from which to start listing transaction
98
+ * e.g `2021-10-25T00.00.05.000z`, `2021-12-25`
99
+ */
100
+ from?: Date;
101
+ /**
102
+ * A timestamp from which to stop listing transaction
103
+ * e.g `2021-10-25T00.00.05.000z`, `2021-12-25`
104
+ */
105
+ to?: Date;
106
+ }
107
+ export interface SplitConfig {
108
+ id: number;
109
+ name: string;
110
+ type: string;
111
+ currency: string;
112
+ integration: number;
113
+ domain: string;
114
+ split_code: string;
115
+ active: boolean;
116
+ bearer_type: string;
117
+ bearer_subaccount: string | null;
118
+ createdAt: Date;
119
+ updatedAt: Date;
120
+ is_dynamic: boolean;
121
+ subaccounts: SubAccount[];
122
+ total_subaccounts: number;
123
+ }
124
+ export interface SubAccount {
125
+ subaccount: {
126
+ id: number;
127
+ sunaccount_code: string;
128
+ business_name: string;
129
+ description: string;
130
+ primary_contact_name: string | null;
131
+ primary_contact_email: string | null;
132
+ primary_contact_phone: string | null;
133
+ metadata: Record<string, any>;
134
+ settlement_bank: string;
135
+ currency: string;
136
+ account_number: string;
137
+ };
138
+ share: number;
139
+ }
140
+ export interface CustomerIdentification {
141
+ country: string;
142
+ type: string;
143
+ value: string;
144
+ }
145
+ export interface DedicatedAccount {
146
+ bank: {
147
+ name: string;
148
+ id: number;
149
+ slug: string;
150
+ };
151
+ id: number;
152
+ account_name: string;
153
+ account_number: string;
154
+ created_at: Date;
155
+ updated_at: Date;
156
+ currency: string;
157
+ split_config: SplitConfig;
158
+ active: boolean;
159
+ assigned: boolean;
160
+ assignment: {
161
+ assignee_id: number;
162
+ assignee_type: string;
163
+ account_type: string;
164
+ integration: number;
165
+ };
166
+ }
167
+ export interface UpdateCustomer {
168
+ first_name: string;
169
+ last_name: string;
170
+ phone: string;
171
+ metadata: Record<string, any>;
172
+ }
173
+ export interface SetRiskAction {
174
+ customer: string;
175
+ risk_action: RiskAction;
176
+ }
177
+ export interface ValidateCustomer {
178
+ first_name: string;
179
+ last_name: string;
180
+ type: ValidationType;
181
+ value: string;
182
+ country: string;
183
+ bvn: string;
184
+ bank_code: string;
185
+ account_number: string;
186
+ }
187
+ declare enum RiskAction {
188
+ default = 0,
189
+ allow = 1,
190
+ deny = 2
191
+ }
192
+ declare enum ValidationType {
193
+ bvn = 0,
194
+ bank_account = 1
195
+ }
196
+ export interface ICustomer {
197
+ integration: number;
198
+ first_name: string;
199
+ last_name: string;
200
+ email: string;
201
+ phone: string | null;
202
+ dedicated_account: DedicatedAccount | null;
203
+ identified: boolean;
204
+ identifications: CustomerIdentification[] | null;
205
+ metadata: Record<string, unknown> | null;
206
+ domain: string;
207
+ customer_code: string;
208
+ id: string;
209
+ transactions: TransactionData[];
210
+ subscriptions: Subscription[];
211
+ authorizations: Authorization[];
212
+ createdAt: Date;
213
+ updatedAt: Date;
214
+ }
215
+ 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 = {}));
@@ -0,0 +1,7 @@
1
+ export interface Meta {
2
+ total: number;
3
+ skipped: number;
4
+ perPage: number;
5
+ page: number;
6
+ pageCount: number;
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,15 +1,23 @@
1
1
  import { Charge } from './charge';
2
+ import { Customer } from './customer';
2
3
  import { Plan } from './plan';
4
+ import { Product } from './product/product';
5
+ import { Subscription } from './subscription/subscription';
3
6
  import { Transaction } from './transaction';
7
+ import { Transfer } from './transfer/transfer';
4
8
  /**
5
9
  * Paystack SDK
6
- * @author Asaju Enitan <@en1tan>
10
+ * @author Asaju Enitan <@tPriest>
7
11
  */
8
12
  export declare class Paystack {
9
13
  readonly key: string;
10
14
  private readonly http;
11
15
  charge: Charge;
12
- transaction: Transaction;
16
+ customer: Customer;
13
17
  plan: Plan;
18
+ product: Product;
19
+ subscription: Subscription;
20
+ transaction: Transaction;
21
+ transfer: Transfer;
14
22
  constructor(key: string);
15
23
  }
package/dist/paystack.js CHANGED
@@ -3,11 +3,15 @@ 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");
6
7
  const plan_1 = require("./plan");
8
+ const product_1 = require("./product/product");
9
+ const subscription_1 = require("./subscription/subscription");
7
10
  const transaction_1 = require("./transaction");
11
+ const transfer_1 = require("./transfer/transfer");
8
12
  /**
9
13
  * Paystack SDK
10
- * @author Asaju Enitan <@en1tan>
14
+ * @author Asaju Enitan <@tPriest>
11
15
  */
12
16
  class Paystack {
13
17
  constructor(key) {
@@ -16,11 +20,17 @@ class Paystack {
16
20
  baseURL: 'https://api.paystack.co',
17
21
  headers: {
18
22
  Authorization: `Bearer ${this.key}`,
23
+ 'Content-Type': 'application/json',
19
24
  },
20
25
  });
26
+ this.http.interceptors.response.use((response) => (response.data = JSON.parse(response.data)));
21
27
  this.charge = new charge_1.Charge(this.http);
22
- this.transaction = new transaction_1.Transaction(this.http);
28
+ this.customer = new customer_1.Customer(this.http);
23
29
  this.plan = new plan_1.Plan(this.http);
30
+ this.product = new product_1.Product(this.http);
31
+ this.subscription = new subscription_1.Subscription(this.http);
32
+ this.transaction = new transaction_1.Transaction(this.http);
33
+ this.transfer = new transfer_1.Transfer(this.http);
24
34
  }
25
35
  }
26
36
  exports.Paystack = Paystack;
@@ -1,5 +1,5 @@
1
- import { Authorization } from '../charge';
2
- import { Meta } from '../transaction/interface';
1
+ import { Meta } from '../interface';
2
+ import { Subscription } from '../subscription/interface';
3
3
  export interface CreatePlan {
4
4
  /**
5
5
  * Name of plan
@@ -54,12 +54,12 @@ interface PlanCreated {
54
54
  integration: number;
55
55
  domain: string;
56
56
  plan_code: string;
57
- description: any;
57
+ description: unknown;
58
58
  send_invoices: boolean;
59
59
  send_sms: boolean;
60
60
  hosted_page: boolean;
61
- hosted_page_url: any;
62
- hosted_page_summary: any;
61
+ hosted_page_url: unknown;
62
+ hosted_page_summary: unknown;
63
63
  currency: string;
64
64
  migrate: boolean;
65
65
  is_archived: boolean;
@@ -75,33 +75,11 @@ interface Plan extends PlanCreated {
75
75
  subscriptions_count: number;
76
76
  active_subscriptions_count: number;
77
77
  total_revenue: number;
78
- subscribers: Subscribers[];
78
+ subscribers: unknown[];
79
79
  }
80
80
  interface Plans extends PlanCreated {
81
81
  subscriptions: Subscription[];
82
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
83
  export interface ListPlanQueryParams {
106
84
  /**
107
85
  * Specify how many records you want to retrieve per page.
@@ -169,4 +147,24 @@ export interface UpdatePlan {
169
147
  */
170
148
  invoice_limit?: number;
171
149
  }
150
+ export interface IPlan {
151
+ domain: string;
152
+ name: string;
153
+ plan_code: string;
154
+ description: string;
155
+ amount: number;
156
+ interval: string;
157
+ send_invoices: boolean;
158
+ send_sms: boolean;
159
+ hosted_page: boolean;
160
+ hosted_page_url: string;
161
+ hosted_page_summary: string;
162
+ currency: string;
163
+ migrate: boolean;
164
+ id: number;
165
+ integration: number;
166
+ is_archived: boolean;
167
+ createdAt: Date;
168
+ updatedAt: Date;
169
+ }
172
170
  export {};
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
  /**
File without changes
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,87 @@
1
+ import { Meta } from '../interface';
2
+ export interface CreateProduct {
3
+ /** Name of product */
4
+ name: string;
5
+ /** A description for this product */
6
+ description: string;
7
+ /**
8
+ * Price should be in *kobo* if currency is `NGN`,
9
+ * *pesewas*, if currency is `GHS`, and *cents*, if currency is `ZAR`
10
+ */
11
+ price: number;
12
+ /** Currency in which price is set. Allowed values are: NGN, GHS, ZAR or USD */
13
+ currency: string;
14
+ /**
15
+ * Set to `true` if the product has unlimited stock. Leave as `false` if the product has limited stock
16
+ */
17
+ unlimited?: boolean;
18
+ /** Number of products in stock. Use if `unlimited` is `false` */
19
+ quantity?: number;
20
+ }
21
+ export interface Response {
22
+ status: boolean;
23
+ message: string;
24
+ }
25
+ export interface ProductCreated extends Response {
26
+ data: Product;
27
+ }
28
+ export interface ListProducts extends Response {
29
+ data: Product[];
30
+ meta: Meta;
31
+ }
32
+ export interface FetchProduct extends Response {
33
+ data: Product;
34
+ }
35
+ export interface UpdateProduct extends Response {
36
+ data: Product;
37
+ }
38
+ export interface ListProductQueryParams {
39
+ /**
40
+ * Specify how many records you want to retrieve per page.
41
+ * If not specify we use a default value of 50.
42
+ */
43
+ perPage?: number;
44
+ /**
45
+ * Specify exactly what page you want to retrieve.
46
+ * If not specify we use a default value of 1.
47
+ */
48
+ page?: number;
49
+ /**
50
+ * A timestamp from which to start listing transaction
51
+ * e.g `2021-10-25T00.00.05.000z`, `2021-12-25`
52
+ */
53
+ from?: Date;
54
+ /**
55
+ * A timestamp from which to stop listing transaction
56
+ * e.g `2021-10-25T00.00.05.000z`, `2021-12-25`
57
+ */
58
+ to?: Date;
59
+ }
60
+ interface Product {
61
+ id: number;
62
+ name: string;
63
+ description: string;
64
+ currency: string;
65
+ price: number;
66
+ quantity: number;
67
+ image_path: string;
68
+ file_path: string;
69
+ is_shippable: boolean;
70
+ unlimited: boolean;
71
+ integration: number;
72
+ domain: string;
73
+ metadata: Record<string, unknown>;
74
+ slug: string;
75
+ product_code: string;
76
+ quantity_sold: number;
77
+ type: string;
78
+ shipping_fields: Record<string, unknown>;
79
+ active: boolean;
80
+ in_stock: boolean;
81
+ minimum_orderable: number;
82
+ maximum_orderable: number;
83
+ low_stock_alert: boolean;
84
+ createdAt: Date;
85
+ updatedAt: Date;
86
+ }
87
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,21 @@
1
+ import { Axios } from 'axios';
2
+ import { CreateProduct, FetchProduct, ListProductQueryParams, ListProducts, ProductCreated, UpdateProduct } from './interface';
3
+ interface BadRequest {
4
+ status: boolean;
5
+ message: string;
6
+ }
7
+ /**
8
+ * @class Product
9
+ * # Producs
10
+ * The products API allows you create and manage inventories
11
+ * on your integration
12
+ */
13
+ export declare class Product {
14
+ http: Axios;
15
+ constructor(http: Axios);
16
+ create(data: CreateProduct): Promise<ProductCreated | BadRequest>;
17
+ list(queryParams?: ListProductQueryParams): Promise<ListProducts | BadRequest>;
18
+ fetch(id: string): Promise<FetchProduct | BadRequest>;
19
+ update(id: string, data: CreateProduct): Promise<UpdateProduct | BadRequest>;
20
+ }
21
+ export {};
@@ -0,0 +1,46 @@
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.Product = void 0;
13
+ /**
14
+ * @class Product
15
+ * # Producs
16
+ * The products API allows you create and manage inventories
17
+ * on your integration
18
+ */
19
+ class Product {
20
+ constructor(http) {
21
+ this.http = http;
22
+ }
23
+ create(data) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ return yield this.http.post('/product', JSON.stringify(data));
26
+ });
27
+ }
28
+ list(queryParams) {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ return yield this.http.get('/product', {
31
+ params: Object.assign({}, queryParams),
32
+ });
33
+ });
34
+ }
35
+ fetch(id) {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ return yield this.http.get(`/product/${id}`);
38
+ });
39
+ }
40
+ update(id, data) {
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ return yield this.http.put(`/product/${id}`, JSON.stringify(data));
43
+ });
44
+ }
45
+ }
46
+ exports.Product = Product;
@@ -0,0 +1 @@
1
+ export * from './interface';
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./interface"), exports);