Skip to content

Commit

Permalink
Continuous payment integration
Browse files Browse the repository at this point in the history
  • Loading branch information
javidlulu committed Aug 26, 2020
1 parent 2962d40 commit 820b94c
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 131 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -64,6 +64,7 @@ Class | Method | HTTP request | Description
*PaymentApi* | [**cancelPayment**](docs/PaymentApi.md#cancelPayment) | **DELETE** /v2/payments/{merchantPaymentId} | Cancel a payment
*PaymentApi* | [**createPayment**](docs/PaymentApi.md#createPayment) | **POST** /v2/payments | Create a payment
*PaymentApi* | [**createPaymentAuthorization**](docs/PaymentApi.md#createPaymentAuthorization) | **POST** /v2/payments/preauthorize | Create a payment authorization to block the money
*PaymentApi* | [**createContinuousPayment**](docs/PaymentApi.md#createContinuousPayment) | **POST** /v1/subscription/payments | Create a continuous payment and start the money transfer
*PaymentApi* | [**revertAuth**](docs/PaymentApi.md#revertAuth) | **POST** /v2/payments/preauthorize/revert | Revert a payment authorization
*PaymentApi* | [**capturePaymentAuth**](docs/PaymentApi.md#capturePaymentAuth) | **POST** /v2/payments/capture | Capture a payment authorization
*PaymentApi* | [**createQRCode**](docs/PaymentApi.md#createQRCode) | **POST** /v2/codes | Create a Code
Expand Down
49 changes: 49 additions & 0 deletions docs/PaymentApi.md
Expand Up @@ -6,6 +6,7 @@ Method | HTTP request | Description
[**cancelPayment**](PaymentApi.md#cancelPayment) | **DELETE** /v2/payments/{merchantPaymentId} | Cancel a payment
[**createPayment**](PaymentApi.md#createPayment) | **POST** /v2/payments | Create a payment
[**createPaymentAuthorization**](PaymentApi.md#createPaymentAuthorization) | **POST** /v2/payments/preauthorize | Create a payment authorization to block the money
[**createContinuousPayment**](docs/PaymentApi.md#createContinuousPayment) | **POST** /v1/subscription/payments | Create a continuous payment and start the money transfer
[**revertAuth**](PaymentApi.md#revertAuth) | **POST** /v2/payments/preauthorize/revert | Revert a payment authorization
[**capturePaymentAuth**](PaymentApi.md#capturePaymentAuth) | **POST** /v2/payments/capture | Capture a payment authorization
[**createQRCode**](PaymentApi.md#createQRCode) | **POST** /v2/codes | Create a Code
Expand Down Expand Up @@ -197,6 +198,54 @@ Please refer to the below document for more information :
https://www.paypay.ne.jp/opa/doc/v1.0/preauth_capture#operation/createAuth
```

<a name="createContinuousPayment"></a>
# **createContinuousPayment**
> PaymentDetails createContinuousPayment(body)
Create a continuous payment
Create a continuous payment and start the money transfer. **Timeout: 30s**

### Example
```java
//Import classes:
import jp.ne.paypay.ApiException;
import jp.ne.paypay.api.PaymentApi;


PaymentApi apiInstance = new PaymentApi(apiClient);

Payment payment = new Payment();
payment.setAmount(new MoneyAmount().amount(1).currency(MoneyAmount.CurrencyEnum.JPY));
payment.setMerchantPaymentId("MERCHANT_PAYMENT_ID");
payment.setUserAuthorizationId("USER_AUTHORIZATION_ID");// User should be with scope continuous_payments
payment.setRequestedAt(Instant.now().getEpochSecond());
payment.setStoreId("STORE_ID");
payment.setTerminalId("TERMINAL_ID");
payment.setOrderReceiptNumber("ORDER_RECEIPT_NUMBER");
payment.setOrderDescription("ORDER_DESCRIPTION");
MerchantOrderItem merchantOrderItem =
new MerchantOrderItem()
.category("pasteries").name("Moon Cake")
.productId("PRODUCT_ID").quantity(1)
.unitPrice(new MoneyAmount().amount(10).currency(MoneyAmount.CurrencyEnum.JPY));
List<MerchantOrderItem> merchantOrderItems = new ArrayList<>();
merchantOrderItems.add(merchantOrderItem);
payment.setOrderItems(new ArrayList<MerchantOrderItem>(merchantOrderItems));

try {
PaymentDetails result = apiInstance.createContinuousPayment(body);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling PaymentApi#createContinuousPayment");
System.out.println(e.getResponseBody());
}
```

```
Please refer to the below document for more information :
https://www.paypay.ne.jp/opa/doc/v1.0/continuous_payments#operation/createPayment
```

<a name="revertAuth"></a>
# **revertAuth**
> PaymentDetails revertAuth(body, agreeSimilarTransaction)
Expand Down
64 changes: 0 additions & 64 deletions src/main/java/jp/ne/paypay/ProgressRequestBody.java

This file was deleted.

63 changes: 0 additions & 63 deletions src/main/java/jp/ne/paypay/ProgressResponseBody.java

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/java/jp/ne/paypay/api/PaymentApi.java
Expand Up @@ -928,7 +928,7 @@ public PaymentDetails createContinuousPayment(Payment body) throws ApiException

/**
* Create a continuous payment
* Create a continuous payment and start the money transfer.. **Timeout: 30s**
* Create a continuous payment and start the money transfer. **Timeout: 30s**
*
* @param body Payment
* @return ApiResponse&lt;PaymentDetails&gt;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/jp/ne/paypay/example/PaymentApiExample.java
Expand Up @@ -371,8 +371,8 @@ private static QRCodeDetails createQRCode(final PaymentApi apiInstance, int amou
qrCode.setStoreInfo("Just Bake");
qrCode.setTerminalId(RandomStringUtils.randomAlphanumeric(8));
qrCode.setRequestedAt(Instant.now().getEpochSecond());
qrCode.redirectUrl("https://www.justbake.in/payment");
qrCode.redirectType(QRCode.RedirectTypeEnum.WEB_LINK);//For Deep Link, RedirectTypeEnum.APP_DEEP_LINK
qrCode.setRedirectUrl("https://paypay.ne.jp/");
qrCode.setRedirectType(QRCode.RedirectTypeEnum.WEB_LINK);//For Deep Link, RedirectTypeEnum.APP_DEEP_LINK
qrCode.setOrderDescription("Payment for Order ID:"+UUID.randomUUID().toString());
//qrCode.isAuthorization(true);
//Long expireAt = Instant.now().getEpochSecond()+5000;
Expand Down
94 changes: 93 additions & 1 deletion src/test/java/jp/ne/paypay/api/PaymentApiTest.java
Expand Up @@ -114,13 +114,16 @@ public void capturePaymentAuthTest() throws ApiException {
capture.setMerchantCaptureId(captureObject.getMerchantCaptureId());
capture.setOrderDescription(captureObject.getOrderDescription());
capture.setRequestedAt(captureObject.getRequestedAt());
capture.setAcceptedAt(Instant.now().getNano());
capture.setStatus(Capture.StatusEnum.COMPLETED);
Assertions.assertNotNull(capture.toString());
paymentStateCaptures.addDataItem(capture);
payment.setCaptures(paymentStateCaptures);
paymentDetails.setData(payment);
ApiResponse<PaymentDetails> paymentDetailsApiResponse = new ApiResponse<>(00001, null, paymentDetails);
Mockito.when(api.capturePaymentAuthWithHttpInfo(captureObject)).thenReturn(paymentDetailsApiResponse);
PaymentDetails response = api.capturePaymentAuth(captureObject);
Assertions.assertNotNull(response.toString());
Assertions.assertEquals(response.getResultInfo().getMessage(), "SUCCESS");
Assertions.assertNotNull(response.getData());
Assertions.assertEquals(response.getData().getMerchantPaymentId(), "merchantPaymentId");
Expand Down Expand Up @@ -216,6 +219,7 @@ public void createPaymentAuthorizationTest() throws ApiException {
ApiResponse<PaymentDetails> paymentDetailsApiResponse = new ApiResponse<>(00001, null, paymentDetails);
Mockito.when(api.createPaymentAuthorizationWithHttpInfo(payment, agreeSimilarTransaction)).thenReturn(paymentDetailsApiResponse);
PaymentDetails response = api.createPaymentAuthorization(payment, agreeSimilarTransaction);
Assertions.assertNotNull(response.toString());
Assertions.assertEquals(response.getResultInfo().getMessage(), "SUCCESS");
Assertions.assertEquals(response.getData().getMerchantPaymentId(), "merchantPaymentId");
Assertions.assertEquals(response.getData().getUserAuthorizationId(), "userAuthorizationId");
Expand Down Expand Up @@ -291,6 +295,7 @@ public void createQRCodeTest() throws ApiException {
ApiResponse<QRCodeDetails> qrCodeDetailsApiResponse = new ApiResponse<>(00001, null, qrCodeDetails);
Mockito.when(api.createQRCodeWithHttpInfo(qrCode)).thenReturn(qrCodeDetailsApiResponse);
QRCodeDetails response = api.createQRCode(qrCode);
Assertions.assertNotNull(response.toString());
Assertions.assertEquals(response.getResultInfo().getMessage(), "SUCCESS");
Assertions.assertEquals(response.getData().getStoreInfo(), storeInfo);
Assertions.assertEquals(response.getData().getCodeType(), codeType);
Expand Down Expand Up @@ -324,6 +329,7 @@ public void deleteQRCodeTest() throws ApiException {
Mockito.when(apiClient.escapeString(codeId)).thenReturn(codeId);
Mockito.when(api.deleteQRCodeWithHttpInfo(codeId)).thenReturn(notDataResponseApiResponse);
NotDataResponse response = api.deleteQRCode(codeId);
Assertions.assertNotNull(response.toString());
Assertions.assertEquals(response.getResultInfo().getMessage(), "SUCCESS");
}
/**
Expand Down Expand Up @@ -413,8 +419,9 @@ public void refundPaymentTest() throws ApiException {
refundDetails.setData(refund);
ApiResponse<RefundDetails> paymentDetailsApiResponse = new ApiResponse<>(00001, null, refundDetails);
Mockito.when(api.refundPaymentWithHttpInfo(refund)).thenReturn(paymentDetailsApiResponse);
Assertions.assertNotNull(refund.toString());
RefundDetails response = api.refundPayment(refund);

Assertions.assertNotNull(response.toString());
Assertions.assertEquals(response.getResultInfo().getMessage(), "SUCCESS");
}

Expand Down Expand Up @@ -444,6 +451,7 @@ public void revertAuthTest() throws ApiException {
revertAuthResponse.setData(revertAuthResponseData);
ApiResponse<RevertAuthResponse> revertAuthResponseApiResponse = new ApiResponse<>(00001, null, revertAuthResponse);
Mockito.when(api.revertAuthWithHttpInfo(paymentStateRevert)).thenReturn(revertAuthResponseApiResponse);
Assertions.assertNotNull(paymentStateRevert.toString());
RevertAuthResponse response = api.revertAuth(paymentStateRevert);
Assertions.assertNotNull(response.toString());
Assertions.assertEquals(response.getResultInfo().getMessage(), "SUCCESS");
Expand Down Expand Up @@ -480,8 +488,92 @@ public void createAccountLinkQRCodeTest() throws ApiException {
linkQRCodeResponse.setResultInfo(resultInfo);
ApiResponse<LinkQRCodeResponse> paymentDetailsApiResponse = new ApiResponse<>(8100001, null, linkQRCodeResponse);
Mockito.when(api.createAccountLinkQRCodeWithHttpInfo(accountLinkQRCode)).thenReturn(paymentDetailsApiResponse);
Assertions.assertNotNull(accountLinkQRCode.toString());
LinkQRCodeResponse response = api.createAccountLinkQRCode(accountLinkQRCode);
Assertions.assertNotNull(response.toString());
Assertions.assertEquals(response.getResultInfo().getMessage(), "SUCCESS");
}

/**
* Create an Account Link QRCode Failed response
* Create an ACCOUNT LINK QR and display it to the user. **Timeout: 10s**
*
* @throws ApiException
* if the Api call fails
*/
@Test
public void createAccountLinkQRCodeFailedTest() throws ApiException {

AccountLinkQRCode accountLinkQRCode = new AccountLinkQRCode();
List<AuthorizationScope> scopes = new ArrayList<>();
scopes.add(AuthorizationScope.DIRECT_DEBIT);
accountLinkQRCode.setScopes(scopes)
.setNonce(RandomStringUtils.randomAlphanumeric(8).toLowerCase())
.setDeviceId("device_id")
.setRedirectUrl("merchant.domain/test")
.setPhoneNumber("phone_number")
.setReferenceId("reference_id")
.setRedirectType(QRCode.RedirectTypeEnum.WEB_LINK);
Assertions.assertNotNull(accountLinkQRCode.toString());
LinkQRCodeResponse linkQRCodeResponse = new LinkQRCodeResponse();
resultInfo.setMessage("FAILED");
linkQRCodeResponse.setResultInfo(resultInfo);
ApiResponse<LinkQRCodeResponse> paymentDetailsApiResponse = new ApiResponse<>(8100001, null, linkQRCodeResponse);
Mockito.when(api.createAccountLinkQRCodeWithHttpInfo(accountLinkQRCode)).thenReturn(paymentDetailsApiResponse);
LinkQRCodeResponse response = api.createAccountLinkQRCode(accountLinkQRCode);

Assertions.assertEquals(response.getResultInfo().getMessage(), "FAILED");
}

/**
* Create continuous payment
*
* Create a continuous payment and start the money transfer. **Timeout: 30s**
*
* @throws ApiException
* if the Api call fails
*/
@Test
public void createContinuousPaymentTest() throws ApiException {

Payment payment = new Payment();
payment.setAmount(new MoneyAmount().amount(10).currency(MoneyAmount.CurrencyEnum.JPY));
payment.merchantPaymentId("merchantPaymentId")
.userAuthorizationId("userAuthorizationId")
.requestedAt(Instant.now().getEpochSecond())
.storeId(RandomStringUtils.randomAlphabetic(8))
.terminalId(RandomStringUtils.randomAlphanumeric(8))
.orderReceiptNumber(RandomStringUtils.randomAlphanumeric(8))
.orderDescription("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);
payment.orderItems(new ArrayList<MerchantOrderItem>(merchantOrderItems));

PaymentDetails paymentDetails = new PaymentDetails();
paymentDetails.resultInfo(resultInfo);
payment.status(PaymentState.StatusEnum.COMPLETED).authorizedAt(Instant.now().getNano()).paymentId("paymentId");
paymentDetails.data(payment);
Assertions.assertNotNull(payment.toString());
ApiResponse<PaymentDetails> paymentDetailsApiResponse = new ApiResponse<>(90001, null, paymentDetails);
Mockito.when(api.createContinuousPaymentWithHttpInfo(payment)).thenReturn(paymentDetailsApiResponse);
PaymentDetails response = api.createContinuousPayment(payment);
Assertions.assertEquals(response.getResultInfo().getMessage(), "SUCCESS");
Assertions.assertEquals(response.getData().getMerchantPaymentId(), "merchantPaymentId");
Assertions.assertEquals(response.getData().getUserAuthorizationId(), "userAuthorizationId");
Assertions.assertEquals(response.getData().getPaymentId(), "paymentId");
Assertions.assertEquals(response.getData().getStatus(), PaymentState.StatusEnum.COMPLETED);
Assertions.assertNotNull(response.getData());
Assertions.assertNotNull(response.getData().getTerminalId());
Assertions.assertNotNull(response.getData().getOrderReceiptNumber());
Assertions.assertNotNull(response.getData().getAmount());
Assertions.assertNotNull(response.getData().getRequestedAt());
Assertions.assertNotNull(response.getData().getOrderItems());
Assertions.assertNotNull(response.getData().getAuthorizedAt());

}
}

0 comments on commit 820b94c

Please sign in to comment.