Paypal 贝宝验证错误

Paypal 贝宝验证错误,paypal,Paypal,我最初在另一个SO帖子(旧版:)上发布了这个问题作为评论,但由于我没有看到任何回应,我认为一个问题可能是最好的 在自己不更改RestAPISDK的情况下,有没有办法让它在发生验证错误时将错误消息返回到我的代码中?目前,我唯一的行动是阅读日志文件,看看发生了什么,但当我试图向用户报告为什么卡号无效、过期等简单的事情收费失败时,这对我没有好处。现在我们收到了400个错误请求,但由于故障被记录下来,API显然看到了发生的情况,只是没有报告 下面是我正在使用的代码-当我执行payment.Create(

我最初在另一个SO帖子(旧版:)上发布了这个问题作为评论,但由于我没有看到任何回应,我认为一个问题可能是最好的

在自己不更改RestAPISDK的情况下,有没有办法让它在发生验证错误时将错误消息返回到我的代码中?目前,我唯一的行动是阅读日志文件,看看发生了什么,但当我试图向用户报告为什么卡号无效、过期等简单的事情收费失败时,这对我没有好处。现在我们收到了400个错误请求,但由于故障被记录下来,API显然看到了发生的情况,只是没有报告

下面是我正在使用的代码-当我执行payment.Create(apiContext)时,会遇到错误


编辑:添加了示例代码

您的代码有问题。发布您使用PAYPAL SDK编写的代码。发布的代码-非常通用。我不会使用PAYPAL API执行此操作,我会在您将其发送到PAYPAL之前执行此操作。谷歌卢恩算法为您尊重的语言。你会发现大量的链接。这并不是说我只是试图利用他们的API进行验证,而是每当一张卡无法处理(为什么不相关)时,就会抛出一个异常,真正的错误就会显示在他们的日志文件中。我需要一种方法来获取真正的错误消息,而不仅仅是一个硬异常。
var card = new PayPal.Api.Payments.CreditCard
        {
            billing_address = new PayPal.Api.Payments.Address
            {
                city = customer.BillingAddress.City,
                country_code = customer.BillingAddress.Country,
                line1 = customer.BillingAddress.Address1,                    
                postal_code = customer.BillingAddress.PostalCode,
                state = customer.BillingAddress.StateProvince
            },
            cvv2 = customer.CreditAccount.SecurityCode,
            expire_month = customer.CreditAccount.ExpirationMonth,
            expire_year = customer.CreditAccount.ExpirationYear,
            first_name = customer.FirstName,
            last_name = customer.LastName,
            number = customer.CreditAccount.CardNumber
        };

        //only send line 2 if it exists, otherwise it'll error out
        if (!string.IsNullOrEmpty(customer.BillingAddress.Address2))
            card.billing_address.line2 = customer.BillingAddress.Address2;

        switch (customer.CreditAccount.CardType)
        {
            case CardTypes.AmericanExpress:
                card.type = "amex";
                break;

            default:
                card.type = customer.CreditAccount.CardType.ToString().ToLower();
                break;
        }

        var amt = new PayPal.Api.Payments.Amount
        {
            currency = "USD",
            details = new PayPal.Api.Payments.Details
            {
                shipping = Math.Round(customer.CreditAccount.Shipping, 2).ToString(),
                subtotal = Math.Round(customer.CreditAccount.Amount, 2).ToString(),
                tax = Math.Round(customer.CreditAccount.Tax, 2).ToString()
            },
            total = Math.Round(customer.CreditAccount.GrandTotal, 2).ToString()
        };

        var payer = new PayPal.Api.Payments.Payer
        {
            funding_instruments = (new FundingInstrument[] { new FundingInstrument { credit_card = card } }).ToList(),
            payment_method = "credit_card"
        };

        var payment = new Payment
        {
            intent = "sale",
            payer = payer,
            transactions = (new Transaction[] {
                new Transaction { description = customer.CreditAccount.Description, amount = amt }
            }).ToList()
        };

        try
        {
            var accessToken = new PayPal.OAuthTokenCredential(this.Configuration.ClientID, this.Configuration.ClientSecret).GetAccessToken();
            var apiContext = new PayPal.APIContext(accessToken);

            var result = payment.Create(apiContext);

            if (result.state == "approved")
                creditResponse = new CreditResponse { AuthorizationCode = result.id, Status = CreditResponseTypes.Success, TransactionId = result.id };
            else
                creditResponse = new CreditResponse { Status = CreditResponseTypes.Declined };
        }
        catch (Exception ex)
        {
            creditResponse = new CreditResponse
            {
                Message = ex.ToString(),
                Status = CreditResponseTypes.Error
            };
        }