-
-
Notifications
You must be signed in to change notification settings - Fork 76
Use Stripe Checkout Element #300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
15568bf
bd87731
c431f91
44f23c3
b0155af
f980d7c
4f14632
18efb0b
2e044f4
30e8f1c
c5937c4
568a608
01b2fae
76b6b62
966176e
7454593
4a125da
e58d57c
52f9f17
0a6982a
caf0854
1ec49d7
827e78e
2da2f14
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,11 @@ public function init(): void { | |
|
|
||
| add_shortcode('wu_confirmation', [$this, 'render_confirmation_page']); | ||
|
|
||
| /* | ||
| * Enqueue payment status polling script on thank you page. | ||
| */ | ||
| add_action('wp_enqueue_scripts', [$this, 'maybe_enqueue_payment_status_poll']); | ||
|
|
||
| add_filter('lostpassword_redirect', [$this, 'filter_lost_password_redirect']); | ||
|
|
||
| if (is_main_site()) { | ||
|
|
@@ -204,6 +209,8 @@ public function get_error_message($error_code, $username = '') { | |
| 'password_reset_mismatch' => __('<strong>Error:</strong> The passwords do not match.'), // phpcs:ignore WordPress.WP.I18n.MissingArgDomain | ||
| 'invalidkey' => __('<strong>Error:</strong> Your password reset link appears to be invalid. Please request a new link below.'), // phpcs:ignore WordPress.WP.I18n.MissingArgDomain | ||
| 'expiredkey' => __('<strong>Error:</strong> Your password reset link has expired. Please request a new link below.'), // phpcs:ignore WordPress.WP.I18n.MissingArgDomain | ||
| 'invalid_key' => __('<strong>Error:</strong> Your password reset link appears to be invalid. Please request a new link below.'), // phpcs:ignore WordPress.WP.I18n.MissingArgDomain | ||
| 'expired_key' => __('<strong>Error:</strong> Your password reset link has expired. Please request a new link below.'), // phpcs:ignore WordPress.WP.I18n.MissingArgDomain | ||
| ]; | ||
|
|
||
| /** | ||
|
|
@@ -665,4 +672,107 @@ public function render_confirmation_page($atts, $content = null) { // phpcs:igno | |
| ] | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Maybe enqueue payment status polling script on thank you page. | ||
| * | ||
| * This script polls the server to check if a pending payment has been completed, | ||
| * providing a fallback mechanism when webhooks are delayed or not working. | ||
| * | ||
| * @since 2.x.x | ||
| * @return void | ||
| */ | ||
| public function maybe_enqueue_payment_status_poll(): void { | ||
|
|
||
| // Only on thank you page (payment hash and status=done in URL) | ||
| $payment_hash = wu_request('payment'); | ||
| $status = wu_request('status'); | ||
|
|
||
| if (empty($payment_hash) || 'done' !== $status || 'none' === $payment_hash) { | ||
| return; | ||
| } | ||
|
|
||
| $payment = wu_get_payment_by_hash($payment_hash); | ||
|
|
||
| if (! $payment) { | ||
| return; | ||
| } | ||
|
|
||
| // Only poll for pending Stripe payments | ||
| $gateway_id = $payment->get_gateway(); | ||
|
|
||
| if (empty($gateway_id)) { | ||
| $membership = $payment->get_membership(); | ||
| $gateway_id = $membership ? $membership->get_gateway() : ''; | ||
| } | ||
|
|
||
| // Only poll for Stripe payments that are still pending | ||
| $is_stripe_payment = in_array($gateway_id, ['stripe', 'stripe-checkout'], true); | ||
| $is_pending = $payment->get_status() === \WP_Ultimo\Database\Payments\Payment_Status::PENDING; | ||
|
|
||
| if (! $is_stripe_payment) { | ||
| return; | ||
| } | ||
|
|
||
| wp_register_script( | ||
| 'wu-payment-status-poll', | ||
| wu_get_asset('payment-status-poll.js', 'js'), | ||
| ['jquery'], | ||
| wu_get_version(), | ||
| true | ||
| ); | ||
|
|
||
| wp_localize_script( | ||
| 'wu-payment-status-poll', | ||
| 'wu_payment_poll', | ||
| [ | ||
| 'payment_hash' => $payment_hash, | ||
| 'ajax_url' => admin_url('admin-ajax.php'), | ||
| 'poll_interval' => 3000, // 3 seconds | ||
| 'max_attempts' => 20, // 60 seconds total | ||
| 'should_poll' => $is_pending, | ||
| 'status_selector' => '.wu-payment-status', | ||
| 'success_redirect' => '', | ||
| 'messages' => [ | ||
| 'completed' => __('Payment confirmed! Refreshing page...', 'ultimate-multisite'), | ||
| 'pending' => __('Verifying your payment with Stripe...', 'ultimate-multisite'), | ||
| 'timeout' => __('Payment verification is taking longer than expected. Your payment may still be processing. Please refresh the page or contact support if you believe payment was made.', 'ultimate-multisite'), | ||
| 'error' => __('Error checking payment status. Retrying...', 'ultimate-multisite'), | ||
| 'checking' => __('Checking payment status...', 'ultimate-multisite'), | ||
| ], | ||
| ] | ||
| ); | ||
|
|
||
| wp_enqueue_script('wu-payment-status-poll'); | ||
|
|
||
| // Add inline CSS for the status messages | ||
| wp_add_inline_style( | ||
| 'wu-checkout', | ||
| ' | ||
| .wu-payment-status { | ||
| padding: 12px 16px; | ||
| border-radius: 6px; | ||
| margin-bottom: 16px; | ||
| font-weight: 500; | ||
| } | ||
| .wu-payment-status-pending, | ||
| .wu-payment-status-checking { | ||
| background-color: #fef3cd; | ||
| color: #856404; | ||
| border: 1px solid #ffc107; | ||
| } | ||
| .wu-payment-status-completed { | ||
| background-color: #d4edda; | ||
| color: #155724; | ||
| border: 1px solid #28a745; | ||
| } | ||
| .wu-payment-status-timeout, | ||
| .wu-payment-status-error { | ||
| background-color: #f8d7da; | ||
| color: #721c24; | ||
| border: 1px solid #f5c6cb; | ||
| } | ||
| ' | ||
| ); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Search for wu-checkout registration and enqueuing in the codebase
rg -n "wu-checkout" --type=php | head -40Repository: Ultimate-Multisite/ultimate-multisite Length of output: 4819 🏁 Script executed: #!/bin/bash
# Get context around lines 757-785 in the checkout-pages file
wc -l inc/checkout/class-checkout-pages.phpRepository: Ultimate-Multisite/ultimate-multisite Length of output: 122 🏁 Script executed: #!/bin/bash
# Read the section around lines 757-785 to understand context
sed -n '740,790p' inc/checkout/class-checkout-pages.phpRepository: Ultimate-Multisite/ultimate-multisite Length of output: 1592 🏁 Script executed: #!/bin/bash
# Get broader context to find the function/method name
sed -n '720,760p' inc/checkout/class-checkout-pages.phpRepository: Ultimate-Multisite/ultimate-multisite Length of output: 1509 🏁 Script executed: #!/bin/bash
# Check the class structure and method definitions
rg -n "function|public|protected|private" inc/checkout/class-checkout-pages.php | grep -B5 -A5 "75[0-9]"Repository: Ultimate-Multisite/ultimate-multisite Length of output: 63 🏁 Script executed: #!/bin/bash
# Look at where class-checkout-pages is instantiated and used
rg -n "class-checkout-pages\|checkout-pages" --type=php | head -20Repository: Ultimate-Multisite/ultimate-multisite Length of output: 63 🏁 Script executed: #!/bin/bash
# Look for function definitions around line 700-750
sed -n '700,730p' inc/checkout/class-checkout-pages.phpRepository: Ultimate-Multisite/ultimate-multisite Length of output: 920 🏁 Script executed: #!/bin/bash
# Get all function/method definitions in the file with line numbers
rg -n "^\s*(public|private|protected)?\s*function" inc/checkout/class-checkout-pages.phpRepository: Ultimate-Multisite/ultimate-multisite Length of output: 1445 🏁 Script executed: #!/bin/bash
# Find where maybe_enqueue_payment_status_poll is called/hooked
rg -n "maybe_enqueue_payment_status_poll" --type=phpRepository: Ultimate-Multisite/ultimate-multisite Length of output: 306 🏁 Script executed: #!/bin/bash
# Check the init method and hooks in class-checkout-pages
sed -n '30,95p' inc/checkout/class-checkout-pages.phpRepository: Ultimate-Multisite/ultimate-multisite Length of output: 2280 🏁 Script executed: #!/bin/bash
# Check when/where wu-checkout is enqueued in class-checkout.php
sed -n '2620,2650p' inc/checkout/class-checkout.phpRepository: Ultimate-Multisite/ultimate-multisite Length of output: 1042 🏁 Script executed: #!/bin/bash
# Find where register_scripts from class-checkout is called
rg -n "register_scripts" inc/checkout/class-checkout.php | head -5Repository: Ultimate-Multisite/ultimate-multisite Length of output: 199 🏁 Script executed: #!/bin/bash
# Search for hooks/actions that call register_scripts on checkout
rg -n "register_scripts\|class-checkout" inc/checkout/class-checkout.php | grep -i "add_action\|add_filter" | head -10Repository: Ultimate-Multisite/ultimate-multisite Length of output: 63 🏁 Script executed: #!/bin/bash
# Check the Checkout class initialization to see when register_scripts is called
sed -n '1,150p' inc/checkout/class-checkout.php | grep -A5 -B5 "register_scripts"Repository: Ultimate-Multisite/ultimate-multisite Length of output: 63 🏁 Script executed: #!/bin/bash
# Find where wu_checkout_scripts action is fired
rg -n "wu_checkout_scripts" --type=phpRepository: Ultimate-Multisite/ultimate-multisite Length of output: 830 🏁 Script executed: #!/bin/bash
# Check the initialization of Checkout class
sed -n '150,250p' inc/checkout/class-checkout.php | head -60Repository: Ultimate-Multisite/ultimate-multisite Length of output: 1516 🏁 Script executed: #!/bin/bash
# Check what's enqueued on thank-you pages - search for enqueue in render_confirmation_page and related methods
sed -n '674,700p' inc/checkout/class-checkout-pages.phpRepository: Ultimate-Multisite/ultimate-multisite Length of output: 988 🏁 Script executed: #!/bin/bash
# Check if wu_checkout_scripts is fired on thank-you page
rg -n "render_confirmation_page\|do_action.*wu_checkout_scripts" inc/checkout/class-checkout-pages.phpRepository: Ultimate-Multisite/ultimate-multisite Length of output: 63 🏁 Script executed: #!/bin/bash
# Get full context of render_confirmation_page method
sed -n '674,695p' inc/checkout/class-checkout-pages.phpRepository: Ultimate-Multisite/ultimate-multisite Length of output: 760 🏁 Script executed: #!/bin/bash
# Check the confirmation template to see if it enqueues wu-checkout
find . -path "./views/*" -name "*confirmation*" -type fRepository: Ultimate-Multisite/ultimate-multisite Length of output: 114 🏁 Script executed: #!/bin/bash
# Look for confirmation template
find . -name "confirmation.php" -type fRepository: Ultimate-Multisite/ultimate-multisite Length of output: 114 🏁 Script executed: #!/bin/bash
# Check where wu_checkout_scripts is fired on the thank-you/confirmation page
rg -n "do_action.*wu_checkout_scripts" views/ --type=phpRepository: Ultimate-Multisite/ultimate-multisite Length of output: 153 🏁 Script executed: #!/bin/bash
# Read the confirmation template to see what it does
cat views/checkout/confirmation.phpRepository: Ultimate-Multisite/ultimate-multisite Length of output: 1703 🏁 Script executed: #!/bin/bash
# Check if confirmation page calls any actions related to scripts
rg -n "do_action\|wp_enqueue" views/checkout/confirmation.phpRepository: Ultimate-Multisite/ultimate-multisite Length of output: 63 🏁 Script executed: #!/bin/bash
# Check if 'wu-checkout' is ever enqueued on pages outside of checkout form context
rg -n "wp_enqueue.*wu-checkout" --type=phpRepository: Ultimate-Multisite/ultimate-multisite Length of output: 701 🏁 Script executed: #!/bin/bash
# Verify: does the thank-you page trigger wp_enqueue_scripts while wu_checkout_scripts fires?
# Check the page flow - look for how pages are rendered
sed -n '1,50p' inc/checkout/class-checkout-pages.phpRepository: Ultimate-Multisite/ultimate-multisite Length of output: 1337 🏁 Script executed: #!/bin/bash
# Double-check by looking at the full maybe_enqueue_payment_status_poll function
sed -n '694,786p' inc/checkout/class-checkout-pages.phpRepository: Ultimate-Multisite/ultimate-multisite Length of output: 2828 Inline styles depend on
Attach the inline CSS to the wp_add_inline_script('wu-payment-status-poll', 'your_css_here', 'before');Or register and enqueue a minimal styles dependency: wp_register_style('wu-payment-status', false);
wp_enqueue_style('wu-payment-status');
wp_add_inline_style('wu-payment-status', '...');🤖 Prompt for AI Agents |
||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
rg -n "payment.status|payment_status|wu_payment.*poll|wu_check_payment" --type=php -C3Repository: Ultimate-Multisite/ultimate-multisite
Length of output: 33946
🏁 Script executed:
Repository: Ultimate-Multisite/ultimate-multisite
Length of output: 10159
🏁 Script executed:
Repository: Ultimate-Multisite/ultimate-multisite
Length of output: 1826
🏁 Script executed:
Repository: Ultimate-Multisite/ultimate-multisite
Length of output: 334
🏁 Script executed:
Repository: Ultimate-Multisite/ultimate-multisite
Length of output: 136
🏁 Script executed:
Repository: Ultimate-Multisite/ultimate-multisite
Length of output: 227
🏁 Script executed:
Repository: Ultimate-Multisite/ultimate-multisite
Length of output: 1671
🏁 Script executed:
Repository: Ultimate-Multisite/ultimate-multisite
Length of output: 637
🏁 Script executed:
Repository: Ultimate-Multisite/ultimate-multisite
Length of output: 388
🏁 Script executed:
Repository: Ultimate-Multisite/ultimate-multisite
Length of output: 63
🏁 Script executed:
Repository: Ultimate-Multisite/ultimate-multisite
Length of output: 1594
🏁 Script executed:
Repository: Ultimate-Multisite/ultimate-multisite
Length of output: 873
🏁 Script executed:
Repository: Ultimate-Multisite/ultimate-multisite
Length of output: 151
🏁 Script executed:
Repository: Ultimate-Multisite/ultimate-multisite
Length of output: 2272
🏁 Script executed:
Repository: Ultimate-Multisite/ultimate-multisite
Length of output: 2116
🏁 Script executed:
Repository: Ultimate-Multisite/ultimate-multisite
Length of output: 337
🏁 Script executed:
Repository: Ultimate-Multisite/ultimate-multisite
Length of output: 3148
🏁 Script executed:
Repository: Ultimate-Multisite/ultimate-multisite
Length of output: 63
🏁 Script executed:
Repository: Ultimate-Multisite/ultimate-multisite
Length of output: 63
🏁 Script executed:
Repository: Ultimate-Multisite/ultimate-multisite
Length of output: 1304
🏁 Script executed:
Repository: Ultimate-Multisite/ultimate-multisite
Length of output: 1025
🏁 Script executed:
Repository: Ultimate-Multisite/ultimate-multisite
Length of output: 63
🏁 Script executed:
Repository: Ultimate-Multisite/ultimate-multisite
Length of output: 274
🏁 Script executed:
Repository: Ultimate-Multisite/ultimate-multisite
Length of output: 63
🏁 Script executed:
Repository: Ultimate-Multisite/ultimate-multisite
Length of output: 566
🏁 Script executed:
Repository: Ultimate-Multisite/ultimate-multisite
Length of output: 300
🏁 Script executed:
Repository: Ultimate-Multisite/ultimate-multisite
Length of output: 4440
Use the main site's admin-ajax.php for consistency with multisite handling patterns.
The AJAX handler is registered globally and the payments table is global, so requests technically work from subsite admin-ajax.php URLs. However, the codebase already uses
get_admin_url(wu_get_main_site_id(), 'admin-ajax.php')for similar AJAX operations in email and invoice template customization. Align this to use the main site's admin-ajax.php URL for consistency and to avoid potential future issues with site context.🤖 Prompt for AI Agents