UNPKG

react-native-moyasar-sdk

Version:

Official React Native Moyasar SDK - Integrate Credit Cards, Apple Pay, Samsung Pay, and STC Pay with simple interfaces for a seamless payment experience in your React Native app

108 lines (105 loc) 3.07 kB
"use strict"; import { PaymentType } from "../../payment_type.js"; import { ApplePayPaymentResponseSource } from "../sources/apple_pay/apple_pay_response_source.js"; import { CreditCardResponseSource } from "../sources/credit_card/credit_card_response_source.js"; import { SamsungPayPaymentResponseSource } from "../sources/samsung_pay/samsung_pay_response_source.js"; import { StcPayResponseSource } from "../sources/stc_pay/stc_pay_response_source.js"; /** Moyasar API response for processing a payment. */ export class PaymentResponse { constructor({ id, status, amount, fee, currency, refunded, refundedAt, captured, capturedAt, voidedAt, description, amountFormat, feeFormat, refundedFormat, capturedFormat, invoiceId, ip, callbackUrl, createdAt, updatedAt, metadata, source }) { this.id = id; this.status = status; this.amount = amount; this.fee = fee; this.currency = currency; this.refunded = refunded; this.refundedAt = refundedAt; this.captured = captured; this.capturedAt = capturedAt; this.voidedAt = voidedAt; this.description = description; this.amountFormat = amountFormat; this.feeFormat = feeFormat; this.refundedFormat = refundedFormat; this.capturedFormat = capturedFormat; this.invoiceId = invoiceId; this.ip = ip; this.callbackUrl = callbackUrl; this.createdAt = createdAt; this.updatedAt = updatedAt; this.metadata = metadata; this.source = source; } /** * Creates a new PaymentResponse instance from a JSON object. */ static fromJson(json, paymentType) { let paymentSource; switch (paymentType) { case PaymentType.creditCard: paymentSource = CreditCardResponseSource.fromJson(json.source); break; case PaymentType.applePay: paymentSource = ApplePayPaymentResponseSource.fromJson(json.source); break; case PaymentType.stcPay: paymentSource = StcPayResponseSource.fromJson(json.source); break; case PaymentType.samsungPay: paymentSource = SamsungPayPaymentResponseSource.fromJson(json.source); break; default: paymentSource = json.source; } return new PaymentResponse({ id: json.id, status: json.status, amount: json.amount, fee: json.fee, currency: json.currency, refunded: json.refunded, refundedAt: json.refunded_at, captured: json.captured, capturedAt: json.captured_at, voidedAt: json.voided_at, description: json.description, amountFormat: json.amount_format, feeFormat: json.fee_format, refundedFormat: json.refunded_format, capturedFormat: json.captured_format, invoiceId: json.invoice_id, ip: json.ip, callbackUrl: json.callback_url, createdAt: json.created_at, updatedAt: json.updated_at, metadata: json.metadata, source: paymentSource }); } } //# sourceMappingURL=payment_response.js.map