-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from swikars1/add-types
add khalti api calls
- Loading branch information
Showing
7 changed files
with
124 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"khalti-epayment": minor | ||
--- | ||
|
||
add khalti api calls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +0,0 @@ | ||
import axios from "axios"; | ||
|
||
export const khaltiInstanceServer = axios.create({ | ||
baseURL: "https://a.khalti.com/api/v2", | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Key f79110302bbf46828fca3a7b7514da97`, // live secret key | ||
}, | ||
responseType: "json", | ||
}); | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,50 @@ | ||
export const add = (a: number, b: number) => { | ||
return a + b + 4; | ||
import axios from "axios"; | ||
import type { | ||
InitiatePaymentRequest, | ||
InitiatePaymentResponse, | ||
} from "./epaymentv2/initiatePayment"; | ||
import type { AllLookupResponse } from "./epaymentv2/paymentLookup"; | ||
|
||
async function awTry<T>(promise: unknown) { | ||
try { | ||
const data = await promise; | ||
return [data, null] as [T, never]; | ||
} catch (err) { | ||
console.error(err); | ||
return [null, err] as [never, unknown]; | ||
} | ||
} | ||
|
||
const khaltiInstanceServer = axios.create({ | ||
baseURL: "https://a.khalti.com/api/v2", | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Key f79110302bbf46828fca3a7b7514da97`, // live secret key | ||
}, | ||
responseType: "json", | ||
}); | ||
|
||
const paymentLookup = async (pidx: string) => { | ||
const [response, error] = await awTry<{ data: AllLookupResponse }>( | ||
khaltiInstanceServer.get(`/epayment/lookup?pidx=${pidx}`) | ||
); | ||
if (error) { | ||
console.log("Error, in lookupPayment: ", error); | ||
} | ||
return response.data; | ||
}; | ||
|
||
const initiatePayment = async (payload: InitiatePaymentRequest) => { | ||
const [response, error] = await awTry<{ data: InitiatePaymentResponse }>( | ||
khaltiInstanceServer.post("/epayment/initiate/", payload) | ||
); | ||
if (error) { | ||
console.log("Error, in initiatePayment: ", error); | ||
} | ||
return response.data; | ||
}; | ||
|
||
export const khaltiApi = { | ||
initiatePayment, | ||
paymentLookup, | ||
}; |