Search in sources :

Example 1 with Capture

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

the class PaymentApiTest method capturePaymentAuthTest.

/**
 * Capture a payment authorization
 *
 * This api is used to capture the payment authorization for a payment  **Timeout: 30s**
 *
 * @throws ApiException if the Api call fails
 */
@Test
public void capturePaymentAuthTest() throws ApiException {
    CaptureObject captureObject = new CaptureObject();
    captureObject.setMerchantCaptureId(UUID.randomUUID().toString());
    captureObject.setMerchantPaymentId("merchantPaymentId");
    captureObject.setAmount(new MoneyAmount().amount(10).currency(MoneyAmount.CurrencyEnum.JPY));
    captureObject.setOrderDescription("new Order");
    captureObject.setRequestedAt(Instant.now().getEpochSecond());
    PaymentDetails paymentDetails = new PaymentDetails();
    paymentDetails.setResultInfo(resultInfo);
    payment.setStatus(PaymentState.StatusEnum.COMPLETED);
    PaymentStateCaptures paymentStateCaptures = new PaymentStateCaptures();
    Capture capture = new Capture();
    capture.acceptedAt(Instant.now().getNano());
    capture.amount(payment.getAmount());
    capture.setExpiresAt(Instant.now().getNano());
    capture.setAmountDescription("amount captured");
    capture.setMerchantCaptureId(captureObject.getMerchantCaptureId());
    capture.setOrderDescription(captureObject.getOrderDescription());
    capture.setRequestedAt(captureObject.getRequestedAt());
    capture.setAcceptedAt(Instant.now().getNano());
    capture.setStatus(Capture.StatusEnum.COMPLETED);
    Assert.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);
    Assert.assertNotNull(response.toString());
    Assert.assertEquals(response.getResultInfo().getMessage(), "SUCCESS");
    Assert.assertNotNull(response.getData());
    Assert.assertEquals(response.getData().getMerchantPaymentId(), "merchantPaymentId");
    Assert.assertEquals(response.getData().getUserAuthorizationId(), "userAuthorizationId");
    Assert.assertEquals(response.getData().getStatus(), Payment.StatusEnum.COMPLETED);
    Assert.assertNotNull(response.getData().getTerminalId());
    Assert.assertNotNull(response.getData().getOrderReceiptNumber());
    Assert.assertNotNull(response.getData().getCaptures());
    Assert.assertNotNull(response.getData().getCaptures().getData().get(0));
    Assert.assertNotNull(response.getData().getCaptures().getData().get(0).getAcceptedAt());
    Assert.assertNotNull(response.getData().getCaptures().getData().get(0).getAmount());
    Assert.assertNotNull(response.getData().getCaptures().getData().get(0).getAmountDescription());
    Assert.assertNotNull(response.getData().getCaptures().getData().get(0).getExpiresAt());
    Assert.assertNotNull(response.getData().getCaptures().getData().get(0).getMerchantCaptureId());
    Assert.assertNotNull(response.getData().getCaptures().getData().get(0).getOrderDescription());
    Assert.assertEquals(response.getData().getCaptures().getData().get(0).getStatus(), Capture.StatusEnum.COMPLETED);
}
Also used : PaymentStateCaptures(jp.ne.paypay.model.PaymentStateCaptures) CaptureObject(jp.ne.paypay.model.CaptureObject) MoneyAmount(jp.ne.paypay.model.MoneyAmount) PaymentDetails(jp.ne.paypay.model.PaymentDetails) Capture(jp.ne.paypay.model.Capture) ApiResponse(jp.ne.paypay.ApiResponse) Test(org.junit.jupiter.api.Test)

Aggregations

ApiResponse (jp.ne.paypay.ApiResponse)1 Capture (jp.ne.paypay.model.Capture)1 CaptureObject (jp.ne.paypay.model.CaptureObject)1 MoneyAmount (jp.ne.paypay.model.MoneyAmount)1 PaymentDetails (jp.ne.paypay.model.PaymentDetails)1 PaymentStateCaptures (jp.ne.paypay.model.PaymentStateCaptures)1 Test (org.junit.jupiter.api.Test)1