Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/mpp-opaque-settlement-output.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@inflowpayai/inflow': minor
---

Surface the MPP challenge `opaque` blob in `mpp decode` output and the settled `amount`/`currency` on the pay result.
2 changes: 2 additions & 0 deletions packages/core/src/flows/mpp-decode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface DecodedChallenge {
expires?: string;
description?: string;
digest?: string;
opaque?: string;
}

/**
Expand Down Expand Up @@ -64,6 +65,7 @@ export function summarizeChallenge(challenge: MppChallenge): DecodedChallenge {
if (challenge.expires !== undefined) out.expires = challenge.expires;
if (challenge.description !== undefined) out.description = challenge.description;
if (challenge.digest !== undefined) out.digest = challenge.digest;
if (challenge.opaque !== undefined) out.opaque = challenge.opaque;
return out;
}

Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/flows/mpp-pay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export interface MppPaySettlement {
reference?: string;
status?: string;
timestamp?: string;
amount?: string;
currency?: string;
}

export interface MppPayResultSuccess extends MppPayResultBase {
Expand Down Expand Up @@ -196,6 +198,8 @@ export function buildSettlement(headers: Headers): MppPaySettlement | undefined
if (receipt.reference !== '') out.reference = receipt.reference;
if (receipt.status !== '') out.status = receipt.status;
if (receipt.timestamp !== '') out.timestamp = receipt.timestamp;
if (receipt.amount !== undefined) out.amount = receipt.amount;
if (receipt.currency !== undefined) out.currency = receipt.currency;
return Object.keys(out).length > 0 ? out : undefined;
}

Expand Down
9 changes: 9 additions & 0 deletions packages/core/test/unit/flows/mpp-decode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ describe('summarizeChallenge', () => {
expect(out).not.toHaveProperty('asset');
expect(out).not.toHaveProperty('chainId');
});

it('surfaces the opaque correlation blob when the challenge carries one', () => {
const out = summarizeChallenge({ ...inflowChallenge(), opaque: 'eyJpc3MiOiJpbmZsb3cifQ' });
expect(out.opaque).toBe('eyJpc3MiOiJpbmZsb3cifQ');
});

it('omits opaque when the challenge has none', () => {
expect(summarizeChallenge(inflowChallenge())).not.toHaveProperty('opaque');
});
});

describe('decodeMppValue', () => {
Expand Down
20 changes: 20 additions & 0 deletions packages/core/test/unit/flows/mpp-pay.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,4 +450,24 @@ describe('buildSettlement', () => {
timestamp: '2025-02-02T00:00:00Z',
});
});

it('includes settled amount and currency when the receipt carries them', () => {
const receipt: MppReceipt = {
challengeId: 'chal-2',
method: 'inflow',
reference: 'ref-10',
status: 'success',
timestamp: '2025-02-02T00:00:00Z',
amount: '10.5',
currency: 'USDC',
};
const headers = new Headers({ [HEADERS.PAYMENT_RECEIPT]: encode(receipt) });
expect(buildSettlement(headers)).toEqual({
reference: 'ref-10',
status: 'success',
timestamp: '2025-02-02T00:00:00Z',
amount: '10.5',
currency: 'USDC',
});
});
});
Loading