forked from BantenITSolutions/oc-shop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.php
63 lines (49 loc) · 2.15 KB
/
routes.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
use DShoreman\Shop\Models\Order as ShopOrder;
use DShoreman\Shop\Models\Settings;
Route::group(['prefix' => 'shop'], function()
{
Route::post('order/payment/process', function()
{
$token = post('stripeToken');
$orderId = Session::get('orderId');
if (!$order = ShopOrder::find($orderId)) {
// Todo: Add some flash data and utilise the ajax stuff instead of redirect
return Redirect::to('shop/checkout/payment/'.$orderId);
}
$order->email = Input::get('stripeEmail');
$order->stripe_token = $token;
$order->billing_name = post('stripeBillingName');
$order->billing_street = post('stripeBillingAddressLine1');
$order->billing_town = post('stripeBillingAddressCity');
$order->billing_county = post('stripeBillingAddressState');
$order->billing_postcode = post('stripeBillingAddressZip');
$order->billing_country = post('stripeBillingAddressCountry');
$order->shipping_name = post('stripeShippingName');
$order->shipping_street = post('stripeShippingAddressLine1');
$order->shipping_town = post('stripeShippingAddressCity');
$order->shipping_county = post('stripeShippingAddressState');
$order->shipping_postcode = post('stripeShippingAddressZip');
$order->shipping_country = post('stripeShippingAddressCountry');
Settings::get('stripe_active_keys') == 'live'
? Stripe::setApiKey(Settings::get('stripe_live_sec_key'))
: Stripe::setApiKey(Settings::get('stripe_test_sec_key'));
try {
$charge = Stripe_Charge::create([
'amount' => $order->total * 100,
'currency' => 'gbp',
'card' => $token,
]);
$order->is_paid = true;
$order->save();
}
catch (Stripe_CardError $e)
{
$error = $e->getJsonBody()['error'];
Flash::error($error['message']);
$order->save();
Redirect::to('shop/checkout/payment/'.$orderId)->withInput();
}
return Redirect::to('shop/order/'.$orderId);
});
});