mirror of
https://github.com/kingomarnajjar/flex-template-web.git
synced 2026-07-29 05:00:43 +10:00
Validate lien items more strictly
This commit is contained in:
parent
97f436653a
commit
7a1e589af3
9 changed files with 507 additions and 1 deletions
|
|
@ -49,6 +49,7 @@ export const Checkout = {
|
|||
lineItems: [
|
||||
{
|
||||
code: 'line-item/night',
|
||||
includeFor: ['customer', 'provider'],
|
||||
quantity: new Decimal(2),
|
||||
unitPrice: new Money(4500, CURRENCY),
|
||||
lineTotal: new Money(9000, CURRENCY),
|
||||
|
|
@ -73,6 +74,7 @@ export const CustomerOrder = {
|
|||
lineItems: [
|
||||
{
|
||||
code: 'line-item/night',
|
||||
includeFor: ['customer', 'provider'],
|
||||
quantity: new Decimal(2),
|
||||
unitPrice: new Money(4500, CURRENCY),
|
||||
lineTotal: new Money(9000, CURRENCY),
|
||||
|
|
@ -97,6 +99,7 @@ export const ProviderSale = {
|
|||
lineItems: [
|
||||
{
|
||||
code: 'line-item/night',
|
||||
includeFor: ['customer', 'provider'],
|
||||
quantity: new Decimal(2),
|
||||
unitPrice: new Money(4500, CURRENCY),
|
||||
lineTotal: new Money(9000, CURRENCY),
|
||||
|
|
@ -104,6 +107,7 @@ export const ProviderSale = {
|
|||
},
|
||||
{
|
||||
code: 'line-item/provider-commission',
|
||||
includeFor: ['provider'],
|
||||
unitPrice: new Money(-2000, CURRENCY),
|
||||
lineTotal: new Money(-2000, CURRENCY),
|
||||
reversal: false,
|
||||
|
|
@ -127,6 +131,7 @@ export const ProviderSaleZeroCommission = {
|
|||
lineItems: [
|
||||
{
|
||||
code: 'line-item/night',
|
||||
includeFor: ['customer', 'provider'],
|
||||
quantity: new Decimal(2),
|
||||
unitPrice: new Money(4500, CURRENCY),
|
||||
lineTotal: new Money(9000, CURRENCY),
|
||||
|
|
@ -134,6 +139,7 @@ export const ProviderSaleZeroCommission = {
|
|||
},
|
||||
{
|
||||
code: 'line-item/provider-commission',
|
||||
includeFor: ['provider'],
|
||||
unitPrice: new Money(0, CURRENCY),
|
||||
lineTotal: new Money(0, CURRENCY),
|
||||
reversal: false,
|
||||
|
|
@ -157,6 +163,7 @@ export const ProviderSaleSingleNight = {
|
|||
lineItems: [
|
||||
{
|
||||
code: 'line-item/night',
|
||||
includeFor: ['customer', 'provider'],
|
||||
quantity: new Decimal(1),
|
||||
unitPrice: new Money(4500, CURRENCY),
|
||||
lineTotal: new Money(4500, CURRENCY),
|
||||
|
|
@ -164,6 +171,7 @@ export const ProviderSaleSingleNight = {
|
|||
},
|
||||
{
|
||||
code: 'line-item/provider-commission',
|
||||
includeFor: ['provider'],
|
||||
unitPrice: new Money(-2000, CURRENCY),
|
||||
lineTotal: new Money(-2000, CURRENCY),
|
||||
reversal: false,
|
||||
|
|
@ -188,6 +196,7 @@ export const ProviderSalePreauthorized = {
|
|||
lineItems: [
|
||||
{
|
||||
code: 'line-item/night',
|
||||
includeFor: ['customer', 'provider'],
|
||||
quantity: new Decimal(1),
|
||||
unitPrice: new Money(4500, CURRENCY),
|
||||
lineTotal: new Money(4500, CURRENCY),
|
||||
|
|
@ -195,6 +204,7 @@ export const ProviderSalePreauthorized = {
|
|||
},
|
||||
{
|
||||
code: 'line-item/provider-commission',
|
||||
includeFor: ['provider'],
|
||||
unitPrice: new Money(-2000, CURRENCY),
|
||||
lineTotal: new Money(-2000, CURRENCY),
|
||||
reversal: false,
|
||||
|
|
@ -219,6 +229,7 @@ export const ProviderSaleAccepted = {
|
|||
lineItems: [
|
||||
{
|
||||
code: 'line-item/night',
|
||||
includeFor: ['customer', 'provider'],
|
||||
quantity: new Decimal(1),
|
||||
unitPrice: new Money(4500, CURRENCY),
|
||||
lineTotal: new Money(4500, CURRENCY),
|
||||
|
|
@ -226,6 +237,7 @@ export const ProviderSaleAccepted = {
|
|||
},
|
||||
{
|
||||
code: 'line-item/provider-commission',
|
||||
includeFor: ['provider'],
|
||||
unitPrice: new Money(-2000, CURRENCY),
|
||||
lineTotal: new Money(-2000, CURRENCY),
|
||||
reversal: false,
|
||||
|
|
@ -250,6 +262,7 @@ export const ProviderSaleDeclined = {
|
|||
lineItems: [
|
||||
{
|
||||
code: 'line-item/night',
|
||||
includeFor: ['customer', 'provider'],
|
||||
quantity: new Decimal(1),
|
||||
unitPrice: new Money(4500, CURRENCY),
|
||||
lineTotal: new Money(4500, CURRENCY),
|
||||
|
|
@ -257,6 +270,7 @@ export const ProviderSaleDeclined = {
|
|||
},
|
||||
{
|
||||
code: 'line-item/provider-commission',
|
||||
includeFor: ['provider'],
|
||||
unitPrice: new Money(-2000, CURRENCY),
|
||||
lineTotal: new Money(-2000, CURRENCY),
|
||||
reversal: false,
|
||||
|
|
@ -281,6 +295,7 @@ export const ProviderSaleAutoDeclined = {
|
|||
lineItems: [
|
||||
{
|
||||
code: 'line-item/night',
|
||||
includeFor: ['customer', 'provider'],
|
||||
quantity: new Decimal(1),
|
||||
unitPrice: new Money(4500, CURRENCY),
|
||||
lineTotal: new Money(4500, CURRENCY),
|
||||
|
|
@ -288,6 +303,7 @@ export const ProviderSaleAutoDeclined = {
|
|||
},
|
||||
{
|
||||
code: 'line-item/provider-commission',
|
||||
includeFor: ['provider'],
|
||||
unitPrice: new Money(-2000, CURRENCY),
|
||||
lineTotal: new Money(-2000, CURRENCY),
|
||||
reversal: false,
|
||||
|
|
@ -312,6 +328,7 @@ export const ProviderSaleDelivered = {
|
|||
lineItems: [
|
||||
{
|
||||
code: 'line-item/night',
|
||||
includeFor: ['customer', 'provider'],
|
||||
quantity: new Decimal(1),
|
||||
unitPrice: new Money(4500, CURRENCY),
|
||||
lineTotal: new Money(4500, CURRENCY),
|
||||
|
|
@ -319,6 +336,7 @@ export const ProviderSaleDelivered = {
|
|||
},
|
||||
{
|
||||
code: 'line-item/provider-commission',
|
||||
includeFor: ['provider'],
|
||||
unitPrice: new Money(-2000, CURRENCY),
|
||||
lineTotal: new Money(-2000, CURRENCY),
|
||||
reversal: false,
|
||||
|
|
@ -343,6 +361,7 @@ export const ProviderSaleCanceled = {
|
|||
lineItems: [
|
||||
{
|
||||
code: 'line-item/night',
|
||||
includeFor: ['customer', 'provider'],
|
||||
quantity: new Decimal(1),
|
||||
unitPrice: new Money(4500, CURRENCY),
|
||||
lineTotal: new Money(4500, CURRENCY),
|
||||
|
|
@ -350,6 +369,7 @@ export const ProviderSaleCanceled = {
|
|||
},
|
||||
{
|
||||
code: 'line-item/night',
|
||||
includeFor: ['customer', 'provider'],
|
||||
quantity: new Decimal(-1),
|
||||
unitPrice: new Money(4500, CURRENCY),
|
||||
lineTotal: new Money(-4500, CURRENCY),
|
||||
|
|
@ -357,6 +377,7 @@ export const ProviderSaleCanceled = {
|
|||
},
|
||||
{
|
||||
code: 'line-item/provider-commission',
|
||||
includeFor: ['provider'],
|
||||
quantity: new Decimal(1),
|
||||
unitPrice: new Money(-2000, CURRENCY),
|
||||
lineTotal: new Money(-2000, CURRENCY),
|
||||
|
|
@ -364,6 +385,7 @@ export const ProviderSaleCanceled = {
|
|||
},
|
||||
{
|
||||
code: 'line-item/provider-commission',
|
||||
includeFor: ['provider'],
|
||||
quantity: new Decimal(-1),
|
||||
unitPrice: new Money(2000, CURRENCY),
|
||||
lineTotal: new Money(-2000, CURRENCY),
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ describe('BookingBreakdown', () => {
|
|||
lineItems: [
|
||||
{
|
||||
code: 'line-item/night',
|
||||
includeFor: ['customer', 'provider'],
|
||||
quantity: new Decimal(2),
|
||||
lineTotal: new Money(2000, 'USD'),
|
||||
unitPrice: new Money(1000, 'USD'),
|
||||
|
|
@ -69,6 +70,7 @@ describe('BookingBreakdown', () => {
|
|||
lineItems: [
|
||||
{
|
||||
code: 'line-item/night',
|
||||
includeFor: ['customer', 'provider'],
|
||||
quantity: new Decimal(2),
|
||||
lineTotal: new Money(2000, 'USD'),
|
||||
unitPrice: new Money(1000, 'USD'),
|
||||
|
|
@ -96,6 +98,7 @@ describe('BookingBreakdown', () => {
|
|||
lineItems: [
|
||||
{
|
||||
code: 'line-item/night',
|
||||
includeFor: ['customer', 'provider'],
|
||||
quantity: new Decimal(2),
|
||||
lineTotal: new Money(2000, 'USD'),
|
||||
unitPrice: new Money(1000, 'USD'),
|
||||
|
|
@ -103,6 +106,7 @@ describe('BookingBreakdown', () => {
|
|||
},
|
||||
{
|
||||
code: 'line-item/provider-commission',
|
||||
includeFor: ['provider'],
|
||||
lineTotal: new Money(-200, 'USD'),
|
||||
unitPrice: new Money(-200, 'USD'),
|
||||
reversal: false,
|
||||
|
|
@ -129,6 +133,7 @@ describe('BookingBreakdown', () => {
|
|||
lineItems: [
|
||||
{
|
||||
code: 'line-item/night',
|
||||
includeFor: ['customer', 'provider'],
|
||||
quantity: new Decimal(2),
|
||||
lineTotal: new Money(2000, 'USD'),
|
||||
unitPrice: new Money(1000, 'USD'),
|
||||
|
|
@ -136,6 +141,7 @@ describe('BookingBreakdown', () => {
|
|||
},
|
||||
{
|
||||
code: 'line-item/night',
|
||||
includeFor: ['customer', 'provider'],
|
||||
quantity: new Decimal(-2),
|
||||
lineTotal: new Money(-2000, 'USD'),
|
||||
unitPrice: new Money(1000, 'USD'),
|
||||
|
|
@ -143,6 +149,7 @@ describe('BookingBreakdown', () => {
|
|||
},
|
||||
{
|
||||
code: 'line-item/provider-commission',
|
||||
includeFor: ['provider'],
|
||||
quantity: new Decimal(1),
|
||||
lineTotal: new Money(-200, 'USD'),
|
||||
unitPrice: new Money(-200, 'USD'),
|
||||
|
|
@ -150,6 +157,7 @@ describe('BookingBreakdown', () => {
|
|||
},
|
||||
{
|
||||
code: 'line-item/provider-commission',
|
||||
includeFor: ['provider'],
|
||||
quantity: new Decimal(-1),
|
||||
lineTotal: new Money(200, 'USD'),
|
||||
unitPrice: new Money(-200, 'USD'),
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -46,6 +46,7 @@ const estimatedNightlyTransaction = (bookingStart, bookingEnd, unitPrice) => {
|
|||
lineItems: [
|
||||
{
|
||||
code: 'line-item/night',
|
||||
includeFor: ['customer', 'provider'],
|
||||
unitPrice: unitPrice,
|
||||
quantity: new Decimal(nightCount),
|
||||
lineTotal: totalPrice,
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ describe('BookingDatesForm', () => {
|
|||
expect(transaction.attributes.lineItems).toEqual([
|
||||
{
|
||||
code: 'line-item/night',
|
||||
includeFor: ['customer', 'provider'],
|
||||
unitPrice: price,
|
||||
quantity: new Decimal(2),
|
||||
lineTotal: new Money(2198, 'USD'),
|
||||
|
|
|
|||
|
|
@ -98,6 +98,10 @@ exports[`InboxPage matches snapshot 1`] = `
|
|||
"lineItems": Array [
|
||||
Object {
|
||||
"code": "line-item/night",
|
||||
"includeFor": Array [
|
||||
"customer",
|
||||
"provider",
|
||||
],
|
||||
"lineTotal": Money {
|
||||
"amount": 1000,
|
||||
"currency": "USD",
|
||||
|
|
@ -111,6 +115,9 @@ exports[`InboxPage matches snapshot 1`] = `
|
|||
},
|
||||
Object {
|
||||
"code": "line-item/provider-commission",
|
||||
"includeFor": Array [
|
||||
"provider",
|
||||
],
|
||||
"lineTotal": Money {
|
||||
"amount": -100,
|
||||
"currency": "USD",
|
||||
|
|
@ -213,6 +220,10 @@ exports[`InboxPage matches snapshot 1`] = `
|
|||
"lineItems": Array [
|
||||
Object {
|
||||
"code": "line-item/night",
|
||||
"includeFor": Array [
|
||||
"customer",
|
||||
"provider",
|
||||
],
|
||||
"lineTotal": Money {
|
||||
"amount": 1000,
|
||||
"currency": "USD",
|
||||
|
|
@ -226,6 +237,9 @@ exports[`InboxPage matches snapshot 1`] = `
|
|||
},
|
||||
Object {
|
||||
"code": "line-item/provider-commission",
|
||||
"includeFor": Array [
|
||||
"provider",
|
||||
],
|
||||
"lineTotal": Money {
|
||||
"amount": -100,
|
||||
"currency": "USD",
|
||||
|
|
@ -486,6 +500,10 @@ exports[`InboxPage matches snapshot 3`] = `
|
|||
"lineItems": Array [
|
||||
Object {
|
||||
"code": "line-item/night",
|
||||
"includeFor": Array [
|
||||
"customer",
|
||||
"provider",
|
||||
],
|
||||
"lineTotal": Money {
|
||||
"amount": 1000,
|
||||
"currency": "USD",
|
||||
|
|
@ -499,6 +517,9 @@ exports[`InboxPage matches snapshot 3`] = `
|
|||
},
|
||||
Object {
|
||||
"code": "line-item/provider-commission",
|
||||
"includeFor": Array [
|
||||
"provider",
|
||||
],
|
||||
"lineTotal": Money {
|
||||
"amount": -100,
|
||||
"currency": "USD",
|
||||
|
|
@ -601,6 +622,10 @@ exports[`InboxPage matches snapshot 3`] = `
|
|||
"lineItems": Array [
|
||||
Object {
|
||||
"code": "line-item/night",
|
||||
"includeFor": Array [
|
||||
"customer",
|
||||
"provider",
|
||||
],
|
||||
"lineTotal": Money {
|
||||
"amount": 1000,
|
||||
"currency": "USD",
|
||||
|
|
@ -614,6 +639,9 @@ exports[`InboxPage matches snapshot 3`] = `
|
|||
},
|
||||
Object {
|
||||
"code": "line-item/provider-commission",
|
||||
"includeFor": Array [
|
||||
"provider",
|
||||
],
|
||||
"lineTotal": Money {
|
||||
"amount": -100,
|
||||
"currency": "USD",
|
||||
|
|
|
|||
|
|
@ -68,6 +68,10 @@ exports[`TransactionPage - Order matches snapshot 1`] = `
|
|||
"lineItems": Array [
|
||||
Object {
|
||||
"code": "line-item/night",
|
||||
"includeFor": Array [
|
||||
"customer",
|
||||
"provider",
|
||||
],
|
||||
"lineTotal": Money {
|
||||
"amount": 1000,
|
||||
"currency": "USD",
|
||||
|
|
@ -81,6 +85,9 @@ exports[`TransactionPage - Order matches snapshot 1`] = `
|
|||
},
|
||||
Object {
|
||||
"code": "line-item/provider-commission",
|
||||
"includeFor": Array [
|
||||
"provider",
|
||||
],
|
||||
"lineTotal": Money {
|
||||
"amount": -100,
|
||||
"currency": "USD",
|
||||
|
|
@ -259,6 +266,10 @@ exports[`TransactionPage - Sale matches snapshot 1`] = `
|
|||
"lineItems": Array [
|
||||
Object {
|
||||
"code": "line-item/night",
|
||||
"includeFor": Array [
|
||||
"customer",
|
||||
"provider",
|
||||
],
|
||||
"lineTotal": Money {
|
||||
"amount": 1000,
|
||||
"currency": "USD",
|
||||
|
|
@ -272,6 +283,9 @@ exports[`TransactionPage - Sale matches snapshot 1`] = `
|
|||
},
|
||||
Object {
|
||||
"code": "line-item/provider-commission",
|
||||
"includeFor": Array [
|
||||
"provider",
|
||||
],
|
||||
"lineTotal": Money {
|
||||
"amount": -100,
|
||||
"currency": "USD",
|
||||
|
|
|
|||
|
|
@ -300,6 +300,15 @@ export const review = shape({
|
|||
subject: user,
|
||||
});
|
||||
|
||||
export const LINE_ITEM_NIGHT = 'line-item/night';
|
||||
|
||||
// TODO: This is speculative, check again when the API adds the day support
|
||||
export const LINE_ITEM_DAY = 'line-item/day';
|
||||
|
||||
export const LINE_ITEM_PROVIDER_COMMISSION = 'line-item/provider-commission';
|
||||
|
||||
const LINE_ITEMS = [LINE_ITEM_NIGHT, LINE_ITEM_DAY, LINE_ITEM_PROVIDER_COMMISSION];
|
||||
|
||||
// Denormalised transaction object
|
||||
export const transaction = shape({
|
||||
id: uuid.isRequired,
|
||||
|
|
@ -316,7 +325,8 @@ export const transaction = shape({
|
|||
|
||||
lineItems: arrayOf(
|
||||
shape({
|
||||
code: string.isRequired,
|
||||
code: oneOf(LINE_ITEMS).isRequired,
|
||||
includeFor: arrayOf(oneOf(['customer', 'provider'])).isRequired,
|
||||
quantity: instanceOf(Decimal),
|
||||
unitPrice: money.isRequired,
|
||||
lineTotal: money.isRequired,
|
||||
|
|
|
|||
|
|
@ -134,6 +134,7 @@ export const createTransaction = options => {
|
|||
lineItems: [
|
||||
{
|
||||
code: 'line-item/night',
|
||||
includeFor: ['customer', 'provider'],
|
||||
quantity: new Decimal(nightCount),
|
||||
unitPrice: new Money(total.amount / nightCount, total.currency),
|
||||
lineTotal: total,
|
||||
|
|
@ -141,6 +142,7 @@ export const createTransaction = options => {
|
|||
},
|
||||
{
|
||||
code: 'line-item/provider-commission',
|
||||
includeFor: ['provider'],
|
||||
unitPrice: new Money(commission.amount * -1, commission.currency),
|
||||
lineTotal: new Money(commission.amount * -1, commission.currency),
|
||||
reversal: false,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue