UNPKG

@darkwolf/telegram-bot.lazy.cjs

Version:
103 lines (91 loc) 2.56 kB
const Helper = require('@darkwolf/helper.cjs') const types = require('./') class SuccessfulPayment { constructor(data = {}, context) { this .setContext(context) .setId(data.id) .setProviderPaymentId(data.providerPaymentId) .setCurrency(data.currency) .setTotalAmount(data.totalAmount) .setInvoicePayload(data.invoicePayload) .setShippingOptionId(data.shippingOptionId) .setOrderInfo(data.orderInfo) } setContext(context = {}) { this.context = context return this } setId(id) { this.id = id return this } setProviderPaymentId(id) { this.providerPaymentId = id return this } setCurrency(currency) { this.currency = currency return this } setTotalAmount(amount) { this.totalAmount = amount return this } setInvoicePayload(payload) { this.invoicePayload = payload return this } setShippingOptionId(id) { this.shippingOptionId = id return this } setOrderInfo(orderInfo) { this.orderInfo = orderInfo ? ( orderInfo instanceof types.OrderInfo ? orderInfo : new types.OrderInfo(orderInfo, this.context) ) : undefined return this } toJSON() { const data = {} if (this.id) { data.id = this.id } if (this.providerPaymentId) { data.providerPaymentId = this.providerPaymentId } if (this.currency) { data.currency = this.currency } if (Helper.exists(this.totalAmount)) { data.totalAmount = this.totalAmount } if (Helper.exists(this.invoicePayload)) { data.invoicePayload = this.invoicePayload } if (this.shippingOptionId) { data.shippingOptionId = this.shippingOptionId } if (this.orderInfo) { data.orderInfo = this.orderInfo.toJSON() } return data } } SuccessfulPayment.from = (data, context) => new SuccessfulPayment(data, context) SuccessfulPayment.fromParams = (params = {}, context) => { const data = { id: params.telegram_payment_charge_id, providerPaymentId: params.provider_payment_charge_id, currency: params.currency, totalAmount: params.total_amount, invoicePayload: params.invoice_payload, shippingOptionId: params.shipping_option_id, orderInfo: params.order_info } if (data.orderInfo) { data.orderInfo = types.OrderInfo.fromParams(data.orderInfo, context) } return new SuccessfulPayment(data, context) } module.exports = SuccessfulPayment