I'm getting this error when I try so save api configure for Iyzico payment gateway

```
TypeError: array_key_last(): Argument #1 ($array) must be of type array, string given in /chroot/home/a94b818d/de88c03958.nxcli.io/app/code/Iyzico/Iyzipay/Controller/IyzicoBase/IyzicoPkiStringBuilder.php:109
Stack trace:
#0 /chroot/home/a94b818d/de88c03958.nxcli.io/app/code/Iyzico/Iyzipay/Controller/IyzicoBase/IyzicoPkiStringBuilder.php(109): array_key_last('tr')
#1 /chroot/home/a94b818d/de88c03958.nxcli.io/app/code/Iyzico/Iyzipay/Observer/IyzipayConfigSaveBefore.php(77): Iyzico\Iyzipay\Controller\IyzicoBase\IyzicoPkiStringBuilder->pkiStringGenerate(Object(stdClass))
#2 /chroot/home/a94b818d/de88c03958.nxcli.io/vendor/magento/framework/Event/Invoker/InvokerDefault.php(88): Iyzico\Iyzipay\Observer\IyzipayConfigSaveBefore->execute(Object(Magento\Framework\Event\Observer))
#3 /chroot/home/a94b818d/de88c03958.nxcli.io/vendor/magento/framework/Event/Invoker/InvokerDefault.php(74): Magento\Framework\Event\Invoker\InvokerDefault->_callObserverMethod(Object(Iyzico\Iyzipay\Observer\IyzipayConfigSaveBefore), Object(Magento\Framework\Event\Observer))
#4 /chroot/home/a94b818d/de88c03958.nxcli.io/vendor/magento/framework/Event/Manager.php(65): Magento\Framework\Event\Invoker\InvokerDefault->dispatch(Array, Object(Magento\Framework\Event\Observer))
#5 /chroot/home/a94b818d/de88c03958.nxcli.io/generated/code/Magento/Framework/Event/Manager/Proxy.php(95): Magento\Framework\Event\Manager->dispatch('admin_system_co...', Array)
#6 /chroot/home/a94b818d/de88c03958.nxcli.io/vendor/magento/module-config/Model/Config.php(225): Magento\Framework\Event\Manager\Proxy->dispatch('admin_system_co...', Array)
#7 /chroot/home/a94b818d/de88c03958.nxcli.io/vendor/magento/module-config/Controller/Adminhtml/System/Config/Save.php(226): Magento\Config\Model\Config->save()
#8 /chroot/home/a94b818d/de88c03958.nxcli.io/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Config\Controller\Adminhtml\System\Config\Save->execute()
#9 /chroot/home/a94b818d/de88c03958.nxcli.io/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Config\Controller\Adminhtml\System\Config\Save\Interceptor->___callParent('execute', Array)
#10 /chroot/home/a94b818d/de88c03958.nxcli.io/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Config\Controller\Adminhtml\System\Config\Save\Interceptor->Magento\Framework\Interception\{closure}()
#11 /chroot/home/a94b818d/de88c03958.nxcli.io/generated/code/Magento/Config/Controller/Adminhtml/System/Config/Save/Interceptor.php(23): Magento\Config\Controller\Adminhtml\System\Config\Save\Interceptor->___callPlugins('execute', Array, Array)
#12 /chroot/home/a94b818d/de88c03958.nxcli.io/vendor/magento/framework/App/Action/Action.php(111): Magento\Config\Controller\Adminhtml\System\Config\Save\Interceptor->execute()
#13 /chroot/home/a94b818d/de88c03958.nxcli.io/vendor/magento/module-backend/App/AbstractAction.php(151): Magento\Framework\App\Action\Action->dispatch(Object(Magento\Framework\App\Request\Http))
#14 /chroot/home/a94b818d/de88c03958.nxcli.io/vendor/magento/module-config/Controller/Adminhtml/System/AbstractConfig.php(69): Magento\Backend\App\AbstractAction->dispatch(Object(Magento\Framework\App\Request\Http))
#15 /chroot/home/a94b818d/de88c03958.nxcli.io/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Config\Controller\Adminhtml\System\AbstractConfig->dispatch(Object(Magento\Framework\App\Request\Http))
#16 /chroot/home/a94b818d/de88c03958.nxcli.io/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Config\Controller\Adminhtml\System\Config\Save\Interceptor->___callParent('dispatch', Array)
#17 /chroot/home/a94b818d/de88c03958.nxcli.io/vendor/magento/module-backend/App/Action/Plugin/Authentication.php(145): Magento\Config\Controller\Adminhtml\System\Config\Save\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#18 /chroot/home/a94b818d/de88c03958.nxcli.io/vendor/magento/framework/Interception/Interceptor.php(135): Magento\Backend\App\Action\Plugin\Authentication->aroundDispatch(Object(Magento\Config\Controller\Adminhtml\System\Config\Save\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#19 /chroot/home/a94b818d/de88c03958.nxcli.io/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Config\Controller\Adminhtml\System\Config\Save\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#20 /chroot/home/a94b818d/de88c03958.nxcli.io/generated/code/Magento/Config/Controller/Adminhtml/System/Config/Save/Interceptor.php(32): Magento\Config\Controller\Adminhtml\System\Config\Save\Interceptor->___callPlugins('dispatch', Array, Array)
#21 /chroot/home/a94b818d/de88c03958.nxcli.io/vendor/magento/framework/App/FrontController.php(245): Magento\Config\Controller\Adminhtml\System\Config\Save\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#22 /chroot/home/a94b818d/de88c03958.nxcli.io/vendor/magento/framework/App/FrontController.php(212): Magento\Framework\App\FrontController->getActionResponse(Object(Magento\Config\Controller\Adminhtml\System\Config\Save\Interceptor), Object(Magento\Framework\App\Request\Http))
#23 /chroot/home/a94b818d/de88c03958.nxcli.io/vendor/magento/framework/App/FrontController.php(147): Magento\Framework\App\FrontController->processRequest(Object(Magento\Framework\App\Request\Http), Object(Magento\Config\Controller\Adminhtml\System\Config\Save\Interceptor))
#24 /chroot/home/a94b818d/de88c03958.nxcli.io/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\App\FrontController->dispatch(Object(Magento\Framework\App\Request\Http))
#25 /chroot/home/a94b818d/de88c03958.nxcli.io/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\App\FrontController\Interceptor->___callParent('dispatch', Array)
#26 /chroot/home/a94b818d/de88c03958.nxcli.io/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#27 /chroot/home/a94b818d/de88c03958.nxcli.io/generated/code/Magento/Framework/App/FrontController/Interceptor.php(23): Magento\Framework\App\FrontController\Interceptor->___callPlugins('dispatch', Array, Array)
#28 /chroot/home/a94b818d/de88c03958.nxcli.io/vendor/magento/framework/App/Http.php(116): Magento\Framework\App\FrontController\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#29 /chroot/home/a94b818d/de88c03958.nxcli.io/generated/code/Magento/Framework/App/Http/Interceptor.php(23): Magento\Framework\App\Http->launch()
#30 /chroot/home/a94b818d/de88c03958.nxcli.io/vendor/magento/framework/App/Bootstrap.php(264): Magento\Framework\App\Http\Interceptor->launch()
#31 /chroot/home/a94b818d/de88c03958.nxcli.io/pub/index.php(30): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http\Interceptor))
#32 {main}

```

**IyzicoPkiStringBuilder.php**

```
<?php
/**
 * iyzico Payment Gateway For Magento 2
 * Copyright (C) 2018 iyzico
 *
 * This file is part of Iyzico/Iyzipay.
 *
 * Iyzico/Iyzipay is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

namespace Iyzico\Iyzipay\Controller\IyzicoBase;

class IyzicoPkiStringBuilder
{

    public function pkiStringGenerate($objectData) {

        $pki_value = "[";
        foreach ($objectData as $key => $data) {

            if(is_object($data)) {

                $name = var_export($key, true);
                $name = str_replace("'", "", $name);
                $pki_value .= $name."=[";

                $end_key = count(get_object_vars($data));
                $count   = 0;

                foreach ($data as $key => $value) {

                    $count++;
                    $name = var_export($key, true);
                    $name = str_replace("'", "", $name);

                    $pki_value .= $name."="."".$value;

                    if($end_key != $count)
                        $pki_value .= ",";
                }

                $pki_value .= "]";

            } else if(is_array($data)) {
                $name = var_export($key, true);
                $name = str_replace("'", "", $name);

                $pki_value .= $name."=[";
                $end_key = count($data);
                $count   = 0;

                foreach ($data as $key => $result) {

                    $count++;
                    $pki_value .= "[";

                    foreach ($result as $key => $item) {
                        $name = var_export($key, true);
                        $name = str_replace("'", "", $name);

                        $pki_value .= $name."="."".$item;
                        $Dresult = (array) $result;

                        $newResult = $Dresult[array_key_last($Dresult)];

                        if($newResult != $item) {
                            $pki_value .= ",";
                        }

                        if($newResult == $item) {
                            if($end_key != $count) {

                                $pki_value .= "], ";

                            } else {

                                $pki_value .= "]";
                            }
                        }
                    }
                }
                $Ddata = (array) $data;

                $newData = $data[array_key_last($data)];
                if($newData == $result)
                    $pki_value .= "]";

            } else {

                $name = var_export($key, true);
                $name = str_replace("'", "", $name);

                $pki_value .= $name."="."".$data."";
            }
                $Ddata = (array) $data;
                $newData = $data[array_key_last($data)];
            if($newObjectData != $data)
                $pki_value .= ",";
        }

        $pki_value .= "]";

        return $pki_value;
    }

    public function createFormObjectSort($objectData) {

        $form_object = new stdClass();

        $form_object->locale                        = $objectData->locale;
        $form_object->conversationId                = $objectData->conversationId;
        $form_object->price                         = $objectData->price;
        $form_object->basketId                      = $objectData->basketId;
        $form_object->paymentGroup                  = $objectData->paymentGroup;

        $form_object->buyer = new stdClass();
        $form_object->buyer = $objectData->buyer;

        $form_object->shippingAddress = new stdClass();
        $form_object->shippingAddress = $objectData->shippingAddress;

        $form_object->billingAddress = new stdClass();
        $form_object->billingAddress = $objectData->billingAddress;

        foreach ($objectData->basketItems as $key => $item) {

            $form_object->basketItems[$key] = new stdClass();
            $form_object->basketItems[$key] = $item;

        }

        $form_object->callbackUrl           = $objectData->callbackUrl;
        $form_object->paymentSource         = $objectData->paymentSource;
        $form_object->currency              = $objectData->currency;
        $form_object->paidPrice             = $objectData->paidPrice;
        $form_object->forceThreeDS          = $objectData->forceThreeDS;
        $form_object->cardUserKey           = $objectData->cardUserKey;

        return $form_object;
    }

    public function authorizationGenerate($pkiString,$apiKey,$secretKey,$rand) {

        $hash_value = $apiKey.$rand.$secretKey.$pkiString;
        $hash       = base64_encode(sha1($hash_value,true));

        $authorization  = 'IYZWS '.$apiKey.':'.$hash;

        $authorization_data = array(
            'authorization' => $authorization,
            'rand_value'    => $rand
        );

        return $authorization_data;
    }
}

```