create(); $product = Product::factory()->create([ 'stock_quantity' => 10000, 'has_options' => false, 'option_groups' => null, // 기본 배송정책 해석에 맡긴다 — 특정 정책을 지목하면 그 정책의 비용만 재게 된다 'shipping_policy_id' => null, ]); $option = ProductOption::factory()->forProduct($product)->create([ 'stock_quantity' => 10000, 'price_adjustment' => 0, 'is_default' => true, 'is_active' => true, ]); // 구매 대상 제한 검증이 Auth::user() 의 역할을 읽으므로 인증 주체를 세운다. // 콘솔에는 세션이 없어 login() 대신 setUser() 를 쓴다. Auth::setUser($user); $tempOrder = $this->tempOrderService->createTempOrderFromDirectItems( items: [[ 'product_id' => $product->id, 'product_option_id' => $option->id, 'quantity' => 1, ]], userId: $user->id, cartKey: null, ); return [ 'temp_order' => $tempOrder, 'user' => $user, // 프론트엔드가 보내는 결제예정금액에 해당 — 임시 주문의 최종 금액을 그대로 쓴다 'expected_total_amount' => (float) $tempOrder->getFinalAmount(), ]; } /** * 계측 대상 — 임시 주문을 실제 주문으로 생성합니다. * * @param array{temp_order: TempOrder, user: User, expected_total_amount: float} $context prepare 산출물 * @return Order 생성된 주문 */ public function create(array $context): Order { return $this->orderProcessingService->createFromTempOrder( tempOrder: $context['temp_order'], ordererInfo: [ 'name' => '성능계측', 'phone' => '01000000000', 'email' => $context['user']->email, ], shippingInfo: [ 'recipient_name' => '성능계측', 'recipient_phone' => '01000000000', 'country_code' => 'KR', 'zipcode' => '06236', 'address' => '서울특별시 강남구 테헤란로 1', 'address_detail' => '1층', ], paymentMethod: 'card', expectedTotalAmount: $context['expected_total_amount'], ); } }