UNPKG

@automattic/wpcom-checkout

Version:
64 lines 3.35 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createGooglePayMethod = createGooglePayMethod; exports.GooglePayLabel = GooglePayLabel; exports.GooglePaySubmitButton = GooglePaySubmitButton; exports.GooglePaySummary = GooglePaySummary; const tslib_1 = require("tslib"); const jsx_runtime_1 = require("react/jsx-runtime"); const composite_checkout_1 = require("@automattic/composite-checkout"); const debug_1 = tslib_1.__importDefault(require("debug")); const react_1 = require("react"); const google_pay_mark_1 = require("../google-pay-mark"); const payment_method_logos_1 = require("../payment-method-logos"); const payment_request_button_1 = tslib_1.__importDefault(require("../payment-request-button")); const web_pay_utils_1 = require("./web-pay-utils"); const debug = (0, debug_1.default)('wpcom-checkout:google-pay-payment-method'); function createGooglePayMethod(stripe, stripeConfiguration, cartKey) { return { id: 'google-pay', paymentProcessorId: 'google-pay', label: (0, jsx_runtime_1.jsx)(GooglePayLabel, {}), submitButton: ((0, jsx_runtime_1.jsx)(GooglePaySubmitButton, { stripe: stripe, stripeConfiguration: stripeConfiguration, cartKey: cartKey })), inactiveContent: (0, jsx_runtime_1.jsx)(GooglePaySummary, {}), getAriaLabel: () => 'Google Pay', isInitiallyDisabled: true, }; } function GooglePayLabel() { return ((0, jsx_runtime_1.jsxs)(react_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("span", { children: "Google Pay" }), (0, jsx_runtime_1.jsx)(payment_method_logos_1.PaymentMethodLogos, { className: "google-pay__logo payment-logos", children: (0, jsx_runtime_1.jsx)(google_pay_mark_1.GooglePayMark, { fill: "#3C4043" }) })] })); } function GooglePaySubmitButton({ disabled, onClick, stripe, stripeConfiguration, cartKey, }) { const togglePaymentMethod = (0, composite_checkout_1.useTogglePaymentMethod)(); const paymentRequestOptions = (0, web_pay_utils_1.usePaymentRequestOptions)(stripeConfiguration, cartKey); const onSubmit = (0, react_1.useCallback)(({ name, paymentMethodToken }) => { debug('submitting stripe payment with key', paymentMethodToken); if (!onClick) { throw new Error('Missing onClick prop; GooglePaySubmitButton must be used as a payment button in CheckoutSubmitButton'); } onClick({ stripe, paymentMethodToken, name, stripeConfiguration, }); }, [onClick, stripe, stripeConfiguration]); const { paymentRequest, allowedPaymentTypes, isLoading } = (0, web_pay_utils_1.useStripePaymentRequest)({ paymentRequestOptions, onSubmit, stripe, }); (0, react_1.useEffect)(() => { if (!isLoading) { togglePaymentMethod('google-pay', allowedPaymentTypes.googlePay); } }, [isLoading, allowedPaymentTypes.googlePay, togglePaymentMethod]); if (!allowedPaymentTypes.googlePay) { return null; } return ((0, jsx_runtime_1.jsx)(payment_request_button_1.default, { disabled: isLoading ? true : disabled, paymentRequest: paymentRequest, paymentType: "google-pay" })); } function GooglePaySummary() { return (0, jsx_runtime_1.jsx)(react_1.Fragment, { children: "Google Pay" }); } //# sourceMappingURL=google-pay.js.map