Example #1
0
 /**
  * Capture   Charge.
  * This method allow you to capture the payment of an existing, authorised, Card Charge
  * @param array $param payload param for caputring a charge
  * @return CheckoutApi_Lib_RespondObj
  * @throws Exception
  * Simple usage:
  *      $param['postedParam'] = array ( 'amount'=>150 );
  *      captureCharge = $Api->captureCharge($param);
  */
 public function captureCharge($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);
     $uri = $this->getUriCharge();
     if (!$isChargeIdValid) {
         $hasError = true;
         $this->throwException('Please provide a valid charge id', array('param' => $param));
     } else {
         $uri = "{$uri}/{$param['chargeId']}/capture";
     }
     if (!$isAmountValid) {
         $this->throwException('Please provide a amount (in cents)', array('param' => $param), false);
     }
     return $this->request($uri, $param, !$hasError);
     return $this->__responseUpdateStatus($this->request($this->getUriCharge(), $param, !$hasError));
 }