feat(payments): persist helcimCustomerCode + skip getOrCreateCustomer on card-on-file
This commit is contained in:
parent
134aef6ab0
commit
4442c57223
10 changed files with 330 additions and 33 deletions
|
|
@ -18,6 +18,13 @@ export default defineEventHandler(async (event) => {
|
|||
try {
|
||||
const customer = await getHelcimCustomer(member.helcimCustomerId)
|
||||
if (customer?.id) {
|
||||
if (!member.helcimCustomerCode && customer.customerCode) {
|
||||
await Member.findByIdAndUpdate(
|
||||
member._id,
|
||||
{ $set: { helcimCustomerCode: customer.customerCode } },
|
||||
{ runValidators: false }
|
||||
)
|
||||
}
|
||||
return {
|
||||
success: true,
|
||||
customerId: customer.id,
|
||||
|
|
@ -49,10 +56,13 @@ export default defineEventHandler(async (event) => {
|
|||
}
|
||||
|
||||
if (existingCustomer) {
|
||||
if (!member.helcimCustomerId) {
|
||||
if (!member.helcimCustomerId || !member.helcimCustomerCode) {
|
||||
await Member.findByIdAndUpdate(
|
||||
member._id,
|
||||
{ $set: { helcimCustomerId: existingCustomer.id } },
|
||||
{ $set: {
|
||||
helcimCustomerId: existingCustomer.id,
|
||||
helcimCustomerCode: existingCustomer.customerCode
|
||||
} },
|
||||
{ runValidators: false }
|
||||
)
|
||||
}
|
||||
|
|
@ -73,7 +83,10 @@ export default defineEventHandler(async (event) => {
|
|||
|
||||
await Member.findByIdAndUpdate(
|
||||
member._id,
|
||||
{ $set: { helcimCustomerId: customerData.id } },
|
||||
{ $set: {
|
||||
helcimCustomerId: customerData.id,
|
||||
helcimCustomerCode: customerData.customerCode
|
||||
} },
|
||||
{ runValidators: false }
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue