-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed Offline Payment method for Customer
- Loading branch information
1 parent
994998d
commit 021b853
Showing
14 changed files
with
212 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
namespace App\Listeners\Incomes\Invoice; | ||
|
||
use App\Events\InvoicePaid; | ||
|
||
class Paid extends Listener | ||
{ | ||
|
||
/** | ||
* Handle the event. | ||
* | ||
* @param $event | ||
* @return void | ||
*/ | ||
public function handle(InvoicePaid $event) | ||
{ | ||
$invoice = $event->invoice; | ||
$request = $event->request; | ||
|
||
$request['invoice_id'] = $invoice->id; | ||
$request['account_id'] = setting('general.default_account'); | ||
|
||
if (!isset($request['amount'])) { | ||
$request['amount'] = $invoice->amount; | ||
} | ||
|
||
$request['currency_code'] = $invoice->currency_code; | ||
$request['currency_rate'] = $invoice->currency_rate; | ||
|
||
$request['paid_at'] = Date::parse('now')->format('Y-m-d'); | ||
|
||
if ($request['amount'] > $invoice->amount) { | ||
$message = trans('messages.error.added', ['type' => trans_choice('general.payment', 1)]); | ||
|
||
return response()->json([ | ||
'success' => false, | ||
'error' => $message, | ||
]); | ||
} elseif ($request['amount'] == $invoice->amount) { | ||
$invoice->invoice_status_code = 'paid'; | ||
} else { | ||
$invoice->invoice_status_code = 'partial'; | ||
} | ||
|
||
$invoice->save(); | ||
|
||
InvoicePayment::create($request->input()); | ||
|
||
$request['status_code'] = $invoice->invoice_status_code; | ||
|
||
$request['notify'] = 0; | ||
|
||
$desc_date = Date::parse($request['paid_at'])->format($this->getCompanyDateFormat()); | ||
|
||
$desc_amount = money((float) $request['amount'], $request['currency_code'], true)->format(); | ||
|
||
$request['description'] = $desc_date . ' ' . $desc_amount; | ||
|
||
InvoiceHistory::create($request->input()); | ||
|
||
return response()->json([ | ||
'success' => true, | ||
'error' => false, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 0 additions & 45 deletions
45
modules/OfflinePayment/Events/Handlers/OfflinePaymentConfirm.php
This file was deleted.
Oops, something went wrong.
54 changes: 54 additions & 0 deletions
54
modules/OfflinePayment/Http/Controllers/OfflinePayment.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace Modules\OfflinePayment\Http\Controllers; | ||
|
||
use App\Events\InvoicePaid; | ||
|
||
use Illuminate\Http\Response; | ||
use Illuminate\Routing\Controller; | ||
|
||
use App\Http\Requests\Customer\InvoicePayment as PaymentRequest; | ||
use App\Http\Requests\Customer\InvoiceConfirm as ConfirmRequest; | ||
|
||
use App\Models\Income\Invoice; | ||
|
||
class OfflinePayment extends Controller | ||
{ | ||
/** | ||
* Show the form for editing the specified resource. | ||
* @param Invoice | ||
* @param PaymentRequest | ||
* @return Response | ||
*/ | ||
public function show(Invoice $invoice, PaymentRequest $request) | ||
{ | ||
$gateway = []; | ||
|
||
$payment_methods = json_decode(setting('offlinepayment.methods'), true); | ||
|
||
foreach ($payment_methods as $payment_method) { | ||
if ($payment_method['code'] == $request['payment_method']) { | ||
$gateway = $payment_method; | ||
|
||
break; | ||
} | ||
} | ||
|
||
$html = view('offlinepayment::show', compact('gateway', 'invoice'))->render(); | ||
|
||
return response()->json([ | ||
'code' => $gateway['code'], | ||
'name' => $gateway['name'], | ||
'description' => $gateway['description'], | ||
'redirect' => false, | ||
'html' => $html, | ||
]); | ||
} | ||
|
||
public function confirm(Invoice $invoice, ConfirmRequest $request) | ||
{ | ||
$result = event(new InvoicePaid($invoice, $request)); | ||
|
||
return response()->json($result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Modules\OfflinePayment\Http\Requests; | ||
|
||
use App\Http\Requests\Request; | ||
|
||
class Show extends Request | ||
{ | ||
/** | ||
* Determine if the user is authorized to make this request. | ||
* | ||
* @return bool | ||
*/ | ||
public function authorize() | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array | ||
*/ | ||
public function rules() | ||
{ | ||
return [ | ||
'payment_method' => 'required|string', | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.