export class TransactionData { billingData?: string; amount?: number; externalActionMessage?: string[]; amountCurrency?: string; id?: string; methodName?: string; method?: string; createdDate?: string; status?: string; customFields?: string; providerTransactionFields?: string; customFormAnswers?: string; /** * The operations (e.g. purchase, refund) carried out for this transaction, each with * its status history. For failed payments, the decline reason is available via * `operations[0].latestStatus.localizedMessage` / `providerErrorCode`. */ operations?: TransactionOperationData[]; /** The status code of the latest operation status (e.g. "7151"), for convenience. */ responseCode?: string; /** * The message of the latest operation status, for convenience * (e.g. "Authentication process for the transaction failed."). */ responseMessage?: string; /** * The localized, user-friendly message of the latest operation status, safe to show * to end-users (e.g. "Transaction declined by the bank."). */ localizedResponseMessage?: string; constructor(params: { billingData?: string; amount?: number; externalActionMessage?: string[]; amountCurrency?: string; id?: string; methodName?: string; method?: string; createdDate?: string; status?: string; customFields?: string; providerTransactionFields?: string; customFormAnswers?: string; operations?: TransactionOperationData[]; responseCode?: string; responseMessage?: string; localizedResponseMessage?: string; }) { this.billingData = params.billingData; this.amount = params.amount; this.externalActionMessage = params.externalActionMessage || []; this.amountCurrency = params.amountCurrency; this.id = params.id; this.methodName = params.methodName; this.method = params.method; this.createdDate = params.createdDate; this.status = params.status; this.customFields = params.customFields; this.providerTransactionFields = params.providerTransactionFields; this.customFormAnswers = params.customFormAnswers; this.operations = params.operations; this.responseCode = params.responseCode; this.responseMessage = params.responseMessage; this.localizedResponseMessage = params.localizedResponseMessage; } } export class TransactionOperationData { id?: string; type?: string; status?: string; /** The most recent status entry, carrying the decline reason for failed operations. */ latestStatus?: OperationStatusData; /** The full status history of the operation, oldest first. */ statuses?: OperationStatusData[]; constructor(params: { id?: string; type?: string; status?: string; latestStatus?: OperationStatusData; statuses?: OperationStatusData[]; }) { this.id = params.id; this.type = params.type; this.status = params.status; this.latestStatus = params.latestStatus; this.statuses = params.statuses; } } export class OperationStatusData { id?: string; value?: string; code?: string; message?: string; /** * A localized, user-friendly message safe to show to end-users * (e.g. "Transaction declined by the bank."). */ localizedMessage?: string; /** The provider-specific error code, when available (e.g. "20151"). */ providerErrorCode?: string; /** The provider-specific error message, when available. */ providerErrorMessage?: string; created?: string; constructor(params: { id?: string; value?: string; code?: string; message?: string; localizedMessage?: string; providerErrorCode?: string; providerErrorMessage?: string; created?: string; }) { this.id = params.id; this.value = params.value; this.code = params.code; this.message = params.message; this.localizedMessage = params.localizedMessage; this.providerErrorCode = params.providerErrorCode; this.providerErrorMessage = params.providerErrorMessage; this.created = params.created; } } export function operationStatusDataFromJson(json: { [key: string]: any; }): OperationStatusData { return new OperationStatusData({ id: json.id, value: json.value, code: json.code, message: json.message, localizedMessage: json.localized_message || json.localizedMessage, providerErrorCode: json.provider_error_code || json.providerErrorCode, providerErrorMessage: json.provider_error_message || json.providerErrorMessage, created: json.created, }); } export function transactionOperationDataFromJson(json: { [key: string]: any; }): TransactionOperationData { const latestStatus = json.latest_status || json.latestStatus; return new TransactionOperationData({ id: json.id, type: json.type, status: json.status, latestStatus: latestStatus ? operationStatusDataFromJson(latestStatus) : undefined, statuses: Array.isArray(json.statuses) ? json.statuses.map(operationStatusDataFromJson) : undefined, }); } export function transactionDataFromJson(json: { [key: string]: any; }): TransactionData { const operations = json.operations; return new TransactionData({ billingData: json.billing_data || json.billingData, amount: json.amount, externalActionMessage: json.external_action_message || json.externalActionMessage || [], amountCurrency: json.amount_currency || json.amountCurrency, id: json.id, methodName: json.method_name || json.methodName, method: json.method, createdDate: json.created_date || json.createdDate, status: json.status, customFields: json.custom_fields || json.customFields, providerTransactionFields: json.provider_transaction_fields || json.providerTransactionFields, customFormAnswers: json.custom_form_answers || json.customFormAnswers, operations: Array.isArray(operations) ? operations.map(transactionOperationDataFromJson) : undefined, responseCode: json.response_code || json.responseCode, responseMessage: json.response_message || json.responseMessage, localizedResponseMessage: json.localized_response_message || json.localizedResponseMessage, }); }