Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V3.5.8 #41

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.DS_Store
.DS_Store?
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007

Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# Requirements
------------
* PHP 8 and greater.
* PHP 8.2 and greater.
* cURL
* WooCommerce 9.0.0+ requires WordPress 6.2.2+

Expand Down
Binary file modified assets/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion assets/admin/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'react-dom', 'wp-api-fetch', 'wp-components', 'wp-dom-ready', 'wp-element', 'wp-i18n'), 'version' => 'dc92777b4c513a8568b3');
<?php return array('dependencies' => array('react', 'react-dom', 'wp-api-fetch', 'wp-components', 'wp-dom-ready', 'wp-element', 'wp-i18n'), 'version' => '46f4d04aee42af432392');
2 changes: 1 addition & 1 deletion assets/admin/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/blocks/woocommerce/blocks.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('wp-html-entities'), 'version' => 'c0cacc6c3d04f2792f02');
<?php return array('dependencies' => array('wp-html-entities'), 'version' => '969a4702d59d9e260099');
2 changes: 1 addition & 1 deletion assets/blocks/woocommerce/blocks.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified assets/images/.DS_Store
Binary file not shown.
Binary file modified assets/images/iyzico_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified i18n/languages/woocommerce-iyzico-en_US.mo
100644 → 100755
Binary file not shown.
17 changes: 16 additions & 1 deletion i18n/languages/woocommerce-iyzico-en_US.po
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -261,4 +261,19 @@ msgid "The shopping credit transaction has been initiated."
msgstr "The shopping credit transaction has been initiated."

msgid "Refunded %s"
msgstr "Refunded %s"
msgstr "Refunded %s"

msgid "The shopping loan transaction was completed successfully."
msgstr "The shopping loan transaction was completed successfully."

msgid "The bank transfer transaction was completed successfully."
msgstr "The bank transfer transaction was completed successfully."

msgid "The balance payment transaction was completed successfully."
msgstr "The balance payment transaction was completed successfully."

msgid "The BKM Express transaction was completed successfully."
msgstr "The BKM Express transaction was completed successfully."

msgid "iyzico Bank transfer/EFT payment is pending."
msgstr "iyzico Bank transfer/EFT payment is pending."
Binary file modified i18n/languages/woocommerce-iyzico-tr_TR.mo
100644 → 100755
Binary file not shown.
14 changes: 13 additions & 1 deletion i18n/languages/woocommerce-iyzico-tr_TR.po
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,16 @@ msgid "The shopping credit transaction has been initiated."
msgstr "Alışveriş kredisi işlemi başlatıldı."

msgid "Refunded %s"
msgstr "İade edildi %s"
msgstr "İade edildi %s"

msgid "The bank transfer transaction was completed successfully."
msgstr "Banka transfer işlemi başarıyla tamamlandı."

msgid "The balance payment transaction was completed successfully."
msgstr "Bakiye ödeme işlemi başarıyla tamamlandı."

msgid "The BKM Express transaction was completed successfully."
msgstr "BKM Express işlemi başarıyla tamamlandı."

msgid "iyzico Bank transfer/EFT payment is pending."
msgstr "iyzico Banka transferi/EFT ödemesi bekleniyor."
Binary file modified includes/.DS_Store
Binary file not shown.
58 changes: 36 additions & 22 deletions includes/Admin/SettingsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ public function renderAdminOptions() {
</a>
</h3>
<?php
$this->getHtmlContent();
}

public function getHtmlContent() {
$html = '<style scoped>
@media (max-width:768px){.iyziBrand{position:fixed;bottom:0;top:auto!important;right:0!important}}
</style>
<div class="iyziBrandWrap">
<div class="iyziBrand" style="clear:both;position:absolute;right: 50px;top:440px;display: flex;flex-direction: column;justify-content: center;">
<img src=' . PLUGIN_URL . '/assets/images/iyzico_logo.png style="width: 250px;margin-left: auto;">
<p style="text-align:center;"><strong>Version: </strong>3.5.8</p>
</div>
</div>';
echo $html;
}

public function renderPage(): void {
Expand Down Expand Up @@ -59,28 +73,6 @@ public function enqueueAdminAssets( $hook ): void {
$this->enqueueAdminStyle();
}

public function enqueueAdminStyle(): void {
$asset_file = PLUGIN_DIR_PATH . 'assets/admin/index.asset.php';

if ( ! file_exists( $asset_file ) ) {
return;
}

$asset = include $asset_file;

wp_enqueue_style(
'AdminStyle',
plugins_url( 'assets/admin/index.css', PLUGIN_BASEFILE ),
array_filter(
$asset['dependencies'],
function ( $style ) {
return wp_style_is( $style, 'registered' );
}
),
$asset['version']
);
}

public function enqueueAdminScript(): void {
$asset_file = PLUGIN_DIR_PATH . 'assets/admin/index.asset.php';

Expand All @@ -106,4 +98,26 @@ public function enqueueAdminScript(): void {

$this->restApi->localizeScript();
}

public function enqueueAdminStyle(): void {
$asset_file = PLUGIN_DIR_PATH . 'assets/admin/index.asset.php';

if ( ! file_exists( $asset_file ) ) {
return;
}

$asset = include $asset_file;

wp_enqueue_style(
'AdminStyle',
plugins_url( 'assets/admin/index.css', PLUGIN_BASEFILE ),
array_filter(
$asset['dependencies'],
function ( $style ) {
return wp_style_is( $style, 'registered' );
}
),
$asset['version']
);
}
}
2 changes: 1 addition & 1 deletion includes/Checkout/BlocksCheckoutMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
class BlocksCheckoutMethod extends AbstractPaymentMethodType {

public $gateway;
protected $name = 'iyzico';
public $checkoutSettings;
protected $name = 'iyzico';

public function __construct() {
$this->checkoutSettings = new CheckoutSettings();
Expand Down
82 changes: 52 additions & 30 deletions includes/Checkout/CheckoutForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,23 @@
namespace Iyzico\IyzipayWoocommerce\Checkout;

use Exception;
use Iyzico\IyzipayWoocommerce\Common\Helpers\RefundProcessor;
use WC_Payment_Gateway;
use Iyzico\IyzipayWoocommerce\Admin\SettingsPage;
use Iyzico\IyzipayWoocommerce\Common\Helpers\CookieManager;
use Iyzico\IyzipayWoocommerce\Common\Helpers\DataFactory;
use Iyzico\IyzipayWoocommerce\Common\Helpers\Logger;
use Iyzico\IyzipayWoocommerce\Common\Helpers\PaymentProcessor;
use Iyzico\IyzipayWoocommerce\Common\Helpers\PriceHelper;
use Iyzico\IyzipayWoocommerce\Common\Helpers\RefundProcessor;
use Iyzico\IyzipayWoocommerce\Common\Helpers\SignatureChecker;
use Iyzico\IyzipayWoocommerce\Common\Helpers\TlsVerifier;
use Iyzico\IyzipayWoocommerce\Common\Helpers\VersionChecker;
use Iyzico\IyzipayWoocommerce\Database\DatabaseManager;
use Iyzipay\Options;
use Iyzipay\Model\CheckoutFormInitialize;
use Iyzipay\Model\ProtectedOverleyScript;
use Iyzipay\Options;
use Iyzipay\Request\CreateCheckoutFormInitializeRequest;
use Iyzipay\Request\RetrieveProtectedOverleyScriptRequest;
use WC_Payment_Gateway;

class CheckoutForm extends WC_Payment_Gateway {

Expand All @@ -38,6 +39,7 @@ class CheckoutForm extends WC_Payment_Gateway {
public $adminSettings;
public $databaseManager;
public $refundProcessor;
public $signatureChecker;

public function __construct() {
$this->id = "iyzico";
Expand All @@ -59,12 +61,13 @@ public function __construct() {
'refunds'
];

$this->logger = new Logger();
$this->cookieManager = new CookieManager();
$this->versionChecker = new VersionChecker( $this->logger );
$this->tlsVerifier = new TlsVerifier();
$this->priceHelper = new PriceHelper();
$this->databaseManager = new DatabaseManager();
$this->logger = new Logger();
$this->cookieManager = new CookieManager();
$this->versionChecker = new VersionChecker( $this->logger );
$this->tlsVerifier = new TlsVerifier();
$this->priceHelper = new PriceHelper();
$this->databaseManager = new DatabaseManager();
$this->signatureChecker = new SignatureChecker();

$this->paymentProcessor = new PaymentProcessor(
$this->logger,
Expand All @@ -73,10 +76,11 @@ public function __construct() {
$this->versionChecker,
$this->tlsVerifier,
$this->checkoutSettings,
$this->databaseManager
$this->databaseManager,
$this->signatureChecker
);

$this->checkoutDataFactory = new DataFactory( $this->priceHelper, $this->checkoutSettings );
$this->checkoutDataFactory = new DataFactory( $this->priceHelper, $this->checkoutSettings, $this->logger );
$this->checkoutView = new CheckoutView( $this->checkoutSettings );
$this->adminSettings = new SettingsPage();
$this->refundProcessor = new RefundProcessor();
Expand All @@ -103,6 +107,15 @@ public function admin_overlay_script() {
return true;
}

protected function create_options(): Options {
$options = new Options();
$options->setApiKey( $this->checkoutSettings->findByKey( 'api_key' ) );
$options->setSecretKey( $this->checkoutSettings->findByKey( 'secret_key' ) );
$options->setBaseUrl( $this->checkoutSettings->findByKey( 'api_type' ) );

return $options;
}

public function handle_api_request() {
if ( isset( $_GET['wc-api'] ) && $_GET['wc-api'] === 'iyzipay' ) {
$this->paymentProcessor->processCallback();
Expand Down Expand Up @@ -158,7 +171,7 @@ protected function create_payment( $orderId ) {

// Payment Source Settings
$affiliate = $this->checkoutSettings->findByKey( 'affiliate_network' );
$paymentSource = "WOOCOMMERCE|$woocommerce->version|CARRERA-3.5.7";
$paymentSource = "WOOCOMMERCE|$woocommerce->version|CARRERA-3.5.8";

if ( strlen( $affiliate ) > 0 ) {
$paymentSource = "$paymentSource|$affiliate";
Expand All @@ -168,7 +181,7 @@ protected function create_payment( $orderId ) {
$request = new CreateCheckoutFormInitializeRequest();
$request->setLocale( $language );
$request->setConversationId( $orderId );
$request->setPrice( $this->priceHelper->subTotalPriceCalc( $cart, $order ) );
$request->setPrice( $this->checkoutDataFactory->createPrice( $order, $cart ) );
$request->setPaidPrice( $this->priceHelper->priceParser( round( $order->get_total(), 2 ) ) );
$request->setCurrency( $currency );
$request->setBasketId( $orderId );
Expand All @@ -191,9 +204,34 @@ protected function create_payment( $orderId ) {
$isSave = $this->checkoutSettings->findByKey( 'request_log_enabled' );
$isSave === 'yes' ? $this->logger->info( "CheckoutFormInitialize Request: " . $request->toJsonString() ) : null;

return CheckoutFormInitialize::create( $request, $options );
$checkoutFormResponse = CheckoutFormInitialize::create( $request, $options );

$rawResult = $checkoutFormResponse->getRawResult();
$rawResultResponse = json_decode( $rawResult );

$conversationId = $checkoutFormResponse->getConversationId();
$token = $checkoutFormResponse->getToken();
$signature = $rawResultResponse->signature;

$secretKey = $options->getSecretKey();
$calculatedSignature = $this->signatureChecker->calculateHmacSHA256Signature( [
$conversationId,
$token
], $secretKey );

if ( $signature != $calculatedSignature ) {
$this->logger->error( "CheckoutForm.php: conversationId: $conversationId token: $token #Signature is not valid." );
}

return $checkoutFormResponse;
}

public function redirect_to_iyzico( string $paymentPageUrl ) {
return [
'result' => 'success',
'redirect' => $paymentPageUrl
];
}

public function checkout_form( $orderId ) {
$checkoutFormInitialize = $this->create_payment( $orderId );
Expand All @@ -220,20 +258,4 @@ public function load_form() {
wp_enqueue_style( 'iyzico-loading-style', plugin_dir_url( PLUGIN_BASEFILE ) . 'assets/css/iyzico-loading.css' );
$this->checkoutView->renderLoadingHtml();
}

public function redirect_to_iyzico( string $paymentPageUrl ) {
return [
'result' => 'success',
'redirect' => $paymentPageUrl
];
}

protected function create_options(): Options {
$options = new Options();
$options->setApiKey( $this->checkoutSettings->findByKey( 'api_key' ) );
$options->setSecretKey( $this->checkoutSettings->findByKey( 'secret_key' ) );
$options->setBaseUrl( $this->checkoutSettings->findByKey( 'api_type' ) );

return $options;
}
}
Binary file modified includes/Common/.DS_Store
Binary file not shown.
56 changes: 56 additions & 0 deletions includes/Common/Abstracts/AbstractBlocksMethod.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace Iyzico\IyzipayWoocommerce\Common\Abstracts;

use Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType;

abstract class AbstractBlocksMethod extends AbstractPaymentMethodType {
protected $settings;
protected $name;

public function __construct() {
$this->initializeSettings();
}

abstract protected function initializeSettings();

abstract public function initialize(): void;

public function is_active(): bool {
return ! empty( $this->settings['enabled'] ) && 'yes' === $this->settings['enabled'];
}

public function get_payment_method_script_handles(): array {
$dependencies = [];
$version = time();
$path = plugin_dir_path( PLUGIN_BASEFILE ) . 'assets/blocks/woocommerce/blocks.asset.php';

if ( file_exists( $path ) ) {
$asset = require $path;
$version = filemtime( plugin_dir_path( PLUGIN_BASEFILE ) . 'assets/blocks/woocommerce/blocks.js' );
$dependencies = $asset['dependencies'] ?? [];
}

wp_register_script(
'wc-' . $this->name . '-blocks-integration',
plugin_dir_url( PLUGIN_BASEFILE ) . 'assets/blocks/woocommerce/blocks.js',
$dependencies,
$version,
true
);

return [ 'wc-' . $this->name . '-blocks-integration' ];
}

public function get_payment_method_data(): array {
$title = $this->settings['title'];
$description = $this->settings['description'];
$image = plugin_dir_url( PLUGIN_BASEFILE ) . 'assets/images/cards.png';

return [
'title' => $title,
'description' => $description,
'icon' => $image
];
}
}
Loading