@montarist/nestpay-api-v2
Version:
Unofficial comprehensive TypeScript API client for Nestpay payment gateway with 3D Secure support
302 lines • 7.23 kB
TypeScript
import { BankProvider, Currency, EncodingType, HashAlgorithm, InstallmentType, Language, MdStatus, ResponseCode, StoreType, ThreeDModel, ThreeDStatus, TransactionType } from './enums';
/**
* Provider endpoint configuration for different banks
*/
export interface ProviderEndpoints {
production: {
api: string;
threeD: string;
};
test: {
api: string;
threeD: string;
};
}
/**
* Configuration interface for initializing Nestpay client
*/
export interface NestpayConfig {
clientId: string;
username: string;
password: string;
storeKey: string;
storeType: StoreType;
provider?: BankProvider;
threeDModel?: ThreeDModel;
isTestMode?: boolean;
hashAlgorithm?: HashAlgorithm;
encodingType?: EncodingType;
apiEndpoint?: string;
threeDEndpoint?: string;
language?: Language;
/** For 3D Pay model specific settings */
refreshTime?: number;
/** For 3D Pay Hosting model */
payHostingUrl?: string;
/** Custom provider endpoints (only for BankProvider.CUSTOM) */
customEndpoints?: ProviderEndpoints;
}
/**
* Credit card information interface
*/
export interface CreditCard {
pan: string;
expiry: string;
cvv: string;
cardHolderName?: string;
}
/**
* Customer information interface
*/
export interface Customer {
name?: string;
email?: string;
phone?: string;
ipAddress?: string;
userId?: string;
}
/**
* Billing address interface
*/
export interface BillingAddress {
name?: string;
company?: string;
address1?: string;
address2?: string;
city?: string;
state?: string;
postalCode?: string;
country?: string;
}
/**
* Shipping address interface
*/
export interface ShippingAddress extends BillingAddress {
}
/**
* Base payment request interface
*/
export interface BasePaymentRequest {
amount: number;
currency: Currency;
orderId: string;
installment?: InstallmentType;
description?: string;
customer?: Customer;
billingAddress?: BillingAddress;
shippingAddress?: ShippingAddress;
extra?: Record<string, string>;
}
/**
* Direct payment request interface
*/
export interface DirectPaymentRequest extends BasePaymentRequest {
creditCard: CreditCard;
transactionType?: TransactionType;
}
/**
* Base 3D Secure payment request interface
*/
export interface BaseThreeDPaymentRequest extends BasePaymentRequest {
creditCard: CreditCard;
callbackUrl: string;
failureUrl: string;
transactionType?: TransactionType;
}
/**
* 3D Secure Classic payment request interface
*/
export interface ThreeDClassicPaymentRequest extends BaseThreeDPaymentRequest {
model: ThreeDModel.CLASSIC;
}
/**
* 3D Pay payment request interface
*/
export interface ThreeDPayPaymentRequest extends BaseThreeDPaymentRequest {
model: ThreeDModel.PAY;
refreshTime?: number;
}
/**
* 3D Pay Hosting payment request interface
*/
export interface ThreeDPayHostingPaymentRequest extends BaseThreeDPaymentRequest {
model: ThreeDModel.PAY_HOSTING;
payHostingUrl?: string;
}
/**
* Union type for all 3D Secure payment requests
*/
export type ThreeDPaymentRequest = ThreeDClassicPaymentRequest | ThreeDPayPaymentRequest | ThreeDPayHostingPaymentRequest | BaseThreeDPaymentRequest;
/**
* 3D Secure form data interface
*/
export interface ThreeDFormData {
html: string;
formAction: string;
formData: Record<string, string>;
model: ThreeDModel;
/** For 3D Pay model - auto submit form after this time */
refreshTime?: number;
}
/**
* Enhanced 3D Secure callback response interface
*/
export interface ThreeDCallbackResponse {
status: ThreeDStatus;
mdStatus?: MdStatus | string;
cavv?: string;
eci?: string;
xid?: string;
hash?: string;
orderId?: string;
amount?: string;
currency?: string;
response?: string;
procReturnCode?: string;
transId?: string;
hostRefNum?: string;
authCode?: string;
errorMessage?: string;
/** 3D Pay specific fields */
payResults?: string;
payResultsData?: string;
/** 3D Pay Hosting specific fields */
merchantId?: string;
/** Model used for this transaction */
model?: ThreeDModel;
}
/**
* Base payment response interface
*/
export interface BasePaymentResponse {
success: boolean;
orderId: string;
transactionId?: string;
authCode?: string;
hostRefNum?: string;
procReturnCode?: string;
response?: ResponseCode;
errorMessage?: string;
hash?: string;
}
/**
* Direct payment response interface
*/
export interface DirectPaymentResponse extends BasePaymentResponse {
amount: number;
currency: Currency;
installment?: string;
}
/**
* 3D Secure payment response interface
*/
export interface ThreeDPaymentResponse extends BasePaymentResponse {
amount: number;
currency: Currency;
threeDStatus: ThreeDStatus;
mdStatus?: MdStatus | string;
cavv?: string;
eci?: string;
xid?: string;
/** Model used for this transaction */
model: ThreeDModel;
}
/**
* Refund request interface
*/
export interface RefundRequest {
orderId: string;
amount?: number;
currency?: Currency;
description?: string;
}
/**
* Refund response interface
*/
export interface RefundResponse extends BasePaymentResponse {
originalOrderId: string;
refundAmount: number;
currency: Currency;
}
/**
* Void request interface
*/
export interface VoidRequest {
orderId: string;
description?: string;
}
/**
* Void response interface
*/
export interface VoidResponse extends BasePaymentResponse {
originalOrderId: string;
}
/**
* Transaction query request interface
*/
export interface TransactionQueryRequest {
orderId: string;
}
/**
* Transaction query response interface
*/
export interface TransactionQueryResponse {
success: boolean;
orderId: string;
transactionId?: string;
amount?: number;
currency?: Currency;
status?: string;
authCode?: string;
hostRefNum?: string;
transactionType?: TransactionType;
transactionDate?: string;
errorMessage?: string;
}
/**
* Error response interface
*/
export interface ErrorResponse {
success: false;
errorCode?: string;
errorMessage: string;
details?: Record<string, unknown>;
}
/**
* Hash parameters interface for generating secure hashes
*/
export interface HashParameters {
clientId: string;
orderId: string;
amount: string;
currency: string;
storeKey: string;
[key: string]: string;
}
/**
* Enhanced hash parameters for different 3D models
*/
export interface ThreeDHashParameters {
clientId: string;
orderId: string;
amount: string;
currency: string;
storeKey: string;
callbackUrl: string;
model: ThreeDModel;
installment?: string;
/** For 3D Pay model */
refreshTime?: string;
/** For 3D Pay Hosting model */
payHostingUrl?: string;
[key: string]: string | undefined;
}
/**
* API response wrapper interface
*/
export interface ApiResponse<T> {
data?: T;
error?: ErrorResponse;
raw?: Record<string, unknown>;
}
//# sourceMappingURL=interfaces.d.ts.map