Changeset 1409404
- Timestamp:
- 05/03/2016 07:44:07 AM (10 years ago)
- Location:
- woocommerce-gateway-paypal-express-checkout/trunk
- Files:
-
- 2 added
- 8 edited
-
includes/abstracts/abstract-wc-gateway-ppec-client-credential.php (modified) (2 diffs)
-
includes/abstracts/abstract-wc-gateway-ppec.php (modified) (1 diff)
-
includes/class-wc-gateway-ppec-cart-handler.php (modified) (15 diffs)
-
includes/class-wc-gateway-ppec-client-credential-certificate.php (modified) (1 diff)
-
includes/class-wc-gateway-ppec-client.php (modified) (2 diffs)
-
includes/class-wc-gateway-ppec-plugin.php (modified) (1 diff)
-
includes/pem (added)
-
includes/pem/bundle.pem (added)
-
readme.txt (modified) (3 diffs)
-
woocommerce-gateway-paypal-express-checkout.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
woocommerce-gateway-paypal-express-checkout/trunk/includes/abstracts/abstract-wc-gateway-ppec-client-credential.php
r1384111 r1409404 96 96 * from this object. 97 97 */ 98 p rotectedfunction get_request_params() {98 public function get_request_params() { 99 99 $params = array( 100 100 'USER' => $this->_username, … … 108 108 return $params; 109 109 } 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 } 110 127 } -
woocommerce-gateway-paypal-express-checkout/trunk/includes/abstracts/abstract-wc-gateway-ppec.php
r1386055 r1409404 226 226 } 227 227 228 $expires = sprintf( $ out, date_i18n( get_option( 'date_format' ), $valid_until ) );228 $expires = sprintf( $expires, date_i18n( get_option( 'date_format' ), $valid_until ) ); 229 229 $out = sprintf( __( 'Certificate belongs to API username %1$s; %2$s', 'woocommerce-gateway-paypal-express-checkout' ), $certinfo['subject']['CN'], $expires ); 230 230 } else { -
woocommerce-gateway-paypal-express-checkout/trunk/includes/class-wc-gateway-ppec-cart-handler.php
r1384111 r1409404 160 160 $discounts = round( WC()->cart->get_cart_discount_total(), $decimals ); 161 161 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 ); 163 163 $item = array( 164 164 'name' => $values['data']->post->post_title, … … 173 173 } 174 174 175 $this->orderTax = round( WC()->cart->tax_total , $decimals );175 $this->orderTax = round( WC()->cart->tax_total + WC()->cart->shipping_tax_total, $decimals ); 176 176 $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; 181 178 $this->orderTotal = $this->totalItemAmount + $this->orderTax + $this->shipping; 182 179 … … 201 198 202 199 $this->items[] = $modifyLineItem; 200 $this->totalItemAmount += $modifyLineItem[ 'amount' ]; 201 $this->orderTotal += $modifyLineItem[ 'amount' ]; 203 202 204 203 } elseif ( WC_Gateway_PPEC_Settings::subtotalMismatchBehaviorDropLineItems == $subtotalBehavior ) { … … 212 211 // enter discount shenanigans. item total cannot be 0 so make modifications accordingly 213 212 if ( $this->totalItemAmount == $discounts ) { 214 $settings = wc_gateway_ppec()-> loadSettings();213 $settings = wc_gateway_ppec()->settings->loadSettings(); 215 214 $behavior = $settings->zeroSubtotalBehavior; 216 215 … … 223 222 'description' => 'Discount Amount', 224 223 'quantity' => 1, 225 'amount' => $discounts224 'amount' => -$discounts 226 225 ); 227 226 228 $this->items[] = $discountLineIt me;227 $this->items[] = $discountLineItem; 229 228 230 229 if ( $is_zdp_currency ) { … … 242 241 243 242 $this->items[] = $modifyLineItem; 244 $this->shipDiscountAmount = $discount; 243 $this->shipDiscountAmount = -$discount; 244 $this->totalItemAmount = $this->totalItemAmount - $discounts + $discount; 245 $this->orderTotal -= $discounts; 245 246 246 247 } elseif ( WC_Gateway_PPEC_Settings::zeroSubtotalBehaviorOmitLineItems == $behavior ) { … … 249 250 unset($this->items); 250 251 $this->shipDiscountAmount = 0; 252 $this->totalItemAmount -= $discounts; 253 $this->orderTotal -= $discounts; 251 254 252 255 } else { 253 256 // ... 254 257 // 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; 256 260 257 261 } … … 270 274 271 275 $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; 272 285 } 273 286 … … 281 294 if ( ! is_numeric( $this->shipping ) ) 282 295 $this->shipping = 0; 283 296 284 297 } 285 298 … … 302 315 $discounts = round( $order->get_total_discount(), $decimals ); 303 316 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 ); 305 318 $item = array( 306 319 'name' => $values['name'], … … 310 323 311 324 $this->items[] = $item; 312 325 313 326 $roundedPayPalTotal += round( $amount * $values['qty'], $decimals ); 314 327 } … … 364 377 'description' => 'Discount Amount', 365 378 'quantity' => 1, 366 'amount' => $discounts379 'amount' => -$discounts 367 380 ); 368 381 369 $this->items[] = $discountLineIt me;382 $this->items[] = $discountLineItem; 370 383 371 384 if ( $is_zdp_currency ) { … … 383 396 384 397 $this->items[] = $modifyLineItem; 385 $this->shipDiscountAmount = $discount; 398 $this->shipDiscountAmount = -$discount; 399 $this->totalItemAmount = $this->totalItemAmount - $discounts + $discount; 400 $this->orderTotal -= $discounts; 386 401 387 402 } elseif ( WC_Gateway_PPEC_Settings::zeroSubtotalBehaviorOmitLineItems == $behavior ) { … … 390 405 unset($this->items); 391 406 $this->shipDiscountAmount = 0; 407 $this->totalItemAmount -= $discounts; 408 $this->orderTotal -= $discounts; 392 409 393 410 } else { 394 411 // ... 395 412 // 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; 398 415 } 399 416 } else { … … 408 425 409 426 $this->items[] = $discLineItem; 427 $this->totalItemAmount -= $discounts; 428 $this->orderTotal -= $discounts; 410 429 } 411 430 412 431 $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; 413 439 } 414 440 -
woocommerce-gateway-paypal-express-checkout/trunk/includes/class-wc-gateway-ppec-client-credential-certificate.php
r1384111 r1409404 44 44 return $this->_certificate; 45 45 } 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 } 46 146 } -
woocommerce-gateway-paypal-express-checkout/trunk/includes/class-wc-gateway-ppec-client.php
r1384111 r1409404 116 116 ); 117 117 118 // For cURL transport. 119 add_action( 'http_api_curl', array( $this->_credential, 'configure_curl' ), 10, 3 ); 120 118 121 wc_gateway_ppec_log( sprintf( '%s: remote request to %s with args: %s', __METHOD__, $this->get_endpoint(), print_r( $args, true ) ) ); 119 122 … … 134 137 wc_gateway_ppec_log( sprintf( '%s: acknowleged response body: %s', __METHOD__, print_r( $result, true ) ) ); 135 138 139 remove_action( 'http_api_curl', array( $this->_credential, 'configure_curl' ), 10 ); 140 136 141 // Let the caller deals with the response. 137 142 return $result; 138 143 139 144 } catch ( Exception $e ) { 145 146 remove_action( 'http_api_curl', array( $this->_credential, 'configure_curl' ), 10 ); 140 147 141 148 // TODO: Maybe returns WP_Error ? -
woocommerce-gateway-paypal-express-checkout/trunk/includes/class-wc-gateway-ppec-plugin.php
r1384111 r1409404 129 129 throw new Exception( __( 'WooCommerce Gateway PayPal Express Checkout requires WooCommerce version 2.5 or greater', 'woocommerce-gateway-paypal-express-checkout' ) ); 130 130 } 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 } 131 150 } 132 151 -
woocommerce-gateway-paypal-express-checkout/trunk/readme.txt
r1386378 r1409404 1 1 === WooCommerce PayPal Express Checkout Payment Gateway === 2 Contributors: automattic, woothemes, akeda, dwainm, royho, allendav, slash1andy, woosteve, spraveenitpro, mikedmoore, fernashes, shellbeezy 2 Contributors: automattic, woothemes, akeda, dwainm, royho, allendav, slash1andy, woosteve, spraveenitpro, mikedmoore, fernashes, shellbeezy, danieldudzic, mikaey 3 3 Tags: ecommerce, e-commerce, commerce, woothemes, wordpress ecommerce, store, sales, sell, shop, shopping, cart, checkout, configurable, paypal 4 4 Requires at least: 4.4 5 5 Tested up to: 4.4 6 Stable tag: 1.0. 06 Stable tag: 1.0.1 7 7 License: GPLv3 8 8 License URI: http://www.gnu.org/licenses/gpl-3.0.html … … 57 57 = Where can I find documentation? = 58 58 59 For help setting up and configuring, please refer to our [user guide](http ://docs.woothemes.com/document/woocommerce-gateway-paypal-express-checkout/)59 For help setting up and configuring, please refer to our [user guide](https://www.woothemes.com/products/woocommerce-gateway-paypal-express-checkout/) 60 60 61 61 = Where can I get support or talk to other users? = … … 81 81 == Changelog == 82 82 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 83 90 = 1.0.0 = 84 91 * Initial stable release -
woocommerce-gateway-paypal-express-checkout/trunk/woocommerce-gateway-paypal-express-checkout.php
r1386378 r1409404 4 4 * Plugin URI: https://woothemes.com 5 5 * 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. 06 * Version: 1.0.1 7 7 * Author: Automattic/WooCommerce 8 8 * Author URI: https://woocommerce.com … … 37 37 require_once( 'includes/class-wc-gateway-ppec-plugin.php' ); 38 38 39 $plugin = new WC_Gateway_PPEC_Plugin( __FILE__, '1.0. 0' );39 $plugin = new WC_Gateway_PPEC_Plugin( __FILE__, '1.0.1' ); 40 40 } 41 41
Note: See TracChangeset
for help on using the changeset viewer.