/** * @param array $parameters * * @return string */ protected function getStringToHash(array $parameters) { $stringToHash = ''; $parameters = array_change_key_case($parameters, CASE_UPPER); foreach (self::$acceptableFields as $acceptableField) { if (isset($parameters[strtoupper($acceptableField)]) && (string) $parameters[strtoupper($acceptableField)] !== '') { $stringToHash .= sprintf('%s=%s%s', strtoupper($acceptableField), $parameters[strtoupper($acceptableField)], $this->token->getShaout()); } } return $stringToHash; }
/** * Perform direct online payment operations * * @param FinancialTransactionInterface $transaction * * @return \ETS\Payment\OgoneBundle\Response\DirectResponse */ protected function getDirectResponse(FinancialTransactionInterface $transaction) { $apiData = array('PSPID' => $this->token->getPspid(), 'USERID' => $this->token->getApiUser(), 'PSWD' => $this->token->getApiPassword(), 'ORDERID' => $transaction->getExtendedData()->get('ORDERID')); if ($transaction->getExtendedData()->has('PAYID')) { $apiData['PAYID'] = $transaction->getExtendedData()->get('PAYID'); } return new DirectResponse($this->sendApiRequest($apiData)); }
/** * @param array $parameters * * @return string */ public function generate(array $parameters) { $shainString = ''; // All parameters need to be arranged alphabetically. ksort($parameters); foreach ($parameters as $key => $value) { // Parameters that do not have a value should NOT be included in the string to hash if (empty($value)) { continue; } // All parameter names should be in UPPERCASE (to avoid any case confusion). $key = strtoupper($key); if (in_array($key, static::$allowed, true) || $this->isWildcarded($key)) { $shainString .= sprintf('%s=%s%s', $key, $value, $this->token->getShain()); } } return strtoupper(sha1($shainString)); }
/** * This method executes an approve transaction. * * By an approval, funds are reserved but no actual money is transferred. A * subsequent deposit transaction must be performed to actually transfer the * money. * * A typical use case, would be Credit Card payments where funds are first * authorized. * * @param FinancialTransactionInterface $transaction The transaction * @param boolean $retry Whether this is a retry transaction * * @throws ActionRequiredException If the transaction's state is NEW * @throws FinancialException If payment is not approved * @throws PaymentPendingException If payment is still approving */ public function approve(FinancialTransactionInterface $transaction, $retry) { $this->logger->debug('approving transaction {id} with PAYID {payid}...', array('id' => $transaction->getId(), 'payid' => $transaction->getExtendedData()->get('PAYID'))); if ($transaction->getState() === FinancialTransactionInterface::STATE_NEW) { $this->logger->debug('Transaction is new. Need to be pending'); throw new ActionRequiredException('Transaction needs to be in state 4'); } if (!isset($this->feedbackResponse)) { $this->logger->debug('No feedback response set.'); $params = array('ORDERID' => $transaction->getExtendedData()->get('ORDERID'), 'PAYID' => $transaction->getExtendedData()->get('PAYID'), 'PSPID' => $this->token->getPspid(), 'PSWD' => $this->token->getApiPassword(), 'USERID' => $this->token->getApiUser()); $this->logger->debug('Checking transaction status with Ogone with params {params}', array('params' => $params)); $xmlResponse = $this->sendApiRequest(array(), $this->getDirectQueryUrl() . '?' . http_build_query($params), 'GET'); $response = new BatchResponse($xmlResponse); $this->logger->debug('response status is {status}', array('status' => $response->getStatus())); if ($response->hasError()) { $this->handleUnsuccessfulResponse($response, $transaction); } $transaction->setReferenceNumber($response->getPaymentId()); } else { $this->logger->debug('feedback response set.'); $response = $this->feedbackResponse; } if ($response->isApproving() || $response->isIncomplete()) { $this->logger->debug('response {res} is still approving', array('res' => $response)); throw new PaymentPendingException(sprintf('Payment is still approving, status: %s.', $response->getStatus())); } if (!$response->isApproved()) { $this->logger->debug('response {res} is not approved', array('res' => $response)); $ex = new FinancialException(sprintf('Payment status "%s" is not valid for approvment', $response->getStatus())); $ex->setFinancialTransaction($transaction); $transaction->setResponseCode($response->getErrorCode()); $transaction->setReasonCode($response->getStatus()); throw $ex; } $transaction->setProcessedAmount($response->getAmount()); $transaction->setResponseCode(PluginInterface::RESPONSE_CODE_SUCCESS); $transaction->setReasonCode(PluginInterface::REASON_CODE_SUCCESS); }
public function __construct(TokenInterface $token) { $this->pspId = $token->getPspid(); $this->apiUser = $token->getApiUser(); $this->apiPassword = $token->getApiPassword(); }