Working flow authorize

This commit is contained in:
2025-09-16 12:45:42 -04:00
parent 3cf6d1911a
commit bd95e14bb3
8 changed files with 356 additions and 43 deletions

View File

@@ -201,16 +201,18 @@ export default defineComponent({
};
// --- STEP 2: CRITICAL CALL - SAVE CARD TO LOCAL DATABASE VIA FLASK ---
let card_id: number;
try {
const flaskPath = `${import.meta.env.VITE_BASE_URL}/payment/card/create/${this.customer.id}`;
console.log("Attempting to save card to local DB via Flask:", flaskPath);
const flaskResponse = await axios.post(flaskPath, flaskPayload, { withCredentials: true, headers: authHeader() });
if (!flaskResponse.data.ok) {
// If the primary save fails, stop everything and show an error.
throw new Error(flaskResponse.data.error || "Failed to save card.");
}
console.log("Card successfully saved to local database via Flask.");
card_id = flaskResponse.data.card_id;
console.log("Card successfully saved to local database via Flask with ID:", card_id);
} catch (error: any) {
const errorMessage = error.response?.data?.error || "A critical error occurred while saving the card.";
@@ -219,15 +221,24 @@ export default defineComponent({
return; // End the function here
}
// --- STEP 3: BEST-EFFORT CALL - TOKENIZE CARD VIA FASTAPI ---
// --- STEP 3: BEST-EFFORT CALL - TOKENIZE CARD VIA FASTAPI AND UPDATE LOCAL CARD ---
try {
const fastapiPath = `${import.meta.env.VITE_AUTHORIZE_URL}/api/payments/customers/${this.customer.id}/cards`;
console.log("Attempting to tokenize card with Authorize.Net via FastAPI:", fastapiPath);
await axios.post(fastapiPath, fastapiPayload, { withCredentials: true, headers: authHeader() });
const fastapiResponse = await axios.post(fastapiPath, fastapiPayload, { withCredentials: true, headers: authHeader() });
console.log("Card successfully tokenized with Authorize.Net via FastAPI.");
// --- STEP 4: UPDATE LOCAL CARD WITH PAYMENT_PROFILE_ID ---
const payment_profile_id = fastapiResponse.data.payment_profile_id;
console.log("Updating local card with payment_profile_id:", payment_profile_id);
const updatePath = `${import.meta.env.VITE_BASE_URL}/payment/card/update_payment_profile/${card_id}`;
await axios.put(updatePath, { auth_net_payment_profile_id: payment_profile_id }, { withCredentials: true, headers: authHeader() });
console.log("Card successfully updated with payment_profile_id.");
} catch (error: any) {
// If this fails, we just log it for the developers. We DON'T show an error to the user.
console.warn("NON-CRITICAL-ERROR: Tokenization with Authorize.Net failed, but the card was saved locally.", error.response?.data || error.message);
// Card is saved but without payment_profile_id, which is ok as nullable.
}
// --- STEP 4: ALWAYS SHOW SUCCESS AND REDIRECT ---
@@ -238,4 +249,4 @@ export default defineComponent({
},
},
});
</script>
</script>