Skip to content

Commit

Permalink
remove prefix check for PaymentId
Browse files Browse the repository at this point in the history
  • Loading branch information
jchen293 committed Apr 10, 2024
1 parent 07bf462 commit 3946aba
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 28 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/easypost/model/PaymentMethodObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ public PaymentMethodType getType() {
return null;
}
String objectType = getObject();
if (getId().startsWith("card_") || (objectType != null && objectType.equals("CreditCard"))) {
if (objectType != null && objectType.equals("CreditCard")) {
type = PaymentMethodType.CREDIT_CARD;
} else if (getId().startsWith("bank_") || (objectType != null && objectType.equals("BankAccount"))) {
} else if (objectType != null && objectType.equals("BankAccount")) {
type = PaymentMethodType.BANK_ACCOUNT;
}
return type;
Expand Down
26 changes: 0 additions & 26 deletions src/test/java/com/easypost/BillingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,30 +139,4 @@ public void testDeterminePaymentMethodTypeByObjectType() throws EasyPostExceptio
assertEquals("BankAccount", bankAccount.getObject());
assertEquals(PaymentMethodObject.PaymentMethodType.BANK_ACCOUNT, bankAccount.getType());
}

/**
* Test determining a payment method type by its legacy prefix.
*
* @throws EasyPostException when the request fails.
*/
@Test
public void testDeterminePaymentMethodTypeByLegacyPrefix() throws EasyPostException {
requestMock.when(() -> Requestor.request(
RequestMethod.GET, "payment_methods", null, PaymentMethod.class, vcr.client))
.thenReturn(paymentMethodLegacyPrefixes);

// Should be a credit card with null object type and "card_" prefix
PaymentMethodObject creditCard =
vcr.client.billing.retrievePaymentMethods().getPrimaryPaymentMethod();
assertTrue(creditCard.getId().startsWith("card_"));
assertNull(creditCard.getObject());
assertEquals(PaymentMethodObject.PaymentMethodType.CREDIT_CARD, creditCard.getType());

// Should be a bank account with null object type and "bank_" prefix
PaymentMethodObject bankAccount =
vcr.client.billing.retrievePaymentMethods().getSecondaryPaymentMethod();
assertTrue(bankAccount.getId().startsWith("bank_"));
assertNull(bankAccount.getObject());
assertEquals(PaymentMethodObject.PaymentMethodType.BANK_ACCOUNT, bankAccount.getType());
}
}

0 comments on commit 3946aba

Please sign in to comment.