paystack-sdk 1.0.16 → 1.0.20

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/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 {};
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);
@@ -0,0 +1,118 @@
1
+ import { Authorization } from '../charge';
2
+ import { ICustomer } from '../customer';
3
+ import { Meta } from '../interface';
4
+ import { IPlan } from '../plan';
5
+ export interface CreateSubscription {
6
+ /**
7
+ * Customer's email address or customer code
8
+ */
9
+ customer: string;
10
+ /**
11
+ * Plan code
12
+ */
13
+ plan: string;
14
+ /**
15
+ * If customer has multiple authorizations, you can set the desired
16
+ * authorization you wish to use for this subscription here.
17
+ * If this is not supplied, the customer's most recent authorization would be used
18
+ */
19
+ authorization?: string;
20
+ /**
21
+ * Set the date for the first debit. (ISO 8601 format)
22
+ * e.g `2022-01-01T00:00:00+01:00`
23
+ */
24
+ start_date?: Date;
25
+ }
26
+ export interface Response {
27
+ status: boolean;
28
+ message: string;
29
+ }
30
+ export interface SubscriptionCreated extends Response {
31
+ data: {
32
+ customer: number;
33
+ plan: number;
34
+ integration: number;
35
+ domain: string;
36
+ start: number;
37
+ status: string;
38
+ quantity: number;
39
+ amount: number;
40
+ authorization: Authorization;
41
+ };
42
+ }
43
+ export interface ListSubscriptions extends Response {
44
+ data: Subscription[];
45
+ meta: Meta;
46
+ }
47
+ export interface FetchSubscription extends Response {
48
+ data: {
49
+ invoices: unknown[];
50
+ customer: ICustomer;
51
+ plan: IPlan;
52
+ integration: number;
53
+ authorization: Authorization;
54
+ domain: string;
55
+ start: number;
56
+ status: string;
57
+ quantity: number;
58
+ amount: number;
59
+ subscription_code: string;
60
+ email_token: string;
61
+ easy_cron_id: string;
62
+ cron_expression: string;
63
+ next_payment_date: Date;
64
+ open_invoice: string;
65
+ id: number;
66
+ createdAt: Date;
67
+ updatedAt: Date;
68
+ };
69
+ }
70
+ export interface GenerateSubscriptionLink extends Response {
71
+ data: {
72
+ link: string;
73
+ };
74
+ }
75
+ export interface EnableOrDisableSubscription {
76
+ code: string;
77
+ token: string;
78
+ }
79
+ export interface Subscription {
80
+ customer: ICustomer;
81
+ plan: IPlan;
82
+ integration: number;
83
+ authorization: Authorization;
84
+ domain: string;
85
+ start: number;
86
+ status: string;
87
+ quantity: number;
88
+ amount: number;
89
+ subscription_code: string;
90
+ email_token: string;
91
+ easy_cron_id: string;
92
+ cron_expression: string;
93
+ next_payment_date: Date;
94
+ open_invoice: string;
95
+ id: number;
96
+ createdAt: Date;
97
+ updatedAt: Date;
98
+ }
99
+ export interface ListSubscriptionQueryParams {
100
+ /**
101
+ * Specify how many records you want to retrieve per page.
102
+ * If not specify we use a default value of 50.
103
+ */
104
+ perPage?: number;
105
+ /**
106
+ * Specify exactly what page you want to retrieve.
107
+ * If not specify we use a default value of 1.
108
+ */
109
+ page?: number;
110
+ /**
111
+ * Filter by Customer ID
112
+ */
113
+ customer?: number;
114
+ /**
115
+ * Filter by Plan ID
116
+ */
117
+ plan?: number;
118
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,18 @@
1
+ import { Axios } from 'axios';
2
+ import { CreateSubscription, EnableOrDisableSubscription, FetchSubscription, GenerateSubscriptionLink, ListSubscriptionQueryParams, ListSubscriptions, Response, SubscriptionCreated } from './interface';
3
+ interface BadRequest {
4
+ status: boolean;
5
+ message: string;
6
+ }
7
+ export declare class Subscription {
8
+ http: Axios;
9
+ constructor(http: Axios);
10
+ create(data: CreateSubscription): Promise<SubscriptionCreated | BadRequest>;
11
+ list(queryParams?: ListSubscriptionQueryParams): Promise<ListSubscriptions | BadRequest>;
12
+ fetch(idOrCode: string): Promise<FetchSubscription | BadRequest>;
13
+ enable(data: EnableOrDisableSubscription): Promise<Response | BadRequest>;
14
+ disable(data: EnableOrDisableSubscription): Promise<Response | BadRequest>;
15
+ generateSubscriptionLink(code: string): Promise<GenerateSubscriptionLink | BadRequest>;
16
+ sendUpdateSubscriptionLink(code: string): Promise<Response | BadRequest>;
17
+ }
18
+ export {};
@@ -0,0 +1,54 @@
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.Subscription = void 0;
13
+ class Subscription {
14
+ constructor(http) {
15
+ this.http = http;
16
+ }
17
+ create(data) {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ const response = yield this.http.post('/subscription', JSON.stringify(data));
20
+ return response;
21
+ });
22
+ }
23
+ list(queryParams) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ return yield this.http.get('/subscription', { params: Object.assign({}, queryParams) });
26
+ });
27
+ }
28
+ fetch(idOrCode) {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ return yield this.http.get(`/subscription/${idOrCode}`);
31
+ });
32
+ }
33
+ enable(data) {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ return yield this.http.post('/subscription/enable', JSON.stringify(data));
36
+ });
37
+ }
38
+ disable(data) {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ return yield this.http.post('/subscription/disable', JSON.stringify(data));
41
+ });
42
+ }
43
+ generateSubscriptionLink(code) {
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ return yield this.http.get(`/subscription/${code}/manage/link`);
46
+ });
47
+ }
48
+ sendUpdateSubscriptionLink(code) {
49
+ return __awaiter(this, void 0, void 0, function* () {
50
+ return yield this.http.post(`/subscription/${code}/manage/email`);
51
+ });
52
+ }
53
+ }
54
+ exports.Subscription = Subscription;
@@ -1,4 +1,5 @@
1
1
  import { Authorization, Customer } from '../charge';
2
+ import { Meta } from '../interface';
2
3
  export interface InitializeTransaction {
3
4
  /**
4
5
  * Amount should be in **kobo** if currency
@@ -72,71 +73,83 @@ export interface InitializeTransaction {
72
73
  */
73
74
  bearer?: string;
74
75
  }
75
- export interface TransactionResponse {
76
+ export interface Response {
76
77
  status: boolean;
77
78
  message: string;
78
- data: TransactionInitializedOk | TransactionData | Transactions | Timeline | ExportTransaction;
79
- meta?: Meta;
80
79
  }
81
- interface TransactionInitializedOk {
82
- authorization_url: string;
83
- access_code: string;
84
- reference: string;
80
+ export interface TransactionInitialized extends Response {
81
+ data: {
82
+ authorization_url: string;
83
+ access_code: string;
84
+ reference: string;
85
+ };
85
86
  }
86
- export 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?: any;
96
- channel: string;
97
- ip_address: string;
98
- log: {
87
+ export interface TransactionData extends Response {
88
+ data: {
89
+ amount: number;
90
+ currency: string;
91
+ transaction_date: Date;
92
+ status: string;
93
+ reference: string;
94
+ domain: string;
95
+ metadata: number;
96
+ gateway_response: string;
97
+ message?: string;
98
+ channel: string;
99
+ ip_address: string;
100
+ log: [
101
+ {
102
+ time_spent: number;
103
+ attempt: number;
104
+ authentication: any;
105
+ errors: number;
106
+ success: boolean;
107
+ mobile: boolean;
108
+ input: [];
109
+ channel: string;
110
+ history: [
111
+ {
112
+ type: string;
113
+ message: string;
114
+ time: number;
115
+ }
116
+ ];
117
+ }
118
+ ];
119
+ fees: number;
120
+ authorization: Authorization;
121
+ customer: Customer;
122
+ pin: string;
123
+ required_amount: number;
124
+ };
125
+ }
126
+ export interface ListTransactions extends Response {
127
+ data: TransactionData[];
128
+ meta: Meta;
129
+ }
130
+ export interface Timeline extends Response {
131
+ data: {
99
132
  time_spent: number;
100
- attempt: number;
133
+ attempts: number;
101
134
  authentication: any;
102
135
  errors: number;
103
136
  success: boolean;
104
137
  mobile: boolean;
105
138
  input: [];
106
- channel: any;
107
- history: {
108
- type: string;
109
- message: string;
110
- time: number;
111
- }[];
139
+ channel: string;
140
+ history: [
141
+ {
142
+ type: string;
143
+ message: string;
144
+ time: number;
145
+ }
146
+ ];
112
147
  };
113
- fees: any;
114
- authorization: Authorization;
115
- customer: Customer;
116
- pin: string;
117
- required_amount: number;
118
148
  }
119
- interface Transactions extends TransactionData {
120
- }
121
- interface Timeline {
122
- time_spent: number;
123
- attempts: number;
124
- authentication: any;
125
- errors: number;
126
- success: boolean;
127
- mobile: boolean;
128
- input: [];
129
- channel: string;
130
- history: [
131
- {
132
- type: string;
133
- message: string;
134
- time: number;
135
- }
136
- ];
137
- }
138
- interface ExportTransaction {
139
- path: string;
149
+ export interface ExportTransaction extends Response {
150
+ data: {
151
+ path: string;
152
+ };
140
153
  }
141
154
  export interface ListTransactionQueryParams {
142
155
  /**
@@ -176,13 +189,6 @@ export interface ListTransactionQueryParams {
176
189
  */
177
190
  amount?: number;
178
191
  }
179
- export interface Meta {
180
- total: number;
181
- skipped: number;
182
- perPage: number;
183
- page: number;
184
- pageCount: number;
185
- }
186
192
  export interface ChargeAuthorization {
187
193
  /**
188
194
  * Amount should be in kobo if currency is `NGN`, *pesewas*,
@@ -292,6 +298,12 @@ export interface PartialDebit {
292
298
  */
293
299
  at_least: string;
294
300
  }
295
- export interface Subscription {
301
+ export interface PartialDebitResponse extends Response {
302
+ data: Record<string, any>;
303
+ }
304
+ export interface CheckAuthorizationResponse extends Response {
305
+ data: {
306
+ amount: string;
307
+ currency: string;
308
+ };
296
309
  }
297
- export {};
@@ -1,3 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- [];