-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: added endpoint for product details #20
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
require("dotenv").config(); | ||
const stripe = require("stripe")(process.env.STRIPE_KEY); | ||
|
||
const headers = { | ||
"Access-Control-Allow-Origin": "*", | ||
"Access-Control-Allow-Headers": "Content-Type", | ||
"Content-Type": "application/json", | ||
}; | ||
|
||
exports.handler = async ({ httpMethod, queryStringParameters }, context, callback) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @vickywane I see that the implementation is now generic and works for any valid Product ID. Therefore the JS function name should match that behavior and be named There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alright. I have adjusted the |
||
const { productId } = queryStringParameters | ||
|
||
if (!productId) { | ||
callback(null, { | ||
statusCode: 422, | ||
headers, | ||
body: JSON.stringify({ message: "Provide productId param to retrieve product details" }), | ||
}); | ||
} | ||
|
||
if (httpMethod === "OPTIONS") { | ||
// for preflight check | ||
callback(null, { | ||
statusCode: 200, | ||
headers, | ||
body: JSON.stringify({ status: "OK" }), | ||
}); | ||
} else if (httpMethod === "GET") { | ||
|
||
try { | ||
const product = await stripe.products.retrieve(productId); | ||
|
||
callback(null, { | ||
statusCode: 200, | ||
headers, | ||
body: JSON.stringify({ product }), | ||
}); | ||
} catch (error) { | ||
callback(null, { | ||
statusCode: 500, | ||
headers, | ||
body: JSON.stringify({ error }), | ||
}); | ||
} | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vickywane is this doc line still necessary? We do not hardcode product ID in the API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now, yes it is.
The
EMAIL_PRODUCT_PRICE_ID
that is used to retrieve only the pricing entity is different from theEMAIL_PRODUCT_ID
.The
EMAIL_PRODUCT_PRICE_ID
is used in the/subscription
function when creating a subscription. The product ID response retrieved using the/product
function does not include the ID of the pricing entity.See subscription and price docs.
I would further rephrase the description of the
EMAIL_PRODUCT_PRICE_ID
to better reflect it's use