next-stripe-helper
Advanced tools
Comparing version 1.1.24 to 1.1.25
@@ -11,2 +11,10 @@ import Stripe from "stripe"; | ||
/** | ||
* Gets a Stripe customer based on the email given. | ||
* | ||
* @param {string} email - The email address of the customer. | ||
* @returns {Customer} - The customer data found mathing the email given | ||
* @throws {Error} - Throws an error if the Stripe API call fails. | ||
*/ | ||
declare function getCustomerByEmail(email: string, limit?: number): Promise<object>; | ||
/** | ||
* Retrieve customer details from Stripe. | ||
@@ -36,2 +44,2 @@ * | ||
declare function getCustomerPaymentMethods(customerId: string): Promise<Stripe.PaymentMethod[]>; | ||
export { createCustomer, getCustomer, updateCustomer, getCustomerPaymentMethods }; | ||
export { createCustomer, getCustomer, getCustomerByEmail, updateCustomer, getCustomerPaymentMethods }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getCustomerPaymentMethods = exports.updateCustomer = exports.getCustomer = exports.createCustomer = void 0; | ||
exports.getCustomerPaymentMethods = exports.updateCustomer = exports.getCustomerByEmail = exports.getCustomer = exports.createCustomer = void 0; | ||
const stripe_1 = require("../utils/stripe"); | ||
@@ -22,2 +22,24 @@ /** | ||
/** | ||
* Gets a Stripe customer based on the email given. | ||
* | ||
* @param {string} email - The email address of the customer. | ||
* @returns {Customer} - The customer data found mathing the email given | ||
* @throws {Error} - Throws an error if the Stripe API call fails. | ||
*/ | ||
async function getCustomerByEmail(email, limit = 1) { | ||
try { | ||
const customers = await stripe_1.stripe.customers.list({ email, limit }); | ||
//if the limit was one, go ahead and return the one customer | ||
if (limit === 1) { | ||
return customers.data[0]; | ||
} | ||
//limit was higher than one, return an array of data | ||
return customers.data; | ||
} | ||
catch (error) { | ||
(0, stripe_1.handleStripeError)(error); | ||
} | ||
} | ||
exports.getCustomerByEmail = getCustomerByEmail; | ||
/** | ||
* Retrieve customer details from Stripe. | ||
@@ -24,0 +46,0 @@ * |
{ | ||
"name": "next-stripe-helper", | ||
"version": "1.1.24", | ||
"version": "1.1.25", | ||
"description": "Easily add Stripe boilerplate code to Nextjs, like webhook handling, and subscription updates. This package provides a thin wrapper around the Stripe API, and makes integrating Stripe and NextJS a lot faster!", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -114,2 +114,15 @@ # next-stripe-helper | ||
### Get a Stripe Customer based on a specific email | ||
Get a customer in Stripe using their email address. | ||
```javascript | ||
const customerData = await getCustomerByEmail(email: string, limit: number = 1) | ||
``` | ||
Parameters: | ||
- `email` (required): The email address of the new customer. | ||
- `limit` (optional): Limit the number of returned customer data. If limit is higher than 1, then an array will be returned. | ||
### Retrieve Customer Details | ||
@@ -116,0 +129,0 @@ |
@@ -20,2 +20,23 @@ import Stripe from "stripe"; | ||
/** | ||
* Gets a Stripe customer based on the email given. | ||
* | ||
* @param {string} email - The email address of the customer. | ||
* @returns {Customer} - The customer data found mathing the email given | ||
* @throws {Error} - Throws an error if the Stripe API call fails. | ||
*/ | ||
async function getCustomerByEmail(email: string, limit: number = 1): Promise<object> { | ||
try { | ||
const customers = await stripe.customers.list({email,limit}); | ||
//if the limit was one, go ahead and return the one customer | ||
if(limit === 1){ | ||
return customers.data[0]; | ||
} | ||
//limit was higher than one, return an array of data | ||
return customers.data; | ||
} catch (error) { | ||
handleStripeError(error as Stripe.errors.StripeError); | ||
} | ||
} | ||
/** | ||
* Retrieve customer details from Stripe. | ||
@@ -74,4 +95,5 @@ * | ||
getCustomer, | ||
getCustomerByEmail, | ||
updateCustomer, | ||
getCustomerPaymentMethods | ||
}; |
Sorry, the diff of this file is not supported yet
112857
1690
754