-
-
Notifications
You must be signed in to change notification settings - Fork 75
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; | ||
| } | ||
| ' | ||
| ); | ||
|
||
| } | ||
| } | ||
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