49 lines
1.4 KiB
PHP
49 lines
1.4 KiB
PHP
<?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;
|
|
});
|
|
}
|
|
}
|