UNPKG

@sergdudko/stripe-js

Version:

Additional methods for working with stripe-js

30 lines 1.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.setDefaultCard = void 0; const handlers_1 = require("../utils/handlers"); const constants_1 = require("../utils/constants"); /** * Set default customer card * * @param cardId - card id (see: https://stripe.com/docs/api/customers/object#card_object-id) * @param customerId - customer id (see: https://stripe.com/docs/api/customers/object#customer_object-id) * @param ephemeralKey - customer ephemeral key * @returns */ const setDefaultCard = async function (cardId, customerId, ephemeralKey) { const stripeApiKey = this._apiKey; if (typeof stripeApiKey !== "string") throw new Error("Initialization failed."); // make request return fetch(`${constants_1.stripeApiUrl}/customers/${customerId}`, { body: `default_source=${cardId}`, headers: { Authorization: `Bearer ${ephemeralKey}`, "Content-Type": "application/x-www-form-urlencoded", "Stripe-Version": constants_1.stripeApiVersion, }, method: "POST", }).then(handlers_1.responseHandler); }; exports.setDefaultCard = setDefaultCard; //# sourceMappingURL=setDefaultCard.js.map