/** * (partial)Refund payment on Adyen * * @param \Magento\Payment\Model\InfoInterface $payment * @param $amount * @return mixed * @throws \Magento\Framework\Exception\LocalizedException */ public function refund(\Magento\Payment\Model\InfoInterface $payment, $amount) { $pspReference = $this->_getPspReference($payment); $merchantAccount = $this->_adyenHelper->getAdyenAbstractConfigData("merchant_account"); $currency = $payment->getOrder()->getBaseCurrencyCode(); $modificationAmount = array('currency' => $currency, 'value' => $amount); $request = array("merchantAccount" => $merchantAccount, "modificationAmount" => $modificationAmount, "reference" => $payment->getOrder()->getIncrementId(), "originalReference" => $pspReference); // call lib $service = new \Adyen\Service\Modification($this->_client); $result = $service->refund($request); if ($result['response'] != '[refund-received]') { // something went wrong throw new \Magento\Framework\Exception\LocalizedException(__('The refund action failed')); } return $result; }
/** * @param \Magento\Payment\Gateway\Http\TransferInterface $transferObject * @return null */ public function placeRequest(\Magento\Payment\Gateway\Http\TransferInterface $transferObject) { $requests = $transferObject->getBody(); $responses = []; foreach ($requests as $request) { // call lib $service = new \Adyen\Service\Modification($this->_client); try { $responses[] = $service->refund($request); } catch (\Adyen\AdyenException $e) { $responses[] = null; } } return $responses; }