【问题标题】:401 Authentication issue with BeanStream Payment Gateway APIBeanStream 支付网关 API 的 401 身份验证问题
【发布时间】:2015-12-11 13:10:16
【问题描述】:

过去三天我一直在尝试将 BeanStream 支付网关与我的产品集成。但不幸的是,我每次都会收到 401 身份验证错误。我已经执行了以下步骤。

  • 1) 创建了一个测试帐户。
  • 2) 从配置 -> 支付配置文件配置 -> 安全设置生成的 API 密码。
  • 3) 从顶部获取商家 ID。
  • 4) 使用 BeanStream 开发人员门户网站上提供的示例代码创建了一个 HttpWeb 请求。下面是它的代码。

    string url = "https://www.beanstream.com/api/v1/payments";
    BeanStreamRequest req = new BeanStreamRequest
    {
        order_number = "10000123",
        amount = 100.00m,
        payment_method = "",
        card = new Card {
            name = "abc",
            number = "5100000010001004",
            expiry_month = "02",
            expiry_year = "18",
            cvd = "642"
        }
    };
    
    JavaScriptSerializer js = new JavaScriptSerializer();
    string jsonString = js.Serialize(req);
    
    string merchantId = "MERCHANT_ID";
    string apiPassCode = "API_PASS_CODE";
    string base64_encode = String.Format("{0}{1}{2}",merchantId,":",apiPassCode);
    string authorization = String.Format("{0}{1}", "Passcode ", Convert.ToBase64String(Encoding.ASCII.GetBytes(base64_encode)));
    HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
    webRequest.Method = "POST";
    webRequest.Accept = "*/*";
    webRequest.Headers[HttpRequestHeader.Authorization] = authorization;
    //webRequest.Headers.Add("Authorization ", authorization);
    webRequest.ContentType = "application/json";
    webRequest.ContentLength = jsonString.Length;
    
    StreamWriter writer = null;
    writer = new StreamWriter(webRequest.GetRequestStream());
    writer.Write(jsonString);
    writer.Close();
    
    string responseString;
    try
    {
        using (HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse())
        {
            using (StreamReader responseStream = new StreamReader(webResponse.GetResponseStream()))
            {
                responseString = responseStream.ReadToEnd();
            }
        }
    }
    catch (WebException ex)
    {
        if (ex.Response != null)
        {
            using (HttpWebResponse errorResponse = (HttpWebResponse)ex.Response)
            {
                using (StreamReader reader = new StreamReader(errorResponse.GetResponseStream()))
                {
                    string remoteEx = reader.ReadToEnd();
                }
            }
        }
    }
    

有什么帮助吗?

【问题讨论】:

    标签: c# payment-gateway beanstream


    【解决方案1】:

    您遇到的问题是您正在为支付配置文件 API (http://developer.beanstream.com/documentation/tokenize-payments/) 创建 API 密钥(密码),然后在支付 API (http://developer.beanstream.com/documentation/take-payments/) 中使用它。这两种资源使用不同的 API 密钥(密码)。请参阅“我的 API 密码在哪里?”在http://developer.beanstream.com/documentation/your-first-integration/。为 Payments API 创建一个 API 密钥,一切都应该按预期工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-15
      • 1970-01-01
      • 1970-01-01
      • 2017-07-14
      • 2019-08-24
      • 2011-01-18
      • 2015-03-28
      • 2022-01-06
      相关资源
      最近更新 更多