PluginProbe
PayPlug for WooCommerce (Official) / 1.10.0
PayPlug for WooCommerce (Official) v1.10.0
3.1.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 All 102 releases
payplug / src / Front / PayplugOney / Requests / OneyBase.php

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

177 lines 4.2 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( 'template_redirect', [ $this, 'showOneyAnimation' ] );
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
90 *
91 * @return void
92 */
93 public function showOneyAnimation()
94 {
95
96 if ( ( is_cart() || is_checkout()) && 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 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) {
104 $this->oney->setDisable(true);
105 }
106
107 add_action('woocommerce_cart_totals_after_order_total', [$this, 'oneyGeneratePopup']);
108 }
109
110 }
111
112 /**
113 * Button to show oney popup product page
114 *
115 * @return void
116 */
117 public function showOneyAnimationProduct()
118 {
119 if ( (is_product()) && PayplugWoocommerceHelper::is_oney_available()) {
120 global $product;
121
122 $total_price = $product->get_price();
123 $this->oney->setTotalPrice($total_price);
124 $this->oney->handleTotalProducts();
125
126 if ($product->get_price() < $this->oney->get_min_amount() || $product->get_price() > $this->oney->get_max_amount() || $this->oney->getTotalProducts() >= PayplugGatewayOney3x::ONEY_PRODUCT_QUANTITY_MAXIMUM) {
127 $this->oney->setDisable(true);
128 }
129
130 $this->oneyGeneratePopup();
131 }
132
133 }
134
135 /**
136 * get Html for Oney
137 */
138 public function oneyGeneratePopup(){
139 $class = "Payplug\\PayplugWoocommerce\\Front\\Layout\\Oney" . $this->getCountry();
140 $class = new $class();
141 echo $class::payWithOney($this->oney);
142 echo $class::disabledOneyPopup($this->oney);
143
144 }
145
146 /**
147 * @param $options
148 * @return void
149 */
150 public function setCountry($options){
151 $this->country = $options["payplug_merchant_country"] ? $options["payplug_merchant_country"] : ["payplug_merchant_country" => "FR"];
152 }
153
154 /**
155 * @return string
156 */
157 public function getCountry(){
158 return $this->country;
159 }
160
161 /**
162 * @return array|OneySimulation
163 */
164 public function getSimulation(){
165 return $this->simulation;
166 }
167
168 /**
169 * @param $oney
170 */
171 public function setOney($oney)
172 {
173 $this->oney = $oney;
174 }
175
176 }
177