Request a refund for an Item.

 @see https://reference.promisepay.com/#request-refund

 @return [Boolean]
343960
def request_refund(options = {})
      response = JSON.parse(@client.patch("items/#{send(:id)}/request_refund", options).body)
      @attributes = response['items']
      true
    end
1144072
def buyer
      response = JSON.parse(@client.get("items/#{send(:id)}/buyers").body)
      Promisepay::User.new(@client, response['users'])
    end
115850
def refund(self, callerReference, transactionId, refundAmount=None,
               callerDescription=None):
        
        params = {}
        params['CallerReference'] = callerReference
        params['TransactionId'] = transactionId
        if(refundAmount != None):
            params['RefundAmount'] = refundAmount
        if(callerDescription != None):
            params['CallerDescription'] = callerDescription
        
        response = self.make_request("Refund", params)
        body = response.read()
        if(response.status == 200):
            rs = ResultSet()
            h = handler.XmlHandler(rs, self)
            xml.sax.parseString(body, h)
            return rs
        else:
            raise FPSResponseError(response.status, response.reason, body)
376619
def delete_refund(self, refund_id):
        """"""
        request = self._delete('transactions/refunds/' + str(refund_id))
        return self.responder(request)
839761
public RefundResponse refund(RefundRequest refundRequest) {
        RefundRequestWrapper wrapper = new RefundRequestWrapper();
        wrapper.setRequest(refundRequest);
        setBaseSettings(wrapper);

        SortedMap<String, Object> refundRequestMap = JsonMapper.nonEmptyMapper().getMapper().convertValue(wrapper, SortedMap.class);
        sign(wrapper, refundRequestMap);

        String url = WxEndpoint.get("url.pay.payment.refund.refund");
        try {
            String xml = XmlObjectMapper.nonEmptyMapper().toXml(wrapper);
            logger.info("支付 refund request: {}", xml);
            String response = wxSslClient.post(url, xml);
            logger.info("支付 refund response: {}", response);

            RefundResponseWrapper responseWrapper = XmlObjectMapper.defaultMapper().fromXml(response, RefundResponseWrapper.class);
            return responseWrapper.getResponse();
        } catch (Exception e) {
            throw new WxRuntimeException(999, "refund failed:" + e.getMessage());
        }
    }
455579
def and_return(response=nil, &block)
      new_response = (response.nil? ? block : response)
      responses.push(*new_response)
    end
842696
def clean_total_refund_amount(self):
        '''
        
        '''
        initial = self.cleaned_data.get('initial_refund_amount', 0)
        total = self.cleaned_data['total_refund_amount']
        summed_refunds = sum([v for k,v in self.cleaned_data.items() if k.startswith('item_refundamount_')])

        if not self.cleaned_data.get('id'):
            raise ValidationError('ID not in cleaned data')

        if summed_refunds != total:
            raise ValidationError(_('Passed value does not match sum of allocated refunds.'))
        elif summed_refunds > self.cleaned_data['id'].amountPaid + self.cleaned_data['id'].refunds:
            raise ValidationError(_('Total refunds allocated exceed revenue received.'))
        elif total < initial:
            raise ValidationError(_('Cannot reduce the total amount of the refund.'))
        return total
699399
def admin_refund
      return if !user_is_allowed('orders', 'edit')
    
      response = Caboose::StdClass.new({
        'refresh' => nil,
        'error' => nil,
        'success' => nil
      })
    
      order = Order.find(params[:id])
    
      if order.financial_status != 'captured'
        response.error = "This order hasn't been captured yet, you will need to void instead"
      else
        if PaymentProcessor.refund(order)
          order.update_attributes(
            :financial_status => 'refunded',
            :status => 'cancelled'
          )
          
          response.success = 'Order refunded successfully'
        else
          response.error = 'Error refunding order'
        end
        
        #if order.calculate_net < (order.amount_discounted || 0) || PaymentProcessor.refund(order)
        #  order.financial_status = 'refunded'
        #  order.status = 'refunded'
        #  order.save
        #  
        #  if order.discounts.any?
        #    discount = order.discounts.first
        #    amount_to_refund = order.calculate_net < order.amount_discounted ? order.calculate_net : order.amount_discounted
        #    discount.update_attribute(:amount_current, amount_to_refund + discount.amount_current)
        #  end
        #  
        #  response.success = "Order refunded successfully"
        #else
        #  response.error = "Error refunding order."
        #end
      end
    
      render json: response
      
      # return if !user_is_allowed('orders', 'edit')
      #     
      # response = Caboose::StdClass.new({
      #   'refresh' => nil,
      #   'error' => nil,
      #   'success' => nil
      # })
      #     
      # order = Order.find(params[:id])
      #     
      # if order.financial_status != 'captured'
      #   response.error = "This order hasn't been captured yet, you will need to void instead"
      # else
      #   if PaymentProcessor.refund(order)
      #     order.financial_status = 'refunded'
      #     order.status = 'refunded'
      #     order.save
      #     
      #     # Add the variant quantities ordered back
      #     order.cancel
      #     
      #     response.success = "Order refunded successfully"
      #   else
      #     response.error = "Error refunding order."
      #   end
      # end
      #     
      # render :json => response
    end
53329
public function getRefundResult()
    {
        $responseVariables = get_object_vars($this->getResponse());
        if (!array_key_exists('refundResult', $responseVariables)) {
            return new RefundResult();
        }
        $refundResult = $responseVariables['refundResult'];
        if (!($refundResult instanceof RefundResult)) {
            return new RefundResult();
        }
        return $refundResult;
    }
362995
def cancel(refund)
      unless @is_valid
        return make_response_with_exception(Exceptions::APIKeyInvalidException.new('API key, password or Rapid endpoint missing or invalid'), RefundResponse)
      end
      begin
        url = @web_url + Constants::CANCEL_AUTHORISATION_METHOD

        request = Message::RefundProcess::CancelAuthorisationMsgProcess.create_request(refund)
        response = Message::RefundProcess::CancelAuthorisationMsgProcess.send_request(url, @api_key, @password, @version, request)
        Message::RefundProcess::CancelAuthorisationMsgProcess.make_result(response)
      rescue => e
        @logger.error(e.to_s) if @logger
        make_response_with_exception(e, RefundResponse)
      end
    end
426345
private function doRefund($refund)
    {
        /** @var Refund $refund */
        $refund = ClassValidator::getInstance('Eway\Rapid\Model\Refund', $refund);

        return $this->getHttpService()->postTransactionRefund($refund->Refund->TransactionID, $refund->toArray());
    }
577858
def make_payment(options = {})
      response = JSON.parse(@client.patch("items/#{send(:id)}/make_payment", options).body)
      @attributes = response['items']
      true
    end
797907
def list_refunds(self, params=None):
        """"""
        request = self._get('transactions/refunds', params)
        return self.responder(request)
334508
def return! request = nil, result = nil, & block
      if (200..207).include? code
        self
      elsif [301, 302, 307].include? code
        unless [:get, :head].include? args[:method]
          raise Exceptions::EXCEPTIONS_MAP[code].new(self, code)
        else
          follow_redirection(request, result, & block)
        end
      elsif code == 303
        args[:method] = :get
        args.delete :payload
        follow_redirection(request, result, & block)
      elsif Exceptions::EXCEPTIONS_MAP[code]
        raise Exceptions::EXCEPTIONS_MAP[code].new(self, code)
      else
        raise RequestFailed.new(self, code)
      end
    end
70031
def refund_order(self, request, pk):
        
        order = Order.objects.get(id=pk)
        order.refund()
        return Response(status=status.HTTP_204_NO_CONTENT)
270858
def to_request(new_input = Undefined)
      new_input.equal?(Undefined) ? self : self.class.new(name, env, new_input)
    end
342343
def query(self, refund_id=None, out_refund_no=None, transaction_id=None,
              out_trade_no=None, device_info=None):
        
        data = {
            'appid': self.appid,
            'device_info': device_info,
            'transaction_id': transaction_id,
            'out_trade_no': out_trade_no,
            'out_refund_no': out_refund_no,
            'refund_id': refund_id,
        }
        return self._post('pay/refundquery', data=data)