hkucuk

Iyzico Payment System Laravel Package

August 19, 2016 • ☕️ 3 min read • 🏷 computer, software

Translated by author into: English


Iyzico is a simple and easy to understand payment system. For more detailed information about Iyzico you can follow the links at the site, and you can follow up for a detailed use. Here I will introduce the package I developed in accordance with the PHP Laravel Framework for the use of API provided by iyzico.


Working logic

Iyzico’s principle of work lies in the principle of “2 queries 2 answers”. First we request a payment form by sending certain parameters to iyzico api. Then, after filling in and confirming the user form, we direct our processes according to the answers from iyizico.

The package that I have developed makes these stages suitable for laravel by linking to the iyzico API and requesting the payment form. Though these steps can be performed with a normal function definition, contributing to the development of the laravel world is not a bad idea at all.

Package Connections:
Github: https://github.com/medyun/hkucuk-iyzico-laravel-package Packagist: https://packagist.org/packages/hkucuk/iyzico

Package Installation:
We need to use Composer to install the package. If you are using composer, you should start using it immediately by following the link. We do the following to the composer.json file in our project file:

{
    "require": {
        "hkucuk/iyzico": "v1.0.0"
    }
}

Then we update our composer file:

composer update

If there is no problem here, your package computer will be installed. After that, we need to make the following arrangements in order for the package to be available in Laravel.

First, we add the following value to the providers value in the config/app.php file.

'providers' => array(
    // ...
    'Hkucuk\Iyzico\IyzicoServiceProvider',
)

Then we do the following addition to the aliases value in the config/app.php file.

'aliases' => array(
    // ...
    'Iyzico' => 'Hkucuk\Iyzico\Facades\Iyzico',
)

After these settings, we finally have to publish the package. In this, we will have to run the following commune from the consol.

php artisan vendor:publish

Package Usage

We need to enter api_id and secret values in config/config.php that comes in the package. If you want to keep these values below the main config directory, you can also define config/packages/hkucuk/iyzico/config.php file in this file.

$data = array(
    "customer_language" => "tr",
    "mode" => "test",
    "external_id" => rand(),
    "type" => "CC.DB",
    "installment" => true,
    "amount" => 1099,
    "return_url" => "http://example.com/iyzicoResponse",
    "currency" => "TRY"
);

$response = Iyzico::getForm($data);

echo $response->code_snippet;

Request for payment form can be made as above. Here, the parameters sent in $ data can vary and can be determined as needed. Here, the code_snippet value of the returned response gives us the code of the form. When we print these codes on the screen, the payment form will appear.

After the form is submitted, the reply from iyzico can be followed as follows:

$data = json_decode(Input::get("json"), true);
var_dump($data);

That is all. If things go well then Laravel and iyzico can be connected in this way.

Good luck.