diff --git a/package.json b/package.json index 0328b176b7..6e9b80158c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wp-e-commerce", - "version": "3.12.0", + "version": "3.12.2", "private": true, "devDependencies": { "grunt": "^0.4.5", diff --git a/readme.md b/readme.md index 93f5c192c0..95dcb35e1e 100644 --- a/readme.md +++ b/readme.md @@ -17,7 +17,7 @@ If you're looking for general user support, please submit your support request o Development status ------------------------- -* The latest stable version is [3.12.0](http://wordpress.org/extend/plugins/wp-e-commerce). +* The latest stable version is [3.12.2](http://wordpress.org/extend/plugins/wp-e-commerce). * Active development version: 4.0-dev (branch [master](https://github.com/wp-e-commerce/WP-e-Commerce)) * [Roadmap for 4.0](https://github.com/wp-e-commerce/wp-e-commerce/wiki/Roadmap) * [4.0 tickets](https://github.com/wp-e-commerce/WP-e-Commerce/milestones/4.0) diff --git a/readme.txt b/readme.txt index a86672a8ca..4f51a6b8d5 100755 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Donate link: https://wpecommerce.org Tags: e-commerce, digital downloads, wp-e-commerce, shop, cart, paypal, authorize, stock control, ecommerce, shipping, tax Requires at least: 4.5 Tested up to: 4.7.2 -Stable tag: 3.12.0 +Stable tag: 3.12.2 WP eCommerce is a free, powerful plugin that empowers you to sell anything online, quickly and easily. @@ -36,6 +36,15 @@ After upgrading from earlier versions look for link "Update Store". This will up == Changelog == += 3.12.2 [2017-3-25] = + +* Enhancement: Default PayPal Credit to On, and ensure it is functional for our 1.0 theme engine. + += 3.12.1 [2017-3-24] = + +* New: Addition of PayPal Credit to PayPal Express Checkout. +* Fix: Ensure WPEC works via WP-CLI. + = 3.12.0 [2017-2-17] = * Fix: When updating a pending order, ensure that the order object's total price is updated as well. diff --git a/wp-shopping-cart.php b/wp-shopping-cart.php index cc8d4b417d..ab762df540 100644 --- a/wp-shopping-cart.php +++ b/wp-shopping-cart.php @@ -3,7 +3,7 @@ * Plugin Name: WP eCommerce * Plugin URI: http://wpecommerce.org/ * Description: A plugin that provides a WordPress Shopping Cart. See also: WPeCommerce.org | Support Forum | Documentation - * Version: 3.12.0 + * Version: 3.12.2 * Author: WP eCommerce * Author URI: http://wpecommerce.org/ * Text Domain: wp-e-commerce diff --git a/wpsc-components/fancy-notifications/fancy-notifications.php b/wpsc-components/fancy-notifications/fancy-notifications.php index b59d0462b3..7618ca46d0 100644 --- a/wpsc-components/fancy-notifications/fancy-notifications.php +++ b/wpsc-components/fancy-notifications/fancy-notifications.php @@ -4,11 +4,7 @@ * WP eCommerce Fancy Notifications */ -add_action( 'wp_enqueue_scripts', array( 'WPSC_Fancy_Notifications', 'enqueue_styles' ) ); -add_action( 'wp_enqueue_scripts', array( 'WPSC_Fancy_Notifications', 'enqueue_scripts' ) ); -add_action( 'wpsc_add_to_cart_button_form_begin', array( 'WPSC_Fancy_Notifications', 'add_fancy_notifications' ) ); -add_action( 'wpsc_theme_footer', array( 'WPSC_Fancy_Notifications', 'fancy_notifications' ) ); -add_filter( 'wpsc_add_to_cart_json_response', array( 'WPSC_Fancy_Notifications', 'wpsc_add_to_cart_json_response' ) ); +add_action( 'plugins_loaded', array( 'WPSC_Fancy_Notifications', 'setup_hooks' ) ); /** * WP eCommerce Fancy Notifications Class @@ -17,6 +13,23 @@ */ class WPSC_Fancy_Notifications { + /** + * Setup Hooks + */ + public static function setup_hooks() { + + if ( self::is_active() ) { + + add_action( 'wp_enqueue_scripts', array( get_class(), 'enqueue_styles' ) ); + add_action( 'wp_enqueue_scripts', array( get_class(), 'enqueue_scripts' ) ); + add_action( 'wpsc_add_to_cart_button_form_begin', array( get_class(), 'add_fancy_notifications' ) ); + add_action( 'wpsc_theme_footer', array( get_class(), 'fancy_notifications' ) ); + add_filter( 'wpsc_add_to_cart_json_response', array( get_class(), 'wpsc_add_to_cart_json_response' ) ); + + } + + } + /** * Fancy Notifications * @@ -128,6 +141,17 @@ public static function enqueue_scripts() { } + /** + * Is Active? + * + * @return boolean + */ + public static function is_active() { + + return get_option( 'fancy_notifications' ) == 1; + + } + /** * Plugin URL * diff --git a/wpsc-components/merchant-core-v3/gateways/paypal-digital-goods.php b/wpsc-components/merchant-core-v3/gateways/paypal-digital-goods.php index a0566b9331..c55064559b 100644 --- a/wpsc-components/merchant-core-v3/gateways/paypal-digital-goods.php +++ b/wpsc-components/merchant-core-v3/gateways/paypal-digital-goods.php @@ -119,10 +119,10 @@ public function add_ecs_button( $cart_table, $context ) { * * @return void */ - public function get_shortcut_url() { + public function get_shortcut_url( $callback = 'shortcut_process' ) { $location = add_query_arg( array( 'payment_gateway' => 'paypal-digital-goods', - 'payment_gateway_callback' => 'shortcut_process', + 'payment_gateway_callback' => $callback, ), home_url( 'index.php' ) ); return apply_filters( 'wpsc_paypal_digital_goods_shortcut_url', $location ); diff --git a/wpsc-components/merchant-core-v3/gateways/paypal-express-checkout.php b/wpsc-components/merchant-core-v3/gateways/paypal-express-checkout.php index cfc63d71d7..5281c9f575 100644 --- a/wpsc-components/merchant-core-v3/gateways/paypal-express-checkout.php +++ b/wpsc-components/merchant-core-v3/gateways/paypal-express-checkout.php @@ -42,19 +42,36 @@ public function __construct( $options, $child = false ) { 'cart_border' => $this->setting->get( 'cart_border' ), 'incontext' => (bool) $this->setting->get( 'incontext', '1' ), 'shortcut' => (bool) $this->setting->get( 'shortcut' , '1' ), + 'credit' => (bool) $this->setting->get( 'credit' , '1' ), ) ); // Express Checkout Button if ( (bool) $this->setting->get( 'shortcut' ) ) { add_action( 'wpsc_cart_item_table_form_actions_left', array( $this, 'add_ecs_button' ), 2, 2 ); } + // Incontext Checkout Scripts if ( (bool) $this->setting->get( 'incontext' ) ) { add_action( 'wp_enqueue_scripts', array( $this, 'incontext_load_scripts' ) ); } + + // PayPal Credit Button + if ( (bool) $this->setting->get( 'credit' ) ) { + add_action( 'wpsc_gateway_v2_inside_gateway_label', array( $this, 'add_credit_button_tev1' ) ); + add_action( 'wpsc_cart_item_table_form_actions_left', array( $this, 'add_credit_button' ), 1, 2 ); + } + } } + public function add_credit_button_tev1( $gateway ) { + if ( 'paypal-express-checkout' !== $gateway ) { return; } + + $url = $this->get_shortcut_url( 'credit_process' ); + echo '' . __( '— or —', 'wp-e-commerce' ) . ''; + echo '' . __( 'PayPal Credit', 'wp-e-commerce' ) . ''; + } + public function incontext_load_scripts() { $is_cart = wpsc_is_theme_engine( '1.0' ) ? wpsc_is_checkout() : ( wpsc_is_checkout() || wpsc_is_cart() ); @@ -89,15 +106,34 @@ public function add_ecs_button( $cart_table, $context ) { } } + /** + * Insert the Credit Shortcut Button + * + * @return void + */ + public function add_credit_button( $cart_table, $context ) { + + if ( wpsc_is_gateway_active( 'paypal-digital-goods' ) || ! wpsc_is_gateway_active( 'paypal-express-checkout' ) ) { + return; + } + + if ( _wpsc_get_current_controller_name() === 'cart' ) { + $url = $this->get_shortcut_url( 'credit_process' ); + echo '' . __( 'PayPal Credit', 'wp-e-commerce' ) . ''; + echo '' . __( '— or —', 'wp-e-commerce' ) . ''; + } + } + /** * Return the ExpressCheckout Shortcut redirection URL * + * @param string $callback * @return void */ - public function get_shortcut_url() { + public function get_shortcut_url( $callback = 'shortcut_process' ) { $location = add_query_arg( array( 'payment_gateway' => 'paypal-express-checkout', - 'payment_gateway_callback' => 'shortcut_process', + 'payment_gateway_callback' => $callback, ), home_url( 'index.php' ) ); return apply_filters( 'wpsc_paypal_express_checkout_shortcut_url', $location ); @@ -112,6 +148,7 @@ public function callback_shortcut_process() { if ( ! isset( $_GET['payment_gateway'] ) ) { return; } + $payment_gateway = $_GET['payment_gateway']; global $wpsc_cart; @@ -136,6 +173,7 @@ public function callback_shortcut_process() { $tax = 0; $tax_percentage = 0; } + $purchase_log->set( array( 'wpec_taxes_total' => $tax, 'wpec_taxes_rate' => $tax_percentage, @@ -182,6 +220,88 @@ public function callback_shortcut_process() { return $sessionid; } + /** + * Credit Shortcut Callback + * + * @return int + */ + public function callback_credit_process() { + if ( ! isset( $_GET['payment_gateway'] ) ) { + return; + } + + $payment_gateway = $_GET['payment_gateway']; + + global $wpsc_cart; + // Create a new PurchaseLog Object + $purchase_log = new WPSC_Purchase_Log(); + + // Create a Sessionid + $sessionid = ( mt_rand( 100, 999 ) . time() ); + wpsc_update_customer_meta( 'checkout_session_id', $sessionid ); + $purchase_log->set( array( + 'user_ID' => get_current_user_id(), + 'date' => time(), + 'plugin_version' => WPSC_VERSION, + 'statusno' => '0', + 'sessionid' => $sessionid, + ) ); + + if ( wpsc_tax_isincluded() ) { + $tax = $wpsc_cart->calculate_total_tax(); + $tax_percentage = $wpsc_cart->tax_percentage; + } else { + $tax = 0; + $tax_percentage = 0; + } + + $purchase_log->set( array( + 'wpec_taxes_total' => $tax, + 'wpec_taxes_rate' => $tax_percentage, + ) ); + + // Save the purchase_log object to generate it's id + $purchase_log->save(); + $purchase_log_id = $purchase_log->get( 'id' ); + + $wpsc_cart->log_id = $purchase_log_id; + wpsc_update_customer_meta( 'current_purchase_log_id', $purchase_log_id ); + + $purchase_log->set( array( + 'gateway' => $payment_gateway, + 'base_shipping' => $wpsc_cart->calculate_base_shipping(), + 'totalprice' => $wpsc_cart->calculate_total_price(), + ) ); + + $purchase_log->save(); + + $wpsc_cart->empty_db( $purchase_log_id ); + $wpsc_cart->save_to_db( $purchase_log_id ); + $wpsc_cart->submit_stock_claims( $purchase_log_id ); + + // Save an empty Form + $form = WPSC_Checkout_Form::get(); + $fields = $form->get_fields(); + + WPSC_Checkout_Form_Data::save_form( $purchase_log, $fields, array(), false ); + + // Return Customer to Review Order Page if there is Shipping + add_filter( 'wpsc_paypal_express_checkout_transact_url', array( &$this, 'review_order_url' ) ); + add_filter( 'wpsc_paypal_express_checkout_return_url', array( &$this, 'review_order_callback' ) ); + + // Set a Temporary Option for EC Shortcut + wpsc_update_customer_meta( 'esc-' . $sessionid, true ); + + // Apply Checkout Actions + do_action( 'wpsc_submit_checkout', array( + 'purchase_log_id' => $purchase_log_id, + 'our_user_id' => get_current_user_id(), + ) ); + do_action( 'wpsc_submit_checkout_gateway', $payment_gateway, $purchase_log ); + + return $sessionid; + } + /** * Return Customer to Review Order Page if there are Shipping Costs. * @@ -417,7 +537,7 @@ public function pull_paypal_details() { } // Save details to the Forms Table - WPSC_Checkout_Form_Data::save_form( $this->purchase_log, $fields ); + WPSC_Checkout_Form_Data::save_form( $this->purchase_log, $fields, array(), false ); } /** @@ -884,7 +1004,21 @@ public function setup_form() { - + + + +

+ + + + + + + +     + + + is_currency_supported() ) : ?> @@ -997,6 +1131,7 @@ protected function convert( $amt ) { * @since 3.9.0 */ public function process() { + $total = $this->convert( $this->purchase_log->get( 'totalprice' ) ); $options = array( 'return_url' => $this->get_return_url(), @@ -1012,6 +1147,14 @@ public function process() { $options['notify_url'] = $this->get_notify_url(); } + // Check if its a Credit transaction and pass required params. + if ( isset( $_GET['payment_gateway_callback'] ) && $_GET['payment_gateway_callback'] == 'credit_process' ) { + $options += array( + 'solution_type' => 'SOLE', + 'user_funding_source' => 'Finance', + ); + } + // SetExpressCheckout $response = $this->gateway->setup_purchase( $options ); diff --git a/wpsc-components/merchant-core-v3/gateways/php-merchant/gateways/paypal-express-checkout.php b/wpsc-components/merchant-core-v3/gateways/php-merchant/gateways/paypal-express-checkout.php index 04db3fc646..b7275cbccc 100644 --- a/wpsc-components/merchant-core-v3/gateways/php-merchant/gateways/paypal-express-checkout.php +++ b/wpsc-components/merchant-core-v3/gateways/php-merchant/gateways/paypal-express-checkout.php @@ -193,6 +193,7 @@ protected function build_checkout_request( $action, $options = array() ) { 'MSGSUBID' => 'message_id', 'INVOICEID' => 'invoice', 'NOTE' => 'note', + 'USERSELECTEDFUNDINGSOURCE' => 'user_funding_source', ) ); // Cart Customization Fields @@ -243,7 +244,6 @@ public function setup_purchase( $options = array(), $action = 'Sale' ) { $this->options = array_merge( $this->options, $options ); $this->requires( array( 'amount', 'return_url', 'cancel_url' ) ); $request = $this->build_checkout_request( $action, $options ); - $response_str = $this->commit( 'SetExpressCheckout', $request ); return new PHP_Merchant_Paypal_Express_Checkout_Response( $response_str ); } diff --git a/wpsc-core/wpsc-constants.php b/wpsc-core/wpsc-constants.php index 4cb8502161..9e96283319 100644 --- a/wpsc-core/wpsc-constants.php +++ b/wpsc-core/wpsc-constants.php @@ -55,7 +55,7 @@ function wpsc_core_constants() { // Define Plugin version if ( ! defined( 'WPSC_VERSION' ) ) { - define( 'WPSC_VERSION' , '3.12.0' ); + define( 'WPSC_VERSION' , '3.12.2' ); } if ( ! defined( 'WPSC_MINOR_VERSION' ) ) { @@ -63,7 +63,7 @@ function wpsc_core_constants() { } if ( ! defined( 'WPSC_PRESENTABLE_VERSION' ) ) { - define( 'WPSC_PRESENTABLE_VERSION', '3.12.0' ); + define( 'WPSC_PRESENTABLE_VERSION', '3.12.2' ); } // Define a salt to use when we hash, WPSC_SALT may be defined for us in our config file, so check first diff --git a/wpsc-core/wpsc-functions.php b/wpsc-core/wpsc-functions.php index 243a876c4e..553dd2efa2 100644 --- a/wpsc-core/wpsc-functions.php +++ b/wpsc-core/wpsc-functions.php @@ -644,12 +644,14 @@ function wpsc_serialize_shopping_cart() { $wpsc_cart->errors = array(); } - // need to prevent set_cookie from being called at this stage in case the user just logged out - // because by now, some output must have been printed out - $customer_id = wpsc_get_current_customer_id(); + if ( function_exists( 'wpsc_get_current_customer_id' ) ) { + // Need to prevent set_cookie from being called at this stage in case the user + // just logged out because by now, some output must have been printed out. + $customer_id = wpsc_get_current_customer_id(); - if ( $customer_id ) { - wpsc_update_customer_cart( $wpsc_cart, $customer_id ); + if ( $customer_id ) { + wpsc_update_customer_cart( $wpsc_cart, $customer_id ); + } } return true;