Search in sources :

Example 31 with CreditCard

use of com.fitpay.android.api.models.card.CreditCard in project fitpay-android-sdk by fitpay.

the class CreditCardTest2 method testDeleteCard.

@Test
public void testDeleteCard() throws Exception {
    Device device = getTestDevice();
    Device createdDevice = createDevice(user, device);
    assertNotNull("created device", createdDevice);
    Collections.DeviceCollection devices = getDevices(user);
    assertNotNull("devices collection should not be null", devices);
    assertEquals("should have one device", 1, devices.getTotalResults());
    String pan = "9999504454545450";
    CreditCard creditCard = getTestCreditCard(pan);
    CreditCard createdCard = createCreditCard(user, creditCard);
    assertNotNull("card not created", createdCard);
    deleteCard(createdCard);
    Collections.CreditCardCollection creditCards = getCreditCards(user);
    assertNotNull("credit cards collection", creditCards);
    assertEquals("number of credit cards", 0, creditCards.getTotalResults());
}
Also used : Device(com.fitpay.android.api.models.device.Device) Collections(com.fitpay.android.api.models.collection.Collections) CreditCard(com.fitpay.android.api.models.card.CreditCard) Test(org.junit.Test)

Example 32 with CreditCard

use of com.fitpay.android.api.models.card.CreditCard in project fitpay-android-sdk by fitpay.

the class CreditCardTest2 method testCantAddCreditCardWithNoDevice.

@Test
public void testCantAddCreditCardWithNoDevice() throws Exception {
    String pan = "9999545454545454";
    CreditCard creditCard = getTestCreditCard(pan);
    final CountDownLatch latch = new CountDownLatch(1);
    ResultProvidingCallback<CreditCard> callback = new ResultProvidingCallback<>(latch);
    user.createCreditCard(creditCard, callback);
    latch.await(TIMEOUT, TimeUnit.SECONDS);
    CreditCard createdCard = callback.getResult();
    assertNull("created card", createdCard);
    assertEquals("error code", 400, callback.getErrorCode());
}
Also used : ResultProvidingCallback(com.fitpay.android.api.callbacks.ResultProvidingCallback) CountDownLatch(java.util.concurrent.CountDownLatch) CreditCard(com.fitpay.android.api.models.card.CreditCard) Test(org.junit.Test)

Example 33 with CreditCard

use of com.fitpay.android.api.models.card.CreditCard in project fitpay-android-sdk by fitpay.

the class CreditCardTest2 method testCanGetCards1.

@Test
public void testCanGetCards1() throws Exception {
    Device device = getTestDevice();
    Device createdDevice = createDevice(user, device);
    assertNotNull("created device", createdDevice);
    Collections.DeviceCollection devices = getDevices(user);
    assertNotNull("devices collection should not be null", devices);
    assertEquals("should have one device", 1, devices.getTotalResults());
    String pan = "9999504454545450";
    CreditCard creditCard = getTestCreditCard(pan);
    CreditCard createdCard = createCreditCard(user, creditCard);
    assertNotNull("card not created", createdCard);
    Collections.CreditCardCollection creditCards = getCreditCards(user);
    assertNotNull("credit cards collection", creditCards);
    assertEquals("number of credit cards", 1, creditCards.getTotalResults());
    assertEquals("credit card id", createdCard.getCreditCardId(), creditCards.getResults().get(0).getCreditCardId());
    verifyCardContents(creditCard, creditCards.getResults().get(0));
}
Also used : Device(com.fitpay.android.api.models.device.Device) Collections(com.fitpay.android.api.models.collection.Collections) CreditCard(com.fitpay.android.api.models.card.CreditCard) Test(org.junit.Test)

Example 34 with CreditCard

use of com.fitpay.android.api.models.card.CreditCard in project fitpay-android-sdk by fitpay.

the class Steps method waitForActivation.

public void waitForActivation() throws InterruptedException {
    Assert.assertNotNull("no currentCard is available to waitForActivation on", currentCard);
    final List<String> errors = new ArrayList<>();
    final boolean[] isCompleted = { false };
    for (int x = 0; x < 20; x++) {
        final CountDownLatch latch = new CountDownLatch(1);
        currentCard.self(new ApiCallback<CreditCard>() {

            @Override
            public void onSuccess(CreditCard result) {
                currentCard = result;
                if ("ACTIVE".equals(result.getState())) {
                    isCompleted[0] = true;
                }
                latch.countDown();
            }

            @Override
            public void onFailure(@ResultCode.Code int errorCode, String errorMessage) {
                errors.add("error code: " + errorCode + ", message: " + errorMessage);
                latch.countDown();
            }
        });
        latch.await(TIMEOUT, TimeUnit.SECONDS);
        assertTrue("error waiting on activation: " + errors, errors.size() == 0);
        if (isCompleted[0]) {
            return;
        } else {
            Thread.sleep(1000);
        }
    }
    fail(currentCard + " never transitioned to ACTIVE");
}
Also used : ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) CreditCard(com.fitpay.android.api.models.card.CreditCard)

Example 35 with CreditCard

use of com.fitpay.android.api.models.card.CreditCard in project fitpay-android-sdk by fitpay.

the class Steps method deleteTestCards.

public void deleteTestCards() throws InterruptedException {
    getCards();
    List<CreditCard> cards = cardsCollection.getResults();
    int size = cards.size();
    final CountDownLatch latch = new CountDownLatch(size);
    final int[] success = { 0 };
    int isNotTestCard = 0;
    for (int i = 0; i < size; i++) {
        CreditCard card = cards.get(i);
        if (card.getName() == null || !card.getName().equals("TEST CARD")) {
            isNotTestCard++;
            latch.countDown();
        } else {
            card.deleteCard(new ApiCallback<Void>() {

                @Override
                public void onSuccess(Void result) {
                    success[0]++;
                    latch.countDown();
                }

                @Override
                public void onFailure(@ResultCode.Code int errorCode, String errorMessage) {
                    latch.countDown();
                }
            });
        }
    }
    latch.await(TIMEOUT * size, TimeUnit.SECONDS);
    getCards();
    Assert.assertEquals(isNotTestCard, cardsCollection.getResults().size());
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) CreditCard(com.fitpay.android.api.models.card.CreditCard)

Aggregations

CreditCard (com.fitpay.android.api.models.card.CreditCard)39 Test (org.junit.Test)21 CountDownLatch (java.util.concurrent.CountDownLatch)20 Device (com.fitpay.android.api.models.device.Device)19 Collections (com.fitpay.android.api.models.collection.Collections)18 ResultProvidingCallback (com.fitpay.android.api.callbacks.ResultProvidingCallback)8 ArrayList (java.util.ArrayList)5 Address (com.fitpay.android.api.models.card.Address)3 Reason (com.fitpay.android.api.models.card.Reason)3 Commit (com.fitpay.android.api.models.device.Commit)3 UserStreamEvent (com.fitpay.android.api.models.UserStreamEvent)2 UserEventStreamListener (com.fitpay.android.api.sse.UserEventStreamListener)2 MockPaymentDeviceConnector (com.fitpay.android.paymentdevice.impl.mock.MockPaymentDeviceConnector)2 SyncRequest (com.fitpay.android.paymentdevice.models.SyncRequest)2 Activity (android.app.Activity)1 Context (android.content.Context)1 SharedPreferences (android.content.SharedPreferences)1 Image (android.media.Image)1 ApiManager (com.fitpay.android.api.ApiManager)1 ApiCallback (com.fitpay.android.api.callbacks.ApiCallback)1