Skip to content

Commit fecedf6

Browse files
authored
Merge pull request #6346 from BitGo/BTC-2225-payments-api-changes
feat: primary key changes for payment apis
2 parents cd5e7bb + b398ae3 commit fecedf6

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

modules/abstract-lightning/src/codecs/api/payment.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ export const PAYMENT_FAILURE_INSUFFICIENT_WALLET_BALANCE = 'INSUFFICIENT_WALLET_
2828
/** Excess custodial lightning balance for the customer's wallet */
2929
export const PAYMENT_FAILURE_EXCESS_WALLET_BALANCE = 'EXCESS_WALLET_BALANCE';
3030
export const PAYMENT_FAILURE_INVOICE_EXPIRED = 'INVOICE_EXPIRED';
31-
export const PAYMENT_FAILURE_PAYMENT_ALREADY_EXISTS = 'PAYMENT_ALREADY_EXISTS';
31+
export const PAYMENT_FAILURE_PAYMENT_ALREADY_SETTLED = 'PAYMENT_ALREADY_SETTLED';
32+
export const PAYMENT_FAILURE_PAYMENT_ALREADY_IN_FLIGHT = 'PAYMENT_ALREADY_IN_FLIGHT';
33+
export const PAYMENT_FAILURE_TRANSIENT_ERROR_RETRY_LATER = 'TRANSIENT_ERROR_RETRY_LATER';
3234
export const PAYMENT_FAILURE_CANCELED = 'CANCELED';
3335
export const PAYMENT_FAILURE_FORCE_FAILED = 'FORCE_FAILED';
3436

@@ -41,7 +43,9 @@ export const PaymentFailureReason = t.union([
4143
t.literal(PAYMENT_FAILURE_INSUFFICIENT_WALLET_BALANCE),
4244
t.literal(PAYMENT_FAILURE_EXCESS_WALLET_BALANCE),
4345
t.literal(PAYMENT_FAILURE_INVOICE_EXPIRED),
44-
t.literal(PAYMENT_FAILURE_PAYMENT_ALREADY_EXISTS),
46+
t.literal(PAYMENT_FAILURE_PAYMENT_ALREADY_SETTLED),
47+
t.literal(PAYMENT_FAILURE_PAYMENT_ALREADY_IN_FLIGHT),
48+
t.literal(PAYMENT_FAILURE_TRANSIENT_ERROR_RETRY_LATER),
4549
t.literal(PAYMENT_FAILURE_CANCELED),
4650
t.literal(PAYMENT_FAILURE_FORCE_FAILED),
4751
]);
@@ -54,6 +58,7 @@ export type PaymentFailureReason = t.TypeOf<typeof PaymentFailureReason>;
5458
export const PaymentInfo = t.intersection(
5559
[
5660
t.type({
61+
id: t.string,
5762
paymentHash: t.string,
5863
walletId: t.string,
5964
txRequestId: t.string,
@@ -83,7 +88,7 @@ export const ListPaymentsResponse = t.intersection(
8388
}),
8489
t.partial({
8590
/**
86-
* This is the paymentHash of the last Payment in the last iteration.
91+
* This is the paymentId of the last Payment in the last iteration.
8792
* Providing this value as the prevId in the next request will return the next batch of payments.
8893
* */
8994
nextBatchPrevId: t.string,
@@ -102,7 +107,8 @@ export const PaymentQuery = t.partial(
102107
limit: BigIntFromString,
103108
startDate: DateFromISOString,
104109
endDate: DateFromISOString,
105-
/** paymentHash provided by nextBatchPrevId in the previous list */
110+
paymentHash: t.string,
111+
/** paymentId provided by nextBatchPrevId in the previous list */
106112
prevId: t.string,
107113
},
108114
'PaymentQuery'
@@ -129,6 +135,7 @@ export const LndCreatePaymentResponse = t.intersection(
129135
paymentHash: t.string,
130136
}),
131137
t.partial({
138+
paymentId: t.string,
132139
paymentPreimage: t.string,
133140
amountMsat: t.string,
134141
feeMsat: t.string,

modules/abstract-lightning/src/wallet/lightning.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,19 +170,20 @@ export interface ILightningWallet {
170170
*/
171171
withdrawOnchain(params: LightningOnchainWithdrawParams): Promise<LightningOnchainWithdrawResponse>;
172172
/**
173-
* Get payment details by payment hash
174-
* @param {string} paymentHash - Payment hash to lookup
173+
* Get payment details by payment id
174+
* @param {string} paymentId - Payment id to lookup
175175
* @returns {Promise<PaymentInfo>} Payment details
176-
* @throws {InvalidPaymentHash} When payment hash is not valid
176+
* @throws {InvalidPaymentId} When payment id is not valid
177177
*/
178-
getPayment(paymentHash: string): Promise<PaymentInfo>;
178+
getPayment(paymentId: string): Promise<PaymentInfo>;
179179
/**
180180
* List payments for a wallet with optional filtering
181181
* @param {PaymentQuery} params Query parameters for filtering payments
182182
* @param {string} [params.status] The status of the payment
183183
* @param {bigint} [params.limit] The maximum number of payments to return
184184
* @param {Date} [params.startDate] The start date for the query
185185
* @param {Date} [params.endDate] The end date for the query
186+
* @param {string} [params.paymentHash] The payment hash of the payments
186187
* @param {string} [params.prevId] Continue iterating (provided by nextBatchPrevId in the previous list)
187188
* @returns {Promise<ListPaymentsResponse>} List of payments and nextBatchPrevId
188189
*/
@@ -393,9 +394,9 @@ export class LightningWallet implements ILightningWallet {
393394
};
394395
}
395396

396-
async getPayment(paymentHash: string): Promise<PaymentInfo> {
397+
async getPayment(paymentId: string): Promise<PaymentInfo> {
397398
const response = await this.wallet.bitgo
398-
.get(this.wallet.bitgo.url(`/wallet/${this.wallet.id()}/lightning/payment/${paymentHash}`, 2))
399+
.get(this.wallet.bitgo.url(`/wallet/${this.wallet.id()}/lightning/payment/${paymentId}`, 2))
399400
.result();
400401
return decodeOrElse(PaymentInfo.name, PaymentInfo, response, (error) => {
401402
throw new Error(`Invalid payment response: ${error}`);

modules/bitgo/test/v2/unit/lightning/lightningWallets.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,7 @@ describe('Lightning wallets', function () {
534534

535535
it('should get payments', async function () {
536536
const payment: PaymentInfo = {
537+
id: '8308fddb-2356-49aa-8548-10c23099854c',
537538
paymentHash: 'foo',
538539
walletId: wallet.wallet.id(),
539540
txRequestId: 'txReqId',
@@ -562,6 +563,7 @@ describe('Lightning wallets', function () {
562563

563564
it('should work properly with pagination while listing payments', async function () {
564565
const payment1: PaymentInfo = {
566+
id: '8308fddb-2356-49aa-8548-10c23099854c',
565567
paymentHash: 'foo1',
566568
walletId: wallet.wallet.id(),
567569
txRequestId: 'txReqId1',
@@ -575,12 +577,14 @@ describe('Lightning wallets', function () {
575577
};
576578
const payment2: PaymentInfo = {
577579
...payment1,
580+
id: '8308fddb-2356-49aa-8548-10c23099854d',
578581
paymentHash: 'foo2',
579582
txRequestId: 'txReqId2',
580583
invoice: 'tlnfoobar2',
581584
};
582585
const payment3: PaymentInfo = {
583586
...payment1,
587+
id: '8308fddb-2356-49aa-8548-10c23099854e',
584588
paymentHash: 'foo3',
585589
txRequestId: 'txReqId3',
586590
invoice: 'tlnfoobar3',

0 commit comments

Comments
 (0)