diff --git a/mnemo_cards_web_v2/lib/domain/services/http_repository_v2.dart b/mnemo_cards_web_v2/lib/domain/services/http_repository_v2.dart index ddc6d5b..c1c9685 100644 --- a/mnemo_cards_web_v2/lib/domain/services/http_repository_v2.dart +++ b/mnemo_cards_web_v2/lib/domain/services/http_repository_v2.dart @@ -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. Future verifyPayment({ required String paymentId, @@ -1239,12 +1262,15 @@ class HttpRepositoryV2 { MnemoCardsProductType productType = MnemoCardsProductType.pack, }) async { try { + // Extract actual payment ID in case a full URL was passed + final actualPaymentId = _extractPaymentId(paymentId); + final query = ApiConfigV2.buildQuery({ 'productId': productId, 'productType': productType.name, }); final response = await _dio.get>( - '${ApiConfigV2.purchasesPaymentVerify(paymentId)}$query', + '${ApiConfigV2.purchasesPaymentVerify(actualPaymentId)}$query', ); final data = response.data ?? const {}; return PaymentVerificationResult.fromJson(data);