提交代码
This commit is contained in:
48
app/Http/Controllers/NotifyController.php
Normal file
48
app/Http/Controllers/NotifyController.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Events\UpgradePaid;
|
||||
use App\Models\Payment;
|
||||
use App\Models\UpgradePayment;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class NotifyController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function payment(Request $request)
|
||||
{
|
||||
$app = app('wechat.payment');
|
||||
|
||||
return $app->handlePaidNotify(function ($message, $fail) {
|
||||
$payment = Payment::where('trade_no', $message['out_trade_no'])->first();
|
||||
if ($payment->state != 'SUCCESS') {
|
||||
$payment->state = 'SUCCESS';
|
||||
$payment->transaction_id = $message['transaction_id'];
|
||||
$payment->paid_at = $message['time_end'];
|
||||
$payment->save();
|
||||
$payment->order->paid();
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
public function upgrade(Request $request)
|
||||
{
|
||||
$app = app('wechat.payment');
|
||||
return $app->handlePaidNotify(function ($message, $fail) {
|
||||
$UpgradePayment = UpgradePayment::where('trade_no', $message['out_trade_no'])->first();
|
||||
$UpgradePayment->state = 'SUCCESS';
|
||||
$UpgradePayment->transaction_id = $message['transaction_id'];
|
||||
$UpgradePayment->paid_at = $message['time_end'];
|
||||
$UpgradePayment->save();
|
||||
event(new UpgradePaid($UpgradePayment));
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user