UNPKG

@apicart/payments-sdk

Version:

Apicart SDK for payment gateways integration

75 lines (55 loc) 1.43 kB
import Apicart from '@apicart/core-sdk'; import PaymentGateway from '../PaymentGateway/PaymentGateway'; export default class PaymentGatewaysPage { private _filteredTotal: number; private _gateways: PaymentGateway[] = []; private _hasMore: boolean; private _total: number; constructor( filteredTotal: number, hasMore: boolean, total: number, gateways: PaymentGateway[] = [] ) { this._filteredTotal = filteredTotal; this._hasMore = hasMore; this._total = total; this._gateways = gateways; } public getFilteredTotal(): number { return this._filteredTotal; } public setFilteredTotal(filteredTotal: number): void { this._filteredTotal = filteredTotal; } public getGateways(): PaymentGateway[] { return this._gateways; } public hasMore(): boolean { return this._hasMore; } public addGateway(paymentGateway: PaymentGateway): void { this._gateways.push(paymentGateway); } public getTotal(): number { return this._total; } public setTotal(total: number): void { this._total = total; } public static deserialize(data: any): PaymentGatewaysPage { const paymentGatewaysPage = new PaymentGatewaysPage(data.filteredTotal, data.hasMore, data.total); Apicart.Utils.Loops.forEach(data.gateways, (paymentGateway: Record<string, any>): void => { paymentGatewaysPage.addGateway(PaymentGateway.deserialize(paymentGateway)); }); return paymentGatewaysPage; } }