/** * @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()); }