Skip to content

Commit 3b1dfbf

Browse files
committed
feat: Introduce wholesale and attribute pricing to product resources, refactor multiple order processing logic, and update seller authentication cookie handling.
1 parent 41094a2 commit 3b1dfbf

File tree

9 files changed

+30
-17
lines changed

9 files changed

+30
-17
lines changed

app/Http/Controllers/Auth/LoginController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ public function login(Request $request){
5757
$cookieNameAccess = 'accessTokenDelivery';
5858
$cookieNameRefresh = 'refreshTokenDelivery';
5959
} else if (str_contains($origin, 'localhost')) {
60-
$cookieNameAccess = 'accessToken';
61-
$cookieNameRefresh = 'refreshToken';
60+
$cookieNameAccess = 'accessTokenSeller';
61+
$cookieNameRefresh = 'refreshTokenSeller';
6262
} else {
6363
$cookieNameAccess = 'accessToken';
6464
$cookieNameRefresh = 'refreshToken';

app/Http/Controllers/Seller/ProductController.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,8 @@ public function update(Request $request, $id)
270270
{
271271
try {
272272
DB::beginTransaction();
273-
274273
// Log de la requête entrante
275-
Log::info('Product update request received', ['product_id' => $id, 'request_all' => $request->all()]);
274+
Log::info('Product update request received', ['product_id' => $id, 'request_all' => $request]);
276275

277276
$user = Auth::guard('api')->user();
278277
$shop = Shop::where('user_id', $user->id)->first();

app/Http/Middleware/AttachAccessTokenFromCookieUser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function handle(Request $request, Closure $next)
1717
} elseif (str_contains($host, 'delivery.akevas.com')) {
1818
$cookieName = 'accessTokenDelivery';
1919
} elseif (str_contains($host, 'localhost:5173')) {
20-
$cookieName = 'accessToken';
20+
$cookieName = 'accessTokenSeller';
2121
}
2222
else {
2323
$cookieName = 'accessToken'; // client / admin

app/Http/Resources/ProductAttributeResource.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public function toArray(Request $request): array
2222
return [
2323
'id' => $this->id,
2424
'value' => $this->attributeValue->value,
25+
'price'=>$this->price,
2526
"product_variation"=>ProductVariationResource::make($this->variation),
2627
];
2728
}

app/Http/Resources/ProductVariationResource.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public function toArray(Request $request): array
3232
'price' => $this->price,
3333
'quantity' => $this->quantity,
3434
'images' => ImageResource::collection($this->images),
35+
'isWhole' => $this->product->wholesalePrices ? true : false,
36+
"wholeSalePrice" => $this->product->wholesalePrices,
3537
'attributes_variation' => $this->attributesVariation->map(function($attr) {
3638
return [
3739
'id' => $attr->id,

app/Jobs/PaymentProcessingJob.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ public function handle(): void
7070

7171
if (isset($responseStatus) && $responseStatus === "FAILED" || $responseStatus === "CANCELED") {
7272
Log::error('PaymentProcessingJob: Payment failed');
73-
73+
Log::info('PaymentProcessingJob: Payment processing for job', [
74+
"app" => $this->request,
75+
"reference" => $this->reference,
76+
]);
7477
return;
7578
}
7679

app/Services/Payment/ValidatePaymentProductService.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ private function createOrder($userId,$amount,$shipping,$productId,$quantity,$qua
136136

137137
private function multipleOrder($userId,$amount,$shipping,$quarter_delivery,$address,$productsPayments,$reference){
138138

139-
foreach($productsPayments as $product){
140-
$order=new Order;
139+
140+
$order=new Order;
141141
$order->user_id=$userId;
142142
$order->isPay=1;
143143
$order->total=$amount;
@@ -150,9 +150,13 @@ private function multipleOrder($userId,$amount,$shipping,$quarter_delivery,$addr
150150
$order->address=$address;
151151
}
152152
$order->save();
153-
SendNewOrderNotificationJob::dispatch($order->id,$product['product_id'])->delay(now()->addMinutes(1));
153+
154154
$this->savePaymentAndOrder($reference,$order->id);
155-
if($product['hasVariation']=="true"){
155+
foreach($productsPayments as $product){
156+
157+
SendNewOrderNotificationJob::dispatch($order->id,$product['product_id'])->delay(now()->addMinutes(1));
158+
159+
if($product['hasVariation']==true){
156160
$orderVariation=new OrderVariation;
157161
$orderVariation->order_id=$order->id;
158162
if($product['attributeVariationId']==null){
@@ -169,6 +173,12 @@ private function multipleOrder($userId,$amount,$shipping,$quarter_delivery,$addr
169173
Log::info('Order variation create success');
170174
$orderVariation->save();
171175
}else{
176+
Log::info('gain order',[
177+
"order_id"=>$order->id,
178+
"product_id"=>$product['product_id'],
179+
"quantity"=>$product['quantity'],
180+
"price"=>$product['price'],
181+
]);
172182
$orderDetails=new OrderDetail;
173183
$orderDetails->order_id=$order->id;
174184
$orderDetails->product_id=$product['product_id'];
@@ -181,9 +191,9 @@ private function multipleOrder($userId,$amount,$shipping,$quarter_delivery,$addr
181191
}
182192
}
183193

184-
return $order;
194+
185195
}
186-
return null;
196+
return $order;
187197
}
188198

189199
private function reduceQuantity($productId,$quantity){

config/cors.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
'paths' => ['api/*'],
1919

20-
'allowed_methods' => ['GET, POST, PUT, DELETE, OPTIONS'],
20+
'allowed_methods' => ['GET, POST, PUT, DELETE, OPTIONS','PATCH'],
2121

2222
'allowed_origins' => ['http://localhost:5173',"https://delivery.akevas.com","https://seller.akevas.com","https://main.akevas.com","https://www.main.akevas.com","https://akevas.com","https://www.akevas.com","https://pay.notchpay.co","https://dev.akevas.com","http://localhost:4173",'http://localhost:5174'],
2323

routes/api.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@
9696
use App\Http\Controllers\Product\Payment\PaymentProductProcessingController;
9797
use App\Http\Controllers\Shops\ListReviewController as ShopReviewController;
9898
use App\Http\Controllers\Admin\Reviews\DeclineOrValidateShopReviewController;
99-
use App\Http\Controllers\Payment\Coolpay\Product\BuyProductProcessController;
10099
use App\Http\Controllers\Product\Payment\HandleWebhookProductPaymentController;
101100
use App\Http\Controllers\Delivery\ProfileController as DeliveryProfileController;
102101
use App\Http\Controllers\Admin\RecentOrderController as AdminRecentOrderController;
@@ -266,10 +265,9 @@
266265

267266
Route::middleware(['auth:api'])->prefix('v1')->group(function () {
268267
Route::get('/orders/towns', [GetOrderOfTownController::class, 'getOrdersByTown']);
269-
Route::get('init/pay/coolpay',[BuyProductProcessController::class,'initPaymentCoolpay']);
268+
//Route::get('init/pay/coolpay',[BuyProductProcessController::class,'initPaymentCoolpay']);
270269
Route::post("init/payment/buy/product", [InitPaymentController::class, "initPayment"]);
271-
Route::post("payment/pending/buy/product", [BuyProductProcessController::class, "paymentPending"]);
272-
Route::post("payment/callback/buy/product", [BuyProductProcessController::class, "buyProductCallBack"]);
270+
273271
Route::get('/current/user', [ProfileController::class, 'currentUser']);
274272
Route::post('/update/user', [ProfileController::class, 'updateUser']);
275273
Route::post('/logout', [LogoutController::class, 'logout']);

0 commit comments

Comments
 (0)