Skip to content

Commit

Permalink
Opencart 3.x 2.0v
Browse files Browse the repository at this point in the history
Opencart 3.x 2.0v
  • Loading branch information
sozgat authored Jun 8, 2021
2 parents 3d78932 + 4e91e83 commit 56ba760
Show file tree
Hide file tree
Showing 13 changed files with 1,051 additions and 841 deletions.
88 changes: 56 additions & 32 deletions upload/admin/controller/extension/payment/iyzico.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?php
class ControllerExtensionPaymentIyzico extends Controller {
private $module_version = '1.1';
private $module_product_name = 'eleven';

private $module_version = '2.0';

private $error = array();

private $fields = array(
Expand Down Expand Up @@ -61,53 +60,60 @@ class ControllerExtensionPaymentIyzico extends Controller {
array(
'validateField' => 'blank',
'name' => 'payment_iyzico_overlay_status',
),
array(
'validateField' => 'blank',
'name' => 'webhook_iyzico_webhook_url_key',
)

);

public function index() {

$this->load->language('extension/payment/iyzico');
$this->load->model('setting/setting');
$this->load->model('user/user');
$this->load->model('extension/payment/iyzico');
$this->load->model('extension/payment/iyzico');

if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {

$request = $this->requestIyzico($this->request->post,'add','');

$overlay_result = $this->getOverlayScript($request['payment_iyzico_overlay_status'],
$request['payment_iyzico_api_key'],
$request['payment_iyzico_secret_key']);
$request['payment_iyzico_api_key'],
$request['payment_iyzico_secret_key']);



$request_overlay = $this->requestIyzico($request,'edit',$overlay_result);

$request = array_merge($request,$request_overlay);

$this->model_setting_setting->editSetting('payment_iyzico',$request);

$this->getApiConnection($request['payment_iyzico_api_key'],$request['payment_iyzico_secret_key']);


$this->response->redirect($this->url->link('extension/payment/iyzico', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true));
}

$this->setIyziWebhookUrlKey();

foreach ($this->fields as $key => $field) {

if (isset($this->error[$field['validateField']])) {
$data[$field['validateField']] = $this->error[$field['validateField']];
} else {
$data[$field['validateField']] = '';
}

if (isset($this->request->post[$field['name']])) {
$data[$field['name']] = $this->request->post[$field['name']];
} else {
$data[$field['name']] = $this->config->get($field['name']);
}
}



$this->document->setTitle($this->language->get('heading_title'));
$this->document->addStyle('view/stylesheet/iyzico/iyzico.css');
$this->document->addScript('view/javascript/iyzico/accordion_iyzico.js','footer');
Expand All @@ -116,27 +122,30 @@ public function index() {

/* Extension Install Completed Status */
$data['install_status'] = $this->installStatus();

/* User Info Get*/
$user_info = $this->model_user_user->getUser($this->user->getId());
$data['firstname'] = $user_info['firstname'];
$data['lastname'] = $user_info['lastname'];

/* Get Api Status */
$data['api_status'] = $this->getApiStatus($data['install_status']);

/* Get Order Status */
$this->load->model('localisation/order_status');
$data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();


$data['action'] = $this->url->link('extension/payment/iyzico', 'user_token=' . $this->session->data['user_token'], true);
$data['heading_title'] = $this->language->get('heading_title');
$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');
$data['locale'] = $this->language->get('code');

$data['iyzico_webhook_url_key'] = $this->config->get('webhook_iyzico_webhook_url_key');
$data['iyzico_webhook_url'] = HTTPS_CATALOG.'index.php?route=extension/payment/iyzico/webhook&key=' .$this->config->get('webhook_iyzico_webhook_url_key');
$data['module_version'] = $this->module_version;

$this->response->setOutput($this->load->view('extension/payment/iyzico', $data));
}

Expand All @@ -150,12 +159,12 @@ private function getApiConnection($api_key,$secret_key) {
$api_con_pki = $this->model_extension_payment_iyzico->pkiStringGenerate($api_con_object);
$authorization_data = $this->model_extension_payment_iyzico->authorizationGenerate($api_key,$secret_key,$api_con_pki);
$test_api_con = $this->model_extension_payment_iyzico->apiConnection($authorization_data,$api_con_object);

if(isset($test_api_con->status) && $test_api_con->status == 'success') {
$api_status = true;

} else {

$api_status = false;
}

Expand Down Expand Up @@ -185,9 +194,9 @@ private function getApiStatus($install_status) {
if($install_status >= 6 ) {

if(isset($this->session->data['api_status']) && !empty($this->session->data['api_status'])) {

$api_status = $this->session->data['api_status'];

} else {
$api_key = $this->config->get('payment_iyzico_api_key');
$secret_key = $this->config->get('payment_iyzico_secret_key');
Expand Down Expand Up @@ -237,32 +246,31 @@ public function uninstall() {
$this->model_setting_event->deleteEventByCode('module_notification');
}

protected function validate() {
protected function validate() {

if (!$this->user->hasPermission('modify', 'extension/payment/iyzico')) {
$this->error['warning'] = $this->language->get('error_permission');
}

foreach ($this->fields as $key => $field) {

if($field['validateField'] != 'blank') {

if (!$this->request->post[$field['name']]){
$this->error[$field['validateField']] = $this->language->get($field['validateField']);
$this->error[$field['validateField']] = $this->language->get($field['validateField']);
}
}

}

return !$this->error;
}

public function requestIyzico($request,$method_type,$extra_request = false) {

$request_modify = array();

if ($method_type == 'add') {


foreach ($this->fields as $key => $field) {

Expand All @@ -272,15 +280,14 @@ public function requestIyzico($request,$method_type,$extra_request = false) {
$request[$field['name']] = str_replace(' ','',$request[$field['name']]);

$request_modify[$field['name']] = $request[$field['name']];

}

}

if($request_modify['payment_iyzico_api_channel'] == 'live') {

$request_modify['payment_iyzico_api_url'] = 'https://api.iyzipay.com';

} else if($request_modify['payment_iyzico_api_channel'] == 'sandbox') {

$request_modify['payment_iyzico_api_url'] = 'https://sandbox-api.iyzipay.com';
Expand All @@ -300,7 +307,7 @@ public function requestIyzico($request,$method_type,$extra_request = false) {
if ($method_type == 'edit') {

if(isset($extra_request->status)) {

if($extra_request->status == 'success') {

$request_modify['payment_iyzico_overlay_token'] = $extra_request->protectedShopId;
Expand All @@ -311,6 +318,23 @@ public function requestIyzico($request,$method_type,$extra_request = false) {
return $request_modify;
}

/**
* @return bool
*/
private function setIyziWebhookUrlKey()
{

$webhookUrl = $this->config->get('webhook_iyzico_webhook_url_key');

$uniqueUrlId = substr(base64_encode(time() . mt_rand()),15,6);

if (!$webhookUrl) {
$this->model_setting_setting->editSetting('webhook_iyzico',array(
"webhook_iyzico_webhook_url_key" => $uniqueUrlId
));
}

return true;
}

}
11 changes: 4 additions & 7 deletions upload/admin/language/en-gb/extension/payment/iyzico.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// Heading
$_['heading_title'] = 'iyzico';
$_['text_iyzico'] = '<a href="http://www.iyzico.com/" target="_blank"><img src="view/image/payment/iyzico_logo.png" alt="iyzico" title="iyzico" /></a>';
$_['text_iyzico'] = '<a href="http://www.iyzico.com/" target="_blank"><img src="view/image/payment/iyzico_logo.png" alt="iyzico" title="iyzico" /></a>';
$_['general_select'] = 'Select';
$_['live'] = 'Live';
$_['sandbox'] = 'Sandbox / Test';
Expand Down Expand Up @@ -52,10 +52,7 @@
$_['current_version_name'] = 'Old Version:';
$_['new_version_name'] = 'New Version:';
$_['description_name'] = 'Description:';






$_['iyzico_webhook'] = 'Webhook Integration';
$_['webhook_url_description'] = "Don't forget to do webhook Integration.";
$_['iyzico_webhook_url_key_error'] = "Webhook URL Error! Please, try these steps respectively. 1- Refresh web page 1-2 times. 2- If webhook url doesn't create , Please, after delete the iyzico plugin, re-install the iyzico plugin and save module settings. 3- Send an email to [email protected]";

5 changes: 4 additions & 1 deletion upload/admin/language/tr-tr/extension/payment/iyzico.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,7 @@
$_['iyzico_update_screen'] = 'İYZİCO GÜNCELLEME EKRANI';
$_['current_version_name'] = 'Mevcur Sürümünüz:';
$_['new_version_name'] = 'Yeni Sürümünüz:';
$_['description_name'] = 'Açıklama:';
$_['description_name'] = 'Açıklama:';
$_['iyzico_webhook'] = 'Webhook Entegrasyonu';
$_['webhook_url_description'] = "Webhook entegrasyonunu yapmayı unutmayınız.";
$_['iyzico_webhook_url_key_error'] = "Webhook URL üretilemedi. Lütfen sırasıyla bu adımları deneyin. 1- Web sayfasını 1-2 defa yenileyin. 2- Webhook URL üretilmediyse lütfen plugini kaldırıp, yeniden kurun ve ayarları kaydedin. 3- Sorun devam ederse [email protected]'a mail atınız.";
Loading

0 comments on commit 56ba760

Please sign in to comment.