original_string: public function  refundCharge($param)
      {
          $chargeHistory = $this->getChargeHistory($param);
          $charges = $chargeHistory->getCharges();
          $uri = $this->getUriCharge();
  
          if(!empty($charges)) {
            $chargesArray = $charges->toArray();
            $toRefund = false;
            $toVoid = false;
            $toRefundData = false;
            $toVoidData = false;
            
            foreach ($chargesArray as $key=> $charge) {
              if (in_array(CheckoutApi_Client_Constant::STATUS_CAPTURE, $charge) 
  				|| in_array(CheckoutApi_Client_Constant::STATUS_REFUND,$charge)){    
                  if(strtolower($charge['status']) == strtolower(CheckoutApi_Client_Constant::STATUS_CAPTURE)) {
                    $toRefund = true;
                    $toRefundData = $charge;
                    break;
                }
              }
              else {
                  $toVoid = true;
                  $toVoidData = $charge;
                }
            }
  
            if($toRefund) {
                $refundChargeId = $toRefundData['id'];
                $param['chargeId'] = $refundChargeId;
                $uri = "$uri/{$param['chargeId']}/refund";
            }
  
            if($toVoid) {
                $voidChargeId = $toVoidData['id'];
                $param['chargeId'] = $voidChargeId;
                $uri = "$uri/{$param['chargeId']}/void";
            }
          }
          else {
            $this->throwException('Please provide a valid charge id',array('param'=>$param));
          }
  
          $hasError = false;
          $param['postedParam']['type'] = CheckoutApi_Client_Constant::CHARGE_TYPE;
  
          $param['method'] = CheckoutApi_Client_Adapter_Constant::API_POST;
          $postedParam = $param['postedParam'];
          
          $this->flushState();
          $isAmountValid = CheckoutApi_Client_Validation_GW3::isValueValid($postedParam);
          $isChargeIdValid = CheckoutApi_Client_Validation_GW3::isChargeIdValid($param);
  
          if(!$isChargeIdValid) {
              $hasError = true;
              $this->throwException('Please provide a valid charge id',array('param'=>$param));
  
          }
          
          if(!$isAmountValid) {
               $this->throwException('Please provide a amount (in cents)',array('param'=>$param),false);
          }
           return $this->_responseUpdateStatus($this->request($uri ,$param,!$hasError));
      }
code: public function  refundCharge($param)
      {
          $chargeHistory = $this->getChargeHistory($param);
          $charges = $chargeHistory->getCharges();
          $uri = $this->getUriCharge();
  
          if(!empty($charges)) {
            $chargesArray = $charges->toArray();
            $toRefund = false;
            $toVoid = false;
            $toRefundData = false;
            $toVoidData = false;
            
            foreach ($chargesArray as $key=> $charge) {
              if (in_array(CheckoutApi_Client_Constant::STATUS_CAPTURE, $charge) 
  				|| in_array(CheckoutApi_Client_Constant::STATUS_REFUND,$charge)){    
                  if(strtolower($charge['status']) == strtolower(CheckoutApi_Client_Constant::STATUS_CAPTURE)) {
                    $toRefund = true;
                    $toRefundData = $charge;
                    break;
                }
              }
              else {
                  $toVoid = true;
                  $toVoidData = $charge;
                }
            }
  
            if($toRefund) {
                $refundChargeId = $toRefundData['id'];
                $param['chargeId'] = $refundChargeId;
                $uri = "$uri/{$param['chargeId']}/refund";
            }
  
            if($toVoid) {
                $voidChargeId = $toVoidData['id'];
                $param['chargeId'] = $voidChargeId;
                $uri = "$uri/{$param['chargeId']}/void";
            }
          }
          else {
            $this->throwException('Please provide a valid charge id',array('param'=>$param));
          }
  
          $hasError = false;
          $param['postedParam']['type'] = CheckoutApi_Client_Constant::CHARGE_TYPE;
  
          $param['method'] = CheckoutApi_Client_Adapter_Constant::API_POST;
          $postedParam = $param['postedParam'];
          
          $this->flushState();
          $isAmountValid = CheckoutApi_Client_Validation_GW3::isValueValid($postedParam);
          $isChargeIdValid = CheckoutApi_Client_Validation_GW3::isChargeIdValid($param);
  
          if(!$isChargeIdValid) {
              $hasError = true;
              $this->throwException('Please provide a valid charge id',array('param'=>$param));
  
          }
          
          if(!$isAmountValid) {
               $this->throwException('Please provide a amount (in cents)',array('param'=>$param),false);
          }
           return $this->_responseUpdateStatus($this->request($uri ,$param,!$hasError));
      }
code_tokens: public function refundCharge ( $ param ) { $ chargeHistory = $ this -> getChargeHistory ( $ param ) ; $ charges = $ chargeHistory -> getCharges ( ) ; $ uri = $ this -> getUriCharge ( ) ; if ( ! empty ( $ charges ) ) { $ chargesArray = $ charges -> toArray ( ) ; $ toRefund = false ; $ toVoid = false ; $ toRefundData = false ; $ toVoidData = false ; foreach ( $ chargesArray as $ key => $ charge ) { if ( in_array ( CheckoutApi_Client_Constant :: STATUS_CAPTURE , $ charge ) || in_array ( CheckoutApi_Client_Constant :: STATUS_REFUND , $ charge ) ) { if ( strtolower ( $ charge [ 'status' ] ) == strtolower ( CheckoutApi_Client_Constant :: STATUS_CAPTURE ) ) { $ toRefund = true ; $ toRefundData = $ charge ; break ; } } else { $ toVoid = true ; $ toVoidData = $ charge ; } } if ( $ toRefund ) { $ refundChargeId = $ toRefundData [ 'id' ] ; $ param [ 'chargeId' ] = $ refundChargeId ; $ uri = "$uri/{$param['chargeId']}/refund" ; } if ( $ toVoid ) { $ voidChargeId = $ toVoidData [ 'id' ] ; $ param [ 'chargeId' ] = $ voidChargeId ; $ uri = "$uri/{$param['chargeId']}/void" ; } } else { $ this -> throwException ( 'Please provide a valid charge id' , array ( 'param' => $ param ) ) ; } $ hasError = false ; $ param [ 'postedParam' ] [ 'type' ] = CheckoutApi_Client_Constant :: CHARGE_TYPE ; $ param [ 'method' ] = CheckoutApi_Client_Adapter_Constant :: API_POST ; $ postedParam = $ param [ 'postedParam' ] ; $ this -> flushState ( ) ; $ isAmountValid = CheckoutApi_Client_Validation_GW3 :: isValueValid ( $ postedParam ) ; $ isChargeIdValid = CheckoutApi_Client_Validation_GW3 :: isChargeIdValid ( $ param ) ; if ( ! $ isChargeIdValid ) { $ hasError = true ; $ this -> throwException ( 'Please provide a valid charge id' , array ( 'param' => $ param ) ) ; } if ( ! $ isAmountValid ) { $ this -> throwException ( 'Please provide a amount (in cents)' , array ( 'param' => $ param ) , false ) ; } return $ this -> _responseUpdateStatus ( $ this -> request ( $ uri , $ param , ! $ hasError ) ) ; }
docstring: Refund  Charge
  This method refunds a Card Charge that has previously been created but not yet refunded
  or void a charge that has been capture
  
  @param array $param payload param for refund a charge
  @return CheckoutApi_Lib_RespondObj
  @throws Exception
  Simple usage:
  $param['postedParam'] = array (
  'value'=>150
  );
  $refundCharge = $Api->refundCharge($param);
docstring_tokens: Refund Charge This method refunds a Card Charge that has previously been created but not yet refunded or void a charge that has been capture