Skip to content

Commit

Permalink
feat: error when post fails in local pay
Browse files Browse the repository at this point in the history
  • Loading branch information
BlairCurrey committed Oct 31, 2024
1 parent 86f6db6 commit 3fc6924
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
41 changes: 40 additions & 1 deletion packages/backend/src/payment-method/local/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { WalletAddress } from '../../open_payments/wallet_address/model'

import { createReceiver } from '../../tests/receiver'
import { mockRatesApi } from '../../tests/rates'
import { AccountingService } from '../../accounting/service'
import { AccountingService, Transaction } from '../../accounting/service'
import { truncateTables } from '../../tests/tableManager'
import { createOutgoingPaymentWithReceiver } from '../../tests/outgoingPayment'
import { OutgoingPayment } from '../../open_payments/payment/outgoing/model'
Expand Down Expand Up @@ -610,5 +610,44 @@ describe('LocalPaymentService', (): void => {
expect((err as PaymentMethodHandlerError).retryable).toBe(false)
}
})

test('throws error when transfer post fails', async (): Promise<void> => {
const { receiver, outgoingPayment } =
await createOutgoingPaymentWithReceiver(deps, {
sendingWalletAddress: walletAddressMap['USD'],
receivingWalletAddress: walletAddressMap['USD'],
method: 'ilp',
quoteOptions: {
debitAmount: {
value: 100n,
assetScale: walletAddressMap['USD'].asset.scale,
assetCode: walletAddressMap['USD'].asset.code
}
}
})

jest.spyOn(accountingService, 'createTransfer').mockResolvedValueOnce({
post: () => Promise.resolve(TransferError.UnknownTransfer)
} as Transaction)

expect.assertions(4)
try {
await localPaymentService.pay({
receiver,
outgoingPayment,
finalDebitAmount: 100n,
finalReceiveAmount: 100n
})
} catch (err) {
expect(err).toBeInstanceOf(PaymentMethodHandlerError)
expect((err as PaymentMethodHandlerError).message).toBe(
'Received error during local payment'
)
expect((err as PaymentMethodHandlerError).description).toBe(
errorToMessage[TransferError.UnknownTransfer]
)
expect((err as PaymentMethodHandlerError).retryable).toBe(false)
}
})
})
})
9 changes: 8 additions & 1 deletion packages/backend/src/payment-method/local/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,5 +284,12 @@ async function pay(
)
}
}
await trxOrError.post()
const transferError = await trxOrError.post()

if (isTransferError(transferError)) {
throw new PaymentMethodHandlerError('Received error during local payment', {
description: errorToMessage[transferError],
retryable: false
})
}
}

0 comments on commit 3fc6924

Please sign in to comment.