Skip to content

Commit

Permalink
WooCommerce Installment tab added.
Browse files Browse the repository at this point in the history
  • Loading branch information
fatihtoprak committed Nov 11, 2022
1 parent 97a18e8 commit 5ebe32d
Show file tree
Hide file tree
Showing 13 changed files with 299 additions and 12 deletions.
Binary file added assets/img/cards/banks/isbank.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 added assets/img/cards/banks/kuveyt-turk.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 added assets/img/cards/banks/saglam-kart.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions assets/moka-installment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
jQuery('.min--installment--price').click(function (e) {
jQuery('a[href="#tab-installment_tab"]').trigger('click');

var position = jQuery('#tab-installment_tab').offset().top;

jQuery("body, html").animate({
scrollTop: position
} );
});
97 changes: 96 additions & 1 deletion assets/moka.css
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,99 @@
.subscription-cancelManually { padding:4px 10px;border-radius: 4px;background:#b13f74;color:#fff;cursor: pointer;}
.subscription-noActions { padding:4px 0;border-bottom:1px solid #6c6c6c;color:#6c6c6c;opacity: 0.8;cursor: help;}
#subscription_ajax_response p {background-color: #b13f3f;color:#fff;text-align: center;padding: 10px;;}
#subscription_ajax_response p.message {background-color: #3f83b1;color:#fff;text-align: center;padding: 10px;;}
#subscription_ajax_response p.message {background-color: #3f83b1;color:#fff;text-align: center;padding: 10px;;}

.installment--table--container {
max-width: unset !important;
margin:unset !important;
padding:unset !important;
display: flex;
flex-wrap: wrap;
margin: 0px -12px;
}
.installment--table--column {
width: 24%;
margin: 0px 0.5% 20px 0.5%;
box-shadow: rgba(0, 0, 0, 0.24) 0px 3px 8px;

}
.installment--table--column .perrate {
display:flex;
justify-content: space-between !important;
align-items: center;
text-align: center;
font-size:14px;
line-height:40px;
border-bottom:1px solid rgb(245, 245, 245);
border-left:1px solid rgb(245, 245, 245);
border-right:1px solid rgb(245, 245, 245);
padding:0 4px;
background:#fff;
}
.installment--table--column .perrate div {
text-align: center;
border-right:1px solid rgb(245, 245, 245);
width:33.3%;
}
.installment--table--table-head div{
text-align: center;
width:33.3%;
border-bottom:unset;
}
.installment--table--table-head div:last-child {
border-right: unset;
border-bottom: unset;
}
.installment--table--column .perrate div:last-child {
border-right: unset;;
}
.installment--table--column .perrate div.empty {
text-align: center;
border-left:1px solid rgb(245, 245, 245);
border-right:1px solid rgb(245, 245, 245);
width:100%;
}
.installment--table--column .perrate div.perUnitPrice {
font-weight: bold;
}
.installment--table--table-head {
display:flex;
justify-content: space-between;
align-items: center;
text-align: center;
font-size:14px;
font-weight:bold;
line-height:34px;
padding:4px;
background:#888 !important;
color:#fff;
}
.installment--table--head {
background-color: rgb(245, 245, 245);
height: 44px;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
border-top-left-radius: 4px;
border-top-right-radius: 4px;
}
.installment--table--head img{
height: 35px;
width: 65px;
object-fit: contain;
}

.min--installment--price {
width: 100%;
align-items: center;
justify-content: space-between;
background: #e6f1f4;
border: 1px solid #bdd5dc;
border-radius: 8px;
padding: 8px;
font-size:17px;
margin:10px 0;
cursor: pointer;
}
.min--installment--price span {font-weight: bold;}
1 change: 1 addition & 0 deletions assets/moka.min.css

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

15 changes: 10 additions & 5 deletions core/library/Moka_Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public function __construct()
$this->order_prefix = $this->get_option( 'order_prefix' );
$this->order_status = $this->get_option( 'order_status' );
$this->subscriptions = $this->get_option( 'subscriptions' );
$this->isSubscriptionsEnabled = 'yes' == $this->subscriptions;

$this->installment_message = $this->get_option( 'installment_message' );
$this->isSubscriptionsEnabled = 'yes' == $this->subscriptions;
$this->optimisthubMoka = new MokaPayment();
$this->maxInstallment = range(1,12);
$this->userInformation = self::getUserInformationData();
Expand All @@ -70,7 +70,7 @@ public function __construct()
add_filter( 'woocommerce_credit_card_form_fields' , [$this,'payment_form_fields'] , 10, 2 );
add_action( 'admin_head', [$this, 'admin_css']);
add_action( 'woocommerce_receipt_'.$this->id, [$this, 'receipt_page']);

self::__saveRates();

}
Expand Down Expand Up @@ -121,6 +121,13 @@ public function init_form_fields()
'default' => 'no',
'desc_tip' => true,
],
'installment_message' => [
'title' => __( 'Show Installment Message under the price_html ?', 'moka-woocommerce' ) .' - '. __( 'Enable/Disable', 'moka-woocommerce' ),
'label' => __('Show Installment Message under the price_html ?', 'moka-woocommerce' ),
'type' => 'checkbox',
'default' => 'yes',
'desc_tip' => true,
],
'installment' => [
'title' => __( 'Installement', 'moka-woocommerce' ),
'label' => __('Enable/Disable Installement ?', 'moka-woocommerce' ),
Expand Down Expand Up @@ -363,8 +370,6 @@ public function payment_fields()
public function payment_scripts()
{
wp_enqueue_script( 'moka-pay-corejs', $this->assets . 'moka.js' , false, OPTIMISTHUB_MOKA_PAY_VERSION );
wp_register_style( 'moka-pay-card_css', $this->assets. 'moka.css' , false, OPTIMISTHUB_MOKA_PAY_VERSION );
wp_enqueue_style ( 'moka-pay-card_css' );
wp_localize_script( 'moka-pay-corejs', 'moka_ajax', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
}

Expand Down
165 changes: 162 additions & 3 deletions core/library/Moka_Init.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exit;
}

define('OPTIMISTHUB_MOKA_PAY_VERSION', '3.0.4');
define('OPTIMISTHUB_MOKA_PAY_VERSION', '3.5');

global $mokaVersion;
$mokaVersion = OPTIMISTHUB_MOKA_PAY_VERSION;
Expand All @@ -16,11 +16,36 @@ class Moka_Init
{
public function __construct()
{
$this->assets = $this->assetDir();

add_action( 'wp_enqueue_scripts', [$this, 'pluginStyles'] );

add_filter( 'woocommerce_payment_gateways', [$this, 'addOptimisthubMokaGateway'] );
add_action( 'wp_dashboard_setup', [$this, 'optimisthubDashBoardWidgetInit']);

add_shortcode( 'moka-taksit-tablosu', [$this, 'installmentShortcode'] );
add_shortcode( 'moka-installment-table', [$this, 'installmentShortcode'] );

add_filter( 'woocommerce_product_tabs', [$this, 'generateInstallmentProductTab'] );
add_filter( 'woocommerce_get_price_html', [$this, 'renderMinInstallmentMessage'] );


}

public function pluginStyles()
{

wp_register_style( 'moka-pay-card_css', $this->assets. 'moka.min.css' , false, OPTIMISTHUB_MOKA_PAY_VERSION );
wp_enqueue_style ( 'moka-pay-card_css' );

wp_enqueue_script(
'moka-installment',
$this->assets . 'moka-installment.js',
array( 'jquery' ),
OPTIMISTHUB_MOKA_PAY_VERSION,
true
);

}

/**
Expand Down Expand Up @@ -69,9 +94,143 @@ public function recentNewsByOptimisthub()
echo '<p><strong>Ücretsiz</strong> Moka POS WooCommerce Eklentisi Optimist Hub Bünyesinde geliştirilmiştir. Açık kaynak kodlu eklentiye sizler de katkıda bulunabilirsiniz. <a href="https://github.com/optimisthub/moka-woocommerce">></a></p> <p style="display:flex;justify-content:center;align-items:center"> <a href="https://optimisthub.com/?ref='. get_bloginfo("wpurl").'&source=moka-woocommerce" target="_blank"> <img style="width:220px" src="'.$assetDir.'/img/optimisthub.svg'.'" alt=""> </a> </p>';
}

}
public function generateInstallmentProductTab($tabs)
{
$tabs['installment_tab'] = array(
'title' => __( 'Installment Options', 'moka-woocommerce' ),
'priority' => 20,
'callback' => [$this, 'generateInstallmentProductTabContent']
);
return $tabs;
}

new Moka_Init();
public function generateInstallmentProductTabContent()
{
global $product, $woocommerce;

$installments = get_option( 'woocommerce_mokapay-installments' );

if(!$installments)
{
return;
}

$productPrice = $product->get_price();

if(!$productPrice)
{
return;
}

$return = '<div class="installment--table--container">';

unset($installments['0-genel']);

foreach ($installments as $perKey => $perValue) {

$return .= '<div class="installment--table--column">';
$return .= '<div class="installment--table--head"><img src="'.self::assetDir().'img/cards/banks/'.self::getCardName($perKey).'" title="'.$perKey.'" alt="'.$perKey.'" width="90" height="35"/></div>';
$return .= '<div class="installment--table--table-head"><div>Taksit</div><div>Taksit Tutarı</div> <div>Toplam Tutar</div></div>';
if(data_get($perValue, 'rates'))
{
$rates = data_get($perValue, 'rates');
unset($rates[0]);
unset($rates[1]);

foreach ($rates as $perRateKey => $perRateValue)
{
if($perRateValue['value']>0 && $perRateValue['active']==1)
{
$returnPrice = self::calculateComission($perRateKey,$perRateValue['value'],$productPrice);

$return .= '<div class="perrate">
<div class="perInstallment">'.$perRateKey.'</div>
<div class="perUnitPrice">'.$returnPrice['unit_price'].' '. get_woocommerce_currency_symbol().'</div>
<div class="perTotal">'.$returnPrice['total_price'].' '. get_woocommerce_currency_symbol().'</div>
</div>';

} else {
$return .= '<div class="perrate"><div class="empty">-</div></div>';
}
}
}
$return .= '</div>';

}

$return .= '</div>';

echo $return;
}

public function renderMinInstallmentMessage($price)
{
if(is_singular('product'))
{
global $product;
global $woocommerce_loop;

$productPrice = $product->get_price();

$options = get_option( 'woocommerce_mokapay_settings' );
$isavaliable = data_get($options, 'installment_message');

if($isavaliable == 'yes' && !is_shop() && $woocommerce_loop['name'] == '')
{
$installments = get_option( 'woocommerce_mokapay-installments' );
$minRate = data_get(current($installments), 'rates.12.value');
$minRatePrice = self::calculateComission(12,$minRate,$productPrice);

echo $price.'
<div class="min--installment--price"><span>'.$minRatePrice['unit_price']. '</span> '.get_woocommerce_currency_symbol() .' \' '.__( 'With installments starting from', 'moka-woocommerce' ).' ...</div>';
}
}
}


private function assetDir()
{
return str_replace('/core/library/', '/assets/' , plugin_dir_url( __FILE__ ));
}

private function getCardName($string)
{
$images = [
'133-kuveyt-turk-katilim-bankasi-a-s' => 'kuveyt-turk.png',
'101-imece-bank' => 'isbank.png',
'4-akbank-t-a-s' => 'axess.svg',
'78-deniz-bank-a-s' => 'bonus.svg',
'98-finansbank-a-s' => 'cardfinans.svg',
'004-hscb-a-s' => 'advantage.svg',
'217-ziraat-bankasi' => 'combo.svg',
'122-is-bankasi-a-s' => 'maximum.svg',
'108-halk-bankasi-a-s' => 'paraf.svg',
'174-vakiflar-bankasi-t-a-o' => 'world.svg',

];
return $images[$string];
}

private function calculateComission($installment, $percent, $price)
{
$realPercent = ($price*$percent)/100;
$totalPrice = $price+($realPercent);

$return = [
'percent' => $percent,
'price' => $price,
'installment' => $installment,
'real_percent' => $realPercent,
'total_price' => number_format($totalPrice,2),
'unit_price' => number_format($totalPrice/$installment,2)
];

return $return;
}

}

new Moka_Init();

2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Moka Payment Gateway for WooCommerce
* Plugin URI: https://github.com/optimisthub/moka-woocommerce
* Description: Moka Payment gateway for woocommerce
* Version: 3.0.4
* Version: 3.5
* Author: Optimist Hub
* Author URI: https://optimisthub.com?ref=mokaPayment
* Domain Path: /languages/
Expand Down
Binary file modified languages/moka-woocommerce-en_US.mo
Binary file not shown.
11 changes: 10 additions & 1 deletion languages/moka-woocommerce-en_US.po
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-12-08T11:49:40+00:00\n"
"PO-Revision-Date: 2022-10-20 01:49+0300\n"
"PO-Revision-Date: 2022-11-11 16:58+0300\n"
"Last-Translator: Fatih Toprak <patron@fatihtoprak.com>\n"
"Language-Team: \n"
"Language: en_US\n"
Expand Down Expand Up @@ -205,3 +205,12 @@ msgstr "Actions"

msgid "Your card information that you have added during the payment will be kept by Moka with the assurance of Moka. Your next subscription payment will be taken with this card."
msgstr "Your card information that you have added during the payment will be kept by Moka with the assurance of Moka. Your next subscription payment will be taken with this card."

msgid "Installment Options"
msgstr "Taksit Seçenekleri"

msgid "With installments starting from"
msgstr "With installments starting from"

msgid "Show Installment Message under the price_html ?"
msgstr "Show Installment Message under the price_html ?"
Binary file modified languages/moka-woocommerce-tr_TR.mo
Binary file not shown.
Loading

0 comments on commit 5ebe32d

Please sign in to comment.