@sergdudko/stripe-js
Version:
Additional methods for working with stripe-js
43 lines • 2.11 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.addSourceToCustomer = void 0;
const handlers_1 = require("../utils/handlers");
const constants_1 = require("../utils/constants");
/**
* Add card to customer (from source or token).
*
* @param token - source or token string (see: https://stripe.com/docs/api/sources/object)
* @param customerId - customer id (see: https://stripe.com/docs/api/customers/object#customer_object-id)
* @param ephemeralKey - customer ephemeral key
* @returns
*/
const addSourceToCustomer = function (token, customerId, ephemeralKey) {
return __awaiter(this, void 0, void 0, function* () {
/* eslint-disable */
const stripeApiKey = this._apiKey;
/* eslint-enable */
if (typeof stripeApiKey !== "string")
throw new Error("Initialization failed.");
// make request
return fetch(`${constants_1.stripeApiUrl}/customers/${customerId}/sources`, {
body: `source=${token}`,
headers: {
Authorization: `Bearer ${ephemeralKey}`,
"Content-Type": "application/x-www-form-urlencoded",
"Stripe-Version": `${constants_1.stripeApiVersion}`,
},
method: "POST",
}).then(handlers_1.responseHandler);
});
};
exports.addSourceToCustomer = addSourceToCustomer;
//# sourceMappingURL=addSourceToCustomer.js.map