Skip to content

Commit 5a52976

Browse files
authored
fix(api/payment): store additional temporary details in KV (#722)
1 parent 98d04e1 commit 5a52976

5 files changed

Lines changed: 26 additions & 4 deletions

File tree

api/src/routes/payment/initiate.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ app.post(
4141
).href
4242

4343
const openPayments = await OpenPaymentsService.getInstance(env)
44-
const { grantContinuation, nonce, ...result } =
44+
const { grantContinuation, nonce, amount, ...result } =
4545
await openPayments.paymentInitiate(params)
4646

4747
// The `/payment/complete` endpoint will find details from the KV based on
@@ -53,9 +53,12 @@ app.post(
5353
{
5454
status: 'PENDING',
5555
quoteId: result.quoteId,
56+
incomingPaymentId: result.incomingPaymentId,
5657
redirectUrl: originalRedirectUrl,
5758
grantContinuation: grantContinuation,
5859
sender: params.sender,
60+
receiver: params.receiver,
61+
amount,
5962
metadata: { description: params.note },
6063
nonce,
6164
},

api/src/routes/payment/redirect.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@ app.get(
8585
status: 'CREATED',
8686
redirectUrl: data.redirectUrl,
8787
outgoingPaymentId,
88+
incomingPaymentId: data.incomingPaymentId,
8889
sender: data.sender,
90+
receiver: data.receiver,
91+
amount: data.amount,
8992
outgoingPaymentGrantAccessToken: accessToken,
9093
},
9194
{ expirationTtl: 5 * 60 /* 5 minutes */ },

api/src/routes/payment/status.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ async function handleStatus(
5656
paymentId,
5757
{
5858
status: 'COMPLETE',
59+
incomingPaymentId: data.incomingPaymentId,
5960
outgoingPaymentId: data.outgoingPaymentId,
61+
sender: data.sender,
62+
receiver: data.receiver,
63+
amount: data.amount,
6064
result: result.success ? 'success' : 'failure',
6165
error: result.success ? undefined : result.error,
6266
},

api/src/utils/open-payments.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ export class OpenPaymentsService {
173173
grantRedirectUrl: grant.interact.redirect,
174174
grantContinuation: grant.continue,
175175
nonce,
176+
amount: debitAmount || receiveAmount!,
176177
}
177178
}
178179

api/src/utils/payments-kv.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,23 @@ import type {
55
import type {
66
GrantWithAccessToken,
77
PendingGrant,
8-
WalletAddress,
98
} from '@interledger/open-payments'
9+
import type { Amount } from '@shared/types'
10+
import type { WalletAddressInfo } from '../types'
1011

1112
export const KV_PAYMENTS_PREFIX = 'payments/'
1213

1314
export type PaymentKvData =
1415
| {
1516
status: 'PENDING'
1617
quoteId: string
18+
incomingPaymentId: string
1719
redirectUrl: string
1820
grantContinuation: PendingGrant['continue']
1921
nonce: string
20-
sender: WalletAddress
22+
sender: WalletAddressInfo
23+
receiver: WalletAddressInfo
24+
amount: Amount
2125
metadata: Record<string, unknown>
2226
}
2327
| {
@@ -27,14 +31,21 @@ export type PaymentKvData =
2731
status: 'CREATED'
2832
// For polling of outgoing payment completion
2933
outgoingPaymentId: string
34+
incomingPaymentId: string
35+
sender: WalletAddressInfo
36+
receiver: WalletAddressInfo
37+
amount: Amount
3038
redirectUrl: string
3139
// For expiring resources/grants when done
3240
outgoingPaymentGrantAccessToken: GrantWithAccessToken['access_token']['value']
33-
sender: WalletAddress
3441
}
3542
| {
3643
status: 'COMPLETE'
3744
outgoingPaymentId: string
45+
incomingPaymentId: string
46+
sender: WalletAddressInfo
47+
receiver: WalletAddressInfo
48+
amount: Amount
3849
result: 'success' | 'failure'
3950
error?: {
4051
code: string

0 commit comments

Comments
 (0)