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
← All changes | src/Gateway/PayplugApi.php +36 -18 1.2.52.9.0 View file →
@@ -6,9 +6,13 @@
6 6 if (!defined('ABSPATH')) {
7 7 exit;
8 8 }
9 9
10 +use Payplug\Exception\BadRequestException;
10 11 use Payplug\Exception\NotFoundException;
12 +use Payplug\Exception\PayplugServerException;
13 +use Payplug\Exception\UnauthorizedException;
14 +use Payplug\Exception\ForbiddenException;
11 15 use Payplug\Payplug;
12 16 use Payplug\Core\HttpClient;
13 17 use Payplug\PayplugWoocommerce\PayplugWoocommerceHelper;
14 18
@@ -36,9 +40,9 @@
36 40 /**
37 41 * Configure PayPlug client.
38 42 */
39 43 public function init() {
40 - $current_mode = $this->gateway->get_current_mode();
44 + $current_mode = $this->gateway->get_current_mode();
41 45 $key = $this->gateway->get_api_key( $current_mode );
42 46
43 47 Payplug::init(array(
44 48 'secretKey' => $key,
@@ -43,9 +47,9 @@
43 47 Payplug::init(array(
44 48 'secretKey' => $key,
45 49 'apiVersion' => "2019-08-06",
46 50 ));
47 - HttpClient::addDefaultUserAgentProduct(
51 + HttpClient::setDefaultUserAgentProduct(
48 52 'PayPlug-WooCommerce',
49 53 PAYPLUG_GATEWAY_VERSION,
50 54 sprintf( 'WooCommerce/%s', WC()->version )
51 55 );
@@ -103,9 +107,9 @@
103 107 * Create a refund.
104 108 *
105 109 * @param string $transaction_id
106 110 * @param array $data
107 - *
111 + *
108 112 * @return null|\Payplug\Resource\Refund
109 113 * @throws \Payplug\Exception\ConfigurationException
110 114 * @author Clément Boirie
111 115 */
@@ -111,28 +115,42 @@
111 115 */
112 116 public function refund_create( $transaction_id, $data ) {
113 117 return $this->do_request_with_fallback( '\Payplug\Refund::create', [ $transaction_id, $data ] );
114 118 }
115 -
119 +
116 120 /**
117 121 * Simulate a oney payment
118 122 *
119 123 * @return array
120 124 */
121 - public function simulate_oney_payment($price)
125 + public function simulate_oney_payment($price, $oney_type = 'with_fees')
122 126 {
123 - $country = wc_get_base_location();
124 - $oney_fees = ["x3_with_fees", "x4_with_fees"];
125 - try {
126 - $response = $this->do_request('\Payplug\OneySimulation::getSimulations', [[
127 - "amount" => (int) $price * 100,
128 - "country" => $country['country'],
129 - "operations" => $oney_fees
130 - ]]);
131 - PayplugWoocommerceHelper::oney_simulation_values($oney_fees, $response);
132 - } catch (\Payplug\Exception\PayplugServerException $e) {
133 - $response = __('Your payment schedule simulation is temporarily unavailable. You will find this information at the payment stage.', 'payplug');
134 - }
127 + $country = PayplugWoocommerceHelper::get_payplug_merchant_country();
128 + $oney_fees = ["x3_" . $oney_type, "x4_" . $oney_type];
129 +
130 + try {
131 + try {
132 + try {
133 + try {
134 + $response = $this->do_request('\Payplug\OneySimulation::getSimulations', [[
135 + "amount" => intval(floatval($price) * 100),
136 + "country" => $country,
137 + "operations" => $oney_fees
138 + ]]);
139 + PayplugWoocommerceHelper::oney_simulation_values($oney_fees, $response);
140 + } catch (PayplugServerException $e) {
141 + $response = __('Your payment schedule simulation is temporarily unavailable. You will find this information at the payment stage.', 'payplug');
142 + }
143 + } catch (BadRequestException $e) {
144 + $response = __('Your payment schedule simulation is temporarily unavailable. You will find this information at the payment stage.', 'payplug');
145 + }
146 + } catch (UnauthorizedException $e) {
147 + $response = __('Your payment schedule simulation is temporarily unavailable. You will find this information at the payment stage.', 'payplug');
148 + }
149 + } catch (ForbiddenException $e) {
150 + $response = __('Your payment schedule simulation is temporarily unavailable. You will find this information at the payment stage.', 'payplug');
151 + }
152 +
135 153 return $response;
136 154 }
137 155
138 156 /**
@@ -173,9 +191,9 @@
173 191
174 192 if ( ! is_array( $params ) ) {
175 193 $params = [ $params ];
176 194 }
177 -
195 +
178 196 return call_user_func_array( $callback, $params );
179 197 }
180 198
181 199 /**