instantPurchaseOptionFactory = $instantPurchaseOptionFactory; $this->paymentTokenManagement = $paymentTokenManagement; $this->addressRepository = $addressRepository; $this->addressFactory = $addressFactory; $this->shippingMethodFactory = $shippingMethodFactory; } /** * Loads entities and use them for instant purchase option creation. * * @param int $customerId * @param string $paymentTokenPublicHash * @param int $shippingAddressId * @param int $billingAddressId * @param string $carrierCode * @param string $shippingMethodCode * @return InstantPurchaseOption */ public function create( int $customerId, string $paymentTokenPublicHash, int $shippingAddressId, int $billingAddressId, string $carrierCode, string $shippingMethodCode ): InstantPurchaseOption { $paymentToken = $this->paymentTokenManagement->getByPublicHash($paymentTokenPublicHash, $customerId); $shippingAddress = $this->getAddress($shippingAddressId); $billingAddress = $this->getAddress($billingAddressId); $shippingMethod = $this->shippingMethodFactory->create() ->setCarrierCode($carrierCode) ->setMethodCode($shippingMethodCode); return $this->instantPurchaseOptionFactory->create( $paymentToken, $shippingAddress, $billingAddress, $shippingMethod ); } /** * Loads customer address model by identifier. * * @param int $addressId * @return Address */ private function getAddress($addressId): Address { $addressDataModel = $this->addressRepository->getById($addressId); $address = $this->addressFactory->create(); $address->updateData($addressDataModel); return $address; } }