@sergdudko/stripe-js 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/.eslintrc.js +117 -0
  2. package/CHANGELOG.md +65 -0
  3. package/README.md +120 -0
  4. package/lib/index.d.ts +24 -0
  5. package/lib/index.js +32 -0
  6. package/lib/index.js.map +1 -0
  7. package/lib/methods/addPaymentMethodToCustomer.d.ts +11 -0
  8. package/lib/methods/addPaymentMethodToCustomer.js +43 -0
  9. package/lib/methods/addPaymentMethodToCustomer.js.map +1 -0
  10. package/lib/methods/addSourceToCustomer.d.ts +11 -0
  11. package/lib/methods/addSourceToCustomer.js +43 -0
  12. package/lib/methods/addSourceToCustomer.js.map +1 -0
  13. package/lib/methods/confirmPaymentIntentByCard.d.ts +10 -0
  14. package/lib/methods/confirmPaymentIntentByCard.js +43 -0
  15. package/lib/methods/confirmPaymentIntentByCard.js.map +1 -0
  16. package/lib/methods/confirmPaymentIntentByPaymentMethod.d.ts +8 -0
  17. package/lib/methods/confirmPaymentIntentByPaymentMethod.js +13 -0
  18. package/lib/methods/confirmPaymentIntentByPaymentMethod.js.map +1 -0
  19. package/lib/methods/deletePaymentMethodFromCustomer.d.ts +10 -0
  20. package/lib/methods/deletePaymentMethodFromCustomer.js +41 -0
  21. package/lib/methods/deletePaymentMethodFromCustomer.js.map +1 -0
  22. package/lib/methods/deleteSourceFromCustomer.d.ts +11 -0
  23. package/lib/methods/deleteSourceFromCustomer.js +41 -0
  24. package/lib/methods/deleteSourceFromCustomer.js.map +1 -0
  25. package/lib/methods/getAllCards.d.ts +9 -0
  26. package/lib/methods/getAllCards.js +40 -0
  27. package/lib/methods/getAllCards.js.map +1 -0
  28. package/lib/methods/getAllPaymentMethods.d.ts +9 -0
  29. package/lib/methods/getAllPaymentMethods.js +40 -0
  30. package/lib/methods/getAllPaymentMethods.js.map +1 -0
  31. package/lib/methods/getCustomer.d.ts +9 -0
  32. package/lib/methods/getCustomer.js +39 -0
  33. package/lib/methods/getCustomer.js.map +1 -0
  34. package/lib/methods/getDefaultCard.d.ts +9 -0
  35. package/lib/methods/getDefaultCard.js +41 -0
  36. package/lib/methods/getDefaultCard.js.map +1 -0
  37. package/lib/methods/index.d.ts +18 -0
  38. package/lib/methods/index.js +35 -0
  39. package/lib/methods/index.js.map +1 -0
  40. package/lib/methods/setDefaultCard.d.ts +10 -0
  41. package/lib/methods/setDefaultCard.js +43 -0
  42. package/lib/methods/setDefaultCard.js.map +1 -0
  43. package/lib/methods/setDefaultPaymentMethod.d.ts +10 -0
  44. package/lib/methods/setDefaultPaymentMethod.js +43 -0
  45. package/lib/methods/setDefaultPaymentMethod.js.map +1 -0
  46. package/lib/utils/constants.d.ts +2 -0
  47. package/lib/utils/constants.js +6 -0
  48. package/lib/utils/constants.js.map +1 -0
  49. package/lib/utils/handlers.d.ts +7 -0
  50. package/lib/utils/handlers.js +26 -0
  51. package/lib/utils/handlers.js.map +1 -0
  52. package/package.json +56 -0
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.deleteSourceFromCustomer = void 0;
13
+ const handlers_1 = require("../utils/handlers");
14
+ const constants_1 = require("../utils/constants");
15
+ /**
16
+ * Delete card from customer.
17
+ *
18
+ * @param sourceId - source or card id (see: https://stripe.com/docs/api/sources/object#source_object-id)
19
+ * @param customerId - customer id (see: https://stripe.com/docs/api/customers/object#customer_object-id)
20
+ * @param ephemeralKey - customer ephemeral key
21
+ * @returns
22
+ */
23
+ const deleteSourceFromCustomer = function (sourceId, customerId, ephemeralKey) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ /* eslint-disable */
26
+ const stripeApiKey = this._apiKey;
27
+ /* eslint-enable */
28
+ if (typeof stripeApiKey !== "string")
29
+ throw new Error("Initialization failed.");
30
+ // make request
31
+ return yield fetch(`${constants_1.stripeApiUrl}/customers/${customerId}/sources/${sourceId}`, {
32
+ headers: {
33
+ Authorization: `Bearer ${ephemeralKey}`,
34
+ "Stripe-Version": constants_1.stripeApiVersion,
35
+ },
36
+ method: "DELETE",
37
+ }).then(handlers_1.responseHandler);
38
+ });
39
+ };
40
+ exports.deleteSourceFromCustomer = deleteSourceFromCustomer;
41
+ //# sourceMappingURL=deleteSourceFromCustomer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deleteSourceFromCustomer.js","sourceRoot":"","sources":["../../src/methods/deleteSourceFromCustomer.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,gDAAoD;AACpD,kDAAoE;AAGpE;;;;;;;GAOG;AACI,MAAM,wBAAwB,GAAG,UAEtC,QAAgB,EAChB,UAAkB,EAClB,YAAoB;;QAEpB,oBAAoB;QACpB,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC;QAClC,mBAAmB;QACnB,IAAI,OAAO,YAAY,KAAK,QAAQ;YAClC,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;QAE5C,eAAe;QACf,OAAO,MAAM,KAAK,CAChB,GAAG,wBAAY,cAAc,UAAU,YAAY,QAAQ,EAAE,EAC7D;YACE,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,YAAY,EAAE;gBACvC,gBAAgB,EAAE,4BAAgB;aACnC;YACD,MAAM,EAAE,QAAQ;SACjB,CACF,CAAC,IAAI,CAAC,0BAAe,CAAC,CAAC;IAC1B,CAAC;CAAA,CAAC;AAvBW,QAAA,wBAAwB,4BAuBnC"}
@@ -0,0 +1,9 @@
1
+ import { StripeExtension } from ".";
2
+ /**
3
+ * Get all customer's card
4
+ *
5
+ * @param customerId - customer id (see: https://stripe.com/docs/api/customers/object#customer_object-id)
6
+ * @param ephemeralKey - customer ephemeral key
7
+ * @returns
8
+ */
9
+ export declare const getAllCards: (this: StripeExtension, customerId: string, ephemeralKey: string) => Promise<any>;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.getAllCards = void 0;
13
+ const handlers_1 = require("../utils/handlers");
14
+ const constants_1 = require("../utils/constants");
15
+ /**
16
+ * Get all customer's card
17
+ *
18
+ * @param customerId - customer id (see: https://stripe.com/docs/api/customers/object#customer_object-id)
19
+ * @param ephemeralKey - customer ephemeral key
20
+ * @returns
21
+ */
22
+ const getAllCards = function (customerId, ephemeralKey) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ /* eslint-disable */
25
+ const stripeApiKey = this._apiKey;
26
+ /* eslint-enable */
27
+ if (typeof stripeApiKey !== "string")
28
+ throw new Error("Initialization failed.");
29
+ // make request
30
+ return fetch(`${constants_1.stripeApiUrl}/payment_methods?customer=${customerId}&type=card&limit=100`, {
31
+ headers: {
32
+ Authorization: `Bearer ${ephemeralKey}`,
33
+ "Stripe-Version": constants_1.stripeApiVersion,
34
+ },
35
+ method: "GET",
36
+ }).then(handlers_1.responseHandler);
37
+ });
38
+ };
39
+ exports.getAllCards = getAllCards;
40
+ //# sourceMappingURL=getAllCards.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getAllCards.js","sourceRoot":"","sources":["../../src/methods/getAllCards.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,gDAAoD;AACpD,kDAAoE;AAGpE;;;;;;GAMG;AACI,MAAM,WAAW,GAAG,UAEzB,UAAkB,EAClB,YAAoB;;QAEpB,oBAAoB;QACpB,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC;QAClC,mBAAmB;QACnB,IAAI,OAAO,YAAY,KAAK,QAAQ;YAClC,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;QAE5C,eAAe;QACf,OAAO,KAAK,CACV,GAAG,wBAAY,6BAA6B,UAAU,sBAAsB,EAC5E;YACE,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,YAAY,EAAE;gBACvC,gBAAgB,EAAE,4BAAgB;aACnC;YACD,MAAM,EAAE,KAAK;SACd,CACF,CAAC,IAAI,CAAC,0BAAe,CAAC,CAAC;IAC1B,CAAC;CAAA,CAAC;AAtBW,QAAA,WAAW,eAsBtB"}
@@ -0,0 +1,9 @@
1
+ import { StripeExtension } from ".";
2
+ /**
3
+ * Get all customer's payment methods
4
+ *
5
+ * @param customerId - customer id (see: https://stripe.com/docs/api/customers/object#customer_object-id)
6
+ * @param ephemeralKey - customer ephemeral key
7
+ * @returns
8
+ */
9
+ export declare const getAllPaymentMethods: (this: StripeExtension, customerId: string, ephemeralKey: string) => Promise<any>;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.getAllPaymentMethods = void 0;
13
+ const handlers_1 = require("../utils/handlers");
14
+ const constants_1 = require("../utils/constants");
15
+ /**
16
+ * Get all customer's payment methods
17
+ *
18
+ * @param customerId - customer id (see: https://stripe.com/docs/api/customers/object#customer_object-id)
19
+ * @param ephemeralKey - customer ephemeral key
20
+ * @returns
21
+ */
22
+ const getAllPaymentMethods = function (customerId, ephemeralKey) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ /* eslint-disable */
25
+ const stripeApiKey = this._apiKey;
26
+ /* eslint-enable */
27
+ if (typeof stripeApiKey !== "string")
28
+ throw new Error("Initialization failed.");
29
+ // make request
30
+ return fetch(`${constants_1.stripeApiUrl}/payment_methods?customer=${customerId}&type=card&limit=100`, {
31
+ headers: {
32
+ Authorization: `Bearer ${ephemeralKey}`,
33
+ "Stripe-Version": constants_1.stripeApiVersion,
34
+ },
35
+ method: "GET",
36
+ }).then(handlers_1.responseHandler);
37
+ });
38
+ };
39
+ exports.getAllPaymentMethods = getAllPaymentMethods;
40
+ //# sourceMappingURL=getAllPaymentMethods.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getAllPaymentMethods.js","sourceRoot":"","sources":["../../src/methods/getAllPaymentMethods.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,gDAAoD;AACpD,kDAAoE;AAGpE;;;;;;GAMG;AACI,MAAM,oBAAoB,GAAG,UAElC,UAAkB,EAClB,YAAoB;;QAEpB,oBAAoB;QACpB,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC;QAClC,mBAAmB;QACnB,IAAI,OAAO,YAAY,KAAK,QAAQ;YAClC,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;QAE5C,eAAe;QACf,OAAO,KAAK,CACV,GAAG,wBAAY,6BAA6B,UAAU,sBAAsB,EAC5E;YACE,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,YAAY,EAAE;gBACvC,gBAAgB,EAAE,4BAAgB;aACnC;YACD,MAAM,EAAE,KAAK;SACd,CACF,CAAC,IAAI,CAAC,0BAAe,CAAC,CAAC;IAC1B,CAAC;CAAA,CAAC;AAtBW,QAAA,oBAAoB,wBAsB/B"}
@@ -0,0 +1,9 @@
1
+ import { StripeExtension } from ".";
2
+ /**
3
+ * Get customer data
4
+ *
5
+ * @param customerId - customer id (see: https://stripe.com/docs/api/customers/object#customer_object-id)
6
+ * @param ephemeralKey - customer ephemeral key
7
+ * @returns
8
+ */
9
+ export declare const getCustomer: (this: StripeExtension, customerId: string, ephemeralKey: string) => Promise<any>;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.getCustomer = void 0;
13
+ const handlers_1 = require("../utils/handlers");
14
+ const constants_1 = require("../utils/constants");
15
+ /**
16
+ * Get customer data
17
+ *
18
+ * @param customerId - customer id (see: https://stripe.com/docs/api/customers/object#customer_object-id)
19
+ * @param ephemeralKey - customer ephemeral key
20
+ * @returns
21
+ */
22
+ const getCustomer = function (customerId, ephemeralKey) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ /* eslint-disable */
25
+ const stripeApiKey = this._apiKey;
26
+ /* eslint-enable */
27
+ if (typeof stripeApiKey !== "string")
28
+ throw new Error("Initialization failed.");
29
+ // make request
30
+ return fetch(`${constants_1.stripeApiUrl}/customers/${customerId}`, {
31
+ headers: {
32
+ Authorization: `Bearer ${ephemeralKey}`,
33
+ "Stripe-Version": constants_1.stripeApiVersion,
34
+ },
35
+ }).then(handlers_1.responseHandler);
36
+ });
37
+ };
38
+ exports.getCustomer = getCustomer;
39
+ //# sourceMappingURL=getCustomer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getCustomer.js","sourceRoot":"","sources":["../../src/methods/getCustomer.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,gDAAoD;AACpD,kDAAoE;AAGpE;;;;;;GAMG;AACI,MAAM,WAAW,GAAG,UAEzB,UAAkB,EAClB,YAAoB;;QAEpB,oBAAoB;QACpB,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC;QAClC,mBAAmB;QACnB,IAAI,OAAO,YAAY,KAAK,QAAQ;YAClC,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;QAE5C,eAAe;QACf,OAAO,KAAK,CAAC,GAAG,wBAAY,cAAc,UAAU,EAAE,EAAE;YACtD,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,YAAY,EAAE;gBACvC,gBAAgB,EAAE,4BAAgB;aACnC;SACF,CAAC,CAAC,IAAI,CAAC,0BAAe,CAAC,CAAC;IAC3B,CAAC;CAAA,CAAC;AAlBW,QAAA,WAAW,eAkBtB"}
@@ -0,0 +1,9 @@
1
+ import { StripeExtension } from ".";
2
+ /**
3
+ * Get customer's default card id
4
+ *
5
+ * @param customerId - customer id (see: https://stripe.com/docs/api/customers/object#customer_object-id)
6
+ * @param ephemeralKey - customer ephemeral key
7
+ * @returns
8
+ */
9
+ export declare const getDefaultCard: (this: StripeExtension, customerId: string, ephemeralKey: string) => Promise<string | undefined>;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.getDefaultCard = void 0;
13
+ const handlers_1 = require("../utils/handlers");
14
+ const constants_1 = require("../utils/constants");
15
+ /**
16
+ * Get customer's default card id
17
+ *
18
+ * @param customerId - customer id (see: https://stripe.com/docs/api/customers/object#customer_object-id)
19
+ * @param ephemeralKey - customer ephemeral key
20
+ * @returns
21
+ */
22
+ const getDefaultCard = function (customerId, ephemeralKey) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ /* eslint-disable */
25
+ const stripeApiKey = this._apiKey;
26
+ /* eslint-enable */
27
+ if (typeof stripeApiKey !== "string")
28
+ throw new Error("Initialization failed.");
29
+ // make request
30
+ return fetch(`${constants_1.stripeApiUrl}/customers/${customerId}`, {
31
+ headers: {
32
+ Authorization: `Bearer ${ephemeralKey}`,
33
+ "Stripe-Version": constants_1.stripeApiVersion,
34
+ },
35
+ })
36
+ .then(handlers_1.responseHandler)
37
+ .then((e) => ((e === null || e === void 0 ? void 0 : e.default_source) ? e.default_source : undefined));
38
+ });
39
+ };
40
+ exports.getDefaultCard = getDefaultCard;
41
+ //# sourceMappingURL=getDefaultCard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getDefaultCard.js","sourceRoot":"","sources":["../../src/methods/getDefaultCard.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,gDAAoD;AACpD,kDAAoE;AAGpE;;;;;;GAMG;AACI,MAAM,cAAc,GAAG,UAE5B,UAAkB,EAClB,YAAoB;;QAEpB,oBAAoB;QACpB,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC;QAClC,mBAAmB;QACnB,IAAI,OAAO,YAAY,KAAK,QAAQ;YAClC,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;QAE5C,eAAe;QACf,OAAO,KAAK,CAAC,GAAG,wBAAY,cAAc,UAAU,EAAE,EAAE;YACtD,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,YAAY,EAAE;gBACvC,gBAAgB,EAAE,4BAAgB;aACnC;SACF,CAAC;aACC,IAAI,CAAC,0BAAe,CAAC;aACrB,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,cAAc,EAAC,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;IACrE,CAAC;CAAA,CAAC;AApBW,QAAA,cAAc,kBAoBzB"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * additional stripe methods
3
+ */
4
+ export declare class StripeExtension {
5
+ constructor(apiKey: string);
6
+ _apiKey: string;
7
+ confirmPaymentIntentByCard: (this: StripeExtension, paymentIntentSecret: string, paymentMethodId: string, returnUrl?: string | undefined) => Promise<import("@stripe/stripe-js").PaymentIntent | undefined>;
8
+ confirmPaymentIntentByPaymentMethod: (this: StripeExtension, paymentIntentSecret: string, paymentMethodId: string, returnUrl?: string | undefined) => Promise<import("@stripe/stripe-js").PaymentIntent | undefined>;
9
+ addSourceToCustomer: (this: StripeExtension, token: string, customerId: string, ephemeralKey: string) => Promise<import("@stripe/stripe-js").Card | undefined>;
10
+ deleteSourceFromCustomer: (this: StripeExtension, sourceId: string, customerId: string, ephemeralKey: string) => Promise<import("@stripe/stripe-js").Card | undefined>;
11
+ getAllCards: (this: StripeExtension, customerId: string, ephemeralKey: string) => Promise<any>;
12
+ getCustomer: (this: StripeExtension, customerId: string, ephemeralKey: string) => Promise<any>;
13
+ setDefaultCard: (this: StripeExtension, cardId: string, customerId: string, ephemeralKey: string) => Promise<any>;
14
+ addPaymentMethodToCustomer: (this: StripeExtension, paymentMethodId: string, customerId: string, ephemeralKey: string) => Promise<import("@stripe/stripe-js").PaymentMethod | undefined>;
15
+ deletePaymentMethodFromCustomer: (this: StripeExtension, paymentMethodId: string, ephemeralKey: string) => Promise<import("@stripe/stripe-js").PaymentMethod | undefined>;
16
+ getAllPaymentMethods: (this: StripeExtension, customerId: string, ephemeralKey: string) => Promise<any>;
17
+ setDefaultPaymentMethod: (this: StripeExtension, paymentMethodId: string, customerId: string, ephemeralKey: string) => Promise<any>;
18
+ }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StripeExtension = void 0;
4
+ const confirmPaymentIntentByCard_1 = require("./confirmPaymentIntentByCard");
5
+ const confirmPaymentIntentByPaymentMethod_1 = require("./confirmPaymentIntentByPaymentMethod");
6
+ const addSourceToCustomer_1 = require("./addSourceToCustomer");
7
+ const deleteSourceFromCustomer_1 = require("./deleteSourceFromCustomer");
8
+ const getAllCards_1 = require("./getAllCards");
9
+ const getCustomer_1 = require("./getCustomer");
10
+ const setDefaultCard_1 = require("./setDefaultCard");
11
+ const addPaymentMethodToCustomer_1 = require("./addPaymentMethodToCustomer");
12
+ const deletePaymentMethodFromCustomer_1 = require("./deletePaymentMethodFromCustomer");
13
+ const getAllPaymentMethods_1 = require("./getAllPaymentMethods");
14
+ const setDefaultPaymentMethod_1 = require("./setDefaultPaymentMethod");
15
+ /**
16
+ * additional stripe methods
17
+ */
18
+ class StripeExtension {
19
+ constructor(apiKey) {
20
+ this.confirmPaymentIntentByCard = confirmPaymentIntentByCard_1.confirmPaymentIntentByCard;
21
+ this.confirmPaymentIntentByPaymentMethod = confirmPaymentIntentByPaymentMethod_1.confirmPaymentIntentByPaymentMethod;
22
+ this.addSourceToCustomer = addSourceToCustomer_1.addSourceToCustomer;
23
+ this.deleteSourceFromCustomer = deleteSourceFromCustomer_1.deleteSourceFromCustomer;
24
+ this.getAllCards = getAllCards_1.getAllCards;
25
+ this.getCustomer = getCustomer_1.getCustomer;
26
+ this.setDefaultCard = setDefaultCard_1.setDefaultCard;
27
+ this.addPaymentMethodToCustomer = addPaymentMethodToCustomer_1.addPaymentMethodToCustomer;
28
+ this.deletePaymentMethodFromCustomer = deletePaymentMethodFromCustomer_1.deletePaymentMethodFromCustomer;
29
+ this.getAllPaymentMethods = getAllPaymentMethods_1.getAllPaymentMethods;
30
+ this.setDefaultPaymentMethod = setDefaultPaymentMethod_1.setDefaultPaymentMethod;
31
+ this._apiKey = apiKey;
32
+ }
33
+ }
34
+ exports.StripeExtension = StripeExtension;
35
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/methods/index.ts"],"names":[],"mappings":";;;AAAA,6EAA0E;AAC1E,+FAA4F;AAC5F,+DAA4D;AAC5D,yEAAsE;AACtE,+CAA4C;AAC5C,+CAA4C;AAC5C,qDAAkD;AAClD,6EAA0E;AAC1E,uFAAoF;AACpF,iEAA8D;AAC9D,uEAAoE;AAEpE;;GAEG;AACH,MAAa,eAAe;IAC1B,YAAY,MAAc;QAInB,+BAA0B,GAAG,uDAA0B,CAAC;QACxD,wCAAmC,GACxC,yEAAmC,CAAC;QAC/B,wBAAmB,GAAG,yCAAmB,CAAC;QAC1C,6BAAwB,GAAG,mDAAwB,CAAC;QACpD,gBAAW,GAAG,yBAAW,CAAC;QAC1B,gBAAW,GAAG,yBAAW,CAAC;QAC1B,mBAAc,GAAG,+BAAc,CAAC;QAChC,+BAA0B,GAAG,uDAA0B,CAAC;QACxD,oCAA+B,GAAG,iEAA+B,CAAC;QAClE,yBAAoB,GAAG,2CAAoB,CAAC;QAC5C,4BAAuB,GAAG,iDAAuB,CAAC;QAdvD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;CAcF;AAjBD,0CAiBC"}
@@ -0,0 +1,10 @@
1
+ import { StripeExtension } from ".";
2
+ /**
3
+ * Set default customer card
4
+ *
5
+ * @param cardId - card id (see: https://stripe.com/docs/api/customers/object#card_object-id)
6
+ * @param customerId - customer id (see: https://stripe.com/docs/api/customers/object#customer_object-id)
7
+ * @param ephemeralKey - customer ephemeral key
8
+ * @returns
9
+ */
10
+ export declare const setDefaultCard: (this: StripeExtension, cardId: string, customerId: string, ephemeralKey: string) => Promise<any>;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.setDefaultCard = void 0;
13
+ const handlers_1 = require("../utils/handlers");
14
+ const constants_1 = require("../utils/constants");
15
+ /**
16
+ * Set default customer card
17
+ *
18
+ * @param cardId - card id (see: https://stripe.com/docs/api/customers/object#card_object-id)
19
+ * @param customerId - customer id (see: https://stripe.com/docs/api/customers/object#customer_object-id)
20
+ * @param ephemeralKey - customer ephemeral key
21
+ * @returns
22
+ */
23
+ const setDefaultCard = function (cardId, customerId, ephemeralKey) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ /* eslint-disable */
26
+ const stripeApiKey = this._apiKey;
27
+ /* eslint-enable */
28
+ if (typeof stripeApiKey !== "string")
29
+ throw new Error("Initialization failed.");
30
+ // make request
31
+ return fetch(`${constants_1.stripeApiUrl}/customers/${customerId}`, {
32
+ body: `default_source=${cardId}`,
33
+ headers: {
34
+ Authorization: `Bearer ${ephemeralKey}`,
35
+ "Content-Type": "application/x-www-form-urlencoded",
36
+ "Stripe-Version": constants_1.stripeApiVersion,
37
+ },
38
+ method: "POST",
39
+ }).then(handlers_1.responseHandler);
40
+ });
41
+ };
42
+ exports.setDefaultCard = setDefaultCard;
43
+ //# sourceMappingURL=setDefaultCard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setDefaultCard.js","sourceRoot":"","sources":["../../src/methods/setDefaultCard.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,gDAAoD;AACpD,kDAAoE;AAGpE;;;;;;;GAOG;AACI,MAAM,cAAc,GAAG,UAE5B,MAAc,EACd,UAAkB,EAClB,YAAoB;;QAEpB,oBAAoB;QACpB,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC;QAClC,mBAAmB;QACnB,IAAI,OAAO,YAAY,KAAK,QAAQ;YAClC,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;QAE5C,eAAe;QACf,OAAO,KAAK,CAAC,GAAG,wBAAY,cAAc,UAAU,EAAE,EAAE;YACtD,IAAI,EAAE,kBAAkB,MAAM,EAAE;YAChC,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,YAAY,EAAE;gBACvC,cAAc,EAAE,mCAAmC;gBACnD,gBAAgB,EAAE,4BAAgB;aACnC;YACD,MAAM,EAAE,MAAM;SACf,CAAC,CAAC,IAAI,CAAC,0BAAe,CAAC,CAAC;IAC3B,CAAC;CAAA,CAAC;AAtBW,QAAA,cAAc,kBAsBzB"}
@@ -0,0 +1,10 @@
1
+ import { StripeExtension } from ".";
2
+ /**
3
+ * Set default customer payment method
4
+ *
5
+ * @param paymentMethodId - payment method id (see: https://stripe.com/docs/api/customers/object#payment_method_object-id)
6
+ * @param customerId - customer id (see: https://stripe.com/docs/api/customers/object#customer_object-id)
7
+ * @param ephemeralKey - customer ephemeral key
8
+ * @returns
9
+ */
10
+ export declare const setDefaultPaymentMethod: (this: StripeExtension, paymentMethodId: string, customerId: string, ephemeralKey: string) => Promise<any>;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.setDefaultPaymentMethod = void 0;
13
+ const handlers_1 = require("../utils/handlers");
14
+ const constants_1 = require("../utils/constants");
15
+ /**
16
+ * Set default customer payment method
17
+ *
18
+ * @param paymentMethodId - payment method id (see: https://stripe.com/docs/api/customers/object#payment_method_object-id)
19
+ * @param customerId - customer id (see: https://stripe.com/docs/api/customers/object#customer_object-id)
20
+ * @param ephemeralKey - customer ephemeral key
21
+ * @returns
22
+ */
23
+ const setDefaultPaymentMethod = function (paymentMethodId, customerId, ephemeralKey) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ /* eslint-disable */
26
+ const stripeApiKey = this._apiKey;
27
+ /* eslint-enable */
28
+ if (typeof stripeApiKey !== "string")
29
+ throw new Error("Initialization failed.");
30
+ // make request for payment method api
31
+ return fetch(`${constants_1.stripeApiUrl}/customers/${customerId}`, {
32
+ body: `invoice_settings[default_payment_method]=${paymentMethodId}`,
33
+ headers: {
34
+ Authorization: `Bearer ${ephemeralKey}`,
35
+ "Content-Type": "application/x-www-form-urlencoded",
36
+ "Stripe-Version": constants_1.stripeApiVersion,
37
+ },
38
+ method: "POST",
39
+ }).then(handlers_1.responseHandler);
40
+ });
41
+ };
42
+ exports.setDefaultPaymentMethod = setDefaultPaymentMethod;
43
+ //# sourceMappingURL=setDefaultPaymentMethod.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setDefaultPaymentMethod.js","sourceRoot":"","sources":["../../src/methods/setDefaultPaymentMethod.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,gDAAoD;AACpD,kDAAoE;AAGpE;;;;;;;GAOG;AACI,MAAM,uBAAuB,GAAG,UAErC,eAAuB,EACvB,UAAkB,EAClB,YAAoB;;QAEpB,oBAAoB;QACpB,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC;QAClC,mBAAmB;QACnB,IAAI,OAAO,YAAY,KAAK,QAAQ;YAClC,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;QAC5C,sCAAsC;QACtC,OAAO,KAAK,CAAC,GAAG,wBAAY,cAAc,UAAU,EAAE,EAAE;YACtD,IAAI,EAAE,4CAA4C,eAAe,EAAE;YACnE,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,YAAY,EAAE;gBACvC,cAAc,EAAE,mCAAmC;gBACnD,gBAAgB,EAAE,4BAAgB;aACnC;YACD,MAAM,EAAE,MAAM;SACf,CAAC,CAAC,IAAI,CAAC,0BAAe,CAAC,CAAC;IAC3B,CAAC;CAAA,CAAC;AArBW,QAAA,uBAAuB,2BAqBlC"}
@@ -0,0 +1,2 @@
1
+ export declare const stripeApiUrl = "https://api.stripe.com/v1";
2
+ export declare const stripeApiVersion = "2022-11-15";
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.stripeApiVersion = exports.stripeApiUrl = void 0;
4
+ exports.stripeApiUrl = "https://api.stripe.com/v1";
5
+ exports.stripeApiVersion = "2022-11-15";
6
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/utils/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,YAAY,GAAG,2BAA2B,CAAC;AAC3C,QAAA,gBAAgB,GAAG,YAAY,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Response handler
3
+ *
4
+ * @param res - fetch response object
5
+ * @returns
6
+ */
7
+ export declare const responseHandler: (res: Response) => Promise<any>;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.responseHandler = void 0;
13
+ /**
14
+ * Response handler
15
+ *
16
+ * @param res - fetch response object
17
+ * @returns
18
+ */
19
+ const responseHandler = (res) => __awaiter(void 0, void 0, void 0, function* () {
20
+ const data = res.json();
21
+ if (!res.ok)
22
+ throw data;
23
+ return data;
24
+ });
25
+ exports.responseHandler = responseHandler;
26
+ //# sourceMappingURL=handlers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handlers.js","sourceRoot":"","sources":["../../src/utils/handlers.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;;GAKG;AACI,MAAM,eAAe,GAAG,CAAO,GAAa,EAAE,EAAE;IACrD,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC;IACxB,IAAI,CAAC,GAAG,CAAC,EAAE;QAAE,MAAM,IAAI,CAAC;IACxB,OAAO,IAAI,CAAC;AACd,CAAC,CAAA,CAAC;AAJW,QAAA,eAAe,mBAI1B"}
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@sergdudko/stripe-js",
3
+ "version": "1.0.1",
4
+ "description": "Additional methods for working with stripe-js",
5
+ "main": "./lib/index.js",
6
+ "types": "./lib/index.d.ts",
7
+ "scripts": {
8
+ "lint": "./node_modules/.bin/eslint -c .eslintrc.js --ext .ts src",
9
+ "prebuild": "npm run lint",
10
+ "build": "./node_modules/.bin/tsc --declaration",
11
+ "test": "./node_modules/.bin/nyc ./node_modules/.bin/mocha --exit ./test/*.test.js",
12
+ "doc": "./node_modules/.bin/typedoc --entryPointStrategy expand src"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/siarheidudko/stripe-js.git"
17
+ },
18
+ "keywords": [
19
+ "stripe",
20
+ "js",
21
+ "stripe-js",
22
+ "customer",
23
+ "card",
24
+ "payment_intent",
25
+ "source",
26
+ "payment_method"
27
+ ],
28
+ "author": "Siarhei Dudko <slavianich@gmail.com>",
29
+ "contributors": [
30
+ "Vadim Nesterovich <vnesterovich@remedypointsolutions.com>"
31
+ ],
32
+ "license": "MIT",
33
+ "bugs": {
34
+ "url": "https://github.com/siarheidudko/stripe-js/issues"
35
+ },
36
+ "homepage": "https://github.com/siarheidudko/stripe-js#readme",
37
+ "devDependencies": {
38
+ "@typescript-eslint/eslint-plugin": "^5.47.0",
39
+ "@typescript-eslint/parser": "^5.47.0",
40
+ "chai": "^4.3.7",
41
+ "eslint": "^8.30.0",
42
+ "eslint-config-prettier": "^8.5.0",
43
+ "eslint-plugin-import": "^2.26.0",
44
+ "jsdom": "^20.0.3",
45
+ "jsdom-global": "^3.0.2",
46
+ "mocha": "^10.2.0",
47
+ "node-fetch": "^2.6.7",
48
+ "nyc": "^15.1.0",
49
+ "stripe": "^11.5.0",
50
+ "typedoc": "^0.23.23",
51
+ "typescript": "^4.9.4"
52
+ },
53
+ "dependencies": {
54
+ "@stripe/stripe-js": "^1.46.0"
55
+ }
56
+ }