mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-26 18:42:49 +00:00
Merge pull request #104 from Tria-plc/freight/feature/payment
minor update
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
import { IsString } from "class-validator";
|
||||
|
||||
export class InitiateBookingPayment {
|
||||
@IsString()
|
||||
bookingId!: string;
|
||||
}
|
||||
@@ -16,13 +16,12 @@ export class PaymentController {
|
||||
return res.send(filled)
|
||||
}
|
||||
|
||||
@Post("/initiate")
|
||||
@Post("/initiate/booking")
|
||||
async initiatePayment() {
|
||||
|
||||
//Only for testing..
|
||||
const redirectBaseURL = "http://localhost:3004/payment"
|
||||
const description = "booking"
|
||||
const data = await this.paymentService.pay(redirectBaseURL, 20, "ETB", "telebirr", description, (_) => {
|
||||
const data = await this.paymentService.pay(20, "ETB", "telebirr", description, "booking", (_) => {
|
||||
return new Promise((resp, _) => {
|
||||
resp({
|
||||
id: randomUUID(),
|
||||
@@ -59,26 +58,4 @@ export class PaymentController {
|
||||
`);
|
||||
}
|
||||
|
||||
|
||||
// @Get("test")
|
||||
// handleTest(@Res() res: Response) {
|
||||
|
||||
|
||||
// const filePath = path.join(__dirname, "templates", "payment.hbs");
|
||||
// console.log(filePath)
|
||||
// console.log(__dirname)
|
||||
// if (fs.existsSync(filePath)) {
|
||||
// const source = fs.readFileSync(filePath, "utf8");
|
||||
// const template = Handlebars.compile(source);
|
||||
|
||||
// const html = template({
|
||||
// url: "https://example.com"
|
||||
// });
|
||||
|
||||
// res.send(html)
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ export class PaymentService {
|
||||
])
|
||||
}
|
||||
|
||||
async pay(redirectBaseURL: string, amount: number, currency: CurrencyType, method: PaymentMethod, reason: string, cb: (qr: QueryRunner) => Promise<{ id: string, type: PaymentEntity["type"] }>, payform: PaymentPlatform = "web"): Promise<{
|
||||
async pay(amount: number, currency: CurrencyType, method: PaymentMethod, reason: string, type: PaymentEntity["type"], cb: (qr: QueryRunner) => Promise<{ id: string, type: PaymentEntity["type"] }>, payform: PaymentPlatform = "web"): Promise<{
|
||||
refId: string,
|
||||
clientAction: ClientAction,
|
||||
status: PaymentEntity["status"],
|
||||
@@ -43,9 +43,16 @@ export class PaymentService {
|
||||
throw new NotFoundException("strategy not found")
|
||||
}
|
||||
|
||||
const orderId = `freigh${Date.now()}${crypto.randomBytes(4).toString('hex')}` //todo: make it dynamic
|
||||
const orderId = `${Date.now()}${crypto.randomBytes(4).toString('hex')}` //todo: make it dynamic
|
||||
let redirectUrl: string;
|
||||
switch (type) {
|
||||
case "booking":
|
||||
redirectUrl = `http://localhost:3001/api/payments/receipts/${orderId}/html`
|
||||
break;
|
||||
}
|
||||
|
||||
const paymentResp = await strategy.pay({
|
||||
redirectBaseURL,
|
||||
redirectUrl,
|
||||
amountMinor: amount,
|
||||
currency: currency,
|
||||
merchantOrderId: orderId,
|
||||
@@ -104,7 +111,7 @@ export class PaymentService {
|
||||
throw new BadRequestException()
|
||||
}
|
||||
|
||||
const filePath = path.join(__dirname, "templates", "ceiepts.hbs");
|
||||
const filePath = path.join(__dirname, "templates", "receipt.hbs");
|
||||
if (!fs.existsSync(filePath)) {
|
||||
throw new InternalServerErrorException()
|
||||
}
|
||||
|
||||
@@ -22,8 +22,7 @@ export class PaymentTelebirrStrategy implements PaymentStrategy {
|
||||
async pay(data: ProviderInitiationInput): Promise<any> {
|
||||
// const refId = randomUUID()
|
||||
// const orderId = createMerchantOrderId()
|
||||
const redirectURL = `${data.redirectBaseURL}/${data.merchantOrderId}`
|
||||
const resp = await this.initiate(redirectURL, data)
|
||||
const resp = await this.initiate(data)
|
||||
return resp;
|
||||
}
|
||||
|
||||
@@ -45,9 +44,9 @@ export class PaymentTelebirrStrategy implements PaymentStrategy {
|
||||
});
|
||||
}
|
||||
|
||||
async initiate(redirectURL: string, input: ProviderInitiationInput): Promise<ProviderInitiationResult> {
|
||||
async initiate(input: ProviderInitiationInput): Promise<ProviderInitiationResult> {
|
||||
const fabricToken = await this.applyFabricToken();
|
||||
const requestBody = this.buildCreateOrderRequest(redirectURL, input);
|
||||
const requestBody = this.buildCreateOrderRequest(input);
|
||||
const response = await this.requestCreateOrder(fabricToken, requestBody);
|
||||
|
||||
const prepayId = response.biz_content?.prepay_id;
|
||||
@@ -177,7 +176,7 @@ export class PaymentTelebirrStrategy implements PaymentStrategy {
|
||||
);
|
||||
}
|
||||
|
||||
private buildCreateOrderRequest(redirectURL: string, input: ProviderInitiationInput): CreateOrderRequest {
|
||||
private buildCreateOrderRequest(input: ProviderInitiationInput): CreateOrderRequest {
|
||||
// const totalAmount = String(input.amountMinor / 100);
|
||||
const totalAmount = String(input.amountMinor)
|
||||
const req = {
|
||||
@@ -188,7 +187,7 @@ export class PaymentTelebirrStrategy implements PaymentStrategy {
|
||||
biz_content: {
|
||||
notify_url: this.notifyUrl,
|
||||
appid: this.merchantAppId,
|
||||
redirect_url: redirectURL,
|
||||
redirect_url: input.redirectUrl,
|
||||
merch_code: this.merchantCode,
|
||||
merch_order_id: input.merchantOrderId,
|
||||
trade_type: 'Checkout' as const,
|
||||
|
||||
@@ -10,7 +10,7 @@ export type ClientAction =
|
||||
| { type: 'LAUNCH_APP'; prepayId: string; receiveCode?: string; shortCode: string };
|
||||
|
||||
export interface ProviderInitiationInput {
|
||||
redirectBaseURL: string;
|
||||
redirectUrl: string;
|
||||
merchantOrderId: string;
|
||||
// bookingRef: string;
|
||||
amountMinor: number;
|
||||
|
||||
Reference in New Issue
Block a user