Created
April 22, 2021 22:07
-
-
Save dayhaysoos/82e27a1b6e22129a3276d9bd727061fa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.post("/charge", async function (req, res) { | |
const { | |
email, | |
stripeToken, | |
address, | |
name, | |
city, | |
state, | |
zip, | |
country, | |
} = req.body; | |
const { itemId } = req.query; | |
try { | |
const result = await stripe.charges.create({ | |
amount: ITEM_DATA[itemId].amount, | |
currency: "usd", | |
description: ITEM_DATA[itemId].title, | |
source: stripeToken, | |
receipt_email: email, | |
shipping: { | |
name, | |
address: { | |
line1: address, | |
city, | |
country, | |
state, | |
postal_code: zip, | |
}, | |
}, | |
}); | |
var formatter = new Intl.NumberFormat("en-US", { | |
style: "currency", | |
currency: "USD", | |
}); | |
res.render("success", { | |
amount: formatter.format(result.amount / 100), | |
receipt_email: result.receipt_email, | |
description: result.description, | |
receipt_url: result.receipt_url, | |
chargeId: result.id, | |
}); | |
} catch (error) { | |
console.log(error); | |
res.send(error); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment