UNPKG

@rnw-community/react-native-payments

Version:

Accept Payments with Apple Pay and Android Pay using the Payment Request API.

69 lines 3.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PaymentResponse = void 0; const shared_1 = require("@rnw-community/shared"); const payments_error_enum_js_1 = require("../../enum/payments-error.enum.js"); const dom_exception_js_1 = require("../../error/dom.exception.js"); const payments_error_js_1 = require("../../error/payments.error.js"); const native_payments_js_1 = require("../native-payments/native-payments.js"); /* * https://www.w3.org/TR/payment-request/#paymentresponse-interface */ class PaymentResponse { constructor( // https://www.w3.org/TR/payment-request/#dom-paymentresponse-requestid requestId, // https://www.w3.org/TR/payment-request/#dom-paymentresponse-methodname methodName, // https://www.w3.org/TR/payment-request/#dom-paymentresponse-details details, shippingOption = null) { this.requestId = requestId; this.methodName = methodName; this.details = details; this.shippingOption = shippingOption; this.completeCalled = false; this.retryCalled = false; } // https://www.w3.org/TR/payment-request/#complete-method async complete(result) { if (this.completeCalled || this.retryCalled) { throw new dom_exception_js_1.DOMException(payments_error_enum_js_1.PaymentsErrorEnum.InvalidStateError); } this.completeCalled = true; // TODO: Implement logic https://www.w3.org/TR/payment-request/#complete-method return native_payments_js_1.NativePayments.complete(result); } // https://www.w3.org/TR/payment-request/#dom-paymentresponse-retry async retry(errorFields) { if (this.completeCalled) { throw new dom_exception_js_1.DOMException(payments_error_enum_js_1.PaymentsErrorEnum.InvalidStateError); } if (this.retryCalled) { throw new dom_exception_js_1.DOMException(payments_error_enum_js_1.PaymentsErrorEnum.InvalidStateError); } const { retry } = native_payments_js_1.NativePayments; if (!(0, shared_1.isDefined)(retry)) { throw new dom_exception_js_1.DOMException(payments_error_enum_js_1.PaymentsErrorEnum.NotSupportedError); } this.retryCalled = true; await retry(this.requestId, errorFields ?? {}).catch(() => { throw new payments_error_js_1.PaymentsError(`Failed retrying PaymentRequest`); }); // eslint-disable-next-line no-undefined return undefined; } toJSON() { return { requestId: this.requestId, methodName: this.methodName, details: this.details, shippingAddress: this.details.shippingAddress ?? null, shippingOption: this.shippingOption, payerEmail: this.details.payerEmail ?? null, payerName: this.details.payerName ?? null, payerPhone: this.details.payerPhone ?? null, }; } } exports.PaymentResponse = PaymentResponse; //# sourceMappingURL=payment-response.js.map