401 BeanStream Payment Gateway API的身份验证问题

时间:2015-09-15 10:10:20

标签: c# payment-gateway beanstream

过去三天我一直在尝试将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();
                }
            }
        }
    }
    

任何帮助?

1 个答案:

答案 0 :(得分:0)

您遇到的问题是您正在为付款资料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密钥,一切都应按预期工作。