PluginProbe
PayPlug for WooCommerce (Official) / 1.2.2
PayPlug for WooCommerce (Official) v1.2.2
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 / PayplugOneyDetail.php

PayplugOneyDetail.php in PayPlug for WooCommerce (Official) 1.2.2, at src/Front/PayplugOneyDetail.php

214 lines 8.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 use Payplug\PayplugWoocommerce\Gateway\PayplugGatewayOney3x;
5 use Payplug\PayplugWoocommerce\PayplugWoocommerceHelper;
6
7 // Exit if accessed directly
8 if (!defined('ABSPATH')) {
9 exit;
10 }
11
12 class PayplugOneyDetail
13 {
14
15 private $min_amount = "XXX";
16 private $max_amount = "XXX";
17
18 public function __construct()
19 {
20 add_action( 'wp_ajax_simulate_oney_payment', [ $this, 'simulate_oney_payment' ]);
21 add_action( 'wp_ajax_nopriv_simulate_oney_payment', [ $this, 'simulate_oney_payment' ]);
22 if (!is_admin()) {
23 if(PayplugWoocommerceHelper::is_oney_available()) {
24 // Product page
25 add_action('woocommerce_single_product_summary', [$this, 'oney_simulate_payment_detail']);
26
27 // Total cart
28 add_action('woocommerce_cart_totals_after_order_total', [$this, 'oney_simulate_payment_detail']);
29
30 // Add CSS
31 add_action( 'wp_enqueue_scripts', [$this, 'add_oney_css'] );
32
33 // Add Js
34 add_action( 'wp_enqueue_scripts', [$this, 'add_oney_js'] );
35
36 // Add Scripts
37 add_action( 'wp_enqueue_scripts', [$this, 'add_oney_script'] );
38 }
39 }
40 }
41
42 /**
43 * Add CSS
44 *
45 * @return void
46 */
47 public function add_oney_script() {
48 wp_localize_script('payplug-oney', 'payplug_config', array(
49 'ajax_url' => admin_url('admin-ajax.php'),
50 'ajax_action' => 'simulate_oney_payment'
51 ));
52 }
53
54 /**
55 * Add CSS
56 *
57 * @return void
58 */
59 public function add_oney_css() {
60 wp_enqueue_style('payplug-oney', PAYPLUG_GATEWAY_PLUGIN_URL . 'assets/css/payplug-oney.css', [], PAYPLUG_GATEWAY_VERSION);
61 }
62
63 /**
64 * Add JS
65 *
66 * @return void
67 */
68 public function add_oney_js() {
69 wp_enqueue_script('payplug-oney-mobile', PAYPLUG_GATEWAY_PLUGIN_URL . 'assets/js/payplug-detect-mobile.js', [], PAYPLUG_GATEWAY_VERSION, true);
70 wp_enqueue_script('payplug-oney', PAYPLUG_GATEWAY_PLUGIN_URL . 'assets/js/payplug-oney.js', [
71 'jquery',
72 'jquery-ui-position'
73 ], PAYPLUG_GATEWAY_VERSION, true);
74 }
75
76 /**
77 * Simulate Oney Payment
78 *
79 * @return void
80 */
81 public function simulate_oney_payment() {
82 $total_price = $_POST['price'];
83 $oney_range = PayplugWoocommerceHelper::get_min_max_oney();
84 $this->min_amount = $oney_range['min'];
85 $this->max_amount = $oney_range['max'];
86 if ($total_price < $this->min_amount || $total_price > $this->max_amount) {
87 $oney_response = false;
88 } else {
89 try {
90 $api = new \Payplug\PayplugWoocommerce\Gateway\PayplugApi(new PayplugGatewayOney3x());
91 $api->init();
92 $oney_response = $api->simulate_oney_payment($total_price);
93 } catch (\Exception $e) {
94 PayplugGatewayOney3x::log("Simulate Oney Payment, " . $e->getMessage() );
95 $oney_response = null;
96 }
97 }
98 $result = $this->get_simulate_oney_payment_popup($oney_response);
99 wp_send_json_success(
100 array(
101 'popup' => $result
102 )
103 );
104 wp_die();
105 }
106
107 /**
108 * Show oney simulation details
109 *
110 * @param $oney_response
111 * @return string
112 */
113 public function get_simulate_oney_payment_popup($oney_response) {
114
115 $cgv = sprintf(__("Offre de financement avec apport obligatoire,
116 réservée aux particuliers et valable pour tout achat de %s€ à %s€.
117 Sous réserve d'acceptation par Oney Bank. Vous disposez d'un délai de 14 jours pour renoncer à votre crédit.
118 Oney Bank - SA au capital de 51 286 585€ - 34 Avenue de Flandre 59170 Croix - 546 380 197 RCS Lille Métropole - n° Orias 07 023 261 www.orias.fr
119 Correspondance : CS 60 006 - 59895 Lille Cedex - www.oney.fr", "payplug"), $this->min_amount, $this->max_amount);
120 $f = function($fn) { return $fn; };
121
122 if($oney_response) {
123 $popup = "
124 <div class='oney-img oney-logo no-margin'></div>
125 <div class='oney-title'>
126 <p class='no-margin oney-color'>{$f(__('PAYMENT', 'payplug'))} </p>
127 <p class='no-margin bold oney-color'>{$f(__('BY CREDIT CARD', 'payplug'))}</p>
128 </div>
129 <div class='oney-content oney-3x-content'>
130 <div class='oney-img oney-3x no-margin'></div>
131 <div class='oney-details'>
132 <p class='bold no-margin'> {$f(__('Bring', 'payplug'))} : {$oney_response['x3_with_fees']['down_payment_amount']} €</p>
133 <p class='bold no-margin'>+2 {$f(__('monthly payment of', 'payplug'))} : {$oney_response['x3_with_fees']['installments'][0]['amount']} € </p>
134 <p class='no-margin'> {$f(__('Of which financing cost', 'payplug'))} : {$oney_response['x3_with_fees']['total_cost']} € </p>
135 <p class='no-margin'> {$f(__('TAEG', 'payplug'))} : {$oney_response['x3_with_fees']['effective_annual_percentage_rate']} % </p>
136 </div>
137 </div>
138 <div class='oney-separator'></div>
139 <div class='oney-content oney-4x-content'>
140 <div class='oney-img oney-4x no-margin'></div>
141 <div class='oney-details'>
142 <p class='bold no-margin'> {$f(__('Bring', 'payplug'))} : {$oney_response['x4_with_fees']['down_payment_amount']} €</p>
143 <p class='bold no-margin'>+3 {$f(__('monthly payment of', 'payplug'))} : {$oney_response['x4_with_fees']['installments'][0]['amount']} € </p>
144 <p class='no-margin'> {$f(__('Of which financing cost', 'payplug'))} : {$oney_response['x4_with_fees']['total_cost']} € </p>
145 <p class='no-margin'> {$f(__('TAEG', 'payplug'))} : {$oney_response['x4_with_fees']['effective_annual_percentage_rate']} % </p>
146 </div>
147 </div>
148 <div class='oney-content oney-cgv-content'>
149 {$cgv}
150 </div>";
151 } else {
152 $popup = "
153 <div id='oney-popup-arrow' class='triangle-left'></div>
154 <div class='oney-content oney-cgv-content'>
155 </div>";
156 }
157
158 return $popup;
159 }
160
161 /**
162 * Button to show oney popup
163 *
164 * @return void
165 */
166 public function oney_simulate_payment_detail()
167 {
168 global $product;
169 $total_price = (is_cart()) ? floatval(WC()->cart->total) : (float) ($product->get_price());
170 $total_products = 0;
171 if(is_cart()) {
172 foreach(WC()->cart->cart_contents as $product) {
173 $total_products += $product['quantity'];
174 }
175 }
176
177 $oney_range = PayplugWoocommerceHelper::get_min_max_oney();
178 $this->min_amount = $oney_range['min'];
179 $this->max_amount = $oney_range['max'];
180 $disabled = "";
181 if ($total_price < $this->min_amount || $total_price > $this->max_amount || $total_products >= PayplugGatewayOney3x::ONEY_PRODUCT_QUANTITY_MAXIMUM) {
182 $disabled = "disabled";
183 }
184
185 ?>
186 <div class="payplug-oney <?php echo $disabled; ?>"
187 data-is-cart="<?php echo is_cart() ? 1 : 0; ?>"
188 data-total-products="<?php echo $total_products; ?>"
189 data-price="<?php echo $total_price ?>"
190 data-max-oney-qty="<?php echo PayplugGatewayOney3x::ONEY_PRODUCT_QUANTITY_MAXIMUM; ?>"
191 data-min-oney="<?php echo $this->min_amount; ?>"
192 data-max-oney="<?php echo $this->max_amount; ?>">
193 <?php echo __('OR PAY IN', 'payplug'); ?>
194 <div class="payplug-oney-popup">
195 <div class="oney-img oney-3x4x"></div>
196 <div id="oney-show-popup" class="bold oney-color">?</div>
197 </div>
198 </div>
199 <div class="payplug-oney <?php echo $disabled; ?>" id="oney-popup">
200 <div id='oney-popup-arrow' class='triangle-left'></div>
201 <div class="payplug-lds-roller"><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div></div>
202 <div id="oney-popup-error">
203 <div class="oney-error range">
204 <?php echo sprintf(__('The total amount of your order should be between %s€ and %s€ to pay with Oney.', 'payplug'), $this->min_amount, $this->max_amount);?>
205 </div>
206 <div class="oney-error qty">
207 <?php echo sprintf(__('The payment with Oney is unavailable because you have more than %s items in your cart.', 'payplug'), PayplugGatewayOney3x::ONEY_PRODUCT_QUANTITY_MAXIMUM);?>
208 </div>
209 </div>
210 </div>
211 <?php
212 }
213 }
214