Exemple #1
0
 /**
  * Performs authorize transaction
  *
  * @param InfoInterface|Object $payment
  * @param float $amount
  * @return $this
  * @throws InvalidTransitionException
  * @throws LocalizedException
  */
 public function authorize(InfoInterface $payment, $amount)
 {
     /** @var Payment $payment */
     $request = $this->buildBasicRequest();
     /** @var \Magento\Sales\Model\Order $order */
     $order = $payment->getOrder();
     $this->addRequestOrderInfo($request, $order);
     $request = $this->fillCustomerContacts($order, $request);
     $token = $payment->getAdditionalInformation(self::PNREF);
     $request->setData('trxtype', self::TRXTYPE_AUTH_ONLY);
     $request->setData('origid', $token);
     $request->setData('amt', $this->formatPrice($amount));
     $response = $this->postRequest($request, $this->getConfig());
     $this->processErrors($response);
     try {
         $this->responseValidator->validate($response, $this);
     } catch (LocalizedException $exception) {
         $payment->setParentTransactionId($response->getData(self::PNREF));
         $this->void($payment);
         throw new LocalizedException(__('Error processing payment. Please try again later.'));
     }
     $this->setTransStatus($payment, $response);
     $this->createPaymentToken($payment, $token);
     $payment->unsAdditionalInformation(self::CC_DETAILS);
     return $this;
 }
Exemple #2
0
 /**
  * Performs authorize transaction
  *
  * @param \Magento\Payment\Model\InfoInterface|Object $payment
  * @param float $amount
  * @return $this
  * @throws InvalidTransitionException
  * @throws LocalizedException
  */
 public function authorize(\Magento\Payment\Model\InfoInterface $payment, $amount)
 {
     $request = $this->buildBasicRequest();
     $order = $payment->getOrder();
     if (!empty($order)) {
         $request = $this->fillCustomerContacts($order, $request);
     }
     $request->setTrxtype(self::TRXTYPE_AUTH_ONLY);
     $request->setOrigid($payment->getAdditionalInformation('pnref'));
     $request->setAmt(round($amount, 2));
     $response = $this->postRequest($request, $this->getConfig());
     $this->processErrors($response);
     try {
         $this->responseValidator->validate($response);
     } catch (LocalizedException $exception) {
         $payment->setParentTransactionId($response->getPnref());
         $this->void($payment);
         throw new LocalizedException(__('Error processing payment, please try again later.'));
     }
     $this->setTransStatus($payment, $response);
     $payment->unsAdditionalInformation('pnref');
     return $this;
 }
Exemple #3
0
 /**
  * Capture payment
  *
  * @param \Magento\Framework\DataObject|\Magento\Payment\Model\InfoInterface|Payment $payment
  * @param float $amount
  * @return $this
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function capture(\Magento\Payment\Model\InfoInterface $payment, $amount)
 {
     $authorizationTransaction = $payment->getAuthorizationTransaction();
     $authorizationPeriod = abs(intval($this->getConfigData('authorization_honor_period')));
     $maxAuthorizationNumber = abs(intval($this->getConfigData('child_authorization_number')));
     $order = $payment->getOrder();
     $isAuthorizationCreated = false;
     if ($payment->getAdditionalInformation($this->_isOrderPaymentActionKey)) {
         $voided = false;
         if (!$authorizationTransaction->getIsClosed() && $this->_isTransactionExpired($authorizationTransaction, $authorizationPeriod)) {
             //Save payment state and configure payment object for voiding
             $isCaptureFinal = $payment->getShouldCloseParentTransaction();
             $payment->setShouldCloseParentTransaction(false);
             $payment->setParentTransactionId($authorizationTransaction->getTxnId());
             $payment->unsTransactionId();
             $payment->setVoidOnlyAuthorization(true);
             $payment->void(new \Magento\Framework\DataObject());
             //Revert payment state after voiding
             $payment->unsAuthorizationTransaction();
             $payment->unsTransactionId();
             $payment->setShouldCloseParentTransaction($isCaptureFinal);
             $voided = true;
         }
         if ($authorizationTransaction->getIsClosed() || $voided) {
             if ($payment->getAdditionalInformation($this->_authorizationCountKey) > $maxAuthorizationNumber - 1) {
                 $this->_exception->create(['phrase' => __('The maximum number of child authorizations is reached.')]);
             }
             $api = $this->_callDoAuthorize($amount, $payment, $authorizationTransaction->getParentTxnId());
             //Adding authorization transaction
             $this->_pro->importPaymentInfo($api, $payment);
             $payment->setTransactionId($api->getTransactionId());
             $payment->setParentTransactionId($authorizationTransaction->getParentTxnId());
             $payment->setIsTransactionClosed(false);
             $formatedPrice = $order->getBaseCurrency()->formatTxt($amount);
             if ($payment->getIsTransactionPending()) {
                 $message = __('We\'ll authorize the amount of %1 as soon as the payment gateway approves it.', $formatedPrice);
             } else {
                 $message = __('The authorized amount is %1.', $formatedPrice);
             }
             $transaction = $this->transactionBuilder->setPayment($payment)->setOrder($order)->setTransactionId($payment->getTransactionId())->setFailSafe(true)->build(Transaction::TYPE_AUTH);
             $payment->addTransactionCommentsToOrder($transaction, $message);
             $payment->setParentTransactionId($api->getTransactionId());
             $isAuthorizationCreated = true;
         }
         //close order transaction if needed
         if ($payment->getShouldCloseParentTransaction()) {
             $orderTransaction = $this->getOrderTransaction($payment);
             if ($orderTransaction) {
                 $orderTransaction->setIsClosed(true);
                 $order->addRelatedObject($orderTransaction);
             }
         }
     }
     if (false === $this->_pro->capture($payment, $amount)) {
         $this->_placeOrder($payment, $amount);
     }
     if ($isAuthorizationCreated && isset($transaction)) {
         $transaction->setIsClosed(true);
     }
     return $this;
 }
 /**
  * Void payment
  * Void is in regards to the payment on the order invoice - to void the authorization, for instance - so that
  * the funds aren't subsequently captured. Payments have to be refunded after capture and cannot be voided.
  *
  * map this operation to APPROVEREVERSAL
  *
  * @param \Magento\Framework\DataObject|InfoInterface|\Magento\Sales\Model\Order\Payment $payment
  *
  * @return $this
  * @throws \Exception
  * @api
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function void(\Magento\Payment\Model\InfoInterface $payment)
 {
     if (!$this->_dataHelper->isBackendAvailable()) {
         return $this;
     }
     $orderNumber = $payment->getAdditionalInformation('orderNumber');
     if (!strlen($orderNumber)) {
         /* dont throw an exception here, might be a pending payment */
         $this->_logger->debug(__METHOD__ . ':No order number found.');
         return $this;
     }
     $orderDetails = $this->getOrderDetails($orderNumber);
     $backendClient = $this->_dataHelper->getBackendClient();
     $approveDone = false;
     foreach ($orderDetails->getOrder()->getPayments() as $wdPayment) {
         /** @var \WirecardCEE_QPay_Response_Toolkit_Order_Payment $wdPayment */
         $this->_logger->debug(__METHOD__ . ':operations allowed:' . implode(',', $wdPayment->getOperationsAllowed()));
         if (in_array('APPROVEREVERSAL', $wdPayment->getOperationsAllowed())) {
             $this->_logger->debug(__METHOD__ . ":{$orderNumber}");
             $ret = $backendClient->approveReversal($orderNumber);
             if ($ret->hasFailed()) {
                 throw new \Exception($ret->getError()->getMessage());
             }
             $approveDone = true;
             $orderTransaction = $this->_transactionRepository->getByTransactionType(Transaction::TYPE_ORDER, $payment->getId(), $payment->getOrder()->getId());
             if ($orderTransaction) {
                 $payment->setParentTransactionId($orderTransaction->getTxnId());
                 $payment->setTransactionId($orderTransaction->getTxnId() . '-void');
             }
             $payment->addTransactionCommentsToOrder($orderTransaction, 'approveReversal');
         }
     }
     if (!$approveDone) {
         throw new \Exception($this->_dataHelper->__('Void not possible anymore for this payment, please try cancel instead!'));
     }
     return $this;
 }