diff --git a/docker/mock-pay/payments.js b/docker/mock-pay/payments.js index 86508bde4..19de0c462 100644 --- a/docker/mock-pay/payments.js +++ b/docker/mock-pay/payments.js @@ -1,8 +1,9 @@ +console.log(`Request - ${context.request.method} ${context.request.path}`); + const paymentsStore = stores.open('payments'); -switch (context.request.method) { - case 'GET': - const getPaymentResponseBody = `{ +if (context.request.method == 'GET') { + const getPaymentResponseBody = `{ "amount": 8200, "description": "Property and Finance LPA", "reference": "Hxzqvk78fBdl", @@ -63,30 +64,28 @@ switch (context.request.method) { } ` - const payment = JSON.parse(paymentsStore.load('payment')) - let response = JSON.parse(getPaymentResponseBody) - let now = new Date() - - response.amount = payment.amount - response.email = payment.email - response.description = payment.description - response.reference = payment.reference - response.refund_summary.amount_available = payment.amount - response.settlement_summary.capture_submit_time = now.toISOString() - response.settlement_summary.captured_date = now.toISOString().split('T')[0] - now.setMinutes(now.getMinutes()-1) - response.created_date = now.toISOString() + const payment = JSON.parse(paymentsStore.load('payment')) + let response = JSON.parse(getPaymentResponseBody) + let now = new Date() - respond().withContent(JSON.stringify(response)) + response.amount = payment.amount + response.email = payment.email + response.description = payment.description + response.reference = payment.reference + response.refund_summary.amount_available = payment.amount + response.settlement_summary.capture_submit_time = now.toISOString() + response.settlement_summary.captured_date = now.toISOString().split('T')[0] - break - case 'POST': - paymentsStore.save('payment', context.request.body) + now.setMinutes(now.getMinutes() - 1) + response.created_date = now.toISOString() - respond() + respond().withContent(JSON.stringify(response)) +} else if (context.request.method == 'POST') { + const body = JSON.parse(context.request.body); + paymentsStore.save('payment', JSON.stringify(body)); - break - default: - respond() + respond() +} else { + respond() }