PHP code example of emreyilmaz99 / php-trsanalpos
1. Go to this page and download the library: Download emreyilmaz99/php-trsanalpos library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
emreyilmaz99 / php-trsanalpos example snippets
use EvrenOnur\SanalPos\Enums\InstallmentCommissionPolicy;
$auth = new MerchantAuth(
bank_code: BankService::SIPAY,
merchant_id: 'merchant-id',
merchant_user: 'merchant-user',
merchant_password: 'merchant-password',
merchant_storekey: 'merchant-storekey',
test_platform: true,
installment_commission_policy: InstallmentCommissionPolicy::ChargeToCustomer,
);
use EvrenOnur\SanalPos\SanalPosClient;
use EvrenOnur\SanalPos\DTOs\{MerchantAuth, SaleInfo, CustomerInfo, Payment3DConfig};
use EvrenOnur\SanalPos\DTOs\Requests\SaleRequest;
use EvrenOnur\SanalPos\Services\BankService;
use EvrenOnur\SanalPos\Enums\{Currency, Country};
$auth = new MerchantAuth(
bank_code: BankService::QNBPAY,
merchant_id: '20158',
merchant_user: '07fb70f9d8de575f32baa6518e38c5d6',
merchant_password: '61d97b2cac247069495be4b16f8604db',
merchant_storekey: '$2y$10$N9IJkgazXMUwCzpn7NJrZePy3v.dIFOQUyW4yGfT3eWry6m.KxanK',
test_platform: true,
);
$customerInfo = new CustomerInfo(
tax_number: '1111111111',
email_address: '[email protected] ',
name: 'cem',
surname: 'pehlivan',
phone_number: '1111111111',
address_description: 'adres',
city_name: 'istanbul',
country: Country::TUR,
post_code: '34000',
tax_office: 'maltepe',
town_name: 'maltepe',
);
$saleRequest = new SaleRequest(
order_number: dechex(time()),
sale_info: new SaleInfo(
card_name_surname: 'test kart',
card_number: '4022780520669303',
card_expiry_month: 1,
card_expiry_year: 2050,
card_cvv: '988',
amount: 10.00,
currency: Currency::TRY,
installment: 1,
),
payment_3d: new Payment3DConfig(confirm: false),
customer_ip_address: '1.1.1.1',
invoice_info: $customerInfo,
shipping_info: $customerInfo,
);
$response = SanalPosClient::sale($saleRequest, $auth);
echo "Status: {$response->status->name}\n";
echo "Mesaj: {$response->message}\n";
echo "İşlem ID: {$response->transaction_id}\n";
$saleRequest = new SaleRequest(
order_number: dechex(time()),
sale_info: new SaleInfo(
card_name_surname: 'test kart',
card_number: '4022780520669303',
card_expiry_month: 1,
card_expiry_year: 2050,
card_cvv: '988',
amount: 10.00,
currency: Currency::TRY,
installment: 1,
),
payment_3d: new Payment3DConfig(
confirm: true,
return_url: 'https://example.com/payment/3d-response',
),
customer_ip_address: request()->ip(),
invoice_info: $customerInfo,
shipping_info: $customerInfo,
);
$response = SanalPosClient::sale($saleRequest, $auth);
// status RedirectURL ise → $response->message içindeki URL'e yönlendirin
// status RedirectHTML ise → $response->message içindeki HTML'i tarayıcıda gösterin
use EvrenOnur\SanalPos\DTOs\Requests\Sale3DResponse;
// Controller method - 3D'den gelen callback
public function virtualPOS3DResponse(Request $request)
{
$responseArray = $request->all();
$response = SanalPosClient::sale3DResponse(
new Sale3DResponse(responseArray: $responseArray),
$auth
);
// $response->status → SaleResponseStatus::Success veya Error
// $response->message → Sonuç mesajı
// $response->transaction_id → İşlem ID
// $response->private_response['response_1'] → callback verisi
// $response->private_response['response_2'] → gerekiyorsa provider tamamlama yanıtı
}
use EvrenOnur\SanalPos\DTOs\Requests\CancelRequest;
$cancelRequest = new CancelRequest(
order_number: 'ORDER-001',
transaction_id: 'TXN-001',
);
$response = SanalPosClient::cancel($cancelRequest, $auth);
use EvrenOnur\SanalPos\DTOs\Requests\RefundRequest;
$refundRequest = new RefundRequest(
order_number: 'ORDER-001',
refund_amount: 50.00,
currency: Currency::TRY,
);
$response = SanalPosClient::refund($refundRequest, $auth);
use EvrenOnur\SanalPos\DTOs\Requests\BINInstallmentQueryRequest;
$request = new BINInstallmentQueryRequest(
BIN: '411111', // Kart numarasının ilk 6 hanesi
currency: Currency::TRY,
);
$response = SanalPosClient::binInstallmentQuery($request, $auth);
use EvrenOnur\SanalPos\Facades\SanalPos;
$response = SanalPos::sale($saleRequest, $auth);
$response = SanalPos::cancel($cancelRequest, $auth);
$response = SanalPos::refund($refundRequest, $auth);
use EvrenOnur\SanalPos\Exceptions\HttpRequestException;
try {
$response = SanalPosClient::sale($saleRequest, $auth);
} catch (HttpRequestException $e) {
// HTTP bağlantı hatası, timeout vb.
echo $e->getMessage();
echo $e->url; // Hata oluşan URL
} catch (\InvalidArgumentException $e) {
// Validasyon hatası (eksik/hatalı parametre)
echo $e->getMessage();
}
bash
composer bash
php artisan vendor:publish --provider="EvrenOnur\SanalPos\SanalPosServiceProvider"