front dev update
This commit is contained in:
@@ -6,16 +6,18 @@ 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/page.dart';
|
||||
import 'package:pshared/models/payment/payment.dart';
|
||||
import 'package:pshared/service/authorization/service.dart';
|
||||
import 'package:pshared/service/services.dart';
|
||||
import 'package:pshared/utils/http/params.dart';
|
||||
|
||||
|
||||
class PaymentService {
|
||||
static final _logger = Logger('service.payment');
|
||||
static const String _objectType = Services.payments;
|
||||
|
||||
static Future<List<Payment>> list(
|
||||
static Future<PaymentPage> listPage(
|
||||
String organizationRef, {
|
||||
int? limit,
|
||||
String? cursor,
|
||||
@@ -25,12 +27,6 @@ class PaymentService {
|
||||
}) 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;
|
||||
}
|
||||
@@ -41,12 +37,35 @@ class PaymentService {
|
||||
queryParams['state'] = states.join(',');
|
||||
}
|
||||
|
||||
final path = '/$organizationRef';
|
||||
final url = queryParams.isEmpty
|
||||
? path
|
||||
: Uri(path: path, queryParameters: queryParams).toString();
|
||||
final url = cursorParamsToUriString(
|
||||
path: '/$organizationRef',
|
||||
limit: limit,
|
||||
cursor: cursor,
|
||||
queryParams: queryParams,
|
||||
);
|
||||
final response = await AuthorizationService.getGETResponse(_objectType, url);
|
||||
return PaymentsResponse.fromJson(response).payments.map((payment) => payment.toDomain()).toList();
|
||||
final parsed = PaymentsResponse.fromJson(response);
|
||||
final payments = parsed.payments.map((payment) => payment.toDomain()).toList();
|
||||
return PaymentPage(items: payments, nextCursor: parsed.nextCursor);
|
||||
}
|
||||
|
||||
static Future<List<Payment>> list(
|
||||
String organizationRef, {
|
||||
int? limit,
|
||||
String? cursor,
|
||||
String? sourceRef,
|
||||
String? destinationRef,
|
||||
List<String>? states,
|
||||
}) async {
|
||||
final page = await listPage(
|
||||
organizationRef,
|
||||
limit: limit,
|
||||
cursor: cursor,
|
||||
sourceRef: sourceRef,
|
||||
destinationRef: destinationRef,
|
||||
states: states,
|
||||
);
|
||||
return page.items;
|
||||
}
|
||||
|
||||
static Future<Payment> pay(
|
||||
@@ -68,4 +87,5 @@ class PaymentService {
|
||||
);
|
||||
return PaymentResponse.fromJson(response).payment.toDomain();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user