diff --git a/includes/class-wc-gateway-ppec-address.php b/includes/class-wc-gateway-ppec-address.php index d9f63738..4a24496f 100644 --- a/includes/class-wc-gateway-ppec-address.php +++ b/includes/class-wc-gateway-ppec-address.php @@ -654,7 +654,8 @@ public function getAddressParams( $prefix = '' ) { $prefix . 'CITY' => $this->_city, $prefix . 'STATE' => $this->_state, $prefix . 'ZIP' => $this->_zip, - $prefix . 'COUNTRYCODE' => $this->_country + $prefix . 'COUNTRYCODE' => $this->_country, + $prefix . 'PHONENUM' => $this->_phoneNumber, ); return $params; diff --git a/includes/class-wc-gateway-ppec-cart-handler.php b/includes/class-wc-gateway-ppec-cart-handler.php index 1a63a6f5..37665c4e 100644 --- a/includes/class-wc-gateway-ppec-cart-handler.php +++ b/includes/class-wc-gateway-ppec-cart-handler.php @@ -194,59 +194,70 @@ protected function set_customer_data( $data ) { $billing_first_name = empty( $data[ 'billing_first_name' ] ) ? '' : wc_clean( $data[ 'billing_first_name' ] ); $billing_last_name = empty( $data[ 'billing_last_name' ] ) ? '' : wc_clean( $data[ 'billing_last_name' ] ); + $billing_country = empty( $data[ 'billing_country' ] ) ? '' : wc_clean( $data[ 'billing_country' ] ); $billing_address_1 = empty( $data[ 'billing_address_1' ] ) ? '' : wc_clean( $data[ 'billing_address_1' ] ); $billing_address_2 = empty( $data[ 'billing_address_2' ] ) ? '' : wc_clean( $data[ 'billing_address_2' ] ); $billing_city = empty( $data[ 'billing_city' ] ) ? '' : wc_clean( $data[ 'billing_city' ] ); $billing_state = empty( $data[ 'billing_state' ] ) ? '' : wc_clean( $data[ 'billing_state' ] ); $billing_postcode = empty( $data[ 'billing_postcode' ] ) ? '' : wc_clean( $data[ 'billing_postcode' ] ); - $billing_country = empty( $data[ 'billing_country' ] ) ? '' : wc_clean( $data[ 'billing_country' ] ); + $billing_phone = empty( $data[ 'billing_phone' ] ) ? '' : wc_clean( $data[ 'billing_phone' ] ); + $billing_email = empty( $data[ 'billing_email' ] ) ? '' : wc_clean( $data[ 'billing_email' ] ); if ( isset( $data['ship_to_different_address'] ) ) { $shipping_first_name = empty( $data[ 'shipping_first_name' ] ) ? '' : wc_clean( $data[ 'shipping_first_name' ] ); $shipping_last_name = empty( $data[ 'shipping_last_name' ] ) ? '' : wc_clean( $data[ 'shipping_last_name' ] ); + $shipping_country = empty( $data[ 'shipping_country' ] ) ? '' : wc_clean( $data[ 'shipping_country' ] ); $shipping_address_1 = empty( $data[ 'shipping_address_1' ] ) ? '' : wc_clean( $data[ 'shipping_address_1' ] ); $shipping_address_2 = empty( $data[ 'shipping_address_2' ] ) ? '' : wc_clean( $data[ 'shipping_address_2' ] ); $shipping_city = empty( $data[ 'shipping_city' ] ) ? '' : wc_clean( $data[ 'shipping_city' ] ); $shipping_state = empty( $data[ 'shipping_state' ] ) ? '' : wc_clean( $data[ 'shipping_state' ] ); $shipping_postcode = empty( $data[ 'shipping_postcode' ] ) ? '' : wc_clean( $data[ 'shipping_postcode' ] ); - $shipping_country = empty( $data[ 'shipping_country' ] ) ? '' : wc_clean( $data[ 'shipping_country' ] ); } else { $shipping_first_name = $billing_first_name; $shipping_last_name = $billing_last_name; + $shipping_country = $billing_country; $shipping_address_1 = $billing_address_1; $shipping_address_2 = $billing_address_2; $shipping_city = $billing_city; $shipping_state = $billing_state; $shipping_postcode = $billing_postcode; - $shipping_country = $billing_country; } + $customer->set_shipping_country( $shipping_country ); $customer->set_shipping_address( $shipping_address_1 ); $customer->set_shipping_address_2( $shipping_address_2 ); $customer->set_shipping_city( $shipping_city ); $customer->set_shipping_state( $shipping_state ); $customer->set_shipping_postcode( $shipping_postcode ); - $customer->set_shipping_country( $shipping_country ); if ( version_compare( WC_VERSION, '3.0', '<' ) ) { + $customer->shipping_first_name = $shipping_first_name; + $customer->shipping_last_name = $shipping_last_name; + $customer->billing_first_name = $billing_first_name; + $customer->billing_last_name = $billing_last_name; + + $customer->set_country( $billing_country ); $customer->set_address( $billing_address_1 ); $customer->set_address_2( $billing_address_2 ); $customer->set_city( $billing_city ); $customer->set_state( $billing_state ); $customer->set_postcode( $billing_postcode ); - $customer->set_country( $billing_country ); + $customer->billing_phone = $billing_phone; + $customer->billing_email = $billing_email; } else { $customer->set_shipping_first_name( $shipping_first_name ); $customer->set_shipping_last_name( $shipping_last_name ); $customer->set_billing_first_name( $billing_first_name ); $customer->set_billing_last_name( $billing_last_name ); + $customer->set_billing_country( $billing_country ); $customer->set_billing_address_1( $billing_address_1 ); $customer->set_billing_address_2( $billing_address_2 ); $customer->set_billing_city( $billing_city ); $customer->set_billing_state( $billing_state ); $customer->set_billing_postcode( $billing_postcode ); - $customer->set_billing_country( $billing_country ); + $customer->set_billing_phone( $billing_phone ); + $customer->set_billing_email( $billing_email ); } } diff --git a/includes/class-wc-gateway-ppec-client.php b/includes/class-wc-gateway-ppec-client.php index 9755e74d..ca53bbbc 100644 --- a/includes/class-wc-gateway-ppec-client.php +++ b/includes/class-wc-gateway-ppec-client.php @@ -307,6 +307,10 @@ public function get_set_express_checkout_params( array $args ) { ) ); + if ( ! empty( $details['email'] ) ) { + $params['EMAIL'] = $details['email']; + } + if ( $args['create_billing_agreement'] ) { $params['L_BILLINGTYPE0'] = 'MerchantInitiatedBillingSingleAgreement'; $params['L_BILLINGAGREEMENTDESCRIPTION0'] = $this->_get_billing_agreement_description(); @@ -449,6 +453,7 @@ protected function _get_extra_discount_line_item( $amount ) { */ protected function _get_details_from_cart() { $settings = wc_gateway_ppec()->settings; + $old_wc = version_compare( WC_VERSION, '3.0', '<' ); $decimals = $settings->get_number_of_decimal_digits(); $rounded_total = $this->_get_rounded_total_in_cart(); @@ -460,6 +465,7 @@ protected function _get_details_from_cart() { 'shipping' => round( WC()->cart->shipping_total, $decimals ), 'items' => $this->_get_paypal_line_items_from_cart(), 'shipping_address' => $this->_get_address_from_customer(), + 'email' => $old_wc ? WC()->customer->billing_email : WC()->customer->get_billing_email(), ); return $this->get_details( $details, $discounts, $rounded_total, WC()->cart->total ); @@ -703,8 +709,12 @@ protected function _get_details_from_order( $order_id ) { } $shipping_address->setCountry( $shipping_country ); + $shipping_address->setPhoneNumber( $old_wc ? $order->billing_phone : $order->get_billing_phone() ); + $details['shipping_address'] = $shipping_address; + $details['email'] = $old_wc ? $order->billing_email : $order->get_billing_email(); + return $details; } @@ -721,8 +731,8 @@ protected function _get_address_from_customer() { $old_wc = version_compare( WC_VERSION, '3.0', '<' ); if ( $customer->get_shipping_address() || $customer->get_shipping_address_2() ) { - $shipping_first_name = $old_wc ? '' : $customer->get_shipping_first_name(); - $shipping_last_name = $old_wc ? '' : $customer->get_shipping_last_name(); + $shipping_first_name = $old_wc ? $customer->shipping_first_name : $customer->get_shipping_first_name(); + $shipping_last_name = $old_wc ? $customer->shipping_last_name : $customer->get_shipping_last_name(); $shipping_address_1 = $customer->get_shipping_address(); $shipping_address_2 = $customer->get_shipping_address_2(); $shipping_city = $customer->get_shipping_city(); @@ -732,14 +742,14 @@ protected function _get_address_from_customer() { } else { // Fallback to billing in case no shipping methods are set. The address returned from PayPal // will be stored in the order as billing. - $shipping_first_name = $old_wc ? '' : $customer->get_billing_first_name(); - $shipping_last_name = $old_wc ? '' : $customer->get_billing_last_name(); - $shipping_address_1 = $old_wc ? $customer->get_address() : $customer->get_billing_address_1(); - $shipping_address_2 = $old_wc ? $customer->get_address_2() : $customer->get_billing_address_2(); - $shipping_city = $old_wc ? $customer->get_city() : $customer->get_billing_city(); - $shipping_state = $old_wc ? $customer->get_state() : $customer->get_billing_state(); - $shipping_postcode = $old_wc ? $customer->get_postcode() : $customer->get_billing_postcode(); - $shipping_country = $old_wc ? $customer->get_country() : $customer->get_billing_country(); + $shipping_first_name = $old_wc ? $customer->billing_first_name : $customer->get_billing_first_name(); + $shipping_last_name = $old_wc ? $customer->billing_last_name : $customer->get_billing_last_name(); + $shipping_address_1 = $old_wc ? $customer->get_address() : $customer->get_billing_address_1(); + $shipping_address_2 = $old_wc ? $customer->get_address_2() : $customer->get_billing_address_2(); + $shipping_city = $old_wc ? $customer->get_city() : $customer->get_billing_city(); + $shipping_state = $old_wc ? $customer->get_state() : $customer->get_billing_state(); + $shipping_postcode = $old_wc ? $customer->get_postcode() : $customer->get_billing_postcode(); + $shipping_country = $old_wc ? $customer->get_country() : $customer->get_billing_country(); } $shipping_address->setName( $shipping_first_name . ' ' . $shipping_last_name ); @@ -749,6 +759,7 @@ protected function _get_address_from_customer() { $shipping_address->setState( $shipping_state ); $shipping_address->setZip( $shipping_postcode ); $shipping_address->setCountry( $shipping_country ); + $shipping_address->setPhoneNumber( $old_wc ? $customer->billing_phone : $customer->get_billing_phone() ); return $shipping_address; }