Skip to content

Commit

Permalink
#50 kur kodu ile ilgili sabitler kod tabanindan kaldirildi.
Browse files Browse the repository at this point in the history
  • Loading branch information
ibrahimgunduz34 committed Mar 15, 2014
1 parent 3862d7f commit 70bc636
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 27 deletions.
52 changes: 26 additions & 26 deletions src/Paranoia/Payment/Adapter/AdapterAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,14 @@
use Paranoia\Payment\Response;
use Paranoia\Payment\TransferInterface;
use Paranoia\Payment\Exception\UnknownTransactionType;

use Paranoia\Payment\Exception\UnknownCurrencyCode;
use Paranoia\Payment\Exception\ConfigurationError;
use Paranoia\Communication\Connector;

use Paranoia\EventManager\EventManagerAbstract;

abstract class AdapterAbstract extends EventManagerAbstract
{
const CURRENCY_TRY = 'TRY';
const CURRENCY_USD = 'USD';
const CURRENCY_EUR = 'EUR';

const EVENT_ON_TRANSACTION_SUCCESSFUL = 'OnTransactionSuccessful';
const EVENT_ON_TRANSACTION_FAILED = 'OnTransactionFailed';
const EVENT_ON_EXCEPTION = 'OnException';
Expand Down Expand Up @@ -49,48 +46,49 @@ public function __construct(StdClass $config)
/**
* build request data for preauthorization transaction.
*
* @param \Payment\Request $request
* @param \Paranoia\Payment\Request $request
* @return mixed
*/
abstract protected function _buildPreauthorizationRequest(Request $request);

/**
* build request data for postauthorization transaction.
*
* @param \Payment\Request $request
* @param \Paranoia\Payment\Request $request
* @return mixed
*/
abstract protected function _buildPostAuthorizationRequest(Request $request);

/**
* build request data for sale transaction.
*
* @param \Payment\Request $request
* @param \Paranoia\Payment\Request $request
* @return mixed
*/
abstract protected function _buildSaleRequest(Request $request);

/**
* build request data for refund transaction.
*
* @param \Payment\Request $request
* @param \Paranoia\Payment\Request $request
* @return mixed
*/
abstract protected function _buildRefundRequest(Request $request);

/**
* build request data for cancel transaction.
*
* @param \Payment\Request $request
* @param \Paranoia\Payment\Request $request
* @return mixed
*/
abstract protected function _buildCancelRequest(Request $request);

/**
* build complete raw data for the specified request.
*
* @param \Payment\Request
* @param \Paranoia\Payment\Request $request
* @param string $requestBuilder
* @internal param $ \Payment\Request
* @return mixed
*/
abstract protected function _buildRequest(Request $request, $requestBuilder);
Expand All @@ -99,14 +97,14 @@ abstract protected function _buildRequest(Request $request, $requestBuilder);
* parses response from returned provider.
*
* @param string $rawResponse
* @return \Payment\Response\PaymentResponse
* @return \Paranoia\Payment\Response\PaymentResponse
*/
abstract protected function _parseResponse($rawResponse);

/**
* returns connector object.
*
* @return \Communication\Adapter\AdapterInterface
* @return \Paranoia\Communication\Adapter\AdapterInterface
*/
public function getConnector()
{
Expand All @@ -119,14 +117,14 @@ public function getConnector()
* @param string $url
* @param mixed $data
* @param array $options
* @throws \ErrorException|\Exception
* @return mixed
*/
protected function _sendRequest($url, $data, $options=null)
{
try {
return $this->getConnector()->sendRequest($url, $data, $options);
} catch(\ErrorException $e) {
$backtrace = debug_backtrace();
$this->_triggerEvent(self::EVENT_ON_EXCEPTION,
array('exception' => $e,
'request' => $this->_maskRequest($this->getConnector()->getLastSentRequest()),
Expand All @@ -138,20 +136,21 @@ protected function _sendRequest($url, $data, $options=null)
/**
* formats the specified string currency code by iso currency codes.
* @param string $currency
* @throws \Paranoia\Payment\Exception\ConfigurationError
* @throws \Paranoia\Payment\Exception\UnknownCurrencyCode
* @return integer
*/
protected function _formatCurrency($currency)
{
switch($currency) {
case self::CURRENCY_TRY:
return '949';
case self::CURRENCY_USD:
return '840';
case self::CURRENCY_EUR:
return '978';
default:
return '949';
if(!property_exists($this->_config, 'currencyCodes')) {
throw new ConfigurationError(
'Currency codes are not defined in configuration.'
);
}
if(!property_exists($this->_config->currencyCodes, $currency)) {
throw new UnknownCurrencyCode(sprintf('%s is unknown currency.', $currency));
}
return $this->_config->currencyCodes->{$currency};
}

/**
Expand Down Expand Up @@ -193,7 +192,7 @@ protected function _formatInstallment($installment)

/**
* stamps transfer objects with time and transaction type.
* @param \Payment\TransferInterface $transfer
* @param \Paranoia\Payment\TransferInterface $transfer
* @param string $transactionType
*/
private function _stamp(TransferInterface $transfer, $transactionType)
Expand All @@ -205,8 +204,9 @@ private function _stamp(TransferInterface $transfer, $transactionType)
/**
* returns transaction code by expected provider.
*
* @param string $transcationType
* @throws UnknownTransactionType
* @param $transactionType
* @throws \Paranoia\Payment\Exception\UnknownTransactionType
* @internal param string $transcationType
* @return string
*/
protected function _getProviderTransactionType($transactionType)
Expand Down
1 change: 0 additions & 1 deletion src/Paranoia/Payment/Adapter/Est.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ protected function _buildSaleRequest(Request $request)
protected function _buildRefundRequest(Request $request)
{
$amount = $this->_formatAmount($request->getAmount());
$installment = $this->_formatInstallment($request->getInstallment());
$currency = $this->_formatCurrency($request->getCurrency());
$type = $this->_getProviderTransactionType($request->getTransactionType());
$requestData = array('Type' => $type,
Expand Down
10 changes: 10 additions & 0 deletions src/Paranoia/Payment/Exception/ConfigurationError.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
namespace Paranoia\Payment\Exception {

use \ErrorException;

class ConfigurationError extends ErrorException
{

}
}
10 changes: 10 additions & 0 deletions src/Paranoia/Payment/Exception/UnknownCurrencyCode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
namespace Paranoia\Payment\Exception {

use \ErrorException;

class UnknownCurrencyCode extends ErrorException
{

}
}
10 changes: 10 additions & 0 deletions tests/Resources/config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
"cvv": "000",
"expire_month": "12",
"expire_year": "2015"
},
"currencyCodes": {
"TRY": 949,
"USD": 840,
"EUR": 978
}
},
"garantibank": {
Expand All @@ -28,6 +33,11 @@
"cvv": "000",
"expire_month": "01",
"expire_year": "2020"
},
"currencyCodes": {
"TRY": 949,
"USD": 840,
"EUR": 978
}
}
}

0 comments on commit 70bc636

Please sign in to comment.