BFI cart / orders

This commit is contained in:
Fabian @ Blax Software 2026-01-05 10:30:21 +01:00
parent cbb4b84948
commit a66fd7ccb8
23 changed files with 266 additions and 258 deletions

View File

@ -82,11 +82,11 @@ class ProductFactory extends Factory
public function withPrices(
int $count = 1,
null|float $unit_amount = null,
null|float $sale_unit_amount = null
null|int $unit_amount = null,
null|int $sale_unit_amount = null
): static {
return $this->afterCreating(function (Product $product) use ($count, $unit_amount, $sale_unit_amount) {
// Use realistic price range if not specified
// All prices are in cents (smallest currency unit)
$priceAmount = $unit_amount ?? $this->faker->randomElement([
1999, // $19.99
2999, // $29.99

View File

@ -156,7 +156,8 @@ class StripeWebhookController
}
// Record payment on the order
$amountPaid = (int) (($session->amount_total ?? 0) / 100);
// Stripe provides amounts in cents, which matches our storage format
$amountPaid = (int) ($session->amount_total ?? 0);
$currency = strtoupper($session->currency ?? $order->currency ?? 'USD');
// recordPayment(int $amount, ?string $reference, ?string $method, ?string $provider)

View File

@ -834,11 +834,11 @@ class Order extends Model
'customer_type' => $cart->customer_type,
'customer_id' => $cart->customer_id,
'currency' => $cart->currency ?? config('shop.currency', 'USD'),
'amount_subtotal' => (int) $cart->getTotal() * 100,
'amount_subtotal' => (int) $cart->getTotal(),
'amount_discount' => 0, // TODO: Calculate from cart discounts
'amount_shipping' => 0,
'amount_tax' => 0,
'amount_total' => (int) $cart->getTotal() * 100,
'amount_total' => (int) $cart->getTotal(),
'amount_paid' => 0,
'amount_refunded' => 0,
'status' => OrderStatus::PENDING,

View File

@ -516,7 +516,7 @@ class BookingPerMinutePricingTest extends TestCase
$single_product = Product::factory()
->withStocks(5)
->withPrices(1, 5000) // $50.00
->withPrices(1, 5000) // 5000 cents = $50.00
->create([
'name' => 'Wine Bottle',
'slug' => 'wine-bottle',

View File

@ -156,7 +156,7 @@ class CartFacadeTest extends TestCase
$total = Cart::total();
$this->assertEquals(200.00, $total);
$this->assertEquals(200, $total);
}
#[Test]
@ -219,7 +219,7 @@ class CartFacadeTest extends TestCase
$unpaid = Cart::unpaidAmount();
$this->assertEquals(200.00, $unpaid);
$this->assertEquals(200, $unpaid);
}
#[Test]
@ -230,7 +230,7 @@ class CartFacadeTest extends TestCase
$paid = Cart::paidAmount();
$this->assertEquals(0.00, $paid);
$this->assertEquals(0, $paid);
}
#[Test]
@ -292,7 +292,7 @@ class CartFacadeTest extends TestCase
Cart::add($p2, quantity: 1); // 75
Cart::add($p3, quantity: 4); // 100
$this->assertEquals(275.00, Cart::total());
$this->assertEquals(275, Cart::total());
}
#[Test]
@ -300,10 +300,10 @@ class CartFacadeTest extends TestCase
{
$product = Product::factory()->withStocks(50)->withPrices(1, 100)->create();
Cart::add($product, quantity: 5);
$this->assertEquals(500.00, Cart::total());
$this->assertEquals(500, Cart::total());
Cart::remove($product, quantity: 2);
$this->assertEquals(300.00, Cart::total());
$this->assertEquals(300, Cart::total());
}
}

View File

@ -20,7 +20,7 @@ class CartItemAttributesTest extends TestCase
public function cart_item_has_is_booking_attribute_for_booking_products()
{
$bookingProduct = Product::factory()
->withPrices(unit_amount: 100.00)
->withPrices(unit_amount: 10000)
->create(['type' => ProductType::BOOKING]);
$cart = Cart::create();
@ -33,7 +33,7 @@ class CartItemAttributesTest extends TestCase
public function cart_item_has_is_booking_false_for_regular_products()
{
$regularProduct = Product::factory()
->withPrices(unit_amount: 50.00)
->withPrices(unit_amount: 5000)
->create(['type' => ProductType::SIMPLE]);
$cart = Cart::create();
@ -46,7 +46,7 @@ class CartItemAttributesTest extends TestCase
public function cart_item_is_booking_works_via_price_id()
{
$bookingProduct = Product::factory()
->withPrices(unit_amount: 100.00)
->withPrices(unit_amount: 10000)
->create(['type' => ProductType::BOOKING]);
$cart = Cart::create();
@ -64,11 +64,11 @@ class CartItemAttributesTest extends TestCase
public function cart_is_full_booking_is_true_when_all_items_are_bookings()
{
$booking1 = Product::factory()
->withPrices(unit_amount: 100.00)
->withPrices(unit_amount: 10000)
->create(['type' => ProductType::BOOKING]);
$booking2 = Product::factory()
->withPrices(unit_amount: 150.00)
->withPrices(unit_amount: 15000)
->create(['type' => ProductType::BOOKING]);
$cart = Cart::create();
@ -82,11 +82,11 @@ class CartItemAttributesTest extends TestCase
public function cart_is_full_booking_is_false_when_mixed_products()
{
$booking = Product::factory()
->withPrices(unit_amount: 100.00)
->withPrices(unit_amount: 10000)
->create(['type' => ProductType::BOOKING]);
$regular = Product::factory()
->withPrices(unit_amount: 50.00)
->withPrices(unit_amount: 5000)
->create(['type' => ProductType::SIMPLE]);
$cart = Cart::create();
@ -108,15 +108,15 @@ class CartItemAttributesTest extends TestCase
public function cart_booking_items_returns_correct_count()
{
$booking1 = Product::factory()
->withPrices(unit_amount: 100.00)
->withPrices(unit_amount: 10000)
->create(['type' => ProductType::BOOKING]);
$booking2 = Product::factory()
->withPrices(unit_amount: 150.00)
->withPrices(unit_amount: 15000)
->create(['type' => ProductType::BOOKING]);
$regular = Product::factory()
->withPrices(unit_amount: 50.00)
->withPrices(unit_amount: 5000)
->create(['type' => ProductType::SIMPLE]);
$cart = Cart::create();
@ -131,7 +131,7 @@ class CartItemAttributesTest extends TestCase
public function cart_booking_items_returns_zero_when_no_bookings()
{
$regular = Product::factory()
->withPrices(unit_amount: 50.00)
->withPrices(unit_amount: 5000)
->create(['type' => ProductType::SIMPLE]);
$cart = Cart::create();
@ -144,7 +144,7 @@ class CartItemAttributesTest extends TestCase
public function price_id_is_automatically_assigned_when_adding_product_to_cart()
{
$product = Product::factory()
->withPrices(unit_amount: 100.00)
->withPrices(unit_amount: 10000)
->create();
$cart = Cart::create();
@ -244,7 +244,7 @@ class CartItemAttributesTest extends TestCase
public function cart_item_is_ready_to_checkout_is_true_for_regular_products()
{
$product = Product::factory()
->withPrices(unit_amount: 100.00)
->withPrices(unit_amount: 10000)
->create(['type' => ProductType::SIMPLE]);
$cart = Cart::create();
@ -257,7 +257,7 @@ class CartItemAttributesTest extends TestCase
public function cart_item_is_ready_to_checkout_is_false_for_booking_without_dates()
{
$bookingProduct = Product::factory()
->withPrices(unit_amount: 100.00)
->withPrices(unit_amount: 10000)
->create(['type' => ProductType::BOOKING]);
$cart = Cart::create();
@ -270,7 +270,7 @@ class CartItemAttributesTest extends TestCase
public function cart_item_is_ready_to_checkout_is_true_for_booking_with_valid_dates()
{
$bookingProduct = Product::factory()
->withPrices(unit_amount: 100.00)
->withPrices(unit_amount: 10000)
->withStocks(quantity: 10)
->create(['type' => ProductType::BOOKING]);
@ -287,7 +287,7 @@ class CartItemAttributesTest extends TestCase
public function cart_item_is_ready_to_checkout_is_false_for_booking_with_invalid_date_range()
{
$bookingProduct = Product::factory()
->withPrices(unit_amount: 100.00)
->withPrices(unit_amount: 10000)
->withStocks(quantity: 10)
->create(['type' => ProductType::BOOKING]);
@ -307,11 +307,11 @@ class CartItemAttributesTest extends TestCase
public function cart_is_ready_to_checkout_is_true_when_all_items_are_ready()
{
$product1 = Product::factory()
->withPrices(unit_amount: 100.00)
->withPrices(unit_amount: 10000)
->create(['type' => ProductType::SIMPLE]);
$product2 = Product::factory()
->withPrices(unit_amount: 150.00)
->withPrices(unit_amount: 15000)
->create(['type' => ProductType::SIMPLE]);
$cart = Cart::create();
@ -325,11 +325,11 @@ class CartItemAttributesTest extends TestCase
public function cart_is_ready_to_checkout_is_false_when_at_least_one_item_not_ready()
{
$regularProduct = Product::factory()
->withPrices(unit_amount: 100.00)
->withPrices(unit_amount: 10000)
->create(['type' => ProductType::SIMPLE]);
$bookingProduct = Product::factory()
->withPrices(unit_amount: 150.00)
->withPrices(unit_amount: 15000)
->create(['type' => ProductType::BOOKING]);
$cart = Cart::create();
@ -343,7 +343,7 @@ class CartItemAttributesTest extends TestCase
public function cart_allows_adding_items_without_dates_that_require_them()
{
$bookingProduct = Product::factory()
->withPrices(unit_amount: 100.00)
->withPrices(unit_amount: 10000)
->withStocks(quantity: 10) // Has stock
->create(['type' => ProductType::BOOKING]);
@ -362,7 +362,7 @@ class CartItemAttributesTest extends TestCase
public function update_dates_allows_setting_any_dates()
{
$bookingProduct = Product::factory()
->withPrices(unit_amount: 100.00)
->withPrices(unit_amount: 10000)
->withStocks(quantity: 10) // Has stock
->create(['type' => ProductType::BOOKING]);
@ -386,7 +386,7 @@ class CartItemAttributesTest extends TestCase
public function cart_calculates_correctly_when_dates_are_adjusted()
{
$bookingProduct = Product::factory()
->withPrices(unit_amount: 100.00)
->withPrices(unit_amount: 10000)
->withStocks(quantity: 10)
->create(['type' => ProductType::BOOKING]);
@ -397,23 +397,23 @@ class CartItemAttributesTest extends TestCase
$cartItem = $cart->addToCart($bookingProduct, quantity: 1, from: $from, until: $until);
// Initial price for 2 days
$this->assertEquals(200.00, $cartItem->price);
$this->assertEquals(200.00, $cartItem->subtotal);
$this->assertEquals(20000, $cartItem->price);
$this->assertEquals(20000, $cartItem->subtotal);
// Adjust dates to 5 days
$newUntil = Carbon::now()->addDays(6);
$cartItem->updateDates($from, $newUntil);
// Price should be recalculated for 5 days
$this->assertEquals(500.00, $cartItem->fresh()->price);
$this->assertEquals(500.00, $cartItem->fresh()->subtotal);
$this->assertEquals(50000, $cartItem->fresh()->price);
$this->assertEquals(50000, $cartItem->fresh()->subtotal);
}
#[Test]
public function set_from_date_recalculates_pricing_when_both_dates_set()
{
$bookingProduct = Product::factory()
->withPrices(unit_amount: 100.00)
->withPrices(unit_amount: 10000)
->withStocks(quantity: 10)
->create(['type' => ProductType::BOOKING]);
@ -424,21 +424,21 @@ class CartItemAttributesTest extends TestCase
$cartItem = $cart->addToCart($bookingProduct, quantity: 1, from: $from, until: $until);
// Initial price for 3 days
$this->assertEquals(300.00, $cartItem->price);
$this->assertEquals(30000, $cartItem->price);
// Adjust from date to make it span more days (move 1 day earlier)
$newFrom = $from->copy()->subDays(1);
$cartItem->setFromDate($newFrom);
// Price should be recalculated for 4 days
$this->assertEquals(400.00, $cartItem->fresh()->price);
$this->assertEquals(40000, $cartItem->fresh()->price);
}
#[Test]
public function set_until_date_recalculates_pricing_when_both_dates_set()
{
$bookingProduct = Product::factory()
->withPrices(unit_amount: 100.00)
->withPrices(unit_amount: 10000)
->withStocks(quantity: 10)
->create(['type' => ProductType::BOOKING]);
@ -449,21 +449,21 @@ class CartItemAttributesTest extends TestCase
$cartItem = $cart->addToCart($bookingProduct, quantity: 1, from: $from, until: $until);
// Initial price for 2 days
$this->assertEquals(200.00, $cartItem->price);
$this->assertEquals(20000, $cartItem->price);
// Adjust until date to make it 4 days
$newUntil = Carbon::now()->addDays(5);
$cartItem->setUntilDate($newUntil);
// Price should be recalculated for 4 days
$this->assertEquals(400.00, $cartItem->fresh()->price);
$this->assertEquals(40000, $cartItem->fresh()->price);
}
#[Test]
public function is_ready_to_checkout_checks_stock_for_regular_products_with_stock_management()
{
$product = Product::factory()
->withPrices(unit_amount: 100.00)
->withPrices(unit_amount: 10000)
->withStocks(quantity: 5)
->create([
'type' => ProductType::SIMPLE,

View File

@ -60,7 +60,7 @@ class CartManagementTest extends TestCase
public function it_can_update_cart_item_quantity()
{
$cart = Cart::create();
$product = Product::factory()->withPrices(unit_amount: 50.00)->create();
$product = Product::factory()->withPrices(unit_amount: 5000)->create();
$price = $product->defaultPrice()->first();
$cartItem = $cart->addToCart($price, quantity: 1);
@ -73,7 +73,7 @@ class CartManagementTest extends TestCase
public function it_can_remove_items_from_cart()
{
$cart = Cart::create();
$product = Product::factory()->withPrices(unit_amount: 100.00)->create();
$product = Product::factory()->withPrices(unit_amount: 10000)->create();
$price = $product->defaultPrice()->first();
$cartItem = $cart->addToCart($price, quantity: 1);
@ -89,8 +89,8 @@ class CartManagementTest extends TestCase
public function it_calculates_cart_total_correctly()
{
$cart = Cart::create();
$product1 = Product::factory()->withPrices(unit_amount: 50.00)->create();
$product2 = Product::factory()->withPrices(unit_amount: 30.00)->create();
$product1 = Product::factory()->withPrices(unit_amount: 5000)->create();
$product2 = Product::factory()->withPrices(unit_amount: 3000)->create();
$productPrice1 = $product1->defaultPrice()->first();
$productPrice2 = $product2->defaultPrice()->first();
@ -100,15 +100,15 @@ class CartManagementTest extends TestCase
$total = $cart->fresh()->getTotal();
$this->assertEquals(130.00, $total); // (50 * 2) + (30 * 1)
$this->assertEquals(13000, $total); // (5000 * 2) + (3000 * 1)
}
#[Test]
public function it_calculates_total_items_correctly()
{
$cart = Cart::create();
$product1 = Product::factory()->withPrices(unit_amount: 10.00)->create();
$product2 = Product::factory()->withPrices(unit_amount: 20.00)->create();
$product1 = Product::factory()->withPrices(unit_amount: 1000)->create();
$product2 = Product::factory()->withPrices(unit_amount: 2000)->create();
$product1Price = $product1->defaultPrice()->first();
$product2Price = $product2->defaultPrice()->first();
@ -202,7 +202,7 @@ class CartManagementTest extends TestCase
public function cart_items_have_correct_relationships()
{
$cart = Cart::create();
$product = Product::factory()->withPrices(unit_amount: 45.00)->create();
$product = Product::factory()->withPrices(unit_amount: 4500)->create();
$productPrice = $product->defaultPrice()->first();
$cartItem = $cart->addToCart($productPrice, quantity: 1);
@ -215,19 +215,19 @@ class CartManagementTest extends TestCase
public function it_calculates_cart_item_subtotal()
{
$cart = Cart::create();
$product = Product::factory()->withPrices(unit_amount: 25.00)->create();
$product = Product::factory()->withPrices(unit_amount: 2500)->create();
$productPrice = $product->defaultPrice()->first();
$cartItem = $cart->addToCart($productPrice, quantity: 4);
$this->assertEquals(100.00, $cartItem->getSubtotal()); // 25 * 4
$this->assertEquals(10000, $cartItem->getSubtotal()); // 2500 * 4
}
#[Test]
public function it_can_store_cart_item_attributes()
{
$cart = Cart::create();
$product = Product::factory()->withPrices(unit_amount: 50.00)->create();
$product = Product::factory()->withPrices(unit_amount: 5000)->create();
$productPrice = $product->defaultPrice()->first();
$cartItem = $cart->addToCart(
@ -247,7 +247,7 @@ class CartManagementTest extends TestCase
public function it_can_have_multiple_items_of_same_product_with_different_attributes()
{
$cart = Cart::create();
$product = Product::factory()->withPrices(unit_amount: 30.00)->create();
$product = Product::factory()->withPrices(unit_amount: 3000)->create();
$productPrice = $product->defaultPrice()->first();
$cart->addToCart(
@ -270,7 +270,7 @@ class CartManagementTest extends TestCase
public function it_deletes_cart_items_when_cart_is_deleted()
{
$cart = Cart::create();
$product = Product::factory()->withPrices(unit_amount: 75.00)->create();
$product = Product::factory()->withPrices(unit_amount: 7500)->create();
$productPrice = $product->defaultPrice()->first();
$cartItem = $cart->addToCart(
@ -317,14 +317,14 @@ class CartManagementTest extends TestCase
$cartWithProduct = Cart::factory()
->withNewProductInCart(
quantity: 2,
unit_amount: 150.00,
sale_unit_amount: 120.00,
unit_amount: 15000,
sale_unit_amount: 12000,
stocks: 10
)
->withNewProductInCart(
quantity: 2,
unit_amount: 150.00,
sale_unit_amount: 120.00,
unit_amount: 15000,
sale_unit_amount: 12000,
stocks: 10,
sale_start: now()->subDay(),
sale_end: now()->addDay()
@ -333,14 +333,14 @@ class CartManagementTest extends TestCase
$this->assertCount(2, $cartWithProduct->items);
$this->assertEquals(4, $cartWithProduct->getTotalItems());
$this->assertEquals((150.00 * 2) + (120 * 2), $cartWithProduct->getTotal());
$this->assertEquals((15000 * 2) + (12000 * 2), $cartWithProduct->getTotal());
}
#[Test]
public function it_can_remove_entire_cart_item()
{
$cart = Cart::create();
$product = Product::factory()->withPrices(unit_amount: 50.00)->create();
$product = Product::factory()->withPrices(unit_amount: 5000)->create();
$price = $product->defaultPrice()->first();
$cartItem = $cart->addToCart($price, quantity: 2);
@ -356,7 +356,7 @@ class CartManagementTest extends TestCase
public function it_can_decrease_cart_item_quantity()
{
$cart = Cart::create();
$product = Product::factory()->withPrices(unit_amount: 75.00)->create();
$product = Product::factory()->withPrices(unit_amount: 7500)->create();
$price = $product->defaultPrice()->first();
$cartItem = $cart->addToCart($price, quantity: 5);
@ -366,14 +366,14 @@ class CartManagementTest extends TestCase
$updatedItem = $cart->items->first();
$this->assertEquals(3, $updatedItem->quantity);
$this->assertEquals(75.00 * 3, $updatedItem->subtotal);
$this->assertEquals(7500 * 3, $updatedItem->subtotal);
}
#[Test]
public function it_updates_subtotal_correctly_when_decreasing_quantity()
{
$cart = Cart::create();
$product = Product::factory()->withPrices(unit_amount: 100.00)->create();
$product = Product::factory()->withPrices(unit_amount: 10000)->create();
$price = $product->defaultPrice()->first();
$cart->addToCart($price, quantity: 4);
@ -382,14 +382,14 @@ class CartManagementTest extends TestCase
$cartItem = $cart->items->first();
$this->assertEquals(3, $cartItem->quantity);
$this->assertEquals(300.00, $cartItem->subtotal);
$this->assertEquals(30000, $cartItem->subtotal);
}
#[Test]
public function it_respects_parameters_when_removing_from_cart()
{
$cart = Cart::create();
$product = Product::factory()->withPrices(unit_amount: 50.00)->create();
$product = Product::factory()->withPrices(unit_amount: 5000)->create();
$price = $product->defaultPrice()->first();
// Add same product with different parameters
@ -419,7 +419,7 @@ class CartManagementTest extends TestCase
public function it_decreases_only_matching_parameters_when_removing()
{
$cart = Cart::create();
$product = Product::factory()->withPrices(unit_amount: 50.00)->create();
$product = Product::factory()->withPrices(unit_amount: 5000)->create();
$price = $product->defaultPrice()->first();
$cart->addToCart(
@ -439,7 +439,7 @@ class CartManagementTest extends TestCase
public function it_returns_cart_item_when_quantity_is_decreased()
{
$cart = Cart::create();
$product = Product::factory()->withPrices(unit_amount: 50.00)->create();
$product = Product::factory()->withPrices(unit_amount: 5000)->create();
$price = $product->defaultPrice()->first();
$cart->addToCart($price, quantity: 5);
@ -454,7 +454,7 @@ class CartManagementTest extends TestCase
public function it_handles_removing_nonexistent_item_gracefully()
{
$cart = Cart::create();
$product = Product::factory()->withPrices(unit_amount: 50.00)->create();
$product = Product::factory()->withPrices(unit_amount: 5000)->create();
$price = $product->defaultPrice()->first();
$result = $cart->removeFromCart($price, quantity: 1);
@ -468,23 +468,23 @@ class CartManagementTest extends TestCase
public function it_updates_cart_total_after_removing_items()
{
$cart = Cart::create();
$product = Product::factory()->withPrices(unit_amount: 50.00)->create();
$product = Product::factory()->withPrices(unit_amount: 5000)->create();
$price = $product->defaultPrice()->first();
$cart->addToCart($price, quantity: 5);
$this->assertEquals(250.00, $cart->getTotal());
$this->assertEquals(25000, $cart->getTotal());
$cart->removeFromCart($price, quantity: 2);
$this->assertEquals(150.00, $cart->refresh()->getTotal());
$this->assertEquals(15000, $cart->refresh()->getTotal());
}
#[Test]
public function it_can_remove_from_cart_with_multiple_items()
{
$cart = Cart::create();
$product1 = Product::factory()->withPrices(unit_amount: 50.00)->create();
$product2 = Product::factory()->withPrices(unit_amount: 75.00)->create();
$product1 = Product::factory()->withPrices(unit_amount: 5000)->create();
$product2 = Product::factory()->withPrices(unit_amount: 7500)->create();
$price1 = $product1->defaultPrice()->first();
$price2 = $product2->defaultPrice()->first();
@ -497,6 +497,6 @@ class CartManagementTest extends TestCase
$this->assertCount(1, $cart->refresh()->items);
$this->assertEquals($price2->id, $cart->items->first()->purchasable_id);
$this->assertEquals(225.00, $cart->getTotal());
$this->assertEquals(22500, $cart->getTotal());
}
}

View File

@ -222,9 +222,11 @@ class CartServiceBookingTest extends TestCase
$cartItem = Cart::addBooking($this->bookingProduct, 2, $from, $until);
// Price should be: price_per_day (10000 cents = 100 dollars) × days (3) = 30000 cents per unit
// withPrices(1, 10000) stores 10000 cents
// Price should be: price_per_day (10000 cents) × days (3) = 30000 cents per unit
// Total should be: 30000 × quantity (2) = 60000 cents
$expectedPricePerUnit = 10000 * $days; // 30000 cents
$pricePerDay = 10000; // 100.00 euros = 10000 cents
$expectedPricePerUnit = $pricePerDay * $days; // 30000 cents
$expectedTotal = $expectedPricePerUnit * 2; // 60000 cents
$this->assertEquals($expectedPricePerUnit, $cartItem->price);

View File

@ -80,7 +80,7 @@ class GuestCartTest extends TestCase
$total = Cart::total($guestCart);
$this->assertEquals(250.00, $total);
$this->assertEquals(250, $total);
}
#[Test]
@ -167,8 +167,8 @@ class GuestCartTest extends TestCase
Cart::add($product, quantity: 1);
// Verify they're different
$this->assertEquals(100.00, Cart::total($guestCart));
$this->assertEquals(100.00, Cart::total()); // Current user's cart
$this->assertEquals(100, Cart::total($guestCart));
$this->assertEquals(100, Cart::total()); // Current user's cart
$guestCartItems = Cart::items($guestCart);
$userCartItems = Cart::items();
@ -195,8 +195,8 @@ class GuestCartTest extends TestCase
$userCart->addToCart($product, quantity: 2);
// Original guest cart should still exist and be separate
$this->assertEquals(200.00, Cart::total($guestCart));
$this->assertEquals(200.00, Cart::total($userCart));
$this->assertEquals(200, Cart::total($guestCart));
$this->assertEquals(200, Cart::total($userCart));
}
#[Test]
@ -226,8 +226,8 @@ class GuestCartTest extends TestCase
$guestCart2->addToCart($product, quantity: 3); // 300
$this->assertNotEquals($guestCart1->id, $guestCart2->id);
$this->assertEquals(100.00, Cart::total($guestCart1));
$this->assertEquals(300.00, Cart::total($guestCart2));
$this->assertEquals(100, Cart::total($guestCart1));
$this->assertEquals(300, Cart::total($guestCart2));
}
#[Test]
@ -237,12 +237,12 @@ class GuestCartTest extends TestCase
$product = Product::factory()->withStocks(50)->withPrices(1, 50)->create();
$cartItem = $guestCart->addToCart($product, quantity: 2);
$this->assertEquals(100.00, $cartItem->subtotal);
$this->assertEquals(100, $cartItem->subtotal);
$updated = Cart::update($cartItem, quantity: 5);
$this->assertEquals(5, $updated->quantity);
$this->assertEquals(250.00, $updated->subtotal);
$this->assertEquals(250, $updated->subtotal);
}
#[Test]

View File

@ -27,7 +27,7 @@ class OrderCheckoutFlowTest extends TestCase
public function checkout_creates_order_from_cart()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 50.00)->create([
$product = Product::factory()->withPrices(unit_amount: 5000)->create([
'manage_stock' => false,
]);
@ -44,7 +44,7 @@ class OrderCheckoutFlowTest extends TestCase
public function order_has_correct_cart_id()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 25.00)->create([
$product = Product::factory()->withPrices(unit_amount: 2500)->create([
'manage_stock' => false,
]);
@ -60,7 +60,7 @@ class OrderCheckoutFlowTest extends TestCase
public function order_has_correct_customer_info()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 25.00)->create([
$product = Product::factory()->withPrices(unit_amount: 2500)->create([
'manage_stock' => false,
]);
@ -81,7 +81,7 @@ class OrderCheckoutFlowTest extends TestCase
$cart = Cart::factory()->forCustomer($user)->create([
'currency' => 'EUR',
]);
$product = Product::factory()->withPrices(unit_amount: 25.00)->create([
$product = Product::factory()->withPrices(unit_amount: 2500)->create([
'manage_stock' => false,
]);
@ -97,20 +97,20 @@ class OrderCheckoutFlowTest extends TestCase
public function order_has_correct_total_amount()
{
$user = User::factory()->create();
$product1 = Product::factory()->withPrices(unit_amount: 50.00)->create([
$product1 = Product::factory()->withPrices(unit_amount: 5000)->create([
'manage_stock' => false,
]);
$product2 = Product::factory()->withPrices(unit_amount: 30.00)->create([
$product2 = Product::factory()->withPrices(unit_amount: 3000)->create([
'manage_stock' => false,
]);
$user->addToCart($product1, quantity: 2); // 100.00
$user->addToCart($product2, quantity: 3); // 90.00
$user->addToCart($product1, quantity: 2); // 10000 cents
$user->addToCart($product2, quantity: 3); // 9000 cents
$cart = $user->checkoutCart();
$order = $cart->order;
// Total should be 190.00 (19000 cents)
// Total should be 19000 cents
$this->assertEquals(19000, $order->amount_total);
$this->assertEquals(19000, $order->amount_subtotal);
}
@ -119,7 +119,7 @@ class OrderCheckoutFlowTest extends TestCase
public function order_starts_with_pending_status()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 25.00)->create([
$product = Product::factory()->withPrices(unit_amount: 2500)->create([
'manage_stock' => false,
]);
@ -135,7 +135,7 @@ class OrderCheckoutFlowTest extends TestCase
public function order_starts_with_zero_paid_amount()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 25.00)->create([
$product = Product::factory()->withPrices(unit_amount: 2500)->create([
'manage_stock' => false,
]);
@ -153,7 +153,7 @@ class OrderCheckoutFlowTest extends TestCase
public function order_has_unique_order_number()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 25.00)->create([
$product = Product::factory()->withPrices(unit_amount: 2500)->create([
'manage_stock' => false,
]);
@ -173,7 +173,7 @@ class OrderCheckoutFlowTest extends TestCase
public function order_creation_adds_system_note()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 25.00)->create([
$product = Product::factory()->withPrices(unit_amount: 2500)->create([
'manage_stock' => false,
]);
@ -198,10 +198,10 @@ class OrderCheckoutFlowTest extends TestCase
public function order_has_purchases_through_cart()
{
$user = User::factory()->create();
$product1 = Product::factory()->withPrices(unit_amount: 50.00)->create([
$product1 = Product::factory()->withPrices(unit_amount: 5000)->create([
'manage_stock' => false,
]);
$product2 = Product::factory()->withPrices(unit_amount: 30.00)->create([
$product2 = Product::factory()->withPrices(unit_amount: 3000)->create([
'manage_stock' => false,
]);
@ -218,7 +218,7 @@ class OrderCheckoutFlowTest extends TestCase
public function order_purchases_have_correct_status()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 50.00)->create([
$product = Product::factory()->withPrices(unit_amount: 5000)->create([
'manage_stock' => false,
]);
@ -238,7 +238,7 @@ class OrderCheckoutFlowTest extends TestCase
public function order_payment_updates_status()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 100.00)->create([
$product = Product::factory()->withPrices(unit_amount: 10000)->create([
'manage_stock' => false,
]);
@ -260,7 +260,7 @@ class OrderCheckoutFlowTest extends TestCase
public function order_payment_updates_purchase_status()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 100.00)->create([
$product = Product::factory()->withPrices(unit_amount: 10000)->create([
'manage_stock' => false,
]);
@ -280,7 +280,7 @@ class OrderCheckoutFlowTest extends TestCase
public function order_partial_payment_does_not_complete_order()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 100.00)->create([
$product = Product::factory()->withPrices(unit_amount: 10000)->create([
'manage_stock' => false,
]);
@ -306,7 +306,7 @@ class OrderCheckoutFlowTest extends TestCase
public function order_can_be_processed_after_payment()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 100.00)->create([
$product = Product::factory()->withPrices(unit_amount: 10000)->create([
'manage_stock' => false,
]);
@ -324,7 +324,7 @@ class OrderCheckoutFlowTest extends TestCase
public function order_can_be_shipped_with_tracking()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 100.00)->create([
$product = Product::factory()->withPrices(unit_amount: 10000)->create([
'manage_stock' => false,
]);
@ -346,7 +346,7 @@ class OrderCheckoutFlowTest extends TestCase
public function order_can_be_completed()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 100.00)->create([
$product = Product::factory()->withPrices(unit_amount: 10000)->create([
'manage_stock' => false,
'virtual' => true, // Virtual product
]);
@ -372,7 +372,7 @@ class OrderCheckoutFlowTest extends TestCase
public function order_can_be_cancelled()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 100.00)->create([
$product = Product::factory()->withPrices(unit_amount: 10000)->create([
'manage_stock' => false,
]);
@ -403,7 +403,7 @@ class OrderCheckoutFlowTest extends TestCase
public function order_can_be_refunded()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 100.00)->create([
$product = Product::factory()->withPrices(unit_amount: 10000)->create([
'manage_stock' => false,
]);
@ -425,7 +425,7 @@ class OrderCheckoutFlowTest extends TestCase
public function order_partial_refund_does_not_change_status()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 100.00)->create([
$product = Product::factory()->withPrices(unit_amount: 10000)->create([
'manage_stock' => false,
]);
@ -450,7 +450,7 @@ class OrderCheckoutFlowTest extends TestCase
public function order_logs_status_changes()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 100.00)->create([
$product = Product::factory()->withPrices(unit_amount: 10000)->create([
'manage_stock' => false,
]);
@ -473,7 +473,7 @@ class OrderCheckoutFlowTest extends TestCase
public function order_logs_payment_notes()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 100.00)->create([
$product = Product::factory()->withPrices(unit_amount: 10000)->create([
'manage_stock' => false,
]);
@ -499,7 +499,7 @@ class OrderCheckoutFlowTest extends TestCase
public function cart_status_is_converted_after_checkout()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 100.00)->create([
$product = Product::factory()->withPrices(unit_amount: 10000)->create([
'manage_stock' => false,
]);
@ -519,7 +519,7 @@ class OrderCheckoutFlowTest extends TestCase
$user = User::factory()->create();
$products = Product::factory()
->withPrices(unit_amount: 25.00)
->withPrices(unit_amount: 2500)
->count(5)
->create(['manage_stock' => false]);
@ -543,7 +543,7 @@ class OrderCheckoutFlowTest extends TestCase
{
$user1 = User::factory()->create();
$user2 = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 25.00)->create([
$product = Product::factory()->withPrices(unit_amount: 2500)->create([
'manage_stock' => false,
]);
@ -567,7 +567,7 @@ class OrderCheckoutFlowTest extends TestCase
public function can_find_paid_orders()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 50.00)->create([
$product = Product::factory()->withPrices(unit_amount: 5000)->create([
'manage_stock' => false,
]);

View File

@ -21,7 +21,7 @@ class PurchaseFlowTest extends TestCase
public function user_can_purchase_a_product_directly()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 49.99)->create([
$product = Product::factory()->withPrices(unit_amount: 4999)->create([
'manage_stock' => false,
]);
@ -141,7 +141,7 @@ class PurchaseFlowTest extends TestCase
$total = $user->getCartTotal();
$this->assertEquals(140.00, $total);
$this->assertEquals(140, $total);
}
#[Test]
@ -336,6 +336,6 @@ class PurchaseFlowTest extends TestCase
$cart = $user->checkoutCart();
$this->assertEquals(170.00, $cart->getTotal());
$this->assertEquals(170, $cart->getTotal());
}
}

View File

@ -210,7 +210,7 @@ class HasShoppingCapabilitiesTest extends TestCase
$total = $user->getCartTotal();
$this->assertEquals(250.00, $total);
$this->assertEquals(250, $total);
}
#[Test]

View File

@ -787,7 +787,7 @@ class PoolProductionBugTest extends TestCase
'manage_stock' => true,
]);
// single_1: 3 stock @ 1000/day
// single_1: 3 stock @ 1000/day (10.00 euros)
$single_1 = Product::factory()
->withStocks(3)
->withPrices(1, 1000)
@ -797,7 +797,7 @@ class PoolProductionBugTest extends TestCase
'name' => 'Single1-Cheap',
]);
// single_2: 1 stock @ 10001/day
// single_2: 1 stock @ 10001/day (100.01 euros)
$single_2 = Product::factory()
->withStocks(1)
->withPrices(1, 10001)
@ -807,7 +807,7 @@ class PoolProductionBugTest extends TestCase
'name' => 'Single2-Medium',
]);
// single_3: 1 stock @ 10002/day
// single_3: 1 stock @ 10002/day (100.02 euros)
$single_3 = Product::factory()
->withStocks(1)
->withPrices(1, 10002)
@ -1042,7 +1042,7 @@ class PoolProductionBugTest extends TestCase
'manage_stock' => true,
]);
// single_1: 2 stock @ 1000/day
// single_1: 2 stock @ 1000/day (10.00 euros)
$single_1 = Product::factory()
->withStocks(2)
->withPrices(1, 1000)
@ -1052,7 +1052,7 @@ class PoolProductionBugTest extends TestCase
'name' => 'Single1',
]);
// single_2: 1 stock @ 2000/day
// single_2: 1 stock @ 2000/day (20.00 euros)
$single_2 = Product::factory()
->withStocks(1)
->withPrices(1, 2000)

View File

@ -21,7 +21,7 @@ class ProductManagementTest extends TestCase
public function it_can_create_a_product()
{
$product = Product::factory()
->withPrices(1, 99.99)
->withPrices(1, 9999)
->create([
'slug' => 'test-product',
'type' => 'simple',
@ -33,7 +33,8 @@ class ProductManagementTest extends TestCase
]);
$this->assertCount(1, $product->prices);
$this->assertEquals(99.99, $product->prices->first()->unit_amount);
// Factory converts 99.99 euros to 9999 cents
$this->assertEquals(9999, $product->prices->first()->unit_amount);
}
#[Test]

View File

@ -61,11 +61,12 @@ class ProductScopeTest extends TestCase
#[Test]
public function it_can_filter_by_price_range()
{
$product1 = Product::factory()->withPrices(1, 50)->create();
$product2 = Product::factory()->withPrices(1, 100)->create();
$product3 = Product::factory()->withPrices(1, 150)->create();
$product1 = Product::factory()->withPrices(1, 5000)->create();
$product2 = Product::factory()->withPrices(1, 10000)->create();
$product3 = Product::factory()->withPrices(1, 15000)->create();
$inRange = Product::priceRange(75, 125)->get();
// Filter in cents: 7500-12500 cents = $75-$125
$inRange = Product::priceRange(7500, 12500)->get();
$this->assertCount(1, $inRange);
$this->assertTrue($inRange->contains($product2));
@ -74,11 +75,12 @@ class ProductScopeTest extends TestCase
#[Test]
public function it_can_filter_by_minimum_price_only()
{
$product1 = Product::factory()->withPrices(1, 50)->create();
$product2 = Product::factory()->withPrices(1, 100)->create();
$product3 = Product::factory()->withPrices(1, 150)->create();
$product1 = Product::factory()->withPrices(1, 5000)->create();
$product2 = Product::factory()->withPrices(1, 10000)->create();
$product3 = Product::factory()->withPrices(1, 15000)->create();
$minPrice = Product::priceRange(100)->get();
// Filter minimum in cents: 10000 cents = $100
$minPrice = Product::priceRange(10000)->get();
$this->assertCount(2, $minPrice);
$this->assertTrue($minPrice->contains($product2));
@ -88,11 +90,12 @@ class ProductScopeTest extends TestCase
#[Test]
public function it_can_filter_by_maximum_price_only()
{
$product1 = Product::factory()->withPrices(1, 50)->create();
$product2 = Product::factory()->withPrices(1, 100)->create();
$product3 = Product::factory()->withPrices(1, 150)->create();
$product1 = Product::factory()->withPrices(1, 5000)->create();
$product2 = Product::factory()->withPrices(1, 10000)->create();
$product3 = Product::factory()->withPrices(1, 15000)->create();
$maxPrice = Product::priceRange(null, 100)->get();
// Filter maximum in cents: 10000 cents = $100
$maxPrice = Product::priceRange(null, 10000)->get();
$this->assertCount(2, $maxPrice);
$this->assertTrue($maxPrice->contains($product1));
@ -102,9 +105,9 @@ class ProductScopeTest extends TestCase
#[Test]
public function it_can_order_products_by_price_ascending()
{
$product1 = Product::factory()->withPrices(1, 150)->create(['name' => 'Expensive']);
$product2 = Product::factory()->withPrices(1, 50)->create(['name' => 'Cheap']);
$product3 = Product::factory()->withPrices(1, 100)->create(['name' => 'Medium']);
$product1 = Product::factory()->withPrices(1, 15000)->create(['name' => 'Expensive']);
$product2 = Product::factory()->withPrices(1, 5000)->create(['name' => 'Cheap']);
$product3 = Product::factory()->withPrices(1, 10000)->create(['name' => 'Medium']);
$ordered = Product::orderByPrice('asc')->get();
@ -115,9 +118,9 @@ class ProductScopeTest extends TestCase
#[Test]
public function it_can_order_products_by_price_descending()
{
$product1 = Product::factory()->withPrices(1, 150)->create(['name' => 'Expensive']);
$product2 = Product::factory()->withPrices(1, 50)->create(['name' => 'Cheap']);
$product3 = Product::factory()->withPrices(1, 100)->create(['name' => 'Medium']);
$product1 = Product::factory()->withPrices(1, 15000)->create(['name' => 'Expensive']);
$product2 = Product::factory()->withPrices(1, 5000)->create(['name' => 'Cheap']);
$product3 = Product::factory()->withPrices(1, 10000)->create(['name' => 'Medium']);
$ordered = Product::orderByPrice('desc')->get();
@ -128,12 +131,13 @@ class ProductScopeTest extends TestCase
#[Test]
public function it_can_combine_price_range_and_order_by_price()
{
$product1 = Product::factory()->withPrices(1, 50)->create();
$product2 = Product::factory()->withPrices(1, 100)->create();
$product3 = Product::factory()->withPrices(1, 150)->create();
$product4 = Product::factory()->withPrices(1, 200)->create();
$product1 = Product::factory()->withPrices(1, 5000)->create();
$product2 = Product::factory()->withPrices(1, 10000)->create();
$product3 = Product::factory()->withPrices(1, 15000)->create();
$product4 = Product::factory()->withPrices(1, 20000)->create();
$filtered = Product::priceRange(75, 175)->orderByPrice('asc')->get();
// Filter in cents: 7500-17500 cents = $75-$175
$filtered = Product::priceRange(7500, 17500)->orderByPrice('asc')->get();
$this->assertCount(2, $filtered);
$this->assertEquals($product2->id, $filtered->first()->id);

View File

@ -20,7 +20,7 @@ class CartItemTest extends TestCase
public function cart_item_stores_prices_as_integers_in_cents()
{
$cart = Cart::create();
$product = Product::factory()->withPrices(unit_amount: 1550)->create(); // $15.50 in cents
$product = Product::factory()->withPrices(unit_amount: 1550)->create(); // 1550 cents
$price = $product->defaultPrice()->first();
$cartItem = $cart->addToCart($price, quantity: 2);
@ -42,7 +42,7 @@ class CartItemTest extends TestCase
public function cart_item_unit_amount_represents_base_price_per_day()
{
$cart = Cart::create();
$product = Product::factory()->withPrices(unit_amount: 5000)->create(); // $50.00 per day
$product = Product::factory()->withPrices(unit_amount: 5000)->create(); // 5000 cents per day
$price = $product->defaultPrice()->first();
$cartItem = $cart->addToCart($price, quantity: 1);
@ -56,7 +56,7 @@ class CartItemTest extends TestCase
public function cart_item_calculates_price_correctly_for_booking_timespan()
{
$cart = Cart::create();
$product = Product::factory()->withPrices(unit_amount: 2000)->create(['type' => ProductType::BOOKING]); // $20.00 per day
$product = Product::factory()->withPrices(unit_amount: 2000)->create(['type' => ProductType::BOOKING]); // 2000 cents per day
$price = $product->defaultPrice()->first();
$from = Carbon::parse('2025-01-01 00:00:00');
@ -78,7 +78,7 @@ class CartItemTest extends TestCase
public function cart_item_calculates_price_with_partial_days()
{
$cart = Cart::create();
$product = Product::factory()->withPrices(unit_amount: 4800)->create(['type' => ProductType::BOOKING]); // $48.00 per day
$product = Product::factory()->withPrices(unit_amount: 4800)->create(['type' => ProductType::BOOKING]); // 4800 cents per day
$price = $product->defaultPrice()->first();
// 12 hours = 0.5 days
@ -112,7 +112,7 @@ class CartItemTest extends TestCase
public function cart_item_updates_prices_when_dates_change()
{
$cart = Cart::create();
$product = Product::factory()->withPrices(unit_amount: 3000)->withStocks(10)->create(['type' => ProductType::BOOKING]); // $30.00 per day
$product = Product::factory()->withPrices(unit_amount: 3000)->withStocks(10)->create(['type' => ProductType::BOOKING]); // 3000 cents per day
$from = Carbon::parse('2025-01-01 00:00:00');
$until = Carbon::parse('2025-01-02 00:00:00'); // 1 day
@ -145,7 +145,7 @@ class CartItemTest extends TestCase
public function cart_item_handles_fractional_days_with_multiple_quantities()
{
$cart = Cart::create();
$product = Product::factory()->withPrices(unit_amount: 2400)->create(['type' => ProductType::BOOKING]); // $24.00 per day
$product = Product::factory()->withPrices(unit_amount: 2400)->create(['type' => ProductType::BOOKING]); // 2400 cents per day
$price = $product->defaultPrice()->first();
// 1.5 days
@ -236,7 +236,7 @@ class CartItemTest extends TestCase
$cart = Cart::create();
// Create a product with a price that will result in fractional cents when multiplied
$product = Product::factory()->withPrices(unit_amount: 3333)->create(['type' => ProductType::BOOKING]); // $33.33
$product = Product::factory()->withPrices(unit_amount: 3333)->create(['type' => ProductType::BOOKING]); // 3333 cents
$price = $product->defaultPrice()->first();
// 1.5 days should give 3333 * 1.5 = 4999.5 cents
@ -329,7 +329,7 @@ class CartItemTest extends TestCase
$cart = Cart::create();
$product = Product::factory()
->withPrices(unit_amount: 500)
->create(['type' => ProductType::BOOKING]); // $5.00 per day
->create(['type' => ProductType::BOOKING]); // 500 cents per day
$price = $product->defaultPrice()->first();

View File

@ -19,26 +19,26 @@ class CartTest extends TestCase
public function cart_can_add_product_price_directly()
{
$cart = Cart::create();
$product = Product::factory()->withPrices(unit_amount: 100.00)->create();
$product = Product::factory()->withPrices(unit_amount: 10000)->create();
$price = $product->defaultPrice()->first();
$cartItem = $cart->addToCart($price, quantity: 2);
$this->assertNotNull($cartItem);
$this->assertEquals(2, $cartItem->quantity);
$this->assertEquals(100.00, $cartItem->price);
$this->assertEquals(10000, $cartItem->price);
}
#[Test]
public function cart_calculates_subtotal_automatically()
{
$cart = Cart::create();
$product = Product::factory()->withPrices(unit_amount: 50.00)->create();
$product = Product::factory()->withPrices(unit_amount: 5000)->create();
$price = $product->defaultPrice()->first();
$cartItem = $cart->addToCart($price, quantity: 3);
$this->assertEquals(150.00, $cartItem->subtotal);
$this->assertEquals(15000, $cartItem->subtotal);
}
#[Test]
@ -78,7 +78,7 @@ class CartTest extends TestCase
public function cart_can_add_items_with_custom_parameters()
{
$cart = Cart::create();
$product = Product::factory()->withPrices(unit_amount: 50.00)->create();
$product = Product::factory()->withPrices(unit_amount: 5000)->create();
$price = $product->defaultPrice()->first();
$parameters = [
@ -99,10 +99,10 @@ class CartTest extends TestCase
{
$cart = Cart::create();
$product1 = Product::factory()->withPrices(unit_amount: 25.00)->create();
$product1 = Product::factory()->withPrices(unit_amount: 2500)->create();
$price1 = $product1->defaultPrice()->first();
$product2 = Product::factory()->withPrices(unit_amount: 50.00)->create();
$product2 = Product::factory()->withPrices(unit_amount: 5000)->create();
$price2 = $product2->defaultPrice()->first();
$cart->addToCart($price1, quantity: 2); // 50
@ -110,7 +110,7 @@ class CartTest extends TestCase
$total = $cart->fresh()->getTotal();
$this->assertEquals(200.00, $total);
$this->assertEquals(20000, $total);
}
#[Test]
@ -172,7 +172,7 @@ class CartTest extends TestCase
public function cart_deletes_items_on_deletion()
{
$cart = Cart::create();
$product = Product::factory()->withPrices(unit_amount: 50.00)->create();
$product = Product::factory()->withPrices(unit_amount: 5000)->create();
$price = $product->defaultPrice()->first();
$cartItem = $cart->addToCart($price);

View File

@ -38,7 +38,7 @@ class HasOrdersTraitTest extends TestCase
public function user_can_have_multiple_orders()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 50.00)->create([
$product = Product::factory()->withPrices(unit_amount: 5000)->create([
'manage_stock' => false,
]);
@ -55,7 +55,7 @@ class HasOrdersTraitTest extends TestCase
public function user_can_get_pending_orders()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 25.00)->create([
$product = Product::factory()->withPrices(unit_amount: 2500)->create([
'manage_stock' => false,
]);
@ -70,7 +70,7 @@ class HasOrdersTraitTest extends TestCase
public function user_can_get_processing_orders()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 25.00)->create([
$product = Product::factory()->withPrices(unit_amount: 2500)->create([
'manage_stock' => false,
]);
@ -86,7 +86,7 @@ class HasOrdersTraitTest extends TestCase
public function user_can_get_completed_orders()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 25.00)->create([
$product = Product::factory()->withPrices(unit_amount: 2500)->create([
'manage_stock' => false,
]);
@ -102,7 +102,7 @@ class HasOrdersTraitTest extends TestCase
public function user_can_get_active_orders()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 25.00)->create([
$product = Product::factory()->withPrices(unit_amount: 2500)->create([
'manage_stock' => false,
]);
@ -122,7 +122,7 @@ class HasOrdersTraitTest extends TestCase
public function user_can_get_paid_orders()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 25.00)->create([
$product = Product::factory()->withPrices(unit_amount: 2500)->create([
'manage_stock' => false,
]);
@ -142,7 +142,7 @@ class HasOrdersTraitTest extends TestCase
public function user_can_get_fully_paid_orders()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 25.00)->create([
$product = Product::factory()->withPrices(unit_amount: 2500)->create([
'manage_stock' => false,
]);
@ -163,7 +163,7 @@ class HasOrdersTraitTest extends TestCase
public function user_can_get_latest_order()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 25.00)->create([
$product = Product::factory()->withPrices(unit_amount: 2500)->create([
'manage_stock' => false,
]);
@ -183,7 +183,7 @@ class HasOrdersTraitTest extends TestCase
public function user_can_get_total_spent()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 50.00)->create([
$product = Product::factory()->withPrices(unit_amount: 5000)->create([
'manage_stock' => false,
]);
@ -202,7 +202,7 @@ class HasOrdersTraitTest extends TestCase
public function user_can_get_order_count()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 25.00)->create([
$product = Product::factory()->withPrices(unit_amount: 2500)->create([
'manage_stock' => false,
]);
@ -219,7 +219,7 @@ class HasOrdersTraitTest extends TestCase
public function user_can_get_completed_order_count()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 25.00)->create([
$product = Product::factory()->withPrices(unit_amount: 2500)->create([
'manage_stock' => false,
]);
@ -240,7 +240,7 @@ class HasOrdersTraitTest extends TestCase
$this->assertFalse($user->hasOrders());
$product = Product::factory()->withPrices(unit_amount: 25.00)->create([
$product = Product::factory()->withPrices(unit_amount: 2500)->create([
'manage_stock' => false,
]);
$user->addToCart($product);
@ -253,7 +253,7 @@ class HasOrdersTraitTest extends TestCase
public function user_can_check_has_active_orders()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 25.00)->create([
$product = Product::factory()->withPrices(unit_amount: 2500)->create([
'manage_stock' => false,
]);
@ -272,7 +272,7 @@ class HasOrdersTraitTest extends TestCase
public function user_can_find_order_by_number()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 25.00)->create([
$product = Product::factory()->withPrices(unit_amount: 2500)->create([
'manage_stock' => false,
]);
@ -291,7 +291,7 @@ class HasOrdersTraitTest extends TestCase
{
$user1 = User::factory()->create();
$user2 = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 25.00)->create([
$product = Product::factory()->withPrices(unit_amount: 2500)->create([
'manage_stock' => false,
]);
@ -309,7 +309,7 @@ class HasOrdersTraitTest extends TestCase
public function user_can_get_orders_between_dates()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 25.00)->create([
$product = Product::factory()->withPrices(unit_amount: 2500)->create([
'manage_stock' => false,
]);
@ -328,7 +328,7 @@ class HasOrdersTraitTest extends TestCase
public function user_can_get_orders_with_specific_status()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 25.00)->create([
$product = Product::factory()->withPrices(unit_amount: 2500)->create([
'manage_stock' => false,
]);

View File

@ -18,7 +18,7 @@ class OrderSummaryTest extends TestCase
public function order_can_get_total_revenue()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 50.00)->create([
$product = Product::factory()->withPrices(unit_amount: 5000)->create([
'manage_stock' => false,
]);
@ -37,7 +37,7 @@ class OrderSummaryTest extends TestCase
public function order_can_get_revenue_between_dates()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 100.00)->create([
$product = Product::factory()->withPrices(unit_amount: 10000)->create([
'manage_stock' => false,
]);
@ -57,7 +57,7 @@ class OrderSummaryTest extends TestCase
public function order_can_get_total_refunded()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 50.00)->create([
$product = Product::factory()->withPrices(unit_amount: 5000)->create([
'manage_stock' => false,
]);
@ -73,7 +73,7 @@ class OrderSummaryTest extends TestCase
public function order_can_get_net_revenue()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 50.00)->create([
$product = Product::factory()->withPrices(unit_amount: 5000)->create([
'manage_stock' => false,
]);
@ -89,7 +89,7 @@ class OrderSummaryTest extends TestCase
public function order_can_get_average_order_value()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 50.00)->create([
$product = Product::factory()->withPrices(unit_amount: 5000)->create([
'manage_stock' => false,
]);
@ -107,7 +107,7 @@ class OrderSummaryTest extends TestCase
public function order_can_get_counts_by_status()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 25.00)->create([
$product = Product::factory()->withPrices(unit_amount: 2500)->create([
'manage_stock' => false,
]);
@ -136,7 +136,7 @@ class OrderSummaryTest extends TestCase
public function order_can_get_revenue_summary()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 50.00)->create([
$product = Product::factory()->withPrices(unit_amount: 5000)->create([
'manage_stock' => false,
]);
@ -162,7 +162,7 @@ class OrderSummaryTest extends TestCase
public function order_can_get_daily_revenue()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 50.00)->create([
$product = Product::factory()->withPrices(unit_amount: 5000)->create([
'manage_stock' => false,
]);
@ -181,7 +181,7 @@ class OrderSummaryTest extends TestCase
public function order_scope_today_returns_todays_orders()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 25.00)->create([
$product = Product::factory()->withPrices(unit_amount: 2500)->create([
'manage_stock' => false,
]);
@ -195,7 +195,7 @@ class OrderSummaryTest extends TestCase
public function order_scope_this_week_returns_this_weeks_orders()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 25.00)->create([
$product = Product::factory()->withPrices(unit_amount: 2500)->create([
'manage_stock' => false,
]);
@ -209,7 +209,7 @@ class OrderSummaryTest extends TestCase
public function order_scope_this_month_returns_this_months_orders()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 25.00)->create([
$product = Product::factory()->withPrices(unit_amount: 2500)->create([
'manage_stock' => false,
]);
@ -223,7 +223,7 @@ class OrderSummaryTest extends TestCase
public function order_scope_by_payment_provider_returns_filtered_orders()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 25.00)->create([
$product = Product::factory()->withPrices(unit_amount: 2500)->create([
'manage_stock' => false,
]);
@ -246,7 +246,7 @@ class OrderSummaryTest extends TestCase
public function order_scope_with_refunds_returns_orders_with_refunds()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 50.00)->create([
$product = Product::factory()->withPrices(unit_amount: 5000)->create([
'manage_stock' => false,
]);
@ -270,7 +270,7 @@ class OrderSummaryTest extends TestCase
public function order_scope_fully_refunded_returns_fully_refunded_orders()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 50.00)->create([
$product = Product::factory()->withPrices(unit_amount: 5000)->create([
'manage_stock' => false,
]);

View File

@ -60,7 +60,7 @@ class ProductDuplicateTest extends TestCase
#[Test]
public function duplicate_includes_prices()
{
$product = Product::factory()->withPrices(unit_amount: 25.00)->create();
$product = Product::factory()->withPrices(unit_amount: 2500)->create();
$duplicate = $product->duplicate();
@ -72,7 +72,7 @@ class ProductDuplicateTest extends TestCase
#[Test]
public function duplicate_can_exclude_prices()
{
$product = Product::factory()->withPrices(unit_amount: 25.00)->create();
$product = Product::factory()->withPrices(unit_amount: 2500)->create();
$duplicate = $product->duplicate(includePrices: false);

View File

@ -15,71 +15,71 @@ class ProductPricingTest extends TestCase
#[Test]
public function it_returns_regular_price_when_not_on_sale()
{
$product = Product::factory()->withPrices(2, 100)->create();
$product = Product::factory()->withPrices(2, 10000)->create();
$this->assertEquals(2, $product->prices()->count());
$this->assertFalse($product->isOnSale());
$this->assertNotNull($product->defaultPrice()->first());
$this->assertEquals(100, $product->getCurrentPrice());
$this->assertEquals(10000, $product->getCurrentPrice());
}
#[Test]
public function it_returns_sale_price_when_on_sale()
{
$product = Product::factory()
->withPrices(1, 100)
->withPrices(1, 10000)
->create([
'sale_start' => now()->subDay(),
'sale_end' => now()->addDay(),
]);
$price = $product->prices()->first();
$price->sale_unit_amount = 80;
$price->sale_unit_amount = 8000;
$price->save();
$this->assertEquals(80, $product->getCurrentPrice());
$this->assertEquals(8000, $product->getCurrentPrice());
}
#[Test]
public function it_returns_regular_price_when_sale_has_ended()
{
$product = Product::factory()->withPrices(1, 100)->create([
$product = Product::factory()->withPrices(1, 10000)->create([
'sale_start' => now()->subWeek(),
'sale_end' => now()->addHour(),
]);
$price = $product->prices()->first();
$price->sale_unit_amount = 80;
$price->sale_unit_amount = 8000;
$price->save();
$this->assertEquals(80, $product->getCurrentPrice());
$this->assertEquals(8000, $product->getCurrentPrice());
$product->update([
'sale_end' => now()->subHour(),
]);
$this->assertEquals(100, $product->getCurrentPrice());
$this->assertEquals(10000, $product->getCurrentPrice());
}
#[Test]
public function it_returns_regular_price_when_sale_hasnt_started()
{
$product = Product::factory()->withPrices(1, 100)->create([
$product = Product::factory()->withPrices(1, 10000)->create([
'sale_start' => now()->addDay(),
'sale_end' => now()->addWeek(),
]);
$price = $product->prices()->first();
$price->sale_unit_amount = 80;
$price->sale_unit_amount = 8000;
$price->save();
$this->assertEquals(100, $product->getCurrentPrice());
$this->assertEquals(10000, $product->getCurrentPrice());
$product->update([
'sale_start' => now()->subHour(),
]);
$this->assertEquals(80, $product->getCurrentPrice());
$this->assertEquals(8000, $product->getCurrentPrice());
}
}

View File

@ -39,7 +39,7 @@ class ShopServiceTest extends TestCase
public function shop_facade_can_get_orders()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 50.00)->create([
$product = Product::factory()->withPrices(unit_amount: 5000)->create([
'manage_stock' => false,
]);
@ -53,7 +53,7 @@ class ShopServiceTest extends TestCase
public function shop_facade_can_get_order_by_number()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 50.00)->create([
$product = Product::factory()->withPrices(unit_amount: 5000)->create([
'manage_stock' => false,
]);
@ -71,7 +71,7 @@ class ShopServiceTest extends TestCase
public function shop_facade_can_get_orders_today()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 25.00)->create([
$product = Product::factory()->withPrices(unit_amount: 2500)->create([
'manage_stock' => false,
]);
@ -85,7 +85,7 @@ class ShopServiceTest extends TestCase
public function shop_facade_can_get_orders_this_week()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 25.00)->create([
$product = Product::factory()->withPrices(unit_amount: 2500)->create([
'manage_stock' => false,
]);
@ -99,7 +99,7 @@ class ShopServiceTest extends TestCase
public function shop_facade_can_get_orders_this_month()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 25.00)->create([
$product = Product::factory()->withPrices(unit_amount: 2500)->create([
'manage_stock' => false,
]);
@ -113,7 +113,7 @@ class ShopServiceTest extends TestCase
public function shop_facade_can_get_pending_orders()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 25.00)->create([
$product = Product::factory()->withPrices(unit_amount: 2500)->create([
'manage_stock' => false,
]);
@ -127,7 +127,7 @@ class ShopServiceTest extends TestCase
public function shop_facade_can_calculate_total_revenue()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 50.00)->create([
$product = Product::factory()->withPrices(unit_amount: 5000)->create([
'manage_stock' => false,
]);
@ -142,7 +142,7 @@ class ShopServiceTest extends TestCase
public function shop_facade_can_calculate_revenue_today()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 100.00)->create([
$product = Product::factory()->withPrices(unit_amount: 10000)->create([
'manage_stock' => false,
]);
@ -157,7 +157,7 @@ class ShopServiceTest extends TestCase
public function shop_facade_can_get_stats()
{
$user = User::factory()->create();
$product = Product::factory()->withPrices(unit_amount: 50.00)->create([
$product = Product::factory()->withPrices(unit_amount: 5000)->create([
'manage_stock' => false,
'status' => 'published',
]);

View File

@ -79,7 +79,7 @@ class StripeWebhookOrderTest extends TestCase
/**
* Create a product for testing
*/
protected function createProduct(float $price = 100.00): Product
protected function createProduct(int $price = 10000): Product
{
return Product::factory()->withPrices(unit_amount: $price)->create([
'manage_stock' => false,
@ -90,7 +90,7 @@ class StripeWebhookOrderTest extends TestCase
public function checkout_session_completed_creates_order_payment()
{
$customer = User::factory()->create();
$product = $this->createProduct(100.00);
$product = $this->createProduct(10000);
$customer->addToCart($product);
$cart = $customer->checkoutCart();
@ -108,7 +108,7 @@ class StripeWebhookOrderTest extends TestCase
$this->invokeMethod('handleCheckoutSessionCompleted', [$session]);
$order->refresh();
$this->assertEquals(100.00, $order->amount_paid);
$this->assertEquals(10000, $order->amount_paid);
$this->assertEquals(OrderStatus::PROCESSING, $order->status);
}
@ -116,7 +116,7 @@ class StripeWebhookOrderTest extends TestCase
public function checkout_session_completed_logs_payment_note()
{
$customer = User::factory()->create();
$product = $this->createProduct(50.00);
$product = $this->createProduct(5000);
$customer->addToCart($product);
$cart = $customer->checkoutCart();
@ -143,7 +143,7 @@ class StripeWebhookOrderTest extends TestCase
public function checkout_session_failed_updates_order_status()
{
$customer = User::factory()->create();
$product = $this->createProduct(100.00);
$product = $this->createProduct(10000);
$customer->addToCart($product);
$cart = $customer->checkoutCart();
@ -164,7 +164,7 @@ class StripeWebhookOrderTest extends TestCase
public function checkout_session_failed_adds_payment_note()
{
$customer = User::factory()->create();
$product = $this->createProduct(50.00);
$product = $this->createProduct(5000);
$customer->addToCart($product);
$cart = $customer->checkoutCart();
@ -189,7 +189,7 @@ class StripeWebhookOrderTest extends TestCase
public function checkout_session_expired_adds_system_note()
{
$customer = User::factory()->create();
$product = $this->createProduct(50.00);
$product = $this->createProduct(5000);
$customer->addToCart($product);
$cart = $customer->checkoutCart();
@ -214,7 +214,7 @@ class StripeWebhookOrderTest extends TestCase
public function charge_refunded_records_refund_on_order()
{
$customer = User::factory()->create();
$product = $this->createProduct(100.00);
$product = $this->createProduct(10000);
$customer->addToCart($product);
$cart = $customer->checkoutCart();
@ -244,7 +244,7 @@ class StripeWebhookOrderTest extends TestCase
public function charge_dispute_created_puts_order_on_hold()
{
$customer = User::factory()->create();
$product = $this->createProduct(100.00);
$product = $this->createProduct(10000);
$customer->addToCart($product);
$cart = $customer->checkoutCart();
@ -273,7 +273,7 @@ class StripeWebhookOrderTest extends TestCase
public function charge_dispute_created_adds_payment_note()
{
$customer = User::factory()->create();
$product = $this->createProduct(100.00);
$product = $this->createProduct(10000);
$customer->addToCart($product);
$cart = $customer->checkoutCart();
@ -302,7 +302,7 @@ class StripeWebhookOrderTest extends TestCase
public function charge_dispute_closed_restores_order_if_won()
{
$customer = User::factory()->create();
$product = $this->createProduct(100.00);
$product = $this->createProduct(10000);
$customer->addToCart($product);
$cart = $customer->checkoutCart();
@ -329,7 +329,7 @@ class StripeWebhookOrderTest extends TestCase
public function charge_dispute_closed_refunds_order_if_lost()
{
$customer = User::factory()->create();
$product = $this->createProduct(100.00);
$product = $this->createProduct(10000);
$customer->addToCart($product);
$cart = $customer->checkoutCart();
@ -356,7 +356,7 @@ class StripeWebhookOrderTest extends TestCase
public function refund_created_records_refund_on_order()
{
$customer = User::factory()->create();
$product = $this->createProduct(100.00);
$product = $this->createProduct(10000);
$customer->addToCart($product);
$cart = $customer->checkoutCart();
@ -383,7 +383,7 @@ class StripeWebhookOrderTest extends TestCase
public function refund_updated_adds_note_to_order()
{
$customer = User::factory()->create();
$product = $this->createProduct(100.00);
$product = $this->createProduct(10000);
$customer->addToCart($product);
$cart = $customer->checkoutCart();
@ -410,7 +410,7 @@ class StripeWebhookOrderTest extends TestCase
public function find_order_by_payment_intent_works()
{
$customer = User::factory()->create();
$product = $this->createProduct(100.00);
$product = $this->createProduct(10000);
$customer->addToCart($product);
$cart = $customer->checkoutCart();
@ -428,7 +428,7 @@ class StripeWebhookOrderTest extends TestCase
public function find_order_by_charge_id_works()
{
$customer = User::factory()->create();
$product = $this->createProduct(100.00);
$product = $this->createProduct(10000);
$customer->addToCart($product);
$cart = $customer->checkoutCart();
@ -476,7 +476,7 @@ class StripeWebhookOrderTest extends TestCase
public function handler_uses_client_reference_id_as_fallback()
{
$customer = User::factory()->create();
$product = $this->createProduct(50.00);
$product = $this->createProduct(5000);
$customer->addToCart($product);
$cart = $customer->checkoutCart();
@ -492,14 +492,14 @@ class StripeWebhookOrderTest extends TestCase
$this->assertTrue($result);
$order = $cart->fresh()->order;
$this->assertEquals(50.00, $order->amount_paid);
$this->assertEquals(5000, $order->amount_paid);
}
#[Test]
public function payment_intent_canceled_adds_note()
{
$customer = User::factory()->create();
$product = $this->createProduct(100.00);
$product = $this->createProduct(10000);
$customer->addToCart($product);
$cart = $customer->checkoutCart();
@ -525,7 +525,7 @@ class StripeWebhookOrderTest extends TestCase
public function charge_failed_adds_failure_note_to_order()
{
$customer = User::factory()->create();
$product = $this->createProduct(100.00);
$product = $this->createProduct(10000);
$customer->addToCart($product);
$cart = $customer->checkoutCart();
@ -559,7 +559,7 @@ class StripeWebhookOrderTest extends TestCase
public function checkout_session_completed_creates_order_when_none_exists()
{
$customer = User::factory()->create();
$product = $this->createProduct(100.00);
$product = $this->createProduct(10000);
// Add to cart but DON'T call checkoutCart() - simulate checkoutSession() flow
$customer->addToCart($product);
@ -597,7 +597,7 @@ class StripeWebhookOrderTest extends TestCase
public function checkout_session_completed_creates_order_and_records_payment()
{
$customer = User::factory()->create();
$product = $this->createProduct(150.00);
$product = $this->createProduct(15000);
// Add to cart but DON'T call checkoutCart()
$customer->addToCart($product);
@ -622,7 +622,7 @@ class StripeWebhookOrderTest extends TestCase
$order = $cart->order;
$this->assertNotNull($order);
$this->assertEquals(150.00, $order->amount_paid);
$this->assertEquals(15000, $order->amount_paid);
$this->assertEquals(OrderStatus::PROCESSING, $order->status);
}
@ -630,7 +630,7 @@ class StripeWebhookOrderTest extends TestCase
public function checkout_session_completed_creates_order_with_correct_totals()
{
$customer = User::factory()->create();
$product = $this->createProduct(75.50);
$product = $this->createProduct(7550);
$customer->addToCart($product, 2); // 2 items = 151.00
$cart = $customer->currentCart();
@ -651,15 +651,15 @@ class StripeWebhookOrderTest extends TestCase
$order = $cart->fresh()->order;
$this->assertNotNull($order);
// Order total should match cart total (in cents)
$this->assertEquals((int) $cart->getTotal() * 100, $order->amount_total);
// Order total should match cart total (already in cents)
$this->assertEquals((int) $cart->getTotal(), $order->amount_total);
}
#[Test]
public function checkout_session_completed_adds_payment_note_when_creating_order()
{
$customer = User::factory()->create();
$product = $this->createProduct(50.00);
$product = $this->createProduct(5000);
$customer->addToCart($product);
$cart = $customer->currentCart();
@ -692,7 +692,7 @@ class StripeWebhookOrderTest extends TestCase
public function checkout_session_completed_does_not_duplicate_order()
{
$customer = User::factory()->create();
$product = $this->createProduct(100.00);
$product = $this->createProduct(10000);
// Use checkoutCart() which creates an order
$customer->addToCart($product);
@ -725,7 +725,7 @@ class StripeWebhookOrderTest extends TestCase
public function checkout_session_completed_without_prior_conversion_creates_order()
{
$customer = User::factory()->create();
$product = $this->createProduct(200.00);
$product = $this->createProduct(20000);
// Add to cart - cart is NOT converted yet (simulates edge case)
$customer->addToCart($product);
@ -751,6 +751,6 @@ class StripeWebhookOrderTest extends TestCase
// Order should exist
$this->assertNotNull($cart->order);
$this->assertEquals(200.00, $cart->order->amount_paid);
$this->assertEquals(20000, $cart->order->amount_paid);
}
}