@powerhousedao/contributor-billing 0.0.99 → 0.1.1
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/dist/document-models/billing-statement/src/reducers/general.d.ts.map +1 -1
- package/dist/document-models/billing-statement/src/reducers/general.js +8 -26
- package/dist/document-models/billing-statement/src/reducers/line-items.d.ts.map +1 -1
- package/dist/document-models/billing-statement/src/reducers/line-items.js +19 -29
- package/dist/document-models/billing-statement/src/reducers/tags.d.ts.map +1 -1
- package/dist/document-models/billing-statement/src/reducers/tags.js +20 -25
- package/dist/document-models/integrations/src/reducers/integrations.d.ts.map +1 -1
- package/dist/document-models/integrations/src/reducers/integrations.js +29 -44
- package/dist/document-models/invoice/src/reducers/general.d.ts.map +1 -1
- package/dist/document-models/invoice/src/reducers/general.js +31 -56
- package/dist/document-models/invoice/src/reducers/items.d.ts.map +1 -1
- package/dist/document-models/invoice/src/reducers/items.js +63 -88
- package/dist/document-models/invoice/src/reducers/parties.d.ts.map +1 -1
- package/dist/document-models/invoice/src/reducers/parties.js +199 -229
- package/dist/editors/billing-statement/components/lineItemsTable.d.ts +3 -2
- package/dist/editors/billing-statement/components/lineItemsTable.d.ts.map +1 -1
- package/dist/editors/billing-statement/components/lineItemsTable.js +12 -8
- package/dist/editors/billing-statement/components/objectSetTable.d.ts +3 -2
- package/dist/editors/billing-statement/components/objectSetTable.d.ts.map +1 -1
- package/dist/editors/billing-statement/editor.d.ts +3 -1
- package/dist/editors/billing-statement/editor.d.ts.map +1 -1
- package/dist/editors/billing-statement/editor.js +2 -2
- package/dist/editors/billing-statement/lineItemTags/lineItemTags.d.ts +2 -2
- package/dist/editors/billing-statement/lineItemTags/lineItemTags.d.ts.map +1 -1
- package/dist/editors/contributor-billing/components/DriveExplorer.d.ts +8 -1
- package/dist/editors/contributor-billing/components/DriveExplorer.d.ts.map +1 -1
- package/dist/editors/contributor-billing/components/DriveExplorer.js +18 -64
- package/dist/editors/contributor-billing/components/InvoiceTable/HeaderControls.d.ts +2 -8
- package/dist/editors/contributor-billing/components/InvoiceTable/HeaderControls.d.ts.map +1 -1
- package/dist/editors/contributor-billing/components/InvoiceTable/HeaderControls.js +21 -7
- package/dist/editors/contributor-billing/components/InvoiceTable/InvoiceTable.d.ts +8 -10
- package/dist/editors/contributor-billing/components/InvoiceTable/InvoiceTable.d.ts.map +1 -1
- package/dist/editors/contributor-billing/components/InvoiceTable/InvoiceTable.js +27 -24
- package/dist/editors/contributor-billing/components/InvoiceTable/InvoiceTableRow.d.ts +6 -8
- package/dist/editors/contributor-billing/components/InvoiceTable/InvoiceTableRow.d.ts.map +1 -1
- package/dist/editors/contributor-billing/components/InvoiceTable/InvoiceTableRow.js +8 -17
- package/dist/editors/contributor-billing/editor.d.ts +1 -10
- package/dist/editors/contributor-billing/editor.d.ts.map +1 -1
- package/dist/editors/contributor-billing/editor.js +2 -23
- package/dist/editors/contributor-billing/hooks/useTransformedNodes.d.ts +2 -1
- package/dist/editors/contributor-billing/hooks/useTransformedNodes.d.ts.map +1 -1
- package/dist/editors/contributor-billing/index.js +1 -1
- package/dist/editors/hooks/useBillingStatementDocument.d.ts +4 -0
- package/dist/editors/hooks/useBillingStatementDocument.d.ts.map +1 -0
- package/dist/editors/hooks/useBillingStatementDocument.js +8 -0
- package/dist/editors/hooks/useIntegrationsDocument.d.ts +4 -0
- package/dist/editors/hooks/useIntegrationsDocument.d.ts.map +1 -0
- package/dist/editors/hooks/useIntegrationsDocument.js +8 -0
- package/dist/editors/hooks/useInvoiceDocument.d.ts +4 -0
- package/dist/editors/hooks/useInvoiceDocument.d.ts.map +1 -0
- package/dist/editors/hooks/useInvoiceDocument.js +8 -0
- package/dist/editors/integrations/editor.d.ts +4 -1
- package/dist/editors/integrations/editor.d.ts.map +1 -1
- package/dist/editors/integrations/editor.js +7 -12
- package/dist/editors/invoice/editor.d.ts +4 -1
- package/dist/editors/invoice/editor.d.ts.map +1 -1
- package/dist/editors/invoice/editor.js +5 -4
- package/dist/editors/invoice/ingestPDF.d.ts.map +1 -1
- package/dist/editors/invoice/ingestPDF.js +3 -3
- package/dist/editors/invoice/invoiceToGnosis.d.ts +3 -2
- package/dist/editors/invoice/invoiceToGnosis.d.ts.map +1 -1
- package/dist/editors/invoice/invoiceToGnosis.js +11 -11
- package/dist/editors/invoice/legalEntity/bankSection.d.ts +1 -0
- package/dist/editors/invoice/legalEntity/bankSection.d.ts.map +1 -1
- package/dist/editors/invoice/legalEntity/bankSection.js +36 -12
- package/dist/editors/invoice/legalEntity/legalEntity.d.ts +2 -1
- package/dist/editors/invoice/legalEntity/legalEntity.d.ts.map +1 -1
- package/dist/editors/invoice/legalEntity/legalEntity.js +2 -2
- package/dist/editors/invoice/lineItemTags/lineItemTags.d.ts.map +1 -1
- package/dist/editors/invoice/lineItems.d.ts.map +1 -1
- package/dist/editors/invoice/lineItems.js +8 -6
- package/dist/editors/invoice/requestFinance.js +2 -2
- package/dist/editors/invoice/uploadPdfChunked.js +1 -1
- package/dist/editors/invoice/validation/validationHandler.d.ts +1 -1
- package/dist/editors/invoice/validation/validationHandler.d.ts.map +1 -1
- package/dist/editors/invoice/validation/validationHandler.js +25 -9
- package/dist/editors/invoice/validation/validationManager.d.ts.map +1 -1
- package/dist/editors/invoice/validation/validationManager.js +3 -2
- package/dist/editors/invoice/validation/validationRules.d.ts +2 -0
- package/dist/editors/invoice/validation/validationRules.d.ts.map +1 -1
- package/dist/editors/invoice/validation/validationRules.js +37 -7
- package/dist/scripts/contributor-billing/createExpenseReportCsv.d.ts +5 -0
- package/dist/scripts/contributor-billing/createExpenseReportCsv.d.ts.map +1 -0
- package/dist/scripts/contributor-billing/createExpenseReportCsv.js +122 -0
- package/dist/style.css +9 -6
- package/package.json +12 -12
- package/dist/reducers/general.d.ts +0 -8
- package/dist/reducers/general.d.ts.map +0 -1
- package/dist/reducers/general.js +0 -73
- package/dist/reducers/items.d.ts +0 -8
- package/dist/reducers/items.d.ts.map +0 -1
- package/dist/reducers/items.js +0 -195
- package/dist/reducers/parties.d.ts +0 -8
- package/dist/reducers/parties.d.ts.map +0 -1
- package/dist/reducers/parties.js +0 -266
- package/dist/reducers/transitions.d.ts +0 -8
- package/dist/reducers/transitions.d.ts.map +0 -1
- package/dist/reducers/transitions.js +0 -162
package/dist/reducers/items.js
DELETED
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This is a scaffold file meant for customization:
|
|
3
|
-
* - modify it by implementing the reducer functions
|
|
4
|
-
* - delete the file and run the code generator again to have it reset
|
|
5
|
-
*/
|
|
6
|
-
export const reducer = {
|
|
7
|
-
addLineItemOperation(state, action, dispatch) {
|
|
8
|
-
try {
|
|
9
|
-
const item = {
|
|
10
|
-
...action.input,
|
|
11
|
-
lineItemTag: [],
|
|
12
|
-
};
|
|
13
|
-
if (state.lineItems.find((x) => x.id === item.id))
|
|
14
|
-
throw new Error("Duplicate input.id");
|
|
15
|
-
validatePrices(item);
|
|
16
|
-
state.lineItems.push(item);
|
|
17
|
-
updateTotals(state);
|
|
18
|
-
}
|
|
19
|
-
catch (e) {
|
|
20
|
-
console.error(e);
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
editLineItemOperation(state, action, dispatch) {
|
|
24
|
-
try {
|
|
25
|
-
const stateItem = state.lineItems.find((x) => x.id === action.input.id);
|
|
26
|
-
if (!stateItem)
|
|
27
|
-
throw new Error("Item matching input.id not found");
|
|
28
|
-
const sanitizedInput = Object.fromEntries(Object.entries(action.input).filter(([, value]) => value !== null));
|
|
29
|
-
// Ensure lineItemTag is always an array if provided
|
|
30
|
-
if ('lineItemTag' in action.input) {
|
|
31
|
-
sanitizedInput.lineItemTag = (action.input.lineItemTag ?? []);
|
|
32
|
-
}
|
|
33
|
-
const nextItem = {
|
|
34
|
-
...stateItem,
|
|
35
|
-
...sanitizedInput,
|
|
36
|
-
};
|
|
37
|
-
validatePrices(nextItem);
|
|
38
|
-
applyInvariants(state, nextItem);
|
|
39
|
-
Object.assign(stateItem, nextItem);
|
|
40
|
-
updateTotals(state);
|
|
41
|
-
}
|
|
42
|
-
catch (e) {
|
|
43
|
-
console.error(e);
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
deleteLineItemOperation(state, action, dispatch) {
|
|
47
|
-
try {
|
|
48
|
-
state.lineItems = state.lineItems.filter((x) => x.id !== action.input.id);
|
|
49
|
-
updateTotals(state);
|
|
50
|
-
}
|
|
51
|
-
catch (e) {
|
|
52
|
-
console.error(e);
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
setLineItemTagOperation(state, action, dispatch) {
|
|
56
|
-
try {
|
|
57
|
-
const stateItem = state.lineItems.find((x) => x.id === action.input.lineItemId);
|
|
58
|
-
if (!stateItem)
|
|
59
|
-
throw new Error("Item matching input.id not found");
|
|
60
|
-
// if tag already exists with the same dimension, update the value and label
|
|
61
|
-
const existingTag = stateItem.lineItemTag?.find((tag) => tag.dimension === action.input.dimension);
|
|
62
|
-
if (existingTag) {
|
|
63
|
-
existingTag.value = action.input.value;
|
|
64
|
-
existingTag.label = action.input.label || null;
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
// if tag does not exist, add it
|
|
68
|
-
const newTag = {
|
|
69
|
-
dimension: action.input.dimension,
|
|
70
|
-
value: action.input.value,
|
|
71
|
-
label: action.input.label || null,
|
|
72
|
-
};
|
|
73
|
-
if (!stateItem.lineItemTag) {
|
|
74
|
-
stateItem.lineItemTag = [];
|
|
75
|
-
}
|
|
76
|
-
// Add the new tag
|
|
77
|
-
stateItem.lineItemTag?.push(newTag);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
catch (e) {
|
|
81
|
-
console.error(e);
|
|
82
|
-
}
|
|
83
|
-
},
|
|
84
|
-
setInvoiceTagOperation(state, action, dispatch) {
|
|
85
|
-
try {
|
|
86
|
-
// if tag already exists with the same dimension, update the value and label
|
|
87
|
-
const existingTag = state.invoiceTags?.find((tag) => tag.dimension === action.input.dimension);
|
|
88
|
-
if (existingTag) {
|
|
89
|
-
existingTag.value = action.input.value;
|
|
90
|
-
existingTag.label = action.input.label || null;
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
// if tag does not exist, add it
|
|
94
|
-
const newTag = {
|
|
95
|
-
dimension: action.input.dimension,
|
|
96
|
-
value: action.input.value,
|
|
97
|
-
label: action.input.label || null,
|
|
98
|
-
};
|
|
99
|
-
if (!state.invoiceTags) {
|
|
100
|
-
state.invoiceTags = [];
|
|
101
|
-
}
|
|
102
|
-
// Add the new tag
|
|
103
|
-
state.invoiceTags.push(newTag);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
catch (e) {
|
|
107
|
-
console.error(e);
|
|
108
|
-
}
|
|
109
|
-
},
|
|
110
|
-
};
|
|
111
|
-
function updateTotals(state) {
|
|
112
|
-
state.totalPriceTaxExcl = state.lineItems.reduce((total, lineItem) => {
|
|
113
|
-
return total + lineItem.quantity * lineItem.unitPriceTaxExcl;
|
|
114
|
-
}, 0.0);
|
|
115
|
-
state.totalPriceTaxIncl = state.lineItems.reduce((total, lineItem) => {
|
|
116
|
-
return total + lineItem.quantity * lineItem.unitPriceTaxIncl;
|
|
117
|
-
}, 0.0);
|
|
118
|
-
}
|
|
119
|
-
function validatePrices(item) {
|
|
120
|
-
const EPSILON = 0.00001; // Small value for floating point comparisons
|
|
121
|
-
// Calculate total prices from unit prices and quantity
|
|
122
|
-
const calcPriceIncl = item.quantity * item.unitPriceTaxIncl;
|
|
123
|
-
const calcPriceExcl = item.quantity * item.unitPriceTaxExcl;
|
|
124
|
-
// Convert tax percentage to decimal rate
|
|
125
|
-
const taxRate = item.taxPercent / 100;
|
|
126
|
-
// Helper function to compare floating point numbers
|
|
127
|
-
const isClose = (a, b) => Math.abs(a - b) < EPSILON;
|
|
128
|
-
// Validate unit prices (tax-exclusive should equal tax-inclusive / (1 + taxRate))
|
|
129
|
-
const expectedUnitPriceExcl = item.unitPriceTaxIncl / (1 + taxRate);
|
|
130
|
-
if (!isClose(item.unitPriceTaxExcl, expectedUnitPriceExcl)) {
|
|
131
|
-
throw new Error("Tax inclusive/exclusive unit prices failed comparison.");
|
|
132
|
-
}
|
|
133
|
-
// Validate total prices
|
|
134
|
-
if (!isClose(calcPriceIncl, item.totalPriceTaxIncl)) {
|
|
135
|
-
throw new Error("Calculated unitPriceTaxIncl does not match input total");
|
|
136
|
-
}
|
|
137
|
-
if (!isClose(calcPriceExcl, item.totalPriceTaxExcl)) {
|
|
138
|
-
throw new Error("Calculated unitPriceTaxExcl does not match input total");
|
|
139
|
-
}
|
|
140
|
-
// Validate total prices using the tax rate
|
|
141
|
-
const expectedTotalPriceExcl = calcPriceIncl / (1 + taxRate);
|
|
142
|
-
if (!isClose(calcPriceExcl, expectedTotalPriceExcl)) {
|
|
143
|
-
throw new Error("Tax inclusive/exclusive totals failed comparison.");
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
const applyInvariants = (state, nextItem) => {
|
|
147
|
-
const EPSILON = 0.00001; // Small value for floating point comparisons
|
|
148
|
-
// Helper function to compare floating point numbers
|
|
149
|
-
const isClose = (a, b) => Math.abs(a - b) < EPSILON;
|
|
150
|
-
// Helper function to check if a value has changed significantly
|
|
151
|
-
const hasChanged = (oldValue, newValue) => !isClose(oldValue, newValue);
|
|
152
|
-
// Find the current state of this line item
|
|
153
|
-
const currentItem = state.lineItems.find(item => item.id === nextItem.id);
|
|
154
|
-
if (!currentItem) {
|
|
155
|
-
// New item, no comparison needed
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
const taxRate = nextItem.taxPercent / 100;
|
|
159
|
-
// Check if totalPriceTaxExcl was changed and update unitPriceTaxExcl accordingly
|
|
160
|
-
const expectedTotalPriceTaxExcl = nextItem.quantity * nextItem.unitPriceTaxExcl;
|
|
161
|
-
if (hasChanged(expectedTotalPriceTaxExcl, nextItem.totalPriceTaxExcl)) {
|
|
162
|
-
// Total was changed, update unit price
|
|
163
|
-
nextItem.unitPriceTaxExcl = nextItem.totalPriceTaxExcl / nextItem.quantity;
|
|
164
|
-
// Update tax-inclusive unit price to maintain tax relationship
|
|
165
|
-
nextItem.unitPriceTaxIncl = nextItem.unitPriceTaxExcl * (1 + taxRate);
|
|
166
|
-
// Update tax-inclusive total to maintain consistency
|
|
167
|
-
nextItem.totalPriceTaxIncl = nextItem.quantity * nextItem.unitPriceTaxIncl;
|
|
168
|
-
}
|
|
169
|
-
// Check if totalPriceTaxIncl was changed and update unitPriceTaxIncl accordingly
|
|
170
|
-
const expectedTotalPriceTaxIncl = nextItem.quantity * nextItem.unitPriceTaxIncl;
|
|
171
|
-
if (hasChanged(expectedTotalPriceTaxIncl, nextItem.totalPriceTaxIncl)) {
|
|
172
|
-
// Total was changed, update unit price
|
|
173
|
-
nextItem.unitPriceTaxIncl = nextItem.totalPriceTaxIncl / nextItem.quantity;
|
|
174
|
-
// Update tax-exclusive unit price to maintain tax relationship
|
|
175
|
-
nextItem.unitPriceTaxExcl = nextItem.unitPriceTaxIncl / (1 + taxRate);
|
|
176
|
-
// Update tax-exclusive total to maintain consistency
|
|
177
|
-
nextItem.totalPriceTaxExcl = nextItem.quantity * nextItem.unitPriceTaxExcl;
|
|
178
|
-
}
|
|
179
|
-
// Check if unitPriceTaxExcl was changed and update totals accordingly
|
|
180
|
-
const expectedUnitPriceTaxIncl = nextItem.unitPriceTaxExcl * (1 + taxRate);
|
|
181
|
-
if (hasChanged(expectedUnitPriceTaxIncl, nextItem.unitPriceTaxIncl)) {
|
|
182
|
-
// Unit price was changed, update tax-inclusive unit price and totals
|
|
183
|
-
nextItem.unitPriceTaxIncl = nextItem.unitPriceTaxExcl * (1 + taxRate);
|
|
184
|
-
nextItem.totalPriceTaxExcl = nextItem.quantity * nextItem.unitPriceTaxExcl;
|
|
185
|
-
nextItem.totalPriceTaxIncl = nextItem.quantity * nextItem.unitPriceTaxIncl;
|
|
186
|
-
}
|
|
187
|
-
// Check if unitPriceTaxIncl was changed and update totals accordingly
|
|
188
|
-
const expectedUnitPriceTaxExcl = nextItem.unitPriceTaxIncl / (1 + taxRate);
|
|
189
|
-
if (hasChanged(expectedUnitPriceTaxExcl, nextItem.unitPriceTaxExcl)) {
|
|
190
|
-
// Unit price was changed, update tax-exclusive unit price and totals
|
|
191
|
-
nextItem.unitPriceTaxExcl = nextItem.unitPriceTaxIncl / (1 + taxRate);
|
|
192
|
-
nextItem.totalPriceTaxExcl = nextItem.quantity * nextItem.unitPriceTaxExcl;
|
|
193
|
-
nextItem.totalPriceTaxIncl = nextItem.quantity * nextItem.unitPriceTaxIncl;
|
|
194
|
-
}
|
|
195
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This is a scaffold file meant for customization:
|
|
3
|
-
* - modify it by implementing the reducer functions
|
|
4
|
-
* - delete the file and run the code generator again to have it reset
|
|
5
|
-
*/
|
|
6
|
-
import type { InvoicePartiesOperations } from "../../gen/parties/operations.js";
|
|
7
|
-
export declare const reducer: InvoicePartiesOperations;
|
|
8
|
-
//# sourceMappingURL=parties.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parties.d.ts","sourceRoot":"","sources":["../../reducers/parties.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAShF,eAAO,MAAM,OAAO,EAAE,wBAwarB,CAAC"}
|
package/dist/reducers/parties.js
DELETED
|
@@ -1,266 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This is a scaffold file meant for customization:
|
|
3
|
-
* - modify it by implementing the reducer functions
|
|
4
|
-
* - delete the file and run the code generator again to have it reset
|
|
5
|
-
*/
|
|
6
|
-
function getStateValue(input, currentValue) {
|
|
7
|
-
return input === undefined ? currentValue : input;
|
|
8
|
-
}
|
|
9
|
-
export const reducer = {
|
|
10
|
-
editIssuerOperation(state, action, dispatch) {
|
|
11
|
-
try {
|
|
12
|
-
if ('address' in state.issuer && ('city' in action.input ||
|
|
13
|
-
'country' in action.input ||
|
|
14
|
-
'extendedAddress' in action.input ||
|
|
15
|
-
'postalCode' in action.input ||
|
|
16
|
-
'stateProvince' in action.input ||
|
|
17
|
-
'streetAddress' in action.input)) {
|
|
18
|
-
state.issuer.address = {
|
|
19
|
-
...state.issuer.address,
|
|
20
|
-
city: action.input.city !== undefined ? action.input.city : state.issuer.address?.city ?? null,
|
|
21
|
-
country: action.input.country !== undefined ? action.input.country : state.issuer.address?.country ?? null,
|
|
22
|
-
extendedAddress: action.input.extendedAddress !== undefined ? action.input.extendedAddress : state.issuer.address?.extendedAddress ?? null,
|
|
23
|
-
postalCode: action.input.postalCode !== undefined ? action.input.postalCode : state.issuer.address?.postalCode ?? null,
|
|
24
|
-
stateProvince: action.input.stateProvince !== undefined ? action.input.stateProvince : state.issuer.address?.stateProvince ?? null,
|
|
25
|
-
streetAddress: action.input.streetAddress !== undefined ? action.input.streetAddress : state.issuer.address?.streetAddress ?? null,
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
if ('contactInfo' in state.issuer && ('tel' in action.input ||
|
|
29
|
-
'email' in action.input)) {
|
|
30
|
-
state.issuer.contactInfo = {
|
|
31
|
-
...state.issuer.contactInfo,
|
|
32
|
-
tel: action.input.tel !== undefined ? action.input.tel : state.issuer.contactInfo?.tel ?? null,
|
|
33
|
-
email: action.input.email !== undefined ? action.input.email : state.issuer.contactInfo?.email ?? null,
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
if ('country' in action.input) {
|
|
37
|
-
state.issuer.country = action.input.country !== undefined ? action.input.country : state.issuer.country ?? null;
|
|
38
|
-
}
|
|
39
|
-
if ('id' in action.input) {
|
|
40
|
-
state.issuer.id = action.input.id ? { taxId: action.input.id } : null;
|
|
41
|
-
}
|
|
42
|
-
if ('name' in action.input) {
|
|
43
|
-
state.issuer.name = action.input.name !== undefined ? action.input.name : state.issuer.name ?? null;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
catch (e) {
|
|
47
|
-
console.error(e);
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
editIssuerBankOperation(state, action, dispatch) {
|
|
51
|
-
try {
|
|
52
|
-
if (!state.issuer.paymentRouting) {
|
|
53
|
-
state.issuer.paymentRouting = {
|
|
54
|
-
bank: null,
|
|
55
|
-
wallet: null,
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
state.issuer.paymentRouting.bank = {
|
|
59
|
-
ABA: getStateValue(action.input.ABA, state.issuer.paymentRouting.bank?.ABA ?? null),
|
|
60
|
-
BIC: getStateValue(action.input.BIC, state.issuer.paymentRouting.bank?.BIC ?? null),
|
|
61
|
-
SWIFT: getStateValue(action.input.SWIFT, state.issuer.paymentRouting.bank?.SWIFT ?? null),
|
|
62
|
-
accountNum: action.input.accountNum ??
|
|
63
|
-
state.issuer.paymentRouting.bank?.accountNum ??
|
|
64
|
-
"",
|
|
65
|
-
accountType: getStateValue(action.input.accountType, state.issuer.paymentRouting.bank?.accountType ?? null),
|
|
66
|
-
address: {
|
|
67
|
-
city: getStateValue(action.input.city, state.issuer.paymentRouting.bank?.address.city ?? null),
|
|
68
|
-
country: getStateValue(action.input.country, state.issuer.paymentRouting.bank?.address.country ?? null),
|
|
69
|
-
extendedAddress: getStateValue(action.input.extendedAddress, state.issuer.paymentRouting.bank?.address.extendedAddress ?? null),
|
|
70
|
-
postalCode: getStateValue(action.input.postalCode, state.issuer.paymentRouting.bank?.address.postalCode ?? null),
|
|
71
|
-
stateProvince: getStateValue(action.input.stateProvince, state.issuer.paymentRouting.bank?.address.stateProvince ?? null),
|
|
72
|
-
streetAddress: getStateValue(action.input.streetAddress, state.issuer.paymentRouting.bank?.address.streetAddress ?? null),
|
|
73
|
-
},
|
|
74
|
-
beneficiary: getStateValue(action.input.beneficiary, state.issuer.paymentRouting.bank?.beneficiary ?? null),
|
|
75
|
-
name: action.input.name ?? state.issuer.paymentRouting.bank?.name ?? "",
|
|
76
|
-
memo: getStateValue(action.input.memo, state.issuer.paymentRouting.bank?.memo ?? null),
|
|
77
|
-
intermediaryBank: {
|
|
78
|
-
ABA: getStateValue(action.input.ABAIntermediary, state.issuer.paymentRouting.bank?.intermediaryBank?.ABA ?? null),
|
|
79
|
-
BIC: getStateValue(action.input.BICIntermediary, state.issuer.paymentRouting.bank?.intermediaryBank?.BIC ?? null),
|
|
80
|
-
SWIFT: getStateValue(action.input.SWIFTIntermediary, state.issuer.paymentRouting.bank?.intermediaryBank?.SWIFT ?? null),
|
|
81
|
-
accountNum: action.input.accountNumIntermediary ??
|
|
82
|
-
state.issuer.paymentRouting.bank?.intermediaryBank?.accountNum ??
|
|
83
|
-
"",
|
|
84
|
-
accountType: getStateValue(action.input.accountTypeIntermediary, state.issuer.paymentRouting.bank?.intermediaryBank?.accountType ??
|
|
85
|
-
null),
|
|
86
|
-
address: {
|
|
87
|
-
city: getStateValue(action.input.cityIntermediary, state.issuer.paymentRouting.bank?.intermediaryBank?.address
|
|
88
|
-
.city ?? null),
|
|
89
|
-
country: getStateValue(action.input.countryIntermediary, state.issuer.paymentRouting.bank?.intermediaryBank?.address
|
|
90
|
-
.country ?? null),
|
|
91
|
-
extendedAddress: getStateValue(action.input.extendedAddressIntermediary, state.issuer.paymentRouting.bank?.intermediaryBank?.address
|
|
92
|
-
.extendedAddress ?? null),
|
|
93
|
-
postalCode: getStateValue(action.input.postalCodeIntermediary, state.issuer.paymentRouting.bank?.intermediaryBank?.address
|
|
94
|
-
.postalCode ?? null),
|
|
95
|
-
stateProvince: getStateValue(action.input.stateProvinceIntermediary, state.issuer.paymentRouting.bank?.intermediaryBank?.address
|
|
96
|
-
.stateProvince ?? null),
|
|
97
|
-
streetAddress: getStateValue(action.input.streetAddressIntermediary, state.issuer.paymentRouting.bank?.intermediaryBank?.address
|
|
98
|
-
.streetAddress ?? null),
|
|
99
|
-
},
|
|
100
|
-
beneficiary: getStateValue(action.input.beneficiaryIntermediary, state.issuer.paymentRouting.bank?.intermediaryBank?.beneficiary ??
|
|
101
|
-
null),
|
|
102
|
-
name: action.input.nameIntermediary ??
|
|
103
|
-
state.issuer.paymentRouting.bank?.intermediaryBank?.name ??
|
|
104
|
-
"",
|
|
105
|
-
memo: getStateValue(action.input.memoIntermediary, state.issuer.paymentRouting.bank?.intermediaryBank?.memo ?? null),
|
|
106
|
-
},
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
catch (e) {
|
|
110
|
-
console.error(e);
|
|
111
|
-
}
|
|
112
|
-
},
|
|
113
|
-
editIssuerWalletOperation(state, action, dispatch) {
|
|
114
|
-
try {
|
|
115
|
-
if (!state.issuer.paymentRouting) {
|
|
116
|
-
state.issuer.paymentRouting = {
|
|
117
|
-
bank: null,
|
|
118
|
-
wallet: null,
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
state.issuer.paymentRouting.wallet = {
|
|
122
|
-
address: action.input.address ??
|
|
123
|
-
state.issuer.paymentRouting.wallet?.address ??
|
|
124
|
-
null,
|
|
125
|
-
chainId: action.input.chainId ??
|
|
126
|
-
state.issuer.paymentRouting.wallet?.chainId ??
|
|
127
|
-
null,
|
|
128
|
-
chainName: action.input.chainName ??
|
|
129
|
-
state.issuer.paymentRouting.wallet?.chainName ??
|
|
130
|
-
null,
|
|
131
|
-
rpc: action.input.rpc ?? state.issuer.paymentRouting.wallet?.rpc ?? null,
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
catch (e) {
|
|
135
|
-
console.error(e);
|
|
136
|
-
}
|
|
137
|
-
},
|
|
138
|
-
editPayerOperation(state, action, dispatch) {
|
|
139
|
-
try {
|
|
140
|
-
if ('address' in state.payer && ('city' in action.input ||
|
|
141
|
-
'country' in action.input ||
|
|
142
|
-
'extendedAddress' in action.input ||
|
|
143
|
-
'postalCode' in action.input ||
|
|
144
|
-
'stateProvince' in action.input ||
|
|
145
|
-
'streetAddress' in action.input)) {
|
|
146
|
-
state.payer.address = {
|
|
147
|
-
...state.payer.address,
|
|
148
|
-
city: action.input.city !== undefined ? action.input.city : state.payer.address?.city ?? null,
|
|
149
|
-
country: action.input.country !== undefined ? action.input.country : state.payer.address?.country ?? null,
|
|
150
|
-
extendedAddress: action.input.extendedAddress !== undefined ? action.input.extendedAddress : state.payer.address?.extendedAddress ?? null,
|
|
151
|
-
postalCode: action.input.postalCode !== undefined ? action.input.postalCode : state.payer.address?.postalCode ?? null,
|
|
152
|
-
stateProvince: action.input.stateProvince !== undefined ? action.input.stateProvince : state.payer.address?.stateProvince ?? null,
|
|
153
|
-
streetAddress: action.input.streetAddress !== undefined ? action.input.streetAddress : state.payer.address?.streetAddress ?? null,
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
if ('contactInfo' in state.payer && ('tel' in action.input ||
|
|
157
|
-
'email' in action.input)) {
|
|
158
|
-
state.payer.contactInfo = {
|
|
159
|
-
...state.payer.contactInfo,
|
|
160
|
-
tel: action.input.tel !== undefined ? action.input.tel : state.payer.contactInfo?.tel ?? null,
|
|
161
|
-
email: action.input.email !== undefined ? action.input.email : state.payer.contactInfo?.email ?? null,
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
if ('country' in action.input) {
|
|
165
|
-
state.payer.country = action.input.country !== undefined ? action.input.country : state.payer.country ?? null;
|
|
166
|
-
}
|
|
167
|
-
if ('id' in action.input) {
|
|
168
|
-
state.payer.id = action.input.id ? { taxId: action.input.id } : null;
|
|
169
|
-
}
|
|
170
|
-
if ('name' in action.input) {
|
|
171
|
-
state.payer.name = action.input.name !== undefined ? action.input.name : state.payer.name ?? null;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
catch (e) {
|
|
175
|
-
console.error(e);
|
|
176
|
-
}
|
|
177
|
-
},
|
|
178
|
-
editPayerBankOperation(state, action, dispatch) {
|
|
179
|
-
try {
|
|
180
|
-
if (!state.payer.paymentRouting) {
|
|
181
|
-
state.payer.paymentRouting = {
|
|
182
|
-
bank: null,
|
|
183
|
-
wallet: null,
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
state.payer.paymentRouting.bank = {
|
|
187
|
-
ABA: getStateValue(action.input.ABA, state.payer.paymentRouting.bank?.ABA ?? null),
|
|
188
|
-
BIC: getStateValue(action.input.BIC, state.payer.paymentRouting.bank?.BIC ?? null),
|
|
189
|
-
SWIFT: getStateValue(action.input.SWIFT, state.payer.paymentRouting.bank?.SWIFT ?? null),
|
|
190
|
-
accountNum: action.input.accountNum ??
|
|
191
|
-
state.payer.paymentRouting.bank?.accountNum ??
|
|
192
|
-
"",
|
|
193
|
-
accountType: getStateValue(action.input.accountType, state.payer.paymentRouting.bank?.accountType ?? null),
|
|
194
|
-
address: {
|
|
195
|
-
city: getStateValue(action.input.city, state.payer.paymentRouting.bank?.address.city ?? null),
|
|
196
|
-
country: getStateValue(action.input.country, state.payer.paymentRouting.bank?.address.country ?? null),
|
|
197
|
-
extendedAddress: getStateValue(action.input.extendedAddress, state.payer.paymentRouting.bank?.address.extendedAddress ?? null),
|
|
198
|
-
postalCode: getStateValue(action.input.postalCode, state.payer.paymentRouting.bank?.address.postalCode ?? null),
|
|
199
|
-
stateProvince: getStateValue(action.input.stateProvince, state.payer.paymentRouting.bank?.address.stateProvince ?? null),
|
|
200
|
-
streetAddress: getStateValue(action.input.streetAddress, state.payer.paymentRouting.bank?.address.streetAddress ?? null),
|
|
201
|
-
},
|
|
202
|
-
beneficiary: getStateValue(action.input.beneficiary, state.payer.paymentRouting.bank?.beneficiary ?? null),
|
|
203
|
-
name: action.input.name ?? state.payer.paymentRouting.bank?.name ?? "",
|
|
204
|
-
memo: getStateValue(action.input.memo, state.payer.paymentRouting.bank?.memo ?? null),
|
|
205
|
-
intermediaryBank: {
|
|
206
|
-
ABA: getStateValue(action.input.ABAIntermediary, state.payer.paymentRouting.bank?.intermediaryBank?.ABA ?? null),
|
|
207
|
-
BIC: getStateValue(action.input.BICIntermediary, state.payer.paymentRouting.bank?.intermediaryBank?.BIC ?? null),
|
|
208
|
-
SWIFT: getStateValue(action.input.SWIFTIntermediary, state.payer.paymentRouting.bank?.intermediaryBank?.SWIFT ?? null),
|
|
209
|
-
accountNum: action.input.accountNumIntermediary ??
|
|
210
|
-
state.payer.paymentRouting.bank?.intermediaryBank?.accountNum ??
|
|
211
|
-
"",
|
|
212
|
-
accountType: getStateValue(action.input.accountTypeIntermediary, state.payer.paymentRouting.bank?.intermediaryBank?.accountType ??
|
|
213
|
-
null),
|
|
214
|
-
address: {
|
|
215
|
-
city: getStateValue(action.input.cityIntermediary, state.payer.paymentRouting.bank?.intermediaryBank?.address.city ??
|
|
216
|
-
null),
|
|
217
|
-
country: getStateValue(action.input.countryIntermediary, state.payer.paymentRouting.bank?.intermediaryBank?.address
|
|
218
|
-
.country ?? null),
|
|
219
|
-
extendedAddress: getStateValue(action.input.extendedAddressIntermediary, state.payer.paymentRouting.bank?.intermediaryBank?.address
|
|
220
|
-
.extendedAddress ?? null),
|
|
221
|
-
postalCode: getStateValue(action.input.postalCodeIntermediary, state.payer.paymentRouting.bank?.intermediaryBank?.address
|
|
222
|
-
.postalCode ?? null),
|
|
223
|
-
stateProvince: getStateValue(action.input.stateProvinceIntermediary, state.payer.paymentRouting.bank?.intermediaryBank?.address
|
|
224
|
-
.stateProvince ?? null),
|
|
225
|
-
streetAddress: getStateValue(action.input.streetAddressIntermediary, state.payer.paymentRouting.bank?.intermediaryBank?.address
|
|
226
|
-
.streetAddress ?? null),
|
|
227
|
-
},
|
|
228
|
-
beneficiary: getStateValue(action.input.beneficiaryIntermediary, state.payer.paymentRouting.bank?.intermediaryBank?.beneficiary ??
|
|
229
|
-
null),
|
|
230
|
-
name: action.input.nameIntermediary ??
|
|
231
|
-
state.payer.paymentRouting.bank?.intermediaryBank?.name ??
|
|
232
|
-
"",
|
|
233
|
-
memo: getStateValue(action.input.memoIntermediary, state.payer.paymentRouting.bank?.intermediaryBank?.memo ?? null),
|
|
234
|
-
},
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
catch (e) {
|
|
238
|
-
console.error(e);
|
|
239
|
-
}
|
|
240
|
-
},
|
|
241
|
-
editPayerWalletOperation(state, action, dispatch) {
|
|
242
|
-
try {
|
|
243
|
-
if (!state.payer.paymentRouting) {
|
|
244
|
-
state.payer.paymentRouting = {
|
|
245
|
-
bank: null,
|
|
246
|
-
wallet: null,
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
state.payer.paymentRouting.wallet = {
|
|
250
|
-
address: action.input.address ??
|
|
251
|
-
state.payer.paymentRouting.wallet?.address ??
|
|
252
|
-
null,
|
|
253
|
-
chainId: action.input.chainId ??
|
|
254
|
-
state.payer.paymentRouting.wallet?.chainId ??
|
|
255
|
-
null,
|
|
256
|
-
chainName: action.input.chainName ??
|
|
257
|
-
state.payer.paymentRouting.wallet?.chainName ??
|
|
258
|
-
null,
|
|
259
|
-
rpc: action.input.rpc ?? state.payer.paymentRouting.wallet?.rpc ?? null,
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
catch (e) {
|
|
263
|
-
console.error(e);
|
|
264
|
-
}
|
|
265
|
-
},
|
|
266
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This is a scaffold file meant for customization:
|
|
3
|
-
* - modify it by implementing the reducer functions
|
|
4
|
-
* - delete the file and run the code generator again to have it reset
|
|
5
|
-
*/
|
|
6
|
-
import type { InvoiceTransitionsOperations } from "../../gen/transitions/operations.js";
|
|
7
|
-
export declare const reducer: InvoiceTransitionsOperations;
|
|
8
|
-
//# sourceMappingURL=transitions.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transitions.d.ts","sourceRoot":"","sources":["../../reducers/transitions.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,qCAAqC,CAAC;AAGxF,eAAO,MAAM,OAAO,EAAE,4BA4IrB,CAAC"}
|
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This is a scaffold file meant for customization:
|
|
3
|
-
* - modify it by implementing the reducer functions
|
|
4
|
-
* - delete the file and run the code generator again to have it reset
|
|
5
|
-
*/
|
|
6
|
-
import { permittedTransitions } from "../../utils/statusTransitions.js";
|
|
7
|
-
export const reducer = {
|
|
8
|
-
cancelOperation(state, action, dispatch) {
|
|
9
|
-
if (permittedTransitions[state.status].includes('CANCELLED')) {
|
|
10
|
-
state.status = 'CANCELLED';
|
|
11
|
-
}
|
|
12
|
-
else {
|
|
13
|
-
throw new Error(`Invalid transition from ${state.status} to CANCELLED`);
|
|
14
|
-
}
|
|
15
|
-
},
|
|
16
|
-
issueOperation(state, action, dispatch) {
|
|
17
|
-
if (!action.input.invoiceNo || !action.input.dateIssued) {
|
|
18
|
-
throw new Error('Invoice number and date issued are required');
|
|
19
|
-
}
|
|
20
|
-
if (permittedTransitions[state.status].includes('ISSUED')) {
|
|
21
|
-
state.status = 'ISSUED';
|
|
22
|
-
state.invoiceNo = action.input.invoiceNo;
|
|
23
|
-
state.dateIssued = action.input.dateIssued;
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
throw new Error(`Invalid transition from ${state.status} to ISSUED`);
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
resetOperation(state, action, dispatch) {
|
|
30
|
-
if (permittedTransitions[state.status].includes('DRAFT')) {
|
|
31
|
-
state.status = 'DRAFT';
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
throw new Error(`Invalid transition from ${state.status} to DRAFT`);
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
rejectOperation(state, action, dispatch) {
|
|
38
|
-
if (!action.input.id || !action.input.reason) {
|
|
39
|
-
throw new Error('Reason, ID and final are required');
|
|
40
|
-
}
|
|
41
|
-
if (permittedTransitions[state.status].includes('REJECTED')) {
|
|
42
|
-
state.status = 'REJECTED';
|
|
43
|
-
const rejection = {
|
|
44
|
-
id: action.input.id,
|
|
45
|
-
reason: action.input.reason,
|
|
46
|
-
final: action.input.final,
|
|
47
|
-
};
|
|
48
|
-
state.rejections.push(rejection);
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
throw new Error(`Invalid transition from ${state.status} to REJECTED`);
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
acceptOperation(state, action, dispatch) {
|
|
55
|
-
if (!action.input.payAfter) {
|
|
56
|
-
throw new Error('Pay after is required');
|
|
57
|
-
}
|
|
58
|
-
if (permittedTransitions[state.status].includes('ACCEPTED')) {
|
|
59
|
-
state.status = 'ACCEPTED';
|
|
60
|
-
state.payAfter = action.input.payAfter;
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
throw new Error(`Invalid transition from ${state.status} to ACCEPTED`);
|
|
64
|
-
}
|
|
65
|
-
},
|
|
66
|
-
reinstateOperation(state, action, dispatch) {
|
|
67
|
-
const finalRejection = state.rejections.find(rejection => rejection.final === true);
|
|
68
|
-
if (finalRejection) {
|
|
69
|
-
throw new Error('Cannot reinstate an invoice that has been rejected');
|
|
70
|
-
}
|
|
71
|
-
if (permittedTransitions[state.status].includes('ISSUED')) {
|
|
72
|
-
state.status = 'ISSUED';
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
throw new Error(`Invalid transition from ${state.status} to ISSUED`);
|
|
76
|
-
}
|
|
77
|
-
},
|
|
78
|
-
schedulePaymentOperation(state, action, dispatch) {
|
|
79
|
-
if (!action.input.id || !action.input.processorRef) {
|
|
80
|
-
throw new Error('ID and processorRef are required');
|
|
81
|
-
}
|
|
82
|
-
if (permittedTransitions[state.status].includes('PAYMENTSCHEDULED')) {
|
|
83
|
-
state.status = 'PAYMENTSCHEDULED';
|
|
84
|
-
state.payments.push({
|
|
85
|
-
id: action.input.id,
|
|
86
|
-
processorRef: action.input.processorRef,
|
|
87
|
-
paymentDate: '',
|
|
88
|
-
txnRef: "",
|
|
89
|
-
confirmed: false,
|
|
90
|
-
issue: "",
|
|
91
|
-
amount: 0,
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
throw new Error(`Invalid transition from ${state.status} to PAYMENTSCHEDULED`);
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
|
-
reapprovePaymentOperation(state, action, dispatch) {
|
|
99
|
-
if (permittedTransitions[state.status].includes('ACCEPTED')) {
|
|
100
|
-
state.status = 'ACCEPTED';
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
throw new Error(`Invalid transition from ${state.status} to ACCEPTED`);
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
|
-
registerPaymentTxOperation(state, action, dispatch) {
|
|
107
|
-
if (permittedTransitions[state.status].includes('PAYMENTSENT')) {
|
|
108
|
-
state.status = 'PAYMENTSENT';
|
|
109
|
-
const payment = state.payments.find(payment => payment.id === action.input.id);
|
|
110
|
-
if (!payment)
|
|
111
|
-
throw new Error('Payment not found');
|
|
112
|
-
payment.txnRef = action.input.txRef;
|
|
113
|
-
payment.paymentDate = action.input.timestamp;
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
throw new Error(`Invalid transition from ${state.status} to PAYMENTSENT`);
|
|
117
|
-
}
|
|
118
|
-
},
|
|
119
|
-
reportPaymentIssueOperation(state, action, dispatch) {
|
|
120
|
-
if (!action.input.id || !action.input.issue) {
|
|
121
|
-
throw new Error('ID and issue are required');
|
|
122
|
-
}
|
|
123
|
-
if (permittedTransitions[state.status].includes('PAYMENTISSUE')) {
|
|
124
|
-
state.status = 'PAYMENTISSUE';
|
|
125
|
-
const payment = state.payments.find(payment => payment.id === action.input.id);
|
|
126
|
-
if (!payment)
|
|
127
|
-
throw new Error('Payment not found');
|
|
128
|
-
payment.issue = action.input.issue;
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
throw new Error(`Invalid transition from ${state.status} to PAYMENTISSUE`);
|
|
132
|
-
}
|
|
133
|
-
},
|
|
134
|
-
confirmPaymentOperation(state, action, dispatch) {
|
|
135
|
-
if (!action.input.id || !action.input.amount) {
|
|
136
|
-
throw new Error('ID and amount are required');
|
|
137
|
-
}
|
|
138
|
-
if (permittedTransitions[state.status].includes('PAYMENTRECEIVED')) {
|
|
139
|
-
state.status = 'PAYMENTRECEIVED';
|
|
140
|
-
const payment = state.payments.find(payment => payment.id === action.input.id);
|
|
141
|
-
if (!payment)
|
|
142
|
-
throw new Error('Payment not found');
|
|
143
|
-
payment.confirmed = true;
|
|
144
|
-
payment.amount = action.input.amount;
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
throw new Error(`Invalid transition from ${state.status} to PAYMENTRECEIVED`);
|
|
148
|
-
}
|
|
149
|
-
},
|
|
150
|
-
closePaymentOperation(state, action, dispatch) {
|
|
151
|
-
if (!action.input.closureReason) {
|
|
152
|
-
throw new Error('Closure reason is required');
|
|
153
|
-
}
|
|
154
|
-
if (permittedTransitions[state.status].includes('PAYMENTCLOSED')) {
|
|
155
|
-
state.status = 'PAYMENTCLOSED';
|
|
156
|
-
state.closureReason = action.input.closureReason;
|
|
157
|
-
}
|
|
158
|
-
else {
|
|
159
|
-
throw new Error(`Invalid transition from ${state.status} to PAYMENTCLOSED`);
|
|
160
|
-
}
|
|
161
|
-
},
|
|
162
|
-
};
|