PluginProbe
PayPlug for WooCommerce (Official) / 2.6.4
PayPlug for WooCommerce (Official) v2.6.4
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 / PayplugOney / Requests / OneyBase.php

OneyBase.php in PayPlug for WooCommerce (Official) 2.6.4, at src/Front/PayplugOney/Requests/OneyBase.php

185 lines 4.4 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\PayplugOney\Requests;
4
5 use Payplug\PayplugWoocommerce\Front\PayplugOney\OneySimulation;
6 use Payplug\PayplugWoocommerce\Gateway\PayplugGatewayOney3x;
7 use Payplug\PayplugWoocommerce\PayplugWoocommerceHelper;
8 use function is_cart;
9 use function is_checkout;
10 use function is_product;
11
12 Abstract class OneyBase
13 {
14
15 /**
16 * @var string
17 */
18 private $country;
19
20 /**
21 * @var OneySimulation
22 */
23 private $simulation = [];
24
25 /**
26 * Dependency injection
27 * @var \Payplug\PayplugWoocommerce\Front\PayplugOney\Country\OneyBase
28 */
29 private $oney;
30
31
32 public function __construct()
33 {
34 add_action( 'wp_ajax_simulate_oney_payment', [ $this, 'simulateOneyPayment' ]);
35 add_action( 'wp_ajax_nopriv_simulate_oney_payment', [ $this, 'simulateOneyPayment' ]);
36 add_action('woocommerce_cart_totals_after_order_total', [$this, 'showOneyAnimationCart']);
37
38 $options = get_option('woocommerce_payplug_settings', []);
39
40 if (isset($options['oney_product_animation']) && ($options['oney_product_animation'] == 'yes'))
41 add_action( 'woocommerce_before_add_to_cart_form', [ $this, 'showOneyAnimationProduct' ] );
42 }
43
44 /**
45 * request simulation
46 * print results
47 */
48 public function simulateOneyPayment(){
49 $simulation = new OneySimulation($this->oney);
50 $this->simulation = $simulation->OneySimulation();
51 $html = $this->drawAnimation();
52
53 wp_send_json_success(
54 array(
55 'popup' => $html
56 )
57 );
58
59 wp_die();
60 }
61
62 /**
63 * draw html popup
64 * @return string
65 */
66 public function drawAnimation(){
67 $class = "Payplug\\PayplugWoocommerce\\Front\\Layout\\Oney" . $this->getCountry();
68
69 switch($this->oney->getOneyType()){
70 case "without_fees":
71 $footer = $class::footerOneyWithoutFees($this->oney->get_min_amount(), $this->oney->get_max_amount());
72 $content = $class::simulationPopupContentWithoutFees($this);
73 break;
74 default:
75 $footer = $class::footerOneyWithFees($this->oney->get_min_amount(), $this->oney->get_max_amount());
76 $content = $class::simulationPopupContent($this);
77 break;
78 }
79
80 $html = <<<HTML
81 $content
82 $footer
83 HTML;
84 return $html;
85
86 }
87
88 /**
89 * Button to show oney popup cart page
90 *
91 * @return void
92 */
93 public function showOneyAnimationCart()
94 {
95
96 if ( ( is_cart() ) && PayplugWoocommerceHelper::is_oney_available()) {
97 global $product;
98
99 $total_price = (is_numeric( floatval(WC()->cart->total))) ? floatval(WC()->cart->total) : (float)($product->get_price());
100 $this->oney->setTotalPrice($total_price);
101 $this->oney->handleTotalProducts();
102
103 //don't show animation
104 if ( !PayplugWoocommerceHelper::check_order_max_amount($this->oney->getTotalPrice()) ) {
105 return false;
106 }
107
108 if ($this->oney->getTotalPrice() < $this->oney->get_min_amount() || $this->oney->getTotalPrice() > $this->oney->get_max_amount() || $this->oney->getTotalProducts() >= PayplugGatewayOney3x::ONEY_PRODUCT_QUANTITY_MAXIMUM) {
109 $this->oney->setDisable(true);
110 }
111
112 $this->oneyGeneratePopup();
113 }
114
115 }
116
117 /**
118 * Button to show oney popup product page
119 *
120 * @return void
121 */
122 public function showOneyAnimationProduct()
123 {
124 if ( (is_product()) && PayplugWoocommerceHelper::is_oney_available()) {
125 global $product;
126 $price = $product->get_price();
127 $this->oney->setTotalPrice($price);
128 $this->oney->handleTotalProducts();
129
130 //don't show animation
131 if ( !PayplugWoocommerceHelper::check_order_max_amount($price) ) {
132 return false;
133 }
134
135 if ($price < $this->oney->get_min_amount() || $price > $this->oney->get_max_amount() || $this->oney->getTotalProducts() >= PayplugGatewayOney3x::ONEY_PRODUCT_QUANTITY_MAXIMUM) {
136 $this->oney->setDisable(true);
137 }
138
139 $this->oneyGeneratePopup();
140 }
141
142 }
143
144 /**
145 * get Html for Oney
146 */
147 public function oneyGeneratePopup(){
148 $class = "Payplug\\PayplugWoocommerce\\Front\\Layout\\Oney" . $this->getCountry();
149 $class = new $class();
150 echo $class::payWithOney($this->oney);
151 echo $class::disabledOneyPopup($this->oney);
152
153 }
154
155 /**
156 * @param $options
157 * @return void
158 */
159 public function setCountry($options){
160 $this->country = !empty($options["payplug_merchant_country"]) ? $options["payplug_merchant_country"] : ["payplug_merchant_country" => "FR"];
161 }
162
163 /**
164 * @return string
165 */
166 public function getCountry(){
167 return $this->country;
168 }
169
170 /**
171 * @return array|OneySimulation
172 */
173 public function getSimulation(){
174 return $this->simulation;
175 }
176
177 /**
178 * @param $oney
179 */
180 public function setOney($oney)
181 {
182 $this->oney = $oney;
183 }
184 }
185