Skip to content

Commit

Permalink
Fix curl issues (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
yanoandri authored Dec 19, 2024
1 parent 4200cb3 commit d19c429
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion modules/gateways/xendit.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
require __DIR__ . '/xendit/autoload.php';

// Module version
const XENDIT_PAYMENT_GATEWAY_VERSION = '2.1.0';
const XENDIT_PAYMENT_GATEWAY_VERSION = '2.1.1';

use WHMCS\Billing\Invoice;
use Xendit\Lib\ActionBase;
Expand Down
2 changes: 1 addition & 1 deletion modules/gateways/xendit/lib/ActionBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,6 @@ public function setTransactionsToExpired($transaction) {
* @return boolean
*/
public function isTransactionsDataValid($transactionsData) {
return !empty($transactionsData) && $transactionsData[0]["transactionid"] !== "";
return !empty($transactionsData) && !empty($transactionsData[0]["transactionid"]) && $transactionsData[0]["transactionid"] !== "";
}
}
23 changes: 20 additions & 3 deletions modules/gateways/xendit/lib/XenditRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,36 @@ protected function request(string $endpoint, array $param = [], string $method =
$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => sprintf("%s/%s", $this->tpi_server_domain, $endpoint),
CURLOPT_URL => sprintf("%s%s", $this->tpi_server_domain, $endpoint),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_TIMEOUT => 60,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_POSTFIELDS => $param["body"] ?? "",
CURLOPT_HTTPHEADER => $param["headers"]
));

$response = curl_exec($curl);
// Handle with retry mechanism
$retry = 3;
$response = false;

while ($retry > 0) {
$response = curl_exec($curl);

// Check for cURL errors
if (curl_errno($curl)) {
$error_msg = curl_error($curl);
if (strpos($error_msg, 'Could not resolve host') !== false) {
$retry--;
sleep(1 * $retry); // Wait for 1 second before retrying
continue;
}
}
break;
}

curl_close($curl);
return $response;
Expand Down

0 comments on commit d19c429

Please sign in to comment.