Skip to content

Commit b40efaa

Browse files
authored
Merge pull request #12 from devfresher/feature-refund
New Feature: Refund
2 parents 546858d + 793b00f commit b40efaa

File tree

8 files changed

+155
-31
lines changed

8 files changed

+155
-31
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ All methods use promise meaning you can either use the `async...await` or `then.
5858
- [x] Bulk Charges
5959
- [ ] Control Panel
6060
- [ ] Disputes
61-
- [ ] Refunds
61+
- [x] Refunds
6262
- [x] Verification
6363
- [ ] Miscellaneous
6464

src/interface.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,13 @@ export interface QueryParams {
3737
*/
3838
to?: Date;
3939
}
40+
41+
/**
42+
* Paystack makes use of the ISO 4217 format for currency codes.
43+
* When sending an amount, it must be sent in the subunit of that currency.
44+
*
45+
* Sending an amount in subunits simply means multiplying the base amount by 100.
46+
* For example, if a customer is supposed to make a payment of NGN 100,
47+
* you would send 10000 = 100 * 100 in your request.
48+
*/
49+
export type Currency = 'NGN' | 'USD' | 'GHS' | 'ZAR' | 'KES';

src/paystack.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { Transaction } from './transaction/transaction';
1616
import { Transfer } from './transfer/transfer';
1717
import { BulkCharge } from './bulkcharge/bulkcharge';
1818
import { Verification } from './verification/verification';
19+
import { Refund } from './refund/refund';
1920

2021
/**
2122
* Paystack SDK
@@ -40,6 +41,7 @@ export class Paystack {
4041
public invoice: Invoice;
4142
public settlement: Settlement;
4243
public recipient: Recipient;
44+
public refund: Refund;
4345
public verification: Verification;
4446
constructor(private readonly key: string) {
4547
this.http = new Axios({
@@ -69,6 +71,7 @@ export class Paystack {
6971
this.invoice = new Invoice(this.http);
7072
this.settlement = new Settlement(this.http);
7173
this.recipient = new Recipient(this.http);
74+
this.refund = new Refund(this.http);
7275
this.verification = new Verification(this.http);
7376
}
7477
}

src/refund/interface.ts

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import { Currency, QueryParams, Response } from '../interface';
2+
import { Transaction } from '../transaction/interface';
3+
4+
export interface CreateRefund {
5+
/**
6+
* Transaction reference or id
7+
*/
8+
transaction: string;
9+
10+
/**
11+
* Amount to be refunded to the customer.
12+
* Amount is optional(defaults to original transaction amount)
13+
* and cannot be more than the original transaction amount.
14+
*/
15+
amount?: number;
16+
17+
/**
18+
* Any of the supported currency
19+
*/
20+
currency?: Currency;
21+
22+
/**
23+
* Customer reason
24+
*/
25+
customer_note?: string;
26+
27+
/**
28+
* Merchant reason
29+
*/
30+
merchant_note?: string;
31+
}
32+
33+
export interface ListRefundQueryParams extends QueryParams {
34+
/**
35+
* Identifier for transaction to be refunded
36+
*/
37+
reference: string;
38+
39+
/**
40+
* Any of the supported currency
41+
*/
42+
currency: Currency;
43+
}
44+
45+
export interface ListRefundsResponse extends Response {
46+
data: Refund[];
47+
}
48+
49+
export interface RefundCreatedResponse extends Response {
50+
data: Refund;
51+
}
52+
53+
export interface FetchRefundResponse extends Response {
54+
data: Refund;
55+
}
56+
57+
export interface Refund {
58+
id: number;
59+
integration: number;
60+
domain: string;
61+
transaction: number | Transaction;
62+
dispute: number;
63+
amount: number;
64+
deducted_amount: number;
65+
currency: string;
66+
channel: string;
67+
fully_deducted: boolean;
68+
refunded_by: string;
69+
refunded_at?: string;
70+
expected_at: string;
71+
settlement: number;
72+
customer_note: string;
73+
merchant_note: string;
74+
createdAt: string;
75+
updatedAt: string;
76+
status: string;
77+
}

src/refund/refund.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { Axios } from 'axios';
2+
import {
3+
FetchRefundResponse,
4+
CreateRefund,
5+
ListRefundQueryParams,
6+
ListRefundsResponse,
7+
RefundCreatedResponse,
8+
} from './interface';
9+
import { BadRequest } from '../interface';
10+
11+
export class Refund {
12+
private http: Axios;
13+
constructor(http: Axios) {
14+
this.http = http;
15+
}
16+
17+
/**
18+
* #### Create Refund
19+
* Initiate a refund on your integration
20+
*/
21+
async create(
22+
data: CreateRefund,
23+
): Promise<RefundCreatedResponse | BadRequest> {
24+
return await this.http.post('/refund', JSON.stringify(data));
25+
}
26+
27+
/**
28+
* #### List Refunds
29+
* List refunds available on your integration
30+
*/
31+
async list(
32+
queryParams?: ListRefundQueryParams,
33+
): Promise<ListRefundsResponse | BadRequest> {
34+
return await this.http.get('/refund', {
35+
params: { ...queryParams },
36+
});
37+
}
38+
39+
/**
40+
* #### Fetch Refund
41+
* Get details of a refund on your integration
42+
*/
43+
async fetch(reference: string): Promise<FetchRefundResponse | BadRequest> {
44+
return await this.http.get(`/refund/${reference}`);
45+
}
46+
}

src/transfer/transfer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ interface BadRequest {
1818
}
1919

2020
export class Transfer {
21-
http: Axios;
21+
private http: Axios;
2222
public control: Control;
2323
constructor(http: Axios) {
2424
this.http = http;

src/verification/interface.ts

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
export interface Response {
2-
status: boolean;
3-
message: string;
4-
}
1+
import { Response } from '../interface';
52

63
export interface ResolveAccount {
74
/**
@@ -16,16 +13,12 @@ export interface ResolveAccount {
1613
bank_code: string;
1714
}
1815

19-
export enum AccountType {
20-
personal = 'personal',
21-
business = 'business',
22-
}
16+
export type AccountType = 'personal' | 'business';
2317

24-
export enum DocumentType {
25-
idNumber = 'identityNumber',
26-
passportNumber = 'passportNumber',
27-
businessRegNumber = 'businessRegistrationNumber',
28-
}
18+
export type DocumentType =
19+
| 'identityNumber'
20+
| 'passportNumber'
21+
| 'businessRegistrationNumber';
2922

3023
export interface AccountResolved extends Response {
3124
data: {
@@ -82,7 +75,7 @@ export interface ValidateAccount {
8275
document_number: string;
8376
}
8477

85-
export interface AccountVerified extends Response {
78+
export interface AccountVerifiedResponse extends Response {
8679
data: {
8780
/**
8881
* Verification Status
@@ -96,7 +89,7 @@ export interface AccountVerified extends Response {
9689
};
9790
}
9891

99-
export interface BinResolved extends Response {
92+
export interface BinResolvedResponse extends Response {
10093
data: {
10194
bin: string;
10295
brand: string;

src/verification/verification.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,13 @@ import {
33
ResolveAccount,
44
AccountResolved,
55
ValidateAccount,
6-
AccountVerified,
7-
BinResolved,
6+
AccountVerifiedResponse,
7+
BinResolvedResponse,
88
} from './interface';
9-
10-
interface BadRequest {
11-
status: boolean;
12-
message: string;
13-
data: null;
14-
}
9+
import { BadRequest } from '../interface';
1510

1611
/**
17-
* # Verification
12+
* ## Verification
1813
* The Verification API allows you perform KYC processes.
1914
*/
2015
export class Verification {
@@ -24,7 +19,7 @@ export class Verification {
2419
}
2520

2621
/**
27-
* # Resolve Account
22+
* #### Resolve Account
2823
* Confirm an account belongs to the right customer
2924
* @param {ResolveAccount} data **Query Param**
3025
*/
@@ -35,24 +30,24 @@ export class Verification {
3530
}
3631

3732
/**
38-
* # Validate Account
33+
* #### Validate Account
3934
* Confirm the authenticity of a customer's account number
4035
* before sending money
4136
* @param {ValidateAccount} data **Data Param**
4237
*/
4338
async validateAccount(
4439
data: ValidateAccount,
45-
): Promise<AccountVerified | BadRequest> {
40+
): Promise<AccountVerifiedResponse | BadRequest> {
4641
return await this.http.post('/bank/validate', JSON.stringify(data));
4742
}
4843

4944
/**
50-
* # Resolve Card BIN
45+
* #### Resolve Card BIN
5146
* Get more information about a customer's card
5247
* using the first 6 characters of the card
5348
* @param {string} bin **Path Param**
5449
*/
55-
async resolveCard(bin: number): Promise<BinResolved | BadRequest> {
50+
async resolveCard(bin: number): Promise<BinResolvedResponse | BadRequest> {
5651
return await this.http.get(`/decision/bin/${bin}`);
5752
}
5853
}

0 commit comments

Comments
 (0)