main
This commit is contained in:
+166
@@ -0,0 +1,166 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Pay;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Str; // For UUID generation
|
||||
use Ramsey\Uuid\Uuid;
|
||||
|
||||
|
||||
class PaymanController extends Controller
|
||||
{
|
||||
protected $accessToken = 'b71c3737-7b89-4f2c-9301-767439079407';
|
||||
|
||||
/**
|
||||
* Get access token from Payman API.
|
||||
*/
|
||||
public function login()
|
||||
{
|
||||
$response = Http::withHeaders(['Cookie' => 'cookiesession1=678A8C341A085F7AF93FECC7B44ACDFF'])
|
||||
->asForm()
|
||||
->post('https://payman2.sandbox.faraboom.co/oauth/token', [
|
||||
'Client_id' => 'demopayman',
|
||||
'Client_secret' => '!8cr?40V',
|
||||
'Grant_type' => 'client_credentials',
|
||||
]);
|
||||
|
||||
$this->accessToken = $response->json()['access_token'];
|
||||
|
||||
return $response->json();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Payman account.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$t = Uuid::uuid4()->toString();
|
||||
$response = Http::withHeaders([
|
||||
'app-key' => 'demopayman',
|
||||
'Client-Ip-Address' => '127.0.0.1',
|
||||
'Client-Platform-Type' => 'web',
|
||||
'Client-Device-Id' => '169.254.75.178',
|
||||
'Client-User-Id' => '09352673656',
|
||||
'Client-User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36',
|
||||
'Content-Type' => 'application/json',
|
||||
'Mobile-no' => '09352673656',
|
||||
'National-code' => '0082205388',
|
||||
'Authorization' => 'Bearer b71c3737-7b89-4f2c-9301-767439079407',
|
||||
'Cookie' => 'cookiesession1=678A8C341A085F7AF93FECC7B44ACDFF',
|
||||
])
|
||||
->post('https://payman2.sandbox.faraboom.co/v1/payman/create', [
|
||||
'payman' => [
|
||||
'bank_code' => 'SINAIR',
|
||||
'user_id' => 'demopayman',
|
||||
'permission_ids' => [1],
|
||||
'contract' => [
|
||||
'expiration_date' => '2026-01-15T01:28:09.5662061+04:30',
|
||||
'max_daily_transaction_count' => 50,
|
||||
'max_monthly_transaction_count' => 100,
|
||||
'max_transaction_amount' => 500000,
|
||||
],
|
||||
],
|
||||
'redirect_url' => 'http://localhost',
|
||||
'trace_id' => $t,
|
||||
]);
|
||||
// دریافت پاسخ از API
|
||||
$statusCode = $response->status(); // وضعیت HTTP
|
||||
$responseBody = $response->json(); // بدنه پاسخ به صورت JSON
|
||||
$responseHeaders = $response->headers(); // هدرهای پاسخ
|
||||
$responseBodyRaw = $response->body(); // بدنه خام پاسخ (به صورت متن)
|
||||
|
||||
// برگشت وضعیت و بدنه پاسخ
|
||||
return response()->json([
|
||||
'status' => $statusCode,
|
||||
'json' => $response->json(),
|
||||
'headers' => $response->headers(),
|
||||
'body' => $response->body(),
|
||||
]);
|
||||
$response = Http::timeout(4)->withHeaders([
|
||||
'Cookie' => 'cookiesession1=678A8C341A085F7AF93FECC7B44ACDFO',
|
||||
'app-key' => 'demopayman',
|
||||
'Client-Ip-Address' => $_SERVER['REMOTE_ADDR'],
|
||||
'Client-Platform-Type' => 'web',
|
||||
'Client-Device-Id' => '169.254.75.178',
|
||||
'Client-User-Id' => '09352673656',
|
||||
'Client-User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36',
|
||||
'Content-Type' => 'application/json',
|
||||
'Mobile-no' => '09352673656',
|
||||
'National-code' => '0082205388',
|
||||
'Authorization' => 'Bearer b71c3737-7b89-4f2c-9301-767439079407',
|
||||
])->post('https://payman2.sandbox.faraboom.co/v1/payman/create', [
|
||||
'payman' => [
|
||||
'bank_code' => 'SINAIR',
|
||||
'user_id' => 'demopayman',
|
||||
'permission_ids' => [1],
|
||||
'contract' => [
|
||||
'expiration_date' => '2026-01-15T01:28:09.5662061+04:30', // Updated expiration date
|
||||
'max_daily_transaction_count' => 50,
|
||||
'max_monthly_transaction_count' => 100,
|
||||
'max_transaction_amount' => 500000,
|
||||
'start_date' => '2025-01-15T08:28:09.5662061+04:30',
|
||||
'Daily_max_transaction_amount' => 500000000,
|
||||
]
|
||||
],
|
||||
'redirect_url' => 'https://api.gholaktala.ir/',
|
||||
'trace_id' => $t,
|
||||
]);
|
||||
|
||||
return $response->getStatusCode().$t.$response;
|
||||
/*{
|
||||
"access_token": "b71c3737-7b89-4f2c-9301-767439079407",
|
||||
"token_type": "bearer",
|
||||
"scope": "all",
|
||||
"expires_in": 28954155
|
||||
}*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve details for a specific trace ID.
|
||||
*/
|
||||
public function createTrace()
|
||||
{
|
||||
$traceId = Str::uuid()->toString();
|
||||
|
||||
$response = Http::timeout(4)->withHeaders([
|
||||
'Cookie' => 'cookiesession1=678A8C341A085F7AF93FECC7B44ACDFO',
|
||||
'Authorization' => 'Bearer ' . $this->accessToken, // Using stored access token
|
||||
])->get('https://payman2.sandbox.faraboom.co/v1/payman/create/trace', [
|
||||
'trace_id' => $traceId,
|
||||
'redirect_url' => 'https://api.gholaktala.ir/',
|
||||
]);
|
||||
|
||||
if ($response->status() === 302) {
|
||||
$location = $response->header('Location');
|
||||
return redirect()->away($location);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'headers' => $response->headers(),
|
||||
'body' => $response->body(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Payman account ID by payman_code.
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
$url = 'https://payman2.sandbox.faraboom.co/v1/payman/getId';
|
||||
$paymanCode = '2gZ04Yx9iHEP'; // You may want to dynamically set this value
|
||||
|
||||
return $response = Http::timeout(4)
|
||||
->withHeaders([
|
||||
'Authorization' => 'Bearer ' . $this->accessToken, // Using stored access token
|
||||
'App-Key' => 'demopayman',
|
||||
'Cookie' => 'cookiesession1=678A8C341A085F7AF93FECC7B44ACDFF',
|
||||
])
|
||||
->get($url, [
|
||||
'payman_code' => $paymanCode // pass the payman_code as a query parameter
|
||||
])->json();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user