Search in sources :

Example 1 with QRCodeDetails

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

the class PaymentApiTest method createQRCodeTest.

/**
 * Create a Code
 *
 * Create a Code to receive payments.  **Timeout: 30s**
 *
 * @throws ApiException if the Api call fails
 */
@Test
public void createQRCodeTest() throws ApiException {
    QRCode qrCode = new QRCode();
    qrCode.setAmount(new MoneyAmount().amount(10).currency(MoneyAmount.CurrencyEnum.JPY));
    qrCode.setMerchantPaymentId(UUID.randomUUID().toString());
    qrCode.setCodeType("ORDER_QR");
    qrCode.setStoreId(RandomStringUtils.randomAlphabetic(8));
    qrCode.setStoreInfo("Just Bake");
    qrCode.setTerminalId(RandomStringUtils.randomAlphanumeric(8));
    qrCode.requestedAt(Instant.now().getEpochSecond());
    qrCode.redirectUrl("https://www.justbake.in/payment");
    // For Deep Link, RedirectTypeEnum.APP_DEEP_LINK
    qrCode.redirectType(QRCode.RedirectTypeEnum.WEB_LINK);
    qrCode.setOrderDescription("Payment for Order ID:" + UUID.randomUUID().toString());
    MerchantOrderItem merchantOrderItem = new MerchantOrderItem().category("Dessert").name("Red Velvet Cake").productId(RandomStringUtils.randomAlphanumeric(8)).quantity(1).unitPrice(new MoneyAmount().amount(10).currency(MoneyAmount.CurrencyEnum.JPY));
    List<MerchantOrderItem> merchantOrderItems = new ArrayList<>();
    merchantOrderItems.add(merchantOrderItem);
    qrCode.setOrderItems(merchantOrderItems);
    String storeInfo = "Just Bake";
    String codeType = "ORDER_QR";
    String redirectUrl = "https://www.justbake.in/payment";
    QRCodeDetails qrCodeDetails = new QRCodeDetails();
    qrCodeDetails.setResultInfo(resultInfo);
    QRCodeResponse qrCodeResponse = new QRCodeResponse();
    qrCodeResponse.amount(new MoneyAmount().amount(10).currency(MoneyAmount.CurrencyEnum.JPY));
    qrCodeResponse.setMerchantPaymentId(UUID.randomUUID().toString());
    qrCodeResponse.setCodeType(codeType);
    qrCodeResponse.setStoreId(RandomStringUtils.randomAlphabetic(8));
    qrCodeResponse.setStoreInfo(storeInfo);
    qrCodeResponse.setTerminalId(RandomStringUtils.randomAlphanumeric(8));
    qrCodeResponse.requestedAt(Instant.now().getEpochSecond());
    qrCodeResponse.redirectUrl(redirectUrl);
    // For Deep Link, RedirectTypeEnum.APP_DEEP_LINK
    qrCodeResponse.redirectType(QRCodeResponse.RedirectTypeEnum.WEB_LINK);
    qrCodeResponse.setOrderDescription("Payment for Order ID:" + UUID.randomUUID().toString());
    MerchantOrderItemResponse merchantOrderItemResponse = new MerchantOrderItemResponse().category("Dessert").name("Red Velvet Cake").productId(RandomStringUtils.randomAlphanumeric(8)).quantity(1).unitPrice(new MoneyAmount().amount(10).currency(MoneyAmount.CurrencyEnum.JPY));
    List<MerchantOrderItemResponse> merchantOrderItemsList = new ArrayList<>();
    merchantOrderItemsList.add(merchantOrderItemResponse);
    qrCodeResponse.setOrderItems(merchantOrderItemsList);
    qrCodeDetails.setData(qrCodeResponse);
    ApiResponse<QRCodeDetails> qrCodeDetailsApiResponse = new ApiResponse<>(00001, null, qrCodeDetails);
    Mockito.when(api.createQRCodeWithHttpInfo(qrCode)).thenReturn(qrCodeDetailsApiResponse);
    QRCodeDetails response = api.createQRCode(qrCode);
    Assert.assertNotNull(response.toString());
    Assert.assertEquals(response.getResultInfo().getMessage(), "SUCCESS");
    Assert.assertEquals(response.getData().getStoreInfo(), storeInfo);
    Assert.assertEquals(response.getData().getCodeType(), codeType);
    Assert.assertEquals(response.getData().getRedirectUrl(), redirectUrl);
    Assert.assertEquals(response.getData().getRedirectType(), QRCodeResponse.RedirectTypeEnum.WEB_LINK);
    Assert.assertNotNull(response.getData());
    Assert.assertNotNull(response.getData().getMerchantPaymentId());
    Assert.assertNotNull(response.getData().getOrderItems());
    Assert.assertNotNull(response.getData().getRequestedAt());
    Assert.assertNotNull(response.getData().getTerminalId());
    Assert.assertNotNull(response.getData().getOrderDescription());
}
Also used : LinkQRCodeResponse(jp.ne.paypay.model.LinkQRCodeResponse) QRCodeResponse(jp.ne.paypay.model.QRCodeResponse) QRCode(jp.ne.paypay.model.QRCode) AccountLinkQRCode(jp.ne.paypay.model.AccountLinkQRCode) MerchantOrderItem(jp.ne.paypay.model.MerchantOrderItem) MerchantOrderItemResponse(jp.ne.paypay.model.MerchantOrderItemResponse) QRCodeDetails(jp.ne.paypay.model.QRCodeDetails) ArrayList(java.util.ArrayList) MoneyAmount(jp.ne.paypay.model.MoneyAmount) ApiResponse(jp.ne.paypay.ApiResponse) Test(org.junit.jupiter.api.Test)

Example 2 with QRCodeDetails

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

the class PaymentApi method createQRCodeWithHttpInfo.

/**
 * Create a Code
 * Create a Code to receive payments.  **Timeout: 30s**
 *
 * @param body Code Creation (optional)
 * @return ApiResponse&lt;QRCodeDetails&gt;
 * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
 */
protected ApiResponse<QRCodeDetails> createQRCodeWithHttpInfo(Object body) throws ApiException {
    Call call = createQRCodeValidateBeforeCall(body);
    Type localVarReturnType = new TypeToken<QRCodeDetails>() {
    }.getType();
    return apiClient.execute(call, localVarReturnType, ApiNameConstants.CREATE_QRCODE);
}
Also used : Call(com.squareup.okhttp.Call) Type(java.lang.reflect.Type) QRCodeDetails(jp.ne.paypay.model.QRCodeDetails)

Example 3 with QRCodeDetails

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

the class ApiClientTest method deserializeTest.

@Test
public void deserializeTest() throws ApiException {
    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();
    Object result = apiClient.deserialize(response, localVarReturnType);
    Assert.assertTrue(result instanceof QRCodeDetails);
    localVarReturnType = new TypeToken<File>() {
    }.getType();
    result = apiClient.deserialize(response, localVarReturnType);
    Assert.assertTrue(result instanceof File);
    json.setLenientOnJson(true);
    builder.body(ResponseBody.create(MediaType.parse("application/json"), json.serialize(qrCodeDetails)));
    response = builder.build();
    result = apiClient.deserialize(response, localVarReturnType);
    Assert.assertTrue(result instanceof File);
    result = apiClient.deserialize(null, localVarReturnType);
    Assert.assertNull(result);
    builder.header("content-disposition", "filename=test.json");
    response = builder.build();
    result = apiClient.deserialize(response, localVarReturnType);
    Assert.assertNotNull(result);
    Assert.assertTrue(result.toString().endsWith(".json"));
}
Also used : QRCodeDetails(jp.ne.paypay.model.QRCodeDetails) 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) File(java.io.File) RequestBody(com.squareup.okhttp.RequestBody) Test(org.junit.jupiter.api.Test)

Example 4 with QRCodeDetails

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

the class PaymentApiExample method createQRCode.

private static QRCodeDetails createQRCode(final PaymentApi apiInstance, int amount) {
    QRCodeDetails result = null;
    try {
        QRCode qrCode = new QRCode();
        qrCode.setAmount(new MoneyAmount().amount(amount).currency(MoneyAmount.CurrencyEnum.JPY));
        qrCode.setMerchantPaymentId(UUID.randomUUID().toString());
        qrCode.setCodeType("ORDER_QR");
        qrCode.setStoreId(RandomStringUtils.randomAlphabetic(8));
        qrCode.setStoreInfo("Just Bake");
        qrCode.setTerminalId(RandomStringUtils.randomAlphanumeric(8));
        qrCode.setRedirectUrl("https://paypay.ne.jp/");
        // For Deep Link, RedirectTypeEnum.APP_DEEP_LINK
        qrCode.setRedirectType(QRCode.RedirectTypeEnum.WEB_LINK);
        qrCode.setOrderDescription("Payment for Order ID:" + UUID.randomUUID().toString());
        result = apiInstance.createQRCode(qrCode);
        System.out.println("\nAPI RESPONSE\n------------------\n");
        System.out.println(result);
    } catch (ApiException e) {
        System.out.println(e.getResponseHeaders().toString());
        System.err.println(e.getResponseBody());
    }
    return result;
}
Also used : QRCode(jp.ne.paypay.model.QRCode) AccountLinkQRCode(jp.ne.paypay.model.AccountLinkQRCode) QRCodeDetails(jp.ne.paypay.model.QRCodeDetails) MoneyAmount(jp.ne.paypay.model.MoneyAmount) ApiException(jp.ne.paypay.ApiException)

Example 5 with QRCodeDetails

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

the class PaymentApiExample method appInvokeFlow.

private static void appInvokeFlow(final PaymentApi paymentApi, final WalletApi walletApiInstance, final String userAuthorizationId) {
    int amount = 1;
    QRCodeDetails qrCodeDetails = createQRCode(paymentApi, amount);
    String merchantPaymentId = qrCodeDetails != null ? qrCodeDetails.getData().getMerchantPaymentId() : null;
    WalletBalance walletBalance = getWalletBalance(walletApiInstance, userAuthorizationId);
    if (merchantPaymentId != null && walletBalance != null && walletBalance.getData().isHasEnoughBalance()) {
        System.out.println("The QR Code can be used as a deeplink to invoke PayPay app and receive Payments. The user " + "can makes the payment using PayPay App");
        System.out.println("For this example, we will create payment using the API...");
        Payment payment = getPaymentObject(merchantPaymentId, userAuthorizationId, amount);
        PaymentDetails paymentDetails = createPayment(paymentApi, payment, false);
        if (paymentDetails != null) {
            System.out.println("Payment created successfully, Now calling the API to get payment details for payment " + "ID:" + merchantPaymentId);
            String refundId = UUID.randomUUID().toString();
            paymentDetails = getPaymentDetails(paymentApi, merchantPaymentId);
            if (paymentDetails != null) {
                System.out.println("Creating Refund for the payment:" + paymentDetails.getData().getPaymentId());
                createRefund(paymentApi, paymentDetails.getData().getPaymentId(), refundId);
                System.out.println("Get refund details:" + refundId);
                getRefundDetails(paymentApi, refundId);
                System.out.println("Finally cancel the payment");
                cancelPayment(paymentApi, merchantPaymentId);
            }
        }
    }
    if (qrCodeDetails != null) {
        System.out.println("Delete the QR Code: " + qrCodeDetails.getData().getCodeId());
        deleteQrCode(paymentApi, qrCodeDetails.getData().getCodeId());
    }
}
Also used : Payment(jp.ne.paypay.model.Payment) WalletBalance(jp.ne.paypay.model.WalletBalance) QRCodeDetails(jp.ne.paypay.model.QRCodeDetails) PaymentDetails(jp.ne.paypay.model.PaymentDetails)

Aggregations

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