fix(helcim): skip HelcimPay verify when a card is already on file
Helcim refuses paymentType:'verify' for cards already saved on a
customer ("A new card must be entered for saving the payment method"),
breaking every "Complete Payment" retry after a partial-failed signup.
Add GET /api/helcim/existing-card and short-circuit HelcimPay verify in
useMemberPayment + payment-setup.vue when a saved card is found, going
straight to subscription creation. The two existence-check fetches run
in parallel with get-or-create-customer so no extra round-trip latency
in the common path.
This commit is contained in:
parent
e3410c52a5
commit
0f841912e2
4 changed files with 201 additions and 42 deletions
25
server/api/helcim/existing-card.get.js
Normal file
25
server/api/helcim/existing-card.get.js
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
// Returns the saved cardToken so callers can skip HelcimPay re-entry.
|
||||
import { requireAuth } from '../../utils/auth.js'
|
||||
import { listHelcimCustomerCards } from '../../utils/helcim.js'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const member = await requireAuth(event)
|
||||
|
||||
if (!member.helcimCustomerId) {
|
||||
return { cardToken: null }
|
||||
}
|
||||
|
||||
const cardsResponse = await listHelcimCustomerCards(member.helcimCustomerId)
|
||||
const cards = Array.isArray(cardsResponse)
|
||||
? cardsResponse
|
||||
: (cardsResponse?.cards || cardsResponse?.data || [])
|
||||
|
||||
if (!cards.length) {
|
||||
return { cardToken: null }
|
||||
}
|
||||
|
||||
const defaultCard =
|
||||
cards.find((c) => c?.default === true || c?.isDefault === true) || cards[0]
|
||||
|
||||
return { cardToken: defaultCard?.cardToken || null }
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue