PluginProbe
PayPlug for WooCommerce (Official) / 2.9.0
PayPlug for WooCommerce (Official) v2.9.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) 2.9.0, at src/Front/PayplugPayWithOney.php

126 lines 3.8 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
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() || is_product()) && PayplugWoocommerceHelper::is_oney_available()) {
19
20 add_action('woocommerce_cart_totals_after_order_total', [$this, 'oney_simulate_payment_detail']);
21 // add_action('woocommerce_review_order_before_payment', [$this, 'oney_simulate_payment_detail']);
22
23 add_action( 'wp_enqueue_scripts', [$this, 'add_oney_css'] );
24
25 add_action( 'wp_enqueue_scripts', [$this, 'add_oney_js'] );
26
27 add_action( 'wp_enqueue_scripts', [$this, 'add_oney_script'] );
28
29 }
30
31 }
32
33 /**
34 * Button to show oney popup
35 *
36 * @return void
37 */
38 public function oney_simulate_payment_detail()
39 {
40 global $product;
41 $total_price = (is_cart()) ? floatval(WC()->cart->total) : (float) ($product->get_price());
42 $this->setTotalPrice($total_price);
43
44 $this->handleTotalProducts();
45
46 if ($this->getTotalPrice() < $this->get_min_amount() || $this->getTotalPrice() > $this->get_max_amount() || $this->getTotalProducts() >= PayplugGatewayOney3x::ONEY_PRODUCT_QUANTITY_MAXIMUM) {
47 $this->setDisable(true);
48 }
49
50 echo self::payWithOney($this);
51 echo self::disabledOneyPopup($this);
52
53 }
54
55 /**
56 * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts.
57 *
58 */
59 public function add_oney_script() {
60 wp_localize_script('payplug-oney', 'payplug_config', array(
61 'ajax_url' => admin_url('admin-ajax.php'),
62 'ajax_action' => 'simulate_oney_payment'
63 ));
64
65 }
66
67 /**
68 * Add CSS
69 *
70 */
71 public function add_oney_css() {
72 wp_enqueue_style('payplug-oney', PAYPLUG_GATEWAY_PLUGIN_URL . 'assets/css/payplug-oney.css', [], PAYPLUG_GATEWAY_VERSION);
73 }
74
75 /**
76 * Add JS
77 *
78 */
79 public function add_oney_js() {
80 wp_enqueue_script('payplug-oney-mobile', PAYPLUG_GATEWAY_PLUGIN_URL . 'assets/js/payplug-detect-mobile.js', [], PAYPLUG_GATEWAY_VERSION, true);
81 wp_enqueue_script('payplug-oney', PAYPLUG_GATEWAY_PLUGIN_URL . 'assets/js/payplug-oney.js', [
82 'jquery',
83 'jquery-ui-position'
84 ], PAYPLUG_GATEWAY_VERSION, true);
85 }
86
87 /**
88 * disabled oney popup
89 * @param PayplugOney $oney
90 * @return string
91 */
92 static function disabledOneyPopup($oney)
93 {
94 return '<div class="payplug-oney ' . $oney->isDisable() . '" id="oney-popup">
95 <div class="payplug-lds-roller"><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div></div>
96 <div id="oney-popup-error">
97 <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>
98 <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>
99 </div>
100 </div>';
101 }
102
103 /**
104 * header for cart oney
105 * @return string
106 */
107 static function payWithOney($oney)
108 {
109 return '
110 <div class="payplug-oney ' . $oney->isDisable(). '"
111 data-is-cart="' . (is_cart() ? 1 : 0) . '"
112 data-total-products="' . $oney->getTotalProducts() . '"
113 data-price="' . $oney->getTotalPrice() .'"
114 data-max-oney-qty="' . PayplugGatewayOney3x::ONEY_PRODUCT_QUANTITY_MAXIMUM .'"
115 data-min-oney="' . $oney->get_min_amount() . '"
116 data-max-oney="' . $oney->get_max_amount() . '">
117 ' . __('OR PAY IN', 'payplug') . '
118 <div class="payplug-oney-popup">
119 <div class="oney-img ' . $oney->getIcon() . '"></div>
120 <div id="oney-show-popup" class="bold oney-color">?</div>
121 </div>
122 </div>';
123 }
124
125 }
126