- Fix Google Wallet class creation: add required issuerName field (merchant name), programLogo with default logo fallback, hexBackgroundColor default - Add default loyalty logo assets (200px + 512px) for programs without custom logos - Smart retry: skip retries on 400/401/403/404 client errors (not transient) - Fix enrollment success page: use sessionStorage for wallet URLs instead of authenticated API call (self-enrolled customers have no session) - Hide wallet section on success page when no wallet URLs available - Wire up T&C modal on enrollment page with program.terms_text - Add startup validation for Google/Apple Wallet configs in lifespan - Add admin wallet status dashboard endpoint and UI (moved to service layer) - Fix Apple Wallet push notifications with real APNs HTTP/2 implementation - Fix docs: correct enrollment URLs (port, path segments, /v1 prefix) - Fix test assertion: !loyalty-enroll! → !enrollment! Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
102 lines
3.5 KiB
JavaScript
102 lines
3.5 KiB
JavaScript
// app/modules/loyalty/static/storefront/js/loyalty-enroll.js
|
|
// Self-service loyalty enrollment
|
|
|
|
function customerLoyaltyEnroll() {
|
|
return {
|
|
...storefrontLayoutData(),
|
|
|
|
// Program info
|
|
program: null,
|
|
|
|
// Form data
|
|
form: {
|
|
email: '',
|
|
first_name: '',
|
|
last_name: '',
|
|
phone: '',
|
|
birthday: '',
|
|
terms_accepted: false,
|
|
marketing_consent: false
|
|
},
|
|
|
|
// State
|
|
loading: false,
|
|
enrolling: false,
|
|
enrolled: false,
|
|
enrolledCard: null,
|
|
error: null,
|
|
showTerms: false,
|
|
|
|
async init() {
|
|
console.log('Customer loyalty enroll initializing...');
|
|
await this.loadProgram();
|
|
},
|
|
|
|
async loadProgram() {
|
|
this.loading = true;
|
|
try {
|
|
const response = await apiClient.get('/storefront/loyalty/program');
|
|
if (response) {
|
|
this.program = response;
|
|
console.log('Program loaded:', this.program.display_name);
|
|
}
|
|
} catch (error) {
|
|
if (error.status === 404) {
|
|
console.log('No loyalty program available');
|
|
this.program = null;
|
|
} else {
|
|
console.error('Failed to load program:', error);
|
|
this.error = 'Failed to load program information';
|
|
}
|
|
} finally {
|
|
this.loading = false;
|
|
}
|
|
},
|
|
|
|
async submitEnrollment() {
|
|
if (!this.form.email || !this.form.first_name || !this.form.terms_accepted) {
|
|
return;
|
|
}
|
|
|
|
this.enrolling = true;
|
|
this.error = null;
|
|
|
|
try {
|
|
const response = await apiClient.post('/storefront/loyalty/enroll', {
|
|
email: this.form.email,
|
|
customer_name: [this.form.first_name, this.form.last_name].filter(Boolean).join(' '),
|
|
customer_phone: this.form.phone || null,
|
|
customer_birthday: this.form.birthday || null,
|
|
marketing_email_consent: this.form.marketing_consent,
|
|
marketing_sms_consent: this.form.marketing_consent
|
|
});
|
|
|
|
if (response) {
|
|
const cardNumber = response.card?.card_number || response.card_number;
|
|
console.log('Enrollment successful:', cardNumber);
|
|
|
|
// Store wallet URLs for the success page (no auth needed)
|
|
if (response.wallet_urls) {
|
|
sessionStorage.setItem('loyalty_wallet_urls', JSON.stringify(response.wallet_urls));
|
|
}
|
|
|
|
// Redirect to success page
|
|
const currentPath = window.location.pathname;
|
|
const successUrl = currentPath.replace(/\/join\/?$/, '/join/success') +
|
|
'?card=' + encodeURIComponent(cardNumber);
|
|
window.location.href = successUrl;
|
|
}
|
|
} catch (error) {
|
|
console.error('Enrollment failed:', error);
|
|
if (error.message?.includes('already')) {
|
|
this.error = 'This email is already registered in our loyalty program.';
|
|
} else {
|
|
this.error = error.message || 'Enrollment failed. Please try again.';
|
|
}
|
|
} finally {
|
|
this.enrolling = false;
|
|
}
|
|
}
|
|
};
|
|
}
|