v2board/app/Http/Controllers/Guest/OrderController.php

48 lines
1.4 KiB
PHP
Raw Normal View History

2019-10-22 23:39:48 +08:00
<?php
namespace App\Http\Controllers\Guest;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Order;
use Illuminate\Support\Facades\Log;
class OrderController extends Controller
{
public function stripeNotify (Request $request) {
Log::info('stripeNotifyData: ' . json_encode($request->input()));
2019-10-23 18:13:54 +08:00
\Stripe\Stripe::setApiKey(config('v2board.stripe_sk_live'));
2019-10-22 23:39:48 +08:00
try {
$event = \Stripe\Webhook::constructEvent(
file_get_contents('php://input'),
$_SERVER['HTTP_STRIPE_SIGNATURE'],
2019-10-23 18:13:54 +08:00
config('v2board.stripe_webhook_key')
2019-10-22 23:39:48 +08:00
);
} catch (\Stripe\Error\SignatureVerification $e) {
abort(400);
}
$obj = $event->data->object;
if ($obj['status'] == 'succeeded') {
2019-10-25 17:35:41 +08:00
$order = Order::where('callback_no', $obj['source']['id'])->first();
2019-10-22 23:39:48 +08:00
if (!$order) {
2019-10-25 17:36:38 +08:00
abort(500, 'ERROR');
2019-10-22 23:39:48 +08:00
}
if ($order->status !== 0) {
die('SUCCESS');
}
$order->status = 1;
if (!$order->save()) {
2019-10-25 17:36:38 +08:00
abort(500, 'ERROR');
2019-10-22 23:39:48 +08:00
}
die('SUCCESS');
}
}
public function stripeReturn (Request $request) {
2019-10-25 17:40:36 +08:00
Log::info('stripeReturnData: ' . json_encode($request->input()));
2019-10-22 23:39:48 +08:00
header('Location:' . '/#/dashboard');
}
}