Stripe error handling and now you can rent an item for a different time while having an upcoming or active rental
This commit is contained in:
@@ -882,7 +882,7 @@ describe('StripeService', () => {
|
||||
|
||||
expect(mockStripeCheckoutSessionsCreate).toHaveBeenCalledWith({
|
||||
customer: 'cus_123456789',
|
||||
payment_method_types: ['card', 'us_bank_account', 'link'],
|
||||
payment_method_types: ['card', 'link'],
|
||||
mode: 'setup',
|
||||
ui_mode: 'embedded',
|
||||
redirect_on_completion: 'never',
|
||||
@@ -915,7 +915,7 @@ describe('StripeService', () => {
|
||||
|
||||
expect(mockStripeCheckoutSessionsCreate).toHaveBeenCalledWith({
|
||||
customer: 'cus_123456789',
|
||||
payment_method_types: ['card', 'us_bank_account', 'link'],
|
||||
payment_method_types: ['card', 'link'],
|
||||
mode: 'setup',
|
||||
ui_mode: 'embedded',
|
||||
redirect_on_completion: 'never',
|
||||
|
||||
@@ -21,42 +21,6 @@ describe('Stripe Errors Utility', () => {
|
||||
}
|
||||
});
|
||||
|
||||
describe('ACH decline codes', () => {
|
||||
const achCodes = [
|
||||
'bank_account_closed',
|
||||
'bank_account_frozen',
|
||||
'bank_account_restricted',
|
||||
'bank_account_unusable',
|
||||
'bank_account_invalid_details',
|
||||
'debit_not_authorized',
|
||||
];
|
||||
|
||||
test.each(achCodes)('%s exists in DECLINE_MESSAGES', (code) => {
|
||||
expect(DECLINE_MESSAGES).toHaveProperty(code);
|
||||
});
|
||||
|
||||
test.each(achCodes)('%s has all required properties', (code) => {
|
||||
const messages = DECLINE_MESSAGES[code];
|
||||
expect(messages).toHaveProperty('ownerMessage');
|
||||
expect(messages).toHaveProperty('renterMessage');
|
||||
expect(messages).toHaveProperty('canOwnerRetry');
|
||||
expect(messages).toHaveProperty('requiresNewPaymentMethod');
|
||||
});
|
||||
|
||||
test.each(achCodes)('%s requires new payment method', (code) => {
|
||||
expect(DECLINE_MESSAGES[code].requiresNewPaymentMethod).toBe(true);
|
||||
});
|
||||
|
||||
test.each(achCodes)('%s does not allow owner retry', (code) => {
|
||||
expect(DECLINE_MESSAGES[code].canOwnerRetry).toBe(false);
|
||||
});
|
||||
|
||||
test.each(achCodes)('%s has non-empty messages', (code) => {
|
||||
expect(DECLINE_MESSAGES[code].ownerMessage.length).toBeGreaterThan(0);
|
||||
expect(DECLINE_MESSAGES[code].renterMessage.length).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Additional card decline codes', () => {
|
||||
const additionalCardCodes = [
|
||||
'call_issuer',
|
||||
@@ -189,51 +153,6 @@ describe('Stripe Errors Utility', () => {
|
||||
expect(result.canOwnerRetry).toBe(true);
|
||||
});
|
||||
|
||||
test('parses ACH decline error - bank_account_closed', () => {
|
||||
const error = {
|
||||
type: 'StripeCardError',
|
||||
code: 'card_declined',
|
||||
decline_code: 'bank_account_closed',
|
||||
message: 'The bank account has been closed.',
|
||||
};
|
||||
|
||||
const result = parseStripeError(error);
|
||||
|
||||
expect(result.code).toBe('bank_account_closed');
|
||||
expect(result.ownerMessage).toBe("The renter's bank account has been closed.");
|
||||
expect(result.renterMessage).toBe('Your bank account has been closed. Please add a different payment method.');
|
||||
expect(result.requiresNewPaymentMethod).toBe(true);
|
||||
});
|
||||
|
||||
test('parses ACH decline error - bank_account_frozen', () => {
|
||||
const error = {
|
||||
type: 'StripeCardError',
|
||||
code: 'card_declined',
|
||||
decline_code: 'bank_account_frozen',
|
||||
message: 'The bank account is frozen.',
|
||||
};
|
||||
|
||||
const result = parseStripeError(error);
|
||||
|
||||
expect(result.code).toBe('bank_account_frozen');
|
||||
expect(result.ownerMessage).toBe("The renter's bank account is frozen.");
|
||||
expect(result.renterMessage).toContain('frozen');
|
||||
});
|
||||
|
||||
test('parses ACH decline error - debit_not_authorized', () => {
|
||||
const error = {
|
||||
type: 'StripeCardError',
|
||||
code: 'card_declined',
|
||||
decline_code: 'debit_not_authorized',
|
||||
message: 'Debit not authorized.',
|
||||
};
|
||||
|
||||
const result = parseStripeError(error);
|
||||
|
||||
expect(result.code).toBe('debit_not_authorized');
|
||||
expect(result.renterMessage).toContain('not authorized');
|
||||
});
|
||||
|
||||
test('returns default error for unknown decline code', () => {
|
||||
const error = {
|
||||
type: 'StripeCardError',
|
||||
@@ -279,7 +198,7 @@ describe('Stripe Errors Utility', () => {
|
||||
const error = {
|
||||
type: 'StripeCardError',
|
||||
code: 'card_declined',
|
||||
decline_code: 'bank_account_frozen',
|
||||
decline_code: 'insufficient_funds',
|
||||
message: 'Original Stripe message',
|
||||
};
|
||||
|
||||
@@ -293,11 +212,11 @@ describe('Stripe Errors Utility', () => {
|
||||
describe('PaymentError', () => {
|
||||
test('creates PaymentError with all properties', () => {
|
||||
const parsedError = {
|
||||
code: 'bank_account_frozen',
|
||||
ownerMessage: "The renter's bank account is frozen.",
|
||||
renterMessage: 'Your bank account is frozen.',
|
||||
code: 'insufficient_funds',
|
||||
ownerMessage: "The renter's card has insufficient funds.",
|
||||
renterMessage: 'Your card has insufficient funds.',
|
||||
canOwnerRetry: false,
|
||||
requiresNewPaymentMethod: true,
|
||||
requiresNewPaymentMethod: false,
|
||||
_originalMessage: 'Original message',
|
||||
_stripeCode: 'card_declined',
|
||||
};
|
||||
@@ -306,17 +225,17 @@ describe('Stripe Errors Utility', () => {
|
||||
|
||||
expect(error).toBeInstanceOf(Error);
|
||||
expect(error.name).toBe('PaymentError');
|
||||
expect(error.code).toBe('bank_account_frozen');
|
||||
expect(error.ownerMessage).toBe("The renter's bank account is frozen.");
|
||||
expect(error.renterMessage).toBe('Your bank account is frozen.');
|
||||
expect(error.requiresNewPaymentMethod).toBe(true);
|
||||
expect(error.code).toBe('insufficient_funds');
|
||||
expect(error.ownerMessage).toBe("The renter's card has insufficient funds.");
|
||||
expect(error.renterMessage).toBe('Your card has insufficient funds.');
|
||||
expect(error.requiresNewPaymentMethod).toBe(false);
|
||||
});
|
||||
|
||||
test('toJSON returns serializable object', () => {
|
||||
const parsedError = {
|
||||
code: 'bank_account_closed',
|
||||
ownerMessage: "The renter's bank account has been closed.",
|
||||
renterMessage: 'Your bank account has been closed.',
|
||||
code: 'expired_card',
|
||||
ownerMessage: "The renter's card has expired.",
|
||||
renterMessage: 'Your card has expired.',
|
||||
canOwnerRetry: false,
|
||||
requiresNewPaymentMethod: true,
|
||||
_originalMessage: 'Should not appear',
|
||||
@@ -326,7 +245,7 @@ describe('Stripe Errors Utility', () => {
|
||||
const error = new PaymentError(parsedError);
|
||||
const json = error.toJSON();
|
||||
|
||||
expect(json).toHaveProperty('code', 'bank_account_closed');
|
||||
expect(json).toHaveProperty('code', 'expired_card');
|
||||
expect(json).toHaveProperty('ownerMessage');
|
||||
expect(json).toHaveProperty('renterMessage');
|
||||
expect(json).not.toHaveProperty('_originalMessage');
|
||||
|
||||
Reference in New Issue
Block a user