Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: degica/komoju-magento
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 282b35f93e11fd8ebd5cabae347b9309ada4e35e
Choose a base ref
..
head repository: degica/komoju-magento
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 486803494a0951f0c68748c05a3c40d7e8e90dbf
Choose a head ref
Showing with 18 additions and 24 deletions.
  1. +17 −23 src/app/code/Komoju/Payments/Api/KomojuApi.php
  2. +1 −1 src/app/code/Komoju/Payments/Controller/KomojuField/ProcessToken.php
40 changes: 17 additions & 23 deletions src/app/code/Komoju/Payments/Api/KomojuApi.php
Original file line number Diff line number Diff line change
@@ -16,14 +16,12 @@ class KomojuApi
private Config $config;
private Curl $curl;
private string $endpoint;
private LoggerInterface $logger;

public function __construct(Config $config, Curl $curl, LoggerInterface $logger)
public function __construct(Config $config, Curl $curl)
{
$this->endpoint = 'https://komoju.com';
$this->config = $config;
$this->curl = $curl;
$this->logger = $logger;
}

public function paymentMethods()
@@ -90,36 +88,32 @@ private function get($uri)
// );
private function post($uri, $payload)
{
$ch = curl_init($this->endpoint . $uri);
$url = $this->endpoint . $uri;
$data_json = json_encode($payload);
$options = [CURLOPT_POST => true,
CURLOPT_HTTPHEADER => ['Content-Type: application/json','Komoju-Via: magento'],
CURLOPT_RETURNTRANSFER => true,
CURLOPT_USERPWD => $this->config->getSecretKey() . ':'
];
$this->curl->setOptions($options);

curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_json);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'komoju-via: magento'
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $this->config->getSecretKey() . ':');
$result = curl_exec($ch);

if (curl_errno($ch)) {
$error = curl_error($ch);
curl_close($ch);
throw new KomojuExceptionBadServer($error);
try {
$this->curl->post($url, $data_json);
} catch (Exception $e) {
throw new KomojuExceptionBadServer($e->getMessage());
}

$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$body = $this->curl->getBody();
$http_code = $this->curl->getStatus();

if ($http_code !== 200) {
$komojuException = new KomojuExceptionBadServer($result);
$komojuException = new KomojuExceptionBadServer($body);
$komojuException->httpCode = $http_code;
throw $komojuException;
}

curl_close($ch);
$decoded = json_decode($body);

$decoded = json_decode($result);

if (!empty(json_last_error())) {
$errorMsg = (__("KOMOJU Payments JSON Decoding Failure. Error: %1", json_last_error_msg()));
throw new InvalidJsonException($errorMsg);
Original file line number Diff line number Diff line change
@@ -86,7 +86,7 @@ public function execute()
return $result->setData(['success' => true, 'message' => 'Token processed successfully', 'data' => $data]);
} catch (Exception $e) {
$data = ['redirect_url' => $session->session_url];
return $result->setData(['success' => true, 'message' => 'Cannot process token, redirect', 'data' => $data]);
return $result->setData(['success' => true, 'message' => 'Cannot process token, redirect', 'data' => $data]);
}
}