Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions
InstantPurchaseOption Class Reference

Public Member Functions

 __construct (PaymentTokenInterface $paymentToken=null, Address $shippingAddress=null, Address $billingAddress=null, ShippingMethodInterface $shippingMethod=null)
 
 isAvailable ()
 
 getPaymentToken ()
 
 getShippingAddress ()
 
 getBillingAddress ()
 
 getShippingMethod ()
 

Detailed Description

Option to make instant purchase.

@api

Since
100.2.0

Definition at line 21 of file InstantPurchaseOption.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( PaymentTokenInterface  $paymentToken = null,
Address  $shippingAddress = null,
Address  $billingAddress = null,
ShippingMethodInterface  $shippingMethod = null 
)

InstantPurchaseOption constructor.

Parameters
PaymentTokenInterface | null$paymentToken
Address | null$shippingAddress
Address | null$billingAddress
ShippingMethodInterface | null$shippingMethod
Exceptions
InvalidArgumentExceptionif invalid data provided (implementation error)

@SuppressWarnings(Magento.TypeDuplication) Type duplication verified. This is not a service class and should not be instantiated directly through Object Manager. Use InstantPurchaseOptionFactory instead.

Definition at line 56 of file InstantPurchaseOption.php.

61  {
62  $customers = [];
63  if ($paymentToken) {
64  $customers[] = $paymentToken->getCustomerId();
65  }
66  if ($shippingAddress) {
67  $customers[] = $shippingAddress->getCustomerId();
68  }
69  if ($billingAddress) {
70  $customers[] = $billingAddress->getCustomerId();
71  }
72  if (count(array_unique($customers)) > 1) {
73  throw new InvalidArgumentException('Provided data does not belong to same customer.');
74  }
75 
76  $this->paymentToken = $paymentToken;
77  $this->shippingAddress = $shippingAddress;
78  $this->billingAddress = $billingAddress;
79  $this->shippingMethod = $shippingMethod;
80  }
$billingAddress
Definition: order.php:25
$shippingAddress
Definition: order.php:40
$shippingMethod
Definition: popup.phtml:12

Member Function Documentation

◆ getBillingAddress()

getBillingAddress ( )

Returns billing address for instant purchase.

Returns
Address
Exceptions
LocalizedExceptionif billing address is not defined
Since
100.2.0

Definition at line 137 of file InstantPurchaseOption.php.

137  : Address
138  {
139  if (!isset($this->billingAddress)) {
140  throw new LocalizedException(__('Billing address is not defined for instance purchase.'));
141  }
142  return $this->billingAddress;
143  }
$billingAddress
Definition: order.php:25
__()
Definition: __.php:13

◆ getPaymentToken()

getPaymentToken ( )

Returns payment token for instant purchase.

Returns
PaymentTokenInterface
Exceptions
LocalizedExceptionif payment token is not defined
Since
100.2.0

Definition at line 105 of file InstantPurchaseOption.php.

105  : PaymentTokenInterface
106  {
107  if (!isset($this->paymentToken)) {
108  throw new LocalizedException(
109  __("A payment method isn't defined for instance purchase. Verify and try again.")
110  );
111  }
112  return $this->paymentToken;
113  }
__()
Definition: __.php:13

◆ getShippingAddress()

getShippingAddress ( )

Returns shipping address for instant purchase.

Returns
Address
Exceptions
LocalizedExceptionif shipping address is not defined
Since
100.2.0

Definition at line 122 of file InstantPurchaseOption.php.

122  : Address
123  {
124  if (!isset($this->shippingAddress)) {
125  throw new LocalizedException(__('Shipping address is not defined for instance purchase.'));
126  }
127  return $this->shippingAddress;
128  }
$shippingAddress
Definition: order.php:40
__()
Definition: __.php:13

◆ getShippingMethod()

getShippingMethod ( )

Returns shipping method for instant purchase.

Returns
ShippingMethodInterface
Exceptions
LocalizedExceptionif shipping method is not defined
Since
100.2.0

Definition at line 152 of file InstantPurchaseOption.php.

152  : ShippingMethodInterface
153  {
154  if (!isset($this->shippingMethod)) {
155  throw new LocalizedException(__('Shipping method is not defined for instance purchase.'));
156  }
157  return $this->shippingMethod;
158  }
__()
Definition: __.php:13
$shippingMethod
Definition: popup.phtml:12

◆ isAvailable()

isAvailable ( )

Checks if option available

Returns
bool
Since
100.2.0

Definition at line 88 of file InstantPurchaseOption.php.

88  : bool
89  {
90  return isset(
91  $this->paymentToken,
92  $this->shippingAddress,
93  $this->billingAddress,
94  $this->shippingMethod
95  ) && $this->shippingMethod->getAvailable();
96  }

The documentation for this class was generated from the following file: