+source +destination in payments

This commit is contained in:
Stephan D
2026-03-10 19:15:20 +01:00
parent 9c2b3bf8bd
commit e5b4de5d48
16 changed files with 716 additions and 56 deletions

View File

@@ -64,8 +64,9 @@ void main() {
test('isPending and isTerminal are derived from typed state', () {
const created = Payment(
paymentRef: 'p-1',
idempotencyKey: 'idem-1',
state: 'orchestration_state_created',
source: null,
destination: null,
orchestrationState: PaymentOrchestrationState.created,
failureCode: null,
failureReason: null,
@@ -76,8 +77,9 @@ void main() {
);
const settled = Payment(
paymentRef: 'p-2',
idempotencyKey: 'idem-2',
state: 'orchestration_state_settled',
source: null,
destination: null,
orchestrationState: PaymentOrchestrationState.settled,
failureCode: null,
failureReason: null,
@@ -96,8 +98,9 @@ void main() {
test('isFailure handles both explicit code and failed state', () {
const withFailureCode = Payment(
paymentRef: 'p-3',
idempotencyKey: 'idem-3',
state: 'orchestration_state_executing',
source: null,
destination: null,
orchestrationState: PaymentOrchestrationState.executing,
failureCode: 'failure_ledger',
failureReason: 'ledger failed',
@@ -108,8 +111,9 @@ void main() {
);
const failedState = Payment(
paymentRef: 'p-4',
idempotencyKey: 'idem-4',
state: 'orchestration_state_failed',
source: null,
destination: null,
orchestrationState: PaymentOrchestrationState.failed,
failureCode: null,
failureReason: null,

View File

@@ -5,6 +5,7 @@ import 'package:test/test.dart';
import 'package:pshared/api/requests/payment/initiate.dart';
import 'package:pshared/api/requests/payment/initiate_payments.dart';
import 'package:pshared/api/requests/payment/quote.dart';
import 'package:pshared/api/responses/payment/payment.dart';
import 'package:pshared/api/responses/payment/quotation.dart';
import 'package:pshared/data/dto/money.dart';
import 'package:pshared/data/dto/payment/currency_pair.dart';
@@ -12,11 +13,13 @@ import 'package:pshared/data/dto/payment/endpoint.dart';
import 'package:pshared/data/dto/payment/intent/fx.dart';
import 'package:pshared/data/dto/payment/intent/payment.dart';
import 'package:pshared/data/mapper/payment/payment.dart';
import 'package:pshared/data/mapper/payment/payment_response.dart';
import 'package:pshared/models/payment/asset.dart';
import 'package:pshared/models/payment/chain_network.dart';
import 'package:pshared/models/payment/methods/card_token.dart';
import 'package:pshared/models/payment/methods/crypto_address.dart';
import 'package:pshared/models/payment/methods/managed_wallet.dart';
import 'package:pshared/models/payment/methods/wallet.dart';
void main() {
group('Payment request DTO contract', () {
@@ -185,5 +188,38 @@ void main() {
expect(json.containsKey('intentRef'), isFalse);
expect(json.containsKey('intentRefs'), isFalse);
});
test(
'payment response parses source and destination endpoint snapshots',
() {
final response = PaymentResponse.fromJson({
'accessToken': {
'token': 'token',
'expiration': '2026-02-25T00:00:00Z',
},
'payment': {
'paymentRef': 'pay-1',
'state': 'orchestration_state_created',
'source': {
'type': 'wallet',
'data': {'walletId': 'wallet-1'},
},
'destination': {'paymentMethodRef': 'pm-123'},
'operations': [],
'meta': {'quotationRef': 'quote-1'},
},
});
final payment = response.payment.toDomain();
expect(payment.paymentRef, equals('pay-1'));
expect(payment.source, isNotNull);
expect(payment.destination, isNotNull);
expect(payment.destination?.paymentMethodRef, equals('pm-123'));
expect(payment.source?.method, isA<WalletPaymentMethod>());
final sourceMethod = payment.source?.method as WalletPaymentMethod;
expect(sourceMethod.walletId, equals('wallet-1'));
},
);
});
}