远程服务器返回错误:(401) Unauthorized with paypal

Posted

技术标签:

【中文标题】远程服务器返回错误:(401) Unauthorized with paypal【英文标题】:The remote server returned an error: (401) Unauthorized with paypal 【发布时间】:2016-12-17 21:30:27 【问题描述】:

场景

在这里,我使用paypal 使用信用卡进行直接付款,我将 CC 详细信息存储在 paypal 帐户中,paypal 返回信用卡令牌,并将此令牌号保存在我的数据库中以进行直接付款,并且通过使用此令牌,我可以使用沙盒帐户直接付款但是当我对真实帐户执行相同操作时,会出现以下错误。

远程服务器返回错误:(401) Unauthorized.

这是我的错误响应:

"name":"UNAUTHORIZED_PAYMENT","message":"未授权 付款。","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#UNAUTHORIZED_PAYMENT","debug_id":"be6ad614a3843"

这是代码

try

    Dictionary<string, string> sdkConfig = new Dictionary<string, string>();
    sdkConfig.Add("mode", "live");
    string accessToken = new OAuthTokenCredential(PayPalConfig.PaypalClientId, PayPalConfig.PaypalClientSecret, sdkConfig).GetAccessToken();
    APIContext apiContext = new APIContext(accessToken);
    apiContext.Config = sdkConfig;

    // Items within a transaction.
    var item = new Item()
    
        name = "Item Name",
        currency = "USD",
        price = "1",
        quantity = "8",
        sku = "sku"
    ;

    // A resource representing a credit card that can be used to fund a payment.
    var credCardToken = new CreditCardToken()
    
        credit_card_id = "Here CC Token Number"
    ;

    var amnt = new Amount()
    
       currency = "USD",
       total = "10",
       details = new Details()
       
           shipping = "1",
           subtotal = "8",
           tax = "1"
       
   ;

   // A transaction defines the contract of a
   // payment - what is the payment for and who
   // is fulfilling it. 
   var tran = new Transaction()
   
      amount = amnt,
      description = "This is the payment transaction description.",
      item_list = new ItemList()  items = new List<Item>()  item  
   ;

   // A resource representing a Payer's funding instrument. For stored credit card payments, set the CreditCardToken field on this object.
   var fundInstrument = new FundingInstrument()
   
       credit_card_token = credCardToken
   ;

   // A Payment Resource; create one using the above types and intent as 'sale'
   var pymnt = new Payment()
   
       intent = "sale",
       payer = new Payer()
       
           funding_instruments = new List<FundingInstrument>()  fundInstrument ,
           payment_method = "credit_card"
       ,
       transactions = new List<Transaction>()  tran 
    ;

    // Create a payment using a valid APIContext
    var createdPayment = pymnt.Create(apiContext);

catch (Exception ex)

    throw;

如果有人对此问题有任何想法,请告诉我。或者建议我哪里做错了。

【问题讨论】:

当您登录 developer.paypal.com 并单击“应用程序”选项卡时,左侧的帐户资格链接会显示什么? 【参考方案1】:

很高兴在一个月后解决了这个问题,

原因: 我的代码方面没有问题,一切都正确,但 Paypal 方面有问题。在我的帐户中,我无法更改直接信用卡权限选项“启用绿色勾号”。但现在经过与Paypal 团队的长时间讨论后解决了。您可以在下图中看到。希望这个答案也对其他人有所帮助。

【讨论】:

以上是关于远程服务器返回错误:(401) Unauthorized with paypal的主要内容,如果未能解决你的问题,请参考以下文章

远程服务器返回错误:(401) Unauthorized: Push Notification

远程服务器返回错误:(401)在Zendesk中未经授权

远程服务器返回错误:(401) Unauthorized with paypal

远程服务器返回错误:(401) Unauthorized。使用 Paypal Rest APi 时

C#使用HttpWebRequest请求url出现远程服务器返回一个错误:401未经授权

ReportViewer中的SSRS导出返回401 Unauthorized