|
16 | 16 | use App\Models\Order;
|
17 | 17 | use App\Models\OrderProduct;
|
18 | 18 | use App\Models\OrderProductRefund;
|
| 19 | +use App\Models\OrderRefund; |
19 | 20 | use App\Models\Procurement;
|
20 | 21 | use App\Models\Role;
|
21 | 22 | use App\Models\Transaction;
|
@@ -474,6 +475,37 @@ public function handleProcurementTransaction(Procurement $procurement)
|
474 | 475 | }
|
475 | 476 | }
|
476 | 477 |
|
| 478 | + /** |
| 479 | + * Will record a transaction resulting from a paid order |
| 480 | + * |
| 481 | + * @return void |
| 482 | + */ |
| 483 | + public function createTransactionFormRefundedOrderShipping( Order $order, OrderRefund $orderRefund ) |
| 484 | + { |
| 485 | + /** |
| 486 | + * If the order shipping is greater than 0 |
| 487 | + * this means the shipping has been refunded |
| 488 | + */ |
| 489 | + if ( $orderRefund->shipping > 0 ) { |
| 490 | + $transactionAccount = $this->getTransactionAccountByCode( TransactionHistory::ACCOUNT_REFUNDS ); |
| 491 | + |
| 492 | + $transaction = new Transaction; |
| 493 | + $transaction->value = $orderRefund->shipping; |
| 494 | + $transaction->active = true; |
| 495 | + $transaction->operation = TransactionHistory::OPERATION_DEBIT; |
| 496 | + $transaction->author = $orderRefund->author; |
| 497 | + $transaction->order_id = $order->id; |
| 498 | + $transaction->order_refund_id = $orderRefund->id; |
| 499 | + $transaction->name = sprintf( __( 'Refund Shipping : %s' ), $order->code ); |
| 500 | + $transaction->id = 0; // this is not assigned to an existing transaction |
| 501 | + $transaction->account = $transactionAccount; |
| 502 | + $transaction->created_at = $orderRefund->created_at; |
| 503 | + $transaction->updated_at = $orderRefund->updated_at; |
| 504 | + |
| 505 | + $this->recordTransactionHistory( $transaction ); |
| 506 | + } |
| 507 | + } |
| 508 | + |
477 | 509 | /**
|
478 | 510 | * Will record a transaction for every refund performed
|
479 | 511 | *
|
@@ -616,6 +648,9 @@ public function handlePaymentStatus(string $previous, string $new, Order $order)
|
616 | 648 | }
|
617 | 649 | }
|
618 | 650 |
|
| 651 | + /** |
| 652 | + * @deprecated ? |
| 653 | + */ |
619 | 654 | public function recomputeTransactionHistory($rangeStarts = null, $rangeEnds = null)
|
620 | 655 | {
|
621 | 656 | /**
|
@@ -678,6 +713,7 @@ public function getTransactionAccountByCode($type): TransactionAccount
|
678 | 713 | /**
|
679 | 714 | * Will process refunded orders
|
680 | 715 | *
|
| 716 | + * @todo the method might no longer be in use. |
681 | 717 | * @param string $rangeStart
|
682 | 718 | * @param string $rangeEnds
|
683 | 719 | * @return void
|
|
0 commit comments