如何解决Zuora付款方法/信用卡api从Java客户端返回90000011,但从邮递员返回成功响应
我正在与我的应用程序集成zuora api。这些是我通过以下步骤使用的以下3种三种API-
第1步请求身份验证令牌
Service api (Test)- https://rest.apisandBox.zuora.com/oauth/token
Request Headers - Content-Type:application/x-www-form-urlencoded
Authorization:Basic YWYzNTg5ZWMtNTFmMC00YTc2LWFlZjEtYjk0YzZmYWE0Y2ViOlJDdGV5OGlTWFFUc00xQytTPTFYWD1POE9tRWM1c0FBWVBaaE5vV24=
请求正文-grant_type:client_credentials
响应正文-{
“ access_token”:“ 41947f41d664437a98a9da38a293c89d”,
“ token_type”:“承载者”,
“ expires_in”:3598,
“ scope”:“ entity.a083d63b-b3f5-8626-f793-65cec903f9ca platform.write service.events.read service.events.write service.genesis.read service.genesis.write service.notifications.read service.notifications.write service .usage.delete service.usage.update service.usage.write tenant.41231 user.2c92c094738e5b090173902066c201ba“,
“ jti”:“ 41947f41d664437a98a9da38a293c89d”
}
使用auth令牌响应中的access_token或jti值,并将其作为Authorization:Bearer传递给标头参数
第2步:-请求进行付款的hmac签名
Service api (Test) - https://rest.apisandBox.zuora.com/v1/hmac-signatures
Request Headers - Content-Type:application/json
Authorization:Bearer 41947f41d664437a98a9da38a293c89d
Request Body - {
"accountKey": "A00000485","method": "POST","uri": "https://rest.apisandBox.zuora.com/v1/payment-methods/credit-cards"
}
Response Body - {
"signature": "MDgzN2ZkYjAzOTQ5NmQ5NDQyZjc5YTU3NjUwMDgxOGIxNTY3YWM2Mw==","token": "C41mzDTudB2uc0Jc6vwrhQGvwq3JTxsF","success": true
}
需要在付款标头中将签名添加为签名:MDgzN2ZkYjAzOTQ5NmQ5NDQyZjc5YTU3NjUwMDgxOGIxNTY3YWM2Mw == 令牌需要以Token:C41mzDTudB2uc0Jc6vwrhQGvwq3JTxsF的形式添加在Make Payment标头中
步骤3:-提出付款请求–
服务Api-https://apisandbox-api.zuora.com/rest/v1/payment-methods/credit-cards
标题参数– 主持人:apisandBox-api.zuora.com 签名:MDgzN2ZkYjAzOTQ5NmQ5NDQyZjc5YTU3NjUwMDgxOGIxNTY3YWM2Mw == 令牌:C41mzDTudB2uc0Jc6vwrhQGvwq3JTxsF 内容类型:application / json 来源:www.test.gov.uk 缓存控制:无缓存
Request Parameters – {
"defaultPaymentMethod": true,
“ cardHolderInfo”: {“ addressLine1”:“ 77 Fallon Glen”, “ addressLine2”:“”, “ zipCode”:“ 94020”, “州”:“加利福尼亚”, “ phone”:“ 4155551234”, “国家”:“美国”, “ cardHolderName”:“ Bill Thiebault”, “ city”:“ Fremont”, “ email”:“ bill@testaddress.com”}, “ expirationMonth”:“ 10”, “ accountKey”:“ A00000485”, “ creditCardType”:“签证”, “ expirationYear”:“ 2021”, “ creditCardNumber”:“ 4012888888881121”, “ securityCode”:“ 123” }
Response Body – {
"success": true,"**paymentMethodId": "2c92c0fb73ad855c0173b8c3316b36a1"**
}
当我使用邮递员执行相同的步骤时,我将获得成功的答复。并且付款方式ID也正在生成。使用Java客户端,前两个服务正在执行。但是,当我点击“付款方式” /“信用卡”的请求时,就会出现问题, 它总是返回- { “成功”:错误, “ processId”:“ 84AD9CF25EC6623A”, “原因”:[{ “代码”:90000011, “ message”:“此资源受保护,请先登录” }] }
如果我在这里错过任何事情,请建议我。
解决方法
我错过了设置标头值的操作。我在这里发布我使用的方法- 它由Oauth令牌生成->生成hmac签名->提出付款方法/信用卡请求。它对我有用。
public void testSpringZuorPaymentCreditCardDifferent() {
HTTPHelper httpHelper = null;
String urlOAuthToken = "https://rest.apisandbox.zuora.com/oauth/token";
String resp = null;
try {
String userNameAndPassword ="c59b646b-53c6-45fb-b9c3-d3ea0978033d" + ":" +"6VLNxA=Fbaorb7yqXO3YRaiS2a+WUfLtwOiVugLqQ";
String authorizationHeaderValue = "Basic " + new String(Base64.encode(userNameAndPassword.getBytes()));
httpHelper = new HTTPHelper(new URL(urlOAuthToken));
Map<String,String> hdmp = new HashMap<String,String>();
hdmp.put("Authorization",authorizationHeaderValue);
hdmp.put("Content-Type","application/x-www-form-urlencoded");
httpHelper.setHeaders(hdmp);
String req = "grant_type=client_credentials";
System.out.println("REQUEST: " + req);
resp = httpHelper.post(req,60000,60000);
System.out.println("OAuth token response : " + resp);
}catch(Exception e) {
e.printStackTrace();
}
String[] arrOfStr = resp.split("\\W+");
System.out.println("Bearer token---------" + arrOfStr[2]);
String urlHmacSignatureUrl = "https://rest.apisandbox.zuora.com/v1/hmac-signatures";
try {
httpHelper = new HTTPHelper(new URL(urlHmacSignatureUrl));
Map<String,"Bearer " + new String(Base64.encode(arrOfStr[2].getBytes())));
hdmp.put("Content-Type","application/json");
hdmp.put("cache-control","no-cache");
httpHelper.setHeaders(hdmp);
String req = "{\n \"accountKey\": \"A00000194\",\n \"method\": \"POST\",\n \"uri\": \"https://rest.apisandbox.zuora.com/v1/payment-methods/credit-cards\"\n}";
System.out.println("REQUEST: " + req);
resp = httpHelper.post(req,60000);
System.out.println("Hmac Signature response : " + resp);
}catch(Exception e) {
e.printStackTrace();
}
arrOfStr = resp.split("\\W+");
System.out.println("signature : - "+arrOfStr[2]);
System.out.println("token : - "+arrOfStr[4]);
String serverURI = "https://apisandbox-api.zuora.com/rest/v1/payment-methods/credit-cards";
try {
java.util.Map<String,String> headers = new java.util.HashMap<String,String>();
httpHelper = new HTTPHelper(new URL(serverURI));
headers.put("Content-Type","application/json");
// headers.put("Signature",arrOfStr[2]+"==");
headers.put("Signature",new String(Base64.encode("YjM4MDY5MDliZmVkYmZiOGFkNmQ1YzFhYzFmNzMyOGI3NjExM2JlNQ==".getBytes())));
headers.put("Token",new String(Base64.encode(arrOfStr[4].getBytes())));
httpHelper.setHeaders(headers);
String req = "{\r\n" +
" \"defaultPaymentMethod\":true,\r\n" +
" \"cardHolderInfo\":{\r\n" +
" \"addressLine1\":\"77 Fallon Glen\",\r\n" +
" \"addressLine2\":\"\",\r\n" +
" \"zipCode\":\"94020\",\r\n" +
" \"state\":\"California\",\r\n" +
" \"phone\":\"4155551234\",\r\n" +
" \"country\":\"USA\",\r\n" +
" \"cardHolderName\":\"Bill Thiebault\",\r\n" +
" \"city\":\"Fremont\",\r\n" +
" \"email\":\"bill@testaddress.com\"\r\n" +
" },\r\n" +
" \"expirationMonth\":\"10\",\r\n" +
" \"accountKey\":\"A00000485\",\r\n" +
" \"creditCardType\":\"Visa\",\r\n" +
" \"expirationYear\":\"2021\",\r\n" +
" \"creditCardNumber\":\"4012888888881121\",\r\n" +
" \"securityCode\":\"123\"\r\n" +
"}";
System.out.println("Req: " + req);
resp = httpHelper.post(req,60000);
System.out.println("Payment Method - Credit Cards: " + resp);
}catch(Exception e) {
e.printStackTrace();
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。