@defra-fish/connectors-lib 1.55.0-rc.5 → 1.55.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -1
- package/package.json +2 -2
- package/src/__tests__/govuk-pay-api.spec.js +2 -40
- package/src/govuk-pay-api.js +9 -9
package/README.md
CHANGED
|
@@ -18,7 +18,6 @@ Provides connectivity to the resources/infrastructure used in the rod licensing
|
|
|
18
18
|
| SALES_API_TIMEOUT_MS | Request timeout for the requests to the sales API | no | 20000 (20s) | | |
|
|
19
19
|
| GOV_PAY_API_URL | The GOV.UK Pay API base url | yes | | | |
|
|
20
20
|
| GOV_PAY_APIKEY | GOV pay access identifier | yes | | | |
|
|
21
|
-
| GOV_PAY_RECURRING_APIKEY | GOV pay access identifier for recurring payments | yes | | | |
|
|
22
21
|
| GOV_PAY_REQUEST_TIMEOUT_MS | Timeout in milliseconds for API requests | no | 10000 | | |
|
|
23
22
|
| GOV_PAY_RCP_API_URL | The GOV.UK Pay API url for agreements | yes | |
|
|
24
23
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defra-fish/connectors-lib",
|
|
3
|
-
"version": "1.55.0
|
|
3
|
+
"version": "1.55.0",
|
|
4
4
|
"description": "Shared connectors",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"node-fetch": "^2.6.7",
|
|
42
42
|
"redlock": "^4.2.0"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "3405322b81a2016ba22e530de8d096a49be0bea4"
|
|
45
45
|
}
|
|
@@ -5,7 +5,6 @@ const fetch = require('node-fetch')
|
|
|
5
5
|
process.env.GOV_PAY_API_URL = 'http://0.0.0.0/payment'
|
|
6
6
|
process.env.GOV_PAY_RCP_API_URL = 'http://0.0.0.0/agreement'
|
|
7
7
|
process.env.GOV_PAY_APIKEY = 'key'
|
|
8
|
-
process.env.GOV_PAY_RECURRING_APIKEY = 'recurringkey'
|
|
9
8
|
|
|
10
9
|
const headers = {
|
|
11
10
|
accept: 'application/json',
|
|
@@ -13,12 +12,6 @@ const headers = {
|
|
|
13
12
|
'content-type': 'application/json'
|
|
14
13
|
}
|
|
15
14
|
|
|
16
|
-
const recurringHeaders = {
|
|
17
|
-
accept: 'application/json',
|
|
18
|
-
authorization: `Bearer ${process.env.GOV_PAY_RECURRING_APIKEY}`,
|
|
19
|
-
'content-type': 'application/json'
|
|
20
|
-
}
|
|
21
|
-
|
|
22
15
|
describe('govuk-pay-api-connector', () => {
|
|
23
16
|
beforeEach(jest.clearAllMocks)
|
|
24
17
|
|
|
@@ -48,17 +41,6 @@ describe('govuk-pay-api-connector', () => {
|
|
|
48
41
|
})
|
|
49
42
|
expect(consoleErrorSpy).toHaveBeenCalled()
|
|
50
43
|
})
|
|
51
|
-
|
|
52
|
-
it('uses the correct API key if recurring arg is set to true', async () => {
|
|
53
|
-
fetch.mockReturnValue({ ok: true, status: 200 })
|
|
54
|
-
await expect(govUkPayApi.createPayment({ cost: 0 }, true)).resolves.toEqual({ ok: true, status: 200 })
|
|
55
|
-
expect(fetch).toHaveBeenCalledWith('http://0.0.0.0/payment', {
|
|
56
|
-
body: JSON.stringify({ cost: 0 }),
|
|
57
|
-
headers: recurringHeaders,
|
|
58
|
-
method: 'post',
|
|
59
|
-
timeout: 10000
|
|
60
|
-
})
|
|
61
|
-
})
|
|
62
44
|
})
|
|
63
45
|
|
|
64
46
|
describe('fetchPaymentStatus', () => {
|
|
@@ -81,16 +63,6 @@ describe('govuk-pay-api-connector', () => {
|
|
|
81
63
|
expect(fetch).toHaveBeenCalledWith('http://0.0.0.0/payment/123', { headers, method: 'get', timeout: 10000 })
|
|
82
64
|
expect(consoleErrorSpy).toHaveBeenCalled()
|
|
83
65
|
})
|
|
84
|
-
|
|
85
|
-
it('uses the correct API key if recurring arg is set to true', async () => {
|
|
86
|
-
fetch.mockReturnValue({ ok: true, status: 200, json: () => {} })
|
|
87
|
-
await expect(govUkPayApi.fetchPaymentStatus(123, true)).resolves.toEqual(expect.objectContaining({ ok: true, status: 200 }))
|
|
88
|
-
expect(fetch).toHaveBeenCalledWith('http://0.0.0.0/payment/123', {
|
|
89
|
-
headers: recurringHeaders,
|
|
90
|
-
method: 'get',
|
|
91
|
-
timeout: 10000
|
|
92
|
-
})
|
|
93
|
-
})
|
|
94
66
|
})
|
|
95
67
|
|
|
96
68
|
describe('fetchPaymentEvents', () => {
|
|
@@ -108,16 +80,6 @@ describe('govuk-pay-api-connector', () => {
|
|
|
108
80
|
await expect(govUkPayApi.fetchPaymentEvents(123)).rejects.toEqual(Error('test event error'))
|
|
109
81
|
expect(consoleErrorSpy).toHaveBeenCalled()
|
|
110
82
|
})
|
|
111
|
-
|
|
112
|
-
it('uses the correct API key if recurring arg is set to true', async () => {
|
|
113
|
-
fetch.mockReturnValue({ ok: true, status: 200, json: () => {} })
|
|
114
|
-
await expect(govUkPayApi.fetchPaymentEvents(123, true)).resolves.toEqual(expect.objectContaining({ ok: true, status: 200 }))
|
|
115
|
-
expect(fetch).toHaveBeenCalledWith('http://0.0.0.0/payment/123/events', {
|
|
116
|
-
headers: recurringHeaders,
|
|
117
|
-
method: 'get',
|
|
118
|
-
timeout: 10000
|
|
119
|
-
})
|
|
120
|
-
})
|
|
121
83
|
})
|
|
122
84
|
|
|
123
85
|
describe('createRecurringPayment', () => {
|
|
@@ -126,7 +88,7 @@ describe('govuk-pay-api-connector', () => {
|
|
|
126
88
|
await expect(govUkPayApi.createRecurringPayment({ cost: 0 })).resolves.toEqual({ ok: true, status: 200 })
|
|
127
89
|
expect(fetch).toHaveBeenCalledWith('http://0.0.0.0/agreement', {
|
|
128
90
|
body: JSON.stringify({ cost: 0 }),
|
|
129
|
-
headers
|
|
91
|
+
headers,
|
|
130
92
|
method: 'post',
|
|
131
93
|
timeout: 10000
|
|
132
94
|
})
|
|
@@ -140,7 +102,7 @@ describe('govuk-pay-api-connector', () => {
|
|
|
140
102
|
expect(govUkPayApi.createRecurringPayment({ reference: '123' })).rejects.toEqual(Error(''))
|
|
141
103
|
expect(fetch).toHaveBeenCalledWith('http://0.0.0.0/agreement', {
|
|
142
104
|
body: JSON.stringify({ reference: '123' }),
|
|
143
|
-
headers
|
|
105
|
+
headers,
|
|
144
106
|
method: 'post',
|
|
145
107
|
timeout: 10000
|
|
146
108
|
})
|
package/src/govuk-pay-api.js
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
import fetch from 'node-fetch'
|
|
5
5
|
const GOV_PAY_REQUEST_TIMEOUT_MS_DEFAULT = 10000
|
|
6
6
|
|
|
7
|
-
const headers =
|
|
7
|
+
const headers = () => ({
|
|
8
8
|
accept: 'application/json',
|
|
9
|
-
authorization: `Bearer ${
|
|
9
|
+
authorization: `Bearer ${process.env.GOV_PAY_APIKEY}`,
|
|
10
10
|
'content-type': 'application/json'
|
|
11
11
|
})
|
|
12
12
|
|
|
@@ -18,7 +18,7 @@ const headers = recurring => ({
|
|
|
18
18
|
export const createRecurringPayment = async preparedPayment => {
|
|
19
19
|
try {
|
|
20
20
|
return fetch(process.env.GOV_PAY_RCP_API_URL, {
|
|
21
|
-
headers: headers(
|
|
21
|
+
headers: headers(),
|
|
22
22
|
method: 'post',
|
|
23
23
|
body: JSON.stringify(preparedPayment),
|
|
24
24
|
timeout: process.env.GOV_PAY_REQUEST_TIMEOUT_MS || GOV_PAY_REQUEST_TIMEOUT_MS_DEFAULT
|
|
@@ -37,10 +37,10 @@ export const createRecurringPayment = async preparedPayment => {
|
|
|
37
37
|
* @param preparedPayment - see the GOV.UK pay API reference for details
|
|
38
38
|
* @returns {Promise<*>}
|
|
39
39
|
*/
|
|
40
|
-
export const createPayment = async
|
|
40
|
+
export const createPayment = async preparedPayment => {
|
|
41
41
|
try {
|
|
42
42
|
return fetch(process.env.GOV_PAY_API_URL, {
|
|
43
|
-
headers: headers(
|
|
43
|
+
headers: headers(),
|
|
44
44
|
method: 'post',
|
|
45
45
|
body: JSON.stringify(preparedPayment),
|
|
46
46
|
timeout: process.env.GOV_PAY_REQUEST_TIMEOUT_MS || GOV_PAY_REQUEST_TIMEOUT_MS_DEFAULT
|
|
@@ -56,10 +56,10 @@ export const createPayment = async (preparedPayment, recurring = false) => {
|
|
|
56
56
|
* @param paymentId
|
|
57
57
|
* @returns {Promise<unknown>}
|
|
58
58
|
*/
|
|
59
|
-
export const fetchPaymentStatus = async
|
|
59
|
+
export const fetchPaymentStatus = async paymentId => {
|
|
60
60
|
try {
|
|
61
61
|
return fetch(`${process.env.GOV_PAY_API_URL}/${paymentId}`, {
|
|
62
|
-
headers: headers(
|
|
62
|
+
headers: headers(),
|
|
63
63
|
method: 'get',
|
|
64
64
|
timeout: process.env.GOV_PAY_REQUEST_TIMEOUT_MS || GOV_PAY_REQUEST_TIMEOUT_MS_DEFAULT
|
|
65
65
|
})
|
|
@@ -74,10 +74,10 @@ export const fetchPaymentStatus = async (paymentId, recurring = false) => {
|
|
|
74
74
|
* @param paymentId
|
|
75
75
|
* @returns {Promise<unknown>}
|
|
76
76
|
*/
|
|
77
|
-
export const fetchPaymentEvents = async
|
|
77
|
+
export const fetchPaymentEvents = async paymentId => {
|
|
78
78
|
try {
|
|
79
79
|
return fetch(`${process.env.GOV_PAY_API_URL}/${paymentId}/events`, {
|
|
80
|
-
headers: headers(
|
|
80
|
+
headers: headers(),
|
|
81
81
|
method: 'get',
|
|
82
82
|
timeout: process.env.GOV_PAY_REQUEST_TIMEOUT_MS || GOV_PAY_REQUEST_TIMEOUT_MS_DEFAULT
|
|
83
83
|
})
|