Skip to content

Commit

Permalink
Merge pull request #221 from alphagov/bau-enable-updating-email-brand…
Browse files Browse the repository at this point in the history
…ing-in-toolbox

Issue #28: Add ability to update email custom branding
  • Loading branch information
stephencdaly committed Oct 9, 2019
2 parents 5280ebb + 75259e9 commit b9bbd19
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 3 deletions.
12 changes: 11 additions & 1 deletion src/lib/pay-request/api_utils/connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ const connectorMethods = function connectorMethods(instance) {
}
}

const updateEmailBranding = async function updateEmailBranding(id, notifySettings) {
const url = `/v1/api/accounts/${id}`
await axiosInstance.patch(url, {
op: 'replace',
path: 'notify_settings',
value: notifySettings
})
}

return {
performanceReport,
gatewayAccountPerformanceReport,
Expand All @@ -100,7 +109,8 @@ const connectorMethods = function connectorMethods(instance) {
charge,
refunds,
getChargeByGatewayTransactionId,
updateCorporateSurcharge
updateCorporateSurcharge,
updateEmailBranding
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/web/modules/gateway_accounts/detail.njk
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@
href: "/gateway_accounts/" + gatewayAccountId + "/surcharge"
})
}}
{{ govukButton({
text: "Edit email branding",
href: "/gateway_accounts/" + gatewayAccountId + "/email_branding"
})
}}
{% endif %}
</div>

Expand Down
43 changes: 43 additions & 0 deletions src/web/modules/gateway_accounts/email_branding.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{% from "components/input/macro.njk" import govukInput %}
{% from "components/button/macro.njk" import govukButton %}
{% extends "layout/layout.njk" %}

{% block main %}
<span class="govuk-caption-m">Update gateway account</span>
<h1 class="govuk-heading-m">Email custom branding</h1>

<div>
<a href="/gateway_accounts/{{ account.gateway_account_id }}" class="govuk-back-link">Gateway account ({{ account.gateway_account_id }})</a>
</div>

<form method="POST" action="/gateway_accounts/{{ account.gateway_account_id }}/email_branding">
{{ govukInput({
id: "api_token",
name: "api_token",
label: { text: "Notify API key" },
autocomplete: "off"
})
}}
{{ govukInput({
id: "template_id",
name: "template_id",
label: { text: "Payment receipt template id" },
autocomplete: "off"
})
}}
{{ govukInput({
id: "refund_issued_template_id",
name: "refund_issued_template_id",
label: { text: "Refund issued template id" },
autocomplete: "off"
})
}}

{{ govukButton({
text: "Update email branding"
})
}}

<input type="hidden" name="_csrf" value="{{ csrf }}">
</form>
{% endblock %}
22 changes: 21 additions & 1 deletion src/web/modules/gateway_accounts/gateway_accounts.http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,24 @@ const updateSurcharge = async function updateSurcharge(req: Request, res: Respon
res.redirect(`/gateway_accounts/${id}`)
}

const emailBranding = async function emailBranding(req: Request, res: Response): Promise<void> {
const { id } = req.params
const account = await getAccount(id)

res.render('gateway_accounts/email_branding', { account, csrf: req.csrfToken() })
}

const updateEmailBranding = async function updateEmailBranding(req: Request, res: Response):
Promise<void> {
const { id } = req.params
const notifySettings = req.body
delete notifySettings._csrf

await Connector.updateEmailBranding(id, notifySettings)
req.flash('info', 'Email custom branding successfully updated')
res.redirect(`/gateway_accounts/${id}`)
}

export default {
overview: wrapAsyncErrorHandler(overview),
overviewDirectDebit: wrapAsyncErrorHandler(overviewDirectDebit),
Expand All @@ -193,5 +211,7 @@ export default {
apiKeys: wrapAsyncErrorHandler(apiKeys),
deleteApiKey: wrapAsyncErrorHandler(deleteApiKey),
surcharge: wrapAsyncErrorHandler(surcharge),
updateSurcharge: wrapAsyncErrorHandler(updateSurcharge)
updateSurcharge: wrapAsyncErrorHandler(updateSurcharge),
emailBranding: wrapAsyncErrorHandler(emailBranding),
updateEmailBranding: wrapAsyncErrorHandler(updateEmailBranding)
}
4 changes: 3 additions & 1 deletion src/web/modules/gateway_accounts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@ export default {
apiKeys: http.apiKeys,
deleteApiKey: http.deleteApiKey,
surcharge: http.surcharge,
updateSurcharge: http.updateSurcharge
updateSurcharge: http.updateSurcharge,
emailBranding: http.emailBranding,
updateEmailBranding: http.updateEmailBranding
}
2 changes: 2 additions & 0 deletions src/web/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ router.post('/gateway_accounts/create/confirm', auth.secured, gatewayAccounts.co

router.get('/gateway_accounts/:id/surcharge', auth.secured, gatewayAccounts.surcharge)
router.post('/gateway_accounts/:id/surcharge', auth.secured, gatewayAccounts.updateSurcharge)
router.get('/gateway_accounts/:id/email_branding', auth.secured, gatewayAccounts.emailBranding)
router.post('/gateway_accounts/:id/email_branding', auth.secured, gatewayAccounts.updateEmailBranding)

router.get('/services', auth.secured, services.overview)
router.get('/services/search', auth.secured, services.search)
Expand Down

0 comments on commit b9bbd19

Please sign in to comment.