Php sitemizde vallet kullanarak ödeme almak istiyoruz ancak gönderilen döküman ve örnek dosyalarını düzgün bir şekilde uyguladığımız halde callback_confirm kısmında yer alan ödemeyi başarılıya çevirme kodumuz çalışmıyor. Ödeme başarılı oluyor, karttan ödeme alıyor ancak farklı farklı hatalar döndürüyor.
örneğin: 'EKSIK_FORM_DATASI' hatası. bununla beraber sitemizdeki sessionları destroy ediyor. Destek talebine yazdığımız halde cevap almış değiliz.
@Vallet;
Vallet ile php entegresi hakkında
5
●286
- 08-09-2023, 22:58:14class
class Vallet_light_api
{
private $userName,$password,$shopCode,$hash;
public function __construct($userName,$password,$shopCode,$hash)
{
$this->userName = $userName;
$this->password = $password;
$this->shopCode = $shopCode;
$this->hash = $hash;
}
private function hash_generate($string)
{
$hash = base64_encode(pack('H*',sha1($this->userName.$this->password.$this->shopCode.$string.$this->hash)));
return $hash;
}
public function create_payment_link($order_data)
{
$post_data = array(
'userName' => $this->userName,
'password' => $this->password,
'shopCode' => $this->shopCode,
'productName' => $order_data['productName'],
'productData' => $order_data['productData'],
'productType' => $order_data['productType'],
'productsTotalPrice' => $order_data['productsTotalPrice'],
'orderPrice' => $order_data['orderPrice'],
'currency' => $order_data['currency'],
'orderId' => $order_data['orderId'],
'locale' => $order_data['locale'],
'conversationId' => $order_data['conversationId'],
'buyerName' => $order_data['buyerName'],
'buyerSurName' => $order_data['buyerSurName'],
'buyerGsmNo' => $order_data['buyerGsmNo'],
'buyerIp' => $order_data['buyerIp'],
'buyerMail' => $order_data['buyerMail'],
'buyerAdress' => $order_data['buyerAdress'],
'buyerCountry' => $order_data['buyerCountry'],
'buyerCity' => $order_data['buyerCity'],
'buyerDistrict' => $order_data['buyerDistrict'],
'callbackOkUrl' => 'https://xxx.com/panel/odemeyap?ynt=kredi&durum=ok',
'callbackFailUrl' => 'https://xxx.com/panel/odemeyap?ynt=kredi&durum=no',
'module'=>'NATIVE_PHP'
);
$post_data['hash'] = $this->hash_generate($post_data['orderId'].$post_data['currency'].$post_data['orderPrice'].$post_data['productsTotalPrice'].$post_data['productType'].$post_data['callbackOkUrl'].$post_data['callbackFailUrl']);
$response = $this->send_post('https://www.vallet.com.tr/api/v1/create-payment-link',$post_data);
if ($response['status']=='success' && isset($response['payment_page_url']))
{
return $response;
}
else
{
print_r($response);
/*Hatayı Sisteminiz için Yönetin ve Döndürün*/
}
}
private function send_post($post_url,$post_data)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$post_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1) ;
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_REFERER, $_SERVER['SERVER_NAME']);
$result_origin = curl_exec($ch);
$response = array();
if (curl_errno($ch))
{
/*Curl sırasında bir sorun oluştu*/
$response = array(
'status'=>'error',
'errorMessage'=>'Curl Geçersiz bir cevap aldı',
);
}
else
{
/*Curl Cevabını Alın*/
/*Curl Cevabını jsondan array'a dönüştür*/
$result = json_decode($result_origin,true);
if (is_array($result))
{
$response = (array) $result;
}
else
{
$response = array(
'status'=>'error',
'errorMessage'=>'Dönen cevap Array değildi',
);
}
}
curl_close($ch);
return $response;
}
}
kod
$komisyon = $tutar*5/100;
$tutar = $tutar+$komisyon;
$adsoyad = explode(" ", $adsoyad);
/*Sınıfı Api bilgilerinizle başlatın*/
$vallet = new Vallet_light_api($apiusername, $apikey, $apishopcode, $apihash);
/*Sipariş Bilgilerinizi Tanımlayın*/
$order_data = array(
'productName' => 'Site Bakiyesi',
'productData' => array(
array(
'productName' => 'Site Bakiyesi',
'productPrice' => $tutar,
'productType' => 'DIJITAL_URUN',
),
),
'productType' => 'DIJITAL_URUN',
'productsTotalPrice' => $tutar,
'orderPrice' => $tutar,
'currency' => 'TRY',
'orderId' => $siparis_key,
'locale' => 'tr',
'conversationId' => '',
'buyerName' => $adsoyad[0],
'buyerSurName' => $adsoyad[1].$adsoyad[2],
'buyerGsmNo' => $tel,
'buyerIp' => iplong(),
'buyerMail' => $mail,
'buyerAdress' => '',
'buyerCountry' => '',
'buyerCity' => '',
'buyerDistrict' => '',
);
/*Sipariş Bilgilerinizi link oluşturmak için sınıfa gönderin*/
$request = $vallet->create_payment_link($order_data);
if ($request['status'] == 'success' && isset($request['payment_page_url'])) {
/*status==success ve payment_page_url varsa başarılı bir işlem yürüttünüz*/
$odeme_link = $request['payment_page_url'];
} else
{
/*Hatalı bir cevap alındı*/
echo 'Ödeme linki üretilirken bir sorun oluştu';
print_r($request);
}
?>
<!-- Ödeme formunun açılması için gereken HTML kodlar / Başlangıç -->
<script src="https://www.paytr.com/js/iframeResizer.min.js"></script>
<iframe src="<?php echo $odeme_link; ?>" id="paytriframe" frameborder="0" scrolling="no" style="width: 100%;"></iframe>
<script>
iFrameResize({}, '#paytriframe');
</script>
<?
}
}
callback
$vallet_config = array(
'userName' => $apiusername,
'password' => $apikey,
'shopCode' => $apishopcode,
'hash' => $apihash,
);
$post = array();
$post['status'] = $_POST['status'];
$post['paymentStatus'] = $_POST['paymentStatus'];
$post['hash'] = $_POST['hash'];
$post['paymentCurrency'] = $_POST['paymentCurrency'];
$post['paymentAmount'] = $_POST['paymentAmount'];
$post['paymentType'] = $_POST['paymentType'];
$post['paymentTime'] = $_POST['paymentTime'];
$post['conversationId'] = $_POST['conversationId'];
$post['orderId'] = $_POST['orderId'];
$post['shopCode'] = $_POST['shopCode'];
$post['orderPrice'] = $_POST['orderPrice'];
$post['productsTotalPrice'] = $_POST['productsTotalPrice'];
$post['productType'] = $_POST['productType'];
$post['callbackOkUrl'] = $_POST['callbackOkUrl'];
$post['callbackFailUrl'] = $_POST['callbackFailUrl'];
if (empty($post['status']) || empty($post['paymentStatus']) || empty($post['hash']) || empty($post['paymentCurrency']) || empty($post['paymentAmount']) || empty($post['paymentType']) || empty($post['orderId']) || empty($post['shopCode']) || empty($post['orderPrice']) || empty($post['productsTotalPrice']) || empty($post['productType']) || empty($post['callbackOkUrl']) || empty($post['callbackFailUrl'])) {
/*Eksik Form Datası Mevcut*/
echo 'EKSIK_FORM_DATASI';
exit();
} else
{
$hash_string = $post['orderId'].$post['paymentCurrency'].$post['orderPrice'].$post['productsTotalPrice'].$post['productType'].$vallet_config["shopCode"].$vallet_config["hash"];
$MY_HASH = base64_encode(pack('H*', sha1($hash_string)));
if ($MY_HASH !== $post['hash']) {
/*Hash Uyuşmuyor*/
echo 'HATALI_HASH_IMZASI';
exit();
} else
{
/*
paymentStatus'un alabileceği değerler =
paymentWait(Ödeme Bekleniyor),
paymentVerification(Ödendi ancak ödeme doğrulama bekliyor. Reddedilebilir. Mal yada hizmetinizi müşterinize paymentOk alana kadar vermeyin),
paymentOk(Ödeme alındı. Artık mal yada hizmetinizi müşterinize verebilirsiniz),
paymentNotPaid('Ödenmedi'),
*/
if ($post['paymentStatus'] == 'paymentOk') {
$query = $db->prepare("SELECT * FROM bills where order_id=
rder_id LIMIT 1");
$gel = $query->execute(array("
rder_id" => $post['orderId']));
$gel = $query->fetch(PDO::FETCH_ASSOC);
$tutar = $gel["money"];
$komisyon = $tutar*5/100;
$tutar = $tutar+$komisyon;
if ($gel["order_id"] != $post['orderId']) {
/*Böyle bir sipariş sistemimde yok*/
echo 'GECERSIZ_SIPARIS_NUMARASI';
exit();
} else if ($gel["status"] == 1) {
/*Zaten ödenmiş ve işlenmiş*/
echo 'OK';
exit();
} else if ($tutar != $post['paymentAmount']) {
echo 'TUTAR_HATALI';
exit();
} else
{
if ($gel) {
$islem = $db->prepare("UPDATE bills SET status = ? WHERE id = ?");
$islem = $islem->execute(array(1, $gel['id']));
$orderusername = $gel["username"];
$userconten = $db->query("SELECT * FROM user WHERE username = '$orderusername' ")->fetch();
if ($userconten["balance"] == 0) {
$total = $gel["money"];
} else {
$total = $userconten["balance"]+$gel["money"];
}
$ek = $db->exec("UPDATE user SET balance ='$total' WHERE username ='$orderusername'");
echo "OK";
exit();
} else
{
/*
Ödeme işlenemedi. Hatanızı basın. Vallet bir kaç dakika sonra yeniden aynı ödeme için size bildirim gönderecektir.
Sisteminizin birden fazla hata vermesi yada OK cevabı dönmemesi durumunda vallet tarafından işyeri sahibi bilgilendirilecktir.
*/
echo 'SIPARIS_ISLENEMEDI';
exit();
}
}
}
}
} - 08-09-2023, 22:59:11İlgili firmanın birden fazla entegrasyonunu sağlamış bulunuyoruz, çok yüksek ihtimalle yaptığınız entegrede hata mevcuttur. Ücretli destek almak isterseniz iletişime geçebilirsiniz.
İletişim Bilgilerimiz:
Whatsapp: 0850 308 5778
Email: info@mofradlimited.com
R10 Konumuz:
https://www.r10.net/kodlama-yazilim-...489128187.html - 08-09-2023, 22:59:52biraz karmasık attım hocam kusura bakma ama suanda aktif calısan kodumu ilettim kodlarda ozellikle calback temizleme sagladım
- 08-09-2023, 23:03:42kodunuzu bir test edeyim hocam. umarım çalışır. Diğer sanal pos firmaları bu kadar uğraştırmamıştı beni. teşekkürler kod içinkoksalkesici adlı üyeden alıntı: mesajı görüntüle
rder_id LIMIT 1");