Skip to content

Commit

Permalink
ref: remove download receipt URL
Browse files Browse the repository at this point in the history
  • Loading branch information
wanlingt committed Jul 20, 2023
1 parent 6e3f690 commit 350e5f9
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ import { BiDownload } from 'react-icons/bi'
import { useToast } from '~hooks/useToast'
import Button from '~components/Button'

import {
getPaymentInvoiceDownloadUrl,
getPaymentReceiptDownloadUrl,
} from '~features/public-form/utils/urls'
import { getPaymentInvoiceDownloadUrl } from '~features/public-form/utils/urls'

import { GenericMessageBlock } from './GenericMessageBlock'

Expand All @@ -23,13 +20,6 @@ export const DownloadReceiptBlock = ({
}: DownloadReceiptBlockProps) => {
const toast = useToast({ status: 'success', isClosable: true })

const handleReceiptClick = () => {
toast({
description: 'Receipt download started',
})
window.location.href = getPaymentReceiptDownloadUrl(formId, paymentId)
}

const handleInvoiceClick = () => {
toast({
description: 'Invoice download started',
Expand All @@ -43,15 +33,6 @@ export const DownloadReceiptBlock = ({
submissionId={submissionId}
>
<>
<Button
hidden // Currently hidden for JTC
mt="2.25rem"
mr="2.25rem"
leftIcon={<BiDownload fontSize="1.5rem" />}
onClick={handleReceiptClick}
>
Save payment receipt
</Button>
<Button
mt="2.25rem"
leftIcon={<BiDownload fontSize="1.5rem" />}
Expand Down
7 changes: 0 additions & 7 deletions frontend/src/features/public-form/utils/urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ export const getPaymentPageUrl = (formId: string, paymentId: string) => {
return `/${formId}/payment/${paymentId}` as const
}

export const getPaymentReceiptDownloadUrl = (
formId: string,
paymentId: string,
) => {
return `${API_BASE_URL}/payments/${formId}/${paymentId}/receipt/download` as const
}

export const getPaymentInvoiceDownloadUrl = (
formId: string,
paymentId: string,
Expand Down
72 changes: 0 additions & 72 deletions src/app/modules/payments/stripe.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Use 'stripe-event-types' for better type discrimination.
/// <reference types="stripe-event-types" />
import axios from 'axios'
import { celebrate, Joi, Segments } from 'celebrate'
import { StatusCodes } from 'http-status-codes'
import get from 'lodash/get'
Expand All @@ -18,7 +17,6 @@ import config from '../../config/config'
import { paymentConfig } from '../../config/features/payment.config'
import { createLoggerWithLabel } from '../../config/logger'
import { stripe } from '../../loaders/stripe'
import { generatePdfFromHtml } from '../../utils/convert-html-to-pdf'
import { createReqMeta } from '../../utils/request'
import { ControllerHandler } from '../core/core.types'
import * as FormService from '../form/form.service'
Expand Down Expand Up @@ -221,76 +219,6 @@ export const downloadPaymentInvoice: ControllerHandler<{
})
}

/**
* Handler for GET /api/v3/payments/:formId/:paymentId/invoice/download
* Receives Stripe webhooks and updates the database with transaction details.
*
* @returns 200 if webhook is successfully processed
* @returns 404 if the PaymentId is not found
* @returns 404 if the FormId is not found
* @returns 404 if payment.completedPayment?.receiptUrl is not found
*/
export const downloadPaymentReceipt: ControllerHandler<{
formId: string
paymentId: string
}> = (req, res) => {
const { formId, paymentId } = req.params
logger.info({
message: 'downloadPaymentReceipt endpoint called',
meta: {
action: 'downloadPaymentReceipt',
formId,
paymentId,
},
})

return PaymentService.findPaymentById(paymentId)
.map((payment) => {
logger.info({
message: 'Found paymentId in payment document',
meta: {
action: 'downloadPaymentReceipt',
payment,
},
})
if (!payment.completedPayment?.receiptUrl) {
return res
.status(StatusCodes.NOT_FOUND)
.send({ message: 'Receipt url not ready' })
}
// retrieve receiptURL as html
return (
axios
.get<string>(payment.completedPayment.receiptUrl)
// convert to pdf and return
.then((receiptUrlResponse) => {
const html = receiptUrlResponse.data
const pdfBufferPromise = generatePdfFromHtml(html)
return pdfBufferPromise
})
.then((pdfBuffer) => {
res.set({
'Content-Type': 'application/pdf',
'Content-Disposition': `attachment; filename=${paymentId}-receipt.pdf`,
})
return res.status(StatusCodes.OK).send(pdfBuffer)
})
)
})
.mapErr((error) => {
logger.error({
message: 'Error retrieving receipt',
meta: {
action: 'downloadPaymentReceipt',
formId,
paymentId,
},
error,
})
return res.status(StatusCodes.NOT_FOUND).json({ message: error })
})
}

const _handleConnectOauthCallback: ControllerHandler<
unknown,
unknown,
Expand Down
15 changes: 1 addition & 14 deletions src/app/routes/api/v3/payments/payments.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,11 @@ PaymentsRouter.get(
StripeController.checkPaymentReceiptStatus,
)

/**
* Downloads the receipt pdf
* @route GET /payments/:formId/:paymentId/receipt/download
*
* @returns 200 with receipt attatchment as content in PDF
* @returns 404 if receipt url doesn't exist or payment does not exist
*/
PaymentsRouter.get(
'/:formId([a-fA-F0-9]{24})/:paymentId([a-fA-F0-9]{24})/receipt/download',
limitRate({ max: rateLimitConfig.downloadPaymentReceipt }),
StripeController.downloadPaymentReceipt,
)

/**
* Downloads the invoice pdf
* @route GET /payments/:formId/:paymentId/invoice/download
*
* @returns 200 with receipt attatchment as content in PDF
* @returns 200 with receipt attachment as content in PDF
* @returns 404 if receipt url doesn't exist or payment does not exist
*/
PaymentsRouter.get(
Expand Down

0 comments on commit 350e5f9

Please sign in to comment.