Skip to content

Commit

Permalink
change file_get_contents to Curl function
Browse files Browse the repository at this point in the history
  • Loading branch information
Ihor Sereda committed Aug 20, 2018
1 parent 1c24e00 commit cc2fec0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
3 changes: 2 additions & 1 deletion catalog/controller/extension/payment/paybear.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ public function callback()
}

$order = $this->model_checkout_order->getOrder($this->request->get['order']);
$data = file_get_contents('php://input');
//$data = file_get_contents('php://input');
$data = $this->model_extension_payment_paybear->url_get_contents('php://input');

if (empty($data) || empty($order)
|| (int) $this->config->get('payment_paybear_completed_status_id') === (int) $order['order_status_id']) {
Expand Down
21 changes: 18 additions & 3 deletions catalog/model/extension/payment/paybear.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public function getCurrencies()
{
if (self::$currencies === null) {
$url = sprintf('%s/currencies?token=%s', self::$baseUrl, $this->config->get('payment_paybear_api_secret'));
$response = file_get_contents($url);
//$response = file_get_contents($url);
$response = $this->url_get_contents($url);
$data = json_decode($response, true);

self::$currencies = $data['data'];
Expand Down Expand Up @@ -98,7 +99,8 @@ public function getRates()
} else {
$url = sprintf("%s/exchange/%s/rate", self::$baseUrl, strtolower($currency));

if ($response = file_get_contents($url)) {
//if ($response = file_get_contents($url)) {
if ($response = $this->url_get_contents($url)) {
$response = json_decode($response);
if ($response->success) {
$ratesData = [];
Expand Down Expand Up @@ -141,7 +143,8 @@ public function getAddress($orderId, $token = 'ETH')
$callbackUrl = str_replace('&', '&', $callbackUrl);

$url = sprintf('%s/%s/payment/%s?token=%s', self::$baseUrl, strtolower($token), urlencode($callbackUrl), $apiSecret);
if ($response = file_get_contents($url)) {
//if ($response = file_get_contents($url)) {
if ($response = $this->url_get_contents($url)) {
$response = json_decode($response);
$currencies = $this->getCurrencies();

Expand Down Expand Up @@ -269,4 +272,16 @@ public function editSettings($data, $store_id = 0) {
}
}

function url_get_contents ($Url) {
if (!function_exists('curl_init')){
die('CURL is not installed!');
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $Url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}

}

0 comments on commit cc2fec0

Please sign in to comment.