Changeset 1024852
- Timestamp:
- 11/13/2014 05:22:32 AM (11 years ago)
- Location:
- woocommerce-fat-zebra-gateway/trunk
- Files:
-
- 5 edited
-
class-wc-fatzebra-masterpass.php (modified) (1 diff)
-
class-wc-fatzebra-visacheckout.php (modified) (11 diffs)
-
class-wc-fatzebra.php (modified) (28 diffs)
-
images/fatzebra-visacheckout.js (modified) (1 diff)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
woocommerce-fat-zebra-gateway/trunk/class-wc-fatzebra-masterpass.php
r1024839 r1024852 9 9 $this->has_fields = true; 10 10 $this->method_title = __( 'Fat Zebra (MasterPass)', 'woocommerce' ); 11 $this->version = "1. 4.6";11 $this->version = "1.5.0"; 12 12 13 13 $this->api_version = "1.0"; -
woocommerce-fat-zebra-gateway/trunk/class-wc-fatzebra-visacheckout.php
r1024842 r1024852 9 9 $this->has_fields = true; 10 10 $this->method_title = __( 'Fat Zebra (VISA Checkout)', 'woocommerce' ); 11 $this->version = "1. 4.6";11 $this->version = "1.5.0"; 12 12 13 13 $this->api_version = "1.0"; … … 66 66 'description' => __("The Visa Checkout API Key (provided by Fat Zebra).", "woocommerce"), 67 67 'default' => "" 68 ) 68 ), 69 'logo_url' => array( 70 'title' => "Logo URL", 71 'type' => 'text', 72 'description' => "The HTTPS Logo URL to be displayed in the Visa Checkout Dialog. Maximum 174px wide and 34px high.", 73 'default' => '' 74 ), 69 75 ); 70 76 … … 89 95 function payment_fields() { 90 96 global $woocommerce; 97 $callid = WC()->session->get('visa_wallet_callid'); 91 98 ?> 92 99 <input type='hidden' name='encKey' id='encKey' /> 93 100 <input type='hidden' name='encPaymentData' id='encPaymentData' /> 94 <input type='hidden' name='callid' id='callid' /> 101 <input type='hidden' name='callid' id='callid' value='<?php echo $callid; ?>' /> 102 <input type='hidden' name='token' id='token' value='<?php echo WC()->session->get('visa_wallet_token'); ?>' /> 95 103 96 104 <p> … … 111 119 'api_key' => $this->settings['api_key'], 112 120 'website' => get_site_url(), 121 'website_name' => get_bloginfo('title'), 122 'logo_url' => $this->settings['logo_url'], 113 123 'regions' => array('AU'), 114 124 'card_brands' => $accepted_cards, 115 125 'currency' => get_woocommerce_currency(), 116 126 'order_total' => $woocommerce->cart->total, 117 'visa_checkout_button' => "<img src='{$visa_base_url}/wallet-services-web/xo/button.png?locale=en_AU&card_brands=" . implode(",", $accepted_cards) . "&style=color&size=213' class='v-button' data-2x-image='{$visa_base_url}/wallet-services-web/xo/button.png?locale=en_AU&card_brands=" . implode(",", $accepted_cards) . "&style=color&size=425' width='213' height='47' role='button' style='float: right;'/>" 127 'visa_checkout_button' => "<img src='{$visa_base_url}/wallet-services-web/xo/button.png?locale=en_AU&card_brands=" . implode(",", $accepted_cards) . "&style=color&size=213' class='v-button' data-2x-image='{$visa_base_url}/wallet-services-web/xo/button.png?locale=en_AU&card_brands=" . implode(",", $accepted_cards) . "&style=color&size=425' width='213' height='47' role='button' style='float: right; width: auto; clear: both; border: none; background: none; box-shadow: none;'/>", 128 'button_text' => 'Pay', 129 'review_message' => 'Please select your card and click Pay to complete your order', 130 'shipping' => false, 131 'checkout_captured' => !is_null($callid) 118 132 ) 119 133 ); … … 126 140 wp_register_script('fz-io-bb', $device_id_url, array('fz-deviceid'), '1', true); 127 141 wp_enqueue_script('fz-io-bb'); 142 } 143 144 if (!is_null($callid)) { 145 //pre-select Visa Checkout as the payment method 146 $available_gateways = WC()->payment_gateways->get_available_payment_gateways(); 147 $available_gateways['fatzebra_visacheckout']->set_current(); 128 148 } 129 149 … … 159 179 $this->params["wallet"] = array( 160 180 "type" => "VISA", 161 "encPaymentData" => $_POST['encPaymentData'],162 "encKey" => $_POST['encKey'],163 181 "callid" => $_POST['callid'] 164 182 ); 183 184 if (isset($_POST['token'])) { 185 $this->params['card_token'] = $_POST['token']; 186 } 165 187 166 188 if ($this->parent_settings['fraud_data'] == 'yes') { … … 237 259 $order->payment_complete(); 238 260 261 // Clear the session values 262 $this->clear_visa_checkout_session_values(); 263 239 264 // Store the card token as post meta 240 265 update_post_meta($order_id, "_fatzebra_card_token", $result["card_token"]); … … 247 272 'redirect' => $this->get_return_url( $order ) 248 273 ); 274 } 275 } 276 277 /** 278 * 279 * @return mixed WP_Error or Array (result) 280 */ 281 function tokenize_card($params) { 282 $sandbox_mode = $this->parent_settings["sandbox_mode"] == "yes"; // Yup, the checkbox settings return as 'yes' or 'no' 283 $test_mode = $this->parent_settings["test_mode"] == "yes"; 284 285 $ip = null; //get_post_meta($post_id, "Customer IP Address", true); 286 if (empty($ip)) $ip = "127.0.0.1"; 287 if (!isset($payload["customer_ip"])) $payload["customer_ip"] = $ip; 288 289 $order_text = json_encode($params); 290 291 $url = $sandbox_mode ? $this->sandbox_url : $url = $this->live_url; 292 // Replace the URL with the tokenize method and re-create the order text (json payload) 293 $url = str_replace("purchases", "credit_cards", $url); 294 if (isset($params['callid'])) { 295 $payload = array("wallet" => array("type" => "VISA", "callid" => $params['callid'])); 296 } else { 297 $payload = array("card_holder" => $params["card_holder"], "card_number" => $params["card_number"], "card_expiry" => $params["card_expiry"], "cvv" => $params["cvv"]); 298 } 299 $order_text = json_encode($payload); 300 301 $args = array('method' => 'POST', 'body' => $order_text, 'headers' => array('Authorization' => 'Basic ' . base64_encode($this->parent_settings["username"] . ":" . $this->parent_settings["token"]), 'X-Test-Mode' => $test_mode, 'User-Agent' => "WooCommerce Plugin " . $this->version), 'timeout' => 30); 302 try { 303 $this->response = (array)wp_remote_request($url, $args); 304 if ((int)$this->response["response"]["code"] != 200 && (int)$this->response["response"]["code"] != 201) { 305 $error = new WP_Error(); 306 $error->add(1, "Credit Card Payment failed: " . $this->response["response"]["message"]); 307 $error->add_data($this->response); 308 return $error; 309 } 310 311 $this->response_data = json_decode($this->response['body']); 312 313 if (!$this->response_data->successful) { 314 $error = new WP_Error(); 315 $error->add(2, "Gateway Error", $this->response_data->errors); 316 317 return $error; 318 } 319 320 return array( 321 "card_token" => $this->response_data->response->token, 322 "card_number" => $this->response_data->response->card_number, 323 "card_expiry" => $this->response_data->response->card_expiry, 324 "card_holder" => $this->response_data->response->card_holder, 325 "transaction_id" => $this->response_data->response->token, 326 "wallet" => $this->response_data->response->wallet); 327 } catch (Exception $e) { 328 $error = new WP_Error(); 329 $error->add(4, "Unknown Error", $e); 330 return $error; 249 331 } 250 332 } … … 391 473 } 392 474 393 function get_customer_real_ip() 394 { 475 function get_customer_real_ip() { 395 476 $customer_ip = $_SERVER['REMOTE_ADDR']; 396 477 if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { … … 400 481 401 482 return $customer_ip; 483 } 484 485 function clear_visa_checkout_session_values() { 486 $keys = array('visa_wallet_first_name', 'visa_wallet_last_name', 'visa_wallet_address_1', 'visa_wallet_address_2', 'visa_wallet_city', 'visa_wallet_state', 'visa_wallet_postcode', 'visa_wallet_phone', 'visa_wallet_email', 'visa_wallet_callid', 'visa_wallet_token'); 487 488 foreach($keys as $key): 489 WC()->session->set($key, null); 490 endforeach; 402 491 } 403 492 } … … 410 499 } 411 500 501 function inject_visacheckout_button() { 502 $payment_gateways = WC()->payment_gateways->get_available_payment_gateways(); 503 if (!isset($payment_gateways['fatzebra_visacheckout'])) { 504 return; 505 } 506 507 $gw = $payment_gateways['fatzebra_visacheckout']; 508 509 $amount = WC()->cart->total; 510 $visa_base_url = $gw->parent_settings['sandbox_mode'] == "yes" ? 'https://sandbox.secure.checkout.visa.com' : 'https://secure.checkout.visa.com'; 511 $accepted_cards = array(); 512 foreach($gw->parent_settings['show_card_logos'] as $card) { 513 if ($card == 'american_express') $card = "AMEX"; 514 $accepted_cards[] = strtoupper($card); 515 } 516 517 wp_register_script( 'fz-visacheckout', plugin_dir_url(__FILE__) . '/images/fatzebra-visacheckout.js', array(), WC_VERSION, false ); 518 wp_register_script( 'visa-checkout', "{$visa_base_url}/checkout-widget/resources/js/integration/v1/sdk.js", array(), WC_VERSION, true ); 519 wp_localize_script( 'fz-visacheckout', 'fzvisa', array( 520 'api_key' => $gw->settings['api_key'], 521 'website' => get_site_url(), 522 'website_name' => get_bloginfo('title'), 523 'logo_url' => $gw->settings['logo_url'], 524 'regions' => array('AU'), 525 'card_brands' => $accepted_cards, 526 'currency' => get_woocommerce_currency(), 527 'order_total' => $amount, 528 'visa_checkout_button' => "<img src='{$visa_base_url}/wallet-services-web/xo/button.png?locale=en_AU&card_brands=" . implode(",", $accepted_cards) . "&style=color&size=213' class='v-button' data-2x-image='{$visa_base_url}/wallet-services-web/xo/button.png?locale=en_AU&card_brands=" . implode(",", $accepted_cards) . "&style=color&size=425' width='213' height='47' role='button' style='float: right; width: auto; clear: both; border: none; background: none; box-shadow: none;'/>", 529 'inline' => true, 530 'shipping' => false, 531 'button_text' => 'Continue', 532 'review_message' => 'Please select your card and click Continue to finish your order', 533 ) 534 ); 535 wp_enqueue_script( 'fz-visacheckout' ); 536 wp_enqueue_script( 'visa-checkout' ); 537 538 // Visa Checkout Button 539 // Visa Checkout INIT 540 // Handler for callback (process payment, retrieve address details, update order) 541 } 542 543 function fz_visacheckout_set_callid_cookie() { 544 if (isset($_POST['callid']) && !empty($_POST['callid'])) { 545 wc_setcookie( 'fatzebra_visacheckout_callid', $_POST['callid'] ); 546 } 547 } 548 549 function fz_visacheckout_load_from_callid($fields) { 550 $payment_gateways = WC()->payment_gateways->get_available_payment_gateways(); 551 if (!isset($payment_gateways['fatzebra_visacheckout'])) { 552 return; 553 } 554 555 $gw = $payment_gateways['fatzebra_visacheckout']; 556 557 $callid = isset($_COOKIE['fatzebra_visacheckout_callid']) ? $_COOKIE['fatzebra_visacheckout_callid'] : null; 558 if (empty($callid)) { 559 return $fields; 560 } 561 562 $token_result = $gw->tokenize_card(array("callid" => $callid)); 563 564 if (is_wp_error($token_result)) { 565 // Tokenization error - for now lets return the fields with no manipulation.. 566 // error_log 567 568 return $fields; 569 } // Arghhh! 570 571 $wallet = $token_result['wallet']; 572 573 // Store the wallet data in a session. It is important to remove this upon successful checkout.... 574 WC()->session->set('visa_wallet_first_name', $wallet->name->first); 575 WC()->session->set('visa_wallet_last_name', $wallet->name->last); 576 WC()->session->set('visa_wallet_address_1', $wallet->address->line_1); 577 WC()->session->set('visa_wallet_address_2', $wallet->address->line_2); 578 WC()->session->set('visa_wallet_city', $wallet->address->city); 579 WC()->session->set('visa_wallet_state', $wallet->address->state); 580 WC()->session->set('visa_wallet_postcode', $wallet->address->postcode); 581 WC()->session->set('visa_wallet_phone', $wallet->address->phone); 582 WC()->session->set('visa_wallet_email', $wallet->email); 583 WC()->session->set('visa_wallet_callid', $callid); 584 WC()->session->set('visa_wallet_token', $token_result['card_token']); 585 586 wc_setcookie('fatzebra_visacheckout_callid', null, time() - 3600); 587 return $fields; 588 } 589 590 function fz_visacheckout_populate_default_field_value($_, $fieldname) { 591 switch($fieldname) { 592 case 'billing_email': 593 return WC()->session->get('visa_wallet_email'); 594 break; 595 596 case 'billing_first_name': 597 case 'shipping_first_name': 598 return WC()->session->get('visa_wallet_first_name'); 599 break; 600 601 case 'billing_last_name': 602 case 'shipping_last_name': 603 return WC()->session->get('visa_wallet_last_name'); 604 break; 605 606 case 'billing_address_1': 607 case 'shipping_address_1': 608 return WC()->session->get('visa_wallet_address_1'); 609 break; 610 611 case 'billing_address_2': 612 case 'shipping_address_2': 613 return WC()->session->get('visa_wallet_address_2'); 614 break; 615 616 617 case 'billing_city': 618 case 'shipping_city': 619 return WC()->session->get('visa_wallet_city'); 620 break; 621 622 case 'billing_state': 623 case 'shipping_state': 624 return WC()->session->get('visa_wallet_state'); 625 break; 626 627 case 'billing_postcode': 628 case 'shipping_postcode': 629 return WC()->session->get('visa_wallet_postcode'); 630 break; 631 632 case 'billing_phone': 633 case 'shipping_phone': 634 return WC()->session->get('visa_wallet_phone'); 635 break; 636 637 case 'ship_to_different_address': 638 return false; // Using wallet we prefill the shipping address. The customer can change this if they want in the form. 639 break; 640 } 641 } 642 643 function fz_visacheckout_ship_to_different_address($value) { 644 return false; 645 } 646 647 function fz_visacheckout_force_gateway($gateways) { 648 if (is_null(WC()->session->get('visa_wallet_callid'))) { 649 return $gateways; 650 } else { 651 652 $forced_gateways = array(); 653 $forced_gateways['fatzebra_visacheckout'] = $gateways['fatzebra_visacheckout']; 654 655 return $forced_gateways; 656 } 657 } 658 659 function fz_visacheckout_anticlickjack() { 660 ?> 661 <style id="antiClickjack">body{display:none;}</style> 662 <script type="text/javascript"> 663 if (self === top) { 664 var antiClickjack = document.getElementById("antiClickjack"); 665 antiClickjack.parentNode.removeChild(antiClickjack); 666 } else { 667 top.location = self.location; 668 } 669 </script> 670 <?php 671 } 672 412 673 add_filter('woocommerce_payment_gateways', 'add_fz_visacheckout_gateway' ); 674 add_action('woocommerce_proceed_to_checkout', 'inject_visacheckout_button'); 675 676 add_action( 'woocommerce_set_cart_cookies', 'fz_visacheckout_set_callid_cookie' ); 677 add_filter( 'woocommerce_checkout_fields' , 'fz_visacheckout_load_from_callid' ); 678 add_filter( 'woocommerce_checkout_get_value', 'fz_visacheckout_populate_default_field_value', -10, 2); 679 add_filter( 'woocommerce_ship_to_different_address_checked', 'fz_visacheckout_ship_to_different_address'); 680 add_filter( 'woocommerce_available_payment_gateways', 'fz_visacheckout_force_gateway', -10, 1); 681 add_action( 'wp_head', 'fz_visacheckout_anticlickjack', 1); 413 682 } -
woocommerce-fat-zebra-gateway/trunk/class-wc-fatzebra.php
r1024843 r1024852 5 5 Plugin URI: https://www.fatzebra.com.au/support/supported-carts 6 6 Description: Extends WooCommerce with Fat Zebra payment gateway along with WooCommerce subscriptions support. 7 Version: 1. 4.57 Version: 1.5.0 8 8 Author: Fat Zebra 9 9 Author URI: https://www.fatzebra.com.au … … 26 26 add_action('plugins_loaded', 'fz_init', 0); 27 27 28 function fz_init() 29 { 28 function fz_init() { 30 29 if (!class_exists('WC_Payment_Gateway')) { 31 30 ?> … … 53 52 fz_visacheckout_init(); 54 53 55 class WC_FatZebra extends WC_Payment_Gateway 56 { 57 58 public function __construct() 59 { 54 class WC_FatZebra extends WC_Payment_Gateway { 55 56 public function __construct() { 60 57 $this->id = 'fatzebra'; 61 58 $this->icon = apply_filters('woocommerce_fatzebra_icon', ''); 62 59 $this->has_fields = true; 63 60 $this->method_title = __('Fat Zebra', 'woocommerce'); 64 $this->version = "1. 4.6";61 $this->version = "1.5.0"; 65 62 66 63 $this->api_version = "1.0"; 67 64 $this->live_url = "https://gateway.fatzebra.com.au/v{$this->api_version}/purchases"; 68 65 $this->sandbox_url = "https://gateway.sandbox.fatzebra.com.au/v{$this->api_version}/purchases"; 69 $this->supports = array('subscriptions', 'products', ' products', 'subscription_cancellation', 'subscription_reactivation', 'subscription_suspension', 'subscription_amount_changes', 'subscription_payment_method_change', 'subscription_date_changes');66 $this->supports = array('subscriptions', 'products', 'refunds', 'subscription_cancellation', 'subscription_reactivation', 'subscription_suspension', 'subscription_amount_changes', 'subscription_payment_method_change', 'subscription_date_changes'); 70 67 $this->params = array(); 71 68 $this->country_map = array("AD" => "AND", "AE" => "ARE", "AF" => "AFG", "AG" => "ATG", "AI" => "AIA", "AL" => "ALB", "AM" => "ARM", "AN" => "ANT", "AO" => "AGO", "AQ" => "ATA", "AR" => "ARG", "AS" => "ASM", "AT" => "AUT", "AU" => "AUS", "AW" => "ABW", "AX" => "ALA", "AZ" => "AZE", "BA" => "BIH", "BB" => "BRB", "BD" => "BGD", "BE" => "BEL", "BF" => "BFA", "BG" => "BGR", "BH" => "BHR", "BI" => "BDI", "BJ" => "BEN", "BL" => "BLM", "BM" => "BMU", "BN" => "BRN", "BO" => "BOL", "BQ" => "BES", "BR" => "BRA", "BS" => "BHS", "BT" => "BTN", "BV" => "BVT", "BW" => "BWA", "BY" => "BLR", "BZ" => "BLZ", "CA" => "CAN", "CC" => "CCK", "CD" => "COD", "CF" => "CAF", "CG" => "COG", "CH" => "CHE", "CI" => "CIV", "CK" => "COK", "CL" => "CHL", "CM" => "CMR", "CN" => "CHN", "CO" => "COL", "CR" => "CRI", "CU" => "CUB", "CV" => "CPV", "CW" => "CUW", "CX" => "CXR", "CY" => "CYP", "CZ" => "CZE", "DE" => "DEU", "DJ" => "DJI", "DK" => "DNK", "DM" => "DMA", "DO" => "DOM", "DZ" => "DZA", "EC" => "ECU", "EE" => "EST", "EG" => "EGY", "EH" => "ESH", "ER" => "ERI", "ES" => "ESP", "ET" => "ETH", "FI" => "FIN", "FJ" => "FJI", "FK" => "FLK", "FM" => "FSM", "FO" => "FRO", "FR" => "FRA", "GA" => "GAB", "GB" => "GBR", "GD" => "GRD", "GE" => "GEO", "GF" => "GUF", "GG" => "GGY", "GH" => "GHA", "GI" => "GIB", "GL" => "GRL", "GM" => "GMB", "GN" => "GIN", "GP" => "GLP", "GQ" => "GNQ", "GR" => "GRC", "GS" => "SGS", "GT" => "GTM", "GU" => "GUM", "GW" => "GNB", "GY" => "GUY", "HK" => "HKG", "HM" => "HMD", "HN" => "HND", "HR" => "HRV", "HT" => "HTI", "HU" => "HUN", "ID" => "IDN", "IE" => "IRL", "IL" => "ISR", "IM" => "IMN", "IN" => "IND", "IO" => "IOT", "IQ" => "IRQ", "IR" => "IRN", "IS" => "ISL", "IT" => "ITA", "JE" => "JEY", "JM" => "JAM", "JO" => "JOR", "JP" => "JPN", "KE" => "KEN", "KG" => "KGZ", "KH" => "KHM", "KI" => "KIR", "KM" => "COM", "KN" => "KNA", "KP" => "PRK", "KR" => "KOR", "KW" => "KWT", "KY" => "CYM", "KZ" => "KAZ", "LA" => "LAO", "LB" => "LBN", "LC" => "LCA", "LI" => "LIE", "LK" => "LKA", "LR" => "LBR", "LS" => "LSO", "LT" => "LTU", "LU" => "LUX", "LV" => "LVA", "LY" => "LBY", "MA" => "MAR", "MC" => "MCO", "MD" => "MDA", "ME" => "MNE", "MF" => "MAF", "MG" => "MDG", "MH" => "MHL", "MK" => "MKD", "ML" => "MLI", "MM" => "MMR", "MN" => "MNG", "MO" => "MAC", "MP" => "MNP", "MQ" => "MTQ", "MR" => "MRT", "MS" => "MSR", "MT" => "MLT", "MU" => "MUS", "MV" => "MDV", "MW" => "MWI", "MX" => "MEX", "MY" => "MYS", "MZ" => "MOZ", "NA" => "NAM", "NC" => "NCL", "NE" => "NER", "NF" => "NFK", "NG" => "NGA", "NI" => "NIC", "NL" => "NLD", "NO" => "NOR", "NP" => "NPL", "NR" => "NRU", "NU" => "NIU", "NZ" => "NZL", "OM" => "OMN", "PA" => "PAN", "PE" => "PER", "PF" => "PYF", "PG" => "PNG", "PH" => "PHL", "PK" => "PAK", "PL" => "POL", "PM" => "SPM", "PN" => "PCN", "PR" => "PRI", "PS" => "PSE", "PT" => "PRT", "PW" => "PLW", "PY" => "PRY", "QA" => "QAT", "RE" => "REU", "RO" => "ROU", "RS" => "SRB", "RU" => "RUS", "RW" => "RWA", "SA" => "SAU", "SB" => "SLB", "SC" => "SYC", "SD" => "SDN", "SE" => "SWE", "SG" => "SGP", "SH" => "SHN", "SI" => "SVN", "SJ" => "SJM", "SK" => "SVK", "SL" => "SLE", "SM" => "SMR", "SN" => "SEN", "SO" => "SOM", "SR" => "SUR", "SS" => "SSD", "ST" => "STP", "SV" => "SLV", "SX" => "SXM", "SY" => "SYR", "SZ" => "SWZ", "TC" => "TCA", "TD" => "TCD", "TF" => "ATF", "TG" => "TGO", "TH" => "THA", "TJ" => "TJK", "TK" => "TKL", "TL" => "TLS", "TM" => "TKM", "TN" => "TUN", "TO" => "TON", "TR" => "TUR", "TT" => "TTO", "TV" => "TUV", "TW" => "TWN", "TZ" => "TZA", "UA" => "UKR", "UG" => "UGA", "UM" => "UMI", "US" => "USA", "UY" => "URY", "UZ" => "UZB", "VA" => "VAT", "VC" => "VCT", "VE" => "VEN", "VG" => "VGB", "VI" => "VIR", "VN" => "VNM", "VU" => "VUT", "WF" => "WLF", "WS" => "WSM", "YE" => "YEM", "YT" => "MYT", "ZA" => "ZAF", "ZM" => "ZMB", "ZW" => "ZWE"); … … 91 88 * Indicates if direct post is enabled/configured or not 92 89 */ 93 function direct_post_enabled() 94 { 90 function direct_post_enabled() { 95 91 return $this->settings['use_direct_post'] == 'yes' && !is_null($this->settings['shared_secret']); 96 92 } … … 99 95 * Indicates if we should send fraud data 100 96 */ 101 function fraud_detection_enabled() 102 { 97 function fraud_detection_enabled() { 103 98 return $this->settings['fraud_data'] == 'yes'; 104 99 } … … 107 102 * Returns the direct post URL 108 103 */ 109 function get_direct_post_url() 110 { 104 function get_direct_post_url() { 111 105 $sandbox_mode = $this->settings["sandbox_mode"] == "yes"; // Yup, the checkbox settings return as 'yes' or 'no' 112 106 $url = $sandbox_mode ? $this->sandbox_url : $url = $this->live_url; … … 209 203 * @since 1.0.0 210 204 */ 211 public function admin_options() 212 { 205 public function admin_options() { 213 206 ?> 214 207 <h3><?php _e('Fat Zebra', 'woocommerce'); ?></h3> … … 220 213 } // End admin_options() 221 214 222 function payment_fields() 223 { 215 function payment_fields() { 224 216 if ($this->direct_post_enabled()) { 225 217 // Register and enqueue direct post handling script … … 231 223 wp_register_script('fz-direct-post-handler', plugin_dir_url(__FILE__) . '/images/fatzebra.js', array('jquery'), WC_VERSION, true); 232 224 wp_localize_script('fz-direct-post-handler', 'fatzebra', array( 233 'url' => $url, 234 'return_path' => $return_path, 235 'verification_value' => $verification_value 236 ) 225 'url' => $url, 226 'return_path' => $return_path, 227 'verification_value' => $verification_value) 237 228 ); 238 229 wp_enqueue_script('fz-direct-post-handler'); … … 253 244 * Process the payment and return the result 254 245 **/ 255 function process_payment($order_id) 256 { 246 function process_payment($order_id) { 257 247 global $woocommerce; 258 248 … … 370 360 } 371 361 372 if (isset($this->response_data->response->fraud_result ) && !empty($this->response_data->response->fraud_result)) {373 if ($this->response_data->response->fraud_result == 'Accept') {362 if (isset($this->response_data->response->fraud_result) && !empty($this->response_data->response->fraud_result)) { 363 if ($this->response_data->response->fraud_result == 'Accept') { 374 364 $order->add_order_note("Fraud Check Result: Accept"); 375 365 } else { 376 $order->add_order_note("Fraud Check Result: " . $this->response_data->response->fraud_result . " - " . implode(", ", $this->response_data->response->fraud_messages));366 $order->add_order_note("Fraud Check Result: " . $this->response_data->response->fraud_result . " - " . implode(", ", $this->response_data->response->fraud_messages)); 377 367 } 378 368 } … … 383 373 update_post_meta($order_id, "_fatzebra_card_token", $result["card_token"]); 384 374 update_post_meta($order_id, "fatzebra_card_token", $result["card_token"]); 375 update_post_meta($order_id, 'Fat Zebra Transaction ID', $result['transaction_id']); 385 376 } 386 377 $woocommerce->cart->empty_cart(); 387 378 388 return array( 389 'result' => 'success', 390 'redirect' => $this->get_return_url($order) 391 ); 392 } 379 return array('result' => 'success', 'redirect' => $this->get_return_url($order)); 380 } 381 } 382 383 /** 384 * Process refund 385 * 386 * If the gateway declares 'refunds' support, this will allow it to refund 387 * a passed in amount. 388 * 389 * @param int $order_id 390 * @param float $amount 391 * @param string $reason 392 * @return boolean True or false based on success, or a WP_Error object 393 */ 394 public function process_refund( $order_id, $amount = null, $reason = '' ) { 395 global $woocommerce; 396 397 $order = new WC_Order($order_id); 398 $this->params["amount"] = (int)($amount * 100); 399 $this->params["reference"] = $order_id . "-" . time(); // It is not possible to simply refund against the order ID as multiple reunds are permitted... 400 $this->params["transaction_id"] = get_post_meta($order_id, 'Fat Zebra Transaction ID', true); // The original FZ transaction ID 401 if (empty($this->params['transaction_id'])) { 402 $this->params["transaction_id"] = $this->fetch_fatzebra_transaction_id($order_id); 403 } 404 405 $this->params["customer_ip"] = $this->get_customer_real_ip(); 406 $this->params["currency"] = $order->get_order_currency(); 407 408 $test_mode = $this->settings['test_mode'] == 'yes'; 409 $this->params["test"] = $test_mode; 410 $sandbox_mode = $this->settings["sandbox_mode"] == "yes"; // Yup, the checkbox settings return as 'yes' or 'no' 411 412 $order_text = json_encode($this->params); 413 414 $url = $sandbox_mode ? $this->sandbox_url : $url = $this->live_url; 415 // URL is for /refunds 416 $url = str_replace('purchases', 'refunds', $url); 417 418 $args = array('method' => 'POST', 419 'body' => $order_text, 420 'headers' => array('Authorization' => 'Basic ' . base64_encode($this->settings["username"] . ":" . $this->settings["token"]), 421 'X-Test-Mode' => $test_mode, 422 'User-Agent' => "WooCommerce Plugin " . $this->version), 423 'timeout' => 30); 424 try { 425 $this->response = (array)wp_remote_request($url, $args); 426 427 if ((int)$this->response["response"]["code"] != 200 && (int)$this->response["response"]["code"] != 201) { 428 wc_add_notice("Refund failed: " . $this->response["response"]["message"], 'error'); 429 return false; 430 } 431 432 $this->response_data = json_decode($this->response['body']); 433 434 if (!$this->response_data->successful) { 435 wc_add_notice('Refund Failed - Gateway Error: ' . implode(",", $this->response_data->errors), 'error'); 436 return false; 437 } 438 439 if (!$this->response_data->response->successful) { 440 wc_add_notice('Refund Declined: ' . $this->response_data->response->message, 'error'); 441 return false; 442 } 443 444 if ($this->response_data->response->successful) { 445 wc_add_notice('Refund Approved'); 446 $order->add_order_note('Refund for ' . $amount . ' successful. Refund ID: ' . $this->response_data->response->id); 447 return true; 448 } 449 450 } catch (Exception $e) { 451 wc_add_notice("Unknown Refund Error - please see error log", "error"); 452 error_log("Exception caught during refund: " . print_r($e, true)); 453 return false; 454 } 455 456 return false; 457 } 458 459 function fetch_fatzebra_transaction_id($order_id) { 460 return false; 393 461 } 394 462 395 463 // For the thankyou page :) 396 function thankyou_page() 397 { 464 function thankyou_page() { 398 465 if ($this->description) echo wpautop(wptexturize($this->description)); 399 466 } … … 406 473 * @param $product_id the product ID 407 474 */ 408 function scheduled_subscription_payment($amount_to_charge, $order, $product_id) 409 { 475 function scheduled_subscription_payment($amount_to_charge, $order, $product_id) { 410 476 $this->params = array(); 411 477 $this->params["amount"] = (int)($amount_to_charge * 100); … … 465 531 * @return mixed WP_Error or Array (result) 466 532 */ 467 function do_payment($params) 468 { 533 function do_payment($params) { 469 534 $sandbox_mode = $this->settings["sandbox_mode"] == "yes"; // Yup, the checkbox settings return as 'yes' or 'no' 470 535 $test_mode = $this->settings["test_mode"] == "yes"; … … 488 553 489 554 $args = array( 490 'method' => 'POST', 491 'body' => $order_text, 555 'method' => 'POST', 556 'body' => $order_text, 492 557 'headers' => array( 493 558 'Authorization' => 'Basic ' . base64_encode($this->settings["username"] . ":" . $this->settings["token"]), 494 'X-Test-Mode' => $test_mode, 559 'X-Test-Mode' => $test_mode, 495 560 'User-Agent' => "WooCommerce Plugin " . $this->version 496 ),561 ), 497 562 'timeout' => 30 498 ); 563 ); 564 499 565 try { 500 566 $this->response = (array)wp_remote_request($url, $args); … … 542 608 * @return mixed WP_Error or Array (result) 543 609 */ 544 function tokenize_card($params) 545 { 610 function tokenize_card($params) { 546 611 $sandbox_mode = $this->settings["sandbox_mode"] == "yes"; // Yup, the checkbox settings return as 'yes' or 'no' 547 612 $test_mode = $this->settings["test_mode"] == "yes"; … … 560 625 561 626 $args = array( 562 'method' => 'POST', 563 'body' => $order_text, 627 'method' => 'POST', 628 'body' => $order_text, 564 629 'headers' => array( 565 630 'Authorization' => 'Basic ' . base64_encode($this->settings["username"] . ":" . $this->settings["token"]), 566 'X-Test-Mode' => $test_mode, 631 'X-Test-Mode' => $test_mode, 567 632 'User-Agent' => "WooCommerce Plugin " . $this->version 568 ),633 ), 569 634 'timeout' => 30 570 );635 ); 571 636 try { 572 637 $this->response = (array)wp_remote_request($url, $args); … … 597 662 598 663 // Add the 'Charge Card' button if the order is on-hold 599 function add_process_deferred_payment_button($order_id) 600 { 664 function add_process_deferred_payment_button($order_id) { 601 665 $order = new WC_Order($order_id); 602 666 if ($order->status == "on-hold") { … … 608 672 * @param $order WC_Order the order to build the payload against 609 673 */ 610 function get_fraud_payload($order) 611 { 612 $fraud_data = array( 613 "website" => get_site_url(), 614 "customer" => $this->get_fraud_customer($order), 615 "items" => $this->get_fraud_items($order), 616 "shipping_address" => $this->get_fraud_shipping($order) 617 ); 674 function get_fraud_payload($order) { 675 $fraud_data = array("website" => get_site_url(), "customer" => $this->get_fraud_customer($order), "items" => $this->get_fraud_items($order), "shipping_address" => $this->get_fraud_shipping($order)); 618 676 619 677 if ($this->settings["fraud_device_id"] === "yes") { … … 627 685 * Fetches the customer details for the fraud check request 628 686 */ 629 function get_fraud_customer($order) 630 { 687 function get_fraud_customer($order) { 631 688 $data = array( 632 'first_name' => $order->billing_first_name, 633 'last_name' => $order->billing_last_name, 634 'email' => $order->billing_email, 635 'address_1' => $order->billing_address_1, 636 'address_2' => $order->billing_address_2, 637 'city' => $order->billing_city, 638 'country' => $this->country_map[$order->billing_country], 639 'post_code' => $order->billing_postcode, 689 'first_name' => $order->billing_first_name, 690 'last_name' => $order->billing_last_name, 691 'email' => $order->billing_email, 692 'address_1' => $order->billing_address_1, 693 'address_2' => $order->billing_address_2, 694 'city' => $order->billing_city, 695 'country' => $this->country_map[$order->billing_country], 696 'post_code' => $order->billing_postcode, 640 697 'home_phone' => $order->billing_phone 641 ); 642 643 // TODO: Customer DOB, Customer Created AT, Existing Customer 698 ); 699 644 700 return $data; 645 701 } … … 648 704 * Fetches the item details from the order for the fraud check request 649 705 */ 650 function get_fraud_items($order) 651 { 706 function get_fraud_items($order) { 652 707 653 708 $data = array(); … … 664 719 665 720 $data[] = array( 666 'product_code' => (string)$product->id, 667 'sku' => $product->sku, 668 'description' => $name, 669 'qty' => $item['qty'], 670 'cost' => $product->get_price(), 721 'product_code' => (string)$product->id, 722 'sku' => $product->sku, 723 'description' => $name, 724 'qty' => $item['qty'], 725 'cost' => $product->get_price(), 671 726 'line_total' => $order->get_line_subtotal($item) 672 );727 ); 673 728 } 674 729 … … 679 734 * Fetches the shipping details from the order for the fraud check request 680 735 */ 681 function get_fraud_shipping($order) 682 { 736 function get_fraud_shipping($order) { 683 737 $data = array( 684 'first_name' => $order->shipping_first_name,685 'last_name' => $order->shipping_last_name,686 'email' => $order->shipping_email,687 'address_1' => $order->shipping_address_1,688 'address_2' => $order->shipping_address_2,689 'city' => $order->shipping_city,690 'country' => $this->country_map[$order->shipping_country],691 'post_code' => $order->shipping_postcode,692 'shipping_method' => 'low_cost' // TODO: Shipping Method Map738 'first_name' => $order->shipping_first_name, 739 'last_name' => $order->shipping_last_name, 740 'email' => $order->shipping_email, 741 'address_1' => $order->shipping_address_1, 742 'address_2' => $order->shipping_address_2, 743 'city' => $order->shipping_city, 744 'country' => $this->country_map[$order->shipping_country], 745 'post_code' => $order->shipping_postcode, 746 'shipping_method' => 'low_cost' // TODO: Shipping Method Map 693 747 ); 694 748 … … 698 752 } 699 753 700 function get_customer_real_ip() 701 { 754 function get_customer_real_ip() { 702 755 $customer_ip = $_SERVER['REMOTE_ADDR']; 703 756 if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { … … 713 766 * Add the gateway to WooCommerce 714 767 **/ 715 function add_fz_gateway($methods) 716 { 768 function add_fz_gateway($methods) { 717 769 $methods[] = 'WC_FatZebra'; 718 770 return $methods; … … 720 772 721 773 // Attempt to process the deferred payment. This is called when you press the 'Charge card' button on the order page. 722 function attempt_deferred_payment($post_id, $post) 723 { 774 function attempt_deferred_payment($post_id, $post) { 724 775 global $wpdb, $woocommerce, $woocommerce_errors; 725 776 … … 787 838 // - The method is not set 788 839 // - the fatzebra_card_token is set 789 function set_recurring_payment_method($post_id) 790 { 840 function set_recurring_payment_method($post_id) { 791 841 $method = get_post_meta($post_id, "_recurring_payment_method", true); 792 842 $token = get_post_meta($post_id, "fatzebra_card_token", true); … … 797 847 } 798 848 849 function fz_customize_woocommerce_states() { 850 global $states; 851 852 $states['AU'] = array( 853 'ACT' => __( 'ACT', 'woocommerce' ), 854 'NSW' => __( 'NSW', 'woocommerce' ), 855 'NT' => __( 'NT', 'woocommerce' ), 856 'QLD' => __( 'QLD', 'woocommerce' ), 857 'SA' => __( 'SA', 'woocommerce' ), 858 'TAS' => __( 'TAS', 'woocommerce' ), 859 'VIC' => __( 'VIC', 'woocommerce' ), 860 'WA' => __( 'WA', 'woocommerce' ) 861 ); 862 863 return $states; 864 } 865 799 866 add_filter('woocommerce_payment_gateways', 'add_fz_gateway'); 800 867 add_action('woocommerce_process_shop_order_meta', 'attempt_deferred_payment', 1, 2); 801 868 add_action('save_post', 'set_recurring_payment_method'); 869 add_filter( 'woocommerce_states', 'fz_customize_woocommerce_states' ); 802 870 } -
woocommerce-fat-zebra-gateway/trunk/images/fatzebra-visacheckout.js
r1024842 r1024852 1 // Visa Checkout Handling2 var visaCheckoutReady = false;3 function onVmeReady() {4 visaCheckoutReady = true;5 }1 // // Visa Checkout Handling 2 // var visaCheckoutReady = false; 3 // function onVmeReady() { 4 // visaCheckoutReady = true; 5 // } 6 6 7 function initVisaCheckout() {8 if (!visaCheckoutReady) { // Wait until Visa Checkout is ready to init...9 setTimeout(initVisaCheckout, 500);10 return false;11 }7 // function initVisaCheckout() { 8 // if (!visaCheckoutReady) { // Wait until Visa Checkout is ready to init... 9 // setTimeout(initVisaCheckout, 500); 10 // return false; 11 // } 12 12 13 V.init({ 14 apikey: fzvisa.api_key, 15 settings: { 16 dataLevel: "SUMMARY" 17 }, 18 paymentRequest: { 19 currencyCode: fzvisa.currency, 20 total: fzvisa.order_total 21 } 22 }); 13 // if (fzvisa.checkout_captured == 1) { 14 // return false; // Visa Checkout has already been completed on the cart page. 15 // } else { 23 16 24 V.on("payment.success", function(payment) { 25 jQuery('#encKey').val(payment.encKey); 26 jQuery('#encPaymentData').val(payment.encPaymentData); 27 jQuery('#callid').val(payment.callid); 17 // V.init({ 18 // apikey: fzvisa.api_key, 19 // settings: { 20 // dataLevel: "SUMMARY", 21 // displayName: fzvisa.website_name, 22 // logoUrl: fzvisa.logo_url 23 // }, 24 // paymentRequest: { 25 // currencyCode: fzvisa.currency, 26 // total: fzvisa.order_total 27 // }, 28 // shipping: { 29 // collectShipping: fzvisa.shipping 30 // }, 31 // review: { 32 // buttonAction: fzvisa.button_text, 33 // message: fzvisa.review_message 34 // } 35 // }); 28 36 29 jQuery('#place_order').show(); 30 jQuery('.v-button').remove();37 // V.on("payment.success", function(payment) { 38 // jQuery('#callid').val(payment.callid); 31 39 32 $form = jQuery("form.checkout"); 33 $form.submit(); 34 }); 40 // if (fzvisa.inline) { 41 // // 'Post' form to wc-api call for processing.. prefill the form and then show the checkout page 42 // jQuery(".checkout-button").click(); 43 // } 35 44 36 V.on("payment.cancel", function(payment) { 37 // Cancelled, but we don't need to do anything, the user just needs to choose an alternative 38 }); 39 V.on("payment.error", function(payment, error) { 40 // Error - report to user, try again? 41 }); 42 } 45 // jQuery('#encKey').val(payment.encKey); 46 // jQuery('#encPaymentData').val(payment.encPaymentData); 47 43 48 44 jQuery( '#order_review' ).on( 'click', '.payment_methods input.input-radio', function() { 45 if ( jQuery( '.payment_methods input.input-radio' ).length > 1 ) { 46 var id = jQuery(this).val(); 47 if (id == 'fatzebra_visacheckout') { 48 if (jQuery('.v-button').length !== 0) return; 49 jQuery('#place_order').hide(); 50 jQuery('#place_order').after(fzvisa.visa_checkout_button); 49 // jQuery('#place_order').show(); 50 // jQuery('.v-button').remove(); 51 51 52 setTimeout(initVisaCheckout, 500); 53 } else { 54 // Remove the visa button and show the place order button again 55 jQuery('.v-button').remove(); 56 jQuery('#place_order').show(); 57 } 58 } 59 }); 52 // $form = jQuery("form.checkout"); 53 // $form.submit(); 54 // }); 55 56 // V.on("payment.cancel", function(payment) { 57 // // Cancelled, but we don't need to do anything, the user just needs to choose an alternative 58 // }); 59 // V.on("payment.error", function(payment, error) { 60 // // Error - report to user, try again? 61 // }); 62 // } 63 // } 64 65 // jQuery( '#order_review' ).on( 'click', '.payment_methods input.input-radio', function() { 66 // if ( jQuery( '.payment_methods input.input-radio' ).length > 1 ) { 67 // if (fzvisa.checkout_captured == 1) { 68 // return; 69 // } 70 // var id = jQuery(this).val(); 71 // if (id == 'fatzebra_visacheckout') { 72 // if (jQuery('.v-button').length !== 0) return; 73 // jQuery('#place_order').hide(); 74 // jQuery('#place_order').after(fzvisa.visa_checkout_button); 75 76 // setTimeout(initVisaCheckout, 500); 77 // } else { 78 // // Remove the visa button and show the place order button again 79 // jQuery('.v-button').remove(); 80 // jQuery('#place_order').show(); 81 // } 82 // } 83 // }); 84 85 // if (fzvisa.inline) { 86 // // Render the 'Checkout' button on the cart page 87 // jQuery(".checkout-button").after("<br />").after(fzvisa.visa_checkout_button); 88 // jQuery(".checkout-button").append("<input type='hidden' name='callid' id='callid' />"); 89 // setTimeout(initVisaCheckout, 500); 90 // } -
woocommerce-fat-zebra-gateway/trunk/readme.txt
r1024839 r1024852 107 107 * Fixed issue with redirect upon successful payment 108 108 109 = 1. 4.5=109 = 1.5.0 = 110 110 * Added support for Direct Post tokenization, sending the card details directly to Fat Zebra instead of via the merchants web server 111 111 * Added support for Visa Checkout as payment option
Note: See TracChangeset
for help on using the changeset viewer.