PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.12.13
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.12.13
3.13.3 3.13.2 3.13.1 3.13.0 3.12.13 3.12.12 3.12.11 3.12.10 3.12.9 3.12.8 3.12.7 3.12.6 3.12.5 3.12.4 3.12.3 3.12.1 3.12.2 3.12.0 3.11.1 3.11.0 3.10.9 3.10.8 3.10.7 3.10.6 2.8.16 All 261 releases
wpfunnels / includes / core / gateways / API / class-wpfnl-gateway.php

class-wpfnl-gateway.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 3.12.13, at includes/core/gateways/API/class-wpfnl-gateway.php

158 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPFunnels\Gateway\API;
4
5 use WPFunnels\Wpfnl_functions;
6
7 abstract class Wpfnl_Gateway extends Wpfnl_API_Base {
8
9 protected $key;
10
11 public function get_key() {
12 return $this->key;
13 }
14
15 /**
16 * This function checks for the need to do the tokenization.
17 * We have to fetch the funnel to decide whether to tokenize the user or not.
18 * @return int|false funnel ID on success false otherwise
19 *
20 */
21 public function should_tokenize($funnel_id) {
22
23 return Wpfnl_functions::is_funnel_exists($funnel_id);
24 }
25
26
27 /**
28 * Get WooCommerce payment geteways.
29 *
30 * @return array
31 */
32 public function get_wc_gateway() {
33
34 global $woocommerce;
35 $gateways = $woocommerce->payment_gateways->payment_gateways();
36
37 return $gateways[ $this->key ];
38 }
39
40
41 /**
42 * Round a float number
43 *
44 * @param float $number
45 * @param int $precision Optional. The number of decimal digits to round to.
46 *
47 * @since 1.0.0
48 *
49 */
50 public function round( $number, $precision = 2 ) {
51 return round( (float) $number, $precision );
52 }
53
54
55 /**
56 * Helper method to return the item description, which is composed of item
57 * meta flattened into a comma-separated string, if available. Otherwise the
58 * product SKU is included.
59 *
60 * The description is automatically truncated to the 127 char limit.
61 *
62 * @param array $item cart or order item
63 * @param \WC_Product $product product data
64 *
65 * @return string
66 * @since 2.0
67 */
68 public function get_item_description( $product ) {
69
70 // Check if pro function exists, otherwise use basic description
71 if ( class_exists('\WPFunnelsPro\Wpfnl_Pro_functions') && method_exists('\WPFunnelsPro\Wpfnl_Pro_functions', 'get_item_description') ) {
72 return \WPFunnelsPro\Wpfnl_Pro_functions::get_item_description($product);
73 }
74
75 // Fallback implementation
76 if ( $product && is_object($product) ) {
77 $description = $product->get_name();
78 if ( $product->get_sku() ) {
79 $description .= ' (' . $product->get_sku() . ')';
80 }
81 return substr( $description, 0, 127 );
82 }
83
84 return '';
85 }
86
87
88 /**
89 * Format prices.
90 *
91 * @param float|int $price
92 * @param int $decimals Optional. The number of decimal points.
93 *
94 * @return string
95 * @since 2.2.12
96 *
97 */
98 public function price_format( $price, $decimals = 2 ) {
99 return number_format( $price, $decimals, '.', '' );
100 }
101
102
103 /**
104 * get order number
105 *
106 * @param \WC_Order $order
107 * @return int|mixed|void
108 *
109 * @since 1.0.0
110 */
111 public function get_order_number( \WC_Order $order, $step_id ) {
112
113 if ( ! empty( $step_id ) ) {
114 return apply_filters( 'wpfunnels/payments_get_order_number', $order->get_id() . '_' . $step_id, $this );
115 } else {
116 return $order->get_id();
117 }
118
119 }
120
121
122 /**
123 * @param $response
124 * @param $key
125 * @return mixed
126 */
127 public function get_value_from_response($response, $key) {
128
129 if ($response && isset($response[$key])) {
130
131 return $response[$key];
132 }
133 }
134
135 /**
136 * check if payment gateway is enabled
137 *
138 * @param \WC_Order $order
139 *
140 * @return bool
141 * @since 1.0.0
142 */
143 public function is_enabled( $order = false ) {
144 global $woocommerce;
145 $gateways = $woocommerce->payment_gateways->payment_gateways();
146 if ( is_array( $gateways ) && in_array( $this->key, $gateways, true ) ) {
147 return true;
148 }
149
150 return false;
151 }
152
153 public function to_string() {
154 return http_build_query($this->get_parameters(), '', '&');
155 }
156
157 }
158