### Python Example: Initial Setup for PayTR Installment Rates Query Source: https://dev.paytr.com/direkt-api/taksit-sorgulama Illustrates the initial setup for querying PayTR installment rates using Python 3.6+. This snippet focuses on importing necessary libraries, defining API integration credentials (merchant ID, key, and salt), and generating a unique request ID based on the current timestamp. ```Python # Python 3.6+ import base64 import hmac import hashlib import requests import json import time # API Entegrasyon Bilgileri - Mağaza paneline giriş yaparak BİLGİ sayfasından alabilirsiniz. merchant_id = 'XXX' merchant_key = b'XXX' merchant_salt = 'XXX' # Sorgu ID request_id = str(time.time()) ``` -------------------------------- ### PayTR Payment Integration Parameters Setup (Python) Source: https://dev.paytr.com/iframe-api/iframe-api-1-adim This Python snippet outlines the initial setup for PayTR payment integration, including merchant credentials (ID, key, salt), customer details (email, name, address, phone), payment amount, order ID, and callback URLs. It also provides guidance on `user_basket` encoding and handling `user_ip` for local development, along with various payment configuration options like timeout, debug mode, test mode, installment limits, and currency. ```Python # Python 3.6+ # 1. ADIM için örnek kodlar import base64 import hmac import hashlib import requests import json # API Entegrasyon Bilgileri - Mağaza paneline giriş yaparak BİLGİ sayfasından alabilirsiniz. merchant_id = 'XXXXXX' merchant_key = b'YYYYYYYYYYYYYY' merchant_salt = b'ZZZZZZZZZZZZZZ' # Müşterinizin sitenizde kayıtlı veya form vasıtasıyla aldığınız eposta adresi email = 'XXXXXXXX' # Tahsil edilecek tutar. payment_amount = '' # 9.99 için 9.99 * 100 = 999 gönderilmelidir. # Sipariş numarası: Her işlemde benzersiz olmalıdır!! Bu bilgi bildirim sayfanıza yapılacak bildirimde geri gönderilir. merchant_oid = '' # Müşterinizin sitenizde kayıtlı veya form aracılığıyla aldığınız ad ve soyad bilgisi user_name = '' # Müşterinizin sitenizde kayıtlı veya form aracılığıyla aldığınız adres bilgisi user_address = '' # Müşterinizin sitenizde kayıtlı veya form aracılığıyla aldığınız telefon bilgisi user_phone = '' # Başarılı ödeme sonrası müşterinizin yönlendirileceği sayfa # !!! Bu sayfa siparişi onaylayacağınız sayfa değildir! Yalnızca müşterinizi bilgilendireceğiniz sayfadır! # !!! Siparişi onaylayacağız sayfa "Bildirim URL" sayfasıdır (Bakınız: 2.ADIM Klasörü). merchant_ok_url = 'http://www.siteniz.com/odeme_basarili.php' # Ödeme sürecinde beklenmedik bir hata oluşması durumunda müşterinizin yönlendirileceği sayfa # !!! Bu sayfa siparişi iptal edeceğiniz sayfa değildir! Yalnızca müşterinizi bilgilendireceğiniz sayfadır! # !!! Siparişi iptal edeceğiniz sayfa "Bildirim URL" sayfasıdır (Bakınız: 2.ADIM Klasörü). merchant_fail_url = 'http://www.siteniz.com/odeme_hata.php' # Müşterinin sepet/sipariş içeriği user_basket = '' # ÖRNEK $user_basket oluşturma - Ürün adedine göre array'leri çoğaltabilirsiniz """ user_basket = base64.b64encode(json.dumps([['Örnek ürün 1', '18.00', 1], ['Örnek ürün 2', '33.25', 2], ['Örnek ürün 3', '45.42', 1]]).encode()) """ # !!! Eğer bu örnek kodu sunucuda değil local makinanızda çalıştırıyorsanız # buraya dış ip adresinizi (https://www.whatismyip.com/) yazmalısınız. Aksi halde geçersiz paytr_token hatası alırsınız. user_ip = '' # İşlem zaman aşımı süresi - dakika cinsinden timeout_limit = '30' # Hata mesajlarının ekrana basılması için entegrasyon ve test sürecinde 1 olarak bırakın. Daha sonra 0 yapabilirsiniz. debug_on = '1' # Mağaza canlı modda iken test işlem yapmak için 1 olarak gönderilebilir. test_mode = '1' no_installment = '0' # Taksit yapılmasını istemiyorsanız, sadece tek çekim sunacaksanız 1 yapın # Sayfada görüntülenecek taksit adedini sınırlamak istiyorsanız uygun şekilde değiştirin. # Sıfır (0) gönderilmesi durumunda yürürlükteki en fazla izin verilen taksit geçerli olur. max_installment = '0' currency = 'TL' ``` -------------------------------- ### Start Express Server Source: https://dev.paytr.com/platform-transfer-talebi/transfer-talimatinin-verilmesi Starts the Express application, listening for incoming requests on port 3200, and logs a confirmation message to the console. ```javascript var port = 3200; app.listen(port, function () { console.log("Server is running. Port:" + port); }); ``` -------------------------------- ### Start Node.js Express Server Source: https://dev.paytr.com/iframe-api/iframe-api-1-adim This snippet initializes and starts the Node.js Express application, making it listen for incoming HTTP requests on a specified port. It includes a console log to confirm the server is running. ```JavaScript var port = 3000; app.listen(port, function () { console.log("Server is running. Port:" + port); }); ``` -------------------------------- ### Direkt API Request Parameters and Example Payload Source: https://dev.paytr.com/en/servis-test-araclari/servis-yanit-gozlem Outlines the parameters for the PayTR Direkt API, covering direct payment details, installment options, and test mode settings, with an example JSON request for direct integration. ```APIDOC Merchant ID: User IP: Merchant OID: Email: Payment Amount: Total Amount: Payment Type: installment_count: currency Test Mode: Non 3D: Merchant Salt: Merchant Key: ``` ```JSON { "merchant_id":"123456", "user_ip":"1.1.1.1", "merchant_oid":"ABC123", "email":"user@domainname.com", "payment_amount":"100", "total_amount":"100", "payment_type":"card", "installment_count":"0", "currency":"TL", "test_mode":"1", "non_3d":"0", "status":"success", "merchant_salt":"XXXYYYZZZ", "merchant_key":"XXXYYYZZZ" } ``` -------------------------------- ### Start Node.js Express Server Source: https://dev.paytr.com/en/platform-transfer-talebi/geri-donen-odemeleri-hesaptan-gonder-2 This snippet initializes a Node.js Express application to listen for incoming HTTP requests on a specified port (3200). It includes a callback function that executes once the server starts, logging a confirmation message to the console. ```JavaScript var port = 3200; app.listen(port, function () { console.log("Server is running. Port:" + port); }); ``` -------------------------------- ### Start Node.js Express Server Source: https://dev.paytr.com/platform-transfer-talebi/geri-donen-odemeleri-hesaptan-gonder This snippet initializes and starts the Express server on a specified port (3200). It includes a callback function that logs a confirmation message to the console once the server is successfully running and listening for incoming requests. ```javascript var port = 3200; app.listen(port, function () { console.log("Server is running. Port:" + port); }); ``` -------------------------------- ### Start Node.js Express Server Source: https://dev.paytr.com/direkt-api/direkt-api-1-adim This snippet initializes and starts the Express application, making it listen for incoming HTTP requests on a specified port (3200). A confirmation message is logged to the console once the server is successfully running. ```JavaScript var port = 3200; app.listen(port, function () { console.log("Server is running. Port:" + port); }); ``` -------------------------------- ### Python PayTR API Parameter Setup Source: https://dev.paytr.com/platform-transfer-talebi/transfer-talimatinin-verilmesi Python 3.6+ code snippet for initializing essential parameters required for PayTR API integration, including merchant credentials, order details, and transfer amounts. ```Python import base64 import hashlib import hmac import json import requests import random # API Entegrasyon Bilgilier - Mağaza paneline giriş yaparak BİLGİ sayfasından alabilirsiniz. merchant_id = 'MAGAZA_NO' merchant_key = b'XXXXXXXXXXX' merchant_salt = 'YYYYYYYYYYY' # Mağaza sipariş no: Satış için belirlediğiniz benzersiz sipariş numarası merchant_oid = '' # Satıcıya yapılacak bu ödemenin takibi için benzersiz takip numarası trans_id = random.randint(1, 9999999).__str__() # Satıcıya yapılacak ödeme tutarı: Satıcıya bu sipariş için ödenecek tutarın 100 ile çarpılmış hali (Örnek: 50.99 TL için 5099) submerchant_amount = '' # Toplam ödeme tutarı: Siparişe ait toplam ödeme tutarının 100 ile çarpılmış hali (Örnek: 50.99 TL için 5099) total_amount = '' # Satıcının banka hesabı için ad soyad/ünvanı transfer_name = '' # Satıcının banka hesabı IBAN numarası transfer_iban = '' ``` -------------------------------- ### Link API Request Parameters and Example Payload Source: https://dev.paytr.com/en/servis-test-araclari/servis-yanit-gozlem Specifies the parameters for creating a PayTR payment link, including product details, currency, and maximum installment options, along with an example JSON payload for link generation. ```APIDOC Name: Price: Currency: Max Installment: Link Type: Language: Peşin Fiyatına: Merchant Salt: Merchant Key: ``` ```JSON { "name":"Sample Product/Service Name", "price":"1445", "currency":"TL", "max_installment":"12", "link_type":"product", "lang":"TR", "pft":"0", "status":"success", "merchant_salt":"XXXYYYZZZ", "merchant_key":"XXXYYYZZZ" } ``` -------------------------------- ### Initialize PayTR Request (Node.js) Source: https://dev.paytr.com/platform-transfer-talebi/transfer-talimatinin-verilmesi This Node.js snippet shows the initial setup for making a PayTR request, including requiring the `request` and `crypto` modules. It indicates the libraries needed for the operation. ```JavaScript var request = require('request'); var crypto = require('crypto'); ``` -------------------------------- ### Node.js Express Setup for PayTR Transfer Request (Partial) Source: https://dev.paytr.com/platform-transfer-talebi/transfer-talimatinin-sonucunun-alinmasi This partial Node.js (Express) example illustrates the initial setup for integrating with PayTR to send transfer requests. It includes setting up an Express application and defining essential merchant credentials and transaction-specific variables required for constructing a transfer request. ```javascript var request = require('request'); var crypto = require('crypto'); var express = require('express'); var app = express(); app.use(express.json()); app.use(express.urlencoded({ extended: true })); var merchant_id = 'MAGAZA_NO'; var merchant_key = 'XXXXXXXXXXX'; var merchant_salt = 'YYYYYYYYYYY'; app.get("/send", function (req, res) { // Merchant order number: Unique order number you defined for the sales transaction var merchant_oid = ''; // Unique transfer number var trans_id = ''; // Amount to be paid to the merchant: The amount to be paid for this order multiplied by 100 (Example: 5099 for 50.99 TL) var submerchant_amount = ''; ``` -------------------------------- ### PayTR BIN Lookup Python Setup Source: https://dev.paytr.com/direkt-api/bin-sorgulama-servisi This Python 3.6+ example sets up the necessary parameters for making a PayTR BIN lookup API request. It includes placeholders for merchant ID, key, and salt, along with the BIN number to be queried. It imports required libraries for cryptographic operations and HTTP requests. ```python # Python 3.6+ # BIN sorgulama servisi için kullanılacak örnek kod import base64 import hmac import hashlib import requests import json # API Entegrasyon Bilgilier - Mağaza paneline giriş yaparak BİLGİ sayfasından alabilirsiniz. merchant_id = 'XXX' merchant_key = b'XXX' merchant_salt = 'XXX' # Sorgulama yapılmak istenen karta ait kart numarasının ilk 6 veya 8 hanesi. Maksimum doğrulama için 8 hane kullanın. bin_number = 'XXXXXX' ``` -------------------------------- ### Start Node.js Express Server Source: https://dev.paytr.com/platform-transfer-talebi/transfer-talimatinin-sonucunun-alinmasi This snippet initializes and starts the Node.js Express application, making it listen for incoming HTTP requests on the specified port (3200 in this example). This is a fundamental step for any web application built with Express. ```JavaScript var port = 3200; app.listen(port, function () { console.log("Server is running. Port:" + port); }); ``` -------------------------------- ### Python PayTR API Integration Setup and Transaction Data Preparation Source: https://dev.paytr.com/platform-transfer-talebi/geri-donen-odemeleri-hesaptan-gonder This Python 3.6+ snippet sets up the necessary credentials for PayTR API integration, including `merchant_id`, `merchant_key`, and `merchant_salt`. It also demonstrates how to prepare transaction details, such as `amount` (multiplied by 100) and `receiver` IBAN information, along with a unique `trans_id`. ```Python # Python 3.6+ import base64 import hmac import hashlib import json import requests import random # API Entegrasyon Bilgilier - Mağaza paneline giriş yaparak BİLGİ sayfasından alabilirsiniz. merchant_id = 'XXXXXX' merchant_key = b'XXXXXXXXYYYYYYYY' merchant_salt = 'XXXXXXXXYYYYYYYY' # Gerekli Bilgiler trans_id = 'PHG' + random.randint(1, 9999999).__str__() trans_info = [ { 'amount': '1283', # amount 100 ile çarpılarak gönderilir!! 'receiver': 'XYZ LTD ŞTİ', 'iban': 'TRXXXXXXXXXXXXXXXXXXXXX' } ] ``` -------------------------------- ### Link API Request Parameters and Example JSON Source: https://dev.paytr.com/servis-test-araclari/servis-yanit-gozlem This section describes the parameters for the PayTR Link API, used to generate payment links. It covers product details, pricing, currency, installment options, and link type. The JSON example illustrates a typical request body for creating a payment link. ```APIDOC Link API Request Body: name (string): Name of the product or service. price (string): Price of the product in cents. currency (string): The currency code (e.g., "TL"). max_installment (string): Maximum number of installments allowed. link_type (string): Type of link (e.g., "product"). lang (string): Language of the payment page (e.g., "TR"). pft (string): "0" for no interest-free installment, "1" for interest-free installment. merchant_salt (string): Your merchant salt key. merchant_key (string): Your merchant key. ``` ```JSON { "name":"Örnek Ürün / Hizmet Adı", "price":"1445", "currency":"TL", "max_installment":"12", "link_type":"product", "lang":"TR", "pft":"0", "status":"success", "merchant_salt":"XXXYYYZZZ", "merchant_key":"XXXYYYZZZ" } ``` -------------------------------- ### Node.js Express Server Initialization Source: https://dev.paytr.com/platform-transfer-talebi/geri-donen-odemeleri-listele Initializes and starts the Node.js Express server on a specified port (3200), making the defined API endpoints accessible for incoming requests. ```javascript var port = 3200; app.listen(port, function () { console.log("Server is running. Port:" + port); }); ``` -------------------------------- ### PayTR C# Payment Integration Setup Source: https://dev.paytr.com/direkt-api/kart-saklama-api/kayitli-karttan-odeme This snippet demonstrates the complete initial setup for a PayTR payment integration in C#. It includes defining user and merchant details, configuring success and failure URLs, dynamically detecting the user's IP address, structuring the product basket, setting various payment parameters (e.g., card type, debug mode, installment count, currency), serializing the basket for API submission, and generating the HMACSHA256 security token. It also shows how to prepare variables for CAPI LIST service integration and pass data to a view. ```C# string user_addressstr = ""; // // Müşterinizin sitenizde kayıtlı veya form aracılığıyla aldığınız telefon bilgisi string user_phonestr = ""; // // Başarılı ödeme sonrası müşterinizin yönlendirileceği sayfa // !!! Bu sayfa siparişi onaylayacağınız sayfa değildir! Yalnızca müşterinizi bilgilendireceğiniz sayfadır! // !!! Siparişi onaylayacağız sayfa "Bildirim URL" sayfasıdır (Bakınız: 2.ADIM Klasörü). string merchant_ok_url = "http://siteniz.com/success"; // // Ödeme sürecinde beklenmedik bir hata oluşması durumunda müşterinizin yönlendirileceği sayfa // !!! Bu sayfa siparişi iptal edeceğiniz sayfa değildir! Yalnızca müşterinizi bilgilendireceğiniz sayfadır! // !!! Siparişi iptal edeceğiniz sayfa "Bildirim URL" sayfasıdır (Bakınız: 2.ADIM Klasörü). string merchant_fail_url = "http://siteniz.com/failed"; // // !!! Eğer bu örnek kodu sunucuda değil local makinanızda çalıştırıyorsanız // buraya dış ip adresinizi (https://www.whatismyip.com/) yazmalısınız. Aksi halde geçersiz paytr_token hatası alırsınız. string user_ip = Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; if (user_ip == "" || user_ip == null){ user_ip = Request.ServerVariables["REMOTE_ADDR"]; } // // ÖRNEK $user_basket oluşturma - Ürün adedine göre object'leri çoğaltabilirsiniz object[][] user_basket = { new object[] {"Örnek ürün 1", "18.00", 1}, // 1. ürün (Ürün Ad - Birim Fiyat - Adet) new object[] {"Örnek ürün 2", "33.25", 2}, // 2. ürün (Ürün Ad - Birim Fiyat - Adet) new object[] {"Örnek ürün 3", "45.42", 1} // 3. ürün (Ürün Ad - Birim Fiyat - Adet) }; /* ############################################################################################ */ // İşlem zaman aşımı süresi - dakika cinsinden string card_type = "bonus"; // // Hata mesajlarının ekrana basılması için entegrasyon ve test sürecinde 1 olarak bırakın. Daha sonra 0 yapabilirsiniz. string debug_on = "1"; // // Mağaza canlı modda iken test işlem yapmak için 1 olarak gönderilebilir. string test_mode = "0"; // // 3D'siz işlem string non_3d = "0"; // // Non3d Test Failed string non3d_test_failed = "0"; // // Taksit Sayısı string installment_count = "0"; // // Ödeme türü string payment_type = "card"; // // Post adresi string post_url = "https://www.paytr.com/odeme"; // // Para birimi olarak TL, EUR, USD gönderilebilir. USD ve EUR kullanmak için kurumsal@paytr.com // üzerinden bilgi almanız gerekmektedir. Boş gönderilirse TL geçerli olur. string currency = "TL"; // // // Sepet içerği oluşturma fonksiyonu, değiştirilmeden kullanılabilir. JavaScriptSerializer ser = new JavaScriptSerializer(); string user_basket_json = ser.Serialize(user_basket); // // Token oluşturma fonksiyonu, değiştirilmeden kullanılmalıdır. string Birlestir = string.Concat(merchant_id, user_ip, merchant_oid, emailstr, payment_amountstr.ToString(), payment_type, installment_count, currency, test_mode, non_3d, merchant_salt); HMACSHA256 hmac = new HMACSHA256(Encoding.UTF8.GetBytes(Birlestir)); byte[] b = hmac.ComputeHash(Encoding.UTF8.GetBytes(Birlestir)); // // CAPI LIST servisinden dönen require_cvv, utoken ve ctoken değerlerinin kullanımı ## // Ödeme işlemini yapan kullanıcının kayıtlı kart listesi alınarak kullanıcının önüne listelenlir. ## // Kullanıcı listelenen kartlar arasından ödeme yapacağı kartı seçer ## //# Kullanıcının seçtiği karta ait require_cvv parametresi kontrol edilip eğer 1 ise CVV gireceği alan gösterilir ## // Kullanıcının seçtiği kartın ctoken bilgisi ve kullanıcının utoken bilgisi ödeme isteğinde gönderilir. ## string utoken = ""; string ctoken = ""; string require_cvv = ""; ViewBag.MerchantId = merchant_id; ViewBag.UserIp = user_ip; ViewBag.MerchantOid = merchant_oid; ViewBag.Email = emailstr; ViewBag.PaymentType = payment_type; ViewBag.PaymentAmount = payment_amountstr.ToString(); ViewBag.InstallmentCount = installment_count; ViewBag.Currency = currency; ViewBag.TestMode = test_mode; ViewBag.Non3d = non_3d; ViewBag.MerchantOkUrl = merchant_ok_url; ``` -------------------------------- ### Initialize PayTR API Credentials and Date Range in Python Source: https://dev.paytr.com/platform-transfer-talebi/geri-donen-odemeleri-listele This Python snippet demonstrates how to import necessary libraries (base64, hmac, hashlib, json, requests) for API interaction. It shows the setup of essential PayTR API credentials such as `merchant_id`, `merchant_key`, and `merchant_salt`. Additionally, it defines `start_date` and `end_date` parameters for API requests, noting the maximum allowed date range. ```python # Python 3.6+ import base64 import hmac import hashlib import json import requests # API Entegrasyon Bilgilier - Mağaza paneline giriş yaparak BİLGİ sayfasından alabilirsiniz. merchant_id = 'XXXXXX' merchant_key = b'XXXXXXXXYYYYYYYY' merchant_salt = 'XXXXXXXXYYYYYYYY' # Gerekli Bilgiler start_date = '2020-05-20 00:00:00' end_date = '2020-06-16 23:59:59' # Başlangıç / Bitiş tarihi. En fazla 31 gün aralık tanımlanabilir. ``` -------------------------------- ### PayTR Installment Rates Service Overview Source: https://dev.paytr.com/en/servis-test-araclari/postman Used in Direct API integration to query and retrieve current installment rates. Merchants can pull these rates daily, save them, and apply them dynamically based on product prices for installment transactions. ```APIDOC Installment Rates Service: Purpose: Used in Direct API integration to pull installment rates. Usage: Rates can vary daily; pull them via API, save to database, and update. Apply rates according to product price in installment transactions. ``` -------------------------------- ### Initialize Express Application and Middleware Source: https://dev.paytr.com/platform-transfer-talebi/transfer-talimatinin-verilmesi Sets up a basic Express application, enabling JSON and URL-encoded body parsing for handling incoming request data. ```javascript var express = require('express'); var app = express(); app.use(express.json()); app.use(express.urlencoded({ extended: true })); ``` -------------------------------- ### PHP Example for PayTR Installment Rates Query Source: https://dev.paytr.com/en/direkt-api/taksit-sorgulama This PHP code demonstrates how to query installment rates from the PayTR API. It constructs a token using `merchant_id`, `request_id`, `merchant_salt`, and `merchant_key`, then sends a POST request to the PayTR endpoint. It handles cURL errors and decodes the JSON response, printing the result or an error message. ```PHP $merchant_id, 'request_id'=>$request_id, 'paytr_token'=>$paytr_token ); $ch=curl_init(); curl_setopt($ch, CURLOPT_URL, "https://www.paytr.com/odeme/taksit-oranlari"); 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, 90); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 90); $result = @curl_exec($ch); if(curl_errno($ch)) { echo curl_error($ch); curl_close($ch); exit; } curl_close($ch); $result=json_decode($result,1); if($result[status]=='success') { //VT işlemleri vs. print_r($result); } else //Örn. $result -> array('status'=>'error', "err_msg" => "Zorunlu alan degeri gecersiz veya gonderilmedi: " { echo $result[err_msg]; } ``` -------------------------------- ### Direct API Request Body Example Source: https://dev.paytr.com/servis-test-araclari/hash-hesaplama This JSON payload demonstrates the parameters required for direct payment processing through the PayTR API. It specifies the payment type (e.g., 'card'), installment count, and standard merchant and user details. The example also includes settings for test mode and 3D Secure bypass. ```JSON { "merchant_id":"123456", "user_ip":"1.1.1.1", "merchant_oid":"ABC123", "email":"user@domainname.com", "payment_amount":"100", "payment_type":"card", "installment_count":"0", "currency":"TL", "test_mode":"1", "non_3d":"0", "merchant_salt":"XXXYYYZZZ", "merchant_key":"XXXYYYZZZ" } ``` -------------------------------- ### Start Node.js Express Server Source: https://dev.paytr.com/en/iframe-api/iframe-api-1-adim This snippet initializes and starts the Express server on port 3000. It logs a confirmation message to the console once the server is successfully running, indicating the port it's listening on. ```javascript var port = 3000; app.listen(port, function () { console.log("Server is running. Port:" + port); }); ``` -------------------------------- ### Successful iFrame Token API Response Example Source: https://dev.paytr.com/en/iframe-api/iframe-api-1-adim An example of a successful JSON response received from the PayTR API after a token request. This response includes the 'status' indicating success and the 'token' string, which is essential for embedding the payment iFrame. ```JSON {"status":"success","token":"28cc613c3d7633cfa4ed0956fdf901e05cf9d9cc0c2ef8db54fa"} ``` -------------------------------- ### PHP Example: Initializing PayTR Payment Parameters Source: https://dev.paytr.com/en/direkt-api/direkt-api-1-adim This PHP code snippet demonstrates how to set up the initial parameters required for a PayTR payment request. It includes defining merchant credentials, redirect URLs, encoding the user's shopping basket into a JSON string, generating a unique order ID, and detecting the user's IP address for the transaction. ```PHP $merchant_id, 'request_id'=>$request_id, 'paytr_token'=>$paytr_token ); $ch=curl_init(); curl_setopt($ch, CURLOPT_URL, "https://www.paytr.com/odeme/taksit-oranlari"); 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, 90); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 90); //XXX: DİKKAT: lokal makinanızda "SSL certificate problem: unable to get local issuer certificate" uyarısı alırsanız eğer //aşağıdaki kodu açıp deneyebilirsiniz. ANCAK, güvenlik nedeniyle sunucunuzda (gerçek ortamınızda) bu kodun kapalı kalması çok önemlidir! //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); $result = @curl_exec($ch); if(curl_errno($ch)) { echo curl_error($ch); curl_close($ch); exit; } curl_close($ch); $result=json_decode($result,1); if($result[status]=='success') { //VT işlemleri vs. print_r($result); } else //Örn. $result -> array('status'=>'error', "err_msg" => "Zorunlu alan degeri gecersiz veya gonderilmedi: " { echo $result[err_msg]; } ``` -------------------------------- ### Python API Integration Setup and Credentials Source: https://dev.paytr.com/durum-sorgu This Python snippet outlines the initial setup for integrating with a payment API. It imports necessary cryptographic and networking libraries and defines placeholder variables for merchant credentials such as ID, key, salt, and order ID, which are crucial for authenticating and identifying transactions. ```Python # Python 3.6+ import base64 import hmac import hashlib import requests import json import random # API Entegrasyon Bilgilier - Mağaza paneline giriş yaparak BİLGİ sayfasından alabilirsiniz. merchant_id = 'XXXXXXXXX' merchant_key = b'XXXXXXXXXXXXXXXXXX' merchant_salt = 'XXXXXXXXXXXXXXXXXX' merchant_oid = '' ``` -------------------------------- ### Node.js Express PayTR Payment Gateway Integration Example Source: https://dev.paytr.com/direkt-api/kart-saklama-api/yeni-kart-ekleme This Node.js Express application snippet provides a comprehensive example of integrating with the PayTR payment gateway. It sets up an Express server, defines various merchant and user parameters (like merchant ID, key, salt, user IP, email, payment amount, etc.), calculates the PayTR token using HMAC-SHA256, and prepares a context object for rendering a payment view. It includes details for setting up merchant IDs, keys, salts, user information, and payment details, along with handling success and failure URLs. ```JavaScript var express = require('express'); var ejsLayouts = require('express-ejs-layouts'); var microtime = require('microtime'); var crypto = require('crypto'); var nodeBase64 = require('nodejs-base64-converter'); var app = express(); var path = require('path'); app.set('views', path.join(__dirname, '/app_server/views')); app.set('view engine', 'ejs'); app.use(ejsLayouts); app.use(express.json()); app.use(express.urlencoded({ extended: true })); var merchant_id = 'XXXXXX'; var merchant_key = 'XXXXXX'; var merchant_salt = 'XXXXXX'; var basket = JSON.stringify([['Örnek Ürün 1', '50.00', 1], ['Örnek Ürün 2', '50.00', 1]]); var user_basket = basket; var merchant_oid = "IN" + microtime.now(); // Sipariş numarası: Her işlemde benzersiz olmalıdır!! Bu bilgi bildirim sayfanıza yapılacak bildirimde geri gönderilir. var user_ip = ''; var email = ''; // Müşterinizin sitenizde kayıtlı veya form vasıtasıyla aldığınız eposta adresi. var payment_amount = '100.99'; // Tahsil edilecek tutar. 100.99 var currency = 'TL'; var test_mode = '0'; // Mağaza canlı modda iken test işlem yapmak için 1 olarak gönderilebilir. var user_name = 'PayTR Test'; // Müşterinizin sitenizde kayıtlı veya form aracılığıyla aldığınız ad ve soyad bilgisi. var user_address = 'test test test'; // Müşterinizin sitenizde kayıtlı veya form aracılığıyla aldığınız adres bilgisi. var user_phone = '05555555555'; // Müşterinizin sitenizde kayıtlı veya form aracılığıyla aldığınız telefon bilgisi. // Başarılı ödeme sonrası müşterinizin yönlendirileceği sayfa // Bu sayfa siparişi onaylayacağınız sayfa değildir! Yalnızca müşterinizi bilgilendireceğiniz sayfadır! var merchant_ok_url = 'http://www.siteniz.com/odeme_basarili.php'; // Ödeme sürecinde beklenmedik bir hata oluşması durumunda müşterinizin yönlendirileceği sayfa // Bu sayfa siparişi iptal edeceğiniz sayfa değildir! Yalnızca müşterinizi bilgilendireceğiniz sayfadır! var merchant_fail_url = 'http://www.siteniz.com/odeme_hata.php'; var debug_on = 1; // Hata mesajlarının ekrana basılması için entegrasyon ve test sürecinde 1 olarak bırakın. Daha sonra 0 yapabilirsiniz. var client_lang = 'tr'; var payment_type = 'card'; var installment_count = '0'; var non_3d = '0'; // 3D'siz işlem. var card_type = ''; var non3d_test_failed = '0'; // Non3d Test Failed. // UTOKEN GÖNDERİLMEDİĞİ DURUMDA, BU KULLANICIYA AİT DAHA ÖNCEDEN KAYDEDİLMİŞ BİR KART OLMADIĞI VARSAYILIR //VE PAYTR TARAFINDA YENİ BİR UTOKEN OLUŞTURULARAK ÖDEME İŞLEMİNİN CEVABINDA DÖNDÜRÜLÜR (BİLDİRİM URL'YE)! // EĞER KULLANICI SİSTEMİNİZDE DAHA ÖNCE BİR KART KAYDETMİŞSE TARAFINIZDA KAYITLI UTOKEN PARAMETRESİNİ POST // İÇERİĞİNE EKLEMELİSİNİZ. BÖYLECE BU KART DA AYNI KULLANICIYA TANIMLANACAKTIR. EĞER MEVCUT KULLANICI İÇİN //YENİ BİR KART TANIMI YAPILACAĞI HALDE MEVCUT UTOKEN GÖNDERİLMEZSE YENİ BİR UTOKEN OLUŞTURULACAĞINDAN KULLANICININ //TÜM KARTLARI TEK BİR UTOKEN ALTINDA GRUPLANMAZ!!! var utoken = ""; app.get("/", function (req, res) { var hashSTR = `${merchant_id}${user_ip}${merchant_oid}${email}${payment_amount}${payment_type}${installment_count}${currency}${test_mode}${non_3d}`; var paytr_token = hashSTR + merchant_salt; var token = crypto.createHmac('sha256', merchant_key).update(paytr_token).digest('base64'); context = { merchant_id, user_ip, merchant_oid, email, payment_type, payment_amount, currency, test_mode, non_3d, merchant_ok_url, merchant_fail_url, user_name, user_address, user_phone, user_basket, debug_on, client_lang, token, non3d_test_failed, installment_count, card_type, utoken, }; res.render('index'); }); var port = 3200; app.listen(port, function () { console.log("Server is running. Port:" + port); }); ``` -------------------------------- ### Example Payment Page HTML Structure with PHP Merchant ID Source: https://dev.paytr.com/havale-eft-iframe-api/havale-eft-iframe-api-1-adim An example HTML structure for a payment page, demonstrating the basic layout and an embedded PHP variable for the merchant ID. This snippet is part of the initial setup for integrating the PayTR iFrame. ```HTML Örnek Ödeme Sayfası

Örnek Ödeme Sayfası