Skip to content

Commit

Permalink
getGateway function fix and added transactions
Browse files Browse the repository at this point in the history
getGateway now returns the tail not the head in session variable. Failed
transactions are now stored in the transactions table.
  • Loading branch information
amostajo committed Nov 17, 2015
1 parent c3d3069 commit 4cc2188
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/LaravelShop.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 4cc2188

Please sign in to comment.