Skip to content

Improve mappings and small improvements #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ public GpApiRequest buildRequest(AuthorizationBuilder builder, GpApiConnector ga
.set("cryptogram", creditCardData.getCryptogram())
.set("eci", creditCardData.getEci())
.set("avs_address", builderBillingAddress != null ? builderBillingAddress.getStreetAddress1() : "")
.set("avs_postal_code", builderBillingAddress != null ? builderBillingAddress.getPostalCode() : "");
.set("avs_postal_code", builderBillingAddress != null ? builderBillingAddress.getPostalCode() : "")
.set("brand_reference", builder.getCardBrandTransactionId());

maskedData.putAll(
MaskValueUtil.hideValues(
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/global/api/entities/Transaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public class Transaction {
private TokenData tokenData;
@Getter @Setter
private InstallmentData installmentData;
@Getter @Setter private List<DisputeDocument> disputeDocuments;

public Customer getCustomerData() {
return customerData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,5 @@ public class TransactionSummary {
private String transactionTime;
private Card cardDetails;
private InstallmentData installmentData;
private BigDecimal merchantDiscountAmount;
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class DepositSummary {
public int refundsTotalCount;
public BigDecimal refundsTotalAmount;
public String refundsTotalCurrency;
public int discountsTotalCount;
public BigDecimal discountsTotalAmount;
public int chargebackTotalCount;
public BigDecimal chargebackTotalAmount;
public String chargebackTotalCurrency;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class DisputeSummary {
private String merchantDbaName;
private String merchantNumber;
private String merchantCategory;
private BigDecimal merchantAmount;
private Date depositDate;
private String depositReference;
private String depositType;
Expand Down
52 changes: 46 additions & 6 deletions src/main/java/com/global/api/mapping/GpApiMapping.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,10 @@
import com.global.api.entities.payFac.Person;
import com.global.api.entities.payFac.UserReference;
import com.global.api.entities.reporting.*;
import com.global.api.paymentMethods.CreditCardData;
import com.global.api.paymentMethods.Installment;
import com.global.api.paymentMethods.InstallmentData;
import com.global.api.paymentMethods.RecurringPaymentMethod;
import com.global.api.paymentMethods.eCheck;
import com.global.api.paymentMethods.*;
import com.global.api.utils.EnumUtils;
import com.global.api.utils.JsonDoc;
import com.global.api.utils.StringUtils;
import com.google.gson.JsonElement;
import lombok.var;
import org.joda.time.DateTime;

Expand Down Expand Up @@ -52,6 +47,7 @@ public class GpApiMapping {
private static final String DOCUMENT_UPLOAD = "DOCUMENT_UPLOAD";
private static final String FILE_CREATE = "FILE_CREATE";
private static final String FILE_SINGLE = "FILE_SINGLE";
private static final String DISPUTE_CHALLENGE = "CHALLENGE";

public static Transaction mapResponse(String rawResponse) throws GatewayException {
Transaction transaction = new Transaction();
Expand Down Expand Up @@ -128,6 +124,24 @@ public static Transaction mapResponse(String rawResponse) throws GatewayExceptio
case TRANSFER:
transaction.setPaymentMethodType(PaymentMethodType.AccountFunds);
break;
case DISPUTE_CHALLENGE:
if (json.has("documents")) {
List<JsonDoc> documents = json.getEnumerator("documents");

List<DisputeDocument> disputeDocuments = new ArrayList<>();
for (JsonDoc document : documents) {
if (document.getString("id") != null) {
DisputeDocument disputeDocument = new DisputeDocument();
disputeDocument.setId(document.getString("id"));
disputeDocument.setType(document.getString("type") != null ? document.getString("type") : null);

disputeDocuments.add(disputeDocument);
}
}

transaction.setDisputeDocuments(disputeDocuments);
}
break;
default:
break;
}
Expand Down Expand Up @@ -525,6 +539,10 @@ public static TransactionSummary mapTransactionSummary(JsonDoc doc) throws Gatew
summary.setInstallmentData(setInstallmentData(installment));
}

if(doc.has("merchant_discount_amount")) {
summary.setMerchantDiscountAmount(doc.getDecimal("merchant_discount_amount"));
}

summary.setFraudManagementResponse(doc.has("risk_assessment") ? mapFraudManagementReport(doc.get("risk_assessment")) : null);

return summary;
Expand Down Expand Up @@ -746,6 +764,12 @@ public static DepositSummary mapDepositSummary(JsonDoc doc) throws GatewayExcept
summary.setRefundsTotalAmount(refunds.getAmount("amount"));
}

if(doc.has("discounts")) {
JsonDoc discounts = doc.get("discounts");
summary.setDiscountsTotalCount(discounts.getInt("count"));
summary.setDiscountsTotalAmount(discounts.getAmount("amount"));
}

if (doc.has("disputes")) {
JsonDoc disputes = doc.get("disputes");

Expand Down Expand Up @@ -802,6 +826,7 @@ public static DisputeSummary mapDisputeSummary(JsonDoc doc) throws GatewayExcept
summary.setReasonCode(doc.getString("reason_code"));
summary.setReason(doc.getString("reason_description"));
summary.setResult(doc.getString("result"));
summary.setMerchantAmount(doc.getAmount("merchant_amount"));

if (doc.has("system")) {
JsonDoc system = doc.get("system");
Expand Down Expand Up @@ -842,6 +867,20 @@ public static DisputeSummary mapDisputeSummary(JsonDoc doc) throws GatewayExcept
summary.setTransactionCardType(card.getString("brand"));
summary.setTransactionBrandReference(card.getString("brand_reference"));
}
} else if(transaction.has("provider")) {
JsonDoc provider = transaction.get("provider");
if (provider.has("payment_method")) {
JsonDoc paymentMethod = provider.get("payment_method");

if (paymentMethod.has("card")) {
JsonDoc card = paymentMethod.get("card");

summary.setTransactionMaskedCardNumber(card.getString("number"));
summary.setTransactionARN(card.getString("arn"));
summary.setTransactionCardType(card.getString("brand"));
summary.setTransactionBrandReference(card.getString("brand_reference"));
}
}
}
}
String timeToRespondBy = doc.getString("time_to_respond_by");
Expand Down Expand Up @@ -875,6 +914,7 @@ public static DisputeSummary mapSettlementDisputeSummary(JsonDoc doc) throws Gat
summary.setCaseIdTime(parseGpApiDateTime(doc.getString("stage_time_created")));
summary.setDepositDate(parseGpApiDate(doc.getString("deposit_time_created")));
summary.setDepositReference(doc.getString("deposit_id"));
summary.setType(doc.getString("funding_type"));

if (doc.has("transaction")) {
JsonDoc transaction = doc.get("transaction");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public void MapTransactionSummaryTest_FromObject() throws GatewayException {
@Test
public void MapDepositSummaryTest() throws GatewayException {
// Arrange
String rawJson = "{\"id\":\"DEP_2342423423\",\"time_created\":\"2020-11-21\",\"status\":\"FUNDED\",\"funding_type\":\"CREDIT\",\"amount\":\"11400\",\"currency\":\"USD\",\"aggregation_model\":\"H-By Date\",\"bank_transfer\":{\"masked_account_number_last4\":\"XXXXXX9999\",\"bank\":{\"code\":\"XXXXX0001\"}},\"system\":{\"mid\":\"101023947262\",\"hierarchy\":\"055-70-024-011-019\",\"name\":\"XYZ LTD.\",\"dba\":\"XYZ Group\"},\"sales\":{\"count\":4,\"amount\":\"12400\"},\"refunds\":{\"count\":1,\"amount\":\"-1000\"},\"discounts\":{\"count\":0,\"amount\":\"\"},\"tax\":{\"count\":0,\"amount\":\"\"},\"disputes\":{\"chargebacks\":{\"count\":0,\"amount\":\"\"},\"reversals\":{\"count\":0,\"amount\":\"\"}},\"fees\":{\"amount\":\"\"},\"action\":{\"id\":\"ACT_TWdmMMOBZ91iQX1DcvxYermuVJ6E6h\",\"type\":\"DEPOSIT_SINGLE\",\"time_created\":\"2020-11-24T18:43:43.370Z\",\"result_code\":\"SUCCESS\",\"app_id\":\"JF2GQpeCrOivkBGsTRiqkpkdKp67Gxi0\",\"app_name\":\"test_app\"}}";
String rawJson = "{\"id\":\"DEP_2342423423\",\"time_created\":\"2020-11-21\",\"status\":\"FUNDED\",\"funding_type\":\"CREDIT\",\"amount\":\"11400\",\"currency\":\"USD\",\"aggregation_model\":\"H-By Date\",\"bank_transfer\":{\"masked_account_number_last4\":\"XXXXXX9999\",\"bank\":{\"code\":\"XXXXX0001\"}},\"system\":{\"mid\":\"101023947262\",\"hierarchy\":\"055-70-024-011-019\",\"name\":\"XYZ LTD.\",\"dba\":\"XYZ Group\"},\"sales\":{\"count\":4,\"amount\":\"12400\"},\"refunds\":{\"count\":1,\"amount\":\"-1000\"},\"discounts\":{\"count\":4,\"amount\":\"259\"},\"tax\":{\"count\":0,\"amount\":\"\"},\"disputes\":{\"chargebacks\":{\"count\":0,\"amount\":\"\"},\"reversals\":{\"count\":0,\"amount\":\"\"}},\"fees\":{\"amount\":\"\"},\"action\":{\"id\":\"ACT_TWdmMMOBZ91iQX1DcvxYermuVJ6E6h\",\"type\":\"DEPOSIT_SINGLE\",\"time_created\":\"2020-11-24T18:43:43.370Z\",\"result_code\":\"SUCCESS\",\"app_id\":\"JF2GQpeCrOivkBGsTRiqkpkdKp67Gxi0\",\"app_name\":\"test_app\"}}";

JsonDoc doc = JsonDoc.parse(rawJson);

Expand Down Expand Up @@ -172,6 +172,12 @@ public void MapDepositSummaryTest() throws GatewayException {
assertEquals(refunds.getAmount("amount"), deposit.getRefundsTotalAmount());
}

if(doc.has("discounts")) {
JsonDoc refunds = doc.get("discounts");
assertEquals((int) refunds.getInt("count"), deposit.getDiscountsTotalCount());
assertEquals(refunds.getAmount("amount"), deposit.getDiscountsTotalAmount());
}

if (doc.has("disputes")) {
JsonDoc disputes = doc.get("disputes");
if (disputes.has("chargebacks")) {
Expand Down