Skip to content

Commit 7b2525f

Browse files
authored
Merge pull request #6215 from alphagov/PP-14844-add_rejection_reason_to_entity
PP-14844 add gateway_rejection_reason to ChargeEntity
2 parents 7507d94 + bcb3d55 commit 7b2525f

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

src/main/java/uk/gov/pay/connector/charge/model/domain/ChargeEntity.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ public class ChargeEntity extends AbstractVersionedEntity {
214214

215215
@Column(name = "requires_3ds")
216216
private Boolean requires3ds;
217+
218+
@Column(name = "gateway_rejection_reason")
219+
private String gatewayRejectionReason;
217220

218221
public ChargeEntity() {
219222
//for jpa
@@ -289,7 +292,11 @@ public Optional<PaymentInstrumentEntity> getPaymentInstrument() {
289292
public void setPaymentInstrument(PaymentInstrumentEntity paymentInstrument) {
290293
this.paymentInstrument = paymentInstrument;
291294
}
292-
295+
296+
public void setGatewayRejectionReason(String gatewayRejectionReason) {
297+
this.gatewayRejectionReason = gatewayRejectionReason;
298+
}
299+
293300
public Long getAmount() {
294301
return amount;
295302
}
@@ -625,6 +632,10 @@ public Instant getUpdatedDate() {
625632
return updatedDate;
626633
}
627634

635+
public String getGatewayRejectionReason() {
636+
return gatewayRejectionReason;
637+
}
638+
628639
public static final class WebChargeEntityBuilder {
629640
private Long amount;
630641
private String returnUrl;

src/test/java/uk/gov/pay/connector/charge/model/domain/ChargeEntityFixture.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public class ChargeEntityFixture {
7979
private Boolean requires3ds;
8080
private ChargeResponse.AuthorisationSummary authorisationSummary;
8181
private AgreementPaymentType agreementPaymentType;
82+
private String gatewayRejectionReason;
8283

8384
public static ChargeEntityFixture aValidChargeEntity() {
8485
return new ChargeEntityFixture();
@@ -178,6 +179,7 @@ public ChargeEntity build() {
178179
chargeEntity.setExemption3dsRequested(exemption3dsRequested);
179180
chargeEntity.setPaymentInstrument(paymentInstrument);
180181
chargeEntity.setUpdatedDate(updatedDate);
182+
chargeEntity.setGatewayRejectionReason(gatewayRejectionReason);
181183

182184
if (this.auth3DsRequiredEntity != null) {
183185
chargeEntity.set3dsRequiredDetails(auth3DsRequiredEntity);
@@ -375,6 +377,11 @@ public ChargeEntityFixture withSavePaymentInstrumentToAgreement(boolean savePaym
375377
return this;
376378
}
377379

380+
public ChargeEntityFixture withGatewayRejectionReason(String gatewayRejectionReason) {
381+
this.gatewayRejectionReason = gatewayRejectionReason;
382+
return this;
383+
}
384+
378385
public ChargeEntityFixture withPaymentInstrument(PaymentInstrumentEntity paymentInstrument) {
379386
this.paymentInstrument = paymentInstrument;
380387
return this;

src/test/java/uk/gov/pay/connector/it/dao/ChargeDaoIT.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,22 @@ void shouldUpdateChargeWithExemption3dsType() {
342342
assertEquals(chargeDao.findByExternalId(chargeEntity.getExternalId()).get().getExemption3dsRequested(), Exemption3dsType.OPTIMISED);
343343
}
344344

345+
@Test
346+
void shouldUpdateChargeWithGatewayRejectionReason() {
347+
ChargeEntity chargeEntity = aValidChargeEntity()
348+
.withGatewayAccountEntity(gatewayAccount)
349+
.withGatewayAccountCredentialsEntity(gatewayAccountCredentialsEntity)
350+
.build();
351+
chargeDao.persist(chargeEntity);
352+
353+
assertNull(chargeDao.findByExternalId(chargeEntity.getExternalId()).get().getGatewayRejectionReason());
354+
355+
chargeEntity.setGatewayRejectionReason("fraudulent");
356+
chargeDao.merge(chargeEntity);
357+
358+
assertEquals(chargeDao.findByExternalId(chargeEntity.getExternalId()).get().getGatewayRejectionReason(), "fraudulent");
359+
}
360+
345361
@Test
346362
void shouldCreateNewChargeWithParityCheckStatus() {
347363
ChargeEntity chargeEntity = aValidChargeEntity()

src/test/java/uk/gov/pay/connector/model/domain/ChargeEntityTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,4 +234,13 @@ void shouldSetRequires3dsToTrueWhenSettingAuth3dsRequiredEntity() {
234234

235235
assertTrue(chargeEntity.getRequires3ds());
236236
}
237+
238+
@Test
239+
void shouldReturnGatewayRejectionReason() {
240+
ChargeEntity chargeCreated = ChargeEntityFixture
241+
.aValidChargeEntity()
242+
.build();
243+
chargeCreated.setGatewayRejectionReason("fraudulent");
244+
assertThat(chargeCreated.getGatewayRejectionReason(), is("fraudulent"));
245+
}
237246
}

0 commit comments

Comments
 (0)