better-payment
Version:
Unified payment gateway library for Turkish payment providers
360 lines (356 loc) • 8.31 kB
TypeScript
/**
* Ödeme durumu enum'u
*/
declare enum PaymentStatus {
SUCCESS = "success",
FAILURE = "failure",
PENDING = "pending",
CANCELLED = "cancelled"
}
/**
* Para birimi
*/
declare enum Currency {
TRY = "TRY",
USD = "USD",
EUR = "EUR",
GBP = "GBP"
}
/**
* Ödeme kartı bilgileri
*/
interface PaymentCard {
cardHolderName: string;
cardNumber: string;
expireMonth: string;
expireYear: string;
cvc: string;
registerCard?: boolean;
}
/**
* Alıcı bilgileri
*/
interface Buyer {
id: string;
name: string;
surname: string;
email: string;
identityNumber: string;
registrationAddress: string;
city: string;
country: string;
zipCode?: string;
ip: string;
gsmNumber: string;
}
/**
* Adres bilgileri
*/
interface Address {
contactName: string;
city: string;
country: string;
address: string;
zipCode?: string;
}
/**
* Sepet item tipi
*/
declare enum BasketItemType {
PHYSICAL = "PHYSICAL",
VIRTUAL = "VIRTUAL"
}
/**
* Sepet item
*/
interface BasketItem {
id: string;
name: string;
category1: string;
category2?: string;
itemType: BasketItemType | string;
price: string;
}
/**
* Ödeme isteği parametreleri
*/
interface PaymentRequest {
price: string;
paidPrice: string;
currency: Currency | string;
basketId: string;
paymentCard: PaymentCard;
buyer: Buyer;
shippingAddress: Address;
billingAddress: Address;
basketItems: BasketItem[];
callbackUrl?: string;
conversationId?: string;
}
/**
* Ödeme yanıtı
*/
interface PaymentResponse {
status: PaymentStatus;
paymentId?: string;
conversationId?: string;
errorCode?: string;
errorMessage?: string;
errorGroup?: string;
rawResponse?: any;
}
/**
* 3D Secure ödeme isteği
*/
interface ThreeDSPaymentRequest extends PaymentRequest {
callbackUrl: string;
installment?: number;
}
/**
* 3D Secure ödeme başlatma yanıtı
*/
interface ThreeDSInitResponse {
status: PaymentStatus;
threeDSHtmlContent?: string;
paymentId?: string;
conversationId?: string;
errorCode?: string;
errorMessage?: string;
rawResponse?: any;
}
/**
* İade isteği
*/
interface RefundRequest {
paymentId: string;
price: string;
currency: Currency | string;
ip: string;
conversationId?: string;
}
/**
* İade yanıtı
*/
interface RefundResponse {
status: PaymentStatus;
refundId?: string;
conversationId?: string;
errorCode?: string;
errorMessage?: string;
rawResponse?: any;
}
/**
* İptal isteği
*/
interface CancelRequest {
paymentId: string;
ip: string;
conversationId?: string;
}
/**
* İptal yanıtı
*/
interface CancelResponse {
status: PaymentStatus;
transactionId?: string;
voidId?: string;
conversationId?: string;
errorCode?: string;
errorMessage?: string;
rawResponse: unknown;
}
/**
* BIN sorgulama yanıtı
*/
interface BinCheckResponse {
binNumber: string;
cardType: string;
cardAssociation: string;
cardFamily: string;
bankName: string;
bankCode: number;
commercial: boolean;
rawResponse?: unknown;
}
/**
* Checkout Form isteği
*/
interface CheckoutFormRequest {
price: string;
paidPrice: string;
currency: Currency | string;
basketId: string;
callbackUrl: string;
enabledInstallments?: number[];
buyer: Buyer;
shippingAddress: Address;
billingAddress: Address;
basketItems: BasketItem[];
conversationId?: string;
}
/**
* Checkout Form başlatma yanıtı
*/
interface CheckoutFormInitResponse {
status: PaymentStatus;
checkoutFormContent?: string;
paymentPageUrl?: string;
token?: string;
tokenExpireTime?: number;
conversationId?: string;
errorCode?: string;
errorMessage?: string;
rawResponse?: any;
}
/**
* Checkout Form sonuç yanıtı
*/
interface CheckoutFormRetrieveResponse {
status: PaymentStatus;
paymentId?: string;
paymentStatus?: string;
price?: number;
paidPrice?: number;
currency?: string;
basketId?: string;
installment?: number;
binNumber?: string;
lastFourDigits?: string;
cardType?: string;
cardAssociation?: string;
cardFamily?: string;
cardToken?: string;
cardUserKey?: string;
fraudStatus?: number;
merchantCommissionRate?: number;
merchantCommissionRateAmount?: number;
iyziCommissionRateAmount?: number;
iyziCommissionFee?: number;
paymentTransactionId?: string;
conversationId?: string;
errorCode?: string;
errorMessage?: string;
rawResponse?: any;
}
/**
* Ödeme sağlayıcısı yapılandırması
*/
interface PaymentProviderConfig {
apiKey: string;
secretKey: string;
baseUrl: string;
locale?: string;
}
/**
* Tüm ödeme sağlayıcıları için temel abstract sınıf
*/
declare abstract class PaymentProvider {
protected config: PaymentProviderConfig;
constructor(config: PaymentProviderConfig);
/**
* Yapılandırmayı doğrula
*/
protected validateConfig(): void;
/**
* Direkt ödeme (3D Secure olmadan)
*/
abstract createPayment(request: PaymentRequest): Promise<PaymentResponse>;
/**
* 3D Secure ödeme başlat
*/
abstract initThreeDSPayment(request: ThreeDSPaymentRequest): Promise<ThreeDSInitResponse>;
/**
* 3D Secure ödeme tamamla (callback'ten sonra)
*/
abstract completeThreeDSPayment(callbackData: any): Promise<PaymentResponse>;
/**
* İade işlemi
*/
abstract refund(request: RefundRequest): Promise<RefundResponse>;
/**
* İptal işlemi
*/
abstract cancel(request: CancelRequest): Promise<CancelResponse>;
/**
* Ödeme sorgulama
*/
abstract getPayment(paymentId: string): Promise<PaymentResponse>;
/**
* BIN sorgulama
*/
binCheck(binNumber: string): Promise<BinCheckResponse>;
}
/**
* Provider türleri
*/
declare enum ProviderType {
IYZICO = "iyzico",
PAYTR = "paytr",
AKBANK = "akbank"
}
/**
* İyzico provider config
*/
interface IyzicoProviderConfig {
enabled: boolean;
config: PaymentProviderConfig;
}
/**
* PayTR provider config (ek alanlar gerekiyor)
*/
interface PayTRProviderConfig {
enabled: boolean;
config: PaymentProviderConfig & {
merchantId: string;
merchantSalt: string;
};
}
/**
* Akbank provider config (ek alanlar gerekiyor)
*/
interface AkbankProviderConfig {
enabled: boolean;
config: PaymentProviderConfig & {
merchantId: string;
terminalId: string;
storeKey: string;
secure3DStoreKey?: string;
testMode?: boolean;
};
}
/**
* Her provider için config (generic type)
*/
interface ProviderConfig {
enabled: boolean;
config: PaymentProviderConfig | (PaymentProviderConfig & {
merchantId: string;
merchantSalt: string;
}) | (PaymentProviderConfig & {
merchantId: string;
terminalId: string;
storeKey: string;
secure3DStoreKey?: string;
testMode?: boolean;
});
}
/**
* BetterPay ana konfigürasyonu
*/
interface BetterPayConfig {
providers: {
[ProviderType.IYZICO]?: IyzicoProviderConfig;
[ProviderType.PAYTR]?: PayTRProviderConfig;
[ProviderType.AKBANK]?: AkbankProviderConfig;
};
defaultProvider?: ProviderType;
}
/**
* Provider instance map
*/
interface ProviderInstances {
[ProviderType.IYZICO]?: any;
[ProviderType.PAYTR]?: any;
[ProviderType.AKBANK]?: any;
}
export { type Address as A, type BinCheckResponse as B, type CancelRequest as C, ProviderType as P, type RefundRequest as R, type ThreeDSPaymentRequest as T, type PaymentRequest as a, type PaymentResponse as b, type ThreeDSInitResponse as c, type RefundResponse as d, type CancelResponse as e, PaymentProvider as f, type PaymentProviderConfig as g, type CheckoutFormRequest as h, type CheckoutFormInitResponse as i, type CheckoutFormRetrieveResponse as j, type BetterPayConfig as k, type ProviderConfig as l, type ProviderInstances as m, PaymentStatus as n, Currency as o, BasketItemType as p, type PaymentCard as q, type Buyer as r, type BasketItem as s };