UNPKG

@sergdudko/stripe-js

Version:

Additional methods for working with stripe-js

30 lines 1.55 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.confirmPaymentIntentByCard = void 0; const handlers_1 = require("../utils/handlers"); const constants_1 = require("../utils/constants"); /** * Confirm payment intent by customer's card * * @param paymentIntentSecret - stripe payment intent secret (see: https://stripe.com/docs/api/payment_intents/object#payment_intent_object-client_secret) * @param paymentMethodId - stripe customer payment method id (see: https://stripe.com/docs/api/cards/object#card_object-id) * @returns */ const confirmPaymentIntentByCard = async function (paymentIntentSecret, paymentMethodId, returnUrl) { const stripeApiKey = this._apiKey; if (typeof stripeApiKey !== "string") throw new Error("Initialization failed."); // make request const paymentIntentId = paymentIntentSecret.replace(/_secret_.+$/i, ""); return fetch(`${constants_1.stripeApiUrl}/payment_intents/${paymentIntentId}/confirm?client_secret=${paymentIntentSecret}`, { body: `payment_method=${paymentMethodId}${typeof returnUrl === 'string' ? `&return_url=${returnUrl}` : ''}`, headers: { Authorization: `Bearer ${stripeApiKey}`, "Content-Type": `application/x-www-form-urlencoded`, "Stripe-Version": `${constants_1.stripeApiVersion}`, }, method: `POST`, }).then(handlers_1.responseHandler); }; exports.confirmPaymentIntentByCard = confirmPaymentIntentByCard; //# sourceMappingURL=confirmPaymentIntentByCard.js.map