/**
  * @param string $paymentId
  * @param string $payerId
  *
  * @throws \Exception
  * @throws \InvalidArgumentException
  * @throws RuntimeException
  *
  * @return \ChingShop\Modules\Sales\Domain\Order\Order
  */
 public function executePayment(string $paymentId, string $payerId)
 {
     $settlement = PayPalSettlement::create(['payment_id' => $paymentId, 'payer_id' => $payerId]);
     $this->log->info("Executing PayPal payment {$paymentId} / {$payerId}");
     $execution = $this->createExecution($paymentId, $payerId);
     $order = $this->cashier->settle($execution->basket(), $settlement);
     if ($execution->approve()) {
         return $order;
     }
     throw new RuntimeException('PayPal payment was not approved.');
 }
 /**
  * Seed an order.
  */
 private function seedOrder()
 {
     $basket = Basket::create();
     $address = Address::create(['name' => $this->faker()->name, 'line_one' => $this->faker()->streetAddress, 'line_two' => $this->faker()->streetName, 'city' => $this->faker()->city, 'post_code' => $this->faker()->postcode, 'country_code' => $this->faker()->countryCode]);
     $basket->address()->associate($address);
     $basket->save();
     $basketItems = [];
     $this->repeat(function () use($basket, &$basketItems) {
         $basketItems[] = BasketItem::create(['basket_id' => $basket->id, 'product_option_id' => ProductOption::inRandomOrder()->first()->id]);
     }, random_int(1, 4));
     $order = Order::create();
     $order->address()->associate($address);
     $order->save();
     /** @var BasketItem $basketItem */
     foreach ($basketItems as $basketItem) {
         $stockItem = new StockItem();
         $basketItem->productOption->stockItems()->save($stockItem);
         $orderItem = OrderItem::create(['basket_item_id' => $basketItem->id, 'order_id' => $order->id, 'price' => $basketItem->priceAsFloat()]);
         $orderItem->stockItem()->save($stockItem);
     }
     Payment::create(['order_id' => $order->id, 'settlement_id' => PayPalSettlement::create(['payment_id' => $this->faker()->uuid, 'payer_id' => $this->faker()->uuid])->id, 'settlement_type' => PayPalSettlement::class]);
 }