Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AuthorizationCommand.php
Go to the documentation of this file.
1 <?php
8 
15 use Magento\Payment\Helper\Formatter;
17 
19 {
20  use Formatter;
21 
25  private $payflowFacade;
26 
31  public function __construct(
32  Transparent $payflowFacade
33  ) {
34  $this->payflowFacade = $payflowFacade;
35  }
36 
45  public function execute(array $commandSubject)
46  {
48  $amount = $commandSubject['amount'];
50  $paymentDO = $commandSubject['payment'];
51  $payment = $paymentDO->getPayment();
52 
53  $storeId = $paymentDO->getOrder()->getStoreId();
54  $this->payflowFacade->setStore($storeId);
55 
56  $request = $this->payflowFacade->buildBasicRequest();
57 
59  $order = $payment->getOrder();
60  $this->payflowFacade->addRequestOrderInfo($request, $order);
61  $request = $this->payflowFacade->fillCustomerContacts($order, $request);
62 
64  $token = $payment->getExtensionAttributes()->getVaultPaymentToken();
65  $request->setData('trxtype', Transparent::TRXTYPE_AUTH_ONLY);
66  $request->setData('origid', $token->getGatewayToken());
67  $request->setData('amt', $this->formatPrice($amount));
68 
69  $response = $this->payflowFacade->postRequest($request, $this->payflowFacade->getConfig());
70  $this->payflowFacade->processErrors($response);
71 
72  try {
73  $this->payflowFacade->getResponceValidator()->validate($response, $this->payflowFacade);
74  } catch (LocalizedException $exception) {
75  $payment->setParentTransactionId($response->getData(Transparent::PNREF));
76  $this->payflowFacade->void($payment);
77  throw new LocalizedException(__("The payment couldn't be processed at this time. Please try again later."));
78  }
79 
80  $this->payflowFacade->setTransStatus($payment, $response);
81 
82  return $this;
83  }
84 }
$response
Definition: 404.php:11
$order
Definition: order.php:55
__()
Definition: __.php:13
$amount
Definition: order.php:14
$payment
Definition: order.php:17