Skip to content

Commit

Permalink
+webhook Integration and Shopping Credit
Browse files Browse the repository at this point in the history
  • Loading branch information
feyzullahdemir committed Feb 1, 2023
1 parent 0ea7cb8 commit 6750021
Show file tree
Hide file tree
Showing 34 changed files with 1,002 additions and 99 deletions.
Binary file added .DS_Store
Binary file not shown.
20 changes: 20 additions & 0 deletions Api/WebhookInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Iyzico\Iyzipay\Api;

/**
* Interface WebhookInterface
*
* @package Iyzico\Iyzipay\Api
*/
interface WebhookInterface
{
/**
* Add one number.
*
* @param string $webhookUrlKey
* @return string
*/
public function getResponse($webhookUrlKey);

}
Binary file modified Block/.DS_Store
Binary file not shown.
Binary file modified Block/Adminhtml/.DS_Store
Binary file not shown.
13 changes: 13 additions & 0 deletions Block/Adminhtml/Config/Disable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
namespace Iyzico\Iyzipay\Block\Adminhtml\Config;

use Magento\Framework\Data\Form\Element\AbstractElement;

class Disable extends \Magento\Config\Block\System\Config\Form\Field
{
protected function _getElementHtml(AbstractElement $element)
{
$element->setDisabled('disabled');
return $element->getElementHtml();
}
}
2 changes: 1 addition & 1 deletion Block/Adminhtml/Config/Fieldset.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function _getHeaderHtml($element)

$html .= '<colgroup class="scope-label" /><colgroup class="" /><tbody>';
$html .= '<div style="position:absolute;right: 0px;top:0px;display: flex;flex-direction: column;justify-content: center;">
<img src="'.$this->getViewFileUrl('Iyzico_Iyzipay::iyzico/iyzico_logo.png').'" style=" width: 200px;
<img src="'.$this->getViewFileUrl('Iyzico_Iyzipay::iyzico/iyzico_logo.png').'" style=" width: 180px;
margin-left: auto;" /><span></span>
</div>';
Expand Down
63 changes: 63 additions & 0 deletions Block/Adminhtml/Config/getWebhookUrl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace Iyzico\Iyzipay\Block\Adminhtml\Config;

use Magento\Config\Block\System\Config\Form\Field;
use Magento\Framework\Data\Form\Element\AbstractElement;
use Magento\Framework\Exception\NoSuchEntityException;

/**
* Class webhookurl
*
* @package Iyzico\Iyzipay\Block\Adminhtml\System\Config\Fieldset
*/
class getWebhookUrl extends Field
{

/**
* @param AbstractElement $element
* @return string
* @throws NoSuchEntityException
*/
protected function _getElementHtml(AbstractElement $element): string
{

$webhookUrlKey = $this->_scopeConfig->getValue('payment/iyzipay/webhook_url_key');
if(isset($webhookUrlKey))
{

return $this->_storeManager->getStore()->getBaseUrl().'rest/V1/iyzico/webhook/'.$webhookUrlKey.'<br>'.$this->iyzicoWebhookSubmitbutton();
}
else {
return 'clear cookies and later "save config button" push';
}

}


public function iyzicoWebhookSubmitbutton()
{

$webhookButtonSet = $this->_scopeConfig->getValue('payment/iyzipay/webhook_url_key_active');
if($webhookButtonSet == 2)
{
$htmlButton = '<form action="#" method="post">
<button class="btn btn-light" type="submit" name="button">Active</button> <a href="mailto:[email protected]">[email protected]</a>
</form> ';

$post_data = $this->getRequest()->getPost();
if(isset($post_data))
{
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$resource = $objectManager->get('Magento\Framework\App\ResourceConnection');
$connection = $resource->getConnection();
$tableName = $resource->getTableName('core_config_data'); //gives table name with prefix
$sql = "Update " . $tableName." Set value = '0' Where path = 'payment/iyzipay/webhook_url_key_active'";
$result = $connection->query($sql);
}
return $htmlButton;

}

}
}
Binary file added Controller/.DS_Store
Binary file not shown.
4 changes: 2 additions & 2 deletions Controller/IyzicoBase/IyzicoFormObjectGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function generateOption($checkoutSession,$cardUserKey,$locale,$currency,$
$iyzico->forceThreeDS = "0";
$iyzico->callbackUrl = $callBack."Iyzico_Iyzipay/response/iyzicocheckoutform";
$iyzico->cardUserKey = $cardUserKey;
$iyzico->paymentSource = "MAGENTO2|".$magentoVersion."|SPACE-1.0.1";
$iyzico->paymentSource = "MAGENTO2|".$magentoVersion."|SPACE-1.2.0";

return $iyzico;

Expand Down Expand Up @@ -152,7 +152,7 @@ public function generateBasketItems($checkoutSession) {
$basketItems[$keyNumber]->id = $item->getProductId();
$basketItems[$keyNumber]->price = $this->helper->priceParser(round($item->getPrice(),2));
$basketItems[$keyNumber]->name = $this->helper->dataCheck($item->getName());
$basketItems[$keyNumber]->category1 = "MAGENTO-ECOMMERCE";
$basketItems[$keyNumber]->category1 = $this->helper->dataCheck($item->getName());
$basketItems[$keyNumber]->itemType = "PHYSICAL";

$keyNumber++;
Expand Down
42 changes: 21 additions & 21 deletions Controller/IyzicoBase/IyzicoPkiStringBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
/**
* 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/>.
*/
Expand All @@ -34,7 +34,7 @@ public function pkiStringGenerate($objectData) {
if(is_object($data)) {

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

$end_key = count(get_object_vars($data));
Expand All @@ -44,7 +44,7 @@ public function pkiStringGenerate($objectData) {

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


$pki_value .= $name."="."".$value;
Expand All @@ -57,7 +57,7 @@ public function pkiStringGenerate($objectData) {

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

$pki_value .= $name."=[";
$end_key = count($data);
Expand All @@ -67,11 +67,11 @@ public function pkiStringGenerate($objectData) {

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

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

$pki_value .= $name."="."".$item;

if(end($result) != $item) {
Expand All @@ -82,7 +82,7 @@ public function pkiStringGenerate($objectData) {
if($end_key != $count) {

$pki_value .= "], ";

} else {

$pki_value .= "]";
Expand All @@ -91,14 +91,14 @@ public function pkiStringGenerate($objectData) {
}
}

if(end($data) == $result)
if(end($data) == $result)
$pki_value .= "]";

} else {

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


$pki_value .= $name."="."".$data."";
}
Expand Down Expand Up @@ -133,10 +133,10 @@ public function createFormObjectSort($objectData) {
$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;
Expand All @@ -153,14 +153,14 @@ 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;
}
}
}
29 changes: 18 additions & 11 deletions Controller/IyzicoBase/IyzicoRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
/**
* 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/>.
*/
Expand All @@ -27,15 +27,22 @@ class IyzicoRequest
public function iyzicoCheckoutFormRequest($baseUrl,$json,$authorizationData) {

$url = $baseUrl.'/payment/iyzipos/checkoutform/initialize/auth/ecom';

return $this->curlPost($json,$authorizationData,$url);

}

public function iyzicoCheckoutFormDetailRequest($baseUrl,$json,$authorizationData) {

$url = $baseUrl.'/payment/iyzipos/checkoutform/auth/ecom/detail';


return $this->curlPost($json,$authorizationData,$url);

}
public function iyzicoPostWebhookUrlKey($baseUrl,$json,$authorizationData) {

$url = $baseUrl.'/payment/notification/update';

return $this->curlPost($json,$authorizationData,$url);

}
Expand Down Expand Up @@ -65,21 +72,21 @@ public function curlPost($json,$authorizationData,$url) {
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($curl, CURLOPT_TIMEOUT, 150);
curl_setopt(

curl_setopt(
$curl, CURLOPT_HTTPHEADER, array(
"Authorization: " .$authorizationData['authorization'],
"x-iyzi-rnd:".$authorizationData['rand_value'],
"x-iyzi-rnd:".$authorizationData['rand_value'],
"Content-Type: application/json",
)
);

$result = json_decode(curl_exec($curl));
curl_close($curl);



return $result;
}

}
}
12 changes: 6 additions & 6 deletions Controller/Payment/Iyzipay.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@
/**
* 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\Iyzico;
namespace Iyzico\Iyzipay\Controller\Payment;

class Iyzipay extends \Magento\Framework\App\Action\Action
{
Expand Down Expand Up @@ -49,4 +49,4 @@ public function execute()
{
return $this->resultPageFactory->create();
}
}
}
1 change: 1 addition & 0 deletions Controller/Request/IyzicoCheckoutForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public function execute()

$requestResponse = $iyzicoRequest->iyzicoCheckoutFormRequest($baseUrl,$iyzicoJson,$authorization);


$result = false;

if($requestResponse->status == 'success') {
Expand Down
Loading

0 comments on commit 6750021

Please sign in to comment.