From 6e17e5c24d211dcf844b895d212c9d1016ee22e7 Mon Sep 17 00:00:00 2001 From: AndPicc Date: Wed, 15 Jun 2022 11:13:17 +0100 Subject: [PATCH] version 4.2.1 --- change_log.txt | 20 +- class-gf-stripe.php | 580 ++++++++++++++++--- css/plugin_settings.css | 2 +- includes/class-gf-stripe-api.php | 285 ++++++++- includes/class-gf-stripe-billing-portal.php | 535 +++++++++++++++++ includes/views/subscription-information.php | 151 +++++ js/admin.js | 127 +++- js/admin.min.js | 2 +- js/frontend.js | 2 +- languages/gravityformsstripe-ar.mo | Bin 469 -> 469 bytes languages/gravityformsstripe-ca.mo | Bin 938 -> 938 bytes languages/gravityformsstripe-da_DK.mo | Bin 6548 -> 6548 bytes languages/gravityformsstripe-de_DE.mo | Bin 23940 -> 23940 bytes languages/gravityformsstripe-de_DE_formal.mo | Bin 823 -> 823 bytes languages/gravityformsstripe-en_AU.mo | Bin 8886 -> 8886 bytes languages/gravityformsstripe-en_GB.mo | Bin 5589 -> 5589 bytes languages/gravityformsstripe-es_ES.mo | Bin 24327 -> 24327 bytes languages/gravityformsstripe-fi.mo | Bin 5598 -> 5598 bytes languages/gravityformsstripe-fr_CA.mo | Bin 6184 -> 6184 bytes languages/gravityformsstripe-fr_FR.mo | Bin 24709 -> 24709 bytes languages/gravityformsstripe-he_IL.mo | Bin 25280 -> 25280 bytes languages/gravityformsstripe-hi_IN.mo | Bin 37469 -> 37469 bytes languages/gravityformsstripe-hu_HU.mo | Bin 413 -> 413 bytes languages/gravityformsstripe-it_IT.mo | Bin 24349 -> 24349 bytes languages/gravityformsstripe-ja.mo | Bin 26372 -> 26372 bytes languages/gravityformsstripe-nb_NO.mo | Bin 849 -> 849 bytes languages/gravityformsstripe-nl_BE.mo | Bin 409 -> 409 bytes languages/gravityformsstripe-nl_NL.mo | Bin 23622 -> 23622 bytes languages/gravityformsstripe-pt_BR.mo | Bin 24064 -> 24064 bytes languages/gravityformsstripe-pt_PT.mo | Bin 24038 -> 24038 bytes languages/gravityformsstripe-ru_RU.mo | Bin 30606 -> 30606 bytes languages/gravityformsstripe-sv_SE.mo | Bin 24336 -> 24336 bytes languages/gravityformsstripe-tr_TR.mo | Bin 23394 -> 23394 bytes languages/gravityformsstripe-zh_CN.mo | Bin 1572 -> 1572 bytes languages/gravityformsstripe.pot | 498 ++++++++++------ stripe.php | 6 +- 36 files changed, 1931 insertions(+), 277 deletions(-) create mode 100644 includes/class-gf-stripe-billing-portal.php create mode 100644 includes/views/subscription-information.php diff --git a/change_log.txt b/change_log.txt index 94268b3..2077ace 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,7 +1,19 @@ -### 4.1.1 -- Updated the stripe API SDK methods. +### 4.2.1 +- Fixed a fatal error which can occur with the Stripe API Client if the add-on isn't connected to a Stripe account. + + +### 4.2 | 2022-02-03 +- Added security enhancements. +- Added the ability to refund payments from the entry detail page. +- Added the ability to capture authorized payments from the entry detail page. +- Added the stripe_customer_portal_link shortcode action to support [self-serve billing portal](https://docs.gravityforms.com/stripe-customer-portal-shortcode-action/). +- Updated the Stripe API SDK methods. - Updated the styling for the disconnect alert messaging. -- Fixed an issue where if future usage is set to 'on_session' and a user enters a 3DS card, they get an infinite loop and can't submit the form. +- Fixed a javascript error when de-authorizing Stripe account. +- Fixed an issue with unsaved warning being displayed on settings pages even when there are no changes made. +- Fixed an issue with the Webhooks Add-On where the payment details in the entry are empty. +- Fixed an issue where if future usage is set to 'on_session' and a user enters a 3DS card. This addresses an issue that results in an infinite loop on form submission. + ### 4.1 | 2021-06-30 - Updated error messages when API isn't connected to be more informative. @@ -11,6 +23,7 @@ - Fixed an issue where the credit card icon overlaps with the placeholder text in the credit card field. - Fixed an issue where the form fails validation if the plan (price) or product, created by the add-on, is archived in the Stripe account. + ### 4.0 | 2021-04-21 - Added a warning notice when deprecated credit card field is still being used. - Added right-to-left language support to the Credit Card field in the form editor in Gravity Forms 2.5. @@ -30,7 +43,6 @@ - Fixed an issue with the Stripe card field preview in the form editor. - ### 3.8 | 2020-09-28 - Added support for Gravity Forms 2.5. - Updated to support 50 metadata mappings. diff --git a/class-gf-stripe.php b/class-gf-stripe.php index 77137b4..6dc4e53 100644 --- a/class-gf-stripe.php +++ b/class-gf-stripe.php @@ -251,6 +251,16 @@ class GFStripe extends GFPaymentAddOn { * @var string */ protected $_input_container_prefix = ''; + + /** + * Instance of the billing portal handler. + * + * @since 4.2 + * + * @var GF_Stripe_Billing_Portal + */ + protected $billing_portal_handler; + /** * Get an instance of this class. * @@ -283,6 +293,9 @@ public function pre_init() { // Run before calling parent method. We don't want to run anything else before displaying thank you page. add_action( 'wp', array( $this, 'maybe_thankyou_page' ), 5 ); + // When the manage subscription link is clicked, it should be handled here. + add_action( 'wp', array( $this->get_billing_portal_handler(), 'maybe_redirect_logged_in_user_to_self_serve_link' ), 10 ); + parent::pre_init(); require_once 'includes/class-gf-field-stripe-creditcard.php'; @@ -304,7 +317,6 @@ public function pre_init() { * @return array The scripts to be enqueued. */ public function scripts() { - $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG || isset( $_GET['gform_debug'] ) ? '' : '.min'; $scripts = array( @@ -348,11 +360,11 @@ public function scripts() { 'handle' => 'gforms_stripe_admin', 'src' => $this->get_base_url() . "/js/admin{$min}.js", 'version' => $this->_version, - 'deps' => array( 'jquery', 'thickbox', 'stripe.js' ), + 'deps' => array( 'jquery', 'thickbox', 'stripe.js', 'wp-a11y' ), 'in_footer' => false, 'enqueue' => array( array( - 'admin_page' => array( 'plugin_settings', 'form_settings' ), + 'admin_page' => array( 'plugin_settings', 'form_settings', 'entry_view' ), 'tab' => array( $this->_slug, $this->get_short_title() ), ), ), @@ -371,6 +383,13 @@ public function scripts() { 'apiMode' => $this->get_api_mode( $this->get_settings() ), 'input_container_prefix' => $this->_input_container_prefix, 'input_prefix' => $this->_input_prefix, + 'refund' => wp_strip_all_tags( __( 'Are you sure you want to refund this payment?', 'gravityformsstripe' ) ), + 'refund_nonce' => wp_create_nonce( 'gf_stripe_refund' ), + 'refund_processing' => wp_strip_all_tags( __( 'Processing refund', 'gravityformsstripe' ) ), + 'refund_complete' => wp_strip_all_tags( __( 'Transaction successfully refunded', 'gravityformsstripe' ) ), + 'capture_confirm' => wp_strip_all_tags( __( 'Are you sure you want to capture this payment?', 'gravityformstripe' ) ), + 'capture_processing' => wp_strip_all_tags( __( 'Processing capture', 'gravityformsstripe' ) ), + 'capture_complete' => wp_strip_all_tags( __( 'Transaction successfully captured', 'gravityformsstripe' ) ), ), ), ); @@ -462,6 +481,8 @@ public function init_ajax() { add_action( 'wp_ajax_gfstripe_update_payment_intent', array( $this, 'update_payment_intent' ) ); add_action( 'wp_ajax_nopriv_gfstripe_get_country_code', array( $this, 'get_country_code' ) ); add_action( 'wp_ajax_gfstripe_get_country_code', array( $this, 'get_country_code' ) ); + add_action( 'wp_ajax_gfstripe_capture_action', array( $this, 'ajax_capture_payment' ) ); + add_action( 'wp_ajax_gfstripe_refund', array( $this, 'ajax_refund' ) ); } /** @@ -475,6 +496,26 @@ public function init_admin() { add_action( 'admin_notices', array( $this, 'maybe_display_update_authentication_message' ) ); add_action( 'admin_notices', array( $this, 'maybe_display_deprecated_cc_field_warning' ) ); add_action( 'admin_init', array( $this, 'maybe_update_auth_tokens' ) ); + add_action( 'gform_payment_details', array( $this, 'maybe_display_capture_button' ), 10, 2 ); + add_action( 'gform_payment_details', array( $this, 'maybe_display_refund_button' ), 10, 2 ); + } + + /** + * Gets billing portal handler instance if already initialized, otherwise, initialize it. + * + * @since 4.2 + * + * @return GF_Stripe_Billing_Portal + */ + public function get_billing_portal_handler() { + + if ( $this->billing_portal_handler instanceof GF_Stripe_Billing_Portal === false ) { + require_once plugin_dir_path( __FILE__ ) . '/includes/class-gf-stripe-billing-portal.php'; + $this->billing_portal_handler = new GF_Stripe_Billing_Portal( $this ); + } + + return $this->billing_portal_handler; + } /** @@ -563,11 +604,11 @@ public function plugin_settings_fields() { 'label' => esc_html__( 'Stripe Credit Card Field (Elements, SCA-ready)', 'gravityformsstripe' ), 'value' => 'stripe_elements', 'tooltip' => '
' . esc_html__( 'Stripe Credit Card Field (Elements)', 'gravityformsstripe' ) . '
' . - '

' . esc_html__( 'Select this option to use a Credit Card field hosted by Stripe. This option offers the benefit of a streamlined user interface and the security of having the credit card field hosted on Stripe\'s servers. Selecting this option or "Stripe Payment Form" greatly simplifies the PCI compliance application process with Stripe.', 'gravityformsstripe' ) . - '

' . - /* translators: 1. Open link tag 2. Close link tag */ - sprintf( esc_html__( 'Stripe Elements is ready for %1$sStrong Customer Authentication%2$s for European customers.', 'gravityformsstripe' ), '', '' ) . - '

', + '

' . esc_html__( 'Select this option to use a Credit Card field hosted by Stripe. This option offers the benefit of a streamlined user interface and the security of having the credit card field hosted on Stripe\'s servers. Selecting this option or "Stripe Payment Form" greatly simplifies the PCI compliance application process with Stripe.', 'gravityformsstripe' ) . + '

' . + /* translators: 1. Open link tag 2. Close link tag */ + sprintf( esc_html__( 'Stripe Elements is ready for %1$sStrong Customer Authentication%2$s for European customers.', 'gravityformsstripe' ), '', '' ) . + '

', ), array( 'label' => esc_html__( 'Stripe Payment Form (Stripe Checkout, SCA-ready)', 'gravityformsstripe' ), @@ -855,7 +896,7 @@ public function get_webhooks_section_description() { ob_start(); ?>

+ onclick="tb_show('Webhook Instructions', '#TB_inline?width=500&inlineId=stripe-webhooks-instructions', '');" onkeypress="tb_show('Webhook Instructions', '#TB_inline?width=500&inlineId=stripe-webhooks-instructions', '');">