Skip to content

Commit 76325f4

Browse files
authored
🤖 Merge PR DefinitelyTyped#73488 feat(midtrans-client): Add initial type definitions by @MystiaFin
1 parent ff1fa4a commit 76325f4

File tree

5 files changed

+99
-0
lines changed

5 files changed

+99
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*
2+
!**/*.d.ts
3+
!**/*.d.cts
4+
!**/*.d.mts
5+
!**/*.d.*.ts
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
export interface MidtransClientOptions {
2+
isProduction: boolean;
3+
serverKey: string;
4+
clientKey: string;
5+
}
6+
7+
export interface TransactionDetails {
8+
order_id: string;
9+
gross_amount: number;
10+
}
11+
12+
export interface SnapTransactionParameters {
13+
transaction_details: TransactionDetails;
14+
}
15+
16+
export interface SnapTransactionResponse {
17+
token: string;
18+
redirect_url: string;
19+
}
20+
21+
export class Snap {
22+
constructor(options: MidtransClientOptions);
23+
createTransaction(parameter: SnapTransactionParameters): Promise<SnapTransactionResponse>;
24+
}
25+
26+
export class CoreApi {
27+
constructor(options: MidtransClientOptions);
28+
charge(parameter: any): Promise<any>;
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import * as midtransClient from 'midtrans-client';
2+
3+
const snap = new midtransClient.Snap({
4+
isProduction: false,
5+
serverKey: 'YOUR_SERVER_KEY',
6+
clientKey: 'YOUR_CLIENT_KEY',
7+
});
8+
9+
const parameters: midtransClient.SnapTransactionParameters = {
10+
transaction_details: {
11+
order_id: 'ORDER-ID-' + new Date().getTime(),
12+
gross_amount: 200000,
13+
},
14+
};
15+
16+
snap.createTransaction(parameters).then((transaction: midtransClient.SnapTransactionResponse) => {
17+
const token: string = transaction.token;
18+
const redirectUrl: string = transaction.redirect_url;
19+
});
20+
21+
const core = new midtransClient.CoreApi({
22+
isProduction: false,
23+
serverKey: 'YOUR_SERVER_KEY',
24+
clientKey: 'YOUR_CLIENT_KEY',
25+
});
26+
27+
core.charge({}).then((chargeResponse: any) => {
28+
const response = chargeResponse;
29+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"private": true,
3+
"name": "@types/midtrans-client",
4+
"version": "1.4.9999",
5+
"projects": [
6+
"https://github.com/midtrans/midtrans-nodejs-client"
7+
],
8+
"devDependencies": {
9+
"@types/midtrans-client": "workspace:."
10+
},
11+
"owners": [
12+
{
13+
"name": "MystiaFin",
14+
"githubUsername": "MystiaFin"
15+
}
16+
]
17+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"lib": [
5+
"es6"
6+
],
7+
"noImplicitAny": true,
8+
"noImplicitThis": true,
9+
"strictFunctionTypes": true,
10+
"strictNullChecks": true,
11+
"types": [],
12+
"noEmit": true,
13+
"forceConsistentCasingInFileNames": true
14+
},
15+
"files": [
16+
"index.d.ts",
17+
"midtrans-client-tests.ts"
18+
]
19+
}

0 commit comments

Comments
 (0)