Search in sources :

Example 11 with NotDataResponse

use of jp.ne.paypay.model.NotDataResponse in project paypayopa-sdk-java by paypay.

the class PaymentApiExample method deleteQrCode.

private static void deleteQrCode(final PaymentApi apiInstance, final String qrCode) {
    try {
        NotDataResponse result = apiInstance.deleteQRCode(qrCode);
        System.out.println("\nAPI RESPONSE\n------------------\n");
        System.out.println(result);
    } catch (ApiException e) {
        System.err.println(e.getResponseBody());
    }
}
Also used : NotDataResponse(jp.ne.paypay.model.NotDataResponse) ApiException(jp.ne.paypay.ApiException)

Example 12 with NotDataResponse

use of jp.ne.paypay.model.NotDataResponse in project paypayopa-sdk-java by paypay.

the class PendingPaymentApi method cancelPendingOrderWithHttpInfo.

/**
 * Cancel a pending order
 * This api is used delete the pending order.  **Timeout: 15s**
 *
 * @param merchantPaymentId (required)
 * @return ApiResponse<NotDataResponse>
 * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
 */
protected ApiResponse<NotDataResponse> cancelPendingOrderWithHttpInfo(String merchantPaymentId) throws ApiException {
    Call call = cancelPendingOrderValidateBeforeCall(merchantPaymentId);
    Type localVarReturnType = new TypeToken<NotDataResponse>() {
    }.getType();
    return apiClient.execute(call, localVarReturnType, ApiNameConstants.CANCEL_REQUEST_ORDER);
}
Also used : Call(com.squareup.okhttp.Call) Type(java.lang.reflect.Type) NotDataResponse(jp.ne.paypay.model.NotDataResponse)

Example 13 with NotDataResponse

use of jp.ne.paypay.model.NotDataResponse in project paypayopa-sdk-java by paypay.

the class ApiClientTest method handleResponseTest.

@Test
public void handleResponseTest() throws ApiException, IOException {
    Request.Builder requestBuild = new Request.Builder();
    requestBuild.url("http://paypay.ne.jp/v2/qrcode");
    requestBuild.header("content-type", "application/json");
    RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), "{\"merchantPaymentId\":'paymentId'}");
    requestBuild.post(requestBody);
    Request request = requestBuild.build();
    Response.Builder builder = new Response.Builder();
    builder.header("content-type", "application/json");
    builder.request(request);
    builder.code(200);
    builder.protocol(Protocol.HTTP_2);
    ResultInfo resultInfo = new ResultInfo();
    resultInfo.setMessage("SUCCESS");
    QRCodeDetails qrCodeDetails = new QRCodeDetails();
    qrCodeDetails.setResultInfo(resultInfo);
    JSON json = new JSON();
    builder.body(ResponseBody.create(MediaType.parse("application/json"), json.serialize(qrCodeDetails)));
    Response response = builder.build();
    Type localVarReturnType = new TypeToken<QRCodeDetails>() {
    }.getType();
    ResponseParameters responseParameters = new ResponseParameters().setResponse(response).setReturnType(localVarReturnType).setApiName("v2_createPayment");
    Object result = apiClient.handleResponse(responseParameters);
    Assert.assertTrue(result instanceof QRCodeDetails);
    responseParameters.setReturnType(null).setApiName(null);
    result = apiClient.handleResponse(new ResponseParameters().setResponse(response));
    Assert.assertFalse(result instanceof QRCodeDetails);
    localVarReturnType = new TypeToken<File>() {
    }.getType();
    result = apiClient.handleResponse(responseParameters.setReturnType(localVarReturnType));
    Assert.assertTrue(result instanceof File);
    Mockito.when(call.execute()).thenReturn(response);
    ApiResponse<Object> apiResponse = apiClient.execute(call, localVarReturnType, null);
    Assert.assertEquals(200, apiResponse.getStatusCode());
    Mockito.when(call.execute()).thenThrow(IOException.class);
    Assert.assertThrows(ApiException.class, () -> apiClient.execute(call, new TypeToken<File>() {
    }.getType(), ""));
    resultInfo = new ResultInfo();
    resultInfo.setMessage("You are not authorized");
    resultInfo.setCode("UNAUTHORIZED");
    resultInfo.setCodeId("802001");
    NotDataResponse notDataResponse = new NotDataResponse();
    notDataResponse.setResultInfo(resultInfo);
    builder.code(401);
    builder.body(ResponseBody.create(MediaType.parse("application/json"), json.serialize(notDataResponse)));
    response = builder.build();
    responseParameters.setResponse(response).setReturnType(localVarReturnType).setApiName("v2_createPayment");
    try {
        apiClient.handleResponse(responseParameters);
    } catch (ApiException e) {
        Assert.assertEquals(e.getResolveUrl(), "https://developer.paypay.ne.jp/develop/resolve?api_name=v2_createPayment&code=UNAUTHORIZED&code_id=802001");
        Assert.assertTrue(e.getResponseBody().contains("UNAUTHORIZED"));
    }
}
Also used : QRCodeDetails(jp.ne.paypay.model.QRCodeDetails) ResponseParameters(jp.ne.paypay.model.ResponseParameters) Request(com.squareup.okhttp.Request) JSON(jp.ne.paypay.JSON) Response(com.squareup.okhttp.Response) NotDataResponse(jp.ne.paypay.model.NotDataResponse) ApiResponse(jp.ne.paypay.ApiResponse) MediaType(com.squareup.okhttp.MediaType) Type(java.lang.reflect.Type) TypeToken(com.google.gson.reflect.TypeToken) ResultInfo(jp.ne.paypay.model.ResultInfo) NotDataResponse(jp.ne.paypay.model.NotDataResponse) File(java.io.File) RequestBody(com.squareup.okhttp.RequestBody) ApiException(jp.ne.paypay.ApiException) Test(org.junit.jupiter.api.Test)

Aggregations

NotDataResponse (jp.ne.paypay.model.NotDataResponse)13 Type (java.lang.reflect.Type)5 ApiResponse (jp.ne.paypay.ApiResponse)5 Test (org.junit.jupiter.api.Test)5 Call (com.squareup.okhttp.Call)4 ApiException (jp.ne.paypay.ApiException)4 TypeToken (com.google.gson.reflect.TypeToken)2 MediaType (com.squareup.okhttp.MediaType)1 Request (com.squareup.okhttp.Request)1 RequestBody (com.squareup.okhttp.RequestBody)1 Response (com.squareup.okhttp.Response)1 File (java.io.File)1 JSON (jp.ne.paypay.JSON)1 QRCodeDetails (jp.ne.paypay.model.QRCodeDetails)1 ResponseParameters (jp.ne.paypay.model.ResponseParameters)1 ResultInfo (jp.ne.paypay.model.ResultInfo)1 UserAuthorizationStatus (jp.ne.paypay.model.UserAuthorizationStatus)1