Browse Source

Added payment validation

pull/6/head
Nafies Luthfi 9 years ago
parent
commit
56f4287566
  1. 6
      app/Http/Controllers/CartController.php
  2. 1
      resources/views/cart/partials/form-draft-detail.blade.php
  3. 36
      tests/Feature/TransactionEntryTest.php

6
app/Http/Controllers/CartController.php

@ -121,8 +121,12 @@ class CartController extends Controller
$this->validate($request, [
'customer.name' => 'required|string|max:30',
'customer.phone' => 'nullable|string|max:20',
'payment' => 'required|numeric',
'total' => 'required|numeric',
'payment' => 'required|numeric|min:' . $request->get('total') . '|max:' . ($request->get('total') + 100000),
'notes' => 'nullable|string|max:100',
], [
'payment.min' => 'Pembayaran minimal ' . formatRp($request->get('total')) . '.',
'payment.max' => 'Pembayaran terlalu besar.'
]);
$draft = $this->cart->updateDraftAttributes($draftKey, $request->only('customer', 'notes', 'payment'));

1
resources/views/cart/partials/form-draft-detail.blade.php

@ -5,6 +5,7 @@
<div class="col-md-6">{!! FormField::text('customer[phone]', ['label' => trans('transaction.customer_phone'), 'value' => $draft->customer['phone']]) !!}</div>
<div class="col-md-6">{!! FormField::price('payment', ['label' => trans('transaction.payment'), 'value' => $draft->payment, 'required' => true]) !!}</div>
</div>
{{ Form::hidden('total', $draft->getTotal()) }}
{!! FormField::textarea('notes', ['label' => trans('transaction.notes'), 'value' => $draft->notes]) !!}
{{ Form::submit(trans('transaction.proccess'), ['class' => 'btn btn-info']) }}
{{ Form::close() }}

36
tests/Feature/TransactionEntryTest.php

@ -214,6 +214,42 @@ class TransactionEntryTest extends BrowserKitTestCase
}
/** @test */
public function it_validates_proper_payment_amount()
{
$cart = new CartCollection();
$draft = $cart->add(new CashDraft());
$product1 = factory(Product::class)->create(['cash_price' => 100000]);
$product2 = factory(Product::class)->create(['cash_price' => 50000]);
$item1 = new Item($product1, 1);
$item2 = new Item($product2, 3);
// Add items to draft
$cart->addItemToDraft($draft->draftKey, $item1);
$cart->addItemToDraft($draft->draftKey, $item2);
$this->loginAsUser();
$this->visit(route('cart.show', $draft->draftKey));
$this->type('Nafies', 'customer[name]');
$this->type('-', 'customer[phone]');
$this->type('catatan', 'notes');
$this->type(100000, 'payment');
$this->press(trans('transaction.proccess'));
$this->dontSee(trans('transaction.confirm'));
$this->type(350001, 'payment');
$this->press(trans('transaction.proccess'));
$this->dontSee(trans('transaction.confirm'));
$this->type(350000, 'payment');
$this->press(trans('transaction.proccess'));
$this->see(trans('transaction.confirm'));
}
/** @test */
public function user_can_save_transaction_if_draft_is_completed()
{
$cart = new CartCollection();

Loading…
Cancel
Save