@@ -10,6 +10,7 @@ class OrderState {
1010 final CantDo ? cantDo;
1111 final Dispute ? dispute;
1212 final Peer ? peer;
13+ final PaymentFailed ? paymentFailed;
1314 final _logger = Logger ();
1415
1516 OrderState ({
@@ -20,6 +21,7 @@ class OrderState {
2021 this .cantDo,
2122 this .dispute,
2223 this .peer,
24+ this .paymentFailed,
2325 });
2426
2527 factory OrderState .fromMostroMessage (MostroMessage message) {
@@ -31,12 +33,13 @@ class OrderState {
3133 cantDo: message.getPayload <CantDo >(),
3234 dispute: message.getPayload <Dispute >(),
3335 peer: message.getPayload <Peer >(),
36+ paymentFailed: message.getPayload <PaymentFailed >(),
3437 );
3538 }
3639
3740 @override
3841 String toString () =>
39- 'OrderState(status: $status , action: $action , order: $order , paymentRequest: $paymentRequest , cantDo: $cantDo , dispute: $dispute , peer: $peer )' ;
42+ 'OrderState(status: $status , action: $action , order: $order , paymentRequest: $paymentRequest , cantDo: $cantDo , dispute: $dispute , peer: $peer , paymentFailed: $ paymentFailed )' ;
4043
4144 @override
4245 bool operator == (Object other) =>
@@ -48,6 +51,7 @@ class OrderState {
4851 other.paymentRequest == paymentRequest &&
4952 other.cantDo == cantDo &&
5053 other.dispute == dispute &&
54+ other.paymentFailed == paymentFailed &&
5155 other.peer == peer;
5256
5357 @override
@@ -59,6 +63,7 @@ class OrderState {
5963 cantDo,
6064 dispute,
6165 peer,
66+ paymentFailed,
6267 );
6368
6469 OrderState copyWith ({
@@ -69,6 +74,7 @@ class OrderState {
6974 CantDo ? cantDo,
7075 Dispute ? dispute,
7176 Peer ? peer,
77+ PaymentFailed ? paymentFailed,
7278 }) {
7379 return OrderState (
7480 status: status ?? this .status,
@@ -78,6 +84,7 @@ class OrderState {
7884 cantDo: cantDo ?? this .cantDo,
7985 dispute: dispute ?? this .dispute,
8086 peer: peer ?? this .peer,
87+ paymentFailed: paymentFailed ?? this .paymentFailed,
8188 );
8289 }
8390
@@ -135,6 +142,7 @@ class OrderState {
135142 cantDo: message.getPayload <CantDo >() ?? cantDo,
136143 dispute: message.getPayload <Dispute >() ?? dispute,
137144 peer: newPeer,
145+ paymentFailed: message.getPayload <PaymentFailed >() ?? paymentFailed,
138146 );
139147
140148 _logger.i ('New state: ${newState .status } - ${newState .action }' );
@@ -154,7 +162,14 @@ class OrderState {
154162
155163 // Actions that should set status to waiting-buyer-invoice
156164 case Action .waitingBuyerInvoice:
165+ return Status .waitingBuyerInvoice;
166+
157167 case Action .addInvoice:
168+ // If current status is paymentFailed, maintain it for UI consistency
169+ // Otherwise, transition to waitingBuyerInvoice for normal flow
170+ if (status == Status .paymentFailed) {
171+ return Status .paymentFailed;
172+ }
158173 return Status .waitingBuyerInvoice;
159174
160175 // FIX: Cuando alguien toma una orden, debe cambiar el status inmediatamente
@@ -213,9 +228,12 @@ class OrderState {
213228 case Action .adminSettled:
214229 return Status .settledByAdmin;
215230
231+ // Actions that should set status to payment failed
232+ case Action .paymentFailed:
233+ return Status .paymentFailed;
234+
216235 // Informational actions that should preserve current status
217236 case Action .rateUser:
218- case Action .paymentFailed:
219237 case Action .invoiceUpdated:
220238 case Action .sendDm:
221239 case Action .tradePubkey:
@@ -274,6 +292,12 @@ class OrderState {
274292 Action .cancel,
275293 ],
276294 },
295+ Status .paymentFailed: {
296+ Action .paymentFailed: [
297+ // Only allow payment retry, no cancel or dispute during retrying
298+ Action .payInvoice,
299+ ],
300+ },
277301 Status .active: {
278302 Action .buyerTookOrder: [
279303 Action .cancel,
@@ -361,6 +385,12 @@ class OrderState {
361385 Action .release,
362386 ],
363387 },
388+ Status .settledHoldInvoice: {
389+ Action .addInvoice: [
390+ Action .addInvoice,
391+ Action .cancel,
392+ ],
393+ },
364394 },
365395 Role .buyer: {
366396 Status .pending: {
@@ -391,6 +421,13 @@ class OrderState {
391421 Action .cancel,
392422 ],
393423 },
424+ Status .paymentFailed: {
425+ Action .addInvoice: [
426+ // Only allow add invoice, no cancel or dispute during retrying
427+ Action .addInvoice,
428+ ],
429+ Action .paymentFailed: [],
430+ },
394431 Status .active: {
395432 Action .holdInvoicePaymentAccepted: [
396433 Action .fiatSent,
@@ -473,6 +510,12 @@ class OrderState {
473510 Action .cancel,
474511 ],
475512 },
513+ Status .settledHoldInvoice: {
514+ Action .addInvoice: [
515+ Action .addInvoice,
516+ Action .cancel,
517+ ],
518+ },
476519 },
477520 };
478521}
0 commit comments