{"record":{"id":"13a77288f3260811","repo":"nopSolutions/nopCommerce","slug":"the-refund-could-not-be-processed","errorCode":null,"errorMessage":"The refund could not be processed","messagePattern":"The refund could not be processed","errorType":"exception","errorClass":"NopException","httpStatus":null,"severity":"error","filePath":"src/Plugins/Nop.Plugin.Payments.PayPalCommerce/Services/PayPalCommerceServiceManager.cs","lineNumber":2579,"sourceCode":"            var currencyCode = (await _currencyService.GetCurrencyByIdAsync(_currencySettings.PrimaryStoreCurrencyId))?.CurrencyCode;\n            if (string.IsNullOrEmpty(currencyCode))\n                throw new NopException(\"Primary store currency not set\");\n\n            if (string.IsNullOrEmpty(nopOrder.CaptureTransactionId))\n                throw new NopException(\"Capture ID not set\");\n\n            var request = new CreateRefundRequest\n            {\n                CaptureId = nopOrder.CaptureTransactionId,\n                Amount = amount.HasValue ? PrepareMoney(amount.Value, currencyCode) : null\n            };\n            var refund = await _httpClient.RequestAsync<CreateRefundRequest, CreateRefundResponse>(request, settings);\n\n            if (refund.Status?.ToUpper() == RefundStatusType.CANCELLED.ToString())\n                throw new NopException(\"The refund was cancelled\");\n\n            if (refund.Status?.ToUpper() == RefundStatusType.FAILED.ToString())\n                throw new NopException(\"The refund could not be processed\");\n\n            if (refund.Status?.ToUpper() == RefundStatusType.PENDING.ToString())\n                throw new NopException($\"Capture is in {refund.Status} status due to {refund.StatusDetails?.Reason}\");\n\n            //save id to avoid double refund\n            var refundIds = await _genericAttributeService\n                .GetAttributeAsync<List<string>>(nopOrder, PayPalCommerceDefaults.RefundIdAttributeName)\n                ?? new();\n            if (!refundIds.Contains(refund.Id))\n                refundIds.Add(refund.Id);\n            await _genericAttributeService.SaveAttributeAsync(nopOrder, PayPalCommerceDefaults.RefundIdAttributeName, refundIds);\n\n            return refund;\n        });\n    }\n\n    #endregion\n","sourceCodeStart":2561,"sourceCodeEnd":2597,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Plugins/Nop.Plugin.Payments.PayPalCommerce/Services/PayPalCommerceServiceManager.cs#L2561-L2597","documentation":"Thrown by RefundAsync when PayPal returns a refund resource with status FAILED. This means PayPal declined to process the refund, typically for funds, account, or restriction reasons, after the API call itself succeeded. It is reported as the Error string and the refund id is not recorded.","triggerScenarios":"PayPal declines the refund: insufficient merchant PayPal balance; account limited/restricted; the capture was already fully refunded; currency/amount constraints rejected it.","commonSituations":"Merchant PayPal balance insufficient to fund the refund; account under limitation; duplicate refund attempt after a prior one already consumed the capture.","solutions":["Ensure the PayPal account has sufficient balance in the capture currency to cover the refund.","Check the PayPal dashboard for account limitations and resolve them, then retry.","Confirm the capture has not already been fully refunded before retrying."],"exampleFix":"// before\nvar (refund, err) = await _serviceManager.RefundAsync(settings, order, amount);\n\n// after\nvar (refund, err) = await _serviceManager.RefundAsync(settings, order, amount);\nif (!string.IsNullOrEmpty(err))\n{\n    NotifyAdmin($\"Refund failed: {err}. Verify PayPal balance and account status.\");\n    return; // leave order un-refunded so it can be retried\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"var (refund, error) = await mgr.RefundAsync(settings, order, amount);\nif (!string.IsNullOrEmpty(error))\n{\n    NotifyAdmin($\"Refund failed: {error}. Check PayPal balance/account status.\");\n    // leave refundable; retry once the account is in good standing\n    return;\n}","preventionTips":["Keep sufficient balance in the capture currency in the PayPal account.","Resolve PayPal account limitations promptly.","Check for prior full refunds on the capture before retrying."],"tags":["payments","paypal-commerce","refund","status","account"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}