diff --git a/src/LaravelShop.php b/src/LaravelShop.php index 47abe88..60a587f 100644 --- a/src/LaravelShop.php +++ b/src/LaravelShop.php @@ -107,7 +107,10 @@ public static function setGateway($gatewayKey) */ public static function getGateway() { - return Session::get('shop.gateway')[0]; + $gateways = Session::get('shop.gateway'); + return $gateways && count($gateways) > 0 + ? $gateways[count($gateways) - 1] + : null; } /** @@ -180,12 +183,26 @@ public static function placeOrder($cart = null) if (isset($order)) { $order->statusCode = 'failed'; $order->save(); + // Create failed transaction + $order->placeTransaction( + static::$gatewayKey, + uniqid(), + static::$exception->getMessage(), + $order->statusCode + ); } } catch (GatewayException $e) { static::$exception = $e; if (isset($order)) { $order->statusCode = 'failed'; $order->save(); + // Create failed transaction + $order->placeTransaction( + static::$gatewayKey, + uniqid(), + static::$exception->getMessage(), + $order->statusCode + ); } } if ($order) {