Skip to content

Commit

Permalink
Added bin metadata endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Silviana Ghita committed Jan 29, 2024
1 parent 7fd2928 commit ca142f2
Show file tree
Hide file tree
Showing 7 changed files with 220 additions and 16 deletions.
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 @@ -100,6 +100,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;
}
}
135 changes: 135 additions & 0 deletions src/main/java/com/mangopay/entities/PaymentMethodMetadata.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
package com.mangopay.entities;

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

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 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 BinData[] getBinData() {
return binData;
}

public void setBinData(BinData[] binData) {
this.binData = binData;
}
}
2 changes: 1 addition & 1 deletion src/main/resources/com/mangopay/core/mangopay.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#Tue Dec 05 17:19:57 EET 2023
#Mon Jan 29 22:37:41 EET 2024
version=2.34.0
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 @@ -696,11 +717,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 @@ -1013,11 +1034,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 @@ -1027,11 +1048,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

0 comments on commit ca142f2

Please sign in to comment.