UNPKG

@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.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.addPaymentMethodToCustomer = void 0; const handlers_js_1 = require("../utils/handlers.js"); const constants_js_1 = require("../utils/constants.js"); /** * Add payment method to customer. * * @param paymentMethodId - payment method id (see: https://stripe.com/docs/api/customers/object#payment_method_object-id) * @param customerId - customer id (see: https://stripe.com/docs/api/customers/object#customer_object-id) * @param ephemeralKey - customer ephemeral key * @returns */ const addPaymentMethodToCustomer = async function (paymentMethodId, customerId, ephemeralKey) { const stripeApiKey = this._apiKey; if (typeof stripeApiKey !== "string") throw new Error("Initialization failed."); // make request return fetch(`${constants_js_1.stripeApiUrl}/payment_methods/${paymentMethodId}/attach`, { body: `customer=${customerId}`, headers: { Authorization: `Bearer ${ephemeralKey}`, "Content-Type": "application/x-www-form-urlencoded", "Stripe-Version": `${constants_js_1.stripeApiVersion}`, }, method: "POST", }).then(handlers_js_1.responseHandler); }; exports.addPaymentMethodToCustomer = addPaymentMethodToCustomer;