2015-09-15 85 views
0

我一直在嘗試將BeanStream支付網關與我的產品從最近三天進行整合。但不幸的是,我每次都收到401驗證錯誤。我已經執行了以下步驟。401 BeanStream支付網關API認證問題

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

任何幫助嗎?

回答

0

您遇到的問題是您要爲付款資料API(http://developer.beanstream.com/documentation/tokenize-payments/)創建API密鑰(密碼),然後在Payments API(http://developer.beanstream.com/documentation/take-payments/)中使用它。這兩個資源使用不同的API密鑰(密碼)。請參閱「我的API密碼在哪裏?」在http://developer.beanstream.com/documentation/your-first-integration/。爲Payments API創建一個API密鑰,一切都應按預期工作。