Skip to content

Commit c32fdde

Browse files
authored
feat(backend): optional debitAmount increateOutgoingPaymentFromIncomingPayment mutation (#3631)
* feat(backend): make debitAmount optional in createOutgoingPaymentFromIncomingPayment mutation * feat(backend): allow creating outgoing payment from incoming payment without debitAmount
1 parent f1375f3 commit c32fdde

File tree

10 files changed

+17
-21
lines changed

10 files changed

+17
-21
lines changed

localenv/mock-account-servicing-entity/generated/graphql.ts

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/backend/src/graphql/generated/graphql.schema.json

Lines changed: 3 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/backend/src/graphql/generated/graphql.ts

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/backend/src/graphql/schema.graphql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1246,7 +1246,7 @@ input CreateOutgoingPaymentFromIncomingPaymentInput {
12461246
"Incoming payment URL to create the outgoing payment from."
12471247
incomingPayment: String!
12481248
"Amount to send (fixed send)."
1249-
debitAmount: AmountInput!
1249+
debitAmount: AmountInput
12501250
"Additional metadata associated with the outgoing payment."
12511251
metadata: JSONObject
12521252
"Unique key to ensure duplicate or retried requests are processed only once. For more information, refer to [idempotency](https://rafiki.dev/apis/graphql/admin-api-overview/#idempotency)."

packages/backend/src/open_payments/payment/outgoing/service.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ export interface CreateFromQuote extends BaseOptions {
196196
}
197197
export interface CreateFromIncomingPayment extends BaseOptions {
198198
incomingPayment: string
199-
debitAmount: Amount
199+
debitAmount?: Amount
200200
}
201201

202202
export type CancelOutgoingPaymentOptions = {
@@ -212,7 +212,7 @@ export type CreateOutgoingPaymentOptions =
212212
export function isCreateFromIncomingPayment(
213213
options: CreateOutgoingPaymentOptions
214214
): options is CreateFromIncomingPayment {
215-
return 'incomingPayment' in options && 'debitAmount' in options
215+
return 'incomingPayment' in options
216216
}
217217

218218
async function cancelOutgoingPayment(
@@ -282,11 +282,10 @@ async function createOutgoingPayment(
282282
description: 'Time to create a quote in outgoing payment'
283283
}
284284
)
285-
const { debitAmount, incomingPayment } = options
286285
const quoteOrError = await deps.quoteService.create({
287286
tenantId,
288-
receiver: incomingPayment,
289-
debitAmount,
287+
receiver: options.incomingPayment,
288+
debitAmount: options.debitAmount,
290289
method: 'ilp',
291290
walletAddressId
292291
})

packages/backend/src/open_payments/quote/service.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ describe('QuoteService', (): void => {
205205
if (!debitAmount && !receiveAmount && !incomingAmount) {
206206
test('fails without receiver.incomingAmount', async (): Promise<void> => {
207207
await expect(quoteService.create(options)).resolves.toMatchObject({
208-
type: QuoteErrorCode.InvalidReceiver
208+
type: QuoteErrorCode.InvalidAmount
209209
})
210210
})
211211
} else {
@@ -552,6 +552,7 @@ describe('QuoteService', (): void => {
552552

553553
test.each`
554554
debitAmount | receiveAmount | description
555+
${undefined} | ${undefined} | ${'with undefined debitAmount and receiveAmount'}
555556
${{ ...debitAmount, value: BigInt(0) }} | ${undefined} | ${'with debitAmount of zero'}
556557
${{ ...debitAmount, value: BigInt(-1) }} | ${undefined} | ${'with negative debitAmount'}
557558
${{ ...debitAmount, assetScale: 3 }} | ${undefined} | ${'with wrong debitAmount asset'}

packages/backend/src/open_payments/quote/service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,9 @@ export async function resolveReceiver(
345345
debitAmount: options.debitAmount,
346346
incomingAmount: receiver.incomingAmount
347347
},
348-
'Could not create quote. debitAmount or incomingAmount required.'
348+
'Could not create quote. One of receiveAmount, debitAmount or incomingAmount (on the incoming payment) is required.'
349349
)
350-
throw new QuoteError(QuoteErrorCode.InvalidReceiver)
350+
throw new QuoteError(QuoteErrorCode.InvalidAmount)
351351
}
352352
return receiver
353353
}

packages/frontend/app/generated/graphql.ts

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/mock-account-service-lib/src/generated/graphql.ts

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/test-lib/src/generated/graphql.ts

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)