0

我正在将 zuora apis 与我的应用程序集成。这些是我通过以下步骤使用的以下 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": "bearer", "expires_in": 3598, "scope": "entity.a083d63b-b3f5-8626-f793-695cec903.ca 平台写 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 用户.2c92c094738e5b090173902066c201ba”,“jti”:“41947f41d664437a98a9da38a293c89d”}

使用 auth token 响应中的 access_token 或 jti 值,并将其作为 Authorization: Bearer 传递给 headers 参数

第 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
                                    }

签名需要在付款标头中添加 asSignature:MDgzN2ZkYjAzOTQ5NmQ5NDQyZjc5YTU3NjUwMDgxOGIxNTY3YWM2Mw== 令牌需要在付款标头中添加为 Token:C41mzDTudB2uc0Jc6vwrhQGvwq3JTxsF

第 3 步:- 提出付款请求 -</p>

服务 API - https://apisandbox-api.zuora.com/rest/v1/payment-methods/credit-cards

标头参数 – 主机:apisandbox-api.zuora.com 签名:MDgzN2ZkYjAzOTQ5NmQ5NDQyZjc5YTU3NjUwMDgxOGIxNTY3YWM2Mw== 令牌:C41mzDTudB2uc0Jc6vwrhQGvwq3JTxsF 内容类型:application/json 来源:www.test.gov.uk 缓存控制:no-cache

            Request Parameters – {
                    "defaultPaymentMethod": true,

“cardHolderInfo”:{“addressLine1”:“77 Fallon Glen”,“addressLine2”:“”,“邮政编码”:“94020”,“州”:“加利福尼亚”,“电话”:“4155551234”,“国家”: “USA”、“cardHolderName”:“Bill Thiebault”、“city”:“Fremont”、“email”:“bill@testaddress.com”}、“expirationMonth”:“10”、“accountKey”:“A00000485”、 “creditCardType”:“Visa”,“expirationYear”:“2021”,“creditCardNumber”:“4012888888881121”,“securityCode”:“123”}

        Response Body – {
                     "success": true,
"**paymentMethodId": "2c92c0fb73ad855c0173b8c3316b36a1"**

}

当我使用邮递员使用相同的步骤时,我能够获得成功响应。并且付款方式 ID 也正在生成。使用 java 客户端正在执行前两个服务。但是当我点击支付方式/信用卡请求时出现问题,它总是返回 - {“success”:false,“processId”:“84AD9CF25EC6623A”,“reasons”:[{“code”:90000011,“message " : "此资源受保护,请先登录" } ] }

如果我在这里遗漏了什么,请建议我。

4

1 回答 1

0

我错过了设置标题值。在这里,我发布了我使用的方法 - 它包括 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, String> hdmp = new HashMap<String, String>();
                
            hdmp.put("Authorization", "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, 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, 60000);
            System.out.println("Payment Method - Credit Cards: " + resp);
            
        }catch(Exception e) {
            e.printStackTrace();
        }
    }
于 2020-08-28T16:55:45.077 回答