Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ChangeOrderStatusToPaymentReviewStep.php
Go to the documentation of this file.
1 <?php
7 
8 use Magento\Mtf\TestStep\TestStepInterface;
10 
17 class ChangeOrderStatusToPaymentReviewStep implements TestStepInterface
18 {
22  private $orderId;
23 
27  private $webApi;
28 
34  public function __construct($orderId, WebapiDecorator $webApi)
35  {
36  $this->orderId = $orderId;
37  $this->webApi = $webApi;
38  }
39 
43  public function run()
44  {
45  $order = $this->getOrder($this->orderId);
46  $order['state'] = 'payment_review';
47  $order['status'] = 'fraud';
48  $this->saveOrder($order);
49  }
50 
56  private function getOrder($incrementId)
57  {
58  $url = $_ENV['app_frontend_url'] . 'rest/V1/orders/';
59  $url .= '?searchCriteria[filterGroups][0][filters][0][field]=increment_id';
60  $url .= '&searchCriteria[filterGroups][0][filters][0][value]=' . $incrementId;
61  $this->webApi->write($url, [], WebapiDecorator::GET);
62  $response = json_decode($this->webApi->read(), true);
63  $this->webApi->close();
64  return $response['items'][0];
65  }
66 
72  private function saveOrder(array $order)
73  {
74  $url = $_ENV['app_frontend_url'] . 'rest/V1/orders';
75  // web api doesn't allow to save payment additional information
76  unset($order['payment']['additional_information']);
77  $this->webApi->write($url, ['entity' => $order], WebapiDecorator::POST);
78  $response = json_decode($this->webApi->read(), true);
79  $this->webApi->close();
80  if (empty($response['entity_id'])) {
81  throw new \Exception('Couldn\'t update order details');
82  }
83  }
84 }
$response
Definition: 404.php:11
$order
Definition: order.php:55