【问题标题】:Keep getting response code 500 in Cardpointe API call在 Cardpointe API 调用中不断收到响应代码 500
【发布时间】:2021-12-26 05:46:40
【问题描述】:

我在对 Cardpointe 网关 (cardconnect) 的 API 调用中不断收到 500 响应代码,任何见解都会有所帮助。 (我可以通过在没有 auth 端点的情况下发布到 URL 来验证测试凭据)

这是我在 Google Apps 脚本中的代码:

function myFunction() {

  var messagesUrl = "https://fts-uat.cardconnect.com/cardconnect/rest/auth";
  var cred = "testing:testing123";
    
  var payload = JSON.stringify({
  "merchid" : "496160873888",
  "account": "4788250000121443",
  "expiry": "1218",
  "cvv2": "123",
  "amount": "100",
  "phone": "15558889999",
  "capture": "y"
  });

  
  var options = {
    "method" : "put",
   "payload" : payload
  };
  
  options.headers = {    
    "Authorization" : "Basic " + Utilities.base64Encode(cred)
    },{
    "Content-Type" : "application/json"
    }
  var res = UrlFetchApp.fetch(messagesUrl, options);
  
  Logger.log(res);
  
}

【问题讨论】:

  • 能否提供你要使用的API的官方文档?
  • options.headers = { "Authorization" : "Basic " + Utilities.base64Encode(cred) },{ "Content-Type" : "application/json" } 应该是options.headers = { "Authorization" : "Basic " + Utilities.base64Encode(cred), "Content-Type" : "application/json" }
  • @Tanaike 感谢您的关注,这里是 API 文档 https://developer.cardpointe.com/cardconnect-api,这里是沙盒测试文档 https://developer.cardpointe.com/guides/cardpointe-gateway
  • @TheMaster。谢谢你成功了!

标签: javascript google-apps-script httprequest http-status-code-500


【解决方案1】:
options.headers = {    
    "Authorization" : "Basic " + Utilities.base64Encode(cred)
    },{
    "Content-Type" : "application/json"
    }

此处的内容类型未设置为options.headers

/*<ignore>*/console.config({maximize:true,timeStamps:false,autoScroll:false});/*</ignore>*/ 
const options ={};
options.headers = {    
"Authorization" : "Basic " + "b64"
},{
"Content-Type" : "application/json"
}
console.log(options)
&lt;!-- https://meta.stackoverflow.com/a/375985/ --&gt;    &lt;script src="https://gh-canon.github.io/stack-snippet-console/console.min.js"&gt;&lt;/script&gt;

headers 应该是具有多个键的单个对象:

options.headers = {    
    "Authorization" : "Basic " + Utilities.base64Encode(cred),
    "Content-Type" : "application/json"
    }

/*<ignore>*/console.config({maximize:true,timeStamps:false,autoScroll:false});/*</ignore>*/ 
const options={}
options.headers = {    
"Authorization" : "Basic " + "b64",
"Content-Type" : "application/json"
}
console.log(options)
&lt;!-- https://meta.stackoverflow.com/a/375985/ --&gt;    &lt;script src="https://gh-canon.github.io/stack-snippet-console/console.min.js"&gt;&lt;/script&gt;

/*<ignore>*/console.config({maximize:true,timeStamps:false,autoScroll:false});/*</ignore>*/ 
let a;
a = 1,3;
console.log(a);// no 3
&lt;!-- https://meta.stackoverflow.com/a/375985/ --&gt;    &lt;script src="https://gh-canon.github.io/stack-snippet-console/console.min.js"&gt;&lt;/script&gt;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-06-23
    • 1970-01-01
    • 2019-04-27
    • 2022-11-10
    • 2022-12-20
    • 2014-10-29
    • 1970-01-01
    相关资源
    最近更新 更多