class PaytrService
{
// env File : $merchantId
private $merchantId;
// env File : $merchantKey
private $merchantKey;
// env File : $merchantSalt
private $merchantSalt;
// User IP : $userIp
private $userIp;
// Order No : $merchantOId
private $merchantOId;
// Payment Amount : $paymentAmount
private $paymentAmount;
// Payment Type : $paymentType - card
private $paymentType;
// InstallmentAmount : $installmentAmount
private $installmentAmount;
// maxInstallment : $maxInstallment
private $maxInstallment;
// Currency - $currency : TL,EUR,USD
private $currency;
// Test Mode : $testMode
private $testMode;
private $timeoutLimit;
private $lang = "tr";
// Post URL : $postUrl
private $postUrl;
// Cart or Basket : $userBasket
private $userBasket;
// Token : $token
private $token;
// Success URL : $merchantOkUrl
private $merchantOkUrl;
// Error URL : $merchantFailUrl
private $merchantFailUrl;
// Debug Mode : $debug
private $debug;
// E-Mail Address : $email
private $email;
private $phone;
private $userName;
private $userAddress;
public function __construct()
{
$this->merchantId = env("PAYTR_MERCHANT_ID");
$this->merchantKey = env("PAYTR_MERCHANT_KEY");
$this->merchantSalt = env("PAYTR_MERCHANT_SALT");
$this->merchantOkUrl = route("paytr.success");
$this->merchantFailUrl = route("paytr.error");
}
public function basket($baskets)
{
return $this->userBasket = htmlentities(json_encode($baskets));
}
public function generateToken()
{
// $merchant_id .$user_ip .$merchant_oid .$email .$payment_amount .$user_basket.$no_installment.$max_installment.$currency.$test_mode
$hashStr = $this->merchantId .$this->userIp .$this->merchantOId .$this->email .$this->paymentAmount .$this->userBasket.$this->installmentAmount.$this->maxInstallment.$this->currency.$this->testMode;
$this->token = base64_encode(hash_hmac('sha256',$hashStr.$this->merchantSalt,$this->merchantKey,true));
}
public function getToken()
{
return $this->token;
}
public function sendData($data,$price,$baskets)
{
}
public function getPostData($data,$price = 1,$baskets)
{
$basketArray = $this->basket($baskets); // Müşteri Sepet
$this->userIp = request()->ip(); // Müşteri IP Adres
$this->timeoutLimit = "30"; // Dakika Olarak Zaman Aşımı
$this->debug = 1;
$this->testMode = 0; // Test Mod
$this->installmentAmount = 0; // Taksit yapılmasını istemiyorsanız, sadece tek çekim sunacaksanız 1 yapın
$this->maxInstallment = 0; // Taksit
$this->currency = "TL"; // Para Birimi : TL,EUR,USD
$this->lang = "tr"; // Dil TR
$this->paymentAmount = (int) $price; // Sepet Fiyat
$this->paymentType = "card"; // Ödeme Tipi Kart
$this->email = $data["email"] ?? 'testmode@paytr.com'; // Müşteri Email
$this->userName = $data["name"];
$this->userAddress = $data["address"];
$this->phone = $data["phone"];
$this->merchantOId = uniqid(); // Sipariş Numarası
$this->postUrl = "https://www.paytr.com/odeme"; // URL Adresi
$this->userBasket = $basketArray;
$this->generateToken();
}
}