paystack-sdk 1.1.20 → 2.1.0

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 CHANGED
@@ -16,7 +16,7 @@ For NPM
16
16
 
17
17
  For Typescript
18
18
 
19
- ```
19
+ ```typescript
20
20
  import {Paystack} from 'paystack-sdk';
21
21
 
22
22
  const paystack = new Paystack("secret_key);
@@ -24,7 +24,7 @@ const paystack = new Paystack("secret_key);
24
24
 
25
25
  For Javscript
26
26
 
27
- ```
27
+ ```javascript
28
28
  const Paystack = require('paystack-sdk').Paystack;
29
29
  const paystack = new Paystack("secret_key");
30
30
  ```
@@ -40,3 +40,11 @@ All methods use promise meaning you can either use the `async...await` or `then.
40
40
  - Subscription
41
41
  - Transaction
42
42
  - Transfer
43
+ - dedicated (For dedicated accounts)
44
+
45
+
46
+ ## CONTRIBUTING
47
+ If you notice a missing function, or maybe a bug. Please feel free to submit
48
+ a PR. I will take a look at it.
49
+ You will need to fork the repo and create a PR against it with your changes.
50
+ Thank you :heart:
@@ -1,13 +1,13 @@
1
1
  import { Authorization } from '../charge';
2
2
  import { Meta } from '../interface';
3
3
  import { Subscription } from '../subscription/interface';
4
- import { TransactionData } from '../transaction';
4
+ import { Transaction } from '../transaction';
5
5
  export interface CreateCustomer {
6
6
  email: string;
7
7
  first_name: string;
8
8
  last_name: string;
9
9
  phone?: string;
10
- metadata?: Record<string, any>;
10
+ metadata?: Record<string, unknown>;
11
11
  }
12
12
  export interface Response {
13
13
  status: boolean;
@@ -15,14 +15,14 @@ export interface Response {
15
15
  }
16
16
  export interface CustomerCreated extends Response {
17
17
  data: {
18
- transactions: TransactionData[];
18
+ transactions: Transaction[];
19
19
  subscriptions: Subscription[];
20
20
  authorizations: Authorization[];
21
21
  first_name: string;
22
22
  last_name: string;
23
23
  email: string;
24
24
  phone: string | null;
25
- metadata: Record<string, any> | null;
25
+ metadata?: Record<string, unknown>;
26
26
  domain: string;
27
27
  customer_code: string;
28
28
  risk_action: string;
@@ -48,7 +48,7 @@ export interface CustomerData extends Response {
48
48
  domain: string;
49
49
  customer_code: string;
50
50
  id: string;
51
- transactions: TransactionData[];
51
+ transactions: Transaction[];
52
52
  subscriptions: Subscription[];
53
53
  authorizations: Authorization[];
54
54
  createdAt: Date;
@@ -206,7 +206,7 @@ export interface ICustomer {
206
206
  domain: string;
207
207
  customer_code: string;
208
208
  id: string;
209
- transactions: TransactionData[];
209
+ transactions: Transaction[];
210
210
  subscriptions: Subscription[];
211
211
  authorizations: Authorization[];
212
212
  createdAt: Date;
@@ -16,7 +16,7 @@ class DedicatedAccount {
16
16
  }
17
17
  create(data) {
18
18
  return __awaiter(this, void 0, void 0, function* () {
19
- return yield this.http.post('/dedicated_account', data);
19
+ return yield this.http.post('/dedicated_account', JSON.stringify(data));
20
20
  });
21
21
  }
22
22
  list(queryParams) {
@@ -36,7 +36,7 @@ class DedicatedAccount {
36
36
  }
37
37
  splitTransaction(data) {
38
38
  return __awaiter(this, void 0, void 0, function* () {
39
- return yield this.http.post('/dedicated_account/split', data);
39
+ return yield this.http.post('/dedicated_account/split', JSON.stringify(data));
40
40
  });
41
41
  }
42
42
  removeSplit(accountNumber) {
@@ -1,7 +1,7 @@
1
1
  import { Authorization, Customer } from '../charge';
2
2
  import { Meta } from '../interface';
3
3
  import { Subscription } from '../subscription';
4
- import { Response, TransactionData } from '../transaction';
4
+ import { Response, Transaction } from '../transaction';
5
5
  export interface DedicatedAccountData {
6
6
  id: number;
7
7
  account_name: string;
@@ -49,7 +49,7 @@ export interface DedicatedAccountCreatedResponse extends Response {
49
49
  }
50
50
  export interface FetchDedicatedVirtualAccountResponse extends Response {
51
51
  data: {
52
- transactions: TransactionData[];
52
+ transactions: Transaction[];
53
53
  subscriptions: Subscription[];
54
54
  authorizations: Authorization[];
55
55
  first_name: string;
@@ -3,6 +3,7 @@ import { Customer } from './customer';
3
3
  import { DedicatedAccount } from './dedicated/dedicated';
4
4
  import { Plan } from './plan';
5
5
  import { Product } from './product/product';
6
+ import { TransactionSplit } from './split/split';
6
7
  import { Subscription } from './subscription/subscription';
7
8
  import { Transaction } from './transaction';
8
9
  import { Transfer } from './transfer/transfer';
@@ -21,5 +22,6 @@ export declare class Paystack {
21
22
  subscription: Subscription;
22
23
  transaction: Transaction;
23
24
  transfer: Transfer;
25
+ split: TransactionSplit;
24
26
  constructor(key: string);
25
27
  }
package/dist/paystack.js CHANGED
@@ -7,6 +7,7 @@ const customer_1 = require("./customer");
7
7
  const dedicated_1 = require("./dedicated/dedicated");
8
8
  const plan_1 = require("./plan");
9
9
  const product_1 = require("./product/product");
10
+ const split_1 = require("./split/split");
10
11
  const subscription_1 = require("./subscription/subscription");
11
12
  const transaction_1 = require("./transaction");
12
13
  const transfer_1 = require("./transfer/transfer");
@@ -25,6 +26,9 @@ class Paystack {
25
26
  },
26
27
  });
27
28
  this.http.interceptors.response.use((response) => (response.data = JSON.parse(response.data)));
29
+ // this.http.interceptors.request.use(
30
+ // (body) => (body.data = JSON.stringify(body.data)),
31
+ // );
28
32
  this.charge = new charge_1.Charge(this.http);
29
33
  this.customer = new customer_1.Customer(this.http);
30
34
  this.plan = new plan_1.Plan(this.http);
@@ -33,6 +37,7 @@ class Paystack {
33
37
  this.transaction = new transaction_1.Transaction(this.http);
34
38
  this.transfer = new transfer_1.Transfer(this.http);
35
39
  this.dedicated = new dedicated_1.DedicatedAccount(this.http);
40
+ this.split = new split_1.TransactionSplit(this.http);
36
41
  }
37
42
  }
38
43
  exports.Paystack = Paystack;
File without changes
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,130 @@
1
+ import { Meta } from '../interface';
2
+ export declare type SplitCurrrencyType = 'GHS' | 'NGN' | 'ZAR' | 'USD';
3
+ export declare type SplitType = 'percentage' | 'flat';
4
+ export interface BadRequest {
5
+ status: boolean;
6
+ message: string;
7
+ data: null;
8
+ }
9
+ interface SubAccount {
10
+ id: number;
11
+ subaccount_code: string;
12
+ business_name: string;
13
+ description: string;
14
+ primary_contact_name?: string;
15
+ primary_contact_email?: string;
16
+ primary_contact_phone?: string;
17
+ metadata?: Record<string, unknown>;
18
+ percentage_charge?: number;
19
+ settlement_bank?: string;
20
+ account_number?: string;
21
+ }
22
+ export interface SplitSubAccount {
23
+ /**
24
+ * This is the sub account code
25
+ */
26
+ subaccount: string;
27
+ share: number;
28
+ }
29
+ export interface CreateSplit {
30
+ /**
31
+ * Name of the transaction split
32
+ */
33
+ name: string;
34
+ /**
35
+ * The type of transaction split you want to create.
36
+ * You can use one of the following: percentage | flat
37
+ */
38
+ type: SplitType;
39
+ /**
40
+ * Any of NGN, GHS, ZAR, or USD
41
+ */
42
+ currency: SplitCurrrencyType;
43
+ /**
44
+ * A list of object containing subaccount code
45
+ * and number of shares: [{subaccount: ‘ACT_xxxxxxxxxx’, share: xxx},{...}]
46
+ */
47
+ subaccounts: SplitSubAccount[];
48
+ /**
49
+ * Any of subaccount | account | all-proportional | all
50
+ */
51
+ bearer_type: string;
52
+ /**
53
+ * Subaccount code
54
+ */
55
+ bearer_subaccount: string;
56
+ }
57
+ export interface ListSplitQueryParams {
58
+ /**
59
+ * The name of the split
60
+ */
61
+ name?: string;
62
+ /**
63
+ * Any of true or false
64
+ */
65
+ active?: boolean;
66
+ /**
67
+ * Sort by name, defaults to createdAt dat
68
+ */
69
+ sort_by?: string;
70
+ /**
71
+ * Number of splits per page. If not specify we use a default value of 50.
72
+ */
73
+ perPage?: number;
74
+ /**
75
+ * Page number to view. If not specify we use a default value of 1.
76
+ * @default 1
77
+ */
78
+ page?: number;
79
+ /**
80
+ * A timestamp from which to start listing splits e.g. 2019-09-24T00:00:05.000Z, 2019-09-21
81
+ */
82
+ from?: Date;
83
+ /**
84
+ * A timestamp at which to stop listing splits e.g. 2019-09-24T00:00:05.000Z, 2019-09-21
85
+ */
86
+ to?: Date;
87
+ }
88
+ interface TransactionSplit {
89
+ id: number;
90
+ name: string;
91
+ type: string;
92
+ currency: SplitCurrrencyType;
93
+ integration: number;
94
+ domain: string;
95
+ split_code: string;
96
+ active: boolean;
97
+ bearer_type: string;
98
+ bearer_subaccount: number;
99
+ createdAt: Date;
100
+ updatedAt: Date;
101
+ subaccounts: {
102
+ subaccount: SubAccount;
103
+ share: number;
104
+ }[];
105
+ total_subaccounts?: number;
106
+ }
107
+ export interface UpdateTransactionSplit {
108
+ name: string;
109
+ active: boolean;
110
+ bearer_type?: string;
111
+ bearer_subaccount?: string;
112
+ }
113
+ export interface Response {
114
+ status: boolean;
115
+ message: string;
116
+ }
117
+ export interface SplitCreatedResponse extends Response {
118
+ data: TransactionSplit;
119
+ }
120
+ export interface ListSplitsResponse extends Response {
121
+ data: TransactionSplit[];
122
+ meta: Meta;
123
+ }
124
+ export interface TransactionSplitResponse extends Response {
125
+ data: TransactionSplit;
126
+ }
127
+ export interface UpdateTransactionSplitResponse extends Response {
128
+ data: TransactionSplit;
129
+ }
130
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,36 @@
1
+ import { Axios } from 'axios';
2
+ import { BadRequest, CreateSplit, ListSplitQueryParams, ListSplitsResponse, Response, SplitCreatedResponse, SplitSubAccount, TransactionSplitResponse, UpdateTransactionSplit, UpdateTransactionSplitResponse } from './interface';
3
+ /**
4
+ * The Transaction Splits API enables merchants
5
+ * split the settlement for a transaction across
6
+ * their payout account, and one or more Subaccounts.
7
+ */
8
+ export declare class TransactionSplit {
9
+ private http;
10
+ constructor(http: Axios);
11
+ /**
12
+ * Create a split payment on your integration
13
+ */
14
+ create(data: CreateSplit): Promise<SplitCreatedResponse | BadRequest>;
15
+ /**
16
+ * List/search for the transaction splits available on your integration.
17
+ */
18
+ list(queryParams?: ListSplitQueryParams): Promise<ListSplitsResponse | BadRequest>;
19
+ /**
20
+ * Get details of a split on your integration.
21
+ */
22
+ fetch(splitId: string): Promise<TransactionSplitResponse | BadRequest>;
23
+ /**
24
+ * Update a transaction split details on your integration
25
+ */
26
+ update(splitId: string, data: UpdateTransactionSplit): Promise<UpdateTransactionSplitResponse | BadRequest>;
27
+ /**
28
+ * Add a Subaccount to a Transaction Split,
29
+ * or update the share of an existing Subaccount in a Transaction Split
30
+ */
31
+ add(splitId: string, data: SplitSubAccount): Promise<TransactionSplitResponse | BadRequest>;
32
+ /**
33
+ * Remove a subaccount from a transaction split
34
+ */
35
+ remove(splitId: string, subaccount: string): Promise<Response | BadRequest>;
36
+ }
@@ -0,0 +1,95 @@
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.TransactionSplit = void 0;
13
+ /**
14
+ * The Transaction Splits API enables merchants
15
+ * split the settlement for a transaction across
16
+ * their payout account, and one or more Subaccounts.
17
+ */
18
+ class TransactionSplit {
19
+ constructor(http) {
20
+ this.http = http;
21
+ }
22
+ /**
23
+ * Create a split payment on your integration
24
+ */
25
+ create(data) {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ return yield this.http.request({
28
+ url: '/split',
29
+ data: JSON.stringify(data),
30
+ method: 'post',
31
+ });
32
+ });
33
+ }
34
+ /**
35
+ * List/search for the transaction splits available on your integration.
36
+ */
37
+ list(queryParams) {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ return yield this.http.request({
40
+ url: '/split',
41
+ params: Object.assign({}, queryParams),
42
+ method: 'get',
43
+ });
44
+ });
45
+ }
46
+ /**
47
+ * Get details of a split on your integration.
48
+ */
49
+ fetch(splitId) {
50
+ return __awaiter(this, void 0, void 0, function* () {
51
+ return yield this.http.request({
52
+ url: `/split/${splitId}`,
53
+ method: 'get',
54
+ });
55
+ });
56
+ }
57
+ /**
58
+ * Update a transaction split details on your integration
59
+ */
60
+ update(splitId, data) {
61
+ return __awaiter(this, void 0, void 0, function* () {
62
+ return yield this.http.request({
63
+ url: `/split/${splitId}`,
64
+ data: JSON.stringify(data),
65
+ method: 'put',
66
+ });
67
+ });
68
+ }
69
+ /**
70
+ * Add a Subaccount to a Transaction Split,
71
+ * or update the share of an existing Subaccount in a Transaction Split
72
+ */
73
+ add(splitId, data) {
74
+ return __awaiter(this, void 0, void 0, function* () {
75
+ return yield this.http.request({
76
+ url: `/split/${splitId}/subaccount/add`,
77
+ data: JSON.stringify(data),
78
+ method: 'post',
79
+ });
80
+ });
81
+ }
82
+ /**
83
+ * Remove a subaccount from a transaction split
84
+ */
85
+ remove(splitId, subaccount) {
86
+ return __awaiter(this, void 0, void 0, function* () {
87
+ return yield this.http.request({
88
+ url: `/split/${splitId}/subaccount/remove`,
89
+ data: JSON.stringify({ subaccount }),
90
+ method: 'post',
91
+ });
92
+ });
93
+ }
94
+ }
95
+ exports.TransactionSplit = TransactionSplit;
@@ -84,47 +84,48 @@ export interface TransactionInitialized extends Response {
84
84
  reference: string;
85
85
  };
86
86
  }
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
- };
87
+ interface Transaction {
88
+ amount: number;
89
+ currency: string;
90
+ transaction_date: Date;
91
+ status: string;
92
+ reference: string;
93
+ domain: string;
94
+ metadata: number;
95
+ gateway_response: string;
96
+ message?: string;
97
+ channel: string;
98
+ ip_address: string;
99
+ log: [
100
+ {
101
+ time_spent: number;
102
+ attempt: number;
103
+ authentication: any;
104
+ errors: number;
105
+ success: boolean;
106
+ mobile: boolean;
107
+ input: [];
108
+ channel: string;
109
+ history: [
110
+ {
111
+ type: string;
112
+ message: string;
113
+ time: number;
114
+ }
115
+ ];
116
+ }
117
+ ];
118
+ fees: number;
119
+ authorization: Authorization;
120
+ customer: Customer;
121
+ pin: string;
122
+ required_amount: number;
123
+ }
124
+ export interface GetTransactionResponse extends Response {
125
+ data: Transaction;
125
126
  }
126
127
  export interface ListTransactions extends Response {
127
- data: TransactionData[];
128
+ data: Transaction[];
128
129
  meta: Meta;
129
130
  }
130
131
  export interface Timeline extends Response {
@@ -307,3 +308,4 @@ export interface CheckAuthorizationResponse extends Response {
307
308
  currency: string;
308
309
  };
309
310
  }
311
+ export {};
@@ -1,5 +1,5 @@
1
1
  import { Axios } from 'axios';
2
- import { CheckAuthorizationResponse, ExportTransaction, ListTransactions, PartialDebitResponse, Timeline, TransactionData } from './interface';
2
+ import { CheckAuthorizationResponse, ExportTransaction, ListTransactions, PartialDebitResponse, Timeline, GetTransactionResponse } from './interface';
3
3
  import { ChargeAuthorization, CheckAuthorization, InitializeTransaction, ListTransactionQueryParams, PartialDebit, TransactionInitialized } from './interface';
4
4
  interface BadRequest {
5
5
  status: boolean;
@@ -19,10 +19,10 @@ export declare class Transaction {
19
19
  * @param {InitializeTransaction} data **Body Param**
20
20
  */
21
21
  initialize(data: InitializeTransaction): Promise<TransactionInitialized | BadRequest>;
22
- verify(reference: string): Promise<TransactionData | BadRequest>;
22
+ verify(reference: string): Promise<GetTransactionResponse | BadRequest>;
23
23
  list(queryParams?: ListTransactionQueryParams): Promise<ListTransactions | BadRequest>;
24
- fetch(id: string): Promise<TransactionData | BadRequest>;
25
- chargeAuthorization(data: ChargeAuthorization): Promise<TransactionData | BadRequest>;
24
+ fetch(id: string): Promise<GetTransactionResponse | BadRequest>;
25
+ chargeAuthorization(data: ChargeAuthorization): Promise<GetTransactionResponse | BadRequest>;
26
26
  checkAuthorization(data: CheckAuthorization): Promise<CheckAuthorizationResponse | BadRequest>;
27
27
  viewTimeline(id: string): Promise<Timeline | BadRequest>;
28
28
  total(queryParams: ListTransactionQueryParams): Promise<ListTransactions | BadRequest>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "paystack-sdk",
3
- "version": "1.1.20",
3
+ "version": "2.1.0",
4
4
  "description": "Paystack SDK written in Typescript",
5
5
  "main": "dist/index.js",
6
6
  "author": "Tech Priest",
@@ -18,8 +18,8 @@
18
18
  },
19
19
  "devDependencies": {
20
20
  "@types/node": "16.11.11",
21
- "@typescript-eslint/eslint-plugin": "^5.10.0",
22
- "@typescript-eslint/parser": "^5.10.0",
21
+ "@typescript-eslint/eslint-plugin": "5.36.2",
22
+ "@typescript-eslint/parser": "5.36.2",
23
23
  "eslint": "8.6.0",
24
24
  "prettier": "2.5.1",
25
25
  "ts-node": "10.4.0",
@@ -29,7 +29,7 @@
29
29
  "typescript-eslint": "0.0.1-alpha.0"
30
30
  },
31
31
  "dependencies": {
32
- "axios": "^0.24.0"
32
+ "axios": "0.24.0"
33
33
  },
34
34
  "files": [
35
35
  "dist/**/*"