PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.19
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.19
1.10.19 1.10.18 1.10.17 1.10.16 1.10.15 1.10.13 1.10.14 1.10.12 1.10.11 1.10.10 1.10.9 1.10.8 untagged-3d9b7ccddc54df87c672 1.10.7 1.10.6 1.10.5 1.10.3 1.10.4 1.10.2 1.10.1 1.10.0 1.9.17 1.9.15 1.9.16 1.9.14 All 163 releases
← All changes | includes/Gateways/Card.php +22 -84 1.9.141.10.19 View file →
@@ -5,20 +5,21 @@
5 5 * @author Paul Kilmurray <paul@kilbot.com>
6 6 *
7 7 * @see https://wcpos.com
8 8 *
9 - * @extends WC_Payment_Gateway
10 9 * @package WCPOS\WooCommercePOS
11 10 */
12 11
13 12 namespace WCPOS\WooCommercePOS\Gateways;
14 13
15 -use WC_Payment_Gateway;
14 +use WC_Order;
15 +use WCPOS\WooCommercePOS\Payments\Abstract_POS_Gateway;
16 +use WP_REST_Request;
16 17
17 18 /**
18 19 * Card class.
19 20 */
20 -class Card extends WC_Payment_Gateway {
21 +class Card extends Abstract_POS_Gateway {
21 22 /**
22 23 * Constructor for the gateway.
23 24 */
24 25 public function __construct() {
@@ -39,13 +40,9 @@
39 40 'process_admin_options',
40 41 )
41 42 );
42 43 add_action( 'woocommerce_thankyou_pos_card', array( $this, 'calculate_cashback' ) );
43 - add_filter( 'wcpos_payment_gateway_provider', array( $this, 'wcpos_provider' ), 10, 3 );
44 - add_filter( 'wcpos_payment_gateway_pos_type', array( $this, 'wcpos_pos_type' ), 10, 3 );
45 - add_filter( 'wcpos_payment_gateway_provider_data', array( $this, 'wcpos_provider_data' ), 10, 3 );
46 - add_filter( 'wcpos_payment_gateway_bootstrap', array( $this, 'wcpos_bootstrap' ), 10, 4 );
47 - add_filter( 'wcpos_process_checkout_action_' . $this->id, array( $this, 'wcpos_process_checkout_action' ), 10, 5 );
44 + $this->register_pos_gateway_contract_hooks();
48 45 }
49 46
50 47 /**
51 48 * Display the payment fields in the checkout.
@@ -139,14 +136,18 @@
139 136 */
140 137 public function calculate_cashback( $order_id ): void {
141 138 $message = '';
142 139 $order = wc_get_order( $order_id );
140 + if ( ! $order ) {
141 + return;
142 + }
143 +
143 144 $cashback = $order->get_meta( '_pos_card_cashback' );
144 145
145 146 // construct message.
146 147 if ( $cashback ) {
147 148 $message = /* translators: POS payment gateway label shown during checkout. */ __( 'Cashback', 'woocommerce-pos' ) . ': ';
148 - $message .= wc_price( $cashback );
149 + $message .= wc_price( $cashback, array( 'currency' => $order->get_currency() ) );
149 150 }
150 151
151 152 echo wp_kses_post( $message );
152 153 }
@@ -151,91 +152,28 @@
151 152 echo wp_kses_post( $message );
152 153 }
153 154
154 155 /**
155 - * POS provider family.
156 + * Provider family identifier.
156 157 *
157 - * @param string $provider Provider value.
158 - * @param mixed $gateway Gateway object.
159 - * @param mixed $request REST request.
158 + * @param WP_REST_Request|null $request Request object.
160 159 */
161 - public function wcpos_provider( $provider, $gateway, $request = null ) {
162 - if ( $gateway instanceof WC_Payment_Gateway && $this->id === $gateway->id ) {
163 - return 'wcpos';
164 - }
165 -
166 - return $provider;
160 + public function get_pos_provider( ?WP_REST_Request $request = null ): string {
161 + return 'wcpos';
167 162 }
168 163
169 164 /**
170 - * POS type.
165 + * Process a POS checkout action for card.
171 166 *
172 - * @param string $pos_type POS type.
173 - * @param mixed $gateway Gateway object.
174 - * @param mixed $request REST request.
175 - */
176 - public function wcpos_pos_type( $pos_type, $gateway, $request = null ) {
177 - if ( $gateway instanceof WC_Payment_Gateway && $this->id === $gateway->id ) {
178 - return 'manual';
179 - }
180 -
181 - return $pos_type;
182 - }
183 -
184 - /**
185 - * Non-secret provider data.
167 + * @param array $state Checkout state.
168 + * @param string $action Checkout action.
169 + * @param array $payment_data Payment data.
170 + * @param WC_Order $order Order object.
171 + * @param WP_REST_Request|null $request Request object.
186 172 *
187 - * @param array $provider_data Provider data.
188 - * @param mixed $gateway Gateway object.
189 - * @param mixed $request REST request.
173 + * @return array|\WP_Error
190 174 */
191 - public function wcpos_provider_data( $provider_data, $gateway, $request = null ) {
192 - if ( $gateway instanceof WC_Payment_Gateway && $this->id === $gateway->id ) {
193 - return array();
194 - }
195 -
196 - return $provider_data;
197 - }
198 -
199 - /**
200 - * Bootstrap response for POS card.
201 - *
202 - * @param array $response Bootstrap response.
203 - * @param string $gateway_id Gateway ID.
204 - * @param array $context Bootstrap context.
205 - * @param mixed $request REST request.
206 - */
207 - public function wcpos_bootstrap( $response, $gateway_id, $context = array(), $request = null ) {
208 - if ( $this->id === $gateway_id ) {
209 - return array(
210 - 'gateway_id' => $gateway_id,
211 - 'status' => 'ready',
212 - 'expires_at' => null,
213 - 'provider_data' => array(),
214 - );
215 - }
216 -
217 - return $response;
218 - }
219 -
220 - /**
221 - * Handle POS checkout contract for card.
222 - *
223 - * @param array|\WP_Error $state Checkout state.
224 - * @param string $action Checkout action.
225 - * @param array $payment_data Payment data.
226 - * @param \WC_Order $order Order object.
227 - * @param mixed $request REST request.
228 - */
229 - public function wcpos_process_checkout_action( $state, $action, $payment_data, $order, $request = null ) {
230 - if ( is_wp_error( $state ) ) {
231 - return $state;
232 - }
233 -
234 - if ( ( $state['gateway_id'] ?? '' ) !== $this->id ) {
235 - return $state;
236 - }
237 -
175 + public function process_pos_checkout_action( array $state, string $action, array $payment_data, WC_Order $order, ?WP_REST_Request $request = null ) {
238 176 if ( 'cancel' === $action ) {
239 177 $state['status'] = 'cancelled';
240 178 return $state;
241 179 }