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): IyzicoIyzipayControllerIyzicoBaseIyzicoPkiStringBuilder->pkiStringGenerate(Object(stdClass))
#2 /chroot/home/a94b818d/de88c03958.nxcli.io/vendor/magento/framework/Event/Invoker/InvokerDefault.php(88): IyzicoIyzipayObserverIyzipayConfigSaveBefore->execute(Object(MagentoFrameworkEventObserver))
#3 /chroot/home/a94b818d/de88c03958.nxcli.io/vendor/magento/framework/Event/Invoker/InvokerDefault.php(74): MagentoFrameworkEventInvokerInvokerDefault->_callObserverMethod(Object(IyzicoIyzipayObserverIyzipayConfigSaveBefore), Object(MagentoFrameworkEventObserver))
#4 /chroot/home/a94b818d/de88c03958.nxcli.io/vendor/magento/framework/Event/Manager.php(65): MagentoFrameworkEventInvokerInvokerDefault->dispatch(Array, Object(MagentoFrameworkEventObserver))
#5 /chroot/home/a94b818d/de88c03958.nxcli.io/generated/code/Magento/Framework/Event/Manager/Proxy.php(95): MagentoFrameworkEventManager->dispatch('admin_system_co...', Array)
#6 /chroot/home/a94b818d/de88c03958.nxcli.io/vendor/magento/module-config/Model/Config.php(225): MagentoFrameworkEventManagerProxy->dispatch('admin_system_co...', Array)
#7 /chroot/home/a94b818d/de88c03958.nxcli.io/vendor/magento/module-config/Controller/Adminhtml/System/Config/Save.php(226): MagentoConfigModelConfig->save()
#8 /chroot/home/a94b818d/de88c03958.nxcli.io/vendor/magento/framework/Interception/Interceptor.php(58): MagentoConfigControllerAdminhtmlSystemConfigSave->execute()
#9 /chroot/home/a94b818d/de88c03958.nxcli.io/vendor/magento/framework/Interception/Interceptor.php(138): MagentoConfigControllerAdminhtmlSystemConfigSaveInterceptor->___callParent('execute', Array)
#10 /chroot/home/a94b818d/de88c03958.nxcli.io/vendor/magento/framework/Interception/Interceptor.php(153): MagentoConfigControllerAdminhtmlSystemConfigSaveInterceptor->MagentoFrameworkInterception{closure}()
#11 /chroot/home/a94b818d/de88c03958.nxcli.io/generated/code/Magento/Config/Controller/Adminhtml/System/Config/Save/Interceptor.php(23): MagentoConfigControllerAdminhtmlSystemConfigSaveInterceptor->___callPlugins('execute', Array, Array)
#12 /chroot/home/a94b818d/de88c03958.nxcli.io/vendor/magento/framework/App/Action/Action.php(111): MagentoConfigControllerAdminhtmlSystemConfigSaveInterceptor->execute()
#13 /chroot/home/a94b818d/de88c03958.nxcli.io/vendor/magento/module-backend/App/AbstractAction.php(151): MagentoFrameworkAppActionAction->dispatch(Object(MagentoFrameworkAppRequestHttp))
#14 /chroot/home/a94b818d/de88c03958.nxcli.io/vendor/magento/module-config/Controller/Adminhtml/System/AbstractConfig.php(69): MagentoBackendAppAbstractAction->dispatch(Object(MagentoFrameworkAppRequestHttp))
#15 /chroot/home/a94b818d/de88c03958.nxcli.io/vendor/magento/framework/Interception/Interceptor.php(58): MagentoConfigControllerAdminhtmlSystemAbstractConfig->dispatch(Object(MagentoFrameworkAppRequestHttp))
#16 /chroot/home/a94b818d/de88c03958.nxcli.io/vendor/magento/framework/Interception/Interceptor.php(138): MagentoConfigControllerAdminhtmlSystemConfigSaveInterceptor->___callParent('dispatch', Array)
#17 /chroot/home/a94b818d/de88c03958.nxcli.io/vendor/magento/module-backend/App/Action/Plugin/Authentication.php(145): MagentoConfigControllerAdminhtmlSystemConfigSaveInterceptor->MagentoFrameworkInterception{closure}(Object(MagentoFrameworkAppRequestHttp))
#18 /chroot/home/a94b818d/de88c03958.nxcli.io/vendor/magento/framework/Interception/Interceptor.php(135): MagentoBackendAppActionPluginAuthentication->aroundDispatch(Object(MagentoConfigControllerAdminhtmlSystemConfigSaveInterceptor), Object(Closure), Object(MagentoFrameworkAppRequestHttp))
#19 /chroot/home/a94b818d/de88c03958.nxcli.io/vendor/magento/framework/Interception/Interceptor.php(153): MagentoConfigControllerAdminhtmlSystemConfigSaveInterceptor->MagentoFrameworkInterception{closure}(Object(MagentoFrameworkAppRequestHttp))
#20 /chroot/home/a94b818d/de88c03958.nxcli.io/generated/code/Magento/Config/Controller/Adminhtml/System/Config/Save/Interceptor.php(32): MagentoConfigControllerAdminhtmlSystemConfigSaveInterceptor->___callPlugins('dispatch', Array, Array)
#21 /chroot/home/a94b818d/de88c03958.nxcli.io/vendor/magento/framework/App/FrontController.php(245): MagentoConfigControllerAdminhtmlSystemConfigSaveInterceptor->dispatch(Object(MagentoFrameworkAppRequestHttp))
#22 /chroot/home/a94b818d/de88c03958.nxcli.io/vendor/magento/framework/App/FrontController.php(212): MagentoFrameworkAppFrontController->getActionResponse(Object(MagentoConfigControllerAdminhtmlSystemConfigSaveInterceptor), Object(MagentoFrameworkAppRequestHttp))
#23 /chroot/home/a94b818d/de88c03958.nxcli.io/vendor/magento/framework/App/FrontController.php(147): MagentoFrameworkAppFrontController->processRequest(Object(MagentoFrameworkAppRequestHttp), Object(MagentoConfigControllerAdminhtmlSystemConfigSaveInterceptor))
#24 /chroot/home/a94b818d/de88c03958.nxcli.io/vendor/magento/framework/Interception/Interceptor.php(58): MagentoFrameworkAppFrontController->dispatch(Object(MagentoFrameworkAppRequestHttp))
#25 /chroot/home/a94b818d/de88c03958.nxcli.io/vendor/magento/framework/Interception/Interceptor.php(138): MagentoFrameworkAppFrontControllerInterceptor->___callParent('dispatch', Array)
#26 /chroot/home/a94b818d/de88c03958.nxcli.io/vendor/magento/framework/Interception/Interceptor.php(153): MagentoFrameworkAppFrontControllerInterceptor->MagentoFrameworkInterception{closure}(Object(MagentoFrameworkAppRequestHttp))
#27 /chroot/home/a94b818d/de88c03958.nxcli.io/generated/code/Magento/Framework/App/FrontController/Interceptor.php(23): MagentoFrameworkAppFrontControllerInterceptor->___callPlugins('dispatch', Array, Array)
#28 /chroot/home/a94b818d/de88c03958.nxcli.io/vendor/magento/framework/App/Http.php(116): MagentoFrameworkAppFrontControllerInterceptor->dispatch(Object(MagentoFrameworkAppRequestHttp))
#29 /chroot/home/a94b818d/de88c03958.nxcli.io/generated/code/Magento/Framework/App/Http/Interceptor.php(23): MagentoFrameworkAppHttp->launch()
#30 /chroot/home/a94b818d/de88c03958.nxcli.io/vendor/magento/framework/App/Bootstrap.php(264): MagentoFrameworkAppHttpInterceptor->launch()
#31 /chroot/home/a94b818d/de88c03958.nxcli.io/pub/index.php(30): MagentoFrameworkAppBootstrap->run(Object(MagentoFrameworkAppHttpInterceptor))
#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 IyzicoIyzipayControllerIyzicoBase;
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;
}
}