Docker kullanıyorum port olarak 8011 ayarladım bir servis yazdım ve daha sonra aynı proje içerisinden tekrar o servise bağlanmaya istek atmaya çalışıyorum ancak url olarak localhost:8011, 127.0.0.1:8011 ve ip adresini kullanmama rağmen cURL error 7: Failed to connect to 127.0.0.1 port 8011 after 1 ms hatası alıyorum ama postman üzerinden istek attığımda bütün url'ler üzerinden çalışıyor. Desteklerinizi bekliyorum.
Yazdığım Servis İstek Fonksiyonu
`<?php
namespace App\Classes\Service;
use GuzzleHttp\Client;
use Illuminate\Support\Facades\Http;
class PaymentService
{
static private $serviceUrl = "http://127.0.0.1:8011/api/v1/pay-control/";
static private $salt;
static private $callbackSuccessUrl;
static private $callbackFailUrl;
static private $price;
public function __construct($salt, $callbackSuccessUrl, $callbackFailUrl, $price)
{
self::$salt = $salt;
self::$callbackSuccessUrl = $callbackSuccessUrl;
self::$callbackFailUrl = $callbackFailUrl;
self::$price = $price;
}
static private function send(string $method, string $hash)
{
try {
$client = new Client();
$options = [
'headers' => [
'Content-Type' => 'application/json',
]
];
$options['body'] = json_encode(
[
'price' => self::$price,
'point' => "0.00",
'order_id' => "3307333742",
'userId' => "3b43544b-10b4-45e2-ab81-2b2b3f1917e8",
'user_phone' => "905555555555",
'ref_code' => "0781534070",
'callback_success_url' => self::$callbackSuccessUrl,
'callback_fail_url' => self::$callbackFailUrl,
'hash' => $hash
]
);
$result = $client->request($method, self::$serviceUrl, $options);
$statusCode = $result->getStatusCode();
$result = json_decode($result->getBody()->getContents(), true);
$result["statusCode"] = $statusCode;
} catch (\Exception $e) {
$errorCode = $e->getCode();
$result = [
"success" => 'failed',
"statusCode" => $errorCode,
];
}
return $result;
}
public function processPayment()
{
$hash = $this->generateHash();
return $this->send('POST', $hash);
}
private function generateHash()
{
$dataToHash = self::$salt . self::$callbackFailUrl . self::$callbackSuccessUrl . self::$price;
return sha1($dataToHash);
}
}
Yazdığım Servis Route
Route::prefix('v1')->group(function ()
{
Route::post('/pay-control',[ApiController::class,'payControl']);
});`
Yazdığım Servis Fonksiyonu
`public function payControl(Request $request)
{
$result = 'failed';
$content = json_decode($request->getContent(), true);
$price = $content['price'];
$point = $content['point'];
$order_id = $content['order_id'];
$userId = $content['userId'];
$user_phone = $content['user_phone'];
$ref_code = $content['ref_code'];
$callback_success_url = $content['callback_success_url'];
$callback_fail_url = $content['callback_fail_url'];
self::$hash = $content['hash'];
$totalLogCount = EntranceLog::whereDate('created_at', today())
->where('status', 1)
->count();
$userLogCount = EntranceLog::where('user_id', $userId)
->whereDate('created_at', today())
->where('status', 1)
->count();
if($totalLogCount < 50)
{
if($userLogCount < 2)
{
$result = 200;
}
}
return $result;
`