PluginProbe ʕ •ᴥ•ʔ
GlobalPayments Gateway Provider for WooCommerce / 1.5.2
GlobalPayments Gateway Provider for WooCommerce v1.5.2
1.20.2 1.20.1 1.19.3 1.19.2 1.19.1 1.19.0 1.18.4 1.18.3 trunk 1.0.0 1.0.0-b2 1.0.2 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.6 1.10.7 1.10.8 1.11.0 1.12.0 1.12.1 1.13.0 1.13.1 1.13.2 1.13.3 1.13.4 1.13.7 1.13.8 1.14.0 1.14.1 1.14.2 1.14.3 1.14.4 1.14.5 1.14.6 1.14.7 1.14.8 1.14.9 1.15.0 1.15.2 1.15.4 1.15.5 1.15.6 1.15.8 1.15.9 1.16.0 1.16.1 1.16.2 1.16.3 1.16.4 1.16.5 1.16.6 1.17.0 1.17.1 1.18.0 1.18.1 1.18.2 1.2.0 1.2.1 1.2.2 1.3.0 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.6.0 1.7.0 1.8.0 1.9.0 1.9.1 1.9.2 1.9.3 1.9.4 1.9.5
global-payments-woocommerce / src / Gateways / GooglePayGateway.php
global-payments-woocommerce / src / Gateways Last commit date
Clients 3 years ago Handlers 3 years ago HeartlandGiftCards 3 years ago Requests 3 years ago Traits 3 years ago AbstractGateway.php 3 years ago ApplePayGateway.php 3 years ago GeniusGateway.php 3 years ago GooglePayGateway.php 3 years ago GpApiGateway.php 3 years ago HeartlandGateway.php 3 years ago TransitGateway.php 3 years ago
GooglePayGateway.php
259 lines
1 <?php
2
3 namespace GlobalPayments\WooCommercePaymentGatewayProvider\Gateways;
4
5 use GlobalPayments\Api\Entities\Enums\Environment;
6 use GlobalPayments\Api\Entities\Enums\GatewayProvider;
7 use GlobalPayments\Api\Entities\Enums\TransactionStatus;
8 use GlobalPayments\WooCommercePaymentGatewayProvider\Plugin;
9 use GlobalPayments\WooCommercePaymentGatewayProvider\Gateways\Traits\MulticheckboxTrait;
10
11 defined( 'ABSPATH' ) || exit;
12
13 class GooglePayGateway extends AbstractGateway {
14
15 use MulticheckboxTrait;
16
17 /**
18 * Gateway ID
19 *
20 * @var string
21 */
22 const GATEWAY_ID = 'globalpayments_googlepay';
23
24 /**
25 * SDK gateway provider
26 *
27 * @var string
28 */
29 public $gateway_provider = GatewayProvider::GP_API;
30
31 /**
32 * @inheritdoc
33 */
34 public $is_digital_wallet = true;
35
36 /**
37 * Supported credit card types
38 *
39 * @var array
40 */
41 public $cc_types;
42
43 /**
44 * Global Payments Merchant Id
45 *
46 * @var string
47 *
48 */
49 public $global_payments_merchant_id;
50
51 /**
52 * Google Merchant Id
53 *
54 * @var int
55 */
56 public $google_merchant_id;
57
58 /**
59 * Google Merchant Name
60 *
61 * @var string
62 */
63 public $google_merchant_name;
64
65 /**
66 * Google pay button color
67 *
68 * @var string
69 */
70 public $button_color;
71
72 /**
73 * Payments action
74 *
75 * @var string
76 */
77 public $payment_action;
78
79 public function __construct() {
80 parent::__construct();
81
82 $this->gateway = new GpApiGateway( true );
83 }
84
85 public function get_first_line_support_email() {
86 return 'api.integrations@globalpay.com';
87 }
88
89 public function configure_method_settings() {
90 $this->id = self::GATEWAY_ID;
91 $this->method_title = __( 'GlobalPayments - Google Pay', 'googlepay-gateway-provider-for-woocommerce' );
92 $this->method_description = __( 'Connect to the Google Pay gateway via Unified Payments Gateway', 'globalpayments-gateway-provider-for-woocommerce' );
93 }
94
95 public function get_frontend_gateway_options() {
96 return array(
97 'env' => $this->gateway->is_production ? Environment::PRODUCTION : Environment::TEST,
98 'google_merchant_id' => $this->google_merchant_id,
99 'google_merchant_name' => $this->google_merchant_name,
100 'global_payments_merchant_id' => $this->global_payments_merchant_id,
101 'cc_types' => $this->cc_types,
102 'button_color' => $this->button_color,
103 'applepay_gateway_id' => ApplePayGateway::GATEWAY_ID,
104 );
105 }
106
107 public function get_backend_gateway_options() {
108 return $this->gateway->get_backend_gateway_options();
109 }
110
111
112 protected function add_hooks() {
113 parent::add_hooks();
114
115 add_filter( 'pre_update_option_woocommerce_globalpayments_googlepay_settings', array(
116 $this,
117 'woocommerce_globalpayments_googlepay_settings'
118 ) );
119 }
120
121 public function woocommerce_globalpayments_googlepay_settings( $settings ) {
122 if ( ! wc_string_to_bool( $settings['enabled'] ) ) {
123 return $settings;
124 }
125
126 if ( empty( $settings['cc_types'] ) ) {
127 add_action( 'admin_notices', function () {
128 echo '<div id="message" class="notice notice-error is-dismissible"><p><strong>' .
129 __( 'Please provide at least one credit card types.', 'globalpayments-gateway-provider-for-woocommerce' ) . '</strong></p></div>';
130 } );
131 }
132
133 return $settings;
134 }
135
136 public function get_gateway_form_fields() {
137 return array(
138 'global_payments_merchant_id' => array(
139 'title' => __( 'Global Payments Client ID*', 'globalpayments-gateway-provider-for-woocommerce' ),
140 'type' => 'text',
141 'description' => __( 'Your Client ID provided by Global Payments.', 'globalpayments-gateway-provider-for-woocommerce' ),
142 'custom_attributes' => array( 'required' => 'required' ),
143 ),
144 'google_merchant_id' => array(
145 'title' => __( 'Google Merchant ID', 'globalpayments-gateway-provider-for-woocommerce' ),
146 'type' => 'text',
147 'description' => __( 'Your Merchant ID provided by Google.', 'globalpayments-gateway-provider-for-woocommerce' ),
148 ),
149 'google_merchant_name' => array(
150 'title' => __( 'Google Merchant Display Name', 'globalpayments-gateway-provider-for-woocommerce' ),
151 'type' => 'text',
152 'description' => __( 'Displayed to the customer in the Google Pay dialog.', 'globalpayments-gateway-provider-for-woocommerce' ),
153 ),
154 'cc_types' => array(
155 'title' => __( 'Accepted Cards*', 'globalpayments-gateway-provider-for-woocommerce' ),
156 'type' => 'multiselectcheckbox',
157 'class' => 'accepted_cards required',
158 'css' => 'width: 450px; height: 110px',
159 'options' => array(
160 'VISA' => 'Visa',
161 'MASTERCARD' => 'MasterCard',
162 'AMEX' => 'AMEX',
163 'DISCOVER' => 'Discover',
164 'JCB' => 'JCB',
165 ),
166 'default' => array( 'VISA' , 'MASTERCARD' , 'AMEX' , 'DISCOVER' , 'JCB' ),
167 ),
168 'button_color' => array(
169 'title' => __( 'Button Color', 'globalpayments-gateway-provider-for-woocommerce' ),
170 'type' => 'select',
171 'default' => 'white',
172 'options' => array(
173 'white' => __( 'White', 'globalpayments-gateway-provider-for-woocommerce' ),
174 'black' => __( 'Black', 'globalpayments-gateway-provider-for-woocommerce' ),
175 ),
176 ),
177 );
178 }
179
180 public function init_form_fields() {
181 $this->form_fields = array_merge(
182 array(
183 'enabled' => array(
184 'title' => __( 'Enable/Disable', 'globalpayments-gateway-provider-for-woocommerce' ),
185 'type' => 'checkbox',
186 'label' => __( 'Enable Gateway', 'globalpayments-gateway-provider-for-woocommerce' ),
187 'default' => 'no',
188 ),
189 'title' => array(
190 'title' => __( 'Title', 'globalpayments-gateway-provider-for-woocommerce' ),
191 'type' => 'text',
192 'description' => __( 'This controls the title which the user sees during checkout.', 'globalpayments-gateway-provider-for-woocommerce' ),
193 'default' => __( 'Pay with Google Pay', 'globalpayments-gateway-provider-for-woocommerce' ),
194 'desc_tip' => true,
195 'custom_attributes' => array( 'required' => 'required' ),
196 ),
197 ),
198 $this->get_gateway_form_fields(),
199 array(
200 'payment_action' => array(
201 'title' => __( 'Payment Action', 'globalpayments-gateway-provider-for-woocommerce' ),
202 'type' => 'select',
203 'description' => __( 'Choose whether you wish to capture funds immediately or authorize payment only for a delayed capture.', 'globalpayments-gateway-provider-for-woocommerce' ),
204 'default' => self::TXN_TYPE_SALE,
205 'desc_tip' => true,
206 'options' => array(
207 self::TXN_TYPE_SALE => __( 'Authorize + Capture', 'globalpayments-gateway-provider-for-woocommerce' ),
208 self::TXN_TYPE_AUTHORIZE => __( 'Authorize only', 'globalpayments-gateway-provider-for-woocommerce' ),
209 ),
210 ),
211 )
212 );
213 }
214
215 public function tokenization_script() {
216 wp_enqueue_script(
217 'globalpayments-googlepay',
218 ( 'https://pay.google.com/gp/p/js/pay.js' ),
219 array(),
220 WC()->version,
221 true
222 );
223
224 $this->helper_script();
225
226 wp_enqueue_script(
227 'globalpayments-wc-googlepay',
228 Plugin::get_url( '/assets/frontend/js/globalpayments-googlepay.js' ),
229 array( 'wc-checkout', 'globalpayments-googlepay', 'globalpayments-helper' ),
230 WC()->version,
231 true
232 );
233
234 wp_localize_script(
235 'globalpayments-wc-googlepay',
236 'globalpayments_googlepay_params',
237 array(
238 'id' => $this->id,
239 'gateway_options' => $this->get_frontend_gateway_options(),
240 )
241 );
242 }
243
244 public function payment_fields() {
245 if ( is_checkout() ) {
246 $this->tokenization_script();
247 echo '<div>' . __( 'Pay with Google Pay', 'globalpayments-gateway-provider-for-woocommerce' ) . '</div>';
248 }
249 }
250
251 public function mapResponseCodeToFriendlyMessage( $responseCode ) {
252 if ( TransactionStatus::DECLINED === $responseCode ) {
253 return __( 'Your payment was unsuccessful. Please try again or use a different payment method.', 'globalpayments-gateway-provider-for-woocommerce' );
254 }
255
256 return __( 'An error occurred while processing the card. Please try again or use a different payment method.', 'globalpayments-gateway-provider-for-woocommerce' );
257 }
258 }
259