PluginProbe
PayPlug for WooCommerce (Official) / 1.5.0
PayPlug for WooCommerce (Official) v1.5.0
3.0.0 2.18.0 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 1.0.22 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.1.0 1.10.0 1.10.1 1.2.1 1.2.10 1.2.11 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 All 101 releases
payplug / src / Front / PayplugPayWithOney.php

PayplugPayWithOney.php in PayPlug for WooCommerce (Official) 1.5.0, at src/Front/PayplugPayWithOney.php

125 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Payplug\PayplugWoocommerce\Front;
4
5 use Payplug\PayplugWoocommerce\Gateway\PayplugGatewayOney3x;
6 use Payplug\PayplugWoocommerce\PayplugWoocommerceHelper;
7
8 class PayplugPayWithOney extends PayplugOney
9 {
10
11 /**
12 * Check if Oney can add JS & CSS in Shop
13 *
14 * @return void
15 */
16 public function check_oney_frontend() {
17
18 if ( ( is_cart() || is_checkout()) && PayplugWoocommerceHelper::is_oney_available() ) {
19
20 add_action('woocommerce_cart_totals_after_order_total', [$this, 'oney_simulate_payment_detail']);
21
22 add_action( 'wp_enqueue_scripts', [$this, 'add_oney_css'] );
23
24 add_action( 'wp_enqueue_scripts', [$this, 'add_oney_js'] );
25
26 add_action( 'wp_enqueue_scripts', [$this, 'add_oney_script'] );
27
28 }
29
30 }
31
32 /**
33 * Button to show oney popup
34 *
35 * @return void
36 */
37 public function oney_simulate_payment_detail()
38 {
39 global $product;
40 $total_price = (is_cart()) ? floatval(WC()->cart->total) : (float) ($product->get_price());
41 $this->setTotalPrice($total_price);
42
43 $this->handleTotalProducts();
44
45 if ($this->getTotalPrice() < $this->get_min_amount() || $this->getTotalPrice() > $this->get_max_amount() || $this->getTotalProducts() >= PayplugGatewayOney3x::ONEY_PRODUCT_QUANTITY_MAXIMUM) {
46 $this->setDisable(true);
47 }
48
49 echo self::payWithOney($this);
50 echo self::disabledOneyPopup($this);
51
52 }
53
54 /**
55 * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts.
56 *
57 */
58 public function add_oney_script() {
59 wp_localize_script('payplug-oney', 'payplug_config', array(
60 'ajax_url' => admin_url('admin-ajax.php'),
61 'ajax_action' => 'simulate_oney_payment'
62 ));
63
64 }
65
66 /**
67 * Add CSS
68 *
69 */
70 public function add_oney_css() {
71 wp_enqueue_style('payplug-oney', PAYPLUG_GATEWAY_PLUGIN_URL . 'assets/css/payplug-oney.css', [], PAYPLUG_GATEWAY_VERSION);
72 }
73
74 /**
75 * Add JS
76 *
77 */
78 public function add_oney_js() {
79 wp_enqueue_script('payplug-oney-mobile', PAYPLUG_GATEWAY_PLUGIN_URL . 'assets/js/payplug-detect-mobile.js', [], PAYPLUG_GATEWAY_VERSION, true);
80 wp_enqueue_script('payplug-oney', PAYPLUG_GATEWAY_PLUGIN_URL . 'assets/js/payplug-oney.js', [
81 'jquery',
82 'jquery-ui-position'
83 ], PAYPLUG_GATEWAY_VERSION, true);
84 }
85
86 /**
87 * disabled oney popup
88 * @param PayplugOney $oney
89 * @return string
90 */
91 static function disabledOneyPopup($oney)
92 {
93 return '<div class="payplug-oney ' . $oney->isDisable() . '" id="oney-popup">
94 <div class="payplug-lds-roller"><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div></div>
95 <div id="oney-popup-error">
96 <div class="oney-error range"> ' . sprintf( __('The total amount of your order should be between %s€ and %s€ to pay with Oney.', 'payplug'), $oney->get_min_amount(), $oney->get_max_amount()) . '</div>
97 <div class="oney-error qty">' . sprintf(__('The payment with Oney is unavailable because you have more than %s items in your cart.', 'payplug'), PayplugGatewayOney3x::ONEY_PRODUCT_QUANTITY_MAXIMUM) . '</div>
98 </div>
99 </div>';
100 }
101
102 /**
103 * header for cart oney
104 * @return string
105 */
106 static function payWithOney($oney)
107 {
108 return '
109 <div class="payplug-oney ' . $oney->isDisable(). '"
110 data-is-cart="' . (is_cart() ? 1 : 0) . '"
111 data-total-products="' . $oney->getTotalProducts() . '"
112 data-price="' . $oney->getTotalPrice() .'"
113 data-max-oney-qty="' . PayplugGatewayOney3x::ONEY_PRODUCT_QUANTITY_MAXIMUM .'"
114 data-min-oney="' . $oney->get_min_amount() . '"
115 data-max-oney="' . $oney->get_max_amount() . '">
116 ' . __('OR PAY IN', 'payplug') . '
117 <div class="payplug-oney-popup">
118 <div class="oney-img ' . $oney->getIcon() . '"></div>
119 <div id="oney-show-popup" class="bold oney-color">?</div>
120 </div>
121 </div>';
122 }
123
124 }
125