removed intent_ref from frontend
This commit is contained in:
@@ -1,40 +1,20 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:pshared/api/requests/payment/base.dart';
|
||||
|
||||
part 'initiate_payments.g.dart';
|
||||
|
||||
|
||||
@JsonSerializable()
|
||||
class InitiatePaymentsRequest extends PaymentBaseRequest {
|
||||
final String quoteRef;
|
||||
final String? intentRef;
|
||||
final List<String>? intentRefs;
|
||||
|
||||
const InitiatePaymentsRequest({
|
||||
required super.idempotencyKey,
|
||||
super.metadata,
|
||||
required this.quoteRef,
|
||||
this.intentRef,
|
||||
this.intentRefs,
|
||||
});
|
||||
|
||||
factory InitiatePaymentsRequest.fromJson(Map<String, dynamic> json) {
|
||||
return InitiatePaymentsRequest(
|
||||
idempotencyKey: json['idempotencyKey'] as String,
|
||||
metadata: (json['metadata'] as Map<String, dynamic>?)?.map(
|
||||
(key, value) => MapEntry(key, value as String),
|
||||
),
|
||||
quoteRef: json['quoteRef'] as String,
|
||||
intentRef: json['intentRef'] as String?,
|
||||
intentRefs: (json['intentRefs'] as List<dynamic>?)
|
||||
?.map((value) => value as String)
|
||||
.toList(),
|
||||
);
|
||||
}
|
||||
|
||||
factory InitiatePaymentsRequest.fromJson(Map<String, dynamic> json) => _$InitiatePaymentsRequestFromJson(json);
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return <String, dynamic>{
|
||||
'idempotencyKey': idempotencyKey,
|
||||
'metadata': metadata,
|
||||
'quoteRef': quoteRef,
|
||||
if (intentRef != null) 'intentRef': intentRef,
|
||||
if (intentRefs != null) 'intentRefs': intentRefs,
|
||||
};
|
||||
}
|
||||
Map<String, dynamic> toJson() => _$InitiatePaymentsRequestToJson(this);
|
||||
}
|
||||
|
||||
@@ -30,8 +30,6 @@ class MultiPaymentProvider extends ChangeNotifier {
|
||||
Future<List<Payment>> pay({
|
||||
String? idempotencyKey,
|
||||
Map<String, String>? metadata,
|
||||
String? intentRef,
|
||||
List<String>? intentRefs,
|
||||
}) async {
|
||||
if (!_organization.isOrganizationSet) {
|
||||
throw StateError('Organization is not set');
|
||||
@@ -54,8 +52,6 @@ class MultiPaymentProvider extends ChangeNotifier {
|
||||
quoteRef,
|
||||
idempotencyKey: idempotencyKey,
|
||||
metadata: metadata,
|
||||
intentRef: intentRef,
|
||||
intentRefs: intentRefs,
|
||||
);
|
||||
|
||||
_setResource(
|
||||
|
||||
@@ -37,8 +37,6 @@ class MultiplePaymentsService {
|
||||
String quoteRef, {
|
||||
String? idempotencyKey,
|
||||
Map<String, String>? metadata,
|
||||
String? intentRef,
|
||||
List<String>? intentRefs,
|
||||
}) async {
|
||||
_logger.fine(
|
||||
'Executing multiple payments for quote $quoteRef in $organizationRef',
|
||||
@@ -47,8 +45,6 @@ class MultiplePaymentsService {
|
||||
idempotencyKey: idempotencyKey ?? const Uuid().v4(),
|
||||
quoteRef: quoteRef,
|
||||
metadata: metadata,
|
||||
intentRef: intentRef,
|
||||
intentRefs: intentRefs,
|
||||
);
|
||||
|
||||
final response = await AuthorizationService.getPOSTResponse(
|
||||
|
||||
@@ -158,15 +158,15 @@ void main() {
|
||||
final request = InitiatePaymentRequest(
|
||||
idempotencyKey: 'idem-2',
|
||||
quoteRef: 'q-1',
|
||||
metadata: const {'intent_ref': 'intent-1'},
|
||||
metadata: const {'client_payment_ref': 'cp-1'},
|
||||
);
|
||||
|
||||
final json = request.toJson();
|
||||
expect(json['idempotencyKey'], equals('idem-2'));
|
||||
expect(json['quoteRef'], equals('q-1'));
|
||||
expect(
|
||||
(json['metadata'] as Map<String, dynamic>)['intent_ref'],
|
||||
equals('intent-1'),
|
||||
(json['metadata'] as Map<String, dynamic>)['client_payment_ref'],
|
||||
equals('cp-1'),
|
||||
);
|
||||
expect(json.containsKey('intent'), isTrue);
|
||||
expect(json['intent'], isNull);
|
||||
@@ -176,35 +176,18 @@ void main() {
|
||||
final request = InitiatePaymentsRequest(
|
||||
idempotencyKey: 'idem-3',
|
||||
quoteRef: 'q-2',
|
||||
intentRefs: const ['intent-a', 'intent-b'],
|
||||
metadata: const {'client_payment_ref': 'cp-1'},
|
||||
);
|
||||
|
||||
final json = request.toJson();
|
||||
expect(json['idempotencyKey'], equals('idem-3'));
|
||||
expect(json['quoteRef'], equals('q-2'));
|
||||
expect(json['intentRefs'], equals(const ['intent-a', 'intent-b']));
|
||||
expect(
|
||||
(json['metadata'] as Map<String, dynamic>)['client_payment_ref'],
|
||||
equals('cp-1'),
|
||||
);
|
||||
expect(json.containsKey('intentRef'), isFalse);
|
||||
expect(json.containsKey('intentRefs'), isFalse);
|
||||
});
|
||||
|
||||
test(
|
||||
'initiate multi payments request supports single intentRef selector',
|
||||
() {
|
||||
final request = InitiatePaymentsRequest(
|
||||
idempotencyKey: 'idem-4',
|
||||
quoteRef: 'q-2',
|
||||
intentRef: 'intent-single',
|
||||
);
|
||||
|
||||
final json = request.toJson();
|
||||
expect(json['idempotencyKey'], equals('idem-4'));
|
||||
expect(json['quoteRef'], equals('q-2'));
|
||||
expect(json['intentRef'], equals('intent-single'));
|
||||
expect(json.containsKey('intentRefs'), isFalse);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -188,7 +188,6 @@ class MultiplePayoutsProvider extends ChangeNotifier {
|
||||
try {
|
||||
_setState(MultiplePayoutsState.sending);
|
||||
_error = null;
|
||||
final intentRefs = _quotedIntentRefs();
|
||||
|
||||
final result = await payment.pay(
|
||||
metadata: <String, String>{
|
||||
@@ -198,7 +197,6 @@ class MultiplePayoutsProvider extends ChangeNotifier {
|
||||
'upload_rows': _rows.length.toString(),
|
||||
...?_uploadAmountMetadata(),
|
||||
},
|
||||
intentRefs: intentRefs.isEmpty ? null : intentRefs,
|
||||
);
|
||||
|
||||
_sentCount = result.length;
|
||||
@@ -274,20 +272,6 @@ class MultiplePayoutsProvider extends ChangeNotifier {
|
||||
List<PaymentQuote> _quoteItems() =>
|
||||
_quotation?.quotation?.items ?? const <PaymentQuote>[];
|
||||
|
||||
List<String> _quotedIntentRefs() {
|
||||
final seen = <String>{};
|
||||
final intentRefs = <String>[];
|
||||
for (final quote in _quoteItems()) {
|
||||
final intentRef = (quote.intentRef ?? '').trim();
|
||||
if (intentRef.isEmpty || seen.contains(intentRef)) {
|
||||
continue;
|
||||
}
|
||||
seen.add(intentRef);
|
||||
intentRefs.add(intentRef);
|
||||
}
|
||||
return intentRefs;
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_quotation?.removeListener(_onQuotationChanged);
|
||||
|
||||
Reference in New Issue
Block a user