Plugin Directory

Changeset 1409404


Ignore:
Timestamp:
05/03/2016 07:44:07 AM (10 years ago)
Author:
akeda
Message:

Preparing for 1.0.1 release

Location:
woocommerce-gateway-paypal-express-checkout/trunk
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • woocommerce-gateway-paypal-express-checkout/trunk/includes/abstracts/abstract-wc-gateway-ppec-client-credential.php

    r1384111 r1409404  
    9696     *               from this object.
    9797     */
    98     protected function get_request_params() {
     98    public function get_request_params() {
    9999        $params = array(
    100100            'USER' => $this->_username,
     
    108108        return $params;
    109109    }
     110
     111    /**
     112     * Allow certificate-based credential to configure cURL, especially
     113     * to set CURLOPT_SSLCERT and CURLOPT_SSLCERTPASSWD.
     114     *
     115     * @throws Exception
     116     *
     117     * @param resource &$handle The cURL handle returned by curl_init().
     118     * @param array    $r       The HTTP request arguments.
     119     * @param string   $url     The request URL.
     120     *
     121     * @return void
     122     */
     123    public function configure_curl( $handle, $r, $url ) {
     124        curl_setopt( $handle, CURLOPT_CAINFO, wc_gateway_ppec()->includes_path . 'pem/bundle.pem' );
     125        curl_setopt( $handle, CURLOPT_SSL_CIPHER_LIST, 'TLSv1' );
     126    }
    110127}
  • woocommerce-gateway-paypal-express-checkout/trunk/includes/abstracts/abstract-wc-gateway-ppec.php

    r1386055 r1409404  
    226226                }
    227227
    228                 $expires = sprintf( $out, date_i18n( get_option( 'date_format' ), $valid_until ) );
     228                $expires = sprintf( $expires, date_i18n( get_option( 'date_format' ), $valid_until ) );
    229229                $out = sprintf( __( 'Certificate belongs to API username %1$s; %2$s', 'woocommerce-gateway-paypal-express-checkout' ), $certinfo['subject']['CN'], $expires );
    230230            } else {
  • woocommerce-gateway-paypal-express-checkout/trunk/includes/class-wc-gateway-ppec-cart-handler.php

    r1384111 r1409404  
    160160        $discounts = round( WC()->cart->get_cart_discount_total(), $decimals );
    161161        foreach ( WC()->cart->cart_contents as $cart_item_key => $values ) {
    162             $amount = round( $values['line_total'] / $values['quantity'] , $decimals );
     162            $amount = round( $values['line_subtotal'] / $values['quantity'] , $decimals );
    163163            $item   = array(
    164164                'name'        => $values['data']->post->post_title,
     
    173173        }
    174174
    175         $this->orderTax = round( WC()->cart->tax_total, $decimals );
     175        $this->orderTax = round( WC()->cart->tax_total + WC()->cart->shipping_tax_total, $decimals );
    176176        $this->shipping = round( WC()->cart->shipping_total, $decimals );
    177         if ( WC()->cart->shipping_tax_total != 0 ) {
    178             $this->orderTax += round( WC()->cart->shipping_tax_total, $decimals );
    179         }
    180         $this->totalItemAmount = round( WC()->cart->cart_contents_total, $decimals );
     177        $this->totalItemAmount = round( WC()->cart->cart_contents_total, $decimals ) + $discounts;
    181178        $this->orderTotal = $this->totalItemAmount + $this->orderTax + $this->shipping;
    182179
     
    201198
    202199                $this->items[] = $modifyLineItem;
     200                $this->totalItemAmount += $modifyLineItem[ 'amount' ];
     201                $this->orderTotal += $modifyLineItem[ 'amount' ];
    203202
    204203            } elseif ( WC_Gateway_PPEC_Settings::subtotalMismatchBehaviorDropLineItems == $subtotalBehavior ) {
     
    212211        // enter discount shenanigans. item total cannot be 0 so make modifications accordingly
    213212        if ( $this->totalItemAmount == $discounts ) {
    214             $settings = wc_gateway_ppec()->loadSettings();
     213            $settings = wc_gateway_ppec()->settings->loadSettings();
    215214            $behavior = $settings->zeroSubtotalBehavior;
    216215
     
    223222                    'description' => 'Discount Amount',
    224223                    'quantity'    => 1,
    225                     'amount'      => $discounts
     224                    'amount'      => -$discounts
    226225                );
    227226
    228                 $this->items[] = $discountLineItme;
     227                $this->items[] = $discountLineItem;
    229228
    230229                if ( $is_zdp_currency ) {
     
    242241
    243242                $this->items[] = $modifyLineItem;
    244                 $this->shipDiscountAmount = $discount;
     243                $this->shipDiscountAmount = -$discount;
     244                $this->totalItemAmount = $this->totalItemAmount - $discounts + $discount;
     245                $this->orderTotal -= $discounts;
    245246
    246247            } elseif ( WC_Gateway_PPEC_Settings::zeroSubtotalBehaviorOmitLineItems == $behavior ) {
     
    249250                unset($this->items);
    250251                $this->shipDiscountAmount = 0;
     252                $this->totalItemAmount -= $discounts;
     253                $this->orderTotal -= $discounts;
    251254
    252255            } else {
    253256                // ...
    254257                // Increase SHIPDISCAMT by the amount of all the coupons in the cart
    255                 $this->shipDiscountAmount = round( WC()->cart->get_order_discount_total(), $decimals );
     258                $this->shipDiscountAmount = -$discounts;
     259                $this->orderTotal -= $discounts;
    256260
    257261            }
     
    270274
    271275            $this->shipDiscountAmount = 0;
     276            $this->totalItemAmount -= $discounts;
     277            $this->orderTotal -= $discounts;
     278        }
     279       
     280        // If the totals don't line up, adjust the tax to make it work (cause it's probably a tax mismatch).
     281        $wooOrderTotal = round( WC()->cart->total, $decimals );
     282        if( $wooOrderTotal != $this->orderTotal ) {
     283            $this->orderTax += $wooOrderTotal - $this->orderTotal;
     284            $this->orderTotal = $wooOrderTotal;
    272285        }
    273286
     
    281294        if ( ! is_numeric( $this->shipping ) )
    282295            $this->shipping = 0;
    283 
     296       
    284297    }
    285298
     
    302315        $discounts = round( $order->get_total_discount(), $decimals );
    303316        foreach ( $order->get_items() as $cart_item_key => $values ) {
    304             $amount = round( $values['line_total'] / $values['qty'] , $decimals );
     317            $amount = round( $values['line_subtotal'] / $values['qty'] , $decimals );
    305318            $item   = array(
    306319                'name'     => $values['name'],
     
    310323
    311324            $this->items[] = $item;
    312 
     325           
    313326            $roundedPayPalTotal += round( $amount * $values['qty'], $decimals );
    314327        }
     
    364377                    'description' => 'Discount Amount',
    365378                    'quantity'    => 1,
    366                     'amount'      => $discounts
     379                    'amount'      => -$discounts
    367380                );
    368381
    369                 $this->items[] = $discountLineItme;
     382                $this->items[] = $discountLineItem;
    370383
    371384                if ( $is_zdp_currency ) {
     
    383396
    384397                $this->items[] = $modifyLineItem;
    385                 $this->shipDiscountAmount = $discount;
     398                $this->shipDiscountAmount = -$discount;
     399                $this->totalItemAmount = $this->totalItemAmount - $discounts + $discount;
     400                $this->orderTotal -= $discounts;
    386401
    387402            } elseif ( WC_Gateway_PPEC_Settings::zeroSubtotalBehaviorOmitLineItems == $behavior ) {
     
    390405                unset($this->items);
    391406                $this->shipDiscountAmount = 0;
     407                $this->totalItemAmount -= $discounts;
     408                $this->orderTotal -= $discounts;
    392409
    393410            } else {
    394411                // ...
    395412                // Increase SHIPDISCAMT by the amount of all the coupons in the cart
    396                 $this->shipDiscountAmount = round( WC()->cart->get_order_discount_total(), $decimals );
    397 
     413                $this->shipDiscountAmount = -$discounts;
     414                $this->orderTotal -= $discounts;
    398415            }
    399416        } else {
     
    408425
    409426                $this->items[] = $discLineItem;
     427                $this->totalItemAmount -= $discounts;
     428                $this->orderTotal -= $discounts;
    410429            }
    411430
    412431            $this->shipDiscountAmount = 0;
     432        }
     433       
     434        // If the totals don't line up, adjust the tax to make it work (cause it's probably a tax mismatch).
     435        $wooOrderTotal = round( $order->get_total(), $decimals );
     436        if( $wooOrderTotal != $this->orderTotal ) {
     437            $this->orderTax += $wooOrderTotal - $this->orderTotal;
     438            $this->orderTotal = $wooOrderTotal;
    413439        }
    414440
  • woocommerce-gateway-paypal-express-checkout/trunk/includes/class-wc-gateway-ppec-client-credential-certificate.php

    r1384111 r1409404  
    4444        return $this->_certificate;
    4545    }
     46
     47    /**
     48     * Allow certificate-based credential to configure cURL, especially
     49     * to set CURLOPT_SSLCERT and CURLOPT_SSLCERTPASSWD.
     50     *
     51     * @throws Exception
     52     *
     53     * @param resource &$handle The cURL handle returned by curl_init().
     54     * @param array    $r       The HTTP request arguments.
     55     * @param string   $url     The request URL.
     56     *
     57     * @return void
     58     */
     59    public function configure_curl( $handle, $r, $url ) {
     60        parent::configure_curl( $handle, $r, $url );
     61
     62        $password         = uniqid();
     63        $certificate_file = $this->_maybe_create_certificate_file( $password );
     64
     65        if ( false === curl_setopt( $handle, CURLOPT_SSLCERT, $certificate_file ) ) {
     66            throw new Exception( __( 'Unable to accept certificate during cURL configuration', 'woocommerce-gateway-ppec' ), WC_Gateway_PPEC_Client::INVALID_ENVIRONMENT_ERROR );
     67        }
     68
     69        if ( $this->_use_secure_transport() && false === curl_setopt( $handle, CURLOPT_SSLCERTPASSWD, $password ) ) {
     70            throw new Exception( __( 'Unable to accept certificate password during cURL configuration', 'woocommerce-gateway-ppec' ), WC_Gateway_PPEC_Client::INVALID_ENVIRONMENT_ERROR );
     71        }
     72    }
     73
     74    /**
     75     * Dump the certificate out to a temporary file, because cURL can't accept
     76     * it any other way.
     77     *
     78     * @throws Exception
     79     *
     80     * @param string $password Password for certificate when using secure transport
     81     *
     82     * @return string Filepath of certificate file
     83     */
     84    protected function _maybe_create_certificate_file( $password ) {
     85        $temp_file = tempnam( sys_get_temp_dir(), 'pptmp_' );
     86        if ( ! $temp_file ) {
     87            throw new Exception( sprintf( __( 'Unable to write certificate file %s during cURL configuration', 'woocommerce-gateway-ppec' ), $temp_file ), WC_Gateway_PPEC_Client::INVALID_ENVIRONMENT_ERROR );
     88        }
     89
     90        if ( $this->_use_secure_transport() ) {
     91            $this->_maybe_create_secure_certificate_file( $temp_file, $password );
     92        } else {
     93            $this->_maybe_create_non_secure_certificate_file( $temp_file );
     94        }
     95
     96        return $temp_file;
     97    }
     98
     99    /**
     100     * If we're using SecureTransport, we have to translate the certificate to
     101     * PKCS12 before passing it to cURL.
     102     *
     103     * @throws Exception
     104     *
     105     * @param string $temp_file Filepath to temporary certificate file
     106     *
     107     * @return void
     108     */
     109    protected function _maybe_create_secure_certificate_file( $temp_file, $password ) {
     110        $private_key = openssl_pkey_get_private( $this->_certificate );
     111
     112        if ( false === $private_key ) {
     113            throw new Exception( __( 'Failed to retrieve private key during cURL configuration', 'woocommerce-gateway-ppec' ), WC_Gateway_PPEC_Client::INVALID_ENVIRONMENT_ERROR );
     114        }
     115
     116        if ( ! openssl_pkcs12_export_to_file( $this->_certificate, $temp_file, $private_key, $password ) ) {
     117            throw new Exception( __( 'Failed to export PKCS12 file during cURL configuration', 'woocommerce-gateway-ppec' ), WC_Gateway_PPEC_Client::INVALID_ENVIRONMENT_ERROR );
     118        }
     119    }
     120
     121    /**
     122     * Create non-password certificate file. Basically just dump the certificate
     123     * string to temporary file.
     124     *
     125     * @throws Exception
     126     *
     127     * @param string $temp_file Filepath to temporary certificate file
     128     *
     129     * @return void
     130     */
     131    protected function _maybe_create_non_secure_certificate_file( $temp_file ) {
     132        if ( false === file_put_contents( $temp_file, $this->_certificate ) ) {
     133            throw new Exception( sprintf( __( 'Unable to write certificate file %s during cURL configuration', 'woocommerce-gateway-ppec' ), $temp_file ), WC_Gateway_PPEC_Client::INVALID_ENVIRONMENT_ERROR );
     134        }
     135    }
     136
     137    /**
     138     * Returns true if secure transport is available in current cURL.
     139     *
     140     * @return bool
     141     */
     142    protected function _use_secure_transport() {
     143        $curl_version = curl_version();
     144        return false !== strpos( $curl_version['ssl_version'], 'SecureTransport' );
     145    }
    46146}
  • woocommerce-gateway-paypal-express-checkout/trunk/includes/class-wc-gateway-ppec-client.php

    r1384111 r1409404  
    116116            );
    117117
     118            // For cURL transport.
     119            add_action( 'http_api_curl', array( $this->_credential, 'configure_curl' ), 10, 3 );
     120
    118121            wc_gateway_ppec_log( sprintf( '%s: remote request to %s with args: %s', __METHOD__, $this->get_endpoint(), print_r( $args, true ) ) );
    119122
     
    134137            wc_gateway_ppec_log( sprintf( '%s: acknowleged response body: %s', __METHOD__, print_r( $result, true ) ) );
    135138
     139            remove_action( 'http_api_curl', array( $this->_credential, 'configure_curl' ), 10 );
     140
    136141            // Let the caller deals with the response.
    137142            return $result;
    138143
    139144        } catch ( Exception $e ) {
     145
     146            remove_action( 'http_api_curl', array( $this->_credential, 'configure_curl' ), 10 );
    140147
    141148            // TODO: Maybe returns WP_Error ?
  • woocommerce-gateway-paypal-express-checkout/trunk/includes/class-wc-gateway-ppec-plugin.php

    r1384111 r1409404  
    129129            throw new Exception( __( 'WooCommerce Gateway PayPal Express Checkout requires WooCommerce version 2.5 or greater', 'woocommerce-gateway-paypal-express-checkout' ) );
    130130        }
     131
     132        if ( ! function_exists( 'curl_init' ) ) {
     133            throw new Exception( __( 'WooCommerce Gateway PayPal Express Checkout requires cURL to be installed on your server', 'woocommerce-gateway-paypal-express-checkout' ) );
     134        }
     135
     136        $openssl_warning = __( 'WooCommerce Gateway PayPal Express Checkout requires OpenSSL >= 1.0.1 to be installed on your server', 'woocommerce-gateway-paypal-express-checkout' );
     137        if ( ! defined( 'OPENSSL_VERSION_TEXT' ) ) {
     138            throw new Exception( $openssl_warning );
     139        }
     140
     141        preg_match( '/^OpenSSL ([\d.]+)/', OPENSSL_VERSION_TEXT, $matches );
     142        if ( empty( $matches[1] ) ) {
     143            throw new Exception( $openssl_warning );
     144        }
     145
     146
     147        if ( ! version_compare( $matches[1], '1.0.1', '>=' ) ) {
     148            throw new Exception( $openssl_warning );
     149        }
    131150    }
    132151
  • woocommerce-gateway-paypal-express-checkout/trunk/readme.txt

    r1386378 r1409404  
    11=== WooCommerce PayPal Express Checkout Payment Gateway ===
    2 Contributors: automattic, woothemes, akeda, dwainm, royho, allendav, slash1andy, woosteve, spraveenitpro, mikedmoore, fernashes, shellbeezy
     2Contributors: automattic, woothemes, akeda, dwainm, royho, allendav, slash1andy, woosteve, spraveenitpro, mikedmoore, fernashes, shellbeezy, danieldudzic, mikaey
    33Tags: ecommerce, e-commerce, commerce, woothemes, wordpress ecommerce, store, sales, sell, shop, shopping, cart, checkout, configurable, paypal
    44Requires at least: 4.4
    55Tested up to: 4.4
    6 Stable tag: 1.0.0
     6Stable tag: 1.0.1
    77License: GPLv3
    88License URI: http://www.gnu.org/licenses/gpl-3.0.html
     
    5757= Where can I find documentation? =
    5858
    59 For help setting up and configuring, please refer to our [user guide](http://docs.woothemes.com/document/woocommerce-gateway-paypal-express-checkout/)
     59For help setting up and configuring, please refer to our [user guide](https://www.woothemes.com/products/woocommerce-gateway-paypal-express-checkout/)
    6060
    6161= Where can I get support or talk to other users? =
     
    8181== Changelog ==
    8282
     83= 1.0.1
     84* Fix - Make sure OpenSSL is installed with 1.0.1 as the minium required version, otherwise display warning
     85* Fix - Make sure cURL transport is available for WP HTTP API, otherwise display warning
     86* Fix - Unhandled certificate-style API credential
     87* Fix - Fixed calculated tax and coupons data that sent over to PayPal
     88* Fix - Fixed calculated shipping discount data that sent over to PayPal
     89
    8390= 1.0.0 =
    8491* Initial stable release
  • woocommerce-gateway-paypal-express-checkout/trunk/woocommerce-gateway-paypal-express-checkout.php

    r1386378 r1409404  
    44 * Plugin URI: https://woothemes.com
    55 * Description: A payment gateway for PayPal Express Checkout ( https://www.paypal.com/us/webapps/mpp/express-checkout ). Requires WC 2.5+
    6  * Version: 1.0.0
     6 * Version: 1.0.1
    77 * Author: Automattic/WooCommerce
    88 * Author URI: https://woocommerce.com
     
    3737        require_once( 'includes/class-wc-gateway-ppec-plugin.php' );
    3838
    39         $plugin = new WC_Gateway_PPEC_Plugin( __FILE__, '1.0.0' );
     39        $plugin = new WC_Gateway_PPEC_Plugin( __FILE__, '1.0.1' );
    4040    }
    4141
Note: See TracChangeset for help on using the changeset viewer.