Search in sources :

Example 1 with PaymentProvider

use of uk.gov.pay.connector.gateway.PaymentProvider in project pay-connector by alphagov.

the class SmartpayPaymentProviderTest method shouldSuccessfullySendACaptureRequest.

@Test
public void shouldSuccessfullySendACaptureRequest() throws Exception {
    PaymentProvider paymentProvider = getSmartpayPaymentProvider();
    CardAuthorisationGatewayRequest request = getCardAuthorisationRequest(chargeEntity);
    GatewayResponse<BaseAuthoriseResponse> response = paymentProvider.authorise(request);
    assertTrue(response.isSuccessful());
    assertThat(response.getBaseResponse().isPresent(), is(true));
    SmartpayAuthorisationResponse smartpayAuthorisationResponse = (SmartpayAuthorisationResponse) response.getBaseResponse().get();
    String transactionId = smartpayAuthorisationResponse.getPspReference();
    assertThat(transactionId, is(not(nullValue())));
    chargeEntity.setGatewayTransactionId(transactionId);
    CaptureResponse captureGatewayResponse = paymentProvider.capture(CaptureGatewayRequest.valueOf(chargeEntity));
    assertTrue(captureGatewayResponse.isSuccessful());
    assertThat(captureGatewayResponse.state(), is(CaptureResponse.ChargeState.PENDING));
}
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) SmartpayAuthorisationResponse(uk.gov.pay.connector.gateway.smartpay.SmartpayAuthorisationResponse) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CardAuthorisationGatewayRequest(uk.gov.pay.connector.gateway.model.request.CardAuthorisationGatewayRequest) Test(org.junit.Test)

Example 2 with PaymentProvider

use of uk.gov.pay.connector.gateway.PaymentProvider in project pay-connector by alphagov.

the class SmartpayPaymentProviderTest method shouldSendSuccessfullyAnOrderForMerchantWithNoAddressInRequest.

@Test
public void shouldSendSuccessfullyAnOrderForMerchantWithNoAddressInRequest() throws Exception {
    PaymentProvider paymentProvider = getSmartpayPaymentProvider();
    AuthCardDetails authCardDetails = AuthCardDetailsFixture.anAuthCardDetails().withCardNo(VALID_SMARTPAY_CARD_NUMBER).withAddress(null).build();
    CardAuthorisationGatewayRequest request = new CardAuthorisationGatewayRequest(chargeEntity, authCardDetails);
    GatewayResponse response = paymentProvider.authorise(request);
    assertTrue(response.isSuccessful());
}
Also used : GatewayResponse(uk.gov.pay.connector.gateway.model.response.GatewayResponse) PaymentProvider(uk.gov.pay.connector.gateway.PaymentProvider) SmartpayPaymentProvider(uk.gov.pay.connector.gateway.smartpay.SmartpayPaymentProvider) AuthCardDetails(uk.gov.pay.connector.gateway.model.AuthCardDetails) CardAuthorisationGatewayRequest(uk.gov.pay.connector.gateway.model.request.CardAuthorisationGatewayRequest) Test(org.junit.Test)

Example 3 with PaymentProvider

use of uk.gov.pay.connector.gateway.PaymentProvider in project pay-connector by alphagov.

the class SmartpayPaymentProviderTest method shouldSendSuccessfullyAnOrderForMerchantWithUsAddressInRequest.

@Test
public void shouldSendSuccessfullyAnOrderForMerchantWithUsAddressInRequest() throws Exception {
    PaymentProvider paymentProvider = getSmartpayPaymentProvider();
    Address usAddress = new Address();
    usAddress.setLine1("125 Kingsway");
    usAddress.setLine2("Aviation House");
    usAddress.setPostcode("90210");
    usAddress.setCity("Washington D.C.");
    usAddress.setCountry("US");
    AuthCardDetails authCardDetails = AuthCardDetailsFixture.anAuthCardDetails().withCardNo(VALID_SMARTPAY_CARD_NUMBER).withAddress(usAddress).build();
    CardAuthorisationGatewayRequest request = new CardAuthorisationGatewayRequest(chargeEntity, authCardDetails);
    GatewayResponse response = paymentProvider.authorise(request);
    assertTrue(response.isSuccessful());
}
Also used : GatewayResponse(uk.gov.pay.connector.gateway.model.response.GatewayResponse) PaymentProvider(uk.gov.pay.connector.gateway.PaymentProvider) SmartpayPaymentProvider(uk.gov.pay.connector.gateway.smartpay.SmartpayPaymentProvider) Address(uk.gov.pay.connector.common.model.domain.Address) AuthCardDetails(uk.gov.pay.connector.gateway.model.AuthCardDetails) CardAuthorisationGatewayRequest(uk.gov.pay.connector.gateway.model.request.CardAuthorisationGatewayRequest) Test(org.junit.Test)

Example 4 with PaymentProvider

use of uk.gov.pay.connector.gateway.PaymentProvider in project pay-connector by alphagov.

the class SmartpayPaymentProviderTest method shouldFailRequestAuthorisationIfCredentialsAreNotCorrect.

@Test
public void shouldFailRequestAuthorisationIfCredentialsAreNotCorrect() throws Exception {
    PaymentProvider paymentProvider = getSmartpayPaymentProvider();
    GatewayAccountEntity accountWithInvalidCredentials = new GatewayAccountEntity();
    accountWithInvalidCredentials.setId(11L);
    accountWithInvalidCredentials.setGatewayAccountCredentials(List.of(aGatewayAccountCredentialsEntity().withCredentials(Map.of("merchant_id", "MerchantAccount", "username", "wrong-username", "password", "wrong-password")).withGatewayAccountEntity(accountWithInvalidCredentials).withPaymentProvider(SMARTPAY.getName()).withState(ACTIVE).build()));
    accountWithInvalidCredentials.setType(TEST);
    chargeEntity.setGatewayAccount(accountWithInvalidCredentials);
    CardAuthorisationGatewayRequest request = getCardAuthorisationRequest(chargeEntity);
    GatewayResponse<BaseAuthoriseResponse> response = paymentProvider.authorise(request);
    assertFalse(response.isSuccessful());
    assertNotNull(response.getGatewayError());
}
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) GatewayAccountEntity(uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntity) CardAuthorisationGatewayRequest(uk.gov.pay.connector.gateway.model.request.CardAuthorisationGatewayRequest) Test(org.junit.Test)

Example 5 with PaymentProvider

use of uk.gov.pay.connector.gateway.PaymentProvider in project pay-connector by alphagov.

the class EventFactoryTest method setUp.

@Before
public void setUp() {
    chargeService = mock(ChargeService.class);
    refundDao = mock(RefundDao.class);
    refundService = mock(RefundService.class);
    chargeEventDao = mock(ChargeEventDao.class);
    paymentProviders = mock(PaymentProviders.class);
    PaymentProvider paymentProvider = new SandboxPaymentProvider();
    when(paymentProviders.byName(any(PaymentGatewayName.class))).thenReturn(paymentProvider);
    eventFactory = new EventFactory(chargeService, refundDao, refundService, chargeEventDao, paymentProviders);
}
Also used : PaymentProvider(uk.gov.pay.connector.gateway.PaymentProvider) SandboxPaymentProvider(uk.gov.pay.connector.gateway.sandbox.SandboxPaymentProvider) EventFactory(uk.gov.pay.connector.events.model.EventFactory) RefundService(uk.gov.pay.connector.refund.service.RefundService) RefundDao(uk.gov.pay.connector.refund.dao.RefundDao) ChargeEventDao(uk.gov.pay.connector.chargeevent.dao.ChargeEventDao) PaymentProviders(uk.gov.pay.connector.gateway.PaymentProviders) PaymentGatewayName(uk.gov.pay.connector.gateway.PaymentGatewayName) ChargeService(uk.gov.pay.connector.charge.service.ChargeService) SandboxPaymentProvider(uk.gov.pay.connector.gateway.sandbox.SandboxPaymentProvider) Before(org.junit.Before)

Aggregations

PaymentProvider (uk.gov.pay.connector.gateway.PaymentProvider)15 Test (org.junit.Test)14 SmartpayPaymentProvider (uk.gov.pay.connector.gateway.smartpay.SmartpayPaymentProvider)14 CardAuthorisationGatewayRequest (uk.gov.pay.connector.gateway.model.request.CardAuthorisationGatewayRequest)10 BaseAuthoriseResponse (uk.gov.pay.connector.gateway.model.response.BaseAuthoriseResponse)7 SandboxPaymentProvider (uk.gov.pay.connector.gateway.sandbox.SandboxPaymentProvider)5 EpdqPaymentProvider (uk.gov.pay.connector.gateway.epdq.EpdqPaymentProvider)4 AuthCardDetails (uk.gov.pay.connector.gateway.model.AuthCardDetails)4 GatewayResponse (uk.gov.pay.connector.gateway.model.response.GatewayResponse)4 StripePaymentProvider (uk.gov.pay.connector.gateway.stripe.StripePaymentProvider)4 WorldpayPaymentProvider (uk.gov.pay.connector.gateway.worldpay.WorldpayPaymentProvider)4 SmartpayAuthorisationResponse (uk.gov.pay.connector.gateway.smartpay.SmartpayAuthorisationResponse)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 Auth3dsRequiredEntity (uk.gov.pay.connector.charge.model.domain.Auth3dsRequiredEntity)2 Address (uk.gov.pay.connector.common.model.domain.Address)2 CaptureResponse (uk.gov.pay.connector.gateway.CaptureResponse)2 Before (org.junit.Before)1 ChargeService (uk.gov.pay.connector.charge.service.ChargeService)1 ChargeEventDao (uk.gov.pay.connector.chargeevent.dao.ChargeEventDao)1 EventFactory (uk.gov.pay.connector.events.model.EventFactory)1