Ejemplo n.º 1
0
 /**
  * Refund capture
  *
  * @param InfoInterface|Payment|Object $payment
  * @param float $amount
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  * @throws \Magento\Framework\Exception\State\InvalidTransitionException
  */
 public function refund(\Magento\Payment\Model\InfoInterface $payment, $amount)
 {
     $request = $this->buildBasicRequest();
     $request->setTrxtype(self::TRXTYPE_CREDIT);
     $request->setOrigid($payment->getParentTransactionId());
     $request->setAmt(round($amount, 2));
     $response = $this->postRequest($request, $this->getConfig());
     $this->processErrors($response);
     if ($response->getResultCode() == self::RESPONSE_CODE_APPROVED) {
         $payment->setTransactionId($response->getPnref())->setIsTransactionClosed(1);
         $payment->setShouldCloseParentTransaction(!$payment->getCreditmemo()->getInvoice()->canRefund());
     }
     return $this;
 }