Search in sources :

Example 36 with CreditCard

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

the class Steps method declineTerms.

public void declineTerms() throws InterruptedException {
    Assert.assertNotNull(currentCard);
    final CountDownLatch latch = new CountDownLatch(1);
    final boolean[] isRequestSuccess = { false };
    currentCard.declineTerms(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.assertTrue(isRequestSuccess[0]);
    Assert.assertNotNull(currentCard);
    Assert.assertEquals(currentCard.getState(), "DECLINED_TERMS_AND_CONDITIONS");
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) CreditCard(com.fitpay.android.api.models.card.CreditCard)

Example 37 with CreditCard

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

the class Steps method selfCard.

public void selfCard() throws InterruptedException {
    Assert.assertNotNull(currentCard);
    TestConstants.waitSomeActionsOnServer();
    final CountDownLatch latch = new CountDownLatch(1);
    final boolean[] isRequestSuccess = { false };
    currentCard.self(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.assertTrue(isRequestSuccess[0]);
    Assert.assertNotNull(currentCard);
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) CreditCard(com.fitpay.android.api.models.card.CreditCard)

Example 38 with CreditCard

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

the class DeviceSyncManagerTest method testActionsSetup.

@Before
@Override
public void testActionsSetup() throws Exception {
    SharedPreferences sp = Mockito.mock(SharedPreferences.class);
    Mockito.when(sp.getAll()).thenReturn(Collections.emptyMap());
    Mockito.when(sp.getString(Matchers.eq("lastCommitId"), (String) Matchers.isNull())).then(new Answer<String>() {

        @Override
        public String answer(InvocationOnMock invocation) throws Throwable {
            return lastCommitId;
        }
    });
    SharedPreferences.Editor spEditor = Mockito.mock(SharedPreferences.Editor.class);
    Mockito.when(sp.edit()).thenReturn(spEditor);
    Mockito.when(spEditor.putString(Matchers.eq("lastCommitId"), Matchers.anyString())).thenAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            lastCommitId = (String) invocation.getArguments()[1];
            return spEditor;
        }
    });
    Mockito.when(spEditor.commit()).thenReturn(true);
    mContext = Mockito.mock(Context.class);
    Mockito.when(mContext.getSharedPreferences(Matchers.anyString(), Matchers.eq(Context.MODE_PRIVATE))).thenReturn(sp);
    syncManager = new DeviceSyncManager(mContext);
    syncManager.onCreate();
    syncManagerCallback = new DeviceSyncManager.DeviceSyncManagerCallback() {

        @Override
        public void syncRequestAdded(SyncRequest request) {
        }

        @Override
        public void syncTaskStarting(SyncRequest request) {
        }

        @Override
        public void syncTaskStarted(SyncRequest request) {
        }

        @Override
        public void syncTaskCompleted(SyncRequest request) {
            if (executionLatch != null) {
                executionLatch.countDown();
            }
        }
    };
    syncManager.registerDeviceSyncManagerCallback(syncManagerCallback);
    mockPaymentDevice = new MockPaymentDeviceConnector();
    userName = TestUtils.getRandomLengthString(5, 10) + "@" + TestUtils.getRandomLengthString(5, 10) + "." + TestUtils.getRandomLengthString(4, 10);
    pin = TestUtils.getRandomLengthNumber(4, 4);
    UserCreateRequest userCreateRequest = getNewTestUser(userName, pin);
    createUser(userCreateRequest);
    assertTrue(doLogin(new LoginIdentity.Builder().setPassword(pin).setUsername(userName).build()));
    this.user = getUser();
    this.device = createDevice(this.user, getTestDevice());
    assertNotNull(this.device);
    String pan = "9999504454545450";
    CreditCard creditCard = getTestCreditCard(pan);
    CreditCard createdCard = createCreditCard(user, creditCard);
    assertNotNull("card not created", createdCard);
    Properties props = new Properties();
    props.put(MockPaymentDeviceConnector.CONFIG_CONNECTED_RESPONSE_TIME, "0");
    mockPaymentDevice.init(props);
    assertEquals("payment service is not initialized", States.INITIALIZED, mockPaymentDevice.getState());
    mockPaymentDevice.connect();
    int count = 0;
    while (mockPaymentDevice.getState() != States.CONNECTED || ++count < 5) {
        Thread.sleep(500);
    }
    assertEquals("payment service should be connected", States.CONNECTED, mockPaymentDevice.getState());
    this.executionLatch = new CountDownLatch(1);
    this.listener = new SyncCompleteListener();
    NotificationManager.getInstance().addListenerToCurrentThread(this.listener);
}
Also used : Context(android.content.Context) SharedPreferences(android.content.SharedPreferences) MockPaymentDeviceConnector(com.fitpay.android.paymentdevice.impl.mock.MockPaymentDeviceConnector) Properties(java.util.Properties) CountDownLatch(java.util.concurrent.CountDownLatch) CreditCard(com.fitpay.android.api.models.card.CreditCard) SyncRequest(com.fitpay.android.paymentdevice.models.SyncRequest) InvocationOnMock(org.mockito.invocation.InvocationOnMock) LoginIdentity(com.fitpay.android.api.models.user.LoginIdentity) DeviceSyncManager(com.fitpay.android.paymentdevice.DeviceSyncManager) UserCreateRequest(com.fitpay.android.api.models.user.UserCreateRequest) Before(org.junit.Before)

Example 39 with CreditCard

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

the class CommitTest2 method testCanGetCommits.

@Test
public void testCanGetCommits() 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);
    createdCard = acceptTerms(createdCard);
    waitForActivation(createdCard);
    pan = "9999504454545451";
    creditCard = getTestCreditCard(pan);
    createdCard = createCreditCard(user, creditCard);
    assertNotNull("card not created", createdCard);
    acceptTerms(createdCard);
    Collections.CommitsCollection commits = getCommits(createdDevice, null);
    assertNotNull("commits collection", commits);
    int totalResults = commits.getTotalResults();
    assertTrue("number of commits should be 2 or more.  Got: " + totalResults, totalResults >= 2);
}
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)

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