This commit is contained in:
root 2019-11-30 12:31:11 +08:00
parent 78673af6e8
commit dbd55e8380

View File

@ -68,27 +68,37 @@ class OrderController extends Controller
} catch (\Stripe\Error\SignatureVerification $e) { } catch (\Stripe\Error\SignatureVerification $e) {
abort(400); abort(400);
} }
switch ($event->type) {
$obj = $event->data->object; case 'source.chargeable':
if ($obj['status'] == 'chargeable') { $source = $event->data->object;
$trade_no = Redis::get($obj['id']); $charge = Charge::create([
if (!$trade_no) { 'amount' => $source['amount'],
abort(500, 'redis is not found trade no by stripe source id.'); 'currency' => $source['currency'],
} 'source' => $source['id'],
$order = Order::where('trade_no', $trade_no)->first(); ]);
if (!$order) { if ($charge['status'] == 'succeeded') {
abort(500, 'order is not found'); $trade_no = Redis::get($source['id']);
} if (!$trade_no) {
if ($order->status !== 0) { abort(500, 'redis is not found trade no by stripe source id.');
die('order is paid'); }
} $order = Order::where('trade_no', $trade_no)->first();
$order->status = 1; if (!$order) {
$order->callback_no = $obj['id']; abort(500, 'order is not found');
if (!$order->save()) { }
abort(500, 'fail'); if ($order->status !== 0) {
} die('order is paid');
Redis::del($obj['id']); }
die('success'); $order->status = 1;
$order->callback_no = $source['id'];
if (!$order->save()) {
abort(500, 'fail');
}
Redis::del($source['id']);
die('success');
}
break;
default:
abort(500, 'event is not support');
} }
} }