· 5 years ago · Feb 11, 2021, 07:56 PM
1<?php
2/**
3 * Plugin Name: WooCommerce MPGS - VISA
4 * Description: Extends WooCommerce with VISA Payment Gateway Services - DO NOT DELETE!
5 * Version: 1.3.0
6 * Text Domain: woo-mpg-visa
7 * Domain Path: /languages
8 * Author: Ali Basheer
9 * Author URI: https://alibasheer.com
10 * License: GNU General Public License v3.0
11 * License URI: http://www.gnu.org/licenses/gpl-3.0.html
12 */
13
14if ( ! defined( 'ABSPATH' ) ) {
15 exit; // Exit if accessed directly.
16}
17
18/**
19 * Loading text domain
20 */
21function load_woo_mpgs_visa_textdomain() {
22 load_plugin_textdomain( 'woo-mpgs-visa', FALSE, basename( dirname( __FILE__ ) ) . '/languages/' );
23}
24add_action( 'plugins_loaded', 'load_woo_mpgs_visa_textdomain' );
25
26/**
27 * Adds plugin page links
28 *
29 * @since 1.0.0
30 * @param array $links all plugin links
31 * @return array $links all plugin links + our custom link (i.e., "Configure")
32 */
33function woo_mpgs_visa_gateway_plugin_links( $links ) {
34 $plugin_links = array(
35 '<a href="' . admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=woo_mpgs_visa' ) . '">' . __( 'Configure', 'woo-mpgs-visa' ) . '</a>'
36 );
37 return array_merge( $plugin_links, $links );
38}
39add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'woo_mpgs_visa_gateway_plugin_links' );
40
41/**
42 * Add the gateway to WC Available Gateways
43 *
44 * @since 1.0.0
45 * @param array $gateways all available WC gateways
46 * @return array $gateways all WC gateways + Woo MPGS VISA gateway
47 */
48function woo_mpgs_visa_add_to_gateways( $gateways ) {
49 $gateways[] = 'WOO_MPGS_VISA';
50 return $gateways;
51}
52add_filter( 'woocommerce_payment_gateways', 'woo_mpgs_visa_add_to_gateways' );
53
54/**
55 * WooCommerce MPGS - VISA
56 *
57 * Extends WooCommerce with VISA Payment Gateway Services.
58 *
59 * @class WOO_MPGS_VISA
60 * @extends WC_Payment_Gateway
61 * @version 1.0.0
62 * @package WooCommerce/Classes/Payment
63 * @author Ali Basheer
64 */
65function woo_mpgs_visa_init() {
66
67 /**
68 * Make sure WooCommerce is active
69 */
70 if ( ! class_exists( 'WooCommerce' ) ) {
71 echo '<div class="error"><p><strong>' . sprintf( esc_html__( 'MPGS VISA requires WooCommerce to be installed and active. You can download %s here.', 'woo-mpgs-visa' ), '<a href="https://woocommerce.com/" target="_blank">WooCommerce</a>' ) . '</strong></p></div>';
72 return;
73 }
74
75 class WOO_MPGS_VISA extends WC_Payment_Gateway {
76
77 /**
78 * Constructor for the gateway.
79 */
80 public function __construct() {
81
82 $this->id = 'woo_mpgs_visa';
83 $this->mpgs_icon = $this->get_option( 'mpgs_icon' );
84 $this->icon = ( ! empty( $this->mpgs_icon ) ) ? $this->mpgs_icon : apply_filters( 'woo_mpgs_icon', plugins_url( 'assets/images/mastercard.png' , __FILE__ ) );
85 $this->has_fields = false;
86 $this->method_title = __( 'MPGS - VISA', 'woo-mpgs-visa' );
87 $this->method_description = __( 'Allows VISA Payment Gateway Services (MPGS - VISA)', 'woo-mpgs-visa' );
88
89 // Load the settings.
90 $this->init_form_fields();
91 $this->init_settings();
92
93 // Define user set variables
94 $this->title = $this->get_option( 'title' );
95 $this->description = $this->get_option( 'description' );
96 $this->service_host = $this->get_option( 'service_host' );
97 $this->api_version = $this->get_option( 'api_version' );
98 $this->merchant_id = $this->get_option( 'merchant_id' );
99 $this->auth_pass = $this->get_option( 'authentication_password' );
100 $this->merchant_name = $this->get_option( 'merchant_name' );
101 $this->merchant_address1 = $this->get_option( 'merchant_address1' );
102 $this->merchant_address2 = $this->get_option( 'merchant_address2' );
103 $this->checkout_interaction = $this->get_option( 'checkout_interaction' );
104
105 // Actions
106 add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
107 add_action( 'woocommerce_receipt_woo_mpgs_visa', array( $this, 'receipt_page' ) );
108 add_action( 'woocommerce_api_woo_mpgs_visa', array( $this, 'process_response' ) );
109 add_action( 'wp_head', array( $this, 'add_checkout_script' ) );
110 }
111
112 /**
113 * Initialize Gateway Settings Form Fields
114 */
115 public function init_form_fields() {
116
117 $this->form_fields = apply_filters( 'woo_mpgs_visa_form_fields', array(
118 'enabled' => array(
119 'title' => __( 'Enable/Disable', 'woo-mpgs-visa' ),
120 'type' => 'checkbox',
121 'label' => __( 'Enable MPGS Payment Module.', 'woo-mpgs-visa' ),
122 'default' => 'yes',
123 ),
124 'title' => array(
125 'title' => __( 'Title', 'woo-mpgs-visa' ),
126 'type' => 'text',
127 'description' => __( 'This controls the title for the payment method the customer sees during checkout.', 'woo-mpgs-visa' ),
128 'default' => __( 'Credit Card', 'woo-mpgs-visa' ),
129 'desc_tip' => true
130 ),
131 'description' => array(
132 'title' => __( 'Description', 'woo-mpgs-visa' ),
133 'type' => 'textarea',
134 'description' => __( 'Payment method description that the customer will see on your checkout.', 'woo-mpgs-visa' ),
135 'default' => __( 'Pay securely by Credit/Debit Card.', 'woo-mpgs-visa' ),
136 'desc_tip' => true
137 ),
138 'mpgs_icon' => array(
139 'title' => __( 'Icon', 'woo-mpgs-visa' ),
140 'type' => 'text',
141 'css' => 'width:100%',
142 'description' => __( 'Enter an image URL to change the icon.', 'woo-mpgs-visa' ),
143 'desc_tip' => true
144 ),
145 'service_host' => array(
146 'title' => __( 'MPGS URL', 'woo-mpgs-visa' ),
147 'type' => 'text',
148 'css' => 'width:100%',
149 'description' => __( 'MPGS URL, given by the Bank. This is an example: https://ap-gateway.mastercard.com/', 'woo-mpgs-visa' ),
150 'placeholder' => __( 'MPGS URL', 'woo-mpgs-visa' ),
151 'default' => __( 'https://ap-gateway.mastercard.com/', 'woo-mpgs-visa' ),
152 'desc_tip' => true
153 ),
154 'api_version' => array(
155 'title' => __( 'API Version', 'woo-mpgs-visa' ),
156 'type' => 'text',
157 'description' => __( 'API version, given by the Bank', 'woo-mpgs-visa' ),
158 'placeholder' => __( 'MPGS API Version (49 is recommended)', 'woo-mpgs-visa' ),
159 'default' => 49,
160 'desc_tip' => true
161 ),
162 'merchant_id' => array(
163 'title' => __( 'Merchant ID', 'woo-mpgs-visa' ),
164 'type' => 'text',
165 'description' => __( 'Merchant ID, given by the Bank', 'woo-mpgs-visa' ),
166 'placeholder' => __( 'Merchant ID', 'woocommerce' ),
167 'desc_tip' => true
168 ),
169 'authentication_password' => array(
170 'title' => __( 'Authentication Password', 'woo-mpgs-visa' ),
171 'type' => 'text',
172 'description' => __( 'Authentication Password, given by the Bank', 'woo-mpgs-visa' ),
173 'placeholder' => __( 'Authentication Password', 'woo-mpgs-visa' ),
174 'desc_tip' => true
175 ),
176 'merchant_name' => array(
177 'title' => __( 'Name', 'woo-mpgs-visa' ),
178 'type' => 'text',
179 'description' => __( 'Merchant name that will appear in the gateway page or popup', 'woo-mpgs-visa' ),
180 'desc_tip' => true
181 ),
182 'merchant_address1' => array(
183 'title' => __( 'Merchant Address Line 1', 'woo-mpgs-visa' ),
184 'type' => 'text',
185 'description' => __( 'Merchant Address Line 1 that will appear in the gateway page or popup', 'woo-mpgs-visa' ),
186 'desc_tip' => true
187 ),
188 'merchant_address2' => array(
189 'title' => __( 'Merchant Address Line 2', 'woo-mpgs-visa' ),
190 'type' => 'text',
191 'description' => __( 'Merchant Address Line 2 that will appear in the gateway page or popup', 'woo-mpgs-visa' ),
192 'desc_tip' => true
193 ),
194 'checkout_interaction' => array(
195 'title' => __( 'Checkout Interaction', 'woo-mpgs-visa' ),
196 'type' => 'select',
197 'description' => __( 'Choose checkout interaction type', 'woo-mpgs-visa' ),
198 'options' => array( 'lightbox' => 'Lightbox', 'paymentpage' => 'Payment Page' ),
199 'default' => '1',
200 )
201 ) );
202 }
203
204 /**
205 * Process the payment and return the result
206 *
207 * @param int $order_id
208 * @return array
209 */
210 public function process_payment( $order_id ) {
211 $order = wc_get_order( $order_id );
212
213 // Prepare session request
214 $session_request = array();
215 $session_request['apiOperation'] = "CREATE_CHECKOUT_SESSION";
216 $session_request['userId'] = $order->get_user_id();
217 $session_request['order']['id'] = $order_id;
218 $session_request['order']['amount'] = $order->get_total();
219 $session_request['order']['currency'] = get_woocommerce_currency();
220 $session_request['interaction']['returnUrl'] = add_query_arg( array( 'order_id' => $order_id, 'wc-api' => 'woo_mpgs_visa' ), home_url('/') );
221 if( (int) $this->api_version >= 52 ) {
222 $session_request['interaction']['operation'] = "PURCHASE";
223 }
224
225 $request_url = $this->service_host . "api/rest/version/" . $this->api_version . "/merchant/" . $this->merchant_id . "/session";
226
227 // Request the session
228 $response_json = wp_remote_post( $request_url, array(
229 'body' => json_encode ( $session_request ),
230 'headers' => array(
231 'Authorization' => 'Basic ' . base64_encode( "merchant." . $this->merchant_id . ":" . $this->auth_pass ),
232 ),
233 ) );
234
235 if ( is_wp_error( $response_json ) ) {
236
237 wc_add_notice( __( 'Payment error: Failed to communicate with MPGS server. Make sure MPGS URL looks like `https://example.mastercard.com/` by removing `checkout/version/*/checkout.js` and end the URL with a slash "/".', 'woo-mpgs-visa' ), 'error' );
238
239 return array(
240 'result' => 'fail',
241 'redirect' => '',
242 );
243 }
244
245 $response = json_decode( $response_json['body'], true );
246
247 if( $response['result'] == 'SUCCESS' && ! empty( $response['successIndicator'] ) ) {
248
249 update_post_meta( $order_id,'woo_mpgs_visa_successIndicator', $response['successIndicator'] );
250 update_post_meta( $order_id,'woo_mpgs_visa_sessionVersion', $response['session']['version'] );
251
252 $pay_url = add_query_arg( array(
253 'sessionId' => $response['session']['id'],
254 'key' => $order->get_order_key(),
255 'pay_for_order' => false,
256 ), $order->get_checkout_payment_url() );
257
258 return array(
259 'result' => 'success',
260 'redirect' => $pay_url
261 );
262
263 } else {
264 wc_add_notice( __( 'Payment error: ', 'woo-mpgs-visa' ) . $response['error']['explanation'], 'error' );
265 }
266 }
267
268 /**
269 * Print payment buttons in the receipt page
270 *
271 * @param int $order_id
272 */
273 public function receipt_page( $order_id ) {
274
275 if( ! empty( $_REQUEST['sessionId'] ) ) {
276
277 $order = wc_get_order( $order_id );
278 ?>
279 <script type="text/javascript">
280
281 function errorCallback( error ) {
282 alert( "Error: " + JSON.stringify( error ) );
283 window.location.href = "<?php echo wc_get_checkout_url(); ?>";
284 }
285
286 Checkout.configure({
287 merchant: "<?php echo $this->merchant_id; ?>",
288 order: {
289 id: "<?php echo $order_id; ?>",
290 amount: "<?php echo $order->get_total(); ?>",
291 currency: "<?php echo get_woocommerce_currency(); ?>",
292 description: "<?php printf( __( 'Pay for order #%d via %s', 'woo-mpgs-visa' ), $order_id, $this->title ); ?>",
293 customerOrderDate: "<?php echo date('Y-m-d'); ?>",
294 customerReference: "<?php echo $order->get_user_id(); ?>",
295 reference: "<?php echo $order_id; ?>"
296 },
297 session: {
298 id: "<?php echo esc_js( $_REQUEST['sessionId'] ); ?>"
299 },
300 billing: {
301 address: {
302 city: "<?php echo $order->get_billing_city(); ?>",
303 country: "<?php echo $this->kia_convert_country_code( $order->get_billing_country() ); ?>",
304 postcodeZip: "<?php echo $order->get_billing_postcode(); ?>",
305 stateProvince: "<?php echo $order->get_billing_state(); ?>",
306 street: "<?php echo $order->get_billing_address_1(); ?>",
307 street2: "<?php echo $order->get_billing_address_2(); ?>"
308 }
309 },
310 <?php if( ! empty( $order->get_billing_email() ) && ! empty( $order->get_billing_first_name() ) && ! empty( $order->get_billing_last_name() ) && ! empty( $order->get_billing_phone() ) ) { ?>
311 customer: {
312 email: "<?php echo $order->get_billing_email(); ?>",
313 firstName: "<?php echo $order->get_billing_first_name(); ?>",
314 lastName: "<?php echo $order->get_billing_last_name(); ?>",
315 phone: "<?php echo $order->get_billing_phone(); ?>"
316 },
317 <?php } ?>
318 interaction: {
319 <?php if( (int) $this->api_version >= 52 ) { ?>
320 operation: "PURCHASE",
321 <?php } ?>
322 merchant: {
323 name: "<?php echo ( ! empty( $this->merchant_name ) ) ? $this->merchant_name : 'MPGS'; ?>",
324 address: {
325 line1: "<?php echo $this->merchant_address1; ?>",
326 line2: "<?php echo $this->merchant_address2; ?>"
327 }
328 },
329 displayControl: {
330 billingAddress : "HIDE",
331 customerEmail : "HIDE",
332 orderSummary : "HIDE",
333 shipping : "HIDE"
334 }
335 }
336 });
337 </script>
338 <p class="loading-payment-text"><?php echo __( 'Loading payment method, please wait. This may take up to 30 seconds.', 'woo-mpgs-visa' ); ?></p>
339 <script type="text/javascript">
340 <?php echo ( $this->checkout_interaction === 'paymentpage' ) ? 'Checkout.showPaymentPage();' : 'Checkout.showLightbox();';?>
341 </script>
342 <?php
343 } else {
344 wc_add_notice( __( 'Payment error: Session not found.', 'woo-mpgs-visa' ), 'error' );
345 wp_redirect( wc_get_checkout_url() );
346 exit;
347 }
348 }
349
350 /**
351 * Handle MPGS response
352 */
353 public function process_response () {
354
355 global $woocommerce;
356 $order_id = $_REQUEST['order_id'];
357 $order = wc_get_order( $order_id );
358 $resultIndicator = $_REQUEST['resultIndicator'];
359 $mpgs_successIndicator = get_post_meta( $order_id, "woo_mpgs_visa_successIndicator", true );
360
361 if( $resultIndicator == $mpgs_successIndicator ) {
362
363 $request_url = $this->service_host . "api/rest/version/" . $this->api_version . "/merchant/" . $this->merchant_id . "/order/" . $order_id;
364
365 // Request the order payment details
366 $response_json = wp_remote_get( $request_url, array(
367 'headers' => array(
368 'Authorization' => 'Basic ' . base64_encode( "merchant." . $this->merchant_id . ":" . $this->auth_pass ),
369 ),
370 ) );
371
372 $response = json_decode( utf8_decode( $response_json['body'] ), true );
373 $transaction_index = count( $response['transaction'] ) - 1;
374 $transaction_result = $response['transaction'][$transaction_index]['result'];
375 $transaction_receipt = $response['transaction'][$transaction_index]['transaction']['receipt'];
376
377 if( $transaction_result == "SUCCESS" && ! empty( $transaction_receipt ) ) {
378 $woocommerce->cart->empty_cart();
379 $order->add_order_note( sprintf( __( 'MPGS Payment completed with Transaction Receipt: %s.', 'woo-mpgs-visa' ), $transaction_receipt ) );
380 $order->payment_complete( $transaction_receipt );
381
382 wp_redirect( $this->get_return_url( $order ) );
383 exit;
384 } else {
385 $order->add_order_note( __('Payment error: Something went wrong.', 'woo-mpgs-visa') );
386 wc_add_notice( __('Payment error: Something went wrong.', 'woo-mpgs-visa'), 'error' );
387 }
388
389 } else {
390 $order->add_order_note( __('Payment error: Invalid transaction.', 'woo-mpgs-visa') );
391 wc_add_notice( __('Payment error: Invalid transaction.', 'woo-mpgs-visa'), 'error' );
392 }
393 // reaching this line means there is an error, redirect back to checkout page
394 wp_redirect( wc_get_checkout_url() );
395 exit;
396 }
397
398 /**
399 * load checkout script
400 */
401 public function add_checkout_script() {
402 if ( ! empty( $_REQUEST['sessionId'] ) ) {
403 ?>
404 <script
405 src="<?php echo $this->service_host; ?>checkout/version/<?php echo $this->api_version; ?>/checkout.js"
406 data-error="errorCallback"
407 data-cancel="<?php echo wc_get_checkout_url(); ?>"
408 >
409 </script>
410 <?php
411 }
412 }
413
414 /**
415 * Converts the WooCommerce country codes to 3-letter ISO codes
416 * https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3
417 * @param string WooCommerce's 2 letter country code
418 * @return string ISO 3-letter country code
419 */
420 function kia_convert_country_code( $country ) {
421 $countries = array(
422 'AF' => 'AFG', //Afghanistan
423 'AX' => 'ALA', //Åland Islands
424 'AL' => 'ALB', //Albania
425 'DZ' => 'DZA', //Algeria
426 'AS' => 'ASM', //American Samoa
427 'AD' => 'AND', //Andorra
428 'AO' => 'AGO', //Angola
429 'AI' => 'AIA', //Anguilla
430 'AQ' => 'ATA', //Antarctica
431 'AG' => 'ATG', //Antigua and Barbuda
432 'AR' => 'ARG', //Argentina
433 'AM' => 'ARM', //Armenia
434 'AW' => 'ABW', //Aruba
435 'AU' => 'AUS', //Australia
436 'AT' => 'AUT', //Austria
437 'AZ' => 'AZE', //Azerbaijan
438 'BS' => 'BHS', //Bahamas
439 'BH' => 'BHR', //Bahrain
440 'BD' => 'BGD', //Bangladesh
441 'BB' => 'BRB', //Barbados
442 'BY' => 'BLR', //Belarus
443 'BE' => 'BEL', //Belgium
444 'BZ' => 'BLZ', //Belize
445 'BJ' => 'BEN', //Benin
446 'BM' => 'BMU', //Bermuda
447 'BT' => 'BTN', //Bhutan
448 'BO' => 'BOL', //Bolivia
449 'BQ' => 'BES', //Bonaire, Saint Estatius and Saba
450 'BA' => 'BIH', //Bosnia and Herzegovina
451 'BW' => 'BWA', //Botswana
452 'BV' => 'BVT', //Bouvet Islands
453 'BR' => 'BRA', //Brazil
454 'IO' => 'IOT', //British Indian Ocean Territory
455 'BN' => 'BRN', //Brunei
456 'BG' => 'BGR', //Bulgaria
457 'BF' => 'BFA', //Burkina Faso
458 'BI' => 'BDI', //Burundi
459 'KH' => 'KHM', //Cambodia
460 'CM' => 'CMR', //Cameroon
461 'CA' => 'CAN', //Canada
462 'CV' => 'CPV', //Cape Verde
463 'KY' => 'CYM', //Cayman Islands
464 'CF' => 'CAF', //Central African Republic
465 'TD' => 'TCD', //Chad
466 'CL' => 'CHL', //Chile
467 'CN' => 'CHN', //China
468 'CX' => 'CXR', //Christmas Island
469 'CC' => 'CCK', //Cocos (Keeling) Islands
470 'CO' => 'COL', //Colombia
471 'KM' => 'COM', //Comoros
472 'CG' => 'COG', //Congo
473 'CD' => 'COD', //Congo, Democratic Republic of the
474 'CK' => 'COK', //Cook Islands
475 'CR' => 'CRI', //Costa Rica
476 'CI' => 'CIV', //Côte d\'Ivoire
477 'HR' => 'HRV', //Croatia
478 'CU' => 'CUB', //Cuba
479 'CW' => 'CUW', //Curaçao
480 'CY' => 'CYP', //Cyprus
481 'CZ' => 'CZE', //Czech Republic
482 'DK' => 'DNK', //Denmark
483 'DJ' => 'DJI', //Djibouti
484 'DM' => 'DMA', //Dominica
485 'DO' => 'DOM', //Dominican Republic
486 'EC' => 'ECU', //Ecuador
487 'EG' => 'EGY', //Egypt
488 'SV' => 'SLV', //El Salvador
489 'GQ' => 'GNQ', //Equatorial Guinea
490 'ER' => 'ERI', //Eritrea
491 'EE' => 'EST', //Estonia
492 'ET' => 'ETH', //Ethiopia
493 'FK' => 'FLK', //Falkland Islands
494 'FO' => 'FRO', //Faroe Islands
495 'FJ' => 'FIJ', //Fiji
496 'FI' => 'FIN', //Finland
497 'FR' => 'FRA', //France
498 'GF' => 'GUF', //French Guiana
499 'PF' => 'PYF', //French Polynesia
500 'TF' => 'ATF', //French Southern Territories
501 'GA' => 'GAB', //Gabon
502 'GM' => 'GMB', //Gambia
503 'GE' => 'GEO', //Georgia
504 'DE' => 'DEU', //Germany
505 'GH' => 'GHA', //Ghana
506 'GI' => 'GIB', //Gibraltar
507 'GR' => 'GRC', //Greece
508 'GL' => 'GRL', //Greenland
509 'GD' => 'GRD', //Grenada
510 'GP' => 'GLP', //Guadeloupe
511 'GU' => 'GUM', //Guam
512 'GT' => 'GTM', //Guatemala
513 'GG' => 'GGY', //Guernsey
514 'GN' => 'GIN', //Guinea
515 'GW' => 'GNB', //Guinea-Bissau
516 'GY' => 'GUY', //Guyana
517 'HT' => 'HTI', //Haiti
518 'HM' => 'HMD', //Heard Island and McDonald Islands
519 'VA' => 'VAT', //Holy See (Vatican City State)
520 'HN' => 'HND', //Honduras
521 'HK' => 'HKG', //Hong Kong
522 'HU' => 'HUN', //Hungary
523 'IS' => 'ISL', //Iceland
524 'IN' => 'IND', //India
525 'ID' => 'IDN', //Indonesia
526 'IR' => 'IRN', //Iran
527 'IQ' => 'IRQ', //Iraq
528 'IE' => 'IRL', //Republic of Ireland
529 'IM' => 'IMN', //Isle of Man
530 'IL' => 'ISR', //Israel
531 'IT' => 'ITA', //Italy
532 'JM' => 'JAM', //Jamaica
533 'JP' => 'JPN', //Japan
534 'JE' => 'JEY', //Jersey
535 'JO' => 'JOR', //Jordan
536 'KZ' => 'KAZ', //Kazakhstan
537 'KE' => 'KEN', //Kenya
538 'KI' => 'KIR', //Kiribati
539 'KP' => 'PRK', //Korea, Democratic People\'s Republic of
540 'KR' => 'KOR', //Korea, Republic of (South)
541 'KW' => 'KWT', //Kuwait
542 'KG' => 'KGZ', //Kyrgyzstan
543 'LA' => 'LAO', //Laos
544 'LV' => 'LVA', //Latvia
545 'LB' => 'LBN', //Lebanon
546 'LS' => 'LSO', //Lesotho
547 'LR' => 'LBR', //Liberia
548 'LY' => 'LBY', //Libya
549 'LI' => 'LIE', //Liechtenstein
550 'LT' => 'LTU', //Lithuania
551 'LU' => 'LUX', //Luxembourg
552 'MO' => 'MAC', //Macao S.A.R., China
553 'MK' => 'MKD', //Macedonia
554 'MG' => 'MDG', //Madagascar
555 'MW' => 'MWI', //Malawi
556 'MY' => 'MYS', //Malaysia
557 'MV' => 'MDV', //Maldives
558 'ML' => 'MLI', //Mali
559 'MT' => 'MLT', //Malta
560 'MH' => 'MHL', //Marshall Islands
561 'MQ' => 'MTQ', //Martinique
562 'MR' => 'MRT', //Mauritania
563 'MU' => 'MUS', //Mauritius
564 'YT' => 'MYT', //Mayotte
565 'MX' => 'MEX', //Mexico
566 'FM' => 'FSM', //Micronesia
567 'MD' => 'MDA', //Moldova
568 'MC' => 'MCO', //Monaco
569 'MN' => 'MNG', //Mongolia
570 'ME' => 'MNE', //Montenegro
571 'MS' => 'MSR', //Montserrat
572 'MA' => 'MAR', //Morocco
573 'MZ' => 'MOZ', //Mozambique
574 'MM' => 'MMR', //Myanmar
575 'NA' => 'NAM', //Namibia
576 'NR' => 'NRU', //Nauru
577 'NP' => 'NPL', //Nepal
578 'NL' => 'NLD', //Netherlands
579 'AN' => 'ANT', //Netherlands Antilles
580 'NC' => 'NCL', //New Caledonia
581 'NZ' => 'NZL', //New Zealand
582 'NI' => 'NIC', //Nicaragua
583 'NE' => 'NER', //Niger
584 'NG' => 'NGA', //Nigeria
585 'NU' => 'NIU', //Niue
586 'NF' => 'NFK', //Norfolk Island
587 'MP' => 'MNP', //Northern Mariana Islands
588 'NO' => 'NOR', //Norway
589 'OM' => 'OMN', //Oman
590 'PK' => 'PAK', //Pakistan
591 'PW' => 'PLW', //Palau
592 'PS' => 'PSE', //Palestinian Territory
593 'PA' => 'PAN', //Panama
594 'PG' => 'PNG', //Papua New Guinea
595 'PY' => 'PRY', //Paraguay
596 'PE' => 'PER', //Peru
597 'PH' => 'PHL', //Philippines
598 'PN' => 'PCN', //Pitcairn
599 'PL' => 'POL', //Poland
600 'PT' => 'PRT', //Portugal
601 'PR' => 'PRI', //Puerto Rico
602 'QA' => 'QAT', //Qatar
603 'RE' => 'REU', //Reunion
604 'RO' => 'ROU', //Romania
605 'RU' => 'RUS', //Russia
606 'RW' => 'RWA', //Rwanda
607 'BL' => 'BLM', //Saint Barthélemy
608 'SH' => 'SHN', //Saint Helena
609 'KN' => 'KNA', //Saint Kitts and Nevis
610 'LC' => 'LCA', //Saint Lucia
611 'MF' => 'MAF', //Saint Martin (French part)
612 'SX' => 'SXM', //Sint Maarten / Saint Matin (Dutch part)
613 'PM' => 'SPM', //Saint Pierre and Miquelon
614 'VC' => 'VCT', //Saint Vincent and the Grenadines
615 'WS' => 'WSM', //Samoa
616 'SM' => 'SMR', //San Marino
617 'ST' => 'STP', //São Tomé and Príncipe
618 'SA' => 'SAU', //Saudi Arabia
619 'SN' => 'SEN', //Senegal
620 'RS' => 'SRB', //Serbia
621 'SC' => 'SYC', //Seychelles
622 'SL' => 'SLE', //Sierra Leone
623 'SG' => 'SGP', //Singapore
624 'SK' => 'SVK', //Slovakia
625 'SI' => 'SVN', //Slovenia
626 'SB' => 'SLB', //Solomon Islands
627 'SO' => 'SOM', //Somalia
628 'ZA' => 'ZAF', //South Africa
629 'GS' => 'SGS', //South Georgia/Sandwich Islands
630 'SS' => 'SSD', //South Sudan
631 'ES' => 'ESP', //Spain
632 'LK' => 'LKA', //Sri Lanka
633 'SD' => 'SDN', //Sudan
634 'SR' => 'SUR', //Suriname
635 'SJ' => 'SJM', //Svalbard and Jan Mayen
636 'SZ' => 'SWZ', //Swaziland
637 'SE' => 'SWE', //Sweden
638 'CH' => 'CHE', //Switzerland
639 'SY' => 'SYR', //Syria
640 'TW' => 'TWN', //Taiwan
641 'TJ' => 'TJK', //Tajikistan
642 'TZ' => 'TZA', //Tanzania
643 'TH' => 'THA', //Thailand
644 'TL' => 'TLS', //Timor-Leste
645 'TG' => 'TGO', //Togo
646 'TK' => 'TKL', //Tokelau
647 'TO' => 'TON', //Tonga
648 'TT' => 'TTO', //Trinidad and Tobago
649 'TN' => 'TUN', //Tunisia
650 'TR' => 'TUR', //Turkey
651 'TM' => 'TKM', //Turkmenistan
652 'TC' => 'TCA', //Turks and Caicos Islands
653 'TV' => 'TUV', //Tuvalu
654 'UG' => 'UGA', //Uganda
655 'UA' => 'UKR', //Ukraine
656 'AE' => 'ARE', //United Arab Emirates
657 'GB' => 'GBR', //United Kingdom
658 'US' => 'USA', //United States
659 'UM' => 'UMI', //United States Minor Outlying Islands
660 'UY' => 'URY', //Uruguay
661 'UZ' => 'UZB', //Uzbekistan
662 'VU' => 'VUT', //Vanuatu
663 'VE' => 'VEN', //Venezuela
664 'VN' => 'VNM', //Vietnam
665 'VG' => 'VGB', //Virgin Islands, British
666 'VI' => 'VIR', //Virgin Island, U.S.
667 'WF' => 'WLF', //Wallis and Futuna
668 'EH' => 'ESH', //Western Sahara
669 'YE' => 'YEM', //Yemen
670 'ZM' => 'ZMB', //Zambia
671 'ZW' => 'ZWE', //Zimbabwe
672
673 );
674
675 $iso_code = isset( $countries[$country] ) ? $countries[$country] : $country;
676 return $iso_code;
677
678 }
679 }
680}
681add_action( 'plugins_loaded', 'woo_mpgs_visa_init' );
682