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

Commit eea16ca

Browse files
authoredAug 4, 2020
feat: make fiat change non-breaking (#639)
1 parent e2e82f9 commit eea16ca

File tree

7 files changed

+49
-12
lines changed

7 files changed

+49
-12
lines changed
 

‎src/config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const payIdServerVersions: readonly string[] = ['1.0']
1+
export const payIdServerVersions: readonly string[] = ['1.0', '1.1']
22
export const adminApiVersions: readonly string[] = ['2020-05-28']
33

44
/**

‎src/middlewares/payIds.ts

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export default async function getPaymentInfo(
7777
// * NOTE: To append a memo, MUST set a memo in createMemo()
7878
const formattedPaymentInfo = formatPaymentInfo(
7979
preferredAddresses,
80+
res.get('PayID-Version'),
8081
payId,
8182
createMemo,
8283
)

‎src/services/basePayId.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ import { ParsedAcceptHeader } from './headers'
99
* a Base PayID flow.
1010
*
1111
* @param addresses - Array of address information associated with a PayID.
12+
* @param version - The PayID protocol response version.
1213
* @param payId - Optionally include a PayId.
1314
* @param memoFn - A function, taking an optional PaymentInformation object,
14-
* that returns a string to be used as the memo.
15-
*
15+
* that returns a string to be used as the memo.
1616
* @returns The formatted PaymentInformation object.
1717
*/
1818
export function formatPaymentInfo(
1919
addresses: readonly AddressInformation[],
20+
version: string,
2021
payId?: string,
2122
memoFn?: (paymentInformation: PaymentInformation) => string,
2223
): PaymentInformation {
@@ -25,7 +26,7 @@ export function formatPaymentInfo(
2526
return {
2627
paymentNetwork: address.paymentNetwork,
2728
...(address.environment && { environment: address.environment }),
28-
addressDetailsType: getAddressDetailsType(address),
29+
addressDetailsType: getAddressDetailsType(address, version),
2930
addressDetails: address.details,
3031
}
3132
}),
@@ -102,12 +103,17 @@ export function getPreferredAddressHeaderPair(
102103
* Gets the associated AddressDetailsType for an address.
103104
*
104105
* @param address - The address information associated with a PayID.
106+
* @param version - The PayID protocol version.
105107
* @returns The AddressDetailsType for the address.
106108
*/
107109
export function getAddressDetailsType(
108110
address: AddressInformation,
111+
version: string,
109112
): AddressDetailsType {
110113
if (address.paymentNetwork === 'ACH') {
114+
if (version === '1.0') {
115+
return AddressDetailsType.AchAddress
116+
}
111117
return AddressDetailsType.FiatAddress
112118
}
113119
return AddressDetailsType.CryptoAddress

‎src/types/protocol.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
/* eslint-disable no-inline-comments -- It is useful to have inline comments for interfaces. */
12
/**
23
* Type of payment address in PaymentInformation.
34
*/
45
export enum AddressDetailsType {
56
CryptoAddress = 'CryptoAddressDetails',
6-
FiatAddress = 'FiatAddressDetails',
7+
FiatAddress = 'FiatAddressDetails', // Replaces AchAddressDetails
8+
AchAddress = 'AchAddressDetails', // Maintain compatibility for 1.0
79
}
810

911
/**

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ describe('E2E - publicAPIRouter - Base PayID', function (): void {
134134
// WHEN we make a GET request to the public endpoint to retrieve payment info with an Accept header specifying ACH
135135
request(app.publicApiExpress)
136136
.get(payId)
137-
.set('PayID-Version', '1.0')
137+
.set('PayID-Version', '1.1')
138138
.set('Accept', acceptHeader)
139139
// THEN we get back our Accept header as the Content-Type
140140
.expect((res) => {

‎test/unit/formatPaymentInfo.test.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { assert } from 'chai'
33
import { formatPaymentInfo } from '../../src/services/basePayId'
44
import { AddressDetailsType } from '../../src/types/protocol'
55

6+
const version1dot1 = '1.1'
7+
68
describe('Base PayID - formatPaymentInfo()', function (): void {
79
it('Returns CryptoAddressDetails & FiatAddressDetails for addressDetailsTypes when formatting array with multiple AddressInformation', function () {
810
// GIVEN an array of AddressInformation with an ACH entry
@@ -48,7 +50,7 @@ describe('Base PayID - formatPaymentInfo()', function (): void {
4850
}
4951

5052
// WHEN we format it
51-
const paymentInfo = formatPaymentInfo(addressInfo, payId)
53+
const paymentInfo = formatPaymentInfo(addressInfo, version1dot1, payId)
5254

5355
// THEN we get back a PaymentInformation object with the appropriate address details
5456
assert.deepStrictEqual(paymentInfo, expectedPaymentInfo)
@@ -80,7 +82,7 @@ describe('Base PayID - formatPaymentInfo()', function (): void {
8082
}
8183

8284
// WHEN we format it and don't pass in a PayID
83-
const paymentInfo = formatPaymentInfo(addressInfo)
85+
const paymentInfo = formatPaymentInfo(addressInfo, version1dot1)
8486

8587
// THEN we get back a PaymentInformation object without a PayID
8688
assert.deepStrictEqual(paymentInfo, expectedPaymentInfo)
@@ -114,7 +116,7 @@ describe('Base PayID - formatPaymentInfo()', function (): void {
114116
}
115117

116118
// WHEN we format it
117-
const paymentInfo = formatPaymentInfo(addressInfo)
119+
const paymentInfo = formatPaymentInfo(addressInfo, version1dot1)
118120

119121
// THEN we get back a PaymentInformation object with no environment
120122
assert.deepStrictEqual(paymentInfo, expectedPaymentInfo)
@@ -153,7 +155,12 @@ describe('Base PayID - formatPaymentInfo()', function (): void {
153155
const memoFn = (): string => 'memo'
154156

155157
// WHEN we format the address information
156-
const paymentInfo = formatPaymentInfo(addressInfo, payId, memoFn)
158+
const paymentInfo = formatPaymentInfo(
159+
addressInfo,
160+
version1dot1,
161+
payId,
162+
memoFn,
163+
)
157164

158165
// THEN we get back a PaymentInformation object with a memo
159166
assert.deepStrictEqual(paymentInfo, expectedPaymentInfo)

‎test/unit/getAddressDetailsType.test.ts

+23-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import { assert } from 'chai'
33
import { getAddressDetailsType } from '../../src/services/basePayId'
44
import { AddressDetailsType } from '../../src/types/protocol'
55

6+
const version1dot0 = '1.0'
7+
const version1dot1 = '1.1'
8+
69
describe('Base PayID - getAddressDetailsType()', function (): void {
710
it('Returns FiatAddressDetails for addressDetailsType when formatting ACH AddressInformation', function () {
811
// GIVEN an array of AddressInformation with a single ACH (empty environment) entry
@@ -16,12 +19,30 @@ describe('Base PayID - getAddressDetailsType()', function (): void {
1619
}
1720

1821
// WHEN we get the address details type
19-
const addressDetailsType = getAddressDetailsType(addressInfo)
22+
const addressDetailsType = getAddressDetailsType(addressInfo, version1dot1)
2023

2124
// THEN we get back an AddressDetailsType of FiatAddress
2225
assert.deepStrictEqual(addressDetailsType, AddressDetailsType.FiatAddress)
2326
})
2427

28+
it('If using version 1.0, returns AchAddressDetails for addressDetailsType when formatting ACH AddressInformation', function () {
29+
// GIVEN an array of AddressInformation with a single ACH (empty environment) entry
30+
const addressInfo = {
31+
paymentNetwork: 'ACH',
32+
environment: null,
33+
details: {
34+
accountNumber: '000123456789',
35+
routingNumber: '123456789',
36+
},
37+
}
38+
39+
// WHEN we get the address details type
40+
const addressDetailsType = getAddressDetailsType(addressInfo, version1dot0)
41+
42+
// THEN we get back an AddressDetailsType of FiatAddress
43+
assert.deepStrictEqual(addressDetailsType, AddressDetailsType.AchAddress)
44+
})
45+
2546
it('Returns CryptoAddressDetails for addressDetailsType when formatting XRP AddressInformation', function () {
2647
// GIVEN an array of AddressInformation with a single XRP entry
2748
const addressInfo = {
@@ -33,7 +54,7 @@ describe('Base PayID - getAddressDetailsType()', function (): void {
3354
}
3455

3556
// WHEN we get the address details type
36-
const addressDetailsType = getAddressDetailsType(addressInfo)
57+
const addressDetailsType = getAddressDetailsType(addressInfo, version1dot1)
3758

3859
// THEN we get back an AddressDetailsType of CryptoAddress
3960
assert.deepStrictEqual(addressDetailsType, AddressDetailsType.CryptoAddress)

0 commit comments

Comments
 (0)
This repository has been archived.