Search in sources :

Example 1 with CaptureObject

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

the class PaymentApiExample method capturePayment.

private static void capturePayment(final PaymentApi apiInstance, String merchantPaymentId, int amount) {
    try {
        CaptureObject captureObject = new CaptureObject();
        captureObject.setMerchantCaptureId(UUID.randomUUID().toString());
        captureObject.setMerchantPaymentId(merchantPaymentId);
        captureObject.setAmount(new MoneyAmount().amount(amount).currency(MoneyAmount.CurrencyEnum.JPY));
        captureObject.setOrderDescription("new Order");
        PaymentDetails paymentDetails = apiInstance.capturePaymentAuth(captureObject);
        System.out.println(paymentDetails);
    } catch (ApiException e) {
        e.printStackTrace();
        System.out.println(e.getResponseBody());
    }
}
Also used : CaptureObject(jp.ne.paypay.model.CaptureObject) MoneyAmount(jp.ne.paypay.model.MoneyAmount) PaymentDetails(jp.ne.paypay.model.PaymentDetails) ApiException(jp.ne.paypay.ApiException)

Example 2 with CaptureObject

use of jp.ne.paypay.model.CaptureObject 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

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