fixes
Some checks are pending
Web App CI / test (push) Waiting to run
Web App CI / build (push) Blocked by required conditions
Deploy Mnemo Cards / Deploy Backend (push) Waiting to run
Deploy Mnemo Cards / Deploy Web App (push) Blocked by required conditions
Deploy Mnemo Cards / Final Verification (push) Blocked by required conditions

This commit is contained in:
Dmitry 2026-01-07 16:00:55 +03:00
parent ca2913ad55
commit feeced1543

View file

@ -1232,6 +1232,29 @@ class HttpRepositoryV2 {
} }
} }
/// Extract payment ID from a string that might be a full URL or just an ID
/// If the string is a URL like /api/v2/purchases/payments/{id}/verify,
/// extracts the ID. Otherwise returns the string as-is.
String _extractPaymentId(String paymentIdOrUrl) {
// If it's a full URL, try to extract the payment ID
if (paymentIdOrUrl.contains('://') || paymentIdOrUrl.startsWith('/')) {
// Try to match pattern: /purchases/payments/{id}/verify (with optional query params)
final regex = RegExp(r'/purchases/payments/([^/?]+)/verify');
final match = regex.firstMatch(paymentIdOrUrl);
if (match != null && match.groupCount >= 1) {
return match.group(1)!;
}
// Try to match pattern: payments/{id}/verify (with optional query params)
final regex2 = RegExp(r'payments/([^/?]+)/verify');
final match2 = regex2.firstMatch(paymentIdOrUrl);
if (match2 != null && match2.groupCount >= 1) {
return match2.group(1)!;
}
}
// If it doesn't look like a URL or we couldn't extract, return as-is
return paymentIdOrUrl;
}
/// Verify payment status after redirection from YooKassa. /// Verify payment status after redirection from YooKassa.
Future<PaymentVerificationResult> verifyPayment({ Future<PaymentVerificationResult> verifyPayment({
required String paymentId, required String paymentId,
@ -1239,12 +1262,15 @@ class HttpRepositoryV2 {
MnemoCardsProductType productType = MnemoCardsProductType.pack, MnemoCardsProductType productType = MnemoCardsProductType.pack,
}) async { }) async {
try { try {
// Extract actual payment ID in case a full URL was passed
final actualPaymentId = _extractPaymentId(paymentId);
final query = ApiConfigV2.buildQuery({ final query = ApiConfigV2.buildQuery({
'productId': productId, 'productId': productId,
'productType': productType.name, 'productType': productType.name,
}); });
final response = await _dio.get<Map<String, dynamic>>( final response = await _dio.get<Map<String, dynamic>>(
'${ApiConfigV2.purchasesPaymentVerify(paymentId)}$query', '${ApiConfigV2.purchasesPaymentVerify(actualPaymentId)}$query',
); );
final data = response.data ?? const <String, dynamic>{}; final data = response.data ?? const <String, dynamic>{};
return PaymentVerificationResult.fromJson(data); return PaymentVerificationResult.fromJson(data);