Method to refund or void ECheck

@param eCheckId
@param refund
@return
@throws BaseException
518919
public Refund refund(String eCheckId, Refund refund) throws BaseException {

		logger.debug("Enter ECheckService::refund");
		
		if (StringUtils.isBlank(eCheckId)) {
			logger.error("IllegalArgumentException {}", eCheckId);
			throw new IllegalArgumentException("eCheckId cannot be empty or null");
		}

		// prepare API url
		String apiUrl = requestContext.getBaseUrl() + "echecks/{id}/refunds".replaceAll("\\{format\\}", "json")
				.replaceAll("\\{" + "id" + "\\}", eCheckId.toString());
		logger.info("apiUrl - " + apiUrl);

		// assign TypeReference for deserialization
		TypeReference<Refund> typeReference = new TypeReference<Refund>() {
		};

		// prepare service request
		Request request = new Request.RequestBuilder(MethodType.POST, apiUrl).requestObject(refund)
				.typeReference(typeReference).context(requestContext).build();

		// make API call
		Response response = sendRequest(request);

		// retrieve response
		Refund refundResponse = (Refund) response.getResponseObject();

		// set additional attributes
		prepareResponse(request, response, refundResponse);
		return refundResponse;
	}
1277648
public function returnCheck(HpsCheck $check, $amount, $clientTransactionId = null)
    {
        //TODO: implement replacement
        throw new HpsException('Check action RETURN not currently supported');
        return $this->_buildTransaction('RETURN', $check, $amount, $clientTransactionId);
    }
1330952
public RefundQuery refundQueryByRefundId(String refundId) {
        RefundQueryRequestWrapper refundQueryRequestWrapper = new RefundQueryRequestWrapper();
        refundQueryRequestWrapper.setRefundId(refundId);
        return refundQuery(refundQueryRequestWrapper);
    }
257037
protected static function deleteRefundTransactionByIdAsyncWithHttpInfo($refund_transaction_id) 
    {
        $returnType = '';  
        $request = self::deleteRefundTransactionByIdRequest($refund_transaction_id); 

        return self::getHttpClient()
            ->sendAsync($request, self::createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    return [null, $response->getStatusCode(), $response->getHeaders()];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        $response->getBody()
                    );
                }
            );
    }
274342
public static RefundqueryResult payRefundquery(Refundquery refundquery,String key){
		Map<String,String> map = MapUtil.objectToMap(refundquery);
		String sign = SignatureUtil.generateSign(map,refundquery.getSign_type(),key);
		refundquery.setSign(sign);
		String refundqueryXML = XMLConverUtil.convertToXML(refundquery);
		HttpUriRequest httpUriRequest = RequestBuilder.post()
				.setHeader(xmlHeader)
				.setUri(baseURI()+ "/pay/refundquery")
				.setEntity(new StringEntity(refundqueryXML,Charset.forName("utf-8")))
				.build();
		return LocalHttpClient.executeXmlResult(httpUriRequest,RefundqueryResult.class,refundquery.getSign_type(),key);
	}
163639
function(storeName, transaction, cb) {
    try {
      return transaction.objectStore(storeName);
    } catch (err) {
      if (isFunction(cb)) return cb(err);
    }
  }
1084814
public function refund(
        $orderNo,
        $refundNo,
        $totalFee,
        $refundFee = null,
        $opUserId = null,
        $type = self::OUT_TRADE_NO,
        $refundAccount = 'REFUND_SOURCE_UNSETTLED_FUNDS'
    ) {
        $params = [
            $type             => $orderNo,
            'out_refund_no'   => $refundNo,
            'total_fee'       => $totalFee,
            'refund_fee'      => $refundFee ?: $totalFee,
            'refund_fee_type' => $this->merchant->fee_type,
            'refund_account'  => $refundAccount,
            'op_user_id'      => $opUserId ?: $this->merchant->merchant_id,
        ];

        return $this->safeRequest(self::API_REFUND, $params);
    }
461578
public function create($orderId, Refund &$refund)
    {
        $data = $refund->exportData();
        $endpoint = '/admin/orders/'.$orderId.'/refunds.json';
        $response = $this->request(
            $endpoint, 'POST', array(
            'refund' => $data
            )
        );
        $refund->setData($response['refund']);
    }
465843
public ECheck create(ECheck eCheck) throws BaseException {

		logger.debug("Enter ECheckService::create");
		
		// prepare API url
		String apiUrl = requestContext.getBaseUrl() + "echecks".replaceAll("\\{format\\}", "json");
		logger.info("apiUrl - " + apiUrl);
		
		// assign TypeReference for deserialization
		TypeReference<ECheck> typeReference = new TypeReference<ECheck>() {
		};

		// prepare service request
		Request request = new Request.RequestBuilder(MethodType.POST, apiUrl).requestObject(eCheck)
				.typeReference(typeReference).context(requestContext).build();

		// make API call
		Response response = sendRequest(request);

		// retrieve response
		ECheck eCheckResponse = (ECheck) response.getResponseObject();

		// set additional attributes
		prepareResponse(request, response, eCheckResponse);
		return eCheckResponse;
	}
343960
def request_refund(options = {})
      response = JSON.parse(@client.patch("items/#{send(:id)}/request_refund", options).body)
      @attributes = response['items']
      true
    end
912589
def update_refund(self, refund_id, refund_deets):
        """"""
        request = self._put('transactions/refunds/' + str(refund_id), refund_deets)
        return self.responder(request)
1159941
def refund_order(self, order_id, **params):
        """"""
        for required in ['currency']:
            if required not in params:
                raise ValueError("Missing required parameter: %s" % required)
        response = self._post('v2', 'orders', order_id, 'refund', data=params)
        return self._make_api_object(response, Order)
1276581
protected void returnToPool() {
        CacheEntryPool cep = cacheEntryPool;
        // An assertion failure here means this CE is being
        // returned to the pool while in use and this
        // should never be the case;
        assert refCount.get() == 0;
        if (lruHead != null)
            lruHead.remove(this);
        reset();
        cep.add(this);
    }
224107
async function refund(ctx) {
  let order = ctx.state.order;
  let body = ctx.state.body || ctx.request.body;
  let orderId = body.order || ctx.request.body.order;
  let reason = body.reason || ctx.request.body.reason;
  let amount = body.amount || ctx.request.body.amount;
  if (!orderId && !order || ctx.method !== 'POST') _2.default.error(400);
  if (!ctx.user) _2.default.error(403);
  if (!reason) _2.default.error('Invalid refund reason');
  if (!order) {
    // $Flow
    let orderTmp = await _Order2.default.findById(orderId).where('user', ctx.user._id);
    order = orderTmp;
    if (!order) _2.default.error('Order not found');
    if (order.state !== 400 && order.state !== 500) _2.default.error('Order state error');
  }
  if (!amount) {
    amount = order.payed;
  }
  if (amount > order.payed) _2.default.error('Invalid refund amount');
  await _2.default.run('Refund', {
    ctx, order, reason, amount
  });
  ctx.body = order.data();
}
812252
public function execute($iAmount)
    {
        //  Ensure we have a driver
        if (empty($this->oDriver)) {
            throw new RefundRequestException('No driver selected.', 1);
        }

        //  Ensure we have a payment
        if (empty($this->oPayment)) {
            throw new RefundRequestException('No payment selected.', 1);
        }

        //  Ensure we have an invoice
        if (empty($this->oInvoice)) {
            $this->setInvoice($this->oPayment->invoice->id);
        }

        //  Validate ability to refund
        if (!$this->oPayment->is_refundable) {
            if ($this->oPayment->available_for_refund->raw === 0) {
                throw new RefundRequestException('Payment is already fully refunded.', 1);
            } else {
                throw new RefundRequestException('Payment is not in a state where it can be refunded.', 1);
            }
        }

        $iRefundAmount = is_null($iAmount) ? $this->oPayment->available_for_refund->raw : $iAmount;

        if (empty($iRefundAmount)) {
            throw new RefundRequestException('Refund amount must be greater than 0.', 1);
        }

        //  Validate refund amount
        if ($iRefundAmount > $this->oPayment->available_for_refund->raw) {
            throw new RefundRequestException(
                'Requested refund amount is greater than the value of the remaining payment balance (' .
                $this->oPayment->available_for_refund->formatted . ').',
                1
            );
        }

        //  Create a refund against the payment if one hasn't been specified
        if (empty($this->oRefund)) {

            $iRefundId = $this->oRefundModel->create([
                'reason'     => $this->getReason(),
                'payment_id' => $this->oPayment->id,
                'invoice_id' => $this->oInvoice->id,
                'currency'   => $this->oPayment->currency->code,
                'amount'     => $iRefundAmount,
            ]);

            if (empty($iRefundId)) {
                throw new RefundRequestException('Failed to create new refund.', 1);
            }

            $this->setRefund($iRefundId);
        }

        //  Execute the refund
        $oRefundResponse = $this->oDriver->refund(
            $this->oPayment->txn_id,
            $iAmount,
            $this->oPayment->currency->code,
            $this->oPayment->custom_data,
            $this->getReason(),
            $this->oPayment,
            $this->oInvoice
        );

        //  Validate driver response
        if (empty($oRefundResponse)) {
            throw new RefundRequestException('Response from driver was empty.', 1);
        }

        if (!($oRefundResponse instanceof RefundResponse)) {
            throw new RefundRequestException(
                'Response from driver must be an instance of \Nails\Invoice\Factory\RefundResponse.',
                1
            );
        }

        if ($oRefundResponse->isComplete()) {

            //  Driver has confirmed that the refund was accepted
            $this->setRefundComplete(
                $oRefundResponse->getTxnId(),
                $oRefundResponse->getFee()
            );

        } elseif ($oRefundResponse->isFailed()) {

            //  Update the payment
            $sRefundClass = get_class($this->oRefundModel);
            $bResult      = $this->oRefundModel->update(
                $this->oRefund->id,
                [
                    'status'    => $sRefundClass::STATUS_FAILED,
                    'fail_msg'  => $oRefundResponse->getError()->msg,
                    'fail_code' => $oRefundResponse->getError()->code,
                ]
            );

            if (empty($bResult)) {
                throw new RefundRequestException('Failed to update existing payment.', 1);
            }
        }

        //  Lock the response so it cannot be altered
        $oRefundResponse->lock();

        return $oRefundResponse;
    }
262807
def fetch(self, refund_id, data={}, **kwargs):
        "
        return super(Refund, self).fetch(refund_id, data, **kwargs)
1283708
@Override
    public void rollback() throws DataCorruptedException, IOException, IllegalStateException
    {
        try {
            this.txContext.abort();
        } catch (final Exception e) {
            throw new DataCorruptedException("Error trying to rollback a Transaction.", e);
        }
    }