0

I have been trying to integrate BeanStream payment gateway with my product from last three days. But unfortunately I am getting 401 authentication error every time. I have performed following steps.

  • 1) Created a test account.
  • 2) Generated API Pass Code from Configuration -> Payment Profile Configuration -> Security Settings.
  • 3) Got merchant Id from top section.
  • 4) Created an HttpWeb request using the sample code provided on BeanStream developer portal. Below is the code for that.

    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();
                }
            }
        }
    }
    

Any help?

4

1 回答 1

0

The issue you are having is that you are creating an API Key (Passcode) for a Payment Profile API (http://developer.beanstream.com/documentation/tokenize-payments/) and then using it in a Payments API (http://developer.beanstream.com/documentation/take-payments/). These two resources use different API Keys (Passcodes). See "Where is my API Passcode?" on http://developer.beanstream.com/documentation/your-first-integration/. Create an API Key for Payments API and everything should work as expected.

于 2016-07-06T20:25:33.393 回答