Skip to content

Commit

Permalink
Rename createRecurringPayment to clarify it creates agreements (#2082)
Browse files Browse the repository at this point in the history
https://eaflood.atlassian.net/browse/IWTF-4373

Since the actual payments are created using the usual createPayment function, just with recurring as true.
  • Loading branch information
irisfaraway authored Dec 6, 2024
1 parent c4f5feb commit a03b513
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions packages/connectors-lib/src/__tests__/govuk-pay-api.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ describe('govuk-pay-api-connector', () => {
})
})

describe('createRecurringPayment', () => {
describe('createRecurringPaymentAgreement', () => {
it('creates new payments', async () => {
fetch.mockReturnValue({ ok: true, status: 200 })
await expect(govUkPayApi.createRecurringPayment({ cost: 0 })).resolves.toEqual({ ok: true, status: 200 })
await expect(govUkPayApi.createRecurringPaymentAgreement({ cost: 0 })).resolves.toEqual({ ok: true, status: 200 })
expect(fetch).toHaveBeenCalledWith('http://0.0.0.0/agreement', {
body: JSON.stringify({ cost: 0 }),
headers: recurringHeaders,
Expand All @@ -137,7 +137,7 @@ describe('govuk-pay-api-connector', () => {
fetch.mockImplementation(() => {
throw new Error('')
})
expect(govUkPayApi.createRecurringPayment({ reference: '123' })).rejects.toEqual(Error(''))
expect(govUkPayApi.createRecurringPaymentAgreement({ reference: '123' })).rejects.toEqual(Error(''))
expect(fetch).toHaveBeenCalledWith('http://0.0.0.0/agreement', {
body: JSON.stringify({ reference: '123' }),
headers: recurringHeaders,
Expand Down
2 changes: 1 addition & 1 deletion packages/connectors-lib/src/govuk-pay-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const headers = recurring => ({
* @param preparedPayment - see the GOV.UK pay API reference for details
* @returns {Promise<*>}
*/
export const createRecurringPayment = async preparedPayment => {
export const createRecurringPaymentAgreement = async preparedPayment => {
try {
return fetch(process.env.GOV_PAY_RCP_API_URL, {
headers: headers(true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ describe('The govuk-pay-service', () => {
ok: true,
json: jest.fn().mockResolvedValue({ success: true, paymentId: 'abc123' })
}
govUkPayApi.createRecurringPayment.mockResolvedValue(mockResponse)
govUkPayApi.createRecurringPaymentAgreement.mockResolvedValue(mockResponse)
const unique = Symbol('payload')
const payload = {
reference: 'd81f1a2b-6508-468f-8342-b6770f60f7cd',
Expand All @@ -318,15 +318,15 @@ describe('The govuk-pay-service', () => {
unique
}
await sendRecurringPayment(payload)
expect(govUkPayApi.createRecurringPayment).toHaveBeenCalledWith(payload)
expect(govUkPayApi.createRecurringPaymentAgreement).toHaveBeenCalledWith(payload)
})

it('should return response body when payment creation is successful', async () => {
const mockResponse = {
ok: true,
json: jest.fn().mockResolvedValue({ success: true, paymentId: 'abc123' })
}
govUkPayApi.createRecurringPayment.mockResolvedValue(mockResponse)
govUkPayApi.createRecurringPaymentAgreement.mockResolvedValue(mockResponse)

const result = await sendRecurringPayment(preparedPayment)

Expand All @@ -338,7 +338,7 @@ describe('The govuk-pay-service', () => {
ok: true,
json: jest.fn().mockResolvedValue({ success: true, paymentId: 'abc123' })
}
govUkPayApi.createRecurringPayment.mockResolvedValue(mockResponse)
govUkPayApi.createRecurringPaymentAgreement.mockResolvedValue(mockResponse)

await sendRecurringPayment(preparedPayment)

Expand All @@ -352,7 +352,7 @@ describe('The govuk-pay-service', () => {
json: jest.fn().mockResolvedValue({ message: 'Server error' })
}
const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {})
govUkPayApi.createRecurringPayment.mockResolvedValue(mockResponse)
govUkPayApi.createRecurringPaymentAgreement.mockResolvedValue(mockResponse)

try {
await sendRecurringPayment(preparedPayment)
Expand All @@ -370,7 +370,7 @@ describe('The govuk-pay-service', () => {
it('should throw error when API call fails with network issue', async () => {
const mockError = new Error('Network error')
const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(jest.fn())
govUkPayApi.createRecurringPayment.mockRejectedValue(mockError)
govUkPayApi.createRecurringPaymentAgreement.mockRejectedValue(mockError)

try {
await sendRecurringPayment(preparedPayment)
Expand All @@ -389,7 +389,7 @@ describe('The govuk-pay-service', () => {
json: jest.fn().mockResolvedValue({ message: 'Rate limit exceeded' })
}
const consoleErrorSpy = jest.spyOn(console, 'info').mockImplementation(jest.fn())
govUkPayApi.createRecurringPayment.mockResolvedValue(mockResponse)
govUkPayApi.createRecurringPaymentAgreement.mockResolvedValue(mockResponse)

try {
await sendRecurringPayment(preparedPayment)
Expand All @@ -404,7 +404,7 @@ describe('The govuk-pay-service', () => {
status: 500,
json: jest.fn().mockResolvedValue({ message: 'Server error' })
}
govUkPayApi.createRecurringPayment.mockResolvedValue(mockResponse)
govUkPayApi.createRecurringPaymentAgreement.mockResolvedValue(mockResponse)

try {
await sendRecurringPayment(preparedPayment)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ export const getPaymentStatus = async (paymentId, recurring = false) => {
}
}

const createRecurringPayment = async preparedPayment => {
const createRecurringPaymentAgreement = async preparedPayment => {
try {
return await govUkPayApi.createRecurringPayment(preparedPayment)
return await govUkPayApi.createRecurringPaymentAgreement(preparedPayment)
} catch (err) {
/*
* Potentially errors caught here (unreachable, timeouts) may be retried - set origin on the error to indicate
Expand All @@ -122,7 +122,7 @@ const createRecurringPayment = async preparedPayment => {
}

export const sendRecurringPayment = async preparedPayment => {
const response = await createRecurringPayment(preparedPayment)
const response = await createRecurringPaymentAgreement(preparedPayment)

if (response.ok) {
const resBody = await response.json()
Expand Down

0 comments on commit a03b513

Please sign in to comment.