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

47 lines
1.3 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') {
$order = Order::where('callback_no', $obj['id'])->first();
if (!$order) {
die('ERROR');
}
if ($order->status !== 0) {
die('SUCCESS');
}
$order->status = 1;
if (!$order->save()) {
die('ERROR');
}
die('SUCCESS');
}
}
public function stripeReturn (Request $request) {
header('Location:' . '/#/dashboard');
}
}