@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
package/.eslintrc.js ADDED
@@ -0,0 +1,117 @@
1
+ module.exports = {
2
+ env: {
3
+ browser: true,
4
+ es6: true,
5
+ node: true,
6
+ },
7
+ extends: [
8
+ "eslint:recommended",
9
+ "prettier",
10
+ "plugin:import/errors",
11
+ "plugin:import/warnings",
12
+ "plugin:import/typescript",
13
+ ],
14
+ globals: {
15
+ Atomics: "readonly",
16
+ SharedArrayBuffer: "readonly",
17
+ },
18
+ parser: "@typescript-eslint/parser",
19
+ parserOptions: {
20
+ project: "tsconfig.json",
21
+ sourceType: "module",
22
+ },
23
+ plugins: ["@typescript-eslint"],
24
+ rules: {
25
+ "@typescript-eslint/adjacent-overload-signatures": "error",
26
+ "@typescript-eslint/no-empty-function": "error",
27
+ "@typescript-eslint/no-empty-interface": "off",
28
+ "@typescript-eslint/no-floating-promises": "error",
29
+ "@typescript-eslint/no-namespace": "error",
30
+ "@typescript-eslint/no-unnecessary-type-assertion": "error",
31
+ "@typescript-eslint/prefer-for-of": "warn",
32
+ "@typescript-eslint/triple-slash-reference": "error",
33
+ "@typescript-eslint/unified-signatures": "warn",
34
+ "comma-dangle": ["warn", "only-multiline"],
35
+ "constructor-super": "error",
36
+ eqeqeq: ["warn", "always"],
37
+ "for-direction": "error",
38
+ "getter-return": "error",
39
+ "import/no-deprecated": "warn",
40
+ "import/no-extraneous-dependencies": "error",
41
+ "import/no-unassigned-import": "warn",
42
+ "no-async-promise-executor": "error",
43
+ "no-case-declarations": "error",
44
+ "no-class-assign": "error",
45
+ "no-compare-neg-zero": "error",
46
+ "no-cond-assign": "error",
47
+ "no-const-assign": "error",
48
+ "no-constant-condition": "error",
49
+ "no-control-regex": "error",
50
+ "no-debugger": "error",
51
+ "no-delete-var": "error",
52
+ "no-dupe-args": "error",
53
+ "no-dupe-class-members": "error",
54
+ "no-dupe-else-if": "error",
55
+ "no-dupe-keys": "error",
56
+ "no-duplicate-case": "error",
57
+ "no-duplicate-imports": "error",
58
+ "no-empty": [
59
+ "error",
60
+ {
61
+ allowEmptyCatch: true,
62
+ },
63
+ ],
64
+ "no-empty-character-class": "error",
65
+ "no-empty-pattern": "error",
66
+ "no-ex-assign": "error",
67
+ "no-extra-boolean-cast": "error",
68
+ "no-extra-semi": "error",
69
+ "no-fallthrough": "error",
70
+ "no-func-assign": "error",
71
+ "no-global-assign": "error",
72
+ "no-import-assign": "error",
73
+ "no-inner-declarations": "error",
74
+ "no-invalid-regexp": "error",
75
+ "no-invalid-this": "error",
76
+ "no-irregular-whitespace": "error",
77
+ "no-misleading-character-class": "error",
78
+ "no-mixed-spaces-and-tabs": "error",
79
+ "no-new-symbol": "error",
80
+ "no-new-wrappers": "error",
81
+ "no-obj-calls": "error",
82
+ "no-octal": "error",
83
+ "no-param-reassign": "error",
84
+ "no-prototype-builtins": "error",
85
+ "no-redeclare": "error",
86
+ "no-regex-spaces": "error",
87
+ "no-self-assign": "error",
88
+ "no-sequences": "error",
89
+ "no-setter-return": "error",
90
+ "no-shadow": [
91
+ "error",
92
+ {
93
+ hoist: "all",
94
+ },
95
+ ],
96
+ "no-shadow-restricted-names": "error",
97
+ "no-sparse-arrays": "error",
98
+ "no-this-before-super": "error",
99
+ "no-throw-literal": "error",
100
+ "no-undef": "error",
101
+ "no-unexpected-multiline": "error",
102
+ "no-unreachable": "error",
103
+ "no-unsafe-finally": "error",
104
+ "no-unsafe-negation": "error",
105
+ "no-unused-labels": "error",
106
+ "no-unused-vars": "off",
107
+ "no-useless-catch": "error",
108
+ "no-useless-escape": "error",
109
+ "no-var": "warn",
110
+ "no-void": "error",
111
+ "no-with": "error",
112
+ "prefer-const": "warn",
113
+ "require-yield": "error",
114
+ "use-isnan": "error",
115
+ "valid-typeof": "error",
116
+ },
117
+ };
package/CHANGELOG.md ADDED
@@ -0,0 +1,65 @@
1
+ # 1.0.1 / 2022-12-28
2
+
3
+ ### :tada: Enhancements
4
+
5
+ - Updated libs
6
+ - Fixed method `confirmPaymentIntentByPaymentMethod`
7
+ - Added tests
8
+
9
+ # 1.0.0 / 2022-06-27
10
+
11
+ ### :tada: Enhancements
12
+
13
+ - Updated libs
14
+ - Added method `addPaymentMethodToCustomer`
15
+ - Added method `confirmPaymentIntentByPaymentMethod`
16
+ - Added method `deletePaymentMethodFromCustomer`
17
+ - Added method `getAllPaymentMethods`
18
+ - Added method `getDefaultCard`
19
+ - Added method `setDefaultPaymentMethod`
20
+ - Changed method `getAllCards`
21
+ - Changed method `getCustomer`
22
+ - Changed method `setDefaultCard`
23
+
24
+ # 0.0.6 / 2021-12-21
25
+
26
+ ### :tada: Enhancements
27
+
28
+ - Add type's declaration
29
+
30
+ # 0.0.5 / 2021-11-30
31
+
32
+ ### :tada: Enhancements
33
+
34
+ - Add new param to `confirmPaymentIntentByCard`
35
+
36
+ # 0.0.4 / 2021-11-09
37
+
38
+ ### :tada: Enhancements
39
+
40
+ - Added method `getAllCards`
41
+ - Added method `getCustomer`
42
+ - Added method `setDefaultCard`
43
+ - Updated docs
44
+
45
+ # 0.0.3 / 2021-11-03
46
+
47
+ ### :tada: Enhancements
48
+
49
+ - Added method `addSourceToCustomer`
50
+ - Added method `deleteSourceFromCustomer`
51
+ - Updated ci/cd
52
+ - Updated docs
53
+
54
+ # 0.0.2 / 2021-11-03
55
+
56
+ ### :tada: Enhancements
57
+
58
+ - Updating documentation
59
+
60
+ # 0.0.1 / 2021-11-03
61
+
62
+ ### :tada: Enhancements
63
+
64
+ - Development started
65
+ - Added method `confirmPaymentIntentByCard`
package/README.md ADDED
@@ -0,0 +1,120 @@
1
+ # @sergdudko/stripe-js
2
+
3
+ Additional methods for working with stripe-js
4
+
5
+ [![npm](https://img.shields.io/npm/v/@sergdudko/stripe-js.svg)](https://www.npmjs.com/package/@sergdudko/stripe-js)
6
+ [![npm](https://img.shields.io/npm/dy/@sergdudko/stripe-js.svg)](https://www.npmjs.com/package/@sergdudko/stripe-js)
7
+ [![NpmLicense](https://img.shields.io/npm/l/@sergdudko/stripe-js.svg)](https://www.npmjs.com/package/@sergdudko/stripe-js)
8
+ ![GitHub last commit](https://img.shields.io/github/last-commit/siarheidudko/stripe-js.svg)
9
+ ![GitHub release](https://img.shields.io/github/release/siarheidudko/stripe-js.svg)
10
+
11
+ ## Usage
12
+
13
+ ### `loadStripe`
14
+
15
+ ```js
16
+ import { loadStripe } from "@sergdudko/stripe-js";
17
+
18
+ const stripe = await loadStripe("pk_test_TYooMQauvdEDq54NiTphI7jx");
19
+ ```
20
+
21
+ ## Stripe.js Documentation
22
+
23
+ - [Stripe.js Docs](https://stripe.com/docs/stripe-js)
24
+ - [Stripe.js Reference](https://stripe.com/docs/js)
25
+ - [React Stripe.js Docs](https://stripe.com/docs/stripe-js/react)
26
+
27
+ ## Additional Methods
28
+
29
+ | Method | Arguments | Description |
30
+ | ----------------------------------- | --------------------------------------------------- | ---------------------------------------------------------------------------- |
31
+ | getCustomer | [customer_id], [ephemeral_key] | Get customer. |
32
+ | confirmPaymentIntentByCard | [client_secret], [card_id], [returnUrl] | Confirm payment intent with the user's payment card (sources api). |
33
+ | addSourceToCustomer | [source or token], [customer_id], [ephemeral_key] | Add payment card to customer (from source or token, sources api). |
34
+ | deleteSourceFromCustomer | [source_id], [customer_id], [ephemeral_key] | Delete payment card from customer (sources api). |
35
+ | getAllCards | [customer_id], [ephemeral_key] | Get all cards from customer (sources api). |
36
+ | setDefaultCard | [defaultCardId], [customer_id], [ephemeral_key] | Set default card (sources api). |
37
+ | getDefaultCard | [customer_id], [ephemeral_key] | Get customer default payment card (sources api). |
38
+ | confirmPaymentIntentByPaymentMethod | [client_secret], [payment_method_id], [returnUrl] | Confirm payment intent with the user's payment method (payment methods api). |
39
+ | addPaymentMethodToCustomer | [payment_method_id], [customer_id], [ephemeral_key] | Attach payment method to customer (payment methods api). |
40
+ | deletePaymentMethodFromCustomer | [payment_method_id], [ephemeral_key] | Detach payment method from customer (payment methods api). |
41
+ | getAllPaymentMethods | [customer_id], [ephemeral_key] | Get all payment methods from customer (payment methods api). |
42
+ | setDefaultPaymentMethod | [payment_method_id], [customer_id], [ephemeral_key] | Set customer default payment method (payment methods api). |
43
+
44
+ ## Examples
45
+
46
+ ```
47
+ stripe.getCustomer(
48
+ 'cus_KO9SkBdMeHoMXR',
49
+ 'ek_test_YWNjdF8xSFhSd0xIZGxNYVpsZTNlLENrVUxKWWNjZExxSDJDb1VKa1YwaXU5VDZVcmVmQXQ_00drAg7pBQ'
50
+ );
51
+
52
+ stripe.confirmPaymentIntentByCard(
53
+ 'pi_3Jrk80HdlMaZle3e1tGtSxiH_secret_mWdWNlqJfkYEoYOml1GqRPyPm',
54
+ 'card_1JrMi8HdlMaZle3eSPPOvapJ',
55
+ 'https://stripe.com/'
56
+ );
57
+
58
+ stripe.addSourceToCustomer(
59
+ 'tok_visa',
60
+ 'cus_KO9SkBdMeHoMXR',
61
+ 'ek_test_YWNjdF8xSFhSd0xIZGxNYVpsZTNlLENrVUxKWWNjZExxSDJDb1VKa1YwaXU5VDZVcmVmQXQ_00drAg7pBQ'
62
+ );
63
+
64
+ stripe.deleteSourceFromCustomer(
65
+ 'card_1JroRSHdlMaZle3e4EIGOZuv',
66
+ 'cus_KO9SkBdMeHoMXR',
67
+ 'ek_test_YWNjdF8xSFhSd0xIZGxNYVpsZTNlLENrVUxKWWNjZExxSDJDb1VKa1YwaXU5VDZVcmVmQXQ_00drAg7pBQ'
68
+ );
69
+
70
+ stripe.getAllCards(
71
+ 'cus_KO9SkBdMeHoMXR',
72
+ 'ek_test_YWNjdF8xSFhSd0xIZGxNYVpsZTNlLENrVUxKWWNjZExxSDJDb1VKa1YwaXU5VDZVcmVmQXQ_00drAg7pBQ'
73
+ );
74
+
75
+ stripe.setDefaultCard(
76
+ 'card_1JrMi8HdlMaZle3eSPPOvapJ',
77
+ 'cus_KO9SkBdMeHoMXR',
78
+ 'ek_test_YWNjdF8xSFhSd0xIZGxNYVpsZTNlLENrVUxKWWNjZExxSDJDb1VKa1YwaXU5VDZVcmVmQXQ_00drAg7pBQ'
79
+ );
80
+
81
+ stripe.getDefaultCard(
82
+ 'cus_KO9SkBdMeHoMXR',
83
+ 'ek_test_YWNjdF8xSFhSd0xIZGxNYVpsZTNlLENrVUxKWWNjZExxSDJDb1VKa1YwaXU5VDZVcmVmQXQ_00drAg7pBQ'
84
+ );
85
+
86
+ stripe.confirmPaymentIntentByPaymentMethod(
87
+ 'pi_3Jrk80HdlMaZle3e1tGtSxiH_secret_mWdWNlqJfkYEoYOml1GqRPyPm',
88
+ 'pm_1JrMi8HdlMaZle3eSPPOvapJ',
89
+ 'https://stripe.com/'
90
+ );
91
+
92
+ stripe.addPaymentMethodToCustomer(
93
+ 'pm_1JrMi8HdlMaZle3eSPPOvapJ',
94
+ 'cus_KO9SkBdMeHoMXR',
95
+ 'ek_test_YWNjdF8xSFhSd0xIZGxNYVpsZTNlLENrVUxKWWNjZExxSDJDb1VKa1YwaXU5VDZVcmVmQXQ_00drAg7pBQ'
96
+ );
97
+
98
+ stripe.deletePaymentMethodFromCustomer(
99
+ 'pm_1JrMi8HdlMaZle3eSPPOvapJ',
100
+ 'ek_test_YWNjdF8xSFhSd0xIZGxNYVpsZTNlLENrVUxKWWNjZExxSDJDb1VKa1YwaXU5VDZVcmVmQXQ_00drAg7pBQ'
101
+ );
102
+
103
+ stripe.getAllPaymentMethods(
104
+ 'cus_KO9SkBdMeHoMXR',
105
+ 'ek_test_YWNjdF8xSFhSd0xIZGxNYVpsZTNlLENrVUxKWWNjZExxSDJDb1VKa1YwaXU5VDZVcmVmQXQ_00drAg7pBQ'
106
+ );
107
+
108
+ stripe.setDefaultPaymentMethod(
109
+ 'pm_1JrMi8HdlMaZle3eSPPOvapJ',
110
+ 'cus_KO9SkBdMeHoMXR',
111
+ 'ek_test_YWNjdF8xSFhSd0xIZGxNYVpsZTNlLENrVUxKWWNjZExxSDJDb1VKa1YwaXU5VDZVcmVmQXQ_00drAg7pBQ'
112
+ );
113
+ ```
114
+
115
+ ## Scripts
116
+
117
+ - To run linting `npm run lint`.
118
+ - To run build `npm run build`.
119
+ - To run testing `npm run test`.
120
+ - To create docs `npm run doc`.
package/lib/index.d.ts ADDED
@@ -0,0 +1,24 @@
1
+ import { StripeConstructorOptions, Stripe as StripeDefault } from "@stripe/stripe-js";
2
+ import { StripeExtension } from "./methods/index";
3
+ /**
4
+ * Stripe default interface
5
+ */
6
+ export interface StripeDefaultWithInternal extends StripeDefault {
7
+ /**
8
+ * Stripe api key after initialization, like pk_...
9
+ */
10
+ _apiKey: string;
11
+ }
12
+ /**
13
+ * Stripe patched library
14
+ */
15
+ export interface Stripe extends StripeExtension, StripeDefault {
16
+ }
17
+ /**
18
+ * Initialize stripe
19
+ *
20
+ * @param publishableKey - stripe public key, like pk_...
21
+ * @param options - stripe initialization options
22
+ * @returns
23
+ */
24
+ export declare const loadStripe: (publishableKey: string, options: StripeConstructorOptions | undefined) => Promise<Stripe>;
package/lib/index.js ADDED
@@ -0,0 +1,32 @@
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.loadStripe = void 0;
13
+ const stripe_js_1 = require("@stripe/stripe-js");
14
+ const index_1 = require("./methods/index");
15
+ /**
16
+ * Initialize stripe
17
+ *
18
+ * @param publishableKey - stripe public key, like pk_...
19
+ * @param options - stripe initialization options
20
+ * @returns
21
+ */
22
+ const loadStripe = (publishableKey, options) => __awaiter(void 0, void 0, void 0, function* () {
23
+ const stripeDefault = yield (0, stripe_js_1.loadStripe)(publishableKey, options);
24
+ if (stripeDefault === null ||
25
+ typeof (stripeDefault === null || stripeDefault === void 0 ? void 0 : stripeDefault._apiKey) !== "string")
26
+ throw new Error("Initialization error.");
27
+ const stripeExtension = new index_1.StripeExtension(stripeDefault._apiKey);
28
+ const stripe = Object.assign(stripeExtension, stripeDefault);
29
+ return stripe;
30
+ });
31
+ exports.loadStripe = loadStripe;
32
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iDAI2B;AAC3B,2CAAkD;AAiBlD;;;;;;GAMG;AACI,MAAM,UAAU,GAAG,CACxB,cAAsB,EACtB,OAA6C,EAC7C,EAAE;IACF,MAAM,aAAa,GAAyB,MAAM,IAAA,sBAAiB,EACjE,cAAc,EACd,OAAO,CACR,CAAC;IACF,IACE,aAAa,KAAK,IAAI;QACtB,OAAO,CAAC,aAA2C,aAA3C,aAAa,uBAAb,aAAa,CAAgC,OAAO,CAAA,KAAK,QAAQ;QAEzE,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;IAC3C,MAAM,eAAe,GAAG,IAAI,uBAAe,CACxC,aAA2C,CAAC,OAAO,CACrD,CAAC;IACF,MAAM,MAAM,GAAW,MAAM,CAAC,MAAM,CAAC,eAAe,EAAE,aAAa,CAAC,CAAC;IACrE,OAAO,MAAM,CAAC;AAChB,CAAC,CAAA,CAAC;AAlBW,QAAA,UAAU,cAkBrB"}
@@ -0,0 +1,11 @@
1
+ import { PaymentMethod } from "@stripe/stripe-js";
2
+ import { StripeExtension } from "./index";
3
+ /**
4
+ * Add payment method to customer.
5
+ *
6
+ * @param paymentMethodId - payment method id (see: https://stripe.com/docs/api/customers/object#payment_method_object-id)
7
+ * @param customerId - customer id (see: https://stripe.com/docs/api/customers/object#customer_object-id)
8
+ * @param ephemeralKey - customer ephemeral key
9
+ * @returns
10
+ */
11
+ export declare const addPaymentMethodToCustomer: (this: StripeExtension, paymentMethodId: string, customerId: string, ephemeralKey: string) => Promise<PaymentMethod | undefined>;
@@ -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.addPaymentMethodToCustomer = void 0;
13
+ const handlers_1 = require("../utils/handlers");
14
+ const constants_1 = require("../utils/constants");
15
+ /**
16
+ * Add payment method to customer.
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 addPaymentMethodToCustomer = 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
31
+ return fetch(`${constants_1.stripeApiUrl}/payment_methods/${paymentMethodId}/attach`, {
32
+ body: `customer=${customerId}`,
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.addPaymentMethodToCustomer = addPaymentMethodToCustomer;
43
+ //# sourceMappingURL=addPaymentMethodToCustomer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addPaymentMethodToCustomer.js","sourceRoot":"","sources":["../../src/methods/addPaymentMethodToCustomer.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,gDAAoD;AACpD,kDAAoE;AAGpE;;;;;;;GAOG;AACI,MAAM,0BAA0B,GAAG,UAExC,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;QAE5C,eAAe;QACf,OAAO,KAAK,CAAC,GAAG,wBAAY,oBAAoB,eAAe,SAAS,EAAE;YACxE,IAAI,EAAE,YAAY,UAAU,EAAE;YAC9B,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,YAAY,EAAE;gBACvC,cAAc,EAAE,mCAAmC;gBACnD,gBAAgB,EAAE,GAAG,4BAAgB,EAAE;aACxC;YACD,MAAM,EAAE,MAAM;SACf,CAAC,CAAC,IAAI,CAAC,0BAAe,CAAC,CAAC;IAC3B,CAAC;CAAA,CAAC;AAtBW,QAAA,0BAA0B,8BAsBrC"}
@@ -0,0 +1,11 @@
1
+ import { Card } from "@stripe/stripe-js";
2
+ import { StripeExtension } from "./index";
3
+ /**
4
+ * Add card to customer (from source or token).
5
+ *
6
+ * @param token - source or token string (see: https://stripe.com/docs/api/sources/object)
7
+ * @param customerId - customer id (see: https://stripe.com/docs/api/customers/object#customer_object-id)
8
+ * @param ephemeralKey - customer ephemeral key
9
+ * @returns
10
+ */
11
+ export declare const addSourceToCustomer: (this: StripeExtension, token: string, customerId: string, ephemeralKey: string) => Promise<Card | undefined>;
@@ -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.addSourceToCustomer = void 0;
13
+ const handlers_1 = require("../utils/handlers");
14
+ const constants_1 = require("../utils/constants");
15
+ /**
16
+ * Add card to customer (from source or token).
17
+ *
18
+ * @param token - source or token string (see: https://stripe.com/docs/api/sources/object)
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 addSourceToCustomer = function (token, 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}/sources`, {
32
+ body: `source=${token}`,
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.addSourceToCustomer = addSourceToCustomer;
43
+ //# sourceMappingURL=addSourceToCustomer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addSourceToCustomer.js","sourceRoot":"","sources":["../../src/methods/addSourceToCustomer.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,gDAAoD;AACpD,kDAAoE;AAGpE;;;;;;;GAOG;AACI,MAAM,mBAAmB,GAAG,UAEjC,KAAa,EACb,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,UAAU,EAAE;YAC9D,IAAI,EAAE,UAAU,KAAK,EAAE;YACvB,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,YAAY,EAAE;gBACvC,cAAc,EAAE,mCAAmC;gBACnD,gBAAgB,EAAE,GAAG,4BAAgB,EAAE;aACxC;YACD,MAAM,EAAE,MAAM;SACf,CAAC,CAAC,IAAI,CAAC,0BAAe,CAAC,CAAC;IAC3B,CAAC;CAAA,CAAC;AAtBW,QAAA,mBAAmB,uBAsB9B"}
@@ -0,0 +1,10 @@
1
+ import { PaymentIntentResult } from "@stripe/stripe-js";
2
+ import { StripeExtension } from "./index";
3
+ /**
4
+ * Confirm payment intent by customer's card
5
+ *
6
+ * @param paymentIntentSecret - stripe payment intent secret (see: https://stripe.com/docs/api/payment_intents/object#payment_intent_object-client_secret)
7
+ * @param paymentMethodId - stripe customer payment method id (see: https://stripe.com/docs/api/cards/object#card_object-id)
8
+ * @returns
9
+ */
10
+ export declare const confirmPaymentIntentByCard: (this: StripeExtension, paymentIntentSecret: string, paymentMethodId: string, returnUrl?: string) => Promise<PaymentIntentResult["paymentIntent"] | undefined>;
@@ -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.confirmPaymentIntentByCard = void 0;
13
+ const handlers_1 = require("../utils/handlers");
14
+ const constants_1 = require("../utils/constants");
15
+ /**
16
+ * Confirm payment intent by customer's card
17
+ *
18
+ * @param paymentIntentSecret - stripe payment intent secret (see: https://stripe.com/docs/api/payment_intents/object#payment_intent_object-client_secret)
19
+ * @param paymentMethodId - stripe customer payment method id (see: https://stripe.com/docs/api/cards/object#card_object-id)
20
+ * @returns
21
+ */
22
+ const confirmPaymentIntentByCard = function (paymentIntentSecret, paymentMethodId, returnUrl) {
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
+ const paymentIntentId = paymentIntentSecret.replace(/_secret_.+$/i, "");
31
+ return fetch(`${constants_1.stripeApiUrl}/payment_intents/${paymentIntentId}/confirm?client_secret=${paymentIntentSecret}`, {
32
+ body: `payment_method=${paymentMethodId}${typeof returnUrl === 'string' ? `&return_url=${returnUrl}` : ''}`,
33
+ headers: {
34
+ Authorization: `Bearer ${stripeApiKey}`,
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.confirmPaymentIntentByCard = confirmPaymentIntentByCard;
43
+ //# sourceMappingURL=confirmPaymentIntentByCard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"confirmPaymentIntentByCard.js","sourceRoot":"","sources":["../../src/methods/confirmPaymentIntentByCard.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,gDAAoD;AACpD,kDAAoE;AAGpE;;;;;;GAMG;AACI,MAAM,0BAA0B,GAAG,UAExC,mBAA2B,EAC3B,eAAuB,EACvB,SAAkB;;QAElB,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,MAAM,eAAe,GAAG,mBAAmB,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC;QACxE,OAAO,KAAK,CACV,GAAG,wBAAY,oBAAoB,eAAe,0BAA0B,mBAAmB,EAAE,EACjG;YACE,IAAI,EAAE,kBAAkB,eAAe,GAAG,OAAO,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,eAAe,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE;YAC3G,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,YAAY,EAAE;gBACvC,cAAc,EAAE,mCAAmC;gBACnD,gBAAgB,EAAE,GAAG,4BAAgB,EAAE;aACxC;YACD,MAAM,EAAE,MAAM;SACf,CACF,CAAC,IAAI,CAAC,0BAAe,CAAC,CAAC;IAC1B,CAAC;CAAA,CAAC;AA1BW,QAAA,0BAA0B,8BA0BrC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Confirm payment intent by customer's payment method
3
+ *
4
+ * @param paymentIntentSecret - stripe payment intent secret (see: https://stripe.com/docs/api/payment_intents/object#payment_intent_object-client_secret)
5
+ * @param paymentMethodId - stripe customer payment method id (see: https://stripe.com/docs/api/cards/object#card_object-id)
6
+ * @returns
7
+ */
8
+ export declare const confirmPaymentIntentByPaymentMethod: (this: import(".").StripeExtension, paymentIntentSecret: string, paymentMethodId: string, returnUrl?: string | undefined) => Promise<import("@stripe/stripe-js").PaymentIntent | undefined>;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.confirmPaymentIntentByPaymentMethod = void 0;
4
+ const confirmPaymentIntentByCard_1 = require("./confirmPaymentIntentByCard");
5
+ /**
6
+ * Confirm payment intent by customer's payment method
7
+ *
8
+ * @param paymentIntentSecret - stripe payment intent secret (see: https://stripe.com/docs/api/payment_intents/object#payment_intent_object-client_secret)
9
+ * @param paymentMethodId - stripe customer payment method id (see: https://stripe.com/docs/api/cards/object#card_object-id)
10
+ * @returns
11
+ */
12
+ exports.confirmPaymentIntentByPaymentMethod = confirmPaymentIntentByCard_1.confirmPaymentIntentByCard;
13
+ //# sourceMappingURL=confirmPaymentIntentByPaymentMethod.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"confirmPaymentIntentByPaymentMethod.js","sourceRoot":"","sources":["../../src/methods/confirmPaymentIntentByPaymentMethod.ts"],"names":[],"mappings":";;;AAAA,6EAA0E;AAE1E;;;;;;GAMG;AACU,QAAA,mCAAmC,GAAG,uDAA0B,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { PaymentMethod } from "@stripe/stripe-js";
2
+ import { StripeExtension } from "./index";
3
+ /**
4
+ * Delete payment method from customer.
5
+ *
6
+ * @param paymentMethodId - payment method id (see: https://stripe.com/docs/api/customers/object#payment_method_object-id)
7
+ * @param ephemeralKey - customer ephemeral key
8
+ * @returns
9
+ */
10
+ export declare const deletePaymentMethodFromCustomer: (this: StripeExtension, paymentMethodId: string, ephemeralKey: string) => Promise<PaymentMethod | 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.deletePaymentMethodFromCustomer = void 0;
13
+ const handlers_1 = require("../utils/handlers");
14
+ const constants_1 = require("../utils/constants");
15
+ /**
16
+ * Delete payment method from customer.
17
+ *
18
+ * @param paymentMethodId - payment method id (see: https://stripe.com/docs/api/customers/object#payment_method_object-id)
19
+ * @param ephemeralKey - customer ephemeral key
20
+ * @returns
21
+ */
22
+ const deletePaymentMethodFromCustomer = function (paymentMethodId, 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/${paymentMethodId}/detach`, {
31
+ headers: {
32
+ Authorization: `Bearer ${ephemeralKey}`,
33
+ "Content-Type": "application/x-www-form-urlencoded",
34
+ "Stripe-Version": `${constants_1.stripeApiVersion}`,
35
+ },
36
+ method: "POST",
37
+ }).then(handlers_1.responseHandler);
38
+ });
39
+ };
40
+ exports.deletePaymentMethodFromCustomer = deletePaymentMethodFromCustomer;
41
+ //# sourceMappingURL=deletePaymentMethodFromCustomer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deletePaymentMethodFromCustomer.js","sourceRoot":"","sources":["../../src/methods/deletePaymentMethodFromCustomer.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,gDAAoD;AACpD,kDAAoE;AAGpE;;;;;;GAMG;AACI,MAAM,+BAA+B,GAAG,UAE7C,eAAuB,EACvB,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,oBAAoB,eAAe,SAAS,EAAE;YACxE,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,YAAY,EAAE;gBACvC,cAAc,EAAE,mCAAmC;gBACnD,gBAAgB,EAAE,GAAG,4BAAgB,EAAE;aACxC;YACD,MAAM,EAAE,MAAM;SACf,CAAC,CAAC,IAAI,CAAC,0BAAe,CAAC,CAAC;IAC3B,CAAC;CAAA,CAAC;AApBW,QAAA,+BAA+B,mCAoB1C"}
@@ -0,0 +1,11 @@
1
+ import { Card } from "@stripe/stripe-js";
2
+ import { StripeExtension } from "./index";
3
+ /**
4
+ * Delete card from customer.
5
+ *
6
+ * @param sourceId - source or card id (see: https://stripe.com/docs/api/sources/object#source_object-id)
7
+ * @param customerId - customer id (see: https://stripe.com/docs/api/customers/object#customer_object-id)
8
+ * @param ephemeralKey - customer ephemeral key
9
+ * @returns
10
+ */
11
+ export declare const deleteSourceFromCustomer: (this: StripeExtension, sourceId: string, customerId: string, ephemeralKey: string) => Promise<Card | undefined>;