Skip to content

Commit c89463a

Browse files
authored
Merge pull request #80 from paypay/PP-58998
PP-58998 - Updated pending payment refund api
2 parents aebc5cd + d191c9c commit c89463a

3 files changed

Lines changed: 13 additions & 50 deletions

File tree

src/main/java/jp/ne/paypay/api/PendingPaymentApi.java

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -151,53 +151,7 @@ private Call cancelPendingOrderValidateBeforeCall(String merchantPaymentId) thro
151151
*/
152152
public RefundDetails refundPayment(Refund refund) throws ApiException {
153153
ApiUtil.validateObject(validator, refund);
154-
ApiResponse<RefundDetails> resp = refundPaymentWithHttpInfo(refund);
155-
return resp.getData();
156-
}
157-
158-
/**
159-
* Refund a payment
160-
*
161-
* @param refund Refund
162-
* @return ApiResponse&lt;PaymentDetails&gt;
163-
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
164-
*/
165-
protected ApiResponse<RefundDetails> refundPaymentWithHttpInfo(Refund refund) throws ApiException {
166-
Call call = refundPaymentCall(refund);
167-
Type localVarReturnType = new TypeToken<RefundDetails>() {
168-
}.getType();
169-
return apiClient.execute(call, localVarReturnType, ApiNameConstants.REFUND_REQUEST_ORDER);
170-
}
171-
172-
/**
173-
* Build call for refundPayment
174-
*
175-
* @param refund Refund
176-
* @return Call to execute
177-
* @throws ApiException If fail to serialize the request payment object
178-
*/
179-
private Call refundPaymentCall(Refund refund) throws ApiException {
180-
181-
String localVarPath = "/v1/requestOrder/refunds";
182-
List<Pair> localVarQueryParams = new ArrayList<>();
183-
List<Pair> localVarCollectionQueryParams = new ArrayList<>();
184-
Map<String, String> localVarHeaderParams = new HashMap<>();
185-
Map<String, Object> localVarFormParams = new HashMap<>();
186-
187-
final String[] localVarAccepts = {
188-
ApiConstants.APPLICATION_JSON
189-
};
190-
final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
191-
if (localVarAccept != null) localVarHeaderParams.put(ApiConstants.ACCEPT, localVarAccept);
192-
193-
final String[] localVarContentTypes = {
194-
195-
};
196-
final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
197-
localVarHeaderParams.put(ApiConstants.CONTENT_TYPE, localVarContentType);
198-
String[] localVarAuthNames = new String[]{ApiConstants.HMAC_AUTH};
199-
apiClient.setReadTimeout(30);
200-
return apiClient.buildCall(localVarPath, "POST", localVarQueryParams, localVarCollectionQueryParams, refund, localVarHeaderParams, localVarFormParams, localVarAuthNames);
154+
return paymentApi.refundPayment(refund);
201155
}
202156

203157
/**

src/test/java/jp/ne/paypay/api/ApiClientTest.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,11 @@ public void deserializeTest() throws ApiException {
190190
result = apiClient.deserialize(null, localVarReturnType);
191191
Assert.assertNull(result);
192192

193+
builder.header("content-disposition","filename=test.json");
194+
response=builder.build();
195+
result = apiClient.deserialize(response, localVarReturnType);
196+
Assert.assertNotNull(result);
197+
Assert.assertTrue(result.toString().endsWith(".json"));
193198
}
194199

195200
@Test
@@ -245,8 +250,12 @@ public void handleResponseTest() throws ApiException, IOException {
245250
builder.body(ResponseBody.create(MediaType.parse("application/json"), json.serialize(notDataResponse)));
246251
response = builder.build();
247252
responseParameters.setResponse(response).setReturnType(localVarReturnType).setApiName("v2_createPayment");
248-
Assert.assertThrows(ApiException.class, ()->apiClient.handleResponse(responseParameters));
249-
253+
try{
254+
apiClient.handleResponse(responseParameters);
255+
}catch(ApiException e){
256+
Assert.assertEquals(e.getResolveUrl(),"https://developer.paypay.ne.jp/develop/resolve?api_name=v2_createPayment&code=UNAUTHORIZED&code_id=802001");
257+
Assert.assertTrue(e.getResponseBody().contains("UNAUTHORIZED"));
258+
}
250259
}
251260

252261
@Test

src/test/java/jp/ne/paypay/api/PendingPaymentApiTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public void refundPaymentTest() throws ApiException {
160160
refund.setStatus(RefundState.StatusEnum.CREATED);
161161
refundDetails.setData(refund);
162162
ApiResponse<RefundDetails> paymentDetailsApiResponse = new ApiResponse<>(00001, null, refundDetails);
163-
Mockito.when(api.refundPaymentWithHttpInfo(refund)).thenReturn(paymentDetailsApiResponse);
163+
Mockito.when(paymentApi.refundPaymentWithHttpInfo(refund)).thenReturn(paymentDetailsApiResponse);
164164
Assert.assertNotNull(refund.toString());
165165
RefundDetails response = api.refundPayment(refund);
166166
Assert.assertNotNull(response.toString());

0 commit comments

Comments
 (0)