/** * @param \Magento\Payment\Model\InfoInterface $payment * @param float $amount * @return $this * @throws LocalizedException */ public function refund(\Magento\Payment\Model\InfoInterface $payment, $amount) { $senderCustomer = $payment->getAdditionalInformation('destination_customer'); $customerId = $payment->getOrder()->getCustomerId(); $customer = $this->customerRepository->getById($customerId); $destinationCustomer = $customer->getCustomAttribute('openpay_customer_id')->getValue(); $paymentLeyend = __('Refund for: ') . __($this->getConfigData('paymentLeyend'))->getText(); $order = $payment->getOrder(); $useOrderId = $this->getConfigData('useOrderId'); $orderId = $order->getIncrementId(); $params = ['customer_id' => $destinationCustomer, 'amount' => $amount, 'description' => $paymentLeyend, 'order_id' => $useOrderId ? $orderId . '-refund' : null]; try { $transaction = $this->transferAdapter->transfer($senderCustomer, $params); $payment->setTransactionId($transaction->getId())->setIsTransactionClosed(0); $this->openpayCustomerRepository->clearCustomerCache($senderCustomer); $this->openpayCustomerRepository->clearCustomerCache($destinationCustomer); } catch (OpenpayException $e) { $this->debugData(['request' => $params, 'exception' => $e->getMessage()]); $this->_logger->error(__('Payment capturing error.')); throw new LocalizedException(__('[' . $e->getErrorCode() . ']' . $e->getMessage())); } return parent::refund($payment, $amount); // TODO: Change the autogenerated stub }
public function refund(\Magento\Payment\Model\InfoInterface $payment, $amount) { parent::refund($payment, $amount); $txn = $payment->getAuthorizationTransaction(); if ($txn) { try { $billnumber = $txn->getParentTxnId() ? $txn->getParentTxnId() : $txn->getTxnId(); $data = array('Merchant_ID' => urlencode($this->getConfigData('merchant')), 'Billnumber' => urlencode($billnumber), 'Login' => urlencode($this->getConfigData('api_login')), 'Password' => urlencode($this->getConfigData('api_password'))); $xml = $this->callAssist(self::CANCEL_URL, $data); if ((int) $xml['firstcode'] || (int) $xml['secondcode']) { throw new \Magento\Framework\Exception\LocalizedException(__('error in call')); } if ('AS000' != (string) $xml->orders->order->responsecode) { throw new \Magento\Framework\Exception\LocalizedException($this->getAssistErrors((string) $xml->orders->order->responsecode)); } /* if (Mage::helper('assist')->isServiceSecured()) { $y = implode("", array( $this->getConfigData('merchant'), (string)$xml->orders->order->ordernumber, (string)$xml->orders->order->orderamount, (string)$xml->orders->order->ordercurrency, (string)$xml->orders->order->orderstate, (string)$xml->orders->order->packetdate )); $keyFile = Mage::getBaseDir('var') . DS . self::PEM_DIR . DS . $this->getConfigData('assist_key'); if ((string)$xml->orders->order->signature != $this->sign($y, $keyFile)) { Mage::throwException('Incorrect Signature.'); } } */ // success $this->_debugger->debug(var_export($xml, true)); } catch (\Magento\Framework\Exception\LocalizedException $e) { $this->_debugger->debug($e->getMessage()); throw $e; } } $this->_debugger->debug('refund'); return $this; }
public function refund(\Magento\Payment\Model\InfoInterface $payment, $amount) { return parent::refund($payment, $amount); }
/** * Refund specified amount for payment * * @param \Magento\Framework\DataObject|InfoInterface $payment * @param float $amount * @return $this * @throws \Magento\Framework\Exception\LocalizedException * @api * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function refund(\Magento\Payment\Model\InfoInterface $payment, $amount) { parent::refund($payment, $amount); // get pspReference $pspReference = $payment->getAdyenPspReference(); $order = $payment->getOrder(); // if amount is a full refund send a refund/cancelled request so if it is not captured yet it will cancel the order $grandTotal = $order->getGrandTotal(); if ($grandTotal == $amount) { $this->_paymentRequest->cancelOrRefund($payment); } else { $this->_paymentRequest->refund($payment, $amount); } return $this; }