Skip to content

Commit

Permalink
Merge pull request #4 from sdkakcy/main
Browse files Browse the repository at this point in the history
timeout_limit && lang parameters added to Iframe API requests
  • Loading branch information
GizemSever authored Jun 3, 2024
2 parents 4d67a8b + 061bf4e commit c3d9926
Showing 1 changed file with 82 additions and 6 deletions.
88 changes: 82 additions & 6 deletions src/Payment/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,46 +14,57 @@ class Payment extends PaytrClient
* @var string
*/
private $userIp;

/**
* @var string
*/
private $merchantOid;

/**
* @var string
*/
private $email;

/**
* @var float
*/
private $paymentAmount;

/**
* @var int
*/
private $noInstallment;

/**
* @var int
*/
private $maxInstallment;

/**
* @var string
*/
private $userName;

/**
* @var string
*/
private $userAddress;

/**
* @var string
*/
private $userPhone;

/**
* @var string
*/
private $successUrl;

/**
* @var string
*/
private $failUrl;

/**
* @var bool
*/
Expand All @@ -69,6 +80,16 @@ class Payment extends PaytrClient
*/
private $currency = Currency::TRY;

/**
* @var int
*/
private $timeoutLimit = 0;

/**
* @var string
*/
private $lang = 'tr';

/**
* @return string
*/
Expand All @@ -83,6 +104,7 @@ public function getCurrency(): string
public function setCurrency(string $currency)
{
$this->currency = $currency;

return $this;
}

Expand All @@ -100,6 +122,7 @@ public function getUserIp(): string
public function setUserIp(string $userIp)
{
$this->userIp = $userIp;

return $this;
}

Expand All @@ -117,6 +140,7 @@ public function getMerchantOid(): string
public function setMerchantOid(string $merchantOid)
{
$this->merchantOid = $merchantOid;

return $this;
}

Expand All @@ -134,6 +158,7 @@ public function getEmail(): string
public function setEmail(string $email)
{
$this->email = $email;

return $this;
}

Expand All @@ -151,6 +176,7 @@ public function getPaymentAmount(): float
public function setPaymentAmount(float $paymentAmount)
{
$this->paymentAmount = $paymentAmount;

return $this;
}

Expand All @@ -168,6 +194,7 @@ public function getNoInstallment(): int
public function setNoInstallment(int $noInstallment)
{
$this->noInstallment = $noInstallment;

return $this;
}

Expand All @@ -185,6 +212,7 @@ public function getMaxInstallment(): int
public function setMaxInstallment(int $maxInstallment)
{
$this->maxInstallment = $maxInstallment;

return $this;
}

Expand All @@ -202,6 +230,7 @@ public function getUserName(): string
public function setUserName(string $userName)
{
$this->userName = $userName;

return $this;
}

Expand All @@ -219,6 +248,7 @@ public function getUserAddress(): string
public function setUserAddress(string $userAddress)
{
$this->userAddress = $userAddress;

return $this;
}

Expand All @@ -236,6 +266,7 @@ public function getUserPhone(): string
public function setUserPhone(string $userPhone)
{
$this->userPhone = $userPhone;

return $this;
}

Expand All @@ -253,6 +284,7 @@ public function getSuccessUrl(): string
public function setSuccessUrl(string $successUrl)
{
$this->successUrl = $successUrl;

return $this;
}

Expand All @@ -270,6 +302,7 @@ public function getFailUrl(): string
public function setFailUrl(string $failUrl)
{
$this->failUrl = $failUrl;

return $this;
}

Expand All @@ -287,6 +320,7 @@ public function isDebugOn(): bool
public function setDebugOn(bool $debugOn)
{
$this->debugOn = $debugOn;

return $this;
}

Expand All @@ -305,6 +339,45 @@ public function getBasket(): Basket
public function setBasket(Basket $basket)
{
$this->basket = $basket;

return $this;
}

/**
* @return int
*/
public function getTimeoutLimit(): int
{
return $this->timeoutLimit;
}

/**
* @param int $timeoutLimit
* @return self
*/
public function setTimeoutLimit(int $timeoutLimit): self
{
$this->timeoutLimit = $timeoutLimit;

return $this;
}

/**
* @return string
*/
public function getLang(): string
{
return $this->lang;
}

/**
* @param string $lang
* @return self
*/
public function setLang(string $lang): self
{
$this->lang = $lang;

return $this;
}

Expand All @@ -326,6 +399,7 @@ private function getHash()
private function createPaymentToken()
{
$hash = $this->getHash();

return base64_encode(hash_hmac('sha256', $hash . $this->credentials['merchant_salt'], $this->credentials['merchant_key'], true));
}

Expand All @@ -337,33 +411,35 @@ private function formattedPaymentAmount()
private function getBody()
{
$paymentToken = $this->createPaymentToken();

return [
'merchant_id' => $this->credentials['merchant_id'],
'user_ip' => $this->getUserIp(),
'merchant_oid' => $this->getMerchantOid(),
'email' => $this->getEmail(),
'payment_amount' => $this->formattedPaymentAmount(),
'paytr_token' => $paymentToken,
'currency' => $this->getCurrency(),
'user_basket' => $this->basket->formatted(),
'debug_on' => $this->isDebugOn(),
'no_installment' => $this->getNoInstallment(),
'max_installment' => $this->getMaxInstallment(),
'paytr_token' => $paymentToken,
'user_name' => $this->getUserName(),
'user_address' => $this->getUserAddress(),
'user_phone' => $this->getUserPhone(),
'merchant_ok_url' => $this->options['success_url'],
'merchant_fail_url' => $this->options['fail_url'],
'currency' => $this->getCurrency(),
'test_mode' => $this->options['test_mode'],
'debug_on' => $this->isDebugOn(),
'timeout_limit' => $this->getTimeoutLimit(),
'lang' => $this->getLang(),
];
}

public function create()
{
$requestBody = $this->getBody();
$response = $this->callApi('POST', 'odeme/api/get-token', $requestBody);
// return $response->getBody();
// return json_decode((string) $response->getBody());

return new PaytrResponse(json_decode((string)$response->getBody(), true));
}
}
}

0 comments on commit c3d9926

Please sign in to comment.