PHP code example of turown / laravel-paytr

1. Go to this page and download the library: Download turown/laravel-paytr library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

turown / laravel-paytr example snippets


$config = new Config();
$config->setMerchantId(00000)
       ->setMerchantKey("XXXXX")
       ->setMerchantSalt("XXXX")
       ->setApiType(2) // iFrame Type
       ->setApiUrl(ENV('PAYTR_API_URL') . 'odeme/api/get-token');

 $hash_data = [
        "merchant_id"       => $config->getMerchantId(),
        "user_ip"           => request()->ip(),
        "merchant_oid"      => 1002945, //must be unique
        "email"             => "[email protected]",
        "payment_amount"    => 999, //9.99 TL|EUR|USD vs. for 999;
        "user_basket"       => json_encode([
            ["Test Product", "9.99", 1] //(Product Name - Unit Price - Quantity)
        ]),
        "no_installment"    => $config->getNoInstallment(),
        "max_installment"   => $config->getMaxInstallment(),
        "currency"          => $config->getCurrency(),
        "test_mode"         => $config->getTestMode()
    ];

 $post_data = [
        'user_name'         => "Ali Rıza Öztetik",
        'user_address'      => "test",
        'user_phone'        => "901111111111", //Need [+][country code][area code][phone number]
        'paytr_token'       => $paytr->setHashStr($hash_data)->getToken()->token,
        'debug_on'          => $config->getDebugOn(),
        'merchant_ok_url'   => $config->getMerchantOkUrl(),
        'merchant_fail_url' => $config->getMerchantFailUrl(),
        'timeout_limit'     => $config->getTimeoutLimit()
    ];

 $post_data = array_merge($post_data, $hash_data); //Absolutely 2 array data must be combined.

$trigger = $paytr->call($post_data, $config->getApiUrl());

{
  +"status": "success"
  +"token": "090aab565210f757db0d9948ed4f58c8723a9f1de3beac1f651a90cdf9b2f678-324703229"
  +"javascript_file_url": "https://www.paytr.com/js/iframeResizer.min.js"
  +"iframe_code": "<iframe src="https://www.paytr.com/odeme/guvenli/090aab565210f757db0d9948ed4f58c8723a9f1de3beac1f651a90cdf9b2f678-324703229" id="paytriframe" frameborder="0" scrolling="no" style="width: 100%;"></iframe>"
  +"script": "<script>iFrameResize({},'#paytriframe');</script>"
}