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());
}
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<QRCodeDetails>
* @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);
}
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"));
}
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;
}
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());
}
}
Aggregations