Search in sources :

Example 1 with RefundGatewayRequest

use of uk.gov.pay.connector.gateway.model.request.RefundGatewayRequest in project pay-connector by alphagov.

the class StripeTransferInRequestTest method setUp.

@Before
public void setUp() {
    gatewayAccount = aGatewayAccountEntity().withGatewayName("stripe").build();
    gatewayAccountCredentialsEntity = aGatewayAccountCredentialsEntity().withCredentials(Map.of("stripe_account_id", stripeConnectAccountId)).withGatewayAccountEntity(gatewayAccount).withPaymentProvider(STRIPE.getName()).withState(ACTIVE).build();
    gatewayAccount.setGatewayAccountCredentials(List.of(gatewayAccountCredentialsEntity));
    when(charge.getExternalId()).thenReturn(chargeExternalId);
    when(refundEntity.getAmount()).thenReturn(refundAmount);
    when(refundEntity.getExternalId()).thenReturn(refundExternalId);
    when(stripeGatewayConfig.getUrl()).thenReturn(stripeBaseUrl);
    when(stripeGatewayConfig.getAuthTokens()).thenReturn(stripeAuthTokens);
    when(stripeGatewayConfig.getPlatformAccountId()).thenReturn(stripePlatformAccountId);
    final RefundGatewayRequest refundGatewayRequest = RefundGatewayRequest.valueOf(charge, refundEntity, gatewayAccount, gatewayAccountCredentialsEntity);
    refundTransferInRequest = StripeTransferInRequest.of(refundGatewayRequest, stripeChargeId, stripeGatewayConfig);
    feeTransferInRequest = StripeTransferInRequest.of(feeAmount, gatewayAccount, gatewayAccountCredentialsEntity, stripeChargeId, chargeExternalId, stripeGatewayConfig);
}
Also used : RefundGatewayRequest(uk.gov.pay.connector.gateway.model.request.RefundGatewayRequest) Before(org.junit.Before)

Example 2 with RefundGatewayRequest

use of uk.gov.pay.connector.gateway.model.request.RefundGatewayRequest in project pay-connector by alphagov.

the class StripeRequestTest method setUp.

@BeforeEach
void setUp() {
    gatewayAccount = aGatewayAccountEntity().withGatewayName(STRIPE.getName()).build();
    var gatewayAccountCredentialsEntity = aGatewayAccountCredentialsEntity().withCredentials(Map.of("stripe_account_id", "stripe_connect_account_id")).withGatewayAccountEntity(gatewayAccount).withPaymentProvider(STRIPE.getName()).withState(ACTIVE).build();
    gatewayAccount.setGatewayAccountCredentials(List.of(gatewayAccountCredentialsEntity));
    when(charge.getGatewayTransactionId()).thenReturn("gatewayTransactionId");
    when(stripeGatewayConfig.getAuthTokens()).thenReturn(stripeAuthTokens);
    final RefundGatewayRequest refundGatewayRequest = RefundGatewayRequest.valueOf(charge, refundEntity, gatewayAccount, gatewayAccountCredentialsEntity);
    stripeRefundRequest = StripeRefundRequest.of(refundGatewayRequest, "charge_id", stripeGatewayConfig);
}
Also used : RefundGatewayRequest(uk.gov.pay.connector.gateway.model.request.RefundGatewayRequest) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with RefundGatewayRequest

use of uk.gov.pay.connector.gateway.model.request.RefundGatewayRequest in project pay-connector by alphagov.

the class StripeRefundRequestTest method setUp.

@Before
public void setUp() {
    gatewayAccount = aGatewayAccountEntity().withGatewayName("stripe").build();
    var gatewayAccountCredentialsEntity = aGatewayAccountCredentialsEntity().withCredentials(Map.of("stripe_account_id", "stripe_account_id")).withGatewayAccountEntity(gatewayAccount).withPaymentProvider(STRIPE.getName()).withState(ACTIVE).build();
    gatewayAccount.setGatewayAccountCredentials(List.of(gatewayAccountCredentialsEntity));
    when(refundEntity.getAmount()).thenReturn(refundAmount);
    when(refundEntity.getExternalId()).thenReturn(refundExternalId);
    when(stripeGatewayConfig.getUrl()).thenReturn(stripeBaseUrl);
    when(stripeGatewayConfig.getAuthTokens()).thenReturn(stripeAuthTokens);
    final RefundGatewayRequest refundGatewayRequest = RefundGatewayRequest.valueOf(charge, refundEntity, gatewayAccount, gatewayAccountCredentialsEntity);
    stripeRefundRequest = StripeRefundRequest.of(refundGatewayRequest, stripeChargeId, stripeGatewayConfig);
}
Also used : RefundGatewayRequest(uk.gov.pay.connector.gateway.model.request.RefundGatewayRequest) Before(org.junit.Before)

Example 4 with RefundGatewayRequest

use of uk.gov.pay.connector.gateway.model.request.RefundGatewayRequest in project pay-connector by alphagov.

the class EpdqPaymentProviderTest method shouldRefundSuccessfully.

@Test
public void shouldRefundSuccessfully() throws Exception {
    setUpAndCheckThatEpdqIsUp();
    var request = new CardAuthorisationGatewayRequest(chargeEntity, authCardDetailsFixture().build());
    GatewayResponse<BaseAuthoriseResponse> response = paymentProvider.authorise(request);
    assertThat(response.isSuccessful(), is(true));
    String transactionId = response.getBaseResponse().get().getTransactionId();
    assertThat(transactionId, is(not(nullValue())));
    CaptureGatewayRequest captureRequest = buildCaptureRequest(chargeEntity, transactionId);
    CaptureResponse captureResponse = paymentProvider.capture(captureRequest);
    assertThat(captureResponse.isSuccessful(), is(true));
    RefundGatewayRequest refundGatewayRequest = buildRefundRequest(chargeEntity, (chargeEntity.getAmount() - 100));
    GatewayRefundResponse refundResponse = paymentProvider.refund(refundGatewayRequest);
    assertThat(refundResponse.isSuccessful(), is(true));
}
Also used : CaptureGatewayRequest(uk.gov.pay.connector.gateway.model.request.CaptureGatewayRequest) BaseAuthoriseResponse(uk.gov.pay.connector.gateway.model.response.BaseAuthoriseResponse) CaptureResponse(uk.gov.pay.connector.gateway.CaptureResponse) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) GatewayRefundResponse(uk.gov.pay.connector.gateway.model.response.GatewayRefundResponse) CardAuthorisationGatewayRequest(uk.gov.pay.connector.gateway.model.request.CardAuthorisationGatewayRequest) RefundGatewayRequest(uk.gov.pay.connector.gateway.model.request.RefundGatewayRequest) Test(org.junit.Test)

Example 5 with RefundGatewayRequest

use of uk.gov.pay.connector.gateway.model.request.RefundGatewayRequest in project pay-connector by alphagov.

the class SmartpayPaymentProviderTest method shouldRefundToAnExistingPaymentSuccessfully.

@Test
public void shouldRefundToAnExistingPaymentSuccessfully() throws Exception {
    CardAuthorisationGatewayRequest request = getCardAuthorisationRequest(chargeEntity);
    PaymentProvider smartpay = getSmartpayPaymentProvider();
    GatewayResponse<BaseAuthoriseResponse> authoriseResponse = smartpay.authorise(request);
    assertTrue(authoriseResponse.isSuccessful());
    SmartpayAuthorisationResponse smartpayAuthorisationResponse = (SmartpayAuthorisationResponse) authoriseResponse.getBaseResponse().get();
    chargeEntity.setGatewayTransactionId(smartpayAuthorisationResponse.getPspReference());
    CaptureResponse captureGatewayResponse = smartpay.capture(CaptureGatewayRequest.valueOf(chargeEntity));
    assertTrue(captureGatewayResponse.isSuccessful());
    RefundEntity refundEntity = new RefundEntity(1L, userExternalId, userEmail, chargeEntity.getExternalId());
    RefundGatewayRequest refundRequest = RefundGatewayRequest.valueOf(Charge.from(chargeEntity), refundEntity, gatewayAccountEntity, gatewayAccountCredentialsEntity);
    GatewayRefundResponse refundResponse = smartpay.refund(refundRequest);
    assertThat(refundResponse.isSuccessful(), is(true));
}
Also used : PaymentProvider(uk.gov.pay.connector.gateway.PaymentProvider) SmartpayPaymentProvider(uk.gov.pay.connector.gateway.smartpay.SmartpayPaymentProvider) BaseAuthoriseResponse(uk.gov.pay.connector.gateway.model.response.BaseAuthoriseResponse) CaptureResponse(uk.gov.pay.connector.gateway.CaptureResponse) RefundEntity(uk.gov.pay.connector.refund.model.domain.RefundEntity) SmartpayAuthorisationResponse(uk.gov.pay.connector.gateway.smartpay.SmartpayAuthorisationResponse) GatewayRefundResponse(uk.gov.pay.connector.gateway.model.response.GatewayRefundResponse) CardAuthorisationGatewayRequest(uk.gov.pay.connector.gateway.model.request.CardAuthorisationGatewayRequest) RefundGatewayRequest(uk.gov.pay.connector.gateway.model.request.RefundGatewayRequest) Test(org.junit.Test)

Aggregations

RefundGatewayRequest (uk.gov.pay.connector.gateway.model.request.RefundGatewayRequest)9 Test (org.junit.Test)6 BaseAuthoriseResponse (uk.gov.pay.connector.gateway.model.response.BaseAuthoriseResponse)6 GatewayRefundResponse (uk.gov.pay.connector.gateway.model.response.GatewayRefundResponse)6 CaptureGatewayRequest (uk.gov.pay.connector.gateway.model.request.CaptureGatewayRequest)5 RefundEntity (uk.gov.pay.connector.refund.model.domain.RefundEntity)5 ChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntity)4 ChargeEntityFixture.aValidChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity)4 Before (org.junit.Before)2 CaptureResponse (uk.gov.pay.connector.gateway.CaptureResponse)2 CardAuthorisationGatewayRequest (uk.gov.pay.connector.gateway.model.request.CardAuthorisationGatewayRequest)2 BeforeEach (org.junit.jupiter.api.BeforeEach)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 PaymentProvider (uk.gov.pay.connector.gateway.PaymentProvider)1 SmartpayAuthorisationResponse (uk.gov.pay.connector.gateway.smartpay.SmartpayAuthorisationResponse)1 SmartpayPaymentProvider (uk.gov.pay.connector.gateway.smartpay.SmartpayPaymentProvider)1