diff --git a/src/main/java/jp/ne/paypay/auth/HmacAuth.java b/src/main/java/jp/ne/paypay/auth/HmacAuth.java index b7541de..81a8060 100644 --- a/src/main/java/jp/ne/paypay/auth/HmacAuth.java +++ b/src/main/java/jp/ne/paypay/auth/HmacAuth.java @@ -69,20 +69,10 @@ private byte[] getHmacData(String nonce, long epoch, String hash){ localContentType = this.contentType; } String DELIMITER = "\n"; - return (formatRequestUrl(this.requestUrl) + DELIMITER + this.httpMethod + DELIMITER + nonce + DELIMITER + epoch + DELIMITER + return (this.requestUrl + DELIMITER + this.httpMethod + DELIMITER + nonce + DELIMITER + epoch + DELIMITER + localContentType + DELIMITER + hash) .getBytes(StandardCharsets.UTF_8); } - private String formatRequestUrl(String requestUrl){ - try{ - if(requestUrl.contains("?")){ - requestUrl = requestUrl.substring(0, requestUrl.indexOf("?")); - } - }catch (Exception e){ - System.out.println("Exception while formatting request url for HMAC Auth"); - } - return requestUrl; - } @Override public void applyToParams(List queryParams, Map headerParams) { if (apiKey == null || apiSecretKey == null) { @@ -94,6 +84,7 @@ public void applyToParams(List queryParams, Map headerPara }catch (Exception e){ System.err.println("Error in getting Authorization: "+e); } + } public String getApiKey() { diff --git a/src/main/java/jp/ne/paypay/example/UserApiExample.java b/src/main/java/jp/ne/paypay/example/UserApiExample.java deleted file mode 100644 index 417cb58..0000000 --- a/src/main/java/jp/ne/paypay/example/UserApiExample.java +++ /dev/null @@ -1,47 +0,0 @@ -package jp.ne.paypay.example; - -import jp.ne.paypay.ApiClient; -import jp.ne.paypay.ApiException; -import jp.ne.paypay.Configuration; -import jp.ne.paypay.api.UserApi; -import jp.ne.paypay.model.NotDataResponse; -import jp.ne.paypay.model.UserAuthorizationStatus; - -public class UserApiExample { - - - public static void main(String[] args) throws ApiException { - ApiClient apiClient = new Configuration().getDefaultApiClient(); - apiClient.setProductionMode(false); - apiClient.setApiKey("API_KEY"); - apiClient.setApiSecretKey("API_SECRET_KEY"); - apiClient.setAssumeMerchant("ASSUME_MERCHANT_ID"); - String userAuthorizationId = "USER_AUTHORIZATION_ID"; - - UserApi userApi = new UserApi(apiClient); - - getUserAuthorizationStatus(userAuthorizationId, userApi); - //Replace the "userAuthorizationId" with the actual one. Please note that this will Unlink the user from the client - unlinkUser("userAuthorizationId", userApi); - } - - private static void getUserAuthorizationStatus(String userAuthorizationId, UserApi userApi) { - try{ - UserAuthorizationStatus userAuthorizationStatus = userApi.getUserAuthorizationStatus(userAuthorizationId); - System.out.println(userAuthorizationStatus); - }catch (ApiException e){ - System.out.println(e.getResponseBody()); - System.out.println(e.getResponseHeaders()); - } - } - private static void unlinkUser(String userAuthorizationId, UserApi userApi) { - try{ - NotDataResponse notDataResponse = userApi.unlinkUser(userAuthorizationId); - System.out.println(notDataResponse); - }catch (ApiException e){ - System.out.println(e.getResponseBody()); - System.out.println(e.getResponseHeaders()); - } - } -} - diff --git a/src/test/java/jp/ne/paypay/api/HmacAuthTest.java b/src/test/java/jp/ne/paypay/api/HmacAuthTest.java index 430e06d..2efde7b 100644 --- a/src/test/java/jp/ne/paypay/api/HmacAuthTest.java +++ b/src/test/java/jp/ne/paypay/api/HmacAuthTest.java @@ -35,12 +35,10 @@ public void hmacAuthTest(){ Assert.assertNotNull(hmacAuth.getHttpMethod()); Assert.assertNotNull(hmacAuth.getRequestBody()); Assert.assertNotNull(hmacAuth.getRequestUrl()); - hmacAuth.setRequestUrl("/v2/api/test?param=p1"); - hmacAuth.applyToParams(queryParams, headerParams); - Assert.assertTrue(headerParams.get("Authorization").startsWith("hmac")); hmacAuth.setContentType(null); headerParams = new HashMap<>(); hmacAuth.applyToParams(queryParams, headerParams); Assert.assertNull(headerParams.get("Authorization")); + } }