@sahabaplus/moyasar
Version:
A comprehensive TypeScript SDK for integrating with the Moyasar payment gateway
107 lines • 3.78 kB
TypeScript
import type { ListPaymentsResponse, Payment } from "./types";
import type { CreatePaymentRequest, UpdatePaymentRequest, RefundPaymentRequest, CapturePaymentRequest } from "./types";
import { PaymentStatus, CardScheme } from "./enums";
import { type Amount, type CurrencyType } from "../../shared/types/index";
import type { MetadataValidator, ValidationResult } from "../../shared/types/index";
type PaymentUtilsParams<T extends object> = {
metadataValidator: MetadataValidator<T>;
};
export declare class PaymentUtils<T extends object> {
private readonly metadataValidator;
constructor(p: PaymentUtilsParams<T>);
/**
* Validate payment creation request using Zod
*/
validateCreatePaymentRequest(request: CreatePaymentRequest<T>): ValidationResult<CreatePaymentRequest<T>>;
/**
* Validate payment update request using Zod
*/
validateUpdatePaymentRequest(request: UpdatePaymentRequest<T>): ValidationResult<UpdatePaymentRequest<T>>;
/**
* Validate refund request using Zod
*/
validateRefundRequest(request: RefundPaymentRequest): ValidationResult<RefundPaymentRequest>;
/**
* Validate capture request using Zod
*/
validateCaptureRequest(request?: CapturePaymentRequest): ValidationResult<CapturePaymentRequest>;
/**
* Format amount for display
*/
formatAmount(amount: Amount, currency: CurrencyType): `${number} ${CurrencyType}`;
/**
* Parse amount from display format to smallest unit
*/
parseAmount(formattedAmount: string, currency: CurrencyType): number;
/**
* Check if payment is in a final state
*/
isPaymentFinal(status: PaymentStatus): boolean;
/**
* Check if payment can be refunded
*/
canRefundPayment(payment: Payment<T>): boolean;
/**
* Check if payment can be captured
*/
canCapturePayment(payment: Payment<T>): boolean;
/**
* Check if payment can be voided
*/
canVoidPayment(payment: Payment<T>): boolean;
/**
* Get maximum refund amount for a payment
*/
getMaxRefundAmount(payment: Payment<T>): number;
/**
* Get maximum capture amount for an authorized payment
*/
getMaxCaptureAmount(payment: Payment<T>): number;
/**
* Check if card scheme matches expected CVV length
*/
validateCvcLength(cvc: string, scheme?: CardScheme): boolean;
/**
* Mask card number for display (show first 6 and last 4 digits)
*/
maskCardNumber(cardNumber: string): string;
/**
* Get last 4 digits of card number
*/
getCardLast4(cardNumber: string): string;
/**
* Build metadata query parameters for filtering
*/
buildMetadataQuery(metadata: Record<string, string>): Record<string, string>;
/**
* Sanitize payment description
*/
sanitizeDescription(description: string): string;
/**
* Generate idempotency key for payment
*/
generateIdempotencyKey(prefix?: string): string;
/**
* Check if payment method requires 3DS by default
*/
requires3DS(source: CreatePaymentRequest["source"]): boolean;
/**
* Parse and validate a Payment response, ensuring all data types are correct
*/
parsePayment(payment: unknown): Payment<T>;
parseListPaymentsResponse(response: unknown): ListPaymentsResponse<T>;
/**
* Parse and validate an array of Payment responses
*/
parsePayments(payments: unknown): Payment<T>[];
/**
* Safely parse a Payment response with error handling
*/
safeParsePayment(payment: unknown): {
success: boolean;
data?: Payment<T>;
error?: string;
};
}
export * as PaymentSchemas from "./validation/schemas";
//# sourceMappingURL=utils.d.ts.map