Skip to content

Commit

Permalink
fix unexpected payment_error
Browse files Browse the repository at this point in the history
  • Loading branch information
juliangruber committed Mar 12, 2019
1 parent 6bcb865 commit c6cda40
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/commands/alias/set.ts
Expand Up @@ -348,7 +348,15 @@ function handleSetupDomainError<T>(

if (error instanceof ERRORS.SourceNotFound) {
output.error(
`You can't purchase the domain your aliasing to since you have no valid payment method.`
`You can't purchase the domain you're aliasing to since you have no valid payment method.`
);
output.print(` Please add a valid payment method and retry.\n`);
return 1;
}

if (error instanceof ERRORS.DomainPaymentError) {
output.error(
`You can't purchase the domain you're aliasing to since your card was declined.`
);
output.print(` Please add a valid payment method and retry.\n`);
return 1;
Expand Down
5 changes: 5 additions & 0 deletions src/commands/domains/buy.ts
Expand Up @@ -135,6 +135,11 @@ export default async function buy(
return 1;
}

if (buyResult instanceof ERRORS.DomainPaymentError) {
output.error(`Your card was declined.`);
return 1;
}

if (buyResult.pending) {
console.log(
`${chalk.cyan('> Success!')} Domain ${param(
Expand Down
1 change: 1 addition & 0 deletions src/util/alias/assign-alias.ts
Expand Up @@ -106,6 +106,7 @@ export default async function assignAlias(
result instanceof ERRORS.InvalidDomain ||
result instanceof ERRORS.SourceNotFound ||
result instanceof ERRORS.UnexpectedDomainPurchaseError ||
result instanceof ERRORS.DomainPaymentError ||
result instanceof ERRORS.UnsupportedTLD ||
result instanceof ERRORS.UserAborted
) {
Expand Down
1 change: 1 addition & 0 deletions src/util/alias/upsert-path-alias.ts
Expand Up @@ -37,6 +37,7 @@ export default async function upsertPathAlias(
domainInfo instanceof ERRORS.InvalidDomain ||
domainInfo instanceof ERRORS.SourceNotFound ||
domainInfo instanceof ERRORS.UnexpectedDomainPurchaseError ||
domainInfo instanceof ERRORS.DomainPaymentError ||
domainInfo instanceof ERRORS.UnsupportedTLD ||
domainInfo instanceof ERRORS.UserAborted
) {
Expand Down
3 changes: 2 additions & 1 deletion src/util/domains/purchase-domain-if-available.ts
Expand Up @@ -62,7 +62,8 @@ export default async function purchaseDomainIfAvailable(
result instanceof ERRORS.DomainNotAvailable ||
result instanceof ERRORS.DomainServiceNotAvailable ||
result instanceof ERRORS.InvalidDomain ||
result instanceof ERRORS.UnexpectedDomainPurchaseError
result instanceof ERRORS.UnexpectedDomainPurchaseError ||
result instanceof ERRORS.DomainPaymentError
) {
return result;
}
Expand Down
3 changes: 3 additions & 0 deletions src/util/domains/purchase-domain.ts
Expand Up @@ -35,6 +35,9 @@ export default async function purchaseDomain(
if (error.code === 'source_not_found') {
return new ERRORS.SourceNotFound();
}
if (error.code === 'payment_error') {
return new ERRORS.DomainPaymentError();
}
throw error;
}
}
13 changes: 13 additions & 0 deletions src/util/errors-ts.ts
Expand Up @@ -338,6 +338,19 @@ export class UnexpectedDomainPurchaseError extends NowError<
}
}

/**
* Returned when there is an expected error charging the card.
*/
export class DomainPaymentError extends NowError<'DOMAIN_PAYMENT_ERROR', {}> {
constructor() {
super({
code: 'DOMAIN_PAYMENT_ERROR',
meta: {},
message: `Your card was declined.`
});
}
}

/**
* Returned during purchase in alias when the domain was purchased but the
* order is pending so the alias can't be completed yet
Expand Down

0 comments on commit c6cda40

Please sign in to comment.