@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.
24 lines (23 loc) • 965 B
JavaScript
import { responseHandler } from "../utils/handlers.js";
import { stripeApiUrl, stripeApiVersion } from "../utils/constants.js";
/**
* Delete card from customer.
*
* @param sourceId - source or card id (see: https://stripe.com/docs/api/sources/object#source_object-id)
* @param customerId - customer id (see: https://stripe.com/docs/api/customers/object#customer_object-id)
* @param ephemeralKey - customer ephemeral key
* @returns
*/
export const deleteSourceFromCustomer = async function (sourceId, customerId, ephemeralKey) {
const stripeApiKey = this._apiKey;
if (typeof stripeApiKey !== "string")
throw new Error("Initialization failed.");
// make request
return await fetch(`${stripeApiUrl}/customers/${customerId}/sources/${sourceId}`, {
headers: {
Authorization: `Bearer ${ephemeralKey}`,
"Stripe-Version": stripeApiVersion,
},
method: "DELETE",
}).then(responseHandler);
};