<?php
/**
* UuddoktaPay FOSSBilling Gateway Module
*
* Copyright (c) 2021 - 2023 UuddoktaPay
* Website: https://uddoktapay.com
* Email: info@uddoktapay.com
* Developer: UddoktaPay Team
*
*/
class Payment_Adapter_UddoktaPay extends Payment_AdapterAbstract implements \FOSSBilling\InjectionAwareInterface
{
private $config = [];
public function setDi(\\Pimple\\Container $di): void
{
$this->di = $di;
}
public function getDi(): ?\\Pimple\\Container
{
return $this->di;
}
public function __construct($config)
{
$this->config = $config;
if (!isset($this->config['merchant_id']) || !isset($this->config['merchant_key']) || !isset($this->config['merchant_salt'])) {
throw new Payment_Exception('The ":pay_gateway" payment gateway is not fully configured. Please configure the :missing', [':pay_gateway' => 'UddoktaPay', ':missing' => 'Merchant ID, Merchant Key, and Merchant Salt']);
}
}
public static function getConfig()
{
return [
'merchant_id' => [
'text', [
'label' => '\*\*\*\*',
],
],
'merchant_key' => [
'text', [
'label' => '\*\*\*\*',
],
],
'merchant_salt' => [
'text', [
'label' => '\*\*\*\*',
],
],
];
}
public function getHtml($api_admin, $invoice_id, $subscription)
{
$invoice = $api_admin->invoice_get(['id' => $invoice_id]);
$data = $this->getPaymentFields($invoice);
$token = $this->initPayment($data);
return $this->generateForm($token);
}
public function processTransaction($api_admin, $id, $data, $gateway_id)
{
// Implement the transaction processing logic here
}
/\*\*
\* Set Payment Fields for UddoktaPay
\* @var array $invoice
\*/
public function getPaymentFields($invoice)
{
// Populate payment fields for UddoktaPay
$fields = [
'merchant_id' => $this->config['merchant_id'],
'user_ip' => $_SERVER["REMOTE_ADDR"],
'merchant_oid' => uniqid(),
'email' => $invoice->client->email,
'payment_amount' => max($invoice->total, 100),
'user_basket' => base64_encode(json_encode($invoice->items)),
'debug_on' => 1,
'no_installment' => 0,
'max_installment' => 0,
'user_name' => $invoice->client->first_name . ' ' . $invoice->client->last_name,
'user_address' => $invoice->client->address1,
'user_phone' => $invoice->client->phone,
'timeout_limit' => '30',
'currency' => 'TL',
'test_mode' => 0,
// Other necessary fields
];
return $fields;
}
/\*\*
\* Init Payment and Get Token
\* @var array $requestData
\* @return string
\*/
private function initPayment($requestData)
{
// Implement payment initiation logic for UddoktaPay
$post_vals = $requestData;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.paytr.com/odeme/api/get-token");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_vals);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
$result = @curl_exec($ch);
if (curl_errno($ch))
die("PAYTR IFRAME connection error. err:" . curl_error($ch));
curl_close($ch);
$result = json_decode($result, 1);
if ($result['status'] == 'success')
return $result['token'];
else
die("PAYTR IFRAME failed. reason:" . $result['reason']);
}
/\*\*
\* Generate Payment Form
\* @var string $token
\*/
private function generateForm($token)
{
$form = '';
$form .= '<form name="payment_form" action="ACTION_URL" method="POST">' . PHP_EOL;
$form .= '<input type="hidden" name="email" value="' . $this->config['email'] . '">' . PHP_EOL; // E-posta adresi hidden input ile formda gönderiliyor
$form .= '<input type="hidden" name="token" value="' . $token . '">' . PHP_EOL;
$form .= '<input class="bb-button bb-button-submit" type="submit" value="Pay Now" id="payment_button"/>' . PHP_EOL;
$form .= '</form>' . PHP_EOL . PHP_EOL;
$form .= '<!-- Ödeme formunun açılması için gereken HTML kodlar / Başlangıç -->' . PHP_EOL;
$form .= '<script src="https://www.paytr.com/js/iframeResizer.min.js"></script>' . PHP_EOL;
$form .= '<iframe src="https://www.paytr.com/odeme/guvenli/' . $token . '" id="paytriframe" frameborder="0" scrolling="no" style="width: 100%;"></iframe>' . PHP_EOL;
$form .= '<script>iFrameResize({}, "#paytriframe");</script>' . PHP_EOL;
$form .= '<!-- Ödeme formunun açılması için gereken HTML kodlar / Bitiş -->' . PHP_EOL;
return $form;
}
}
?>