Skip to content
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

PP-12427 switch to worldpay (MOTO service) impl #4458

Merged
merged 3 commits into from
Feb 18, 2025

Conversation

nlsteers
Copy link
Collaborator

@nlsteers nlsteers commented Feb 12, 2025

WHAT

  • new views and controllers for handling switch to worldpay tasks for a moto service
  • new ChargeRequest class
  • new GatewayAccountSwitchPaymentProviderRequest class
  • extend WorldpayTasks: add makeALivePayment (verify that worldpay credentials are working)
  • update GatewayAccountCredentialUpdateRequest, enable credential state change
  • extract one off customer initiated credentials validation into reusable schema

HOW

this PR requires a corresponding change in connector in order to behave correctly

additionally, our stubbing mechanism for worldpay orders does not account for how we currently handle moto services.

in production a gateway account will have a MOTO specific merchant code that worldpay will recognise and determine not to request a 3DS check.

our stubbing mechanism is not that smart (because connector still includes the flag to request 3DS regardless of MOTO status). you will need to manually change the gateway account requires3ds flag to false in order to test locally if using stubs to mock out worldpay responses

SCREENS

Screenshot 2025-02-17 at 23 24 05 Screenshot 2025-02-17 at 23 21 31 Screenshot 2025-02-17 at 23 21 38 Screenshot 2025-02-17 at 23 21 43 Screenshot 2025-02-17 at 23 22 22 Screenshot 2025-02-17 at 23 23 01 Screenshot 2025-02-17 at 23 23 16 Screenshot 2025-02-17 at 23 23 20 Screenshot 2025-02-17 at 23 23 23 Screenshot 2025-02-17 at 23 23 33 Screenshot 2025-02-17 at 23 23 40 Screenshot 2025-02-17 at 23 24 16 Screenshot 2025-02-17 at 23 24 24

@nlsteers
Copy link
Collaborator Author

needs alphagov/pay-connector#5722

@nlsteers nlsteers force-pushed the pp-12427/moto-switch-to-worldpay branch 2 times, most recently from cdf7e5a to 3d8c88f Compare February 17, 2025 23:35
- new views and controllers for handling switch to worldpay tasks for a moto service
- new `ChargeRequest` class
- new `GatewayAccountSwitchPaymentProviderRequest` class
- extend `WorldpayTasks`: add `makeALivePayment` (verify that worldpay credentials are working)
- update `GatewayAccountCredentialUpdateRequest`, enable credential state change
- extract one off customer initiated credentials validation into reusable schema
@nlsteers nlsteers force-pushed the pp-12427/moto-switch-to-worldpay branch from 3d8c88f to 737de20 Compare February 18, 2025 00:23
*/
constructor (gatewayAccount, serviceExternalId) {
constructor (gatewayAccount, serviceExternalId, switchingPsp = false) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i wonder whether there should be a static WorldpayTasks.forSwitchingPsp method instead of a constructor with various options

Comment on lines +56 to +67
chargeService.getCharge(service.externalId, account.type, chargeExternalId)
.then(async (charge) => {
if (charge.state.status === 'success') {
await worldpayDetailsService.updateCredentialState(service.externalId, account.type, targetCredential.externalId, user.externalId, CREDENTIAL_STATE.VERIFIED)
req.flash('messages', { state: 'success', icon: '✓', heading: 'Payment verified', body: `This service is ready to switch to ${formatPSPName(targetCredential.paymentProvider)}` })
} else {
req.flash('messages', { state: 'error', heading: 'There is a problem', body: 'The payment has failed. Check your Worldpay credentials and try again. If you need help, contact [email protected]' })
}
res.redirect(formatSimplifiedAccountPathsFor(paths.simplifiedAccount.settings.switchPsp.switchToWorldpay.index,
service.externalId, account.type))
})
.catch(err => next(err))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this might be neater without the promise/then and just using async/await like

const charge = await chargeService.getCharge(...)
if (charge.state.status !== 'success') {
 // return error
}
await worldpayDetailsService.updateCredentialState(...)
// return success

may need a try/catch to be sure errors are handled properly

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll experiment with the structure here once I have a cypress test for this controller

@nlsteers nlsteers force-pushed the pp-12427/moto-switch-to-worldpay branch from e94d6f9 to 5be728f Compare February 18, 2025 16:23
Copy link
Contributor

@DomBelcher DomBelcher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nlsteers nlsteers merged commit b278d35 into master Feb 18, 2025
14 checks passed
@nlsteers nlsteers deleted the pp-12427/moto-switch-to-worldpay branch February 18, 2025 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants