Skip to content

Commit a4ec9f8

Browse files
committed
fix signup page
1 parent a6dc6d8 commit a4ec9f8

File tree

2 files changed

+47
-20
lines changed

2 files changed

+47
-20
lines changed

src/portal/CloudHealthOffice.Portal/Pages/Signup.razor

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,16 @@
129129
<div class="form-section">
130130
<h2>Payment Information</h2>
131131
<p class="payment-note">💳 Secure payment powered by Stripe. Your card will be charged after the 14-day trial.</p>
132-
132+
133133
<div class="form-group">
134134
<label for="card-element">Credit Card *</label>
135-
<div id="card-element" class="stripe-element">
135+
@if (!string.IsNullOrEmpty(_stripeInitError))
136+
{
137+
<div class="alert alert-warning mt-2">
138+
<strong>Payment system unavailable:</strong> @_stripeInitError
139+
</div>
140+
}
141+
<div id="card-element" class="stripe-element" style="@(!string.IsNullOrEmpty(_stripeInitError) ? "display:none" : "")">
136142
<!-- Stripe Element will be inserted here -->
137143
</div>
138144
<div id="card-errors" class="payment-error" role="alert"></div>
@@ -161,7 +167,7 @@
161167

162168
<div class="alert alert-info mt-3">
163169
<strong>14-Day Free Trial</strong><br/>
164-
Start using the platform immediately. Your card won't be charged until February 23, 2026.
170+
Start using the platform immediately. Your card won't be charged until @DateTime.Now.AddDays(14).ToString("MMMM d, yyyy").
165171
</div>
166172
</div>
167173

@@ -170,7 +176,7 @@
170176
<div class="alert alert-danger">@errorMessage</div>
171177
}
172178

173-
<button type="submit" class="btn btn-primary btn-lg" disabled="@isSubmitting">
179+
<button type="submit" class="btn btn-primary btn-lg" disabled="@(isSubmitting || !string.IsNullOrEmpty(_stripeInitError))">
174180
@if (isSubmitting)
175181
{
176182
<span>Creating account...</span>
@@ -228,6 +234,8 @@
228234
private bool enableAttachments = false;
229235
private bool enableEnrollment = false;
230236

237+
private string? _stripeInitError;
238+
231239
protected override async Task OnAfterRenderAsync(bool firstRender)
232240
{
233241
if (firstRender)
@@ -240,13 +248,32 @@
240248
{
241249
try
242250
{
243-
var stripePublishableKey = Configuration["Stripe:PublishableKey"] ?? "pk_test_placeholder";
244-
await JSRuntime.InvokeVoidAsync("StripeHandler.initialize", stripePublishableKey);
245-
Logger.LogInformation("Stripe initialized successfully");
251+
var stripePublishableKey = Configuration["Stripe:PublishableKey"];
252+
if (string.IsNullOrEmpty(stripePublishableKey))
253+
{
254+
_stripeInitError = "Payment system is not configured. Please contact support@cloudhealthoffice.com.";
255+
Logger.LogError("Stripe:PublishableKey is not configured");
256+
StateHasChanged();
257+
return;
258+
}
259+
260+
var initError = await JSRuntime.InvokeAsync<string?>("StripeHandler.initialize", stripePublishableKey);
261+
if (initError != null)
262+
{
263+
_stripeInitError = initError;
264+
Logger.LogError("Stripe initialization failed: {Error}", initError);
265+
StateHasChanged();
266+
}
267+
else
268+
{
269+
Logger.LogInformation("Stripe initialized successfully");
270+
}
246271
}
247272
catch (Exception ex)
248273
{
274+
_stripeInitError = "Failed to load payment form. Please refresh the page and try again.";
249275
Logger.LogError(ex, "Failed to initialize Stripe");
276+
StateHasChanged();
250277
}
251278
}
252279

src/portal/CloudHealthOffice.Portal/wwwroot/js/stripe-handler.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,23 @@ window.StripeHandler = {
44
cardElement: null,
55

66
initialize: function(publishableKey) {
7-
//console.log('Initializing Stripe with key:', publishableKey.substring(0, 10) + '...');
8-
97
// Check if Stripe is already loaded
108
if (typeof Stripe === 'undefined') {
119
console.error('Stripe.js not loaded');
12-
return;
10+
return 'Stripe.js failed to load. Please disable any ad blockers and reload the page.';
1311
}
1412

1513
// Initialize Stripe only once
1614
if (!this.stripe) {
17-
this.stripe = Stripe(publishableKey);
15+
try {
16+
this.stripe = Stripe(publishableKey);
17+
} catch (ex) {
18+
console.error('Stripe() constructor failed:', ex);
19+
return 'Payment system could not be initialized: ' + ex.message;
20+
}
21+
1822
const elements = this.stripe.elements();
19-
23+
2024
this.cardElement = elements.create('card', {
2125
style: {
2226
base: {
@@ -32,25 +36,21 @@ window.StripeHandler = {
3236
const cardElementDiv = document.getElementById('card-element');
3337
if (cardElementDiv) {
3438
this.cardElement.mount('#card-element');
35-
console.log('Card element mounted successfully');
3639
} else {
3740
console.error('Card element div not found');
41+
return 'Payment form element not found. Please reload the page.';
3842
}
3943

4044
// Listen for card validation errors
4145
this.cardElement.on('change', function(event) {
4246
const displayError = document.getElementById('card-errors');
4347
if (displayError) {
44-
if (event.error) {
45-
displayError.textContent = event.error.message;
46-
} else {
47-
displayError.textContent = '';
48-
}
48+
displayError.textContent = event.error ? event.error.message : '';
4949
}
5050
});
51-
} else {
52-
console.log('Stripe already initialized');
5351
}
52+
53+
return null; // null = success
5454
},
5555

5656
createPaymentMethod: async function(name, email) {

0 commit comments

Comments
 (0)