Skip to content

Commit

Permalink
refactor(locksmith): no need to throw errors when renewing fiat keys
Browse files Browse the repository at this point in the history
  • Loading branch information
julien51 committed Dec 13, 2023
1 parent 2235f53 commit 5a37ea6
Showing 1 changed file with 48 additions and 6 deletions.
54 changes: 48 additions & 6 deletions locksmith/src/worker/helpers/renewFiatKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,25 @@ export async function renewFiatKey({
)

if (!stripeEnabled) {
throw new Error('Stripe connect is not enabled')
logger.info(
`Stripe connect is not enabled for lock ${lockAddress} on ${network}`
)
return {
keyId,
lockAddress,
network,
}
}

if (!stripeAccount) {
throw new Error('No stripe connect account associated with the lock')
logger.info(
`No stripe connect account associated with the lock ${lockAddress} on ${network}`
)
return {
keyId,
lockAddress,
network,
}
}

const subscription = await KeySubscription.findOne({
Expand All @@ -61,11 +75,25 @@ export async function renewFiatKey({
})

if (!subscription) {
throw new Error('No subscription found')
logger.info(
`No subscription found for key ${keyId} on ${lockAddress} on network ${network}`
)
return {
keyId,
lockAddress,
network,
}
}

if (subscription.userAddress !== userAddress) {
throw new Error('Key owner is not the subscriber')
logger.info(
`Key owner is not the subscriber key ${keyId} on ${lockAddress} on network ${network}`
)
return {
keyId,
lockAddress,
network,
}
}

const customer = await stripe.customers.retrieve(
Expand All @@ -76,7 +104,14 @@ export async function renewFiatKey({
)

if (customer.deleted) {
throw new Error('Customer does not exist anymore')
logger.info(
`Customer does not exist anymore for key ${keyId} on ${lockAddress} on network ${network}`
)
return {
keyId,
lockAddress,
network,
}
}

const paymentMethod = await stripe.paymentMethods.list(
Expand All @@ -92,7 +127,14 @@ export async function renewFiatKey({
const paymentMethodId = paymentMethod.data?.[0]?.id

if (!paymentMethodId) {
throw new Error('No payment method available on the customer profile.')
logger.info(
`No payment method available on the customer profile for key ${keyId} on ${lockAddress} on network ${network}`
)
return {
keyId,
lockAddress,
network,
}
}

const web3Service = new Web3Service(networks)
Expand Down

0 comments on commit 5a37ea6

Please sign in to comment.