Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PlaceOrderWithHostedProStep.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Checkout\Test\Page\CheckoutOnepage;
10 use Magento\Checkout\Test\Page\CheckoutOnepageSuccess;
11 use Magento\Mtf\Fixture\FixtureFactory;
12 use Magento\Mtf\Fixture\FixtureInterface;
13 use Magento\Mtf\TestStep\TestStepInterface;
14 use Magento\Payment\Test\Fixture\CreditCard;
16 
20 class PlaceOrderWithHostedProStep implements TestStepInterface
21 {
27  private $checkoutOnepage;
28 
34  private $fixtureFactory;
35 
41  private $products;
42 
48  private $payment;
49 
55  private $creditCard;
56 
60  private $checkoutOnepageSuccess;
61 
67  private $order;
68 
78  public function __construct(
79  CheckoutOnepage $checkoutOnepage,
80  FixtureFactory $fixtureFactory,
81  CreditCard $creditCard,
82  CheckoutOnepageSuccess $checkoutOnepageSuccess,
83  array $payment,
84  array $products,
85  OrderInjectable $order = null
86  ) {
87  $this->checkoutOnepage = $checkoutOnepage;
88  $this->fixtureFactory = $fixtureFactory;
89  $this->creditCard = $creditCard;
90  $this->payment = $payment;
91  $this->products = $products;
92  $this->checkoutOnepageSuccess = $checkoutOnepageSuccess;
93  $this->order = $order;
94  }
95 
101  public function run()
102  {
103  $attempts = 1;
104  $this->checkoutOnepage->getPaymentBlock()->selectPaymentMethod($this->payment);
105  $this->checkoutOnepage->getPaymentBlock()->getSelectedPaymentMethodBlock()->clickPlaceOrder();
106  $this->checkoutOnepage->getHostedProBlock()->fillPaymentData($this->creditCard);
107  // As Paypal Sandbox is not stable there are three attempts given to place order
108  while ($this->checkoutOnepage->getHostedProBlock()->isErrorMessageVisible() && $attempts <= 3) {
109  $this->checkoutOnepage->getHostedProBlock()->fillPaymentData($this->creditCard);
110  $attempts++;
111  }
112 
113  $orderId = $this->checkoutOnepageSuccess->getSuccessBlock()->getGuestOrderId();
115  $data = [
116  'id' => $orderId,
117  'entity_id' => ['products' => $this->products]
118  ];
119  $orderData = $this->order !== null ? $this->order->getData() : [];
120  $order = $this->fixtureFactory->createByCode(
121  'orderInjectable',
122  ['data' => array_merge($data, $orderData)]
123  );
124 
125  return [
126  'orderId' => $orderId,
127  'order' => $order,
128  ];
129  }
130 }
$payment
Definition: order.php:17
__construct(CheckoutOnepage $checkoutOnepage, FixtureFactory $fixtureFactory, CreditCard $creditCard, CheckoutOnepageSuccess $checkoutOnepageSuccess, array $payment, array $products, OrderInjectable $order=null)