Search in sources :

Example 6 with CreditCard

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

the class CreditCardTest2 method testCanAcceptTerms.

@Test
public void testCanAcceptTerms() 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 = "9999545454545454";
    CreditCard creditCard = getTestCreditCard(pan);
    CreditCard createdCard = createCreditCard(user, creditCard);
    assertNotNull("card not created", createdCard);
    assertEquals("card not in expected state", "ELIGIBLE", createdCard.getState());
    createdCard = acceptTerms(createdCard);
    assertNotNull("card not successfully updated by accept terms", createdCard);
    assertEquals("card state", "PENDING_VERIFICATION", createdCard.getState());
}
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 7 with CreditCard

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

the class CreditCardTest2 method testCanAddCreditCard.

@Test
public void testCanAddCreditCard() 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);
    verifyCardContents(creditCard, createdCard);
    final CountDownLatch latch = new CountDownLatch(1);
    ResultProvidingCallback<Image> callback = new ResultProvidingCallback<>(latch);
    createdCard.getCardMetaData().getBrandLogo().get(0).self(callback);
    latch.await(TIMEOUT, TimeUnit.SECONDS);
// TODO enable test for image retrieval
// assertEquals(-1, callback.getErrorCode());
}
Also used : ResultProvidingCallback(com.fitpay.android.api.callbacks.ResultProvidingCallback) Device(com.fitpay.android.api.models.device.Device) Collections(com.fitpay.android.api.models.collection.Collections) CountDownLatch(java.util.concurrent.CountDownLatch) Image(android.media.Image) CreditCard(com.fitpay.android.api.models.card.CreditCard) Test(org.junit.Test)

Example 8 with CreditCard

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

the class Steps method acceptTerms.

public void acceptTerms() throws InterruptedException {
    getDevices();
    Assert.assertNotNull(currentUser);
    Assert.assertNotNull(currentCard);
    Assert.assertNotNull(currentDevice);
    final CountDownLatch latch = new CountDownLatch(2);
    final boolean[] isRequestSuccess = { false };
    ApiManager.getInstance().createRelationship(currentUser.getId(), currentCard.getCreditCardId(), currentDevice.getDeviceIdentifier(), new ApiCallback<Relationship>() {

        @Override
        public void onSuccess(Relationship result) {
            latch.countDown();
        }

        @Override
        public void onFailure(@ResultCode.Code int errorCode, String errorMessage) {
            latch.countDown();
        }
    });
    latch.await(TIMEOUT, TimeUnit.SECONDS);
    currentCard.acceptTerms(new ApiCallback<CreditCard>() {

        @Override
        public void onSuccess(CreditCard result) {
            isRequestSuccess[0] = true;
            currentCard = result;
            latch.countDown();
        }

        @Override
        public void onFailure(@ResultCode.Code int errorCode, String errorMessage) {
            latch.countDown();
        }
    });
    latch.await(TIMEOUT, TimeUnit.SECONDS);
    Assert.assertNotNull(currentCard);
    Assert.assertTrue(isRequestSuccess[0]);
    Assert.assertEquals("PENDING_VERIFICATION", currentCard.getState());
}
Also used : Relationship(com.fitpay.android.api.models.Relationship) CountDownLatch(java.util.concurrent.CountDownLatch) CreditCard(com.fitpay.android.api.models.card.CreditCard)

Example 9 with CreditCard

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

the class Steps method createCard.

public void createCard(String pan) throws InterruptedException {
    Assert.assertNotNull(currentUser);
    String cardName = "TEST CARD";
    int expYear = 2018;
    int expMonth = 10;
    String city = "Boulder";
    String state = "CO";
    String postalCode = "80302";
    String countryCode = "US";
    String street1 = "1035 Pearl St";
    String cvv = "133";
    Address address = new Address();
    address.setCity(city);
    address.setState(state);
    address.setPostalCode(postalCode);
    address.setCountryCode(countryCode);
    address.setStreet1(street1);
    CreditCard creditCard = new CreditCard.Builder().setCVV(cvv).setPAN(pan).setExpDate(expYear, expMonth).setAddress(address).setName(cardName).build();
    final BlockingQueue<CreditCard> cards = new ArrayBlockingQueue<>(1);
    currentUser.createCreditCard(creditCard, new ApiCallback<CreditCard>() {

        @Override
        public void onSuccess(CreditCard result) {
            cards.add(result);
        }

        @Override
        public void onFailure(@ResultCode.Code int errorCode, String errorMessage) {
            fail(errorMessage);
        }
    });
    CreditCard card = cards.poll(TIMEOUT, TimeUnit.SECONDS);
    Assert.assertNotNull(card);
    Assert.assertEquals(cardName, card.getName());
    Assert.assertEquals(city, card.getAddress().getCity());
    Assert.assertEquals(state, card.getAddress().getState());
    Assert.assertEquals(postalCode, card.getAddress().getPostalCode());
    Assert.assertEquals(countryCode, card.getAddress().getCountryCode());
    Assert.assertEquals(street1, card.getAddress().getStreet1());
    Assert.assertNotNull(card.getCVV());
    Assert.assertEquals(card.getPan().substring(12), pan.substring(12));
    Assert.assertTrue(expYear == card.getExpYear());
    Assert.assertTrue(expMonth == card.getExpMonth());
    Assert.assertEquals("ELIGIBLE", card.getState());
    currentCard = card;
}
Also used : Address(com.fitpay.android.api.models.card.Address) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) CreditCard(com.fitpay.android.api.models.card.CreditCard)

Example 10 with CreditCard

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

the class Steps method reactivateCard.

public void reactivateCard() throws InterruptedException {
    Assert.assertNotNull(currentCard);
    final CountDownLatch latch = new CountDownLatch(1);
    final boolean[] isRequestSuccess = { false };
    final List<String> errors = new ArrayList<>();
    Reason reason = new Reason();
    reason.setReason("found");
    reason.setCausedBy(CardInitiators.INITIATOR_CARDHOLDER);
    currentCard.reactivate(reason, new ApiCallback<CreditCard>() {

        @Override
        public void onSuccess(CreditCard result) {
            isRequestSuccess[0] = true;
            currentCard = result;
            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);
    Assert.assertTrue("failed reactivate request: " + errors, isRequestSuccess[0]);
    Assert.assertNotNull(currentCard);
}
Also used : ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) Reason(com.fitpay.android.api.models.card.Reason) 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