Skip to content

bulentsakarya/paytr-laravel

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Licence

MIT License

Description

PayTR integration for Laravel.
This package is under development, first version only supports iFame payment screen.

Thanks in advance for your contribution.

Installation

composer require turown/laravel-paytr

Publish configuration and assets

php artisan vendor:publish --tag="paytr"

Usage

To run this project you will need to add the following environment variables to your .env file

PAYTR_MERCANT_ID
PAYTR_MERCANT_KEY
PAYTR_MERCANT_SALT
PAYTR_API_URL
PAYTR_OK_URL
PAYTR_FAIL_URL

Configs

You can change or get the necessary settings in the config file. This file is important

use PayTR\Config;

You can easily access it with the help of it, you can perform operations as in the example.

The example below is the config that needs to be set for simple api triggering.

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

Next, we define the required array variable to generate the HASH DATA.

 $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()
    ];

And we set the post data array and trigger the necessary

 $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.

Then you can activate the PayTR class and operate with the call method.

use PayTR\Paytr;

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



Using iFrame will return you success and a token after the transaction. In addition, I have included the necessary javascript codes for you.

{
  +"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>"
}

By including the script with the "javascript_file_url" in the return, you can print the "iframe_code" code wherever you want. Don't forget to include the "script" variable as well.



It's actually that simple!

A payment screen will then appear on your screen. After the transaction made on this screen, the API will return to you, all your successful or unsuccessful returns are specified in the settings;

'merchant_ok_url' => $config->getMerchantOkUrl()
'merchant_fail_url' => $config->getMerchantFailUrl()

This is why these settings are very important.

About

PayTR integration for Laravel.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%