コード例 #1
0
ファイル: Express.php プロジェクト: pradeep-wagento/magento2
 /**
  * Order payment
  *
  * @param \Magento\Framework\DataObject|\Magento\Payment\Model\InfoInterface|Payment $payment
  * @param float $amount
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function order(\Magento\Payment\Model\InfoInterface $payment, $amount)
 {
     $paypalTransactionData = $this->_checkoutSession->getPaypalTransactionData();
     if (!is_array($paypalTransactionData)) {
         $this->_placeOrder($payment, $amount);
     } else {
         $this->_importToPayment($this->_pro->getApi()->setData($paypalTransactionData), $payment);
     }
     $payment->setAdditionalInformation($this->_isOrderPaymentActionKey, true);
     if ($payment->getIsFraudDetected()) {
         return $this;
     }
     $order = $payment->getOrder();
     $orderTransactionId = $payment->getTransactionId();
     $api = $this->_callDoAuthorize($amount, $payment, $orderTransactionId);
     $state = \Magento\Sales\Model\Order::STATE_PROCESSING;
     $status = true;
     $formattedPrice = $order->getBaseCurrency()->formatTxt($amount);
     if ($payment->getIsTransactionPending()) {
         $message = __('The ordering amount of %1 is pending approval on the payment gateway.', $formattedPrice);
         $state = \Magento\Sales\Model\Order::STATE_PAYMENT_REVIEW;
     } else {
         $message = __('Ordered amount of %1', $formattedPrice);
     }
     $transaction = $this->transactionBuilder->setPayment($payment)->setOrder($order)->setTransactionId($payment->getTransactionId())->build(Transaction::TYPE_ORDER);
     $payment->addTransactionCommentsToOrder($transaction, $message);
     $this->_pro->importPaymentInfo($api, $payment);
     if ($payment->getIsTransactionPending()) {
         $message = __('We\'ll authorize the amount of %1 as soon as the payment gateway approves it.', $formattedPrice);
         $state = \Magento\Sales\Model\Order::STATE_PAYMENT_REVIEW;
         if ($payment->getIsFraudDetected()) {
             $status = \Magento\Sales\Model\Order::STATUS_FRAUD;
         }
     } else {
         $message = __('The authorized amount is %1.', $formattedPrice);
     }
     $payment->resetTransactionAdditionalInfo();
     $payment->setTransactionId($api->getTransactionId());
     $payment->setParentTransactionId($orderTransactionId);
     $transaction = $this->transactionBuilder->setPayment($payment)->setOrder($order)->setTransactionId($payment->getTransactionId())->build(Transaction::TYPE_AUTH);
     $payment->addTransactionCommentsToOrder($transaction, $message);
     $order->setState($state)->setStatus($status);
     $payment->setSkipOrderProcessing(true);
     return $this;
 }