diff --git a/.changeset/mpp-opaque-settlement-output.md b/.changeset/mpp-opaque-settlement-output.md new file mode 100644 index 0000000..7a52073 --- /dev/null +++ b/.changeset/mpp-opaque-settlement-output.md @@ -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. diff --git a/packages/core/src/flows/mpp-decode.ts b/packages/core/src/flows/mpp-decode.ts index 8633d76..c9a277b 100644 --- a/packages/core/src/flows/mpp-decode.ts +++ b/packages/core/src/flows/mpp-decode.ts @@ -28,6 +28,7 @@ export interface DecodedChallenge { expires?: string; description?: string; digest?: string; + opaque?: string; } /** @@ -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; } diff --git a/packages/core/src/flows/mpp-pay.ts b/packages/core/src/flows/mpp-pay.ts index ca3f9fd..b01705d 100644 --- a/packages/core/src/flows/mpp-pay.ts +++ b/packages/core/src/flows/mpp-pay.ts @@ -51,6 +51,8 @@ export interface MppPaySettlement { reference?: string; status?: string; timestamp?: string; + amount?: string; + currency?: string; } export interface MppPayResultSuccess extends MppPayResultBase { @@ -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; } diff --git a/packages/core/test/unit/flows/mpp-decode.test.ts b/packages/core/test/unit/flows/mpp-decode.test.ts index 12e4507..557e47a 100644 --- a/packages/core/test/unit/flows/mpp-decode.test.ts +++ b/packages/core/test/unit/flows/mpp-decode.test.ts @@ -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', () => { diff --git a/packages/core/test/unit/flows/mpp-pay.test.ts b/packages/core/test/unit/flows/mpp-pay.test.ts index 5124287..3eebfc0 100644 --- a/packages/core/test/unit/flows/mpp-pay.test.ts +++ b/packages/core/test/unit/flows/mpp-pay.test.ts @@ -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', + }); + }); });