Skip to content

Commit

Permalink
Fix script for mock-pay
Browse files Browse the repository at this point in the history
  • Loading branch information
hawx committed Jan 2, 2025
1 parent ea5d44a commit 259bb2f
Showing 1 changed file with 23 additions and 24 deletions.
47 changes: 23 additions & 24 deletions docker/mock-pay/payments.js
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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()
}

0 comments on commit 259bb2f

Please sign in to comment.