Payments listing method
This commit is contained in:
20
frontend/pshared/lib/api/responses/payment/payments.dart
Normal file
20
frontend/pshared/lib/api/responses/payment/payments.dart
Normal file
@@ -0,0 +1,20 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import 'package:pshared/api/responses/base.dart';
|
||||
import 'package:pshared/api/responses/token.dart';
|
||||
import 'package:pshared/data/dto/payment/payment.dart';
|
||||
|
||||
part 'payments.g.dart';
|
||||
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class PaymentsResponse extends BaseAuthorizedResponse {
|
||||
|
||||
final List<PaymentDTO> payments;
|
||||
|
||||
const PaymentsResponse({required super.accessToken, required this.payments});
|
||||
|
||||
factory PaymentsResponse.fromJson(Map<String, dynamic> json) => _$PaymentsResponseFromJson(json);
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$PaymentsResponseToJson(this);
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
import 'package:logging/logging.dart';
|
||||
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
import 'package:pshared/api/requests/payment/initiate.dart';
|
||||
import 'package:pshared/api/responses/payment/payment.dart';
|
||||
import 'package:pshared/api/responses/payment/payments.dart';
|
||||
import 'package:pshared/data/mapper/payment/payment_response.dart';
|
||||
import 'package:pshared/models/payment/payment.dart';
|
||||
import 'package:pshared/service/authorization/service.dart';
|
||||
@@ -13,6 +15,40 @@ class PaymentService {
|
||||
static final _logger = Logger('service.payment');
|
||||
static const String _objectType = Services.payments;
|
||||
|
||||
static Future<List<Payment>> list(
|
||||
String organizationRef, {
|
||||
int? limit,
|
||||
String? cursor,
|
||||
String? sourceRef,
|
||||
String? destinationRef,
|
||||
List<String>? states,
|
||||
}) async {
|
||||
_logger.fine('Listing payments for organization $organizationRef');
|
||||
final queryParams = <String, String>{};
|
||||
if (limit != null) {
|
||||
queryParams['limit'] = limit.toString();
|
||||
}
|
||||
if (cursor != null && cursor.isNotEmpty) {
|
||||
queryParams['cursor'] = cursor;
|
||||
}
|
||||
if (sourceRef != null && sourceRef.isNotEmpty) {
|
||||
queryParams['source_ref'] = sourceRef;
|
||||
}
|
||||
if (destinationRef != null && destinationRef.isNotEmpty) {
|
||||
queryParams['destination_ref'] = destinationRef;
|
||||
}
|
||||
if (states != null && states.isNotEmpty) {
|
||||
queryParams['state'] = states.join(',');
|
||||
}
|
||||
|
||||
final path = '/$organizationRef';
|
||||
final url = queryParams.isEmpty
|
||||
? path
|
||||
: Uri(path: path, queryParameters: queryParams).toString();
|
||||
final response = await AuthorizationService.getGETResponse(_objectType, url);
|
||||
return PaymentsResponse.fromJson(response).payments.map((payment) => payment.toDomain()).toList();
|
||||
}
|
||||
|
||||
static Future<Payment> pay(
|
||||
String organizationRef,
|
||||
String quotationRef, {
|
||||
|
||||
Reference in New Issue
Block a user