use of uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntity in project pay-connector by alphagov.
the class WorldpayNotificationService method handleNotificationFor.
@Transactional
public boolean handleNotificationFor(String ipAddress, String payload) {
if (isNotificationRejectedFromIpAddress(ipAddress)) {
logger.error("{} notification received from ip '{}' which is not in domain '{}'", PAYMENT_GATEWAY_NAME, ipAddress, notificationDomain());
return false;
}
WorldpayNotification notification;
try {
logger.info("Parsing {} notification", PAYMENT_GATEWAY_NAME);
logger.debug("Payload: {}", payload);
notification = XMLUnmarshaller.unmarshall(payload, WorldpayNotification.class);
logger.info("Parsed {} notification: {}", PAYMENT_GATEWAY_NAME, notification);
} catch (XMLUnmarshallerException e) {
logger.error("{} notification parsing failed: {}", PAYMENT_GATEWAY_NAME, e);
return true;
}
if (isIgnored(notification)) {
logger.info("{} notification {} ignored", PAYMENT_GATEWAY_NAME, notification);
return true;
}
if (isTransactionIdBlank(notification)) {
logger.warn("{} notification {} failed verification because it has no transaction ID", PAYMENT_GATEWAY_NAME, notification);
return true;
}
Optional<Charge> maybeCharge = chargeService.findByProviderAndTransactionIdFromDbOrLedger(PAYMENT_GATEWAY_NAME, notification.getTransactionId());
if (maybeCharge.isEmpty()) {
// will be blocked until the notification being retried is successful or removed from Worldpay's queue
if (gatewayAccountService.isATelephonePaymentNotificationAccount(notification.getMerchantCode())) {
logger.info("{} notification {} for telephone payments gateway account could not be evaluated (associated charge entity not found)", PAYMENT_GATEWAY_NAME, notification);
return false;
}
logger.info("{} notification {} could not be evaluated (associated charge entity not found)", PAYMENT_GATEWAY_NAME, notification);
return true;
}
Charge charge = maybeCharge.get();
Optional<GatewayAccountEntity> mayBeGatewayAccountEntity = gatewayAccountService.getGatewayAccount(charge.getGatewayAccountId());
if (mayBeGatewayAccountEntity.isEmpty()) {
logger.error("{} notification {} could not be processed (associated gateway account [{}] not found for charge [{}] {}, {})", PAYMENT_GATEWAY_NAME, notification, charge.getGatewayAccountId(), charge.getExternalId(), kv(PAYMENT_EXTERNAL_ID, charge.getExternalId()), kv(GATEWAY_ACCOUNT_ID, charge.getGatewayAccountId()));
return false;
}
GatewayAccountEntity gatewayAccountEntity = mayBeGatewayAccountEntity.get();
if (isCaptureNotification(notification)) {
if (charge.isHistoric()) {
chargeNotificationProcessor.processCaptureNotificationForExpungedCharge(gatewayAccountEntity, notification.getTransactionId(), charge, CAPTURED);
return true;
}
chargeNotificationProcessor.invoke(notification.getTransactionId(), charge, CAPTURED, notification.getGatewayEventDate());
} else if (isRefundNotification(notification)) {
refundNotificationProcessor.invoke(PaymentGatewayName.WORLDPAY, newRefundStatus(notification), gatewayAccountEntity, notification.getReference(), notification.getTransactionId(), charge);
} else if (isErrorNotification(notification)) {
if (gatewayAccountEntity.isLive()) {
logger.error("{} error notification received for live account {}", PAYMENT_GATEWAY_NAME, notification);
} else {
logger.info("{} error notification received for test account {}", PAYMENT_GATEWAY_NAME, notification);
}
} else {
logger.error("{} notification {} unknown", PAYMENT_GATEWAY_NAME, notification);
}
return true;
}
use of uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntity in project pay-connector by alphagov.
the class GatewayAccountObjectConverter method createEntityFrom.
public static GatewayAccountEntity createEntityFrom(GatewayAccountRequest gatewayAccountRequest) {
GatewayAccountEntity gatewayAccountEntity = new GatewayAccountEntity(GatewayAccountType.fromString(gatewayAccountRequest.getProviderAccountType()));
gatewayAccountEntity.setExternalId(randomUuid());
gatewayAccountEntity.setServiceName(gatewayAccountRequest.getServiceName());
gatewayAccountEntity.setServiceId(gatewayAccountRequest.getServiceId());
gatewayAccountEntity.setDescription(gatewayAccountRequest.getDescription());
gatewayAccountEntity.setAnalyticsId(gatewayAccountRequest.getAnalyticsId());
gatewayAccountEntity.setRequires3ds(gatewayAccountRequest.getRequires3ds());
gatewayAccountEntity.setIntegrationVersion3ds(DEFAULT_INTEGRATION_VERSION_3_DS);
gatewayAccountEntity.addNotification(EmailNotificationType.PAYMENT_CONFIRMED, new EmailNotificationEntity(gatewayAccountEntity));
gatewayAccountEntity.addNotification(EmailNotificationType.REFUND_ISSUED, new EmailNotificationEntity(gatewayAccountEntity));
return gatewayAccountEntity;
}
use of uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntity in project pay-connector by alphagov.
the class GatewayAccountCredentialsService method updateGatewayAccountCredentials.
@Transactional
public GatewayAccountCredentials updateGatewayAccountCredentials(GatewayAccountCredentialsEntity gatewayAccountCredentialsEntity, Iterable<JsonPatchRequest> updateRequests) {
for (JsonPatchRequest updateRequest : updateRequests) {
if (JsonPatchOp.REPLACE == updateRequest.getOp()) {
updateGatewayAccountCredentialField(updateRequest, gatewayAccountCredentialsEntity);
}
}
gatewayAccountCredentialsDao.merge(gatewayAccountCredentialsEntity);
GatewayAccountEntity gatewayAccountEntity = gatewayAccountCredentialsEntity.getGatewayAccountEntity();
LOGGER.info("Updated credentials for gateway account [id={}]", gatewayAccountEntity.getId(), kv(GATEWAY_ACCOUNT_ID, gatewayAccountEntity.getId()), kv(GATEWAY_ACCOUNT_TYPE, gatewayAccountEntity.getType()), kv(PROVIDER, gatewayAccountCredentialsEntity.getPaymentProvider()), kv("state", gatewayAccountCredentialsEntity.getState()), kv(USER_EXTERNAL_ID, gatewayAccountCredentialsEntity.getLastUpdatedByUserExternalId()));
return new GatewayAccountCredentials(gatewayAccountCredentialsEntity);
}
use of uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntity 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());
}
use of uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntity in project pay-connector by alphagov.
the class ChargeDaoCardDetailsIT method persist_shouldStoreNullCardTypeDetails.
@Test
public void persist_shouldStoreNullCardTypeDetails() {
GatewayAccountEntity testAccount = new GatewayAccountEntity(GatewayAccountType.TEST);
testAccount.setExternalId(randomUuid());
gatewayAccountDao.persist(testAccount);
GatewayAccountCredentialsEntity credentialsEntity = aGatewayAccountCredentialsEntity().withCredentials(Map.of("username", "theUsername", "password", "thePassword", "merchant_id", "theMerchantCode")).withGatewayAccountEntity(testAccount).withPaymentProvider(SANDBOX.getName()).withState(ACTIVE).withExternalId(randomUuid()).build();
gatewayAccountCredentialsDao.persist(credentialsEntity);
Address billingAddress = AddressFixture.anAddress().build();
ChargeEntity chargeEntity = ChargeEntityFixture.aValidChargeEntity().withGatewayAccountCredentialsEntity(credentialsEntity).build();
CardDetailsEntity cardDetailsEntity = new CardDetailsEntity(FirstDigitsCardNumber.of("123456"), LastDigitsCardNumber.of("1258"), "Mr. Pay Mc Payment", CardExpiryDate.valueOf("03/09"), "VISA", null, new AddressEntity(billingAddress));
chargeEntity.setCardDetails(cardDetailsEntity);
chargeDao.persist(chargeEntity);
Map<String, Object> cardDetailsSaved = databaseTestHelper.getChargeCardDetails(chargeEntity.getId());
assertThat(cardDetailsSaved, hasEntry("card_type", null));
}
Aggregations