Skip to content
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

feature/ Added bin metadata endpoint #320

Merged
merged 3 commits into from
Feb 6, 2024
Merged
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
1 change: 1 addition & 0 deletions src/main/java/com/mangopay/core/APIs/ApiBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ protected MangoPayApi getRoot() {
put("payins_ideal-web_create", new String[]{"/payins/payment-methods/ideal", RequestType.POST.toString()});
put("payins_giropay-web_create", new String[]{"/payins/payment-methods/giropay", RequestType.POST.toString()});

put("payment_method-metadata", new String[]{"/payment-methods/metadata", RequestType.POST.toString()});

put("payouts_bankwire_create", new String[]{"/payouts/bankwire/", RequestType.POST.toString()});
put("payouts_bankwire_get", new String[]{"/payouts/bankwire/%s", RequestType.GET.toString()});
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/mangopay/core/APIs/PayInApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,12 @@ public interface PayInApi {
* @throws Exception
*/
PayIn createPayPal(PayIn payIn) throws Exception;

/**
* Look up metadata from BIN or Google Pay token
* @param metadata The PaymentMethodMetadata post object
* @return PaymentMethodMetadata object returned by API.
* @throws Exception
*/
PaymentMethodMetadata getPaymentMethodMetadata(PaymentMethodMetadata metadata) throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,9 @@ private String getExecutionKey(PayIn payIn) throws Exception {
public PayIn createPayPal(PayIn payIn) throws Exception {
return this.createObject(PayIn.class, null, "payins_paypal-web_create_v2", payIn);
}

@Override
public PaymentMethodMetadata getPaymentMethodMetadata(PaymentMethodMetadata metadata) throws Exception {
return this.createObject(PaymentMethodMetadata.class, null, "payment_method-metadata", metadata);
}
}
34 changes: 34 additions & 0 deletions src/main/java/com/mangopay/entities/BinData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.mangopay.entities;

import com.google.gson.annotations.SerializedName;

public class BinData {

/**
* The subtype of the card product. Examples include: CLASSIC, GOLD, PLATINUM, PREPAID, etc.
*/
@SerializedName("SubType")
private String subType;

/**
* The card brand. Examples include: AMERICAN EXPRESS, DISCOVER, JCB, MASTERCARD, VISA, etc.
*/
@SerializedName("Brand")
private String brand;

public String getSubType() {
return subType;
}

public void setSubType(String subType) {
this.subType = subType;
}

public String getBrand() {
return brand;
}

public void setBrand(String brand) {
this.brand = brand;
}
}
137 changes: 137 additions & 0 deletions src/main/java/com/mangopay/entities/PaymentMethodMetadata.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package com.mangopay.entities;

import com.google.gson.annotations.SerializedName;
import com.mangopay.core.EntityBase;

import java.util.List;

public class PaymentMethodMetadata extends EntityBase {

/**
* The type of metadata. Allowed values: BIN, GOOGLE_PAY
*/
@SerializedName("Type")
private String type;

/**
* The bank identification number (BIN). (Format: 6 or 8 digits)
*/
@SerializedName("Bin")
private String bin;

/**
* The tokenized payment data provided by the third-party payment method.
*/
@SerializedName("Token")
private String token;

/**
* In the case of Google Pay, the format of the Token.
* PAN_ONLY – The card is registered in the Google account and requires 3DS authentication.
* CRYPTOGRAM_3DS – The card is enrolled in the customer’s Google Wallet and authentication is handled by the Android device.
*/
@SerializedName("TokenFormat")
private String tokenFormat;

/**
* The type of the card. Allowed / Returned / Default values: CREDIT, DEBIT, CHARGE CARD
*/
@SerializedName("CardType")
private String cardType;

/**
* The country where the card was issued. Format: ISO-3166 alpha-2 two-letter country code
*/
@SerializedName("IssuerCountryCode")
private String issuerCountryCode;

/**
* The name of the card issuer.
*/
@SerializedName("IssuingBank")
private String issuingBank;

/**
* Whether the card is held in a personal or commercial capacity.
*/
@SerializedName("CommercialIndicator")
private String commercialIndicator;

/**
* Additional data about the card based on the BIN. In the case of co-branded card products, two objects are returned.
*/
@SerializedName("BinData")
private List<BinData> binData;

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public String getBin() {
return bin;
}

public void setBin(String bin) {
this.bin = bin;
}

public String getToken() {
return token;
}

public void setToken(String token) {
this.token = token;
}

public String getTokenFormat() {
return tokenFormat;
}

public void setTokenFormat(String tokenFormat) {
this.tokenFormat = tokenFormat;
}

public String getCardType() {
return cardType;
}

public void setCardType(String cardType) {
this.cardType = cardType;
}

public String getIssuerCountryCode() {
return issuerCountryCode;
}

public void setIssuerCountryCode(String issuerCountryCode) {
this.issuerCountryCode = issuerCountryCode;
}

public String getIssuingBank() {
return issuingBank;
}

public void setIssuingBank(String issuingBank) {
this.issuingBank = issuingBank;
}

public String getCommercialIndicator() {
return commercialIndicator;
}

public void setCommercialIndicator(String commercialIndicator) {
this.commercialIndicator = commercialIndicator;
}

public List<BinData> getBinData() {
return binData;
}

public void setBinData(List<BinData> binData) {
this.binData = binData;
}
}
51 changes: 36 additions & 15 deletions src/test/java/com/mangopay/core/PayInApiImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,27 @@ public void getCardDirect() {
}
}

@Test
public void cardDirectGetPaymentMethodsMetadata() {
try {
PayIn payIn = this.getNewPayInCardDirect();

PaymentMethodMetadata paymentMethodMetadata = new PaymentMethodMetadata();
paymentMethodMetadata.setType("BIN");
paymentMethodMetadata.setBin(((PayInPaymentDetailsCard) payIn.getPaymentDetails()).getCardInfo().getBin());

PaymentMethodMetadata resultMetadata = this.api.getPayInApi().getPaymentMethodMetadata(paymentMethodMetadata);
assertTrue(resultMetadata.getBin().equals(paymentMethodMetadata.getBin()));
assertNotNull(resultMetadata.getIssuerCountryCode());
assertNotNull(resultMetadata.getIssuingBank());
assertNotNull(resultMetadata.getBinData());
assertNotNull(resultMetadata.getCardType());

} catch (Exception ex) {
fail(ex.getMessage());
}
}

@Test
public void createRefundCardDirect() {
try {
Expand Down Expand Up @@ -698,11 +719,11 @@ public void testDirectPayInCheckCardInfo() {
try {
PayIn payIn = this.getNewPayInCardDirect();

assertNotNull(((PayInPaymentDetailsCard)payIn.getPaymentDetails()).getCardInfo());
assertNotNull(((PayInPaymentDetailsCard)payIn.getPaymentDetails()).getCardInfo().getBrand());
assertNotNull(((PayInPaymentDetailsCard)payIn.getPaymentDetails()).getCardInfo().getType());
assertNotNull(((PayInPaymentDetailsCard)payIn.getPaymentDetails()).getCardInfo().getIssuingBank());
assertNotNull(((PayInPaymentDetailsCard)payIn.getPaymentDetails()).getCardInfo().getBin());
assertNotNull(((PayInPaymentDetailsCard) payIn.getPaymentDetails()).getCardInfo());
assertNotNull(((PayInPaymentDetailsCard) payIn.getPaymentDetails()).getCardInfo().getBrand());
assertNotNull(((PayInPaymentDetailsCard) payIn.getPaymentDetails()).getCardInfo().getType());
assertNotNull(((PayInPaymentDetailsCard) payIn.getPaymentDetails()).getCardInfo().getIssuingBank());
assertNotNull(((PayInPaymentDetailsCard) payIn.getPaymentDetails()).getCardInfo().getBin());
} catch (Exception e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -1015,11 +1036,11 @@ public void testCreateRecurringPaymentMITCheckCardInfo() {
cit.setDebitedFunds(new Money().setAmount(11).setCurrency(CurrencyIso.EUR));
RecurringPayIn createdCit = this.api.getPayInApi().createRecurringPayInCIT(null, cit);

assertNotNull(((PayInPaymentDetailsCard)createdCit.getPaymentDetails()).getCardInfo());
assertNotNull(((PayInPaymentDetailsCard)createdCit.getPaymentDetails()).getCardInfo().getBrand());
assertNotNull(((PayInPaymentDetailsCard)createdCit.getPaymentDetails()).getCardInfo().getType());
assertNotNull(((PayInPaymentDetailsCard)createdCit.getPaymentDetails()).getCardInfo().getIssuingBank());
assertNotNull(((PayInPaymentDetailsCard)createdCit.getPaymentDetails()).getCardInfo().getBin());
assertNotNull(((PayInPaymentDetailsCard) createdCit.getPaymentDetails()).getCardInfo());
assertNotNull(((PayInPaymentDetailsCard) createdCit.getPaymentDetails()).getCardInfo().getBrand());
assertNotNull(((PayInPaymentDetailsCard) createdCit.getPaymentDetails()).getCardInfo().getType());
assertNotNull(((PayInPaymentDetailsCard) createdCit.getPaymentDetails()).getCardInfo().getIssuingBank());
assertNotNull(((PayInPaymentDetailsCard) createdCit.getPaymentDetails()).getCardInfo().getBin());

RecurringPayInMIT mit = new RecurringPayInMIT();
mit.setRecurringPayInRegistrationId(result.getId());
Expand All @@ -1029,11 +1050,11 @@ public void testCreateRecurringPaymentMITCheckCardInfo() {
mit.setTag("custom meta");
RecurringPayIn createdMit = this.api.getPayInApi().createRecurringPayInMIT(null, mit);

assertNotNull(((PayInPaymentDetailsCard)createdMit.getPaymentDetails()).getCardInfo());
assertNotNull(((PayInPaymentDetailsCard)createdMit.getPaymentDetails()).getCardInfo().getBrand());
assertNotNull(((PayInPaymentDetailsCard)createdMit.getPaymentDetails()).getCardInfo().getType());
assertNotNull(((PayInPaymentDetailsCard)createdMit.getPaymentDetails()).getCardInfo().getIssuingBank());
assertNotNull(((PayInPaymentDetailsCard)createdMit.getPaymentDetails()).getCardInfo().getBin());
assertNotNull(((PayInPaymentDetailsCard) createdMit.getPaymentDetails()).getCardInfo());
assertNotNull(((PayInPaymentDetailsCard) createdMit.getPaymentDetails()).getCardInfo().getBrand());
assertNotNull(((PayInPaymentDetailsCard) createdMit.getPaymentDetails()).getCardInfo().getType());
assertNotNull(((PayInPaymentDetailsCard) createdMit.getPaymentDetails()).getCardInfo().getIssuingBank());
assertNotNull(((PayInPaymentDetailsCard) createdMit.getPaymentDetails()).getCardInfo().getBin());
} catch (Exception e) {
fail(e.getMessage());
}
Expand Down
Loading