Skip to content

Commit b2d0cef

Browse files
committed
feat: Implement Cart, Checkout, and Order Management Controllers
- Added CartController for managing cart operations including adding, updating, removing, and clearing items. - Introduced CheckoutController to handle checkout processes, including subscription management and coupon application. - Created OrderController for managing user orders, including listing and storing orders. - Developed ShopController for product management, including filtering and retrieving product details. - Seeded initial shop data with attributes, categories, vendors, and products for testing.
1 parent 3cb8bcf commit b2d0cef

File tree

123 files changed

+16156
-1171
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

123 files changed

+16156
-1171
lines changed

composer.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"barryvdh/laravel-dompdf": "^3.1",
2929
"creativeorange/gravatar": "^1.0",
3030
"doctrine/dbal": "^3.4",
31+
"flutterwavedev/flutterwave-v3": "^1.1",
3132
"gocardless/gocardless-pro": "^6.6",
3233
"illuminate/console": "^12.0",
3334
"illuminate/contracts": "^12.0",
@@ -46,6 +47,7 @@
4647
"laravel/sanctum": "^4.0",
4748
"league/csv": "^9.15",
4849
"league/iso3166": "^4.3",
50+
"mercadopago/dx-php": "^3.5",
4951
"nesbot/carbon": "^3.0",
5052
"qirolab/laravel-themer": "^2.4",
5153
"razorpay/razorpay": "^2.9",
@@ -57,7 +59,9 @@
5759
"symfony/http-kernel": "^7.0",
5860
"symfony/polyfill-intl-icu": "^1.22.1",
5961
"twilio/sdk": "^7.16",
60-
"vedmant/laravel-shortcodes": "^1.1"
62+
"vedmant/laravel-shortcodes": "^1.1",
63+
"xendit/xendit-php": "^7.0",
64+
"yabacon/paystack-php": "^2.2"
6165
},
6266
"require-dev": {
6367
"mockery/mockery": "^1.6",

database/factories/CouponFactory.php

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
<?php
2+
3+
namespace Coderstm\Database\Factories;
4+
5+
use Coderstm\Models\Coupon;
6+
use Illuminate\Database\Eloquent\Factories\Factory;
7+
8+
/**
9+
* @template TModel of \Workbench\App\Coupon
10+
*
11+
* @extends \Illuminate\Database\Eloquent\Factories\Factory<TModel>
12+
*/
13+
class CouponFactory extends Factory
14+
{
15+
/**
16+
* The name of the factory's corresponding model.
17+
*
18+
* @var class-string<TModel>
19+
*/
20+
protected $model = Coupon::class;
21+
22+
/**
23+
* Define the model's default state.
24+
*
25+
* @return array<string, mixed>
26+
*/
27+
public function definition(): array
28+
{
29+
return [
30+
'name' => $this->faker->words(2, true) . ' Coupon',
31+
'promotion_code' => strtoupper($this->faker->lexify('????') . $this->faker->numerify('##')),
32+
'type' => $this->faker->randomElement(['product', 'plan']),
33+
'discount_type' => $this->faker->randomElement(['percentage', 'fixed', 'override']),
34+
'value' => $this->faker->randomFloat(2, 5, 50),
35+
'active' => true,
36+
'auto_apply' => $this->faker->boolean(30), // 30% chance of auto-apply
37+
'max_redemptions' => $this->faker->boolean() ? $this->faker->numberBetween(10, 100) : null,
38+
'expires_at' => $this->faker->boolean() ? $this->faker->dateTimeBetween('now', '+1 year') : null,
39+
'duration' => $this->faker->randomElement(['forever', 'once', 'repeating']),
40+
'duration_in_months' => $this->faker->boolean() ? $this->faker->numberBetween(1, 12) : null,
41+
];
42+
}
43+
44+
public function active()
45+
{
46+
return $this->state(function (array $attributes) {
47+
return [
48+
'active' => true,
49+
];
50+
});
51+
}
52+
53+
public function inactive()
54+
{
55+
return $this->state(function (array $attributes) {
56+
return [
57+
'active' => false,
58+
];
59+
});
60+
}
61+
62+
public function percentage($value = null)
63+
{
64+
return $this->state(function (array $attributes) use ($value) {
65+
return [
66+
'discount_type' => 'percentage',
67+
'value' => $value ?? $this->faker->randomFloat(2, 5, 50),
68+
];
69+
});
70+
}
71+
72+
public function fixedAmount($value = null)
73+
{
74+
return $this->state(function (array $attributes) use ($value) {
75+
return [
76+
'discount_type' => 'fixed',
77+
'value' => $value ?? $this->faker->randomFloat(2, 10, 100),
78+
];
79+
});
80+
}
81+
82+
public function override($value = null)
83+
{
84+
return $this->state(function (array $attributes) use ($value) {
85+
return [
86+
'discount_type' => 'override',
87+
'value' => $value ?? $this->faker->randomFloat(2, 5, 25),
88+
];
89+
});
90+
}
91+
92+
public function autoApply()
93+
{
94+
return $this->state(function (array $attributes) {
95+
return [
96+
'auto_apply' => true,
97+
];
98+
});
99+
}
100+
101+
public function noAutoApply()
102+
{
103+
return $this->state(function (array $attributes) {
104+
return [
105+
'auto_apply' => false,
106+
];
107+
});
108+
}
109+
110+
public function withExpiry($date = null)
111+
{
112+
return $this->state(function (array $attributes) use ($date) {
113+
return [
114+
'expires_at' => $date ?? $this->faker->dateTimeBetween('now', '+6 months'),
115+
];
116+
});
117+
}
118+
119+
public function withoutExpiry()
120+
{
121+
return $this->state(function (array $attributes) {
122+
return [
123+
'expires_at' => null,
124+
];
125+
});
126+
}
127+
128+
public function withMaxRedemptions($max = null)
129+
{
130+
return $this->state(function (array $attributes) use ($max) {
131+
return [
132+
'max_redemptions' => $max ?? $this->faker->numberBetween(10, 100),
133+
];
134+
});
135+
}
136+
137+
public function unlimited()
138+
{
139+
return $this->state(function (array $attributes) {
140+
return [
141+
'max_redemptions' => null,
142+
];
143+
});
144+
}
145+
146+
public function forProducts()
147+
{
148+
return $this->state(function (array $attributes) {
149+
return [
150+
'type' => 'product',
151+
];
152+
});
153+
}
154+
155+
public function forPlans()
156+
{
157+
return $this->state(function (array $attributes) {
158+
return [
159+
'type' => 'plan',
160+
];
161+
});
162+
}
163+
164+
public function forever()
165+
{
166+
return $this->state(function (array $attributes) {
167+
return [
168+
'duration' => 'forever',
169+
'duration_in_months' => null,
170+
];
171+
});
172+
}
173+
174+
public function once()
175+
{
176+
return $this->state(function (array $attributes) {
177+
return [
178+
'duration' => 'once',
179+
'duration_in_months' => null,
180+
];
181+
});
182+
}
183+
184+
public function repeating($months = null)
185+
{
186+
return $this->state(function (array $attributes) use ($months) {
187+
return [
188+
'duration' => 'repeating',
189+
'duration_in_months' => $months ?? $this->faker->numberBetween(1, 12),
190+
];
191+
});
192+
}
193+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
3+
namespace Coderstm\Database\Factories\Shop;
4+
5+
use Coderstm\Models\Shop\Checkout;
6+
use Illuminate\Database\Eloquent\Factories\Factory;
7+
8+
class CheckoutFactory extends Factory
9+
{
10+
protected $model = Checkout::class;
11+
12+
public function definition()
13+
{
14+
return [
15+
'token' => $this->faker->uuid(),
16+
'email' => $this->faker->email(),
17+
'first_name' => $this->faker->firstName(),
18+
'last_name' => $this->faker->lastName(),
19+
'phone_number' => $this->faker->phoneNumber(),
20+
'currency' => 'USD',
21+
'sub_total' => 0,
22+
'tax_total' => 0,
23+
'discount_total' => 0,
24+
'grand_total' => 0,
25+
'created_at' => now(),
26+
'updated_at' => now(),
27+
];
28+
}
29+
30+
public function withUser($user = null)
31+
{
32+
return $this->state([
33+
'user_id' => $user ? $user->id : \App\Models\User::factory()->create()->id,
34+
]);
35+
}
36+
37+
public function withEmail($email = null)
38+
{
39+
return $this->state([
40+
'email' => $email ?? $this->faker->email(),
41+
]);
42+
}
43+
44+
public function withTotals($subTotal = 1000, $taxTotal = 100, $discountTotal = 0)
45+
{
46+
$grandTotal = $subTotal + $taxTotal - $discountTotal;
47+
48+
return $this->state([
49+
'sub_total' => $subTotal,
50+
'tax_total' => $taxTotal,
51+
'discount_total' => $discountTotal,
52+
'grand_total' => $grandTotal,
53+
]);
54+
}
55+
56+
public function subscription()
57+
{
58+
return $this->state([
59+
'type' => 'subscription',
60+
]);
61+
}
62+
63+
public function standard()
64+
{
65+
return $this->state([
66+
'type' => 'standard',
67+
]);
68+
}
69+
70+
public function withCoupon($couponCode = null)
71+
{
72+
return $this->state([
73+
'coupon_code' => $couponCode ?? 'TEST10',
74+
]);
75+
}
76+
}

database/factories/Shop/Product/VariantFactory.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,40 @@ public function definition()
2929
'out_of_stock_track_inventory' => rand(0, 1),
3030
];
3131
}
32+
33+
public function isDefault()
34+
{
35+
return $this->state(function (array $attributes) {
36+
return [
37+
'is_default' => true,
38+
];
39+
});
40+
}
41+
42+
public function taxable()
43+
{
44+
return $this->state(function (array $attributes) {
45+
return [
46+
'taxable' => true,
47+
];
48+
});
49+
}
50+
51+
public function nonTaxable()
52+
{
53+
return $this->state(function (array $attributes) {
54+
return [
55+
'taxable' => false,
56+
];
57+
});
58+
}
59+
60+
public function forProduct($productId)
61+
{
62+
return $this->state(function (array $attributes) use ($productId) {
63+
return [
64+
'product_id' => $productId,
65+
];
66+
});
67+
}
3268
}

database/factories/Shop/ProductFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ public function definition()
2727
'title' => fake()->sentence,
2828
'description' => fake()->paragraph,
2929
'has_variant' => rand(0, 1),
30-
'category' => Category::inRandomOrder()->first()->toArray(),
31-
'vendor' => Vendor::inRandomOrder()->first()->toArray(),
30+
'category' => Category::inRandomOrder()->first()?->toArray(),
31+
'vendor' => Vendor::inRandomOrder()->first()?->toArray(),
3232
];
3333
}
3434
}

database/migrations/2021_09_11_193660_create_payment_methods_table.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public function up()
2424
$table->string('name');
2525
$table->string('label')->nullable();
2626
$table->string('provider')->default('manual')->index();
27+
$table->string('integration_via')->nullable();
2728
$table->string('link')->nullable();
2829
$table->string('logo')->nullable();
2930
$table->text('description')->nullable();
@@ -37,6 +38,7 @@ public function up()
3738
$table->decimal('transaction_fee', 10, 2)->default(0.00);
3839
$table->text('webhook')->nullable();
3940
$table->{$this->jsonable()}('options')->nullable();
41+
$table->integer('order')->default(0);
4042

4143
$table->timestamps();
4244
$table->softDeletes();

database/migrations/2022_07_24_092101_create_plans_table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function up()
2929
$table->unsignedInteger('interval_count')->default(1);
3030
$table->double('price', 12, 2)->default(0.00);
3131
$table->unsignedInteger('trial_days')->nullable()->default(0);
32-
$table->{$this->jsonable()}('options')->nullable();
32+
$table->{$this->jsonable()}('metadata')->nullable();
3333
$table->timestamps();
3434
$table->softDeletes();
3535
});

database/migrations/2022_07_24_092102_create_coupons_table.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ public function up(): void
1717
Schema::create('coupons', function (Blueprint $table) {
1818
$table->id();
1919
$table->string('name')->nullable();
20+
$table->string('type')->default('plan')->comment('Type of coupon: plan, product, or cart');
21+
$table->enum('discount_type', ['percentage', 'fixed', 'override'])->default('percentage');
22+
$table->double('value', 10, 2)->default(0);
2023
$table->string('promotion_code')->unique()->index();
21-
$table->{$this->jsonable()}('applies_to')->nullable();
2224
$table->string('duration');
2325
$table->unsignedInteger('duration_in_months')->nullable();
2426
$table->unsignedInteger('max_redemptions')->nullable();
25-
$table->unsignedBigInteger('amount_off')->nullable();
26-
$table->unsignedSmallInteger('percent_off')->nullable();
27-
$table->boolean('fixed')->default(false);
27+
$table->boolean('auto_apply')->default(false);
2828
$table->boolean('active')->default(true)->index();
2929
$table->dateTime('expires_at')->nullable()->index();
3030
$table->timestamps();

0 commit comments

Comments
 (0)