/**
  * @param \Ilis\Bundle\PaymentBundle\Entity\Transaction\CreditCard $transaction
  */
 public function capture(CreditCardTransaction $transaction)
 {
     if (!is_numeric($transaction->getAmount()) || $transaction->getAmount() <= 0) {
         throw new Exception("Invalid amount");
     }
     // TODO: Check if the transaction has set the proper payment method
     $request = new WsRequest();
     $request->setOrder($transaction->getId());
     $amount = (double) number_format($transaction->getAmount(), 2, '.', '') * 100;
     $request->setAmount($amount);
     $request->setOrder($transaction->getIdentifier());
     $request->setMerchantCode($this->merchant->getCode());
     $request->setTerminal($this->merchant->getTerminal());
     $request->setCurrency($this->merchant->getCurrency());
     $request->setPan($transaction->creditCard);
     $request->setCvv2($transaction->cvv);
     $request->setExpiryDate(sprintf("%s%s", $transaction->expiryDateYear, $transaction->expiryDateMonth));
     $request->setTransactionType(WsTransaction::TYPE_AUTH);
     $this->merchant->signRequest($request);
     $response = $this->client->makeRequest($request);
     $operation = $response->getOperation();
     $authCode = $operation ? trim((string) $operation->Ds_AuthorisationCode) : null;
     if ($response->isValid() && !empty($authCode)) {
         $transaction->setStatus(Transaction::STATUS_SUCCESS);
         $transaction->setAuthCode((string) $response->getOperation()->Ds_AuthorisationCode);
     } else {
         $transaction->setStatus(Transaction::STATUS_ERROR);
         $transaction->setStatusCode((string) $response->getCode());
     }
     $transaction->setRawData($response->asXml());
 }
 /**
  * Sign a Webservice Request
  * 
  * @param Request $request
  * @return void
  * 
  */
 public function signRequest(Request $request)
 {
     $txt = '';
     if ($request->hasAmount()) {
         $txt .= $request->getAmount();
     }
     if ($request->hasOrder()) {
         $txt .= $request->getOrder();
     }
     if ($request->hasMerchantCode()) {
         $txt .= $request->getMerchantCode();
     }
     if ($request->hasCurrency()) {
         $txt .= $request->getCurrency();
     }
     switch ($request->getTransactionType()) {
         case Transaction::TYPE_AUTH:
         case Transaction::TYPE_PREAUTH:
         case Transaction::TYPE_AUTH_DEFERRED:
             if ($request->hasPan()) {
                 $txt .= $request->getPan();
             }
             if ($request->hasCvv2()) {
                 $txt .= $request->getCvv2();
             }
             break;
         case Transaction::TYPE_RECURRING_AUTH_INITIAL:
         case Transaction::TYPE_RECURRING_AUTH_DEFERRED_INTITIAL:
             if ($request->hasPan()) {
                 $txt .= $request->getPan();
             }
             if ($request->hasSumtotal()) {
                 $txt .= $request->getSumtotal();
             }
             if ($request->hasCvv2()) {
                 $txt .= $request->getCvv2();
             }
             break;
         case Transaction::TYPE_FULLFILL:
         case Transaction::TYPE_VOID:
         case Transaction::TYPE_RECURRING_AUTH:
         case Transaction::TYPE_CANCEL:
         case Transaction::TYPE_FULLFILL_DEFERRED:
         case Transaction::TYPE_CANCEL_DEFERRED:
         case Transaction::TYPE_RECURRING_AUTH_DEFERRED:
             // Nothing to add here
             break;
     }
     // Append Transaction Type
     $txt .= $request->getTransactionType();
     // Append Secret Key
     $txt .= $this->getSecretKey();
     // Calculate hash
     $signature = sha1($txt);
     // Sign Request
     $request->setSignature($signature);
 }