TRON -> TRON_MAINNET

This commit is contained in:
Stephan D
2026-02-01 03:35:16 +01:00
parent be3fd6075f
commit 8faed5cbaa
28 changed files with 452 additions and 90 deletions

View File

@@ -0,0 +1,11 @@
class DownloadedFile {
final List<int> bytes;
final String filename;
final String mimeType;
const DownloadedFile({
required this.bytes,
required this.filename,
required this.mimeType,
});
}

View File

@@ -10,6 +10,7 @@ class OperationItem {
final double toAmount;
final String toCurrency;
final String payId;
final String? paymentRef;
final String? cardNumber;
final PaymentMethod? paymentMethod;
final String name;
@@ -24,10 +25,11 @@ class OperationItem {
required this.toAmount,
required this.toCurrency,
required this.payId,
this.paymentRef,
this.cardNumber,
this.paymentMethod,
required this.name,
required this.date,
required this.comment,
});
}
}

View File

@@ -79,6 +79,11 @@ class AuthorizationService {
return httpr.getGETResponse(service, url, authToken: token);
}
static Future<httpr.BinaryResponse> getGETBinaryResponse(String service, String url) async {
final token = await TokenService.getAccessTokenSafe();
return httpr.getBinaryGETResponse(service, url, authToken: token);
}
static Future<Map<String, dynamic>> getPOSTResponse(String service, String url, Map<String, dynamic> body) async {
final token = await TokenService.getAccessTokenSafe();
return httpr.getPOSTResponse(service, url, body, authToken: token);

View File

@@ -0,0 +1,44 @@
import 'package:logging/logging.dart';
import 'package:pshared/models/file/downloaded_file.dart';
import 'package:pshared/service/authorization/service.dart';
import 'package:pshared/service/services.dart';
class PaymentDocumentsService {
static final _logger = Logger('service.payment_documents');
static const String _objectType = Services.payments;
static Future<DownloadedFile> getAct(String organizationRef, String paymentRef) async {
final encodedRef = Uri.encodeQueryComponent(paymentRef);
final url = '/documents/act/$organizationRef?payment_ref=$encodedRef';
_logger.fine('Downloading act document for payment $paymentRef');
final response = await AuthorizationService.getGETBinaryResponse(_objectType, url);
final filename = _filenameFromDisposition(response.header('content-disposition')) ??
'act_$paymentRef.pdf';
final mimeType = response.header('content-type') ?? 'application/pdf';
return DownloadedFile(
bytes: response.bytes,
filename: filename,
mimeType: mimeType,
);
}
static String? _filenameFromDisposition(String? disposition) {
if (disposition == null || disposition.isEmpty) return null;
final parts = disposition.split(';');
for (final part in parts) {
final trimmed = part.trim();
if (trimmed.toLowerCase().startsWith('filename=')) {
var value = trimmed.substring('filename='.length).trim();
if (value.startsWith('"') && value.endsWith('"') && value.length > 1) {
value = value.substring(1, value.length - 1);
}
if (value.isNotEmpty) {
return value;
}
}
}
return null;
}
}

View File

@@ -163,3 +163,49 @@ Future<FileUploaded?> getFileUploadResponse(String service, String url, String f
final streamedResponse = await _fileUploadRequest(service, url, fileName, fileType, mediaType, bytes, authToken: authToken);
return FileUploaded.fromJson(await _handleResponse(http.Response.fromStream(streamedResponse)));
}
class BinaryResponse {
final List<int> bytes;
final Map<String, String> headers;
final int statusCode;
const BinaryResponse({
required this.bytes,
required this.headers,
required this.statusCode,
});
String? header(String key) => headers[key.toLowerCase()];
}
Future<BinaryResponse> getBinaryGETResponse(String service, String url, {String? authToken}) async {
late http.Response response;
try {
response = await getRequest(service, url, authToken: authToken);
} catch (e) {
throw ConnectivityError(message: e.toString());
}
if (response.statusCode < 200 || response.statusCode >= 300) {
late HTTPMessage message;
try {
message = HTTPMessage.fromJson(json.decode(response.body));
} catch (e) {
_throwConnectivityError(response, e);
}
late ErrorResponse error;
try {
error = ErrorResponse.fromJson(message.data);
} catch (e) {
_throwConnectivityError(response, e);
}
throw error;
}
return BinaryResponse(
bytes: response.bodyBytes,
headers: response.headers,
statusCode: response.statusCode,
);
}

View File

@@ -8,7 +8,7 @@ environment:
# Add regular dependencies here.
dependencies:
analyzer: ^10.0.0
json_annotation: ^4.9.0
json_annotation: ^4.10.0
http: ^1.1.0
provider: ^6.0.5
flutter: