From 835380b3076e9518ce42a3c82cfb5e7682f58f94 Mon Sep 17 00:00:00 2001 From: Geoffrey Crofte Date: Mon, 5 Dec 2016 18:47:48 +0100 Subject: [PATCH 01/15] Introduce Imagify:: checkDiscount() and check_imagify_discount() function --- inc/api/imagify.php | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/inc/api/imagify.php b/inc/api/imagify.php index c4c82402f..49dabb4fd 100755 --- a/inc/api/imagify.php +++ b/inc/api/imagify.php @@ -101,9 +101,11 @@ function get_imagify_all_prices() { } /** - * Check Coupon Code - * + * Check if Coupon Code exists + * + * @param string $coupon the coupon code to check * @return object + * * @since 1.6 * @author Geoffrey Crofte **/ @@ -111,6 +113,17 @@ function check_imagify_coupon_code( $coupon ) { return Imagify()->checkCouponCode( $coupon ); } +/** + * Check if Discount/Promotion is available + * + * @return object + * @since 1.6.3 + * @author Geoffrey Crofte + **/ +function check_imagify_discount() { + return Imagify()->checkDiscount(); +} + /* * Get Maximum image size for free plan * @@ -343,6 +356,15 @@ public function checkCouponCode( $coupon ) { return $this->httpCall( 'coupons/' . $coupon . '/' ); } + /** + * Get information about current discount + * + * @return object + */ + public function checkDiscount() { + return $this->httpCall( 'pricing/discount/' ); + } + /* * Get Public Info * From 122663b4d7ece9476e888360c1c49d359c268e88 Mon Sep 17 00:00:00 2001 From: Geoffrey Crofte Date: Mon, 5 Dec 2016 18:48:14 +0100 Subject: [PATCH 02/15] Introduce WP AJAX hook to get current discount --- inc/admin/ajax.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/inc/admin/ajax.php b/inc/admin/ajax.php index 946f13e10..a5c295936 100755 --- a/inc/admin/ajax.php +++ b/inc/admin/ajax.php @@ -706,6 +706,25 @@ function _imagify_get_estimated_sizes() { } } + +/** + * Get current discount promotion to display information on payment modal + * + * @return JSON WP formatted answer + * + * @since 1.6.3 + * @author Geoffrey Crofte + */ +add_action( 'wp_ajax_imagify_get_discount', '_imagify_get_discount' ); +function _imagify_get_discount() { + if ( check_ajax_referer( 'imagify_get_pricing_' . get_current_user_id(), 'imagifynonce', false) ) { + $discount = check_imagify_discount(); + wp_send_json_success( $discount ); + } else { + wp_send_json_error( 'check_ajax_referer for getting discount failed' ); + } +} + /** * Estimate sizes and update the options values for them * From 1c9ccafdc4040661b6cbbeb0b8215f0fc3a08a7b Mon Sep 17 00:00:00 2001 From: Geoffrey Crofte Date: Tue, 6 Dec 2016 11:35:40 +0100 Subject: [PATCH 03/15] Introduce imagify_print_discount_banner() --- inc/functions/admin-ui.php | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/inc/functions/admin-ui.php b/inc/functions/admin-ui.php index 589966ec3..b85a9641e 100755 --- a/inc/functions/admin-ui.php +++ b/inc/functions/admin-ui.php @@ -225,7 +225,7 @@ function get_imagify_media_column_content( $attachment, $context = 'wp' ) { * * @return string HTML * - * @since 1.5 + * @since 1.6 * @author Geoffrey * * @todo add only for no-payable users? @@ -255,7 +255,7 @@ function get_imagify_new_to_imagify() { * @param float $value the price value * @return string the markuped price * - * @since 1.5 + * @since 1.6 * @author Geoffrey */ function get_imagify_price_table_format( $value ) { @@ -268,7 +268,8 @@ function get_imagify_price_table_format( $value ) { * Return the payment modal HTML * @return string HTML code for payement modal * - * @since 1.5 + * @since 1.6 + * @since 1.6.3 Include discount banners * @author Geoffrey * * @todo Make first offers dynamic thanks to consumption estimation @@ -314,6 +315,8 @@ function imagify_payment_modal() { + +

@@ -479,6 +482,8 @@ function imagify_payment_modal() {

+ +
@@ -487,6 +492,7 @@ function imagify_payment_modal() {
+