mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-01-26 03:04:05 +00:00
85 - Storing Charge Details with Orders
This commit is contained in:
@@ -9,12 +9,13 @@ class Order extends Model
|
||||
{
|
||||
protected $guarded = [];
|
||||
|
||||
public static function forTickets($tickets, $email, $amount)
|
||||
public static function forTickets($tickets, $email, $charge)
|
||||
{
|
||||
$order = self::create([
|
||||
'confirmation_number' => OrderConfirmationNumber::generate(),
|
||||
'email' => $email,
|
||||
'amount' => $amount,
|
||||
'amount' => $charge->amount(),
|
||||
'card_last_four' => $charge->cardLastFour(),
|
||||
]);
|
||||
|
||||
$order->tickets()->saveMany($tickets);
|
||||
|
||||
@@ -30,9 +30,9 @@ class Reservation
|
||||
|
||||
public function complete($paymentGateway, $paymentToken)
|
||||
{
|
||||
$paymentGateway->charge($this->totalCost(), $paymentToken);
|
||||
$charge = $paymentGateway->charge($this->totalCost(), $paymentToken);
|
||||
|
||||
return Order::forTickets($this->tickets(), $this->email(), $this->totalCost());
|
||||
return Order::forTickets($this->tickets(), $this->email(), $charge);
|
||||
}
|
||||
|
||||
public function cancel()
|
||||
|
||||
@@ -4,6 +4,7 @@ use App\Order;
|
||||
use App\Ticket;
|
||||
use App\Concert;
|
||||
use App\Reservation;
|
||||
use App\Billing\Charge;
|
||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
@@ -14,17 +15,17 @@ class OrderTest extends TestCase
|
||||
use DatabaseMigrations;
|
||||
|
||||
/** @test */
|
||||
function creating_an_order_from_tickets_email_and_amount()
|
||||
function creating_an_order_from_tickets_email_and_charge()
|
||||
{
|
||||
$concert = factory(Concert::class)->create()->addTickets(5);
|
||||
$this->assertEquals(5, $concert->ticketsRemaining());
|
||||
$tickets = factory(Ticket::class, 3)->create();
|
||||
$charge = new Charge(['amount' => 3600, 'card_last_four' => '1234']);
|
||||
|
||||
$order = Order::forTickets($concert->findTickets(3), 'john@example.com', 3600);
|
||||
$order = Order::forTickets($tickets, 'john@example.com', $charge);
|
||||
|
||||
$this->assertEquals('john@example.com', $order->email);
|
||||
$this->assertEquals(3, $order->ticketQuantity());
|
||||
$this->assertEquals(3600, $order->amount);
|
||||
$this->assertEquals(2, $concert->ticketsRemaining());
|
||||
$this->assertEquals('1234', $order->card_last_four);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
|
||||
Reference in New Issue
Block a user