PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.12.8
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.12.8
3.13.4 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 All 262 releases
wpfunnels / includes / core / gateways / class-wpfnl-gateway-factory.php

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

176 lines 6.2 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;
4
5
6 use WPFunnels\Traits\SingletonTrait;
7 use WPFunnels\Wpfnl_functions;
8
9 class Payment_Gateways_Factory {
10
11 use SingletonTrait;
12
13 protected $payment_gateway;
14
15
16 public function __construct() {
17
18 if( Wpfnl_functions::is_wc_active() ){
19 add_action( 'wp_loaded', array( $this, 'load_payment_gateway_integrations' ), 5 );
20 add_action( 'wp_ajax_nopriv_wpfunnels_create_express_checkout_token', array( $this, 'create_wc_express_checkout_token' ), 9999 );
21 add_action( 'wp_ajax_wpfunnels_create_express_checkout_token', array( $this, 'create_wc_express_checkout_token' ), 9999 );
22
23 add_action( 'wp_ajax_nopriv_wpfunnels_create_express_checkout_token_wc', array( $this, 'create_wc_paypal_express_checkout_token' ), 9999 );
24 add_action( 'wp_ajax_wpfunnels_create_express_checkout_token_wc', array( $this, 'create_wc_paypal_express_checkout_token' ), 9999 );
25
26 add_action( 'wp_ajax_nopriv_wpfunnels_create_paypal_express_checkout_token', array( $this, 'create_paypal_express_checkout_token' ), 9999 );
27 add_action( 'wp_ajax_wpfunnels_create_paypal_express_checkout_token', array( $this, 'create_paypal_express_checkout_token' ), 9999 );
28
29 /**
30 * Paypal API rtetreieving hook for creating billing agreement
31 */
32 add_action( 'woocommerce_api_wpfunnels_paypal', array( $this, 'maybe_handle_paypal_api_call' ),9999 );
33 add_action( 'woocommerce_api_wpfunnels_paypal_express', array( $this, 'maybe_handle_paypal_express_api_call' ),9999 );
34
35 /** Show only supported payment gateway in funnel checkout page */
36 add_filter( 'woocommerce_available_payment_gateways', [$this, 'wpfnl_show_supported_payment_gateway'], 10, 1 );
37 }
38
39 }
40
41
42 /**
43 *
44 */
45 public function load_payment_gateway_integrations() {
46 $available_gateways = \WC()->payment_gateways()->get_available_payment_gateways();
47 if ( false === is_array( $available_gateways ) ) {
48 return $available_gateways;
49 }
50 $supported = array_keys( $available_gateways );
51 foreach ( $supported as $key ) {
52 $this->build_gateway( $key );
53 }
54 return $available_gateways;
55 }
56
57
58
59 /**
60 * build payment gateway object
61 * based on user selection
62 *
63 * @param $gateway
64 * @return bool
65 *
66 * @since 1.0.0
67 */
68 public function build_gateway( $gateway ){
69
70 $gateways = $this->get_supported_payment_gateways();
71 if(isset($gateways[$gateway])) {
72 $gateway_class = "WPFunnels\\Gateway\\".$gateways[$gateway];
73 if ( class_exists( $gateway_class ) ) {
74 $this->payment_gateway = new $gateway_class();
75 return $this->payment_gateway;
76 }
77 }
78
79 return false;
80 }
81
82
83 /**
84 * get all supported payment gateways of WPFunnels
85 *
86 * @return array
87 *
88 * @since 1.0.0
89 */
90 public function get_supported_payment_gateways() {
91 $gateways = array(
92 'stripe' => 'Wpfnl_Stripe_payment_process',
93 'paypal' => 'Wpfnl_Gateway_Paypal',
94 'ppcp-card-button-gateway' => 'Wpfnl_Gateway_Paypal',
95 'ppcp-gateway' => 'Wpfnl_Gateway_Paypal_WooCommerce',
96 'cod' => 'Wpfnl_Gateway_Cod',
97 'mollie_wc_gateway_creditcard' => 'Wpfnl_Gateway_Mollie',
98 'mollie_wc_gateway_ideal' => 'Wpfnl_Gateway_Mollie_Idea',
99 'authorize_net_cim_credit_card' => 'Wpfnl_Gateway_Authorize_Net',
100 'officeguy' => 'Wpfnl_Gateway_OfficeGuy',
101 'payfast' => 'Wpfnl_Gateway_PayFast',
102 'square_credit_card' => 'Wpfnl_Gateway_Square',
103 'bacs' => 'Wpfnl_Gateway_Bacs',
104 'cheque' => 'Wpfnl_Gateway_Cheque',
105 'woocommerce_payments' => 'Wpfnl_Woocommerce_Payments'
106 );
107 return apply_filters('wpfunnels/supported_payment_gateways', $gateways);
108 }
109
110
111 /**
112 * create paypal token
113 * @since 1.0.0
114 */
115 public function create_wc_express_checkout_token() {
116 $this->build_gateway( 'paypal' )->create_express_checkout_token();
117 }
118
119
120 /**
121 * create paypal express token
122 * @since 1.0.0
123 */
124 public function create_wc_paypal_express_checkout_token() {
125 $this->build_gateway( 'ppec_paypal' )->create_express_checkout_token();
126 }
127
128
129 /**
130 *
131 */
132 public function maybe_handle_paypal_api_call() {
133 $this->build_gateway( 'paypal' )->maybe_create_billing();
134 $this->build_gateway( 'paypal' )->handle_api_calls();
135
136 }
137
138 /**
139 *
140 */
141 public function maybe_handle_paypal_express_api_call() {
142 $this->build_gateway( 'ppec_paypal' )->maybe_create_billing();
143 $this->build_gateway( 'ppec_paypal' )->handle_api_calls();
144 }
145
146
147 /**
148 * Show supported payment gateway in funnel checkout page
149 *
150 * @param Array $available_gateways
151 *
152 * @return Array $available_gateways
153 */
154 public function wpfnl_show_supported_payment_gateway( $available_gateways ){
155
156 $is_checkout = Wpfnl_functions::is_funnel_checkout_page();
157 if( $is_checkout['status'] ){
158 $is_funnel_checkout = Wpfnl_functions::check_if_this_is_step_type_by_id( $is_checkout['id'], 'checkout' );
159 if( $is_funnel_checkout ){
160 $offer_settings = Wpfnl_functions::get_offer_settings();
161 if( isset($offer_settings['show_supported_payment_gateway']) && 'on' === $offer_settings['show_supported_payment_gateway'] ){
162 $supported_gateways = $this->get_supported_payment_gateways();
163 foreach( $available_gateways as $key=>$gateway ){
164 if( !isset( $supported_gateways[$key] ) ){
165 unset( $available_gateways[$key] );
166 }
167 }
168 }
169 }
170 }
171
172 return $available_gateways;
173 }
174
175 }
176