Skip to content

Commit

Permalink
Merge pull request #576 from alphagov/PP-6125-return-source-and-live-…
Browse files Browse the repository at this point in the history
…in-transactionview-response

PP-6125 Return `source` and `live` in Response
  • Loading branch information
rory malcolm authored Feb 6, 2020
2 parents 5d37db3 + 111df88 commit 2aedc19
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 6 deletions.
20 changes: 17 additions & 3 deletions src/main/java/uk/gov/pay/ledger/transaction/model/Payment.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import uk.gov.pay.commons.api.json.ApiResponseDateTimeSerializer;
import uk.gov.pay.commons.model.Source;
import uk.gov.pay.ledger.transaction.search.model.RefundSummary;
import uk.gov.pay.ledger.transaction.search.model.SettlementSummary;
import uk.gov.pay.ledger.transaction.state.TransactionState;
Expand Down Expand Up @@ -40,6 +41,8 @@ public class Payment extends Transaction{
private Long totalAmount;
private RefundSummary refundSummary;
private SettlementSummary settlementSummary;
private Boolean live;
private Source source;

public Payment() {

Expand All @@ -52,7 +55,7 @@ public Payment(Long id, String gatewayAccountId, Long amount,
CardDetails cardDetails, Boolean delayedCapture, Map<String, Object> externalMetaData,
Integer eventCount, String gatewayTransactionId, Long corporateCardSurcharge, Long fee,
Long netAmount, Long totalAmount, RefundSummary refundSummary, SettlementSummary settlementSummary,
Boolean moto) {
Boolean moto, Boolean live, Source source) {
super(id, gatewayAccountId, amount, externalId);
this.corporateCardSurcharge = corporateCardSurcharge;
this.fee = fee;
Expand All @@ -78,6 +81,8 @@ public Payment(Long id, String gatewayAccountId, Long amount,
this.eventCount = eventCount;
this.gatewayTransactionId = gatewayTransactionId;
this.moto = moto;
this.live = live;
this.source = source;
}

public Payment(String gatewayAccountId, Long amount,
Expand All @@ -87,11 +92,12 @@ public Payment(String gatewayAccountId, Long amount,
CardDetails cardDetails, Boolean delayedCapture, Map<String, Object> externalMetaData,
Integer eventCount, String gatewayTransactionId, Long corporateCardSurcharge, Long fee,
Long netAmount, RefundSummary refundSummary, Long totalAmount, SettlementSummary settlementSummary,
Boolean moto) {
Boolean moto, Boolean live, Source source) {

this(null, gatewayAccountId, amount, reference, description, state, language, externalId, returnUrl, email,
paymentProvider, createdDate, cardDetails, delayedCapture, externalMetaData, eventCount,
gatewayTransactionId, corporateCardSurcharge, fee, netAmount, totalAmount, refundSummary, settlementSummary, moto);
gatewayTransactionId, corporateCardSurcharge, fee, netAmount, totalAmount, refundSummary,
settlementSummary, moto, live, source);
}

@Override
Expand Down Expand Up @@ -184,4 +190,12 @@ public Long getTotalAmount() {
public SettlementSummary getSettlementSummary() {
return settlementSummary;
}

public Boolean isLive() {
return live;
}

public Source getSource() {
return source;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ private Transaction createPayment(TransactionEntity entity) {
refundSummary,
entity.getTotalAmount(),
settlementSummary,
entity.isMoto()
entity.isMoto(),
entity.isLive(),
entity.getSource()
);
} catch (IOException e) {
LOGGER.error("Error during the parsing transaction entity data [{}] [errorMessage={}]", entity.getExternalId(), e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import uk.gov.pay.commons.api.json.ApiResponseDateTimeSerializer;
import uk.gov.pay.commons.model.Source;
import uk.gov.pay.ledger.transaction.model.CardDetails;
import uk.gov.pay.ledger.transaction.model.Payment;
import uk.gov.pay.ledger.transaction.model.Refund;
Expand Down Expand Up @@ -54,6 +55,8 @@ public class TransactionView {
private TransactionType transactionType;
private TransactionView parentTransaction;
private Boolean moto;
private Boolean live;
private Source source;

public TransactionView(Builder builder) {
this.id = builder.id;
Expand Down Expand Up @@ -84,6 +87,8 @@ public TransactionView(Builder builder) {
this.transactionType = builder.transactionType;
this.parentTransaction = builder.parentTransaction;
this.moto = builder.moto;
this.live = builder.live;
this.source = builder.source;
}

public TransactionView() {
Expand Down Expand Up @@ -119,6 +124,8 @@ public static TransactionView from(Transaction transaction, int statusVersion) {
.withTransactionType(payment.getTransactionType())
.withGatewayTransactionId(payment.getGatewayTransactionId())
.withMoto(payment.getMoto())
.withLive(payment.isLive())
.withSource(payment.getSource())
.build();
}

Expand Down Expand Up @@ -267,6 +274,14 @@ public TransactionView getParentTransaction() {
return parentTransaction;
}

public Boolean getLive() {
return live;
}

public Source getSource() {
return source;
}

public static class Builder {
private TransactionView parentTransaction;
private Long id;
Expand Down Expand Up @@ -297,6 +312,8 @@ public static class Builder {
private TransactionType transactionType;
private List<Link> links = new ArrayList<>();
private Boolean moto;
private Boolean live;
private Source source;

public Builder() {
}
Expand Down Expand Up @@ -444,5 +461,15 @@ public Builder withMoto(Boolean moto) {
this.moto = moto;
return this;
}

public Builder withLive(Boolean live) {
this.live = live;
return this;
}

public Builder withSource(Source source) {
this.source = source;
return this;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import uk.gov.pay.commons.model.Source;
import uk.gov.pay.ledger.event.model.Event;
import uk.gov.pay.ledger.metadatakey.dao.MetadataKeyDao;
import uk.gov.pay.ledger.rule.AppWithPostgresAndSqsRule;
Expand Down Expand Up @@ -66,7 +67,9 @@ public void shouldGetTransaction() {

transactionFixture = aTransactionFixture()
.withDefaultCardDetails()
.withDefaultTransactionDetails();
.withDefaultTransactionDetails()
.withLive(Boolean.TRUE)
.withSource(String.valueOf(Source.CARD_API));
transactionFixture.insert(rule.getJdbi());

given().port(port)
Expand All @@ -79,7 +82,9 @@ public void shouldGetTransaction() {
.body("card_details.cardholder_name", is(transactionFixture.getCardDetails().getCardHolderName()))
.body("card_details.expiry_date", is(transactionFixture.getCardDetails().getExpiryDate()))
.body("card_details.card_type", is(transactionFixture.getCardDetails().getCardType().toString().toLowerCase()))
.body("card_details.billing_address.line1", is(transactionFixture.getCardDetails().getBillingAddress().getAddressLine1()));
.body("card_details.billing_address.line1", is(transactionFixture.getCardDetails().getBillingAddress().getAddressLine1()))
.body("live", is(Boolean.TRUE))
.body("source", is(String.valueOf(Source.CARD_API)));
}

@Test
Expand Down Expand Up @@ -715,6 +720,32 @@ public void shouldGetAllTransactionsAsCSVWithAcceptType() throws IOException {
assertHealthyCsvResponse(csvResponseStream, transactionFixture);
}

@Test
public void returnedTransactionsShould_haveCorrectSourceAndLive() {
TransactionFixture cancelledTransaction1 = aTransactionFixture()
.withDefaultCardDetails()
.withGatewayAccountId("123")
.withDefaultTransactionDetails()
.withSource(String.valueOf(Source.CARD_API))
.withLive(Boolean.TRUE)
.withState(TransactionState.FAILED_CANCELLED)
.insert(rule.getJdbi());

given().port(port)
.contentType(JSON)
.accept(JSON)
.get("/v1/transaction" +
"?account_id=123" +
"&state=cancelled"
)
.then()
.statusCode(Response.Status.OK.getStatusCode())
.contentType(JSON)
.body("page", is(1))
.body("results[0].live", is(Boolean.TRUE))
.body("results[0].source", is(String.valueOf(Source.CARD_API)));
}

@Test
public void shouldReturnCSVHeadersInCorrectOrder() throws IOException {
String targetGatewayAccountId = "123";
Expand Down

0 comments on commit 2aedc19

Please sign in to comment.