| 1 |
<?php |
| 2 |
|
| 3 |
namespace Payplug\PayplugWoocommerce\Gateway; |
| 4 |
|
| 5 |
// Exit if accessed directly |
| 6 |
use Payplug\PayplugWoocommerce\PayplugWoocommerceHelper; |
| 7 |
|
| 8 |
if (!defined('ABSPATH')) { |
| 9 |
exit; |
| 10 |
} |
| 11 |
|
| 12 |
/** |
| 13 |
* PayPlug WooCommerce Gateway. |
| 14 |
* |
| 15 |
* @package Payplug\PayplugWoocommerce\Gateway |
| 16 |
*/ |
| 17 |
class PayplugGatewayOney3xWithoutFees extends PayplugGatewayOney3x |
| 18 |
{ |
| 19 |
|
| 20 |
public function __construct() |
| 21 |
{ |
| 22 |
parent::__construct(); |
| 23 |
$this->id = 'oney_x3_without_fees'; |
| 24 |
$this->method_title = _x('PayPlug Oney 3x', 'Gateway method title', 'payplug'); |
| 25 |
$this->method_description = __('Enable PayPlug Oney 3x for your customers.', 'payplug'); |
| 26 |
$this->title = __('Pay by credit card in 3x installments without fees with Oney', 'payplug'); |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* Get payment icons. |
| 31 |
* |
| 32 |
* @return string |
| 33 |
*/ |
| 34 |
public function get_icon() |
| 35 |
{ |
| 36 |
if ($this->check_oney_is_available() === true) { |
| 37 |
$total_price = floatval(WC()->cart->total); |
| 38 |
$this->oney_response = $this->api->simulate_oney_payment($total_price,'without_fees'); |
| 39 |
$currency = get_woocommerce_currency_symbol(get_option('woocommerce_currency')); |
| 40 |
$f = function ($fn) { |
| 41 |
return $fn; |
| 42 |
}; |
| 43 |
if(is_array($this->oney_response)) { |
| 44 |
$this->description = <<<HTML |
| 45 |
<p> |
| 46 |
<div class="payplug-oney-flex"> |
| 47 |
<div>{$f(__('Bring', 'payplug'))}:</div> |
| 48 |
<div>{$this->oney_response['x3_without_fees']['down_payment_amount']} {$currency}</div> |
| 49 |
</div> |
| 50 |
<div class="payplug-oney-flex"> |
| 51 |
<div>{$f(__('1st monthly payment', 'payplug'))}:</div> |
| 52 |
<div>{$this->oney_response['x3_without_fees']['installments'][0]['amount']} {$currency}</div> |
| 53 |
</div> |
| 54 |
<div class="payplug-oney-flex"> |
| 55 |
<div>{$f(__('2nd monthly payment', 'payplug'))}:</div> |
| 56 |
<div>{$this->oney_response['x3_without_fees']['installments'][1]['amount']} {$currency}</div> |
| 57 |
</div> |
| 58 |
</p> |
| 59 |
HTML; |
| 60 |
} else { |
| 61 |
$this->description = $this->oney_response; |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
$country = PayplugWoocommerceHelper::getISOCountryCode(); |
| 66 |
$available_img = file_exists(PAYPLUG_GATEWAY_PLUGIN_DIR . 'assets/images/Oney3x-' . $country . '.png') ? 'Oney3x-' . $country . '.png' : 'Oney3x.png'; |
| 67 |
$disable_img = file_exists(PAYPLUG_GATEWAY_PLUGIN_DIR . 'assets/images/Oney3x_grey-' . $country . '.png') ? 'Oney3x_grey-' . $country . '.png' : 'Oney3x_grey.png'; |
| 68 |
$image = ($this->check_oney_is_available() === true) ? $available_img : $disable_img; |
| 69 |
|
| 70 |
$icons = apply_filters('payplug_payment_icons', [ |
| 71 |
'payplug' => sprintf('<img src="%s" alt="Oney 3x" class="payplug-payment-icon" />', esc_url(PAYPLUG_GATEWAY_PLUGIN_URL . '/assets/images/' . $image)), |
| 72 |
]); |
| 73 |
$icons_str = ''; |
| 74 |
foreach ($icons as $icon) { |
| 75 |
$icons_str .= $icon; |
| 76 |
} |
| 77 |
return $icons_str; |
| 78 |
} |
| 79 |
} |
| 80 |
|