@sergdudko/stripe-js 1.3.20 → 2.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.
- package/LICENSE +21 -0
- package/README.md +43 -2
- package/dist/cjs/esm.js +6 -0
- package/{lib → dist/cjs}/index.js +1 -1
- package/{lib → dist/cjs}/methods/index.js +2 -0
- package/dist/cjs/types.js +3 -0
- package/{lib → dist/cjs}/utils/constants.js +1 -1
- package/dist/esm/esm.js +2 -0
- package/dist/esm/index.js +22 -0
- package/dist/esm/methods/addPaymentMethodToCustomer.js +26 -0
- package/dist/esm/methods/addSourceToCustomer.js +26 -0
- package/dist/esm/methods/confirmPaymentIntentByCard.js +26 -0
- package/dist/esm/methods/confirmPaymentIntentByPaymentMethod.js +10 -0
- package/dist/esm/methods/deletePaymentMethodFromCustomer.js +24 -0
- package/dist/esm/methods/deleteSourceFromCustomer.js +24 -0
- package/dist/esm/methods/getAllCards.js +23 -0
- package/dist/esm/methods/getAllPaymentMethods.js +23 -0
- package/dist/esm/methods/getCustomer.js +22 -0
- package/dist/esm/methods/getDefaultCard.js +24 -0
- package/dist/esm/methods/index.js +33 -0
- package/dist/esm/methods/setDefaultCard.js +26 -0
- package/dist/esm/methods/setDefaultPaymentMethod.js +26 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/utils/constants.js +3 -0
- package/dist/esm/utils/handlers.js +13 -0
- package/dist/types/esm.d.ts +2 -0
- package/dist/types/index.d.ts +11 -0
- package/{lib → dist/types}/methods/index.d.ts +1 -0
- package/dist/types/types.d.ts +72 -0
- package/{lib → dist/types}/utils/constants.d.ts +1 -1
- package/package.json +58 -21
- package/CHANGELOG.md +0 -1208
- package/FUNDING.yml +0 -2
- package/ignoreUpdatesModules.json +0 -4
- package/lib/index.d.ts +0 -24
- package/lib/index.js.map +0 -1
- package/lib/methods/addPaymentMethodToCustomer.js.map +0 -1
- package/lib/methods/addSourceToCustomer.js.map +0 -1
- package/lib/methods/confirmPaymentIntentByCard.js.map +0 -1
- package/lib/methods/confirmPaymentIntentByPaymentMethod.js.map +0 -1
- package/lib/methods/deletePaymentMethodFromCustomer.js.map +0 -1
- package/lib/methods/deleteSourceFromCustomer.js.map +0 -1
- package/lib/methods/getAllCards.js.map +0 -1
- package/lib/methods/getAllPaymentMethods.js.map +0 -1
- package/lib/methods/getCustomer.js.map +0 -1
- package/lib/methods/getDefaultCard.js.map +0 -1
- package/lib/methods/index.js.map +0 -1
- package/lib/methods/setDefaultCard.js.map +0 -1
- package/lib/methods/setDefaultPaymentMethod.js.map +0 -1
- package/lib/utils/constants.js.map +0 -1
- package/lib/utils/handlers.js.map +0 -1
- /package/{lib → dist/cjs}/methods/addPaymentMethodToCustomer.js +0 -0
- /package/{lib → dist/cjs}/methods/addSourceToCustomer.js +0 -0
- /package/{lib → dist/cjs}/methods/confirmPaymentIntentByCard.js +0 -0
- /package/{lib → dist/cjs}/methods/confirmPaymentIntentByPaymentMethod.js +0 -0
- /package/{lib → dist/cjs}/methods/deletePaymentMethodFromCustomer.js +0 -0
- /package/{lib → dist/cjs}/methods/deleteSourceFromCustomer.js +0 -0
- /package/{lib → dist/cjs}/methods/getAllCards.js +0 -0
- /package/{lib → dist/cjs}/methods/getAllPaymentMethods.js +0 -0
- /package/{lib → dist/cjs}/methods/getCustomer.js +0 -0
- /package/{lib → dist/cjs}/methods/getDefaultCard.js +0 -0
- /package/{lib → dist/cjs}/methods/setDefaultCard.js +0 -0
- /package/{lib → dist/cjs}/methods/setDefaultPaymentMethod.js +0 -0
- /package/{lib → dist/cjs}/utils/handlers.js +0 -0
- /package/{lib → dist/types}/methods/addPaymentMethodToCustomer.d.ts +0 -0
- /package/{lib → dist/types}/methods/addSourceToCustomer.d.ts +0 -0
- /package/{lib → dist/types}/methods/confirmPaymentIntentByCard.d.ts +0 -0
- /package/{lib → dist/types}/methods/confirmPaymentIntentByPaymentMethod.d.ts +0 -0
- /package/{lib → dist/types}/methods/deletePaymentMethodFromCustomer.d.ts +0 -0
- /package/{lib → dist/types}/methods/deleteSourceFromCustomer.d.ts +0 -0
- /package/{lib → dist/types}/methods/getAllCards.d.ts +0 -0
- /package/{lib → dist/types}/methods/getAllPaymentMethods.d.ts +0 -0
- /package/{lib → dist/types}/methods/getCustomer.d.ts +0 -0
- /package/{lib → dist/types}/methods/getDefaultCard.d.ts +0 -0
- /package/{lib → dist/types}/methods/setDefaultCard.d.ts +0 -0
- /package/{lib → dist/types}/methods/setDefaultPaymentMethod.d.ts +0 -0
- /package/{lib → dist/types}/utils/handlers.d.ts +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 Siarhei Dudko
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -8,16 +8,32 @@ Supercharge Your Stripe Integration with Enhanced Methods for stripe-js: Take Fu
|
|
|
8
8
|

|
|
9
9
|

|
|
10
10
|
|
|
11
|
+
## 🚀 What's New in v2.0.0
|
|
12
|
+
|
|
13
|
+
- ✅ **Dual Package**: Full support for both CommonJS and ES Modules
|
|
14
|
+
- ✅ **TypeScript**: Complete type definitions and TypeScript source
|
|
15
|
+
- ✅ **Optimized Types**: Shared type definitions for smaller bundle size
|
|
16
|
+
- ✅ **TypeScript Tests**: All tests converted to TypeScript with `node --test --import tsx`
|
|
17
|
+
- ✅ **Better Tree-shaking**: Optimized module structure for better bundling
|
|
18
|
+
|
|
11
19
|
## Usage
|
|
12
20
|
|
|
13
|
-
###
|
|
21
|
+
### ES Modules (Recommended)
|
|
14
22
|
|
|
15
|
-
```
|
|
23
|
+
```typescript
|
|
16
24
|
import { loadStripe } from "@sergdudko/stripe-js";
|
|
17
25
|
|
|
18
26
|
const stripe = await loadStripe("pk_test_TYooMQauvdEDq54NiTphI7jx");
|
|
19
27
|
```
|
|
20
28
|
|
|
29
|
+
### CommonJS
|
|
30
|
+
|
|
31
|
+
```javascript
|
|
32
|
+
const { loadStripe } = require("@sergdudko/stripe-js");
|
|
33
|
+
|
|
34
|
+
const stripe = await loadStripe("pk_test_TYooMQauvdEDq54NiTphI7jx");
|
|
35
|
+
```
|
|
36
|
+
|
|
21
37
|
## Stripe.js Documentation
|
|
22
38
|
|
|
23
39
|
- [Stripe.js Docs](https://stripe.com/docs/stripe-js)
|
|
@@ -118,3 +134,28 @@ stripe.setDefaultPaymentMethod(
|
|
|
118
134
|
- To run build `npm run build`.
|
|
119
135
|
- To run testing `npm run test`.
|
|
120
136
|
- To create docs `npm run doc`.
|
|
137
|
+
|
|
138
|
+
## 📄 License
|
|
139
|
+
|
|
140
|
+
MIT License - see [LICENSE](./LICENSE) file for details.
|
|
141
|
+
|
|
142
|
+
## 🆘 Support
|
|
143
|
+
|
|
144
|
+
- 📝 **Issues**: [GitHub Issues](https://github.com/siarheidudko/stripe-js/issues)
|
|
145
|
+
- 💬 **Discussions**: [GitHub Discussions](https://github.com/siarheidudko/stripe-js/discussions)
|
|
146
|
+
- 📧 **Email**: [siarhei@dudko.dev](mailto:siarhei@dudko.dev)
|
|
147
|
+
|
|
148
|
+
## 💝 Support This Project
|
|
149
|
+
|
|
150
|
+
If my Stripe JS Extension helps you build amazing applications, consider supporting its development:
|
|
151
|
+
|
|
152
|
+
- ☕ **[Buy me a coffee](https://www.buymeacoffee.com/dudko.dev)**
|
|
153
|
+
- 💳 **[PayPal](https://paypal.me/dudkodev)**
|
|
154
|
+
- 🎯 **[Patreon](https://patreon.com/dudko_dev)**
|
|
155
|
+
- 🌐 **[More options](http://dudko.dev/donate)**
|
|
156
|
+
|
|
157
|
+
Your support helps maintain and improve Redux Cluster for the entire community!
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
**Made with ❤️ by [Siarhei Dudko](https://github.com/siarheidudko)**
|
package/dist/cjs/esm.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadStripe = void 0;
|
|
4
|
+
var index_1 = require("./index");
|
|
5
|
+
Object.defineProperty(exports, "loadStripe", { enumerable: true, get: function () { return index_1.loadStripe; } });
|
|
6
|
+
//# sourceMappingURL=esm.js.map
|
|
@@ -11,7 +11,7 @@ const index_1 = require("./methods/index");
|
|
|
11
11
|
* @returns
|
|
12
12
|
*/
|
|
13
13
|
const loadStripe = async (publishableKey, options) => {
|
|
14
|
-
const stripeDefault = await (0, stripe_js_1.loadStripe)(publishableKey
|
|
14
|
+
const stripeDefault = await (0, stripe_js_1.loadStripe)(`${publishableKey}`, options);
|
|
15
15
|
if (stripeDefault === null ||
|
|
16
16
|
// eslint-disable-next-line no-underscore-dangle
|
|
17
17
|
typeof stripeDefault?._apiKey !== "string")
|
|
@@ -8,6 +8,7 @@ const deleteSourceFromCustomer_1 = require("./deleteSourceFromCustomer");
|
|
|
8
8
|
const getAllCards_1 = require("./getAllCards");
|
|
9
9
|
const getCustomer_1 = require("./getCustomer");
|
|
10
10
|
const setDefaultCard_1 = require("./setDefaultCard");
|
|
11
|
+
const getDefaultCard_1 = require("./getDefaultCard");
|
|
11
12
|
const addPaymentMethodToCustomer_1 = require("./addPaymentMethodToCustomer");
|
|
12
13
|
const deletePaymentMethodFromCustomer_1 = require("./deletePaymentMethodFromCustomer");
|
|
13
14
|
const getAllPaymentMethods_1 = require("./getAllPaymentMethods");
|
|
@@ -24,6 +25,7 @@ class StripeExtension {
|
|
|
24
25
|
this.getAllCards = getAllCards_1.getAllCards;
|
|
25
26
|
this.getCustomer = getCustomer_1.getCustomer;
|
|
26
27
|
this.setDefaultCard = setDefaultCard_1.setDefaultCard;
|
|
28
|
+
this.getDefaultCard = getDefaultCard_1.getDefaultCard;
|
|
27
29
|
this.addPaymentMethodToCustomer = addPaymentMethodToCustomer_1.addPaymentMethodToCustomer;
|
|
28
30
|
this.deletePaymentMethodFromCustomer = deletePaymentMethodFromCustomer_1.deletePaymentMethodFromCustomer;
|
|
29
31
|
this.getAllPaymentMethods = getAllPaymentMethods_1.getAllPaymentMethods;
|
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.stripeApiVersion = exports.stripeApiUrl = void 0;
|
|
4
4
|
exports.stripeApiUrl = "https://api.stripe.com/v1";
|
|
5
|
-
exports.stripeApiVersion = "2025-
|
|
5
|
+
exports.stripeApiVersion = "2025-08-27.basil";
|
|
6
6
|
//# sourceMappingURL=constants.js.map
|
package/dist/esm/esm.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { loadStripe as loadStripeDefault, } from "@stripe/stripe-js";
|
|
2
|
+
import { StripeExtension } from "./methods/index";
|
|
3
|
+
/**
|
|
4
|
+
* Initialize stripe
|
|
5
|
+
*
|
|
6
|
+
* @param publishableKey - stripe public key, like pk_...
|
|
7
|
+
* @param options - stripe initialization options
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export const loadStripe = async (publishableKey, options) => {
|
|
11
|
+
const stripeDefault = await loadStripeDefault(`${publishableKey}`, options);
|
|
12
|
+
if (stripeDefault === null ||
|
|
13
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
14
|
+
typeof stripeDefault?._apiKey !== "string")
|
|
15
|
+
throw new Error("Initialization error.");
|
|
16
|
+
const stripeExtension = new StripeExtension(
|
|
17
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
18
|
+
stripeDefault._apiKey);
|
|
19
|
+
const stripe = Object.assign(stripeDefault, stripeExtension);
|
|
20
|
+
return stripe;
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { responseHandler } from "../utils/handlers";
|
|
2
|
+
import { stripeApiUrl, stripeApiVersion } from "../utils/constants";
|
|
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 const addPaymentMethodToCustomer = async function (paymentMethodId, customerId, ephemeralKey) {
|
|
12
|
+
const stripeApiKey = this._apiKey;
|
|
13
|
+
if (typeof stripeApiKey !== "string")
|
|
14
|
+
throw new Error("Initialization failed.");
|
|
15
|
+
// make request
|
|
16
|
+
return fetch(`${stripeApiUrl}/payment_methods/${paymentMethodId}/attach`, {
|
|
17
|
+
body: `customer=${customerId}`,
|
|
18
|
+
headers: {
|
|
19
|
+
Authorization: `Bearer ${ephemeralKey}`,
|
|
20
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
21
|
+
"Stripe-Version": `${stripeApiVersion}`,
|
|
22
|
+
},
|
|
23
|
+
method: "POST",
|
|
24
|
+
}).then(responseHandler);
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=addPaymentMethodToCustomer.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { responseHandler } from "../utils/handlers";
|
|
2
|
+
import { stripeApiUrl, stripeApiVersion } from "../utils/constants";
|
|
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 const addSourceToCustomer = async function (token, customerId, ephemeralKey) {
|
|
12
|
+
const stripeApiKey = this._apiKey;
|
|
13
|
+
if (typeof stripeApiKey !== "string")
|
|
14
|
+
throw new Error("Initialization failed.");
|
|
15
|
+
// make request
|
|
16
|
+
return fetch(`${stripeApiUrl}/customers/${customerId}/sources`, {
|
|
17
|
+
body: `source=${token}`,
|
|
18
|
+
headers: {
|
|
19
|
+
Authorization: `Bearer ${ephemeralKey}`,
|
|
20
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
21
|
+
"Stripe-Version": `${stripeApiVersion}`,
|
|
22
|
+
},
|
|
23
|
+
method: "POST",
|
|
24
|
+
}).then(responseHandler);
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=addSourceToCustomer.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { responseHandler } from "../utils/handlers";
|
|
2
|
+
import { stripeApiUrl, stripeApiVersion } from "../utils/constants";
|
|
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 const confirmPaymentIntentByCard = async function (paymentIntentSecret, paymentMethodId, returnUrl) {
|
|
11
|
+
const stripeApiKey = this._apiKey;
|
|
12
|
+
if (typeof stripeApiKey !== "string")
|
|
13
|
+
throw new Error("Initialization failed.");
|
|
14
|
+
// make request
|
|
15
|
+
const paymentIntentId = paymentIntentSecret.replace(/_secret_.+$/i, "");
|
|
16
|
+
return fetch(`${stripeApiUrl}/payment_intents/${paymentIntentId}/confirm?client_secret=${paymentIntentSecret}`, {
|
|
17
|
+
body: `payment_method=${paymentMethodId}${typeof returnUrl === 'string' ? `&return_url=${returnUrl}` : ''}`,
|
|
18
|
+
headers: {
|
|
19
|
+
Authorization: `Bearer ${stripeApiKey}`,
|
|
20
|
+
"Content-Type": `application/x-www-form-urlencoded`,
|
|
21
|
+
"Stripe-Version": `${stripeApiVersion}`,
|
|
22
|
+
},
|
|
23
|
+
method: `POST`,
|
|
24
|
+
}).then(responseHandler);
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=confirmPaymentIntentByCard.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { confirmPaymentIntentByCard } from "./confirmPaymentIntentByCard";
|
|
2
|
+
/**
|
|
3
|
+
* Confirm payment intent by customer's payment method
|
|
4
|
+
*
|
|
5
|
+
* @param paymentIntentSecret - stripe payment intent secret (see: https://stripe.com/docs/api/payment_intents/object#payment_intent_object-client_secret)
|
|
6
|
+
* @param paymentMethodId - stripe customer payment method id (see: https://stripe.com/docs/api/cards/object#card_object-id)
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export const confirmPaymentIntentByPaymentMethod = confirmPaymentIntentByCard;
|
|
10
|
+
//# sourceMappingURL=confirmPaymentIntentByPaymentMethod.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { responseHandler } from "../utils/handlers";
|
|
2
|
+
import { stripeApiUrl, stripeApiVersion } from "../utils/constants";
|
|
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 const deletePaymentMethodFromCustomer = async function (paymentMethodId, ephemeralKey) {
|
|
11
|
+
const stripeApiKey = this._apiKey;
|
|
12
|
+
if (typeof stripeApiKey !== "string")
|
|
13
|
+
throw new Error("Initialization failed.");
|
|
14
|
+
// make request
|
|
15
|
+
return fetch(`${stripeApiUrl}/payment_methods/${paymentMethodId}/detach`, {
|
|
16
|
+
headers: {
|
|
17
|
+
Authorization: `Bearer ${ephemeralKey}`,
|
|
18
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
19
|
+
"Stripe-Version": `${stripeApiVersion}`,
|
|
20
|
+
},
|
|
21
|
+
method: "POST",
|
|
22
|
+
}).then(responseHandler);
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=deletePaymentMethodFromCustomer.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { responseHandler } from "../utils/handlers";
|
|
2
|
+
import { stripeApiUrl, stripeApiVersion } from "../utils/constants";
|
|
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 const deleteSourceFromCustomer = async function (sourceId, customerId, ephemeralKey) {
|
|
12
|
+
const stripeApiKey = this._apiKey;
|
|
13
|
+
if (typeof stripeApiKey !== "string")
|
|
14
|
+
throw new Error("Initialization failed.");
|
|
15
|
+
// make request
|
|
16
|
+
return await fetch(`${stripeApiUrl}/customers/${customerId}/sources/${sourceId}`, {
|
|
17
|
+
headers: {
|
|
18
|
+
Authorization: `Bearer ${ephemeralKey}`,
|
|
19
|
+
"Stripe-Version": stripeApiVersion,
|
|
20
|
+
},
|
|
21
|
+
method: "DELETE",
|
|
22
|
+
}).then(responseHandler);
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=deleteSourceFromCustomer.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { responseHandler } from "../utils/handlers";
|
|
2
|
+
import { stripeApiUrl, stripeApiVersion } from "../utils/constants";
|
|
3
|
+
/**
|
|
4
|
+
* Get all customer's card
|
|
5
|
+
*
|
|
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 const getAllCards = async function (customerId, ephemeralKey) {
|
|
11
|
+
const stripeApiKey = this._apiKey;
|
|
12
|
+
if (typeof stripeApiKey !== "string")
|
|
13
|
+
throw new Error("Initialization failed.");
|
|
14
|
+
// make request
|
|
15
|
+
return fetch(`${stripeApiUrl}/payment_methods?customer=${customerId}&type=card&limit=100`, {
|
|
16
|
+
headers: {
|
|
17
|
+
Authorization: `Bearer ${ephemeralKey}`,
|
|
18
|
+
"Stripe-Version": stripeApiVersion,
|
|
19
|
+
},
|
|
20
|
+
method: "GET",
|
|
21
|
+
}).then(responseHandler);
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=getAllCards.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { responseHandler } from "../utils/handlers";
|
|
2
|
+
import { stripeApiUrl, stripeApiVersion } from "../utils/constants";
|
|
3
|
+
/**
|
|
4
|
+
* Get all customer's payment methods
|
|
5
|
+
*
|
|
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 const getAllPaymentMethods = async function (customerId, ephemeralKey) {
|
|
11
|
+
const stripeApiKey = this._apiKey;
|
|
12
|
+
if (typeof stripeApiKey !== "string")
|
|
13
|
+
throw new Error("Initialization failed.");
|
|
14
|
+
// make request
|
|
15
|
+
return fetch(`${stripeApiUrl}/payment_methods?customer=${customerId}&type=card&limit=100`, {
|
|
16
|
+
headers: {
|
|
17
|
+
Authorization: `Bearer ${ephemeralKey}`,
|
|
18
|
+
"Stripe-Version": stripeApiVersion,
|
|
19
|
+
},
|
|
20
|
+
method: "GET",
|
|
21
|
+
}).then(responseHandler);
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=getAllPaymentMethods.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { responseHandler } from "../utils/handlers";
|
|
2
|
+
import { stripeApiUrl, stripeApiVersion } from "../utils/constants";
|
|
3
|
+
/**
|
|
4
|
+
* Get customer data
|
|
5
|
+
*
|
|
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 const getCustomer = async function (customerId, ephemeralKey) {
|
|
11
|
+
const stripeApiKey = this._apiKey;
|
|
12
|
+
if (typeof stripeApiKey !== "string")
|
|
13
|
+
throw new Error("Initialization failed.");
|
|
14
|
+
// make request
|
|
15
|
+
return fetch(`${stripeApiUrl}/customers/${customerId}`, {
|
|
16
|
+
headers: {
|
|
17
|
+
Authorization: `Bearer ${ephemeralKey}`,
|
|
18
|
+
"Stripe-Version": stripeApiVersion,
|
|
19
|
+
},
|
|
20
|
+
}).then(responseHandler);
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=getCustomer.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { responseHandler } from "../utils/handlers";
|
|
2
|
+
import { stripeApiUrl, stripeApiVersion } from "../utils/constants";
|
|
3
|
+
/**
|
|
4
|
+
* Get customer's default card id
|
|
5
|
+
*
|
|
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 const getDefaultCard = async function (customerId, ephemeralKey) {
|
|
11
|
+
const stripeApiKey = this._apiKey;
|
|
12
|
+
if (typeof stripeApiKey !== "string")
|
|
13
|
+
throw new Error("Initialization failed.");
|
|
14
|
+
// make request
|
|
15
|
+
return fetch(`${stripeApiUrl}/customers/${customerId}`, {
|
|
16
|
+
headers: {
|
|
17
|
+
Authorization: `Bearer ${ephemeralKey}`,
|
|
18
|
+
"Stripe-Version": stripeApiVersion,
|
|
19
|
+
},
|
|
20
|
+
})
|
|
21
|
+
.then(responseHandler)
|
|
22
|
+
.then((e) => (e?.default_source ? e.default_source : undefined));
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=getDefaultCard.js.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { confirmPaymentIntentByCard } from "./confirmPaymentIntentByCard";
|
|
2
|
+
import { confirmPaymentIntentByPaymentMethod } from "./confirmPaymentIntentByPaymentMethod";
|
|
3
|
+
import { addSourceToCustomer } from "./addSourceToCustomer";
|
|
4
|
+
import { deleteSourceFromCustomer } from "./deleteSourceFromCustomer";
|
|
5
|
+
import { getAllCards } from "./getAllCards";
|
|
6
|
+
import { getCustomer } from "./getCustomer";
|
|
7
|
+
import { setDefaultCard } from "./setDefaultCard";
|
|
8
|
+
import { getDefaultCard } from "./getDefaultCard";
|
|
9
|
+
import { addPaymentMethodToCustomer } from "./addPaymentMethodToCustomer";
|
|
10
|
+
import { deletePaymentMethodFromCustomer } from "./deletePaymentMethodFromCustomer";
|
|
11
|
+
import { getAllPaymentMethods } from "./getAllPaymentMethods";
|
|
12
|
+
import { setDefaultPaymentMethod } from "./setDefaultPaymentMethod";
|
|
13
|
+
/**
|
|
14
|
+
* additional stripe methods
|
|
15
|
+
*/
|
|
16
|
+
export class StripeExtension {
|
|
17
|
+
constructor(apiKey) {
|
|
18
|
+
this.confirmPaymentIntentByCard = confirmPaymentIntentByCard;
|
|
19
|
+
this.confirmPaymentIntentByPaymentMethod = confirmPaymentIntentByPaymentMethod;
|
|
20
|
+
this.addSourceToCustomer = addSourceToCustomer;
|
|
21
|
+
this.deleteSourceFromCustomer = deleteSourceFromCustomer;
|
|
22
|
+
this.getAllCards = getAllCards;
|
|
23
|
+
this.getCustomer = getCustomer;
|
|
24
|
+
this.setDefaultCard = setDefaultCard;
|
|
25
|
+
this.getDefaultCard = getDefaultCard;
|
|
26
|
+
this.addPaymentMethodToCustomer = addPaymentMethodToCustomer;
|
|
27
|
+
this.deletePaymentMethodFromCustomer = deletePaymentMethodFromCustomer;
|
|
28
|
+
this.getAllPaymentMethods = getAllPaymentMethods;
|
|
29
|
+
this.setDefaultPaymentMethod = setDefaultPaymentMethod;
|
|
30
|
+
this._apiKey = apiKey;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { responseHandler } from "../utils/handlers";
|
|
2
|
+
import { stripeApiUrl, stripeApiVersion } from "../utils/constants";
|
|
3
|
+
/**
|
|
4
|
+
* Set default customer card
|
|
5
|
+
*
|
|
6
|
+
* @param cardId - card id (see: https://stripe.com/docs/api/customers/object#card_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 const setDefaultCard = async function (cardId, customerId, ephemeralKey) {
|
|
12
|
+
const stripeApiKey = this._apiKey;
|
|
13
|
+
if (typeof stripeApiKey !== "string")
|
|
14
|
+
throw new Error("Initialization failed.");
|
|
15
|
+
// make request
|
|
16
|
+
return fetch(`${stripeApiUrl}/customers/${customerId}`, {
|
|
17
|
+
body: `default_source=${cardId}`,
|
|
18
|
+
headers: {
|
|
19
|
+
Authorization: `Bearer ${ephemeralKey}`,
|
|
20
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
21
|
+
"Stripe-Version": stripeApiVersion,
|
|
22
|
+
},
|
|
23
|
+
method: "POST",
|
|
24
|
+
}).then(responseHandler);
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=setDefaultCard.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { responseHandler } from "../utils/handlers";
|
|
2
|
+
import { stripeApiUrl, stripeApiVersion } from "../utils/constants";
|
|
3
|
+
/**
|
|
4
|
+
* Set default customer payment method
|
|
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 const setDefaultPaymentMethod = async function (paymentMethodId, customerId, ephemeralKey) {
|
|
12
|
+
const stripeApiKey = this._apiKey;
|
|
13
|
+
if (typeof stripeApiKey !== "string")
|
|
14
|
+
throw new Error("Initialization failed.");
|
|
15
|
+
// make request for payment method api
|
|
16
|
+
return fetch(`${stripeApiUrl}/customers/${customerId}`, {
|
|
17
|
+
body: `invoice_settings[default_payment_method]=${paymentMethodId}`,
|
|
18
|
+
headers: {
|
|
19
|
+
Authorization: `Bearer ${ephemeralKey}`,
|
|
20
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
21
|
+
"Stripe-Version": stripeApiVersion,
|
|
22
|
+
},
|
|
23
|
+
method: "POST",
|
|
24
|
+
}).then(responseHandler);
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=setDefaultPaymentMethod.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { StripeConstructorOptions } from "@stripe/stripe-js";
|
|
2
|
+
import { Stripe } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Initialize stripe
|
|
5
|
+
*
|
|
6
|
+
* @param publishableKey - stripe public key, like pk_...
|
|
7
|
+
* @param options - stripe initialization options
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export declare const loadStripe: (publishableKey: string, options?: StripeConstructorOptions) => Promise<Stripe>;
|
|
11
|
+
export type { Stripe, StripeDefaultWithInternal } from "./types";
|
|
@@ -11,6 +11,7 @@ export declare class StripeExtension {
|
|
|
11
11
|
getAllCards: (this: StripeExtension, customerId: string, ephemeralKey: string) => Promise<any>;
|
|
12
12
|
getCustomer: (this: StripeExtension, customerId: string, ephemeralKey: string) => Promise<any>;
|
|
13
13
|
setDefaultCard: (this: StripeExtension, cardId: string, customerId: string, ephemeralKey: string) => Promise<any>;
|
|
14
|
+
getDefaultCard: (this: StripeExtension, customerId: string, ephemeralKey: string) => Promise<string | undefined>;
|
|
14
15
|
addPaymentMethodToCustomer: (this: StripeExtension, paymentMethodId: string, customerId: string, ephemeralKey: string) => Promise<import("@stripe/stripe-js").PaymentMethod | undefined>;
|
|
15
16
|
deletePaymentMethodFromCustomer: (this: StripeExtension, paymentMethodId: string, ephemeralKey: string) => Promise<import("@stripe/stripe-js").PaymentMethod | undefined>;
|
|
16
17
|
getAllPaymentMethods: (this: StripeExtension, customerId: string, ephemeralKey: string) => Promise<any>;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { StripeConstructorOptions, Stripe as StripeDefault } from "@stripe/stripe-js";
|
|
2
|
+
/**
|
|
3
|
+
* Stripe default interface with internal properties
|
|
4
|
+
*/
|
|
5
|
+
export interface StripeDefaultWithInternal extends StripeDefault {
|
|
6
|
+
/**
|
|
7
|
+
* Stripe api key after initialization, like pk_...
|
|
8
|
+
*/
|
|
9
|
+
_apiKey: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Base interface for Stripe extension methods
|
|
13
|
+
*/
|
|
14
|
+
export interface StripeExtensionMethods {
|
|
15
|
+
/**
|
|
16
|
+
* Confirm payment intent by card
|
|
17
|
+
*/
|
|
18
|
+
confirmPaymentIntentByCard(clientSecret: string, cardId: string, returnUrl: string): Promise<any>;
|
|
19
|
+
/**
|
|
20
|
+
* Confirm payment intent by payment method
|
|
21
|
+
*/
|
|
22
|
+
confirmPaymentIntentByPaymentMethod(clientSecret: string, paymentMethodId: string, returnUrl: string): Promise<any>;
|
|
23
|
+
/**
|
|
24
|
+
* Add source to customer
|
|
25
|
+
*/
|
|
26
|
+
addSourceToCustomer(token: string, customerId: string, ephemeralKey: string): Promise<any>;
|
|
27
|
+
/**
|
|
28
|
+
* Delete source from customer
|
|
29
|
+
*/
|
|
30
|
+
deleteSourceFromCustomer(sourceId: string, customerId: string, ephemeralKey: string): Promise<any>;
|
|
31
|
+
/**
|
|
32
|
+
* Get all cards for customer
|
|
33
|
+
*/
|
|
34
|
+
getAllCards(customerId: string, ephemeralKey: string): Promise<any>;
|
|
35
|
+
/**
|
|
36
|
+
* Get customer data
|
|
37
|
+
*/
|
|
38
|
+
getCustomer(customerId: string, ephemeralKey: string): Promise<any>;
|
|
39
|
+
/**
|
|
40
|
+
* Get default card
|
|
41
|
+
*/
|
|
42
|
+
getDefaultCard(customerId: string, ephemeralKey: string): Promise<string | undefined>;
|
|
43
|
+
/**
|
|
44
|
+
* Set default card
|
|
45
|
+
*/
|
|
46
|
+
setDefaultCard(cardId: string, customerId: string, ephemeralKey: string): Promise<any>;
|
|
47
|
+
/**
|
|
48
|
+
* Add payment method to customer
|
|
49
|
+
*/
|
|
50
|
+
addPaymentMethodToCustomer(paymentMethodId: string, customerId: string, ephemeralKey: string): Promise<any>;
|
|
51
|
+
/**
|
|
52
|
+
* Delete payment method from customer
|
|
53
|
+
*/
|
|
54
|
+
deletePaymentMethodFromCustomer(paymentMethodId: string, ephemeralKey: string): Promise<any>;
|
|
55
|
+
/**
|
|
56
|
+
* Get all payment methods for customer
|
|
57
|
+
*/
|
|
58
|
+
getAllPaymentMethods(customerId: string, ephemeralKey: string): Promise<any>;
|
|
59
|
+
/**
|
|
60
|
+
* Set default payment method
|
|
61
|
+
*/
|
|
62
|
+
setDefaultPaymentMethod(paymentMethodId: string, customerId: string, ephemeralKey: string): Promise<any>;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Extended Stripe interface combining default Stripe with extensions
|
|
66
|
+
*/
|
|
67
|
+
export interface Stripe extends StripeExtensionMethods, StripeDefault {
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Load Stripe function type
|
|
71
|
+
*/
|
|
72
|
+
export type LoadStripeFunction = (publishableKey: string, options?: StripeConstructorOptions) => Promise<Stripe>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const stripeApiUrl = "https://api.stripe.com/v1";
|
|
2
|
-
export declare const stripeApiVersion = "2025-
|
|
2
|
+
export declare const stripeApiVersion = "2025-08-27.basil";
|