From b49b0b01336c614e43350aa2b7428ede4d009559 Mon Sep 17 00:00:00 2001 From: roykho Date: Mon, 9 Nov 2015 15:36:52 -0800 Subject: [PATCH 1/2] Fix - address fields were not properly being passed to Simplify via token --- .../assets/js/simplify-commerce.js | 22 +++++++++++++++---- .../assets/js/simplify-commerce.min.js | 2 +- ...ss-wc-addons-gateway-simplify-commerce.php | 16 ++------------ .../class-wc-gateway-simplify-commerce.php | 8 +------ 4 files changed, 22 insertions(+), 26 deletions(-) diff --git a/includes/gateways/simplify-commerce/assets/js/simplify-commerce.js b/includes/gateways/simplify-commerce/assets/js/simplify-commerce.js index 93589952438..84076254c8a 100644 --- a/includes/gateways/simplify-commerce/assets/js/simplify-commerce.js +++ b/includes/gateways/simplify-commerce/assets/js/simplify-commerce.js @@ -17,9 +17,16 @@ } }); - var card = $( '#simplify_commerce-card-number' ).val(), - cvc = $( '#simplify_commerce-card-cvc' ).val(), - expiry = $.payment.cardExpiryVal( $( '#simplify_commerce-card-expiry' ).val() ); + var card = $( '#simplify_commerce-card-number' ).val(), + cvc = $( '#simplify_commerce-card-cvc' ).val(), + expiry = $.payment.cardExpiryVal( $( '#simplify_commerce-card-expiry' ).val() ), + address1 = $form.find( '#billing_address_1' ).val(), + address2 = $form.find( '#billing_address_2' ).val(), + addressCountry = $form.find( '#billing_country' ).val(), + addressState = $form.find( '#billing_state' ).val(), + addressCity = $form.find( '#billing_city' ).val(), + addressZip = $form.find( '#billing_postcode' ).val(), + name = $form.find( '#billing_first_name' ).val() + ' ' + $form.find( '#billing_last_name' ).val(); card = card.replace( /\s/g, '' ); @@ -29,7 +36,14 @@ number: card, cvc: cvc, expMonth: expiry.month, - expYear: ( expiry.year - 2000 ) + expYear: ( expiry.year - 2000 ), + addressLine1: address1, + addressLine2: address2, + addressCountry: addressCountry, + addressState: addressState, + addressZip: addressZip, + addressCity: addressCity, + name: name } }, simplifyResponseHandler ); diff --git a/includes/gateways/simplify-commerce/assets/js/simplify-commerce.min.js b/includes/gateways/simplify-commerce/assets/js/simplify-commerce.min.js index 404ac81e6b8..4b474ae0c1c 100644 --- a/includes/gateways/simplify-commerce/assets/js/simplify-commerce.min.js +++ b/includes/gateways/simplify-commerce/assets/js/simplify-commerce.min.js @@ -1 +1 @@ -!function(a){function b(){var b=a("form.checkout, form#order_review");if(a("#payment_method_simplify_commerce").is(":checked")&&0===a("input.simplify-token").size()){b.block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var d=a("#simplify_commerce-card-number").val(),e=a("#simplify_commerce-card-cvc").val(),f=a.payment.cardExpiryVal(a("#simplify_commerce-card-expiry").val());return d=d.replace(/\s/g,""),SimplifyCommerce.generateToken({key:Simplify_commerce_params.key,card:{number:d,cvc:e,expMonth:f.month,expYear:f.year-2e3}},c),!1}return!0}function c(b){var c=a("form.checkout, form#order_review"),d=a("#simplify_commerce-cc-form");if(b.error){if(a(".woocommerce-error, .simplify-token",d).remove(),c.unblock(),"validation"===b.error.code){for(var e=b.error.fieldErrors,f=e.length,g="",h=0;f>h;h++)g+="
  • "+Simplify_commerce_params[e[h].field]+" "+Simplify_commerce_params.is_invalid+" - "+e[h].message+".
  • ";d.prepend('")}}else d.append(''),c.submit()}a(function(){a(document.body).on("checkout_error",function(){a(".simplify-token").remove()}),a("form.checkout").on("checkout_place_order_simplify_commerce",function(){return b()}),a("form#order_review").on("submit",function(){return b()}),a("form.checkout, form#order_review").on("change","#simplify_commerce-cc-form input",function(){a(".simplify-token").remove()})})}(jQuery); \ No newline at end of file +!function(e){function r(){var r=e("form.checkout, form#order_review");if(e("#payment_method_simplify_commerce").is(":checked")&&0===e("input.simplify-token").size()){r.block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var o=e("#simplify_commerce-card-number").val(),n=e("#simplify_commerce-card-cvc").val(),c=e.payment.cardExpiryVal(e("#simplify_commerce-card-expiry").val()),m=r.find("#billing_address_1").val(),l=r.find("#billing_address_2").val(),a=r.find("#billing_country").val(),f=r.find("#billing_state").val(),s=r.find("#billing_city").val(),t=r.find("#billing_postcode").val(),d=r.find("#billing_first_name").val()+" "+r.find("#billing_last_name").val();return o=o.replace(/\s/g,""),SimplifyCommerce.generateToken({key:Simplify_commerce_params.key,card:{number:o,cvc:n,expMonth:c.month,expYear:c.year-2e3,addressLine1:m,addressLine2:l,addressCountry:a,addressState:f,addressZip:t,addressCity:s,name:d}},i),!1}return!0}function i(r){var i=e("form.checkout, form#order_review"),o=e("#simplify_commerce-cc-form");if(r.error){if(e(".woocommerce-error, .simplify-token",o).remove(),i.unblock(),"validation"===r.error.code){for(var n=r.error.fieldErrors,c=n.length,m="",l=0;c>l;l++)m+="
  • "+Simplify_commerce_params[n[l].field]+" "+Simplify_commerce_params.is_invalid+" - "+n[l].message+".
  • ";o.prepend('")}}else o.append(''),i.submit()}e(function(){e(document.body).on("checkout_error",function(){e(".simplify-token").remove()}),e("form.checkout").on("checkout_place_order_simplify_commerce",function(){return r()}),e("form#order_review").on("submit",function(){return r()}),e("form.checkout, form#order_review").on("change","#simplify_commerce-cc-form input",function(){e(".simplify-token").remove()})})}(jQuery); \ No newline at end of file diff --git a/includes/gateways/simplify-commerce/class-wc-addons-gateway-simplify-commerce.php b/includes/gateways/simplify-commerce/class-wc-addons-gateway-simplify-commerce.php index 521288fb985..1d79201ef5a 100644 --- a/includes/gateways/simplify-commerce/class-wc-addons-gateway-simplify-commerce.php +++ b/includes/gateways/simplify-commerce/class-wc-addons-gateway-simplify-commerce.php @@ -304,13 +304,7 @@ class WC_Addons_Gateway_Simplify_Commerce extends WC_Gateway_Simplify_Commerce { 'customer' => $customer_id, 'description' => sprintf( __( '%s - Order #%s', 'woocommerce' ), esc_html( get_bloginfo( 'name', 'display' ) ), $order->get_order_number() ), 'currency' => strtoupper( get_woocommerce_currency() ), - 'reference' => $order->id, - 'card.addressCity' => $order->billing_city, - 'card.addressCountry' => $order->billing_country, - 'card.addressLine1' => $order->billing_address_1, - 'card.addressLine2' => $order->billing_address_2, - 'card.addressState' => $order->billing_state, - 'card.addressZip' => $order->billing_postcode + 'reference' => $order->id ) ); } catch ( Exception $e ) { @@ -445,13 +439,7 @@ class WC_Addons_Gateway_Simplify_Commerce extends WC_Gateway_Simplify_Commerce { 'customer' => $customer_id, 'description' => trim( substr( $pre_order_name, 0, 1024 ) ), 'currency' => strtoupper( get_woocommerce_currency() ), - 'reference' => $order->id, - 'card.addressCity' => $order->billing_city, - 'card.addressCountry' => $order->billing_country, - 'card.addressLine1' => $order->billing_address_1, - 'card.addressLine2' => $order->billing_address_2, - 'card.addressState' => $order->billing_state, - 'card.addressZip' => $order->billing_postcode + 'reference' => $order->id ) ); if ( 'APPROVED' == $payment->paymentStatus ) { diff --git a/includes/gateways/simplify-commerce/class-wc-gateway-simplify-commerce.php b/includes/gateways/simplify-commerce/class-wc-gateway-simplify-commerce.php index 3e79c69370b..fa190b4a9c8 100644 --- a/includes/gateways/simplify-commerce/class-wc-gateway-simplify-commerce.php +++ b/includes/gateways/simplify-commerce/class-wc-gateway-simplify-commerce.php @@ -327,13 +327,7 @@ class WC_Gateway_Simplify_Commerce extends WC_Payment_Gateway { 'token' => $cart_token, 'description' => sprintf( __( '%s - Order #%s', 'woocommerce' ), esc_html( get_bloginfo( 'name', 'display' ) ), $order->get_order_number() ), 'currency' => strtoupper( get_woocommerce_currency() ), - 'reference' => $order->id, - 'card.addressCity' => $order->billing_city, - 'card.addressCountry' => $order->billing_country, - 'card.addressLine1' => $order->billing_address_1, - 'card.addressLine2' => $order->billing_address_2, - 'card.addressState' => $order->billing_state, - 'card.addressZip' => $order->billing_postcode + 'reference' => $order->id ) ); $order_complete = $this->process_order_status( $order, $payment->id, $payment->paymentStatus, $payment->authCode ); From 84436f4a11e398b246098cf11731c389cf99f383 Mon Sep 17 00:00:00 2001 From: roykho Date: Mon, 9 Nov 2015 16:37:55 -0800 Subject: [PATCH 2/2] Fix hosted payments address fields were not passing to simplify --- .../class-wc-gateway-simplify-commerce.php | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/includes/gateways/simplify-commerce/class-wc-gateway-simplify-commerce.php b/includes/gateways/simplify-commerce/class-wc-gateway-simplify-commerce.php index fa190b4a9c8..996c96eeb7c 100644 --- a/includes/gateways/simplify-commerce/class-wc-gateway-simplify-commerce.php +++ b/includes/gateways/simplify-commerce/class-wc-gateway-simplify-commerce.php @@ -398,14 +398,19 @@ class WC_Gateway_Simplify_Commerce extends WC_Payment_Gateway { */ protected function get_hosted_payments_args( $order ) { $args = apply_filters( 'woocommerce_simplify_commerce_hosted_args', array( - 'sc-key' => $this->public_key, - 'amount' => $order->order_total * 100, - 'reference' => $order->id, - 'name' => esc_html( get_bloginfo( 'name', 'display' ) ), - 'description' => sprintf( __( 'Order #%s', 'woocommerce' ), $order->get_order_number() ), - 'receipt' => 'false', - 'color' => $this->modal_color, - 'redirect-url' => WC()->api_request_url( 'WC_Gateway_Simplify_Commerce' ) + 'sc-key' => $this->public_key, + 'amount' => $order->order_total * 100, + 'reference' => $order->id, + 'name' => esc_html( get_bloginfo( 'name', 'display' ) ), + 'description' => sprintf( __( 'Order #%s', 'woocommerce' ), $order->get_order_number() ), + 'receipt' => 'false', + 'color' => $this->modal_color, + 'redirect-url' => WC()->api_request_url( 'WC_Gateway_Simplify_Commerce' ), + 'address' => $order->billing_address_1 . ' ' . $order->billing_address_2, + 'address-city' => $order->billing_city, + 'address-state' => $order->billing_state, + 'address-zip' => $order->billing_postcode, + 'address-country' => $order->billing_country ), $order->id ); return $args;