Skip to content

Commit 84c91b5

Browse files
authored
Removed CreditCardFund (#150)
- removed CreditCardFund class - Account for VCR on credit card test - Fix VCR environmental variables
1 parent 689e98d commit 84c91b5

File tree

4 files changed

+16
-54
lines changed

4 files changed

+16
-54
lines changed

src/main/java/com/easypost/model/CreditCard.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class CreditCard extends BaseCreditCard {
1515
* @return CreditCardFund object.
1616
* @throws EasyPostException when the request fails.
1717
*/
18-
public static CreditCardFund fund(String amount, CreditCardPriority primaryOrSecondary) throws EasyPostException {
18+
public static boolean fund(String amount, CreditCardPriority primaryOrSecondary) throws EasyPostException {
1919
return fund(amount, primaryOrSecondary, null);
2020
}
2121

@@ -28,7 +28,7 @@ public static CreditCardFund fund(String amount, CreditCardPriority primaryOrSec
2828
* @return CreditCardFund object.
2929
* @throws EasyPostException when the request fails.
3030
*/
31-
public static CreditCardFund fund(String amount, CreditCardPriority primaryOrSecondary, String apiKey)
31+
public static boolean fund(String amount, CreditCardPriority primaryOrSecondary, String apiKey)
3232
throws EasyPostException {
3333
PaymentMethod paymentMethods = PaymentMethod.all();
3434
String cardID = null;
@@ -44,16 +44,18 @@ public static CreditCardFund fund(String amount, CreditCardPriority primaryOrSec
4444
break;
4545
}
4646

47-
if (cardID == null || cardID.isEmpty() || !cardID.startsWith("card_")) {
47+
if (cardID == null || !cardID.startsWith("card_")) {
4848
throw new EasyPostException("The chosen payment method is not a credit card. Please try again.");
4949
}
5050

5151
Map<String, Object> params = new HashMap<String, Object>();
5252
params.put("amount", amount);
5353

54-
return request(RequestMethod.POST,
55-
String.format("%s/%s/%s/%s", EasyPost.API_BASE, "credit_cards", cardID, "charges"), params,
56-
CreditCardFund.class, apiKey);
54+
// will attempt to serialize the empty response to a CreditCard object (doesn't matter)
55+
request(RequestMethod.POST, String.format("%s/%s/%s/%s", EasyPost.API_BASE, "credit_cards", cardID, "charges"),
56+
params, CreditCard.class, apiKey);
57+
58+
return true;
5759
}
5860

5961
/**

src/main/java/com/easypost/model/CreditCardFund.java

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/test/java/com/easypost/CreditCardTest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.easypost.exception.EasyPostException;
44
import com.easypost.model.CreditCard;
5-
import com.easypost.model.CreditCardFund;
65
import com.easypost.model.CreditCardPriority;
76
import org.junit.jupiter.api.BeforeAll;
87
import org.junit.jupiter.api.Disabled;
@@ -11,14 +10,16 @@
1110
import static org.junit.jupiter.api.Assertions.assertTrue;
1211

1312
public final class CreditCardTest {
13+
private static TestUtils.VCR vcr;
14+
1415
/**
1516
* Setup the testing environment for this file.
1617
*
1718
* @throws EasyPostException when the request fails.
1819
*/
1920
@BeforeAll
2021
public static void setup() throws EasyPostException {
21-
EasyPost.apiKey = System.getenv("EASYPOST_PROD_API_KEY");
22+
vcr = new TestUtils.VCR("credit_card", TestUtils.ApiKey.PRODUCTION);
2223
}
2324

2425
/**
@@ -29,9 +30,8 @@ public static void setup() throws EasyPostException {
2930
@Test
3031
@Disabled // Skipping due to the lack of an available real credit card in tests
3132
public void testFund() throws EasyPostException {
32-
CreditCardFund creditCardFund = CreditCard.fund("20", CreditCardPriority.PRIMARY);
33-
34-
assertTrue(creditCardFund != null);
33+
vcr.setUpTest("fund");
34+
assertTrue(CreditCard.fund("2000", CreditCardPriority.PRIMARY));
3535
}
3636

3737
/**
@@ -42,6 +42,7 @@ public void testFund() throws EasyPostException {
4242
@Test
4343
@Disabled // Skipping due to the lack of an available real credit card in tests
4444
public void testDelete() throws EasyPostException {
45+
vcr.setUpTest("delete");
4546
CreditCard.delete("card_123");
4647
}
4748
}

src/test/java/com/easypost/TestUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,9 @@ public static String getApiKey(ApiKey apiKey) {
7878
}
7979

8080
String value = System.getenv(keyName);
81-
return value != null ? value :
81+
value = (value != null && !value.isEmpty()) ? value :
8282
API_KEY_FAILED_TO_PULL; // if can't pull from environment, will use a fake key. Won't matter on replay.
83+
return value;
8384
}
8485

8586
public static final class VCR {

0 commit comments

Comments
 (0)