diff --git a/.changeset/tender-ravens-breathe.md b/.changeset/tender-ravens-breathe.md new file mode 100644 index 00000000..192d146f --- /dev/null +++ b/.changeset/tender-ravens-breathe.md @@ -0,0 +1,5 @@ +--- +'@interledger/open-payments': major +--- + +Adding properties for new quoting mechanism diff --git a/openapi/auth-server.yaml b/openapi/auth-server.yaml index 7da138aa..f04009ee 100644 --- a/openapi/auth-server.yaml +++ b/openapi/auth-server.yaml @@ -1,7 +1,7 @@ openapi: 3.1.0 info: title: Open Payments Authorization Server - version: '1.0' + version: '1.1' license: name: Apache 2.0 identifier: Apache-2.0 @@ -112,7 +112,7 @@ paths: limits: receiver: 'https://openpayments.guide/connections/45a0d0ee-26dc-4c66-89e0-01fbf93156f7' interval: 'R12/2019-08-24T14:15:22Z/P1M' - sendAmount: + debitAmount: value: '500' assetCode: USD assetScale: 2 @@ -180,7 +180,7 @@ paths: limits: receiver: 'https://openpayments.guide/bob/incoming-payments/48884225-b393-4872-90de-1b737e2491c2' interval: 'R12/2019-08-24T14:15:22Z/P1M' - sendAmount: + debitAmount: value: '500' assetCode: USD assetScale: 2 @@ -275,7 +275,7 @@ paths: limits: interval: 'R12/2019-08-24T14:15:22Z/P1M' receiver: 'https://openpayments.guide/bob/incoming-payments/48884225-b393-4872-90de-1b737e2491c2' - sendAmount: + debitAmount: value: '500' assetCode: USD assetScale: 2 @@ -515,9 +515,11 @@ components: properties: receiver: $ref: './schemas.yaml#/components/schemas/receiver' - sendAmount: + debitAmount: + description: 'All amounts are maxima, i.e. multiple payments can be created under a grant as long as the total amounts of these payments do not exceed the maximum amount per interval as specified in the grant.' $ref: './schemas.yaml#/components/schemas/amount' receiveAmount: + description: 'All amounts are maxima, i.e. multiple payments can be created under a grant as long as the total amounts of these payments do not exceed the maximum amount per interval as specified in the grant.' $ref: './schemas.yaml#/components/schemas/amount' interval: $ref: '#/components/schemas/interval' @@ -526,7 +528,7 @@ components: required: - interval - required: - - sendAmount + - debitAmount - required: - receiveAmount securitySchemes: diff --git a/openapi/resource-server.yaml b/openapi/resource-server.yaml index 3520ec6d..fcfe71a0 100644 --- a/openapi/resource-server.yaml +++ b/openapi/resource-server.yaml @@ -1,7 +1,7 @@ openapi: 3.1.0 info: title: Open Payments - version: '1.1' + version: '1.2' license: name: Apache 2.0 identifier: Apache-2.0 @@ -36,12 +36,12 @@ servers: description: 'Server for when Payment Pointer has a pathname (ie https://openpayments.guide/alice)' variables: paymentPointer: - default: openpayments.guide/alice + default: https://openpayments.guide/alice - url: '{paymentPointer}/.well-known/pay' description: 'Server for when Payment Pointer has no pathname (ie https://openpayments.guide)' variables: paymentPointer: - default: openpayments.guide + default: https://openpayments.guide tags: - name: payment-pointer description: payment pointer operations @@ -167,7 +167,8 @@ paths: assetScale: 2 completed: false expiresAt: '2022-02-03T23:20:50.52Z' - metadata: { externalRef: 'INV2022-02-0137' } + metadata: + externalRef: INV2022-02-0137 ilpStreamConnection: id: 'https://openpayments.guide/connections/ff394f02-7b7b-45e2-b645-51d04e7c345c' ilpAddress: g.ilp.iwuyge987y.98y08y @@ -185,10 +186,11 @@ paths: application/json: schema: type: object + additionalProperties: false properties: incomingAmount: - description: The maximum amount that should be paid into the payment pointer under this incoming payment. $ref: ./schemas.yaml#/components/schemas/amount + description: The maximum amount that should be paid into the payment pointer under this incoming payment. expiresAt: type: string description: The date and time when payments into the incoming payment must no longer be accepted. @@ -196,9 +198,7 @@ paths: writeOnly: true metadata: type: object - additionalProperties: true description: Additional metadata associated with the incoming payment. (Optional) - additionalProperties: false examples: Create incoming payment for $25 to pay invoice INV2022-02-0137: value: @@ -206,7 +206,8 @@ paths: value: '2500' assetCode: USD assetScale: 2 - metadata: { externalRef: 'INV2022-02-0137' } + metadata: + externalRef: INV2022-02-0137 description: |- A subset of the incoming payments schema is accepted as input to create a new incoming payment. @@ -268,10 +269,8 @@ paths: createdAt: '2022-03-12T23:20:50.52Z' updatedAt: '2022-04-01T10:24:36.11Z' metadata: - { - description: 'Hi Mo, this is for the cappuccino I bought for you the other day.', - externalRef: 'Coffee w/ Mo on 10 March 22' - } + description: 'Hi Mo, this is for the cappuccino I bought for you the other day.' + externalRef: Coffee w/ Mo on 10 March 22 completed: true - id: 'https://openpayments.guide/alice/incoming-payments/32abc219-3dc3-44ec-a225-790cacfca8fa' paymentPointer: 'https://openpayments.guide/alice/' @@ -284,9 +283,7 @@ paths: createdAt: '2022-03-12T23:20:50.52Z' updatedAt: '2022-04-01T10:24:36.11Z' metadata: - { - description: 'I love your website, Alice! Thanks for the great content' - } + description: 'I love your website, Alice! Thanks for the great content' completed: false backward pagination: value: @@ -308,9 +305,7 @@ paths: createdAt: '2022-03-12T23:20:50.52Z' updatedAt: '2022-04-01T10:24:36.11Z' metadata: - { - description: 'I love your website, Alice! Thanks for the great content' - } + description: 'I love your website, Alice! Thanks for the great content' - id: 'https://openpayments.guide/alice/incoming-payments/016da9d5-c9a4-4c80-a354-86b915a04ff8' paymentPointer: 'https://openpayments.guide/alice/' incomingAmount: @@ -327,10 +322,8 @@ paths: createdAt: '2022-03-12T23:20:50.52Z' updatedAt: '2022-04-01T10:24:36.11Z' metadata: - { - description: 'Hi Mo, this is for the cappuccino I bought for you the other day.', - externalRef: 'Coffee w/ Mo on 10 March 22' - } + description: 'Hi Mo, this is for the cappuccino I bought for you the other day.' + externalRef: Coffee w/ Mo on 10 March 22 '401': $ref: '#/components/responses/401' '403': @@ -364,8 +357,8 @@ paths: paymentPointer: 'https://openpayments.guide/alice/' failed: false receiver: 'https://openpayments.guide/bob/incoming-payments/48884225-b393-4872-90de-1b737e2491c2' - sendAmount: - value: '2500' + debitAmount: + value: '2600' assetCode: USD assetScale: 2 receiveAmount: @@ -376,7 +369,8 @@ paths: value: '0' assetCode: USD assetScale: 2 - metadata: { description: Thank you for the shoes. } + metadata: + description: Thank you for the shoes. createdAt: '2022-03-12T23:20:50.52Z' updatedAt: '2022-04-01T10:24:36.11Z' '401': @@ -390,7 +384,8 @@ paths: Create an outgoing payment based on a quote: value: quoteId: 'https://openpayments.guide/alice/quotes/ab03296b-0c8b-4776-b94e-7ee27d868d4d' - metadata: { externalRef: 'INV2022-02-0137' } + metadata: + externalRef: INV2022-02-0137 schema: type: object properties: @@ -408,7 +403,7 @@ paths: description: |- A subset of the outgoing payments schema is accepted as input to create a new outgoing payment. - The `sendAmount` must use the same `assetCode` and `assetScale` as the payment pointer. + The `debitAmount` must use the same `assetCode` and `assetScale` as the payment pointer. required: true description: |- An **outgoing payment** is a sub-resource of a payment pointer. It represents a payment from the payment pointer. @@ -452,8 +447,8 @@ paths: value: '2500' assetCode: USD assetScale: 2 - sendAmount: - value: '2500' + debitAmount: + value: '2600' assetCode: USD assetScale: 2 sentAmount: @@ -463,16 +458,14 @@ paths: createdAt: '2022-03-12T23:20:50.52Z' updatedAt: '2022-04-01T10:24:36.11Z' metadata: - { - description: 'APlusVideo subscription', - externalRef: 'customer: 847458475' - } + description: APlusVideo subscription + externalRef: 'customer: 847458475' - id: 'https://openpayments.guide/alice/outgoing-payments/0cffa5a4-58fd-4cc8-8e01-7145c72bf07c' paymentPointer: 'https://openpayments.guide/alice/' failed: false receiver: 'https://openpayments.guide/shoeshop/incoming-payments/2fe92c6f-ef0d-487c-8759-3784eae6bce9' - sendAmount: - value: '7026' + debitAmount: + value: '7126' assetCode: USD assetScale: 2 receiveAmount: @@ -486,10 +479,8 @@ paths: createdAt: '2022-03-12T23:20:50.52Z' updatedAt: '2022-04-01T10:24:36.11Z' metadata: - { - description: 'Thank you for your purchase at ShoeShop!', - externalRef: 'INV2022-8943756' - } + description: Thank you for your purchase at ShoeShop! + externalRef: INV2022-8943756 backward pagination: value: pagination: @@ -502,8 +493,8 @@ paths: paymentPointer: 'https://openpayments.guide/alice/' failed: false receiver: 'https://openpayments.guide/shoeshop/incoming-payments/2fe92c6f-ef0d-487c-8759-3784eae6bce9' - sendAmount: - value: '7026' + debitAmount: + value: '7126' assetCode: USD assetScale: 2 receiveAmount: @@ -517,10 +508,8 @@ paths: createdAt: '2022-03-12T23:20:50.52Z' updatedAt: '2022-04-01T10:24:36.11Z' metadata: - { - description: 'Thank you for your purchase at ShoeShop!', - externalRef: 'INV2022-8943756' - } + description: Thank you for your purchase at ShoeShop! + externalRef: INV2022-8943756 - id: 'https://openpayments.guide/alice/outgoing-payments/8c68d3cc-0a0f-4216-98b4-4fa44a6c88cf' paymentPointer: 'https://openpayments.guide/alice/' failed: false @@ -529,8 +518,8 @@ paths: value: '2500' assetCode: USD assetScale: 2 - sendAmount: - value: '2500' + debitAmount: + value: '2600' assetCode: USD assetScale: 2 sentAmount: @@ -540,10 +529,8 @@ paths: createdAt: '2022-03-12T23:20:50.52Z' updatedAt: '2022-04-01T10:24:36.11Z' metadata: - { - description: 'APlusVideo subscription', - externalRef: 'customer: 847458475' - } + description: APlusVideo subscription + externalRef: 'customer: 847458475' '401': $ref: '#/components/responses/401' '403': @@ -576,7 +563,7 @@ paths: id: 'https://openpayments.guide/alice/quotes/8c68d3cc-0a0f-4216-98b4-4fa44a6c88cf' paymentPointer: 'https://openpayments.guide/alice/' receiver: 'https://openpayments.guide/aplusvideo/incoming-payments/45d495ad-b763-4882-88d7-aa14d261686e' - sendAmount: + debitAmount: value: '2500' assetCode: USD assetScale: 2 @@ -599,7 +586,7 @@ paths: Create fixed-send-amount quote for $25 to an ILP STREAM connection: value: receiver: 'https://openpayments.guide/connections/45a0d0ee-26dc-4c66-89e0-01fbf93156f7' - sendAmount: + debitAmount: value: '2500' assetCode: USD assetScale: 2 @@ -634,18 +621,17 @@ paths: properties: receiver: $ref: ./schemas.yaml#/components/schemas/receiver - sendAmount: + debitAmount: description: The fixed amount that would be sent from the sending payment pointer given a successful outgoing payment. $ref: ./schemas.yaml#/components/schemas/amount required: - receiver - - sendAmount + - debitAmount additionalProperties: false - description: |- A subset of the quotes schema is accepted as input to create a new quote. - The quote must be created with a (`sendAmount` xor `receiveAmount`) unless the `receiver` is an Incoming Payment which has an `incomingAmount`. + The quote must be created with a (`debitAmount` xor `receiveAmount`) unless the `receiver` is an Incoming Payment which has an `incomingAmount`. required: true description: A **quote** is a sub-resource of a payment pointer. It represents a quote for a payment from the payment pointer. parameters: @@ -683,10 +669,8 @@ paths: createdAt: '2022-03-12T23:20:50.52Z' updatedAt: '2022-04-01T10:24:36.11Z' metadata: - { - description: 'Thanks for the flowers!', - externalRef: 'INV-12876' - } + description: Thanks for the flowers! + externalRef: INV-12876 ilpStreamConnection: id: 'https://openpayments.guide/connections/4a1b0150-db73-49e8-8713-628baa4a17ff' ilpAddress: g.ilp.iwuyge987y.98y08y @@ -737,10 +721,8 @@ paths: createdAt: '2022-03-12T23:20:50.52Z' updatedAt: '2022-04-01T10:24:36.11Z' metadata: - { - description: 'Hi Mo, this is for the cappuccino I bought for you the other day.', - externalRef: 'Coffee w/ Mo on 10 March 2' - } + description: 'Hi Mo, this is for the cappuccino I bought for you the other day.' + externalRef: Coffee w/ Mo on 10 March 2 '401': $ref: '#/components/responses/401' '403': @@ -776,7 +758,7 @@ paths: paymentPointer: 'https://openpayments.guide/bob/' failed: false receiver: 'https://openpayments.guide/alice/incoming-payments/2f1b0150-db73-49e8-8713-628baa4a17ff' - sendAmount: + debitAmount: value: '2500' assetCode: USD assetScale: 2 @@ -791,10 +773,8 @@ paths: createdAt: '2022-03-12T23:20:50.52Z' updatedAt: '2022-04-01T10:24:36.11Z' metadata: - { - description: 'Thanks for the flowers!', - externalRef: 'INV-12876' - } + description: Thanks for the flowers! + externalRef: INV-12876 '401': $ref: '#/components/responses/401' '403': @@ -826,7 +806,7 @@ paths: id: 'https://openpayments.guide/bob/quotes/3859b39e-4666-4ce5-8745-72f1864c5371' paymentPointer: 'https://openpayments.guide/bob/' receiver: 'https://openpayments.guide/alice/incoming-payments/2f1b0150-db73-49e8-8713-628baa4a17ff' - sendAmount: + debitAmount: value: '2500' assetCode: USD assetScale: 2 @@ -962,10 +942,8 @@ components: createdAt: '2022-03-12T23:20:50.52Z' updatedAt: '2022-04-01T10:24:36.11Z' metadata: - { - description: 'Hi Mo, this is for the cappuccino I bought for you the other day.', - externalRef: 'Coffee w/ Mo on 10 March 22' - } + description: 'Hi Mo, this is for the cappuccino I bought for you the other day.' + externalRef: Coffee w/ Mo on 10 March 22 - id: 'https://openpayments.guide/alice/incoming-payments/456da9d5-c9a4-4c80-a354-86b915a04ff8' paymentPointer: 'https://openpayments.guide/alice/' incomingAmount: @@ -995,18 +973,17 @@ components: description: Describes whether the incoming payment has completed receiving fund. default: false incomingAmount: - description: The maximum amount that should be paid into the payment pointer under this incoming payment. $ref: ./schemas.yaml#/components/schemas/amount + description: The maximum amount that should be paid into the payment pointer under this incoming payment. receivedAmount: - description: The total amount that has been paid into the payment pointer under this incoming payment. $ref: ./schemas.yaml#/components/schemas/amount + description: The total amount that has been paid into the payment pointer under this incoming payment. expiresAt: type: string description: The date and time when payments under this incoming payment will no longer be accepted. format: date-time metadata: type: object - additionalProperties: true description: Additional metadata associated with the incoming payment. (Optional) createdAt: type: string @@ -1043,10 +1020,8 @@ components: createdAt: '2022-03-12T23:20:50.52Z' updatedAt: '2022-04-01T10:24:36.11Z' metadata: - { - description: 'Hi Mo, this is for the cappuccino I bought for you the other day.', - externalRef: 'Coffee w/ Mo on 10 March 22' - } + description: 'Hi Mo, this is for the cappuccino I bought for you the other day.' + externalRef: Coffee w/ Mo on 10 March 22 ilpStreamConnection: id: 'https://openpayments.guide/connections/032da9d5-c9a4-4c80-a354-86b915a04ff8' ilpApddress: g.ilp.iwuyge987y.98y08y @@ -1100,8 +1075,8 @@ components: value: '2500' assetCode: USD assetScale: 2 - sendAmount: - value: '2500' + debitAmount: + value: '2600' assetCode: USD assetScale: 2 sentAmount: @@ -1111,16 +1086,14 @@ components: createdAt: '2022-03-12T23:20:50.52Z' updatedAt: '2022-04-01T10:24:36.11Z' metadata: - { - description: 'APlusVideo subscription', - externalRef: 'customer: 847458475' - } + description: APlusVideo subscription + externalRef: 'customer: 847458475' - id: 'https://openpayments.guide/alice/outgoing-payments/0cffa5a4-58fd-4cc8-8e01-7145c72bf07c' paymentPointer: 'https://openpayments.guide/alice/' failed: false receiver: 'https://openpayments.guide/shoeshop/2fe92c6f-ef0d-487c-8759-3784eae6bce9' - sendAmount: - value: '7026' + debitAmount: + value: '7126' assetCode: USD assetScale: 2 sentAmount: @@ -1130,10 +1103,9 @@ components: createdAt: '2022-03-12T23:20:50.52Z' updatedAt: '2022-04-01T10:24:36.11Z' metadata: - { - description: 'Thank you for your purchase at ShoeShop!', - externalRef: 'INV2022-8943756' - } + description: Thank you for your purchase at ShoeShop! + externalRef: INV2022-8943756 + additionalProperties: false properties: id: type: string @@ -1155,20 +1127,19 @@ components: description: Describes whether the payment failed to send its full amount. default: false receiver: - description: The URL of the incoming payment or ILP STREAM Connection that is being paid. $ref: ./schemas.yaml#/components/schemas/receiver + description: The URL of the incoming payment or ILP STREAM Connection that is being paid. receiveAmount: - description: The total amount that should be received by the receiver when this outgoing payment has been paid. $ref: ./schemas.yaml#/components/schemas/amount - sendAmount: - description: The total amount that should be sent when this outgoing payment has been paid. + description: The total amount that should be received by the receiver when this outgoing payment has been paid. + debitAmount: $ref: ./schemas.yaml#/components/schemas/amount + description: The total amount that should be deducted from the sender's account when this outgoing payment has been paid. sentAmount: - description: The total amount that has been sent under this outgoing payment. $ref: ./schemas.yaml#/components/schemas/amount + description: The total amount that has been sent under this outgoing payment. metadata: type: object - additionalProperties: true description: Additional metadata associated with the outgoing payment. (Optional) createdAt: type: string @@ -1182,12 +1153,11 @@ components: - id - paymentPointer - receiver - - sendAmount - receiveAmount + - debitAmount - sentAmount - createdAt - updatedAt - additionalProperties: false quote: title: Quote description: A **quote** resource represents the quoted amount details with which an Outgoing Payment may be created. @@ -1200,7 +1170,11 @@ components: value: '2500' assetCode: USD assetScale: 2 - sendAmount: + debitAmount: + value: '2600' + assetCode: USD + assetScale: 2 + sentAmount: value: '2500' assetCode: USD assetScale: 2 @@ -1209,13 +1183,13 @@ components: - id: 'https://openpayments.guide/alice/quotes/8c68d3cc-0a0f-4216-98b4-4fa44a6c88cf' paymentPointer: 'https://openpayments.guide/alice/' receiver: 'https://openpayments.guide/aplusvideo/incoming-payments/45d495ad-b763-4882-88d7-aa14d261686e' - sendAmount: - value: '2500' + debitAmount: + value: '7126' assetCode: USD assetScale: 2 - receiveAmount: - value: '2198' - assetCode: EUR + sentAmount: + value: '7026' + assetCode: USD assetScale: 2 createdAt: '2022-03-12T23:20:50.52Z' expiresAt: '2022-04-12T23:20:50.52Z' @@ -1233,13 +1207,16 @@ components: readOnly: true receiver: $ref: ./schemas.yaml#/components/schemas/receiver + description: The URL of the incoming payment or ILP STREAM Connection that the quote is created for. receiveAmount: $ref: ./schemas.yaml#/components/schemas/amount - sendAmount: + description: The total amount that should be received by the receiver when the corresponding outgoing payment has been paid. + debitAmount: $ref: ./schemas.yaml#/components/schemas/amount + description: "The total amount that should be deducted from the sender's account when the corresponding outgoing payment has been paid. " expiresAt: type: string - description: The date and time when the calculated `sendAmount` is no longer valid. + description: The date and time when the calculated `debitAmount` is no longer valid. readOnly: true createdAt: type: string @@ -1250,7 +1227,7 @@ components: - paymentPointer - receiver - receiveAmount - - sendAmount + - debitAmount - createdAt page-info: description: '' diff --git a/openapi/schemas.yaml b/openapi/schemas.yaml index 7b3b5aa5..8a14d434 100644 --- a/openapi/schemas.yaml +++ b/openapi/schemas.yaml @@ -14,7 +14,6 @@ components: amount: title: amount type: object - description: 'All amounts are maxima, i.e. multiple payments can be created under a grant as long as the total amounts of these payments do not exceed the maximum amount per interval as specified in the grant.' properties: value: type: string diff --git a/packages/open-payments/README.md b/packages/open-payments/README.md index 7a82420e..f19377bb 100644 --- a/packages/open-payments/README.md +++ b/packages/open-payments/README.md @@ -179,7 +179,7 @@ const quote = await client.quote.create( { receiver: incomingPayment.id } ) -// quote.sendAmount.value = '5200' +// quote.debitAmount.value = '5200' ``` 5. Create `OutgoingPayment` grant & start interaction flow: diff --git a/packages/open-payments/src/client/outgoing-payment.test.ts b/packages/open-payments/src/client/outgoing-payment.test.ts index 8c104745..d72ae947 100644 --- a/packages/open-payments/src/client/outgoing-payment.test.ts +++ b/packages/open-payments/src/client/outgoing-payment.test.ts @@ -62,7 +62,7 @@ describe('outgoing-payment', (): void => { test('throws if outgoing payment does not pass validation', async (): Promise => { const outgoingPayment = mockOutgoingPayment({ - sendAmount: { + debitAmount: { assetCode: 'USD', assetScale: 3, value: '5' @@ -194,7 +194,7 @@ describe('outgoing-payment', (): void => { test('throws if an outgoing payment does not pass validation', async (): Promise => { const invalidOutgoingPayment = mockOutgoingPayment({ - sendAmount: { + debitAmount: { assetCode: 'CAD', assetScale: 2, value: '5' @@ -291,7 +291,7 @@ describe('outgoing-payment', (): void => { test('throws if outgoing payment does not pass validation', async (): Promise => { const outgoingPayment = mockOutgoingPayment({ - sendAmount: { + debitAmount: { assetCode: 'USD', assetScale: 3, value: '5' @@ -361,7 +361,7 @@ describe('outgoing-payment', (): void => { test('throws if send amount and sent amount asset scales are different', async (): Promise => { const outgoingPayment = mockOutgoingPayment({ - sendAmount: { + debitAmount: { assetCode: 'USD', assetScale: 3, value: '5' @@ -380,7 +380,7 @@ describe('outgoing-payment', (): void => { test('throws if send amount and sent amount asset codes are different', async (): Promise => { const outgoingPayment = mockOutgoingPayment({ - sendAmount: { + debitAmount: { assetCode: 'CAD', assetScale: 2, value: '5' @@ -399,7 +399,7 @@ describe('outgoing-payment', (): void => { test('throws if sent amount is larger than send amount', async (): Promise => { const outgoingPayment = mockOutgoingPayment({ - sendAmount: { + debitAmount: { assetCode: 'USD', assetScale: 2, value: '5' @@ -418,7 +418,7 @@ describe('outgoing-payment', (): void => { test('throws if sent amount equals send amount, but payment has failed', async (): Promise => { const outgoingPayment = mockOutgoingPayment({ - sendAmount: { + debitAmount: { assetCode: 'USD', assetScale: 2, value: '5' diff --git a/packages/open-payments/src/client/outgoing-payment.ts b/packages/open-payments/src/client/outgoing-payment.ts index 8a1b1b5a..7c72cded 100644 --- a/packages/open-payments/src/client/outgoing-payment.ts +++ b/packages/open-payments/src/client/outgoing-payment.ts @@ -176,19 +176,19 @@ export const listOutgoingPayments = async ( export const validateOutgoingPayment = ( payment: OutgoingPayment ): OutgoingPayment => { - const { sendAmount, sentAmount } = payment + const { debitAmount, sentAmount } = payment if ( - sendAmount.assetCode !== sentAmount.assetCode || - sendAmount.assetScale !== sentAmount.assetScale + debitAmount.assetCode !== sentAmount.assetCode || + debitAmount.assetScale !== sentAmount.assetScale ) { throw new Error( 'Asset code or asset scale of sending amount does not match sent amount' ) } - if (BigInt(sendAmount.value) < BigInt(sentAmount.value)) { + if (BigInt(debitAmount.value) < BigInt(sentAmount.value)) { throw new Error('Amount sent is larger than maximum amount to send') } - if (sendAmount.value === sentAmount.value && payment.failed) { + if (debitAmount.value === sentAmount.value && payment.failed) { throw new Error('Amount to send matches sent amount but payment failed') } diff --git a/packages/open-payments/src/openapi/generated/auth-server-types.ts b/packages/open-payments/src/openapi/generated/auth-server-types.ts index 23474523..a91ec977 100644 --- a/packages/open-payments/src/openapi/generated/auth-server-types.ts +++ b/packages/open-payments/src/openapi/generated/auth-server-types.ts @@ -166,7 +166,9 @@ export interface components { */ "limits-outgoing": Partial & { receiver?: external["schemas.yaml"]["components"]["schemas"]["receiver"]; - sendAmount?: external["schemas.yaml"]["components"]["schemas"]["amount"]; + /** @description All amounts are maxima, i.e. multiple payments can be created under a grant as long as the total amounts of these payments do not exceed the maximum amount per interval as specified in the grant. */ + debitAmount?: external["schemas.yaml"]["components"]["schemas"]["amount"]; + /** @description All amounts are maxima, i.e. multiple payments can be created under a grant as long as the total amounts of these payments do not exceed the maximum amount per interval as specified in the grant. */ receiveAmount?: external["schemas.yaml"]["components"]["schemas"]["amount"]; interval?: components["schemas"]["interval"]; }; @@ -312,10 +314,7 @@ export interface external { paths: {}; components: { schemas: { - /** - * amount - * @description All amounts are maxima, i.e. multiple payments can be created under a grant as long as the total amounts of these payments do not exceed the maximum amount per interval as specified in the grant. - */ + /** amount */ amount: { /** * Format: uint64 diff --git a/packages/open-payments/src/openapi/generated/resource-server-types.ts b/packages/open-payments/src/openapi/generated/resource-server-types.ts index 9f091529..9157c59e 100644 --- a/packages/open-payments/src/openapi/generated/resource-server-types.ts +++ b/packages/open-payments/src/openapi/generated/resource-server-types.ts @@ -245,8 +245,8 @@ export interface components { receiver: external["schemas.yaml"]["components"]["schemas"]["receiver"]; /** @description The total amount that should be received by the receiver when this outgoing payment has been paid. */ receiveAmount: external["schemas.yaml"]["components"]["schemas"]["amount"]; - /** @description The total amount that should be sent when this outgoing payment has been paid. */ - sendAmount: external["schemas.yaml"]["components"]["schemas"]["amount"]; + /** @description The total amount that should be deducted from the sender's account when this outgoing payment has been paid. */ + debitAmount: external["schemas.yaml"]["components"]["schemas"]["amount"]; /** @description The total amount that has been sent under this outgoing payment. */ sentAmount: external["schemas.yaml"]["components"]["schemas"]["amount"]; /** @description Additional metadata associated with the outgoing payment. (Optional) */ @@ -277,10 +277,13 @@ export interface components { * @description The URL of the payment pointer from which this quote's payment would be sent. */ paymentPointer: string; + /** @description The URL of the incoming payment or ILP STREAM Connection that the quote is created for. */ receiver: external["schemas.yaml"]["components"]["schemas"]["receiver"]; + /** @description The total amount that should be received by the receiver when the corresponding outgoing payment has been paid. */ receiveAmount: external["schemas.yaml"]["components"]["schemas"]["amount"]; - sendAmount: external["schemas.yaml"]["components"]["schemas"]["amount"]; - /** @description The date and time when the calculated `sendAmount` is no longer valid. */ + /** @description The total amount that should be deducted from the sender's account when the corresponding outgoing payment has been paid. */ + debitAmount: external["schemas.yaml"]["components"]["schemas"]["amount"]; + /** @description The date and time when the calculated `debitAmount` is no longer valid. */ expiresAt?: string; /** * Format: date-time @@ -539,7 +542,7 @@ export interface operations { /** * A subset of the outgoing payments schema is accepted as input to create a new outgoing payment. * - * The `sendAmount` must use the same `assetCode` and `assetScale` as the payment pointer. + * The `debitAmount` must use the same `assetCode` and `assetScale` as the payment pointer. */ requestBody: { content: { @@ -580,7 +583,7 @@ export interface operations { /** * A subset of the quotes schema is accepted as input to create a new quote. * - * The quote must be created with a (`sendAmount` xor `receiveAmount`) unless the `receiver` is an Incoming Payment which has an `incomingAmount`. + * The quote must be created with a (`debitAmount` xor `receiveAmount`) unless the `receiver` is an Incoming Payment which has an `incomingAmount`. */ requestBody: { content: { @@ -596,7 +599,7 @@ export interface operations { | { receiver: external["schemas.yaml"]["components"]["schemas"]["receiver"]; /** @description The fixed amount that would be sent from the sending payment pointer given a successful outgoing payment. */ - sendAmount: external["schemas.yaml"]["components"]["schemas"]["amount"]; + debitAmount: external["schemas.yaml"]["components"]["schemas"]["amount"]; }; }; }; @@ -720,10 +723,7 @@ export interface external { paths: {}; components: { schemas: { - /** - * amount - * @description All amounts are maxima, i.e. multiple payments can be created under a grant as long as the total amounts of these payments do not exceed the maximum amount per interval as specified in the grant. - */ + /** amount */ amount: { /** * Format: uint64 diff --git a/packages/open-payments/src/test/helpers.ts b/packages/open-payments/src/test/helpers.ts index 8851ba0d..aea886b9 100644 --- a/packages/open-payments/src/test/helpers.ts +++ b/packages/open-payments/src/test/helpers.ts @@ -154,7 +154,7 @@ export const mockOutgoingPayment = ( id: `https://example.com/.well-known/pay/outgoing-payments/${uuid()}`, paymentPointer: 'https://example.com/.well-known/pay', failed: false, - sendAmount: { + debitAmount: { assetCode: 'USD', assetScale: 2, value: '10' @@ -286,7 +286,7 @@ export const mockQuote = (overrides?: Partial): Quote => ({ id: `https://example.com/.well-known/pay/quotes/${uuid()}`, receiver: 'https://example.com/.well-known/peer', paymentPointer: 'https://example.com/.well-known/pay', - sendAmount: { + debitAmount: { value: '100', assetCode: 'USD', assetScale: 2 diff --git a/packages/open-payments/src/types.ts b/packages/open-payments/src/types.ts index e93c700a..834dd0ee 100644 --- a/packages/open-payments/src/types.ts +++ b/packages/open-payments/src/types.ts @@ -51,16 +51,16 @@ export type Quote = RSComponents['schemas']['quote'] type QuoteArgsBase = { receiver: RSOperations['create-quote']['requestBody']['content']['application/json']['receiver'] } -type QuoteArgsWithSendAmount = QuoteArgsBase & { - sendAmount?: RSComponents['schemas']['quote']['sendAmount'] +type QuoteArgsWithDebitAmount = QuoteArgsBase & { + debitAmount?: RSComponents['schemas']['quote']['debitAmount'] receiveAmount?: never } type QuoteArgsWithReceiveAmount = QuoteArgsBase & { - sendAmount?: never + debitAmount?: never receiveAmount?: RSComponents['schemas']['quote']['receiveAmount'] } export type CreateQuoteArgs = - | QuoteArgsWithSendAmount + | QuoteArgsWithDebitAmount | QuoteArgsWithReceiveAmount export const getASPath =

(path: P): string =>