@sergdudko/stripe-js
Version:
Supercharge Your Stripe Integration with Enhanced Methods for stripe-js: Take Full Control of Customer Card Management Right from Your Frontend! Elevate Your Payment Processing Capabilities with Ease and Efficiency.
30 lines (29 loc) • 1.51 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.confirmPaymentIntentByCard = void 0;
const handlers_js_1 = require("../utils/handlers.js");
const constants_js_1 = require("../utils/constants.js");
/**
* 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_js_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_js_1.stripeApiVersion}`,
},
method: `POST`,
}).then(handlers_js_1.responseHandler);
};
exports.confirmPaymentIntentByCard = confirmPaymentIntentByCard;