diff --git a/README.md b/README.md index b30a53b..b2ac926 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Stripe payment gateway for Restrict Content Pro, using [Stripe Elements](https:/ ## Usage -1. Download the zip +1. Download the [latest release](https://github.com/TomodomoCo/rcp-stripe-elements/releases/latest) 2. Install the plugin 3. Activate the plugin 4. ... diff --git a/class-rcp-payment-gateway-stripe-elements.php b/class-rcp-payment-gateway-stripe-elements.php index 16f054a..7c34fff 100644 --- a/class-rcp-payment-gateway-stripe-elements.php +++ b/class-rcp-payment-gateway-stripe-elements.php @@ -38,6 +38,15 @@ public function fields() { ), ) ); + // Set `form_id` if on RCP Update Billing page + if ( rcp_elements_is_update_card_page() !== false ) { + $form_id = apply_filters( 'rcp_elements_update_form_id', 'rcp_update_card_form' ); + + // Set `form_id` if on RCP Registration page + } else { + $form_id = apply_filters( 'rcp_elements_registration_form_id', 'rcp_registration_form' ); + } + ob_start(); ?>
@@ -48,12 +57,13 @@ public function fields() {
@@ -132,12 +153,24 @@ function stripeTokenHandler( token ) { } /** - * Load Stripe Elements JS; dequeue Stripe Checkout JS + * Print form fields for this Gateway on `update billing` view in RCP + * + * @return string + */ + public function update_fields() { + parent::init(); + + return $this->fields(); + } + + /** + * Load Stripe Elements JS * * @return void */ public function scripts() { - wp_enqueue_script( 'stripe-elements', 'https://js.stripe.com/v3/' ); + wp_register_script( 'stripe-elements', 'https://js.stripe.com/v3/', array( 'jquery' ) ); + wp_enqueue_script( 'stripe-elements' ); } /** diff --git a/rcp-stripe-elements.php b/rcp-stripe-elements.php index 3638f3a..cbed472 100644 --- a/rcp-stripe-elements.php +++ b/rcp-stripe-elements.php @@ -45,3 +45,54 @@ function rcp_elements_register_stripe_elements_gateway( $gateways ) { return $gateways; } add_filter( 'rcp_payment_gateways', 'rcp_elements_register_stripe_elements_gateway' ); + +/** + * Custom path for RCP template overrides + * + * @param array $template_stack + * @param string $template_names + * + * @return array $template_stack + */ +function rcp_elements_custom_template_path( $template_stack, $template_names ) { + $template_stack[] = trailingslashit( plugin_dir_path( __FILE__ ) ) . 'templates/'; + + return $template_stack; +} +add_filter( 'rcp_template_stack', 'rcp_elements_custom_template_path', 10, 2 ); + +/** + * Conditionally loads Stripe Elements JS for the `update card` page + * + * @return void + */ +function rcp_elements_load_scripts() { + + // Bail early if scripts shouldn't be loaded + if ( rcp_elements_is_update_card_page() === false ) { + return; + } + + $gateway = new RCP_Payment_Gateway_Stripe_Elements(); + $gateway->scripts(); +} +add_action( 'wp_enqueue_scripts', 'rcp_elements_load_scripts', 10, 0 ); + +/** + * Checks if the current page is the RCP update card page + * + * @return bool + */ +function rcp_elements_is_update_card_page() { + global $rcp_options, $post; + + if ( isset( $rcp_options['update_card'] ) ) { + return is_page( $rcp_options['update_card'] ); + } + + if ( ! empty( $post ) && has_shortcode( $post->post_content, 'rcp_update_card' ) ) { + return true; + } + + return false; +} \ No newline at end of file diff --git a/templates/card-update-form.php b/templates/card-update-form.php new file mode 100644 index 0000000..9e2fc5a --- /dev/null +++ b/templates/card-update-form.php @@ -0,0 +1,45 @@ + + + +
+ + get_card_details(); ?> + + +

+ +
+

+ + + + + + + +

+
+ + + + update_fields(); + ?> + +
+
+

+ + +

+ +
diff --git a/templates/index.php b/templates/index.php new file mode 100644 index 0000000..1d713ab --- /dev/null +++ b/templates/index.php @@ -0,0 +1,2 @@ +