Merge pull request #5265 from bagisto-europe/transactions
This commit is contained in:
commit
0afedafcc7
|
|
@ -123,17 +123,24 @@ class TransactionController extends Controller
|
|||
$transactionData['payment_method'] = $request->payment_method;
|
||||
$transactionData['invoice_id'] = $invoice->id;
|
||||
$transactionData['order_id'] = $invoice->order_id;
|
||||
$transactionData['amount'] = $request->amount;
|
||||
$transactionData['status'] = 'paid';
|
||||
$transactionData['data'] = json_encode($data);
|
||||
|
||||
$this->orderTransactionRepository->create($transactionData);
|
||||
|
||||
if ($invoice->base_grand_total == $request->amount) {
|
||||
$this->orderRepository->updateOrderStatus($order, 'processing');
|
||||
$update = $this->invoiceRepository->updateState($invoice, "paid");
|
||||
} else {
|
||||
$this->orderRepository->updateOrderStatus($order, 'pending');
|
||||
$update = $this->invoiceRepository->updateState($invoice, "pending");
|
||||
$transactionTotal = $this->orderTransactionRepository->where('invoice_id', $invoice->id)->sum('amount');
|
||||
|
||||
if ($transactionTotal >= $invoice->base_grand_total) {
|
||||
$shipments = $this->shipmentRepository->where('order_id', $invoice->order_id);
|
||||
|
||||
if ($shipments) {
|
||||
$this->orderRepository->updateOrderStatus($order, 'completed');
|
||||
} else {
|
||||
$this->orderRepository->updateOrderStatus($order, 'processing');
|
||||
}
|
||||
|
||||
$this->invoiceRepository->updateState($invoice, "paid");
|
||||
}
|
||||
|
||||
session()->flash('success', trans('admin::app.sales.transactions.response.transaction-saved'));
|
||||
|
|
@ -187,4 +194,4 @@ class TransactionController extends Controller
|
|||
|
||||
return $detailsData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddTransactionAmountColumn extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('order_transactions', function (Blueprint $table) {
|
||||
$table->decimal('amount', 12, 4)->default(0)->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('order_transactions', function (Blueprint $table) {
|
||||
$table->dropColumn('amount');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -273,6 +273,24 @@ class Order extends Model implements OrderContract
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if a invoice is still unpaid
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasOpenInvoice(): bool
|
||||
{
|
||||
$pendingInvoice = $this->invoices()->where('state', 'pending')
|
||||
->orWhere('state', 'pending_payment')
|
||||
->get();
|
||||
|
||||
if ($pendingInvoice) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if order can be canceled or not
|
||||
|
|
|
|||
|
|
@ -158,6 +158,8 @@ class ShipmentRepository extends Repository
|
|||
|
||||
if (isset($orderState)) {
|
||||
$this->orderRepository->updateOrderStatus($order, $orderState);
|
||||
} elseif ($order->hasOpenInvoice()) {
|
||||
$this->orderRepository->updateOrderStatus($order, 'pending_payment');
|
||||
} else {
|
||||
$this->orderRepository->updateOrderStatus($order);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue