diff --git a/app/Http/Controllers/BillingController.php b/app/Http/Controllers/BillingController.php index f5e25c1..62e4ad0 100644 --- a/app/Http/Controllers/BillingController.php +++ b/app/Http/Controllers/BillingController.php @@ -24,8 +24,6 @@ class BillingController extends Controller } //Expects an array 'packs' representing the amount of each multiple of credits. - //This controller should have a way of figuring out how much of each pack - //was bought later. //Should validate that all amounts are positive integers in a reasonable range public function secret(Request $request) { $user = Auth::user(); @@ -34,14 +32,14 @@ class BillingController extends Controller + $request->packs[ 'credits1000' ]*101000; $transaction = new Transaction; - $transaction->credits = $request->packs['credits10']*10 + - $request->packs['credits50']*50 + - $request->packs['credits100']*100 + - $request->packs['credits1000']*1000; + $transaction->credits = $request->packs['credits10']*1000 + + $request->packs['credits50']*5000 + + $request->packs['credits100']*10000 + + $request->packs['credits1000']*100000; $transaction->credits_extra = - $request->packs['credits50']*5 + - $request->packs['credits100']*10 + - $request->packs['credits1000']*150; + $request->packs['credits50']*500 + + $request->packs['credits100']*1000 + + $request->packs['credits1000']*15000; $transaction->user_id = $user->id; $transaction->charge = $amount; @@ -75,6 +73,7 @@ class BillingController extends Controller ]); } + //Adds correct credit amount to the charged user, precise to two decimal places public function chargeEvent(Request $request) { $event = \Stripe\Event::constructFrom($request->all()); $charge = $event->data->object; diff --git a/app/Http/Controllers/OrderController.php b/app/Http/Controllers/OrderController.php index 4057906..fd4ee38 100644 --- a/app/Http/Controllers/OrderController.php +++ b/app/Http/Controllers/OrderController.php @@ -10,7 +10,7 @@ use Illuminate\Support\Facades\Log; class OrderController extends Controller { - //THis should also reduce user's available credits + //This should also reduce user's available credits public function newOrder(Request $request) { $user = Auth::user(); $order = new Order; @@ -22,7 +22,11 @@ class OrderController extends Controller $order->note = $request->note ?: ''; $order->status = 'processing'; - $cost = ceil($order->quantity*$order->service->price/1000); + if (!$this->validateOrder($request)){ + abort(422); + } + + $cost = ceil($order->quantity*$order->service->price/100000); $user->credits = $user->credits - $cost; if ($cost > $user->credits) { abort(520, 'Insufficient Credits'); @@ -30,4 +34,15 @@ class OrderController extends Controller $user->save(); $order->save(); } + + // Should probably check for other things like service availability + public function validateOrder($order) { + $service = Service::find($order->service); + + if ($order->quantity < $service->minimum || + $order->quantity > $service->maximum) { + return false; + } + return true; + } } diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index b790b5c..fb04301 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -19,7 +19,7 @@ class DatabaseSeeder extends Seeder */ public function run() { - Stripe::setApiKey(env('STRIPE_SECRET')); + Stripe::setApiKey(config('services.stripe.secret')); User::create([ 'name' => 'test_user_unverified', 'email' => 'unverified@example.com', diff --git a/resources/js/panel/panel.vue b/resources/js/panel/panel.vue index 2edb207..1499fe5 100644 --- a/resources/js/panel/panel.vue +++ b/resources/js/panel/panel.vue @@ -4,7 +4,7 @@

Welcome, {{user.name}}!

-
wallet

Credits: {{user.credits}}

+
wallet

Credits: {{(user.credits/100).toLocaleString('en')}}

News and Announcements

We've just launched. Thanks for joining us.

diff --git a/resources/js/panel/service-pane.vue b/resources/js/panel/service-pane.vue index f0f88ab..c96b1ab 100644 --- a/resources/js/panel/service-pane.vue +++ b/resources/js/panel/service-pane.vue @@ -2,7 +2,7 @@

{{site.charAt(0).toUpperCase() + site.slice(1)}}

    -
  • {{service.name}}{{service.price}}{{service.minimum.toLocaleString('en')}}{{service.maximum.toLocaleString('en')}} +
  • {{service.name}}{{(service.price/100).toLocaleString('en')}}{{service.minimum.toLocaleString('en')}}{{service.maximum.toLocaleString('en')}} diff --git a/resources/js/panel/services.vue b/resources/js/panel/services.vue index 0a872d9..3e141ae 100644 --- a/resources/js/panel/services.vue +++ b/resources/js/panel/services.vue @@ -5,7 +5,7 @@ Credits
-

{{credits.toLocaleString('en')}}

+

{{(credits/100).toLocaleString('en')}}

@@ -93,11 +94,17 @@ import Loading from '../icons/loading.vue' function select(service) { this.completed = false + if (this.amount < service.minimum){ + this.amount = service.minimum; + } + if (this.amount > service.maximum){ + this.amount = service.maximum; + } this.selected = service } function cost() { - return Math.ceil(this.selected.price * this.amount / 1000) + return (this.selected.price * this.amount / 100000).toFixed(2) } function buyService() { @@ -108,6 +115,10 @@ function buyService() { document.getElementById('overlay-error').textContent = 'Insuficient Credits' return + } else if (this.amount < this.selected.minimum || this.amount > this.selected.maximum) { + document.getElementById('overlay-error').textContent = + 'Invalid amount' + return } this.paying = true