WordPress.org

Plugin Directory

Changeset 1699076


Ignore:
Timestamp:
07/19/17 16:31:00 (4 months ago)
Author:
bor0
Message:

Update trunk to version 1.4.2

Location:
woocommerce-gateway-paypal-express-checkout/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • woocommerce-gateway-paypal-express-checkout/trunk/includes/class-wc-gateway-ppec-admin-handler.php

    r1673238 r1699076  
    168168                    $order->add_order_note( __( 'Unable to capture charge!', 'woocommerce-gateway-paypal-express-checkout' ) . ' ' . $result->get_error_message() ); 
    169169                } else { 
     170                    update_post_meta( $order_id, '_paypal_status', ! empty( $trans_details['PAYMENTSTATUS'] ) ? $trans_details['PAYMENTSTATUS'] : 'completed' ); 
    170171                    $order->add_order_note( sprintf( __( 'PayPal Express Checkout charge complete (Charge ID: %s)', 'woocommerce-gateway-paypal-express-checkout' ), $trans_id ) ); 
    171172                } 
  • woocommerce-gateway-paypal-express-checkout/trunk/includes/class-wc-gateway-ppec-checkout-handler.php

    r1687057 r1699076  
    828828        // Store meta data to order 
    829829        $old_wc = version_compare( WC_VERSION, '3.0', '<' ); 
    830         if ( $old_wc ) { 
    831             update_post_meta( $order->id, '_paypal_status', strtolower( $payment->payment_status ) ); 
    832         } else { 
    833             $order->update_meta_data( '_paypal_status', strtolower( $payment->payment_status ) ); 
    834         } 
    835  
     830 
     831        update_post_meta( $old_wc ? $order->id : $order->get_id(), '_paypal_status', strtolower( $payment->payment_status ) ); 
    836832        update_post_meta( $old_wc ? $order->id : $order->get_id(), '_transaction_id', $payment->transaction_id ); 
    837833 
  • woocommerce-gateway-paypal-express-checkout/trunk/includes/class-wc-gateway-ppec-client.php

    r1687057 r1699076  
    449449 
    450450        $decimals      = $settings->get_number_of_decimal_digits(); 
    451         $discounts     = round( WC()->cart->get_cart_discount_total(), $decimals ); 
    452451        $rounded_total = $this->_get_rounded_total_in_cart(); 
     452        $discounts     = WC()->cart->get_cart_discount_total(); 
    453453 
    454454        $details = array( 
     
    458458            'items'             => $this->_get_paypal_line_items_from_cart(), 
    459459        ); 
     460 
     461        return $this->get_details( $details, $discounts, $rounded_total, WC()->cart->total ); 
     462    } 
     463 
     464    /** 
     465     * Get line items from cart contents. 
     466     * 
     467     * @since 1.2.0 
     468     * 
     469     * @return array Line items 
     470     */ 
     471    protected function _get_paypal_line_items_from_cart() { 
     472        $settings = wc_gateway_ppec()->settings; 
     473        $decimals = $settings->get_number_of_decimal_digits(); 
     474 
     475        $items = array(); 
     476        foreach ( WC()->cart->cart_contents as $cart_item_key => $values ) { 
     477            $amount = round( $values['line_subtotal'] / $values['quantity'] , $decimals ); 
     478 
     479            if ( version_compare( WC_VERSION, '3.0', '<' ) ) { 
     480                $name = $values['data']->post->post_title; 
     481                $description = $values['data']->post->post_content; 
     482            } else { 
     483                $product = $values['data']; 
     484                $name = $product->get_name(); 
     485                $description = $product->get_description(); 
     486            } 
     487 
     488            $item   = array( 
     489                'name'        => $name, 
     490                'description' => $description, 
     491                'quantity'    => $values['quantity'], 
     492                'amount'      => $amount, 
     493            ); 
     494 
     495            $items[] = $item; 
     496        } 
     497 
     498        return $items; 
     499    } 
     500 
     501    /** 
     502     * Get rounded total of items in cart. 
     503     * 
     504     * @since 1.2.0 
     505     * 
     506     * @return float Rounded total in cart 
     507     */ 
     508    protected function _get_rounded_total_in_cart() { 
     509        $settings = wc_gateway_ppec()->settings; 
     510        $decimals = $settings->get_number_of_decimal_digits(); 
     511 
     512        $rounded_total = 0; 
     513        foreach ( WC()->cart->cart_contents as $cart_item_key => $values ) { 
     514            $amount         = round( $values['line_subtotal'] / $values['quantity'] , $decimals ); 
     515            $rounded_total += round( $amount * $values['quantity'], $decimals ); 
     516        } 
     517 
     518        return $rounded_total; 
     519    } 
     520 
     521    /** 
     522     * Get details from populated price array 
     523     * 
     524     * @since 1.4.1 
     525     * 
     526     * @param array $details Prices 
     527     * 
     528     * @return array Details 
     529     */ 
     530    protected function get_details( $details, $discounts, $rounded_total, $total ) { 
     531        $settings = wc_gateway_ppec()->settings; 
     532        $decimals = $settings->get_number_of_decimal_digits(); 
     533 
     534        $discounts = round( $discounts, $decimals ); 
    460535 
    461536        $details['order_total'] = round( 
     
    491566            // Omit line items altogether. 
    492567            unset( $details['items'] ); 
    493             $details['ship_discount_amount'] = 0; 
    494             $details['total_item_amount']   -= $discounts; 
    495             $details['order_total']         -= $discounts; 
    496         } else { 
    497             if ( $discounts > 0 ) { 
    498                 $details['items'][] = $this->_get_extra_offset_line_item( - abs( $discounts ) ); 
    499             } 
    500  
    501             $details['ship_discount_amount'] = 0; 
    502             $details['total_item_amount']   -= $discounts; 
    503             $details['order_total']         -= $discounts; 
    504         } 
     568        } 
     569 
     570        $details['ship_discount_amount'] = 0; 
     571 
     572        // AMT 
     573        $details['order_total']       = $details['order_total'] - $discounts; 
     574 
     575        // ITEMAMT 
     576        $details['total_item_amount'] = $details['total_item_amount'] - $discounts; 
    505577 
    506578        // If the totals don't line up, adjust the tax to make it work (it's 
    507579        // probably a tax mismatch). 
    508         $wc_order_total = round( WC()->cart->total, $decimals ); 
    509         if ( $wc_order_total != $details['order_total'] ) { 
     580        $wc_order_total = round( $total, $decimals ); 
     581        $discounted_total = $details['order_total']; 
     582 
     583        if ( $wc_order_total != $discounted_total ) { 
    510584            // tax cannot be negative 
    511             if ( $details['order_total'] < $wc_order_total ) { 
    512                 $details['order_tax'] += $wc_order_total - $details['order_total']; 
     585            if ( $discounted_total < $wc_order_total ) { 
     586                $details['order_tax'] += $wc_order_total - $discounted_total; 
    513587                $details['order_tax'] = round( $details['order_tax'], $decimals ); 
    514588            } else { 
    515                 $details['ship_discount_amount'] += $wc_order_total - $details['order_total']; 
     589                $details['ship_discount_amount'] += $wc_order_total - $discounted_total; 
    516590                $details['ship_discount_amount'] = round( $details['ship_discount_amount'], $decimals ); 
    517591            } 
     
    524598        } 
    525599 
     600        $lisum = 0; 
     601 
     602        foreach ( $details['items'] as $li => $values ) { 
     603            $lisum += $values['quantity'] * $values['amount']; 
     604        } 
     605 
     606        if ( 0 !== $lisum ) { 
     607            $details['items'][] = $this->_get_extra_offset_line_item( $details['total_item_amount'] - $lisum ); 
     608        } 
     609 
    526610        return $details; 
    527     } 
    528  
    529     /** 
    530      * Get line items from cart contents. 
    531      * 
    532      * @since 1.2.0 
    533      * 
    534      * @return array Line items 
    535      */ 
    536     protected function _get_paypal_line_items_from_cart() { 
    537         $settings = wc_gateway_ppec()->settings; 
    538         $decimals = $settings->get_number_of_decimal_digits(); 
    539  
    540         $items = array(); 
    541         foreach ( WC()->cart->cart_contents as $cart_item_key => $values ) { 
    542             $amount = round( $values['line_subtotal'] / $values['quantity'] , $decimals ); 
    543  
    544             if ( version_compare( WC_VERSION, '3.0', '<' ) ) { 
    545                 $name = $values['data']->post->post_title; 
    546                 $description = $values['data']->post->post_content; 
    547             } else { 
    548                 $product = $values['data']; 
    549                 $name = $product->get_name(); 
    550                 $description = $product->get_description(); 
    551             } 
    552  
    553             $item   = array( 
    554                 'name'        => $name, 
    555                 'description' => $description, 
    556                 'quantity'    => $values['quantity'], 
    557                 'amount'      => $amount, 
    558             ); 
    559  
    560             $items[] = $item; 
    561         } 
    562  
    563         return $items; 
    564     } 
    565  
    566     /** 
    567      * Get rounded total of items in cart. 
    568      * 
    569      * @since 1.2.0 
    570      * 
    571      * @return float Rounded total in cart 
    572      */ 
    573     protected function _get_rounded_total_in_cart() { 
    574         $settings = wc_gateway_ppec()->settings; 
    575         $decimals = $settings->get_number_of_decimal_digits(); 
    576  
    577         $rounded_total = 0; 
    578         foreach ( WC()->cart->cart_contents as $cart_item_key => $values ) { 
    579             $amount         = round( $values['line_subtotal'] / $values['quantity'] , $decimals ); 
    580             $rounded_total += round( $amount * $values['quantity'], $decimals ); 
    581         } 
    582  
    583         return $rounded_total; 
    584611    } 
    585612 
     
    600627 
    601628        $decimals      = $settings->is_currency_supports_zero_decimal() ? 0 : 2; 
    602         $discounts     = round( $order->get_total_discount(), $decimals ); 
    603629        $rounded_total = $this->_get_rounded_total_in_order( $order ); 
     630        $discounts     = $order->get_total_discount(); 
    604631 
    605632        $details = array( 
     633            'total_item_amount' => round( $order->get_subtotal(), $decimals ) + $discounts, 
    606634            'order_tax'         => round( $order->get_total_tax(), $decimals ), 
    607635            'shipping'          => round( ( version_compare( WC_VERSION, '3.0', '<' ) ? $order->get_total_shipping() : $order->get_shipping_total() ), $decimals ), 
    608             'total_item_amount' => round( $order->get_subtotal(), $decimals ), 
    609636            'items'             => $this->_get_paypal_line_items_from_order( $order ), 
    610637        ); 
    611638 
    612         $details['order_total'] = round( $details['total_item_amount'] + $details['order_tax'] + $details['shipping'], $decimals ); 
    613  
    614         // Compare WC totals with what PayPal will calculate to see if they match. 
    615         // if they do not match, check to see what the merchant would like to do. 
    616         // Options are to remove line items or add a line item to adjust for 
    617         // the difference. 
    618         if ( $details['total_item_amount'] != $rounded_total ) { 
    619             if ( 'add' === $settings->get_subtotal_mismatch_behavior() ) { 
    620                 // Add line item to make up different between WooCommerce 
    621                 // calculations and PayPal calculations. 
    622                 $diff = round( $details['total_item_amount'] - $rounded_total, $decimals ); 
    623  
    624                 $details['items'][] = $this->_get_extra_offset_line_item( $diff ); 
    625  
    626             } else { 
    627                 // Omit line items altogether. 
    628                 unset( $details['items'] ); 
    629             } 
    630         } 
    631  
    632         // Enter discount shenanigans. Item total cannot be 0 so make modifications 
    633         // accordingly. 
    634         if ( $details['total_item_amount'] == $discounts ) { 
    635             // Omit line items altogether. 
    636             unset( $details['items'] ); 
    637             $details['ship_discount_amount'] = 0; 
    638             $details['total_item_amount']   -= $discounts; 
    639             $details['order_total']         -= $discounts; 
    640         } else { 
    641             if ( $discounts > 0 ) { 
    642                 $details['items'][] = $this->_get_extra_discount_line_item( $discounts ); 
    643  
    644                 $details['total_item_amount'] -= $discounts; 
    645                 $details['order_total']       -= $discounts; 
    646             } 
    647  
    648             $details['ship_discount_amount'] = 0; 
    649         } 
    650  
    651         // If the totals don't line up, adjust the tax to make it work (it's 
    652         // probably a tax mismatch). 
    653         $wc_order_total = round( $order->get_total(), $decimals ); 
    654         if ( $wc_order_total != $details['order_total'] ) { 
    655             // tax cannot be negative 
    656             if ( $details['order_total'] < $wc_order_total ) { 
    657                 $details['order_tax'] += $wc_order_total - $details['order_total']; 
    658                 $details['order_tax'] = round( $details['order_tax'], $decimals ); 
    659             } else { 
    660                 $details['ship_discount_amount'] += $wc_order_total - $details['order_total']; 
    661                 $details['ship_discount_amount'] = round( $details['ship_discount_amount'], $decimals ); 
    662             } 
    663  
    664             $details['order_total'] = $wc_order_total; 
    665         } 
    666  
    667         if ( ! is_numeric( $details['shipping'] ) ) { 
    668             $details['shipping'] = 0; 
    669         } 
     639        $details = $this->get_details( $details, $order->get_total_discount(), $rounded_total, $order->get_total() ); 
    670640 
    671641        // PayPal shipping address from order. 
  • woocommerce-gateway-paypal-express-checkout/trunk/includes/class-wc-gateway-ppec-plugin.php

    r1687057 r1699076  
    375375 
    376376    /** 
    377      * Check if shipping is needed for PayPal. 
     377     * Check if shipping is needed for PayPal. This only checks for virtual products (#286), 
     378     * but skips the check if there are no shipping methods enabled (#249). 
    378379     * 
    379380     * @since 1.4.1 
     
    383384     */ 
    384385    public static function needs_shipping() { 
    385         // In case there are no shipping methods defined, we still return true (see #249) 
    386         if ( ! wc_shipping_enabled() || 0 === wc_get_shipping_method_count( true ) ) { 
    387             return true; 
    388         } 
    389  
    390         // Otherwise go through all items and see if they require shipping (e.g. virtual items will not, see #286) 
    391         return WC()->cart->needs_shipping(); 
     386        $cart_contents  = WC()->cart->cart_contents; 
     387        $needs_shipping = false; 
     388 
     389        if ( ! empty( $cart_contents ) ) { 
     390            foreach ( $cart_contents as $cart_item_key => $values ) { 
     391                if ( $values['data']->needs_shipping() ) { 
     392                    $needs_shipping = true; 
     393                    break; 
     394                } 
     395            } 
     396        } 
     397 
     398        return apply_filters( 'woocommerce_cart_needs_shipping', $needs_shipping ); 
    392399    } 
    393400} 
  • woocommerce-gateway-paypal-express-checkout/trunk/readme.txt

    r1687057 r1699076  
    44Requires at least: 4.4 
    55Tested up to: 4.7 
    6 Stable tag: 1.4.1 
     6Stable tag: 1.4.2 
    77License: GPLv3 
    88License URI: http://www.gnu.org/licenses/gpl-3.0.html 
     
    8585 
    8686== Changelog == 
     87 
     88= 1.4.2 = 
     89* Fix   - _paypal_status on Authorize transactions not updating to processing after capture. 
     90* Fix   - 10413 (The totals of the cart item amounts do not match order amounts) error with discounts. 
     91* Fix   - Shipping Address being required on Virtual products. 
    8792 
    8893= 1.4.1 = 
  • woocommerce-gateway-paypal-express-checkout/trunk/woocommerce-gateway-paypal-express-checkout.php

    r1687057 r1699076  
    44 * Plugin URI: https://woocommerce.com/products/woocommerce-gateway-paypal-express-checkout/ 
    55 * Description: A payment gateway for PayPal Express Checkout (https://www.paypal.com/us/webapps/mpp/express-checkout). 
    6  * Version: 1.4.1 
     6 * Version: 1.4.2 
    77 * Author: WooCommerce 
    88 * Author URI: https://woocommerce.com 
     
    2626} 
    2727 
    28 define( 'WC_GATEWAY_PPEC_VERSION', '1.4.1' ); 
     28define( 'WC_GATEWAY_PPEC_VERSION', '1.4.2' ); 
    2929 
    3030/** 
Note: See TracChangeset for help on using the changeset viewer.