-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(feat) : Add ability to capture reference code for defined mode of pa…
…yments (#526)
- Loading branch information
1 parent
17889fa
commit ad56e2d
Showing
11 changed files
with
124 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { z } from 'zod'; | ||
import { type MappedBill } from '../types'; | ||
|
||
export function usePaymentSchema(bill: MappedBill) { | ||
const paymentSchema = z | ||
.object({ | ||
method: z | ||
.object({ | ||
uuid: z.string(), | ||
name: z.string(), | ||
attributeTypes: z.array( | ||
z.object({ | ||
uuid: z.string(), | ||
description: z.string(), | ||
required: z.boolean(), | ||
}), | ||
), | ||
}) | ||
.nullable() | ||
.refine((val) => val !== null, { message: 'Payment method is required' }), | ||
amount: z.number().refine((value) => { | ||
const amountDue = Number(bill.totalAmount) - (Number(bill.tenderedAmount) + Number(value)); | ||
return amountDue >= 0 && value > 0; | ||
}, 'Amount paid should not be greater than amount due'), | ||
referenceCode: z.string(), | ||
}) | ||
.refine( | ||
(data) => { | ||
const hasRequiredAttribute = data.method?.attributeTypes.some((attr) => attr.required === true); | ||
if (hasRequiredAttribute) { | ||
return data.referenceCode.trim().length > 0; | ||
} | ||
return true; | ||
}, | ||
{ | ||
message: 'Reference code is required for this payment method', | ||
path: ['referenceCode'], | ||
}, | ||
); | ||
|
||
return paymentSchema; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters