Skip to content

Commit 4641c73

Browse files
add support for receipt email
1 parent d7e10b4 commit 4641c73

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/routes/customerPayment/create.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const permissions = tcMiddleware.permissions;
1212

1313
const schema = {
1414
body: Joi.object().keys({
15+
receiptEmail: Joi.string().email(),
1516
amount: Joi.number().integer().min(1).required(),
1617
currency: Joi.string().valid(_.values(CUSTOMER_PAYMENT_CURRENCY)).default(CUSTOMER_PAYMENT_CURRENCY.USD),
1718
paymentMethodId: Joi.string().required(),
@@ -24,8 +25,8 @@ module.exports = [
2425
validate(schema),
2526
permissions('customerPayment.create'),
2627
(req, res, next) => {
27-
const { amount, currency, reference, referenceId, paymentMethodId } = req.body;
28-
createCustomerPayment(amount, currency, paymentMethodId, reference, referenceId, req.authUser.userId, req)
28+
const { amount, currency, reference, referenceId, paymentMethodId, receiptEmail } = req.body;
29+
createCustomerPayment(amount, currency, paymentMethodId, reference, referenceId, receiptEmail, req.authUser.userId, req)
2930
.then((result) => {
3031
// Write to the response
3132
res.status(201).json(result);

src/services/customerPaymentService.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,20 @@ async function sendCustomerPaymentMessage(event, customerPayment, req) {
7979
* @param {string} paymentMethodId the payment method id
8080
* @param {string} reference the payment method id
8181
* @param {string} referenceId the payment method id
82+
* @param {string} receiptEmail the receipt email
8283
* @param {string} userId the payment method id
8384
* @param {object} req the request
8485
* @returns {Promise} the customer payment
8586
*/
86-
export async function createCustomerPayment(amount, currency, paymentMethodId, reference, referenceId, userId, req) {
87+
export async function createCustomerPayment(amount, currency, paymentMethodId, reference, referenceId, receiptEmail, userId, req) {
8788
const intent = await convertStripError(() => stripe.paymentIntents.create({
8889
amount,
8990
currency: _.lowerCase(currency),
9091
payment_method: paymentMethodId,
9192
capture_method: STRIPE_CONSTANT.CAPTURE_METHOD,
9293
confirmation_method: STRIPE_CONSTANT.CONFIRMATION_METHOD,
9394
confirm: true,
95+
...(receiptEmail ? { receipt_email: receiptEmail } : {})
9496
}));
9597
const customerPayment = await models.CustomerPayment.create({
9698
reference,

0 commit comments

Comments
 (0)