Skip to content
This repository was archived by the owner on Mar 8, 2024. It is now read-only.

Commit 3b4f23c

Browse files
0xCLARITYdino-rodriguez
authored andcommitted
Add version to payment information (#662)
Co-authored-by: Dino Rodriguez <[email protected]>
1 parent bb1ad88 commit 3b4f23c

File tree

8 files changed

+38
-17
lines changed

8 files changed

+38
-17
lines changed

src/services/basePayId.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ export function formatPaymentInfo(
2626
memoFn?: (paymentInformation: PaymentInformation) => string,
2727
): PaymentInformation {
2828
const paymentInformation: PaymentInformation = {
29+
payId,
30+
version,
2931
addresses: addresses.map((address) => {
3032
return {
3133
paymentNetwork: address.paymentNetwork,
@@ -56,7 +58,6 @@ export function formatPaymentInfo(
5658
}),
5759
}
5860
}),
59-
payId,
6061
}
6162

6263
return {

src/types/protocol.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ export interface FiatAddressDetails {
2525
}
2626

2727
/**
28-
* Payment information included in a PaymentSetupDetails or by itself (in the
29-
* case of a GET request to the base path /).
28+
* The payment information response payload of a PayID Protocol (Public API) request.
3029
*/
3130
export interface PaymentInformation {
3231
readonly payId?: string
32+
readonly version?: string
3333
readonly addresses: Address[]
3434
readonly verifiedAddresses: VerifiedAddress[]
3535
readonly memo?: string

test/integration/e2e/public-api/basePayId.test.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,13 @@ describe('E2E - publicAPIRouter - Base PayID', function (): void {
3333
],
3434
verifiedAddresses: [],
3535
payId: 'alice$127.0.0.1',
36+
version: '1.1',
3637
}
3738

3839
// WHEN we make a GET request to the public endpoint to retrieve payment info with an Accept header specifying xrpl-mainnet
3940
request(app.publicApiExpress)
4041
.get(payId)
41-
.set('PayID-Version', '1.0')
42+
.set('PayID-Version', '1.1')
4243
.set('Accept', acceptHeader)
4344
// THEN we get back our Accept header as the Content-Type
4445
.expect((res) => {
@@ -65,12 +66,13 @@ describe('E2E - publicAPIRouter - Base PayID', function (): void {
6566
],
6667
verifiedAddresses: [],
6768
payId: 'alice$127.0.0.1',
69+
version: '1.1',
6870
}
6971

7072
// WHEN we make a GET request to the public endpoint to retrieve payment info with an Accept header specifying xrpl-testnet
7173
request(app.publicApiExpress)
7274
.get(payId)
73-
.set('PayID-Version', '1.0')
75+
.set('PayID-Version', '1.1')
7476
.set('Accept', acceptHeader)
7577
// THEN we get back our Accept header as the Content-Type
7678
.expect((res) => {
@@ -97,12 +99,13 @@ describe('E2E - publicAPIRouter - Base PayID', function (): void {
9799
],
98100
verifiedAddresses: [],
99101
payId: 'alice$127.0.0.1',
102+
version: '1.1',
100103
}
101104

102105
// WHEN we make a GET request to the public endpoint to retrieve payment info with an Accept header specifying btc-testnet
103106
request(app.publicApiExpress)
104107
.get(payId)
105-
.set('PayID-Version', '1.0')
108+
.set('PayID-Version', '1.1')
106109
.set('Accept', acceptHeader)
107110
// THEN we get back our Accept header as the Content-Type
108111
.expect((res) => {
@@ -129,6 +132,7 @@ describe('E2E - publicAPIRouter - Base PayID', function (): void {
129132
],
130133
verifiedAddresses: [],
131134
payId: 'alice$127.0.0.1',
135+
version: '1.1',
132136
}
133137

134138
// WHEN we make a GET request to the public endpoint to retrieve payment info with an Accept header specifying ACH
@@ -157,7 +161,7 @@ describe('E2E - publicAPIRouter - Base PayID', function (): void {
157161
// WHEN we make a GET request to the public endpoint to retrieve payment info with an Accept header specifying xrpl-testnet
158162
request(app.publicApiExpress)
159163
.get(payId)
160-
.set('PayID-Version', '1.0')
164+
.set('PayID-Version', '1.1')
161165
.set('Accept', acceptHeader)
162166
.expect('Content-Type', /application\/json/u)
163167
// THEN we get back a 404 with the expected error response.
@@ -177,7 +181,7 @@ describe('E2E - publicAPIRouter - Base PayID', function (): void {
177181
// WHEN we make a GET request to the public endpoint to retrieve payment info with an Accept header specifying xrpl-devnet
178182
request(app.publicApiExpress)
179183
.get(payId)
180-
.set('PayID-Version', '1.0')
184+
.set('PayID-Version', '1.1')
181185
.set('Accept', acceptHeader)
182186
.expect('Content-Type', /application\/json/u)
183187
// THEN we get back a 404 with the expected error response.
@@ -197,7 +201,7 @@ describe('E2E - publicAPIRouter - Base PayID', function (): void {
197201
// WHEN we request all addresses for that PayID
198202
request(app.publicApiExpress)
199203
.get(payId)
200-
.set('PayID-Version', '1.0')
204+
.set('PayID-Version', '1.1')
201205
.set('Accept', acceptHeader)
202206
// THEN we get back a 404 with the expected error response.
203207
.expect(HttpStatus.NotFound, expectedErrorResponse, done)

test/integration/e2e/public-api/basePayIdContentNegotiation.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,19 @@ let app: App
1818

1919
const USER = '/alice'
2020
const PAYID = `${USER.slice(1)}$127.0.0.1`
21+
const VERSION = '1.1'
22+
2123
const XRPL_EXPECTED_TESTNET_RESPONSE = {
2224
addresses: [XRPL_TESTNET_ADDRESS],
2325
verifiedAddresses: [],
2426
payId: PAYID,
27+
version: VERSION,
2528
}
2629
const XRPL_EXPECTED_MAINNET_RESPONSE = {
2730
addresses: [XRPL_MAINNET_ADDRESS],
2831
verifiedAddresses: [],
2932
payId: PAYID,
33+
version: VERSION,
3034
}
3135

3236
describe('E2E - publicAPIRouter - Content Negotiation', function (): void {

test/integration/e2e/public-api/verifiablePayId.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ describe('E2E - publicAPIRouter - Verifiable PayID', function (): void {
2626
const expectedResponse: PaymentInformation = {
2727
addresses: [],
2828
payId: 'johnwick$127.0.0.1',
29+
version: '1.1',
2930
verifiedAddresses: [
3031
{
3132
payload: JSON.stringify({
@@ -72,6 +73,7 @@ describe('E2E - publicAPIRouter - Verifiable PayID', function (): void {
7273
const expectedResponse: PaymentInformation = {
7374
addresses: [],
7475
payId: 'johnwick$127.0.0.1',
76+
version: '1.1',
7577
verifiedAddresses: [
7678
{
7779
payload: JSON.stringify({
@@ -118,6 +120,7 @@ describe('E2E - publicAPIRouter - Verifiable PayID', function (): void {
118120
const expectedResponse: PaymentInformation = {
119121
addresses: [],
120122
payId: 'johnwick$127.0.0.1',
123+
version: '1.1',
121124
verifiedAddresses: [
122125
{
123126
payload: JSON.stringify({
@@ -164,6 +167,7 @@ describe('E2E - publicAPIRouter - Verifiable PayID', function (): void {
164167
const expectedResponse: PaymentInformation = {
165168
addresses: [],
166169
payId: 'johnwick$127.0.0.1',
170+
version: '1.1',
167171
verifiedAddresses: [
168172
{
169173
payload: JSON.stringify({
@@ -208,6 +212,8 @@ describe('E2E - publicAPIRouter - Verifiable PayID', function (): void {
208212
const payId = '/johnwick'
209213
const acceptHeader = 'application/payid+json'
210214
const expectedResponse: PaymentInformation = {
215+
payId: 'johnwick$127.0.0.1',
216+
version: '1.1',
211217
addresses: [
212218
{
213219
paymentNetwork: 'BTC',
@@ -218,7 +224,6 @@ describe('E2E - publicAPIRouter - Verifiable PayID', function (): void {
218224
},
219225
},
220226
],
221-
payId: 'johnwick$127.0.0.1',
222227
verifiedAddresses: [
223228
{
224229
payload: JSON.stringify({

test/integration/e2e/public-api/verifiablePayIdContentNegotiation.test.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ let app: App
1818

1919
const USER = '/johnwick'
2020
const PAYID = `${USER.slice(1)}$127.0.0.1`
21+
const VERSION = '1.1'
2122
const XRPL_EXPECTED_TESTNET_RESPONSE = {
2223
addresses: [],
2324
verifiedAddresses: [
@@ -30,6 +31,7 @@ const XRPL_EXPECTED_TESTNET_RESPONSE = {
3031
},
3132
],
3233
payId: PAYID,
34+
version: VERSION,
3335
}
3436

3537
describe('E2E - publicAPIRouter - Verifiable PayId Content Negotiation', function (): void {
@@ -46,7 +48,7 @@ describe('E2E - publicAPIRouter - Verifiable PayId Content Negotiation', functio
4648
// both testnet and mainnet, with no q for either
4749
request(app.publicApiExpress)
4850
.get(USER)
49-
.set('PayID-Version', '1.1')
51+
.set('PayID-Version', VERSION)
5052
.set('Accept', acceptHeader)
5153
// THEN we get back an xrpl testnet header as our Content-Type
5254
.expect((res) => {
@@ -67,7 +69,7 @@ describe('E2E - publicAPIRouter - Verifiable PayId Content Negotiation', functio
6769
// and mainnet, with testnet having a higher q-value
6870
request(app.publicApiExpress)
6971
.get(USER)
70-
.set('PayID-Version', '1.1')
72+
.set('PayID-Version', VERSION)
7173
.set('Accept', acceptHeader)
7274
// THEN we get back an xrpl testnet header as the Content-Type
7375
.expect((res) => {
@@ -88,7 +90,7 @@ describe('E2E - publicAPIRouter - Verifiable PayId Content Negotiation', functio
8890
// xrpl-testnet and xrpl-mainnet, with a higher q for xrpl-testnet
8991
request(app.publicApiExpress)
9092
.get(USER)
91-
.set('PayID-Version', '1.1')
93+
.set('PayID-Version', VERSION)
9294
.set('Accept', acceptHeader)
9395
// THEN we get back a xrpl-testnet accept header as the Content-Type
9496
.expect((res) => {
@@ -110,7 +112,7 @@ describe('E2E - publicAPIRouter - Verifiable PayId Content Negotiation', functio
110112
// a non-existent network+environment most preferred, followed by xrpl-mainnet and xrpl-testnet
111113
request(app.publicApiExpress)
112114
.get(USER)
113-
.set('PayID-Version', '1.1')
115+
.set('PayID-Version', VERSION)
114116
.set('Accept', acceptHeader)
115117
// THEN we get back a xrpl-testnet accept header as the Content-Type
116118
.expect((res) => {

test/unit/formatPaymentInfoBasePayId.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ describe('Base PayID - formatPaymentInfo()', function (): void {
2727
},
2828
]
2929
const expectedPaymentInfo = {
30+
payId: 'alice$example.com',
31+
version: '1.1',
3032
addresses: [
3133
{
3234
paymentNetwork: 'XRP',
@@ -46,7 +48,6 @@ describe('Base PayID - formatPaymentInfo()', function (): void {
4648
},
4749
],
4850
verifiedAddresses: [],
49-
payId: 'alice$example.com',
5051
}
5152

5253
// WHEN we format it
@@ -65,6 +66,7 @@ describe('Base PayID - formatPaymentInfo()', function (): void {
6566
it('Does not return a environment field when it is not included in the address information', function (): void {
6667
// GIVEN an array of AddressInformation with an ACH entry (no environment)
6768
const payId = 'alice$example.com'
69+
const version = '1.1'
6870
const addressInfo = [
6971
{
7072
paymentNetwork: 'ACH',
@@ -89,6 +91,7 @@ describe('Base PayID - formatPaymentInfo()', function (): void {
8991
],
9092
verifiedAddresses: [],
9193
payId,
94+
version,
9295
}
9396

9497
// WHEN we format it
@@ -131,6 +134,7 @@ describe('Base PayID - formatPaymentInfo()', function (): void {
131134
verifiedAddresses: [],
132135
payId: 'alice$example.com',
133136
memo: 'memo',
137+
version: '1.1',
134138
}
135139

136140
// AND GIVEN a createMemo() that returns a truthy value

test/unit/formatPaymentInfoVerifiablePayId.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
describe('Verifiable PayID - formatPaymentInfo()', function (): void {
1111
it('Returns properly formatted array for Verifiable PayID', function () {
1212
// GIVEN an array of AddressInformation with an ACH entry
13-
const version1dot1 = '1.1'
13+
const version = '1.1'
1414
const payId = 'alice$example.com'
1515
const verifiedAddressInfo: AddressInformation[] = [
1616
{
@@ -76,14 +76,15 @@ describe('Verifiable PayID - formatPaymentInfo()', function (): void {
7676
},
7777
],
7878
payId: 'alice$example.com',
79+
version: '1.1',
7980
}
8081

8182
// WHEN we format it
8283
const paymentInfo = formatPaymentInfo(
8384
[],
8485
verifiedAddressInfo,
8586
'anIdentityKey',
86-
version1dot1,
87+
version,
8788
payId,
8889
)
8990

0 commit comments

Comments
 (0)