@defra-fish/recurring-payments-job 1.63.0-rc.10 → 1.63.0-rc.11
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defra-fish/recurring-payments-job",
|
|
3
|
-
"version": "1.63.0-rc.
|
|
3
|
+
"version": "1.63.0-rc.11",
|
|
4
4
|
"description": "Rod Licensing Recurring Payments Job",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -36,11 +36,11 @@
|
|
|
36
36
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@defra-fish/business-rules-lib": "1.63.0-rc.
|
|
40
|
-
"@defra-fish/connectors-lib": "1.63.0-rc.
|
|
39
|
+
"@defra-fish/business-rules-lib": "1.63.0-rc.11",
|
|
40
|
+
"@defra-fish/connectors-lib": "1.63.0-rc.11",
|
|
41
41
|
"commander": "^7.2.0",
|
|
42
42
|
"debug": "^4.3.3",
|
|
43
43
|
"moment-timezone": "^0.5.34"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "7d0e5dab76d8aebb0dbaecb857c3d44fdc6f79f9"
|
|
46
46
|
}
|
|
@@ -20,6 +20,7 @@ jest.mock('@defra-fish/business-rules-lib', () => ({
|
|
|
20
20
|
}))
|
|
21
21
|
jest.mock('@defra-fish/connectors-lib', () => ({
|
|
22
22
|
salesApi: {
|
|
23
|
+
cancelRecurringPayment: jest.fn(),
|
|
23
24
|
createPaymentJournal: jest.fn(),
|
|
24
25
|
createTransaction: jest.fn(() => ({
|
|
25
26
|
id: 'test-transaction-id',
|
|
@@ -636,6 +637,30 @@ describe('recurring-payments-processor', () => {
|
|
|
636
637
|
}
|
|
637
638
|
)
|
|
638
639
|
|
|
640
|
+
it.each([
|
|
641
|
+
['a failure', 'agreement-id', getPaymentStatusFailure()],
|
|
642
|
+
['a failure', 'test-agreement-id', getPaymentStatusFailure()],
|
|
643
|
+
['a failure', 'another-agreement-id', getPaymentStatusFailure()],
|
|
644
|
+
['an error', 'agreement-id', getPaymentStatusError()],
|
|
645
|
+
['an error', 'test-agreement-id', getPaymentStatusError()],
|
|
646
|
+
['an error', 'another-agreement-id', getPaymentStatusError()]
|
|
647
|
+
])('cancelRecurringPayment is called when payment is %s', async (_status, agreementId, mockStatus) => {
|
|
648
|
+
salesApi.getDueRecurringPayments.mockReturnValueOnce([getMockDueRecurringPayment({ agreementId })])
|
|
649
|
+
const id = Symbol('recurring-payment-id')
|
|
650
|
+
salesApi.createTransaction.mockResolvedValueOnce({
|
|
651
|
+
recurringPayment: {
|
|
652
|
+
id
|
|
653
|
+
}
|
|
654
|
+
})
|
|
655
|
+
const mockPaymentResponse = { payment_id: 'test-payment-id', created_date: '2025-01-01T00:00:00.000Z' }
|
|
656
|
+
sendPayment.mockResolvedValueOnce(mockPaymentResponse)
|
|
657
|
+
getPaymentStatus.mockResolvedValueOnce(mockStatus)
|
|
658
|
+
|
|
659
|
+
await processRecurringPayments()
|
|
660
|
+
|
|
661
|
+
expect(salesApi.cancelRecurringPayment).toHaveBeenCalledWith(id)
|
|
662
|
+
})
|
|
663
|
+
|
|
639
664
|
it('updatePaymentJournal is called with transaction id and failed status code payment is not succesful and payment journal exists', async () => {
|
|
640
665
|
salesApi.getDueRecurringPayments.mockReturnValueOnce([getMockDueRecurringPayment()])
|
|
641
666
|
const transactionId = 'test-transaction-id'
|
|
@@ -154,6 +154,7 @@ const processRecurringPaymentStatus = async payment => {
|
|
|
154
154
|
paymentStatus: PAYMENT_JOURNAL_STATUS_CODES.Failed
|
|
155
155
|
})
|
|
156
156
|
}
|
|
157
|
+
await salesApi.cancelRecurringPayment(payment.transaction.recurringPayment.id)
|
|
157
158
|
}
|
|
158
159
|
} catch (error) {
|
|
159
160
|
const status = error.response?.status
|
|
@@ -165,5 +166,6 @@ const processRecurringPaymentStatus = async payment => {
|
|
|
165
166
|
} else {
|
|
166
167
|
debug(`Unexpected error fetching payment status for ${payment.paymentId}.`)
|
|
167
168
|
}
|
|
169
|
+
await salesApi.cancelRecurringPayment(payment.transaction.recurringPayment.id)
|
|
168
170
|
}
|
|
169
171
|
}
|