Skip to content

Commit

Permalink
Make config file dynamic
Browse files Browse the repository at this point in the history
  • Loading branch information
akoSalman committed Nov 9, 2019
1 parent 935f95e commit 0b17a80
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 78 deletions.
22 changes: 11 additions & 11 deletions src/Asanpardakht/Asanpardakht.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function setCallback($url)
function getCallback()
{
if (!$this->callbackUrl)
$this->callbackUrl = $this->config->get('gateway.asanpardakht.callback-url');
$this->callbackUrl = $this->config['asanpardakht']['callback-url'];

$url = $this->makeCallback($this->callbackUrl, ['transaction_id' => $this->transactionId()]);

Expand All @@ -115,8 +115,8 @@ protected function sendPayRequest()
{
$this->newTransaction();

$username = $this->config->get('gateway.asanpardakht.username');
$password = $this->config->get('gateway.asanpardakht.password');
$username = $this->config['asanpardakht']['username'];
$password = $this->config['asanpardakht']['password'];
$orderId = $this->transactionId();
$price = $this->amount;
$localDate = date("Ymd His");
Expand All @@ -126,7 +126,7 @@ protected function sendPayRequest()

$encryptedRequest = $this->encrypt($req);
$params = array(
'merchantConfigurationID' => $this->config->get('gateway.asanpardakht.merchantConfigId'),
'merchantConfigurationID' => $this->config['asanpardakht']['merchantConfigId'],
'encryptedRequest' => $encryptedRequest
);

Expand Down Expand Up @@ -202,12 +202,12 @@ protected function userPayment()
protected function verifyAndSettlePayment()
{

$username = $this->config->get('gateway.asanpardakht.username');
$password = $this->config->get('gateway.asanpardakht.password');
$username = $this->config['asanpardakht']['username'];
$password = $this->config['asanpardakht']['password'];

$encryptedCredintials = $this->encrypt("{$username},{$password}");
$params = array(
'merchantConfigurationID' => $this->config->get('gateway.asanpardakht.merchantConfigId'),
'merchantConfigurationID' => $this->config['asanpardakht']['merchantConfigId'],
'encryptedCredentials' => $encryptedCredintials,
'payGateTranID' => $this->trackingCode
);
Expand Down Expand Up @@ -260,8 +260,8 @@ protected function verifyAndSettlePayment()
private function encrypt($string = "")
{

$key = $this->config->get('gateway.asanpardakht.key');
$iv = $this->config->get('gateway.asanpardakht.iv');
$key = $this->config['asanpardakht']['key'];
$iv = $this->config['asanpardakht']['iv'];

try {

Expand Down Expand Up @@ -289,8 +289,8 @@ private function encrypt($string = "")
*/
private function decrypt($string = "")
{
$key = $this->config->get('gateway.asanpardakht.key');
$iv = $this->config->get('gateway.asanpardakht.iv');
$key = $this->config['asanpardakht']['key'];
$iv = $this->config['asanpardakht']['iv'];

try {

Expand Down
17 changes: 11 additions & 6 deletions src/GatewayResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class GatewayResolver
protected $request;

/**
* @var Config
* @var array Config
*/
public $config;

Expand All @@ -36,16 +36,16 @@ class GatewayResolver

/**
* Gateway constructor.
* @param null $config
* @param array $config
* @param null $port
*/
public function __construct($config = null, $port = null)
public function __construct($config = [], $port = null)
{
$this->config = app('config');
$this->config = !$config ?: app('config')['gateway'];
$this->request = app('request');

if ($this->config->has('gateway.timezone'))
date_default_timezone_set($this->config->get('gateway.timezone'));
if ($tz = $this->getTimeZone())
date_default_timezone_set($tz);

if (!is_null($port)) $this->make($port);
}
Expand Down Expand Up @@ -168,4 +168,9 @@ function make($port)

return $this;
}

private function getTimeZone()
{
return $this->config['gateway']['timezone'] ?? null;
}
}
6 changes: 3 additions & 3 deletions src/JahanPay/JahanPay.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function setCallback($url)
function getCallback()
{
if (!$this->callbackUrl)
$this->callbackUrl = $this->config->get('gateway.jahanpay.callback-url');
$this->callbackUrl = $this->config['jahanpay']['callback-url'];

return $this->makeCallback($this->callbackUrl, ['transaction_id' => $this->transactionId()]);
}
Expand All @@ -101,7 +101,7 @@ protected function sendPayRequest()
try {
$soap = new SoapClient($this->serverUrl);
$response = $soap->requestpayment(
$this->config->get('gateway.jahanpay.api'),
$this->config['jahanpay']['api'],
$this->amount,
$this->getCallback(),
$this->transactionId(),
Expand Down Expand Up @@ -157,7 +157,7 @@ protected function verifyPayment()
try {
$soap = new SoapClient($this->serverUrl);
$response = $soap->verification(
$this->config->get('gateway.jahanpay.api'),
$this->config['jahanpay']['api'],
$this->amount,
$this->refId
);
Expand Down
20 changes: 10 additions & 10 deletions src/Mellat/Mellat.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function getAdditionalData ()
function getCallback()
{
if (!$this->callbackUrl)
$this->callbackUrl = $this->config->get('gateway.mellat.callback-url');
$this->callbackUrl = $this->config['mellat']['callback-url'];

return $this->makeCallback($this->callbackUrl, ['transaction_id' => $this->transactionId()]);
}
Expand All @@ -124,9 +124,9 @@ protected function sendPayRequest()
$this->newTransaction();

$fields = array(
'terminalId' => $this->config->get('gateway.mellat.terminalId'),
'userName' => $this->config->get('gateway.mellat.username'),
'userPassword' => $this->config->get('gateway.mellat.password'),
'terminalId' => $this->config['mellat']['terminalId'],
'userName' => $this->config['mellat']['username'],
'userPassword' => $this->config['mellat']['password'],
'orderId' => $this->transactionId(),
'amount' => $this->amount,
'localDate' => $dateTime->format('Ymd'),
Expand Down Expand Up @@ -191,9 +191,9 @@ protected function userPayment()
protected function verifyPayment()
{
$fields = array(
'terminalId' => $this->config->get('gateway.mellat.terminalId'),
'userName' => $this->config->get('gateway.mellat.username'),
'userPassword' => $this->config->get('gateway.mellat.password'),
'terminalId' => $this->config['mellat']['terminalId'],
'userName' => $this->config['mellat']['username'],
'userPassword' => $this->config['mellat']['password'],
'orderId' => $this->transactionId(),
'saleOrderId' => $this->transactionId(),
'saleReferenceId' => $this->trackingCode()
Expand Down Expand Up @@ -229,9 +229,9 @@ protected function verifyPayment()
protected function settleRequest()
{
$fields = array(
'terminalId' => $this->config->get('gateway.mellat.terminalId'),
'userName' => $this->config->get('gateway.mellat.username'),
'userPassword' => $this->config->get('gateway.mellat.password'),
'terminalId' => $this->config['mellat']['terminalId'],
'userName' => $this->config['mellat']['username'],
'userPassword' => $this->config['mellat']['password'],
'orderId' => $this->transactionId(),
'saleOrderId' => $this->transactionId(),
'saleReferenceId' => $this->trackingCode
Expand Down
6 changes: 3 additions & 3 deletions src/Parsian/Parsian.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function setCallback($url)
function getCallback()
{
if (!$this->callbackUrl)
$this->callbackUrl = $this->config->get('gateway.parsian.callback-url');
$this->callbackUrl = $this->config['parsian']['callback-url'];

return $this->makeCallback($this->callbackUrl, ['transaction_id' => $this->transactionId()]);
}
Expand Down Expand Up @@ -124,7 +124,7 @@ protected function sendPayRequest()
$this->newTransaction();

$params = array(
'LoginAccount' => $this->config->get('gateway.parsian.pin'),
'LoginAccount' => $this->config['parsian']['pin'],
'Amount' => $this->amount,
'OrderId' => $this->transactionId(),
'CallBackUrl' => $this->getCallback(),
Expand Down Expand Up @@ -186,7 +186,7 @@ protected function verifyPayment()
throw new ParsianErrorException('تراکنشی یافت نشد', -1);

$params = array(
'LoginAccount' => $this->config->get('gateway.parsian.pin'),
'LoginAccount' => $this->config['parsian']['pin'],
'Token' => $token
);

Expand Down
14 changes: 7 additions & 7 deletions src/Pasargad/Pasargad.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ public function ready()
public function redirect()
{

$processor = new RSAProcessor($this->config->get('gateway.pasargad.certificate-path'),RSAKeyType::XMLFile);
$processor = new RSAProcessor($this->config['pasargad']['certificate-path'],RSAKeyType::XMLFile);

$url = $this->gateUrl;
$redirectUrl = $this->getCallback();
$invoiceNumber = $this->transactionId();
$amount = $this->amount;
$terminalCode = $this->config->get('gateway.pasargad.terminalId');
$merchantCode = $this->config->get('gateway.pasargad.merchantId');
$terminalCode = $this->config['pasargad']['terminalId'];
$merchantCode = $this->config['pasargad']['merchantId'];
$timeStamp = date("Y/m/d H:i:s");
$invoiceDate = date("Y/m/d H:i:s");
$action = 1003;
Expand Down Expand Up @@ -101,7 +101,7 @@ function setCallback($url)
function getCallback()
{
if (!$this->callbackUrl)
$this->callbackUrl = $this->config->get('gateway.pasargad.callback-url');
$this->callbackUrl = $this->config['pasargad']['callback-url'];

return $this->callbackUrl;
}
Expand All @@ -125,7 +125,7 @@ protected function sendPayRequest()
*/
protected function verifyPayment()
{
$processor = new RSAProcessor($this->config->get('gateway.pasargad.certificate-path'),RSAKeyType::XMLFile);
$processor = new RSAProcessor($this->config['pasargad']['certificate-path'],RSAKeyType::XMLFile);

if (!Input::has('tref'))
throw new PasargadErrorException('درخواست غیر معتبر', -1);
Expand All @@ -141,8 +141,8 @@ protected function verifyPayment()
}

$fields = array(
'MerchantCode' => $this->config->get('gateway.pasargad.merchantId'),
'TerminalCode' => $this->config->get('gateway.pasargad.terminalId'),
'MerchantCode' => $this->config['pasargad']['merchantId'],
'TerminalCode' => $this->config['pasargad']['terminalId'],
'InvoiceNumber' => $check_array['resultObj']['invoiceNumber'],
'InvoiceDate' => Input::get('iD'),
'amount' => $check_array['resultObj']['amount'],
Expand Down
6 changes: 3 additions & 3 deletions src/Payir/Payir.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function setCallback($url)
function getCallback()
{
if (!$this->callbackUrl)
$this->callbackUrl = $this->config->get('gateway.payir.callback-url');
$this->callbackUrl = $this->config['payir']['callback-url'];
return urlencode($this->makeCallback($this->callbackUrl, ['transaction_id' => $this->transactionId()]));
}

Expand All @@ -114,7 +114,7 @@ protected function sendPayRequest()
{
$this->newTransaction();
$fields = [
'api' => $this->config->get('gateway.payir.api'),
'api' => $this->config['payir']['api'],
'amount' => $this->amount,
'redirect' => $this->getCallback(),
];
Expand Down Expand Up @@ -172,7 +172,7 @@ protected function userPayment()
protected function verifyPayment()
{
$fields = [
'api' => $this->config->get('gateway.payir.api'),
'api' => $this->config['payir']['api'],
'transId' => $this->refId(),
];
$ch = curl_init();
Expand Down
6 changes: 3 additions & 3 deletions src/Payline/Payline.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function setCallback($url)
function getCallback()
{
if (!$this->callbackUrl)
$this->callbackUrl = $this->config->get('gateway.payline.callback-url');
$this->callbackUrl = $this->config['payline']['callback-url'];

return urlencode($this->makeCallback($this->callbackUrl, ['transaction_id' => $this->transactionId()]));
}
Expand All @@ -105,7 +105,7 @@ protected function sendPayRequest()
$this->newTransaction();

$fields = array(
'api' => $this->config->get('gateway.payline.api'),
'api' => $this->config['payline']['api'],
'amount' => $this->amount,
'redirect' => $this->getCallback(),
);
Expand Down Expand Up @@ -164,7 +164,7 @@ protected function userPayment()
protected function verifyPayment()
{
$fields = array(
'api' => $this->config->get('gateway.payline.api'),
'api' => $this->config['payline']['api'],
'id_get' => $this->refId(),
'trans_id' => $this->trackingCode()
);
Expand Down
6 changes: 3 additions & 3 deletions src/Paypal/Paypal.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function redirect()
function getCallback()
{
if (!$this->callbackUrl)
$this->callbackUrl = $this->config->get('gateway.paypal.settings.call_back_url');
$this->callbackUrl = $this->config['paypal.settings']['call_back_url'];

return $this->makeCallback($this->callbackUrl, ['transaction_id' => $this->transactionId()]);
}
Expand Down Expand Up @@ -236,15 +236,15 @@ protected function verifyPayment()

public function getProductName(){
if(!$this->productName){
return $this->config->get('gateway.paypal.default_product_name');
return $this->config['paypal']['default_product_name'];
}

return $this->productName;
}

public function getShipmentPrice(){
if(!$this->shipmentPrice){
return $this->config->get('gateway.paypal.default_shipment_price');
return $this->config['paypal']['default_shipment_price'];
}

return $this->shipmentPrice;
Expand Down
18 changes: 9 additions & 9 deletions src/PortAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ abstract class PortAbstract
protected $cardNumber = '';

/**
* @var Config
* @var array $config
*/
protected $config;

Expand Down Expand Up @@ -73,13 +73,10 @@ abstract class PortAbstract
*/
protected $trackingCode;

/**
* Initialize of class
*
* @param Config $config
* @param DataBaseManager $db
* @param int $port
*/
/**
* Initialize of class
*
*/
function __construct()
{
$this->db = app('db');
Expand All @@ -90,6 +87,9 @@ function boot(){

}

/**
* @param array $config
*/
function setConfig($config)
{
$this->config = $config;
Expand All @@ -108,7 +108,7 @@ function getTable()
*/
function getLogTable()
{
return $this->db->table($this->config->get('gateway.table') . '_logs');
return $this->db->table($this->config['table') '][' '_logs'];
}

/**
Expand Down
Loading

0 comments on commit 0b17a80

Please sign in to comment.