36 lines
1.2 KiB
Dart
36 lines
1.2 KiB
Dart
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/data/mapper/payment/payment_response.dart';
|
|
import 'package:pshared/models/payment/payment.dart';
|
|
import 'package:pshared/service/authorization/service.dart';
|
|
import 'package:pshared/service/services.dart';
|
|
|
|
|
|
class PaymentService {
|
|
static final _logger = Logger('service.payment');
|
|
static const String _objectType = Services.payments;
|
|
|
|
static Future<Payment> pay(
|
|
String organizationRef,
|
|
String quotationRef, {
|
|
String? idempotencyKey,
|
|
Map<String, String>? metadata,
|
|
}) async {
|
|
_logger.fine('Executing payment for quotation $quotationRef in $organizationRef');
|
|
final request = InitiatePaymentRequest(
|
|
idempotencyKey: idempotencyKey ?? Uuid().v4(),
|
|
quoteRef: quotationRef,
|
|
metadata: metadata,
|
|
);
|
|
final response = await AuthorizationService.getPOSTResponse(
|
|
_objectType,
|
|
'/by-quote/$organizationRef',
|
|
request.toJson(),
|
|
);
|
|
return PaymentResponse.fromJson(response).payment.toDomain();
|
|
}
|
|
}
|