106 lines
2.5 KiB
TypeScript
Executable File
106 lines
2.5 KiB
TypeScript
Executable File
//------------------ process payment -------------------------
|
|
|
|
import Decimal from "decimal.js";
|
|
|
|
import { Payment } from "../entities/payment.entity";
|
|
import { GatewayEnum } from "../enums/gateway.enum";
|
|
import { PaymentStatus } from "../enums/payment-status.enum";
|
|
import { GatewayType } from "../types/gateway.type";
|
|
|
|
export interface IProcessPaymentParams {
|
|
amount: number;
|
|
description: string;
|
|
// callBackPath: string;
|
|
email?: string;
|
|
mobile?: string;
|
|
invoiceId?: string;
|
|
}
|
|
|
|
export interface IProcessPaymentData {
|
|
redirectUrl: string;
|
|
message: string;
|
|
reference: string;
|
|
}
|
|
|
|
//------------------ Verify payment -------------------------
|
|
|
|
export interface IVerifyPayment {
|
|
code: number;
|
|
ref_id: number;
|
|
}
|
|
|
|
export interface IPaymentVerifyParams {
|
|
amount: Decimal;
|
|
reference: string;
|
|
// status: GatewayPaymentStatus;
|
|
}
|
|
|
|
//--------------------- zarinpal --------------------------------
|
|
interface MetaData {
|
|
mobile?: string;
|
|
email?: string;
|
|
order_id?: string;
|
|
}
|
|
|
|
export interface ZarinPalPGNewArgs {
|
|
merchant_id: string;
|
|
amount: number;
|
|
description: string;
|
|
callback_url: string;
|
|
metadata?: MetaData;
|
|
currency?: "IRR" | "IRT";
|
|
}
|
|
|
|
interface IZarinPalPGRequestData {
|
|
code: number;
|
|
message: string;
|
|
authority: string;
|
|
fee_type: string;
|
|
fee: number;
|
|
}
|
|
|
|
export interface ZarinPalPGNewRequestData {
|
|
data: IZarinPalPGRequestData;
|
|
error: string[];
|
|
}
|
|
|
|
interface IZarinpalPaymentVerifyData {
|
|
code: number;
|
|
message: string;
|
|
card_hash: string;
|
|
card_pan: string;
|
|
ref_id: number;
|
|
fee_type: string;
|
|
fee: number;
|
|
}
|
|
|
|
export interface ZarinPalPGVerifyData {
|
|
data: IZarinpalPaymentVerifyData;
|
|
error: string[];
|
|
}
|
|
|
|
export interface PaymentVerificationResult {
|
|
status: PaymentStatus;
|
|
payment: Payment;
|
|
redirectUrl?: URL;
|
|
additionalParams?: Record<string, string>;
|
|
}
|
|
|
|
//********************************************** */
|
|
//------------------abstract class----------------
|
|
|
|
export interface IPaymentGateway {
|
|
processPayment(processPaymentParam: IProcessPaymentParams): Promise<IProcessPaymentData>;
|
|
verifyPayment(verifyPaymentParam: IPaymentVerifyParams): Promise<IVerifyPayment>;
|
|
}
|
|
|
|
// export abstract class PaymentGateway {
|
|
// abstract processPayment(processPaymentParam: IProcessPaymentParams): Promise<IProcessPaymentData>;
|
|
// abstract verifyPayment(verifyPaymentParam: IPaymentVerifyParams): Promise<IPaymentVerifyData>;
|
|
// }
|
|
|
|
export interface IPaymentGatewayFactory {
|
|
getPaymentGateway(provider: GatewayType): IPaymentGateway;
|
|
getAvailablePaymentGateways(): { gateways: Array<{ name: GatewayEnum }> };
|
|
}
|