Search in sources :

Example 21 with Device

use of com.fitpay.android.api.models.device.Device in project fitpay-android-sdk by fitpay.

the class CommitTest2 method testCanConfirmCommits.

@Test
public void testCanConfirmCommits() 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);
    assertTrue("number of commits should be 2 or more.  Got: " + commits.getTotalResults(), commits.getTotalResults() >= 2);
    for (Commit commit : commits.getResults()) {
        final CountDownLatch latch = new CountDownLatch(1);
        if (commit.canConfirmCommit()) {
            CommitConfirm confirm = new CommitConfirm(ResponseState.SUCCESS);
            commit.confirm(confirm, new ApiCallback<Void>() {

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

                @Override
                public void onFailure(@ResultCode.Code int errorCode, String errorMessage) {
                    fail("commit confirm failed");
                }
            });
        } else {
        // TODO: uncomment out once the paltform supports this feature fully
        // if (!commit.getCommitType().equals(CommitTypes.APDU_PACKAGE)) {
        // fail("expected confirm link on commit: " + commit);
        // }
        }
        latch.await(5000, TimeUnit.MILLISECONDS);
    }
}
Also used : Device(com.fitpay.android.api.models.device.Device) CountDownLatch(java.util.concurrent.CountDownLatch) CreditCard(com.fitpay.android.api.models.card.CreditCard) Commit(com.fitpay.android.api.models.device.Commit) CommitConfirm(com.fitpay.android.api.models.device.CommitConfirm) Collections(com.fitpay.android.api.models.collection.Collections) Test(org.junit.Test)

Example 22 with Device

use of com.fitpay.android.api.models.device.Device in project fitpay-android-sdk by fitpay.

the class CommitTest2 method testCanGetLofOfCommits.

@Test
public void testCanGetLofOfCommits() 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());
    CreditCard[] creditCardArray = new CreditCard[8];
    String panBase = "99995044545454";
    int count = 0;
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 4; j++) {
            String pan = panBase + i + j;
            CreditCard creditCard = getTestCreditCard(pan);
            CreditCard createdCard = createCreditCard(user, creditCard);
            assertNotNull("card not created", createdCard);
            creditCardArray[count] = acceptTerms(createdCard);
            count++;
        }
    }
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < count; j++) {
            if (creditCardArray[j].canMakeDefault()) {
                makeDefaultCard(creditCardArray[j]);
            }
        }
    }
    // wait for all commits
    final int correctResult = 39;
    int totalResults = 0;
    for (int i = 0; i < 3; i++) {
        Collections.CommitsCollection commits = getAllCommits(createdDevice, null);
        assertNotNull(commits);
        assertTrue("number of commits should be 10 or more.  Got: " + commits.getTotalResults(), commits.getTotalResults() >= 10);
        totalResults = commits.getTotalResults();
    }
    assertEquals("number of commits should be 39.  Got: " + totalResults, totalResults, correctResult);
}
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 23 with Device

use of com.fitpay.android.api.models.device.Device in project fitpay-android-sdk by fitpay.

the class CommitTest2 method testCanGetCommitsAfter.

@Test
public void testCanGetCommitsAfter() 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: " + commits.getTotalResults(), commits.getTotalResults() >= 2);
    for (Commit commit : commits.getResults()) {
        Collections.CommitsCollection lastCommits = getCommits(createdDevice, commit.getCommitId());
        assertEquals("number of commits with lastId", --totalResults, lastCommits.getTotalResults());
    }
}
Also used : Commit(com.fitpay.android.api.models.device.Commit) 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 24 with Device

use of com.fitpay.android.api.models.device.Device in project fitpay-android-sdk by fitpay.

the class WebViewCommunicatorImpl method getUserAndDevice.

private void getUserAndDevice(final String deviceId, final String callbackId) {
    ApiManager.getInstance().getUser(new ApiCallback<User>() {

        @Override
        public void onSuccess(User result) {
            if (result == null) {
                onTaskError(EventCallback.USER_CREATED, callbackId, "getUser failed: result is null");
                return;
            }
            WebViewCommunicatorImpl.this.user = result;
            RxBus.getInstance().post(new UserReceived(user.getId(), user.getUsername()));
            EventCallback eventCallback = new EventCallback.Builder().setCommand(EventCallback.USER_CREATED).setStatus(EventCallback.STATUS_OK).build();
            eventCallback.send();
            result.getDevice(deviceId, new ApiCallback<Device>() {

                @Override
                public void onSuccess(Device result) {
                    WebViewCommunicatorImpl.this.device = result;
                    String token = ApiManager.getPushToken();
                    String deviceToken = device.getNotificationToken();
                    final Runnable onSuccess = () -> onTaskSuccess(EventCallback.GET_USER_AND_DEVICE, callbackId);
                    boolean automaticallySubscribeToUserEventStream = true;
                    if (ApiManager.getConfig().containsKey(ApiManager.PROPERTY_AUTOMATICALLY_SUBSCRIBE_TO_USER_EVENT_STREAM)) {
                        automaticallySubscribeToUserEventStream = "true".equals(ApiManager.getConfig().get(ApiManager.PROPERTY_AUTOMATICALLY_SUBSCRIBE_TO_USER_EVENT_STREAM));
                    }
                    if (automaticallySubscribeToUserEventStream) {
                        try {
                            UserEventStreamManager.subscribe(user.getId());
                        } catch (IOException e) {
                            FPLog.e(e);
                        }
                        boolean automaticSyncThroughUserEventStream = true;
                        if (ApiManager.getConfig().containsKey(ApiManager.PROPERTY_AUTOMATICALLY_SYNC_FROM_USER_EVENT_STREAM)) {
                            automaticSyncThroughUserEventStream = "true".equals(ApiManager.getConfig().get(ApiManager.PROPERTY_AUTOMATICALLY_SYNC_FROM_USER_EVENT_STREAM));
                        }
                        if (automaticSyncThroughUserEventStream) {
                            userEventStreamSyncListener = new UserEventStreamListener() {

                                @Override
                                public void onUserEvent(UserStreamEvent event) {
                                    if ("SYNC".equals(event.getType())) {
                                        SyncInfo syncInfo = gson.fromJson(event.getPayload(), SyncInfo.class);
                                        syncInfo.setInitiator(SyncInitiator.PLATFORM);
                                        SyncRequest syncRequest = new SyncRequest.Builder().setSyncId(syncInfo.getSyncId()).setSyncInfo(syncInfo).setConnector(deviceService.getPaymentDeviceConnector()).setDevice(device).setUser(user).build();
                                        RxBus.getInstance().post(syncRequest);
                                    }
                                }
                            };
                            NotificationManager.getInstance().addListener(userEventStreamSyncListener);
                        }
                    }
                    if (deviceToken == null || !deviceToken.equals(token)) {
                        Device updatedDevice = new Device.Builder().setNotificationToken(token).build();
                        device.updateToken(updatedDevice, deviceToken == null, new ApiCallback<Device>() {

                            @Override
                            public void onSuccess(Device result) {
                                WebViewCommunicatorImpl.this.device = result;
                                onSuccess.run();
                            }

                            @Override
                            public void onFailure(@ResultCode.Code int errorCode, String errorMessage) {
                                onTaskError(EventCallback.GET_USER_AND_DEVICE, callbackId, "update device failed:" + errorMessage);
                            }
                        });
                    } else {
                        onSuccess.run();
                    }
                }

                @Override
                public void onFailure(@ResultCode.Code int errorCode, String errorMessage) {
                    onTaskError(EventCallback.GET_USER_AND_DEVICE, callbackId, "getDevice failed " + errorMessage);
                }
            });
        }

        @Override
        public void onFailure(@ResultCode.Code int errorCode, String errorMessage) {
            onTaskError(EventCallback.USER_CREATED, callbackId, "getUser failed " + errorMessage);
        }
    });
}
Also used : User(com.fitpay.android.api.models.user.User) ApiCallback(com.fitpay.android.api.callbacks.ApiCallback) Device(com.fitpay.android.api.models.device.Device) UserStreamEvent(com.fitpay.android.api.models.UserStreamEvent) UserEventStreamListener(com.fitpay.android.api.sse.UserEventStreamListener) EventCallback(com.fitpay.android.utils.EventCallback) IOException(java.io.IOException) SyncRequest(com.fitpay.android.paymentdevice.models.SyncRequest) NotificationSyncRequest(com.fitpay.android.paymentdevice.events.NotificationSyncRequest) SyncInfo(com.fitpay.android.paymentdevice.models.SyncInfo) UserReceived(com.fitpay.android.webview.events.UserReceived)

Example 25 with Device

use of com.fitpay.android.api.models.device.Device in project fitpay-android-sdk by fitpay.

the class WebViewCommunicatorTest method setup.

@Before
public void setup() throws Exception {
    userName = TestUtils.getRandomLengthString(5, 10) + "@" + TestUtils.getRandomLengthString(5, 10) + "." + TestUtils.getRandomLengthString(4, 10);
    pin = TestUtils.getRandomLengthNumber(4, 4);
    UserCreateRequest user = getNewTestUser(userName, pin);
    User createdUser = createUser(user);
    assertNotNull("user should have been created", createdUser);
    loginIdentity = getTestLoginIdentity(userName, pin);
    doLogin(loginIdentity);
    this.user = getUser();
    assertNotNull(user);
    Device device = getTestDevice();
    Device createdDevice = createDevice(this.user, device);
    assertNotNull("device", createdDevice);
}
Also used : User(com.fitpay.android.api.models.user.User) Device(com.fitpay.android.api.models.device.Device) UserCreateRequest(com.fitpay.android.api.models.user.UserCreateRequest) Before(org.junit.Before)

Aggregations

Device (com.fitpay.android.api.models.device.Device)39 Test (org.junit.Test)28 Collections (com.fitpay.android.api.models.collection.Collections)22 CreditCard (com.fitpay.android.api.models.card.CreditCard)19 CountDownLatch (java.util.concurrent.CountDownLatch)15 PaymentDevice (com.fitpay.android.api.models.device.PaymentDevice)9 ResultProvidingCallback (com.fitpay.android.api.callbacks.ResultProvidingCallback)8 Commit (com.fitpay.android.api.models.device.Commit)3 ApiCallback (com.fitpay.android.api.callbacks.ApiCallback)2 UserStreamEvent (com.fitpay.android.api.models.UserStreamEvent)2 User (com.fitpay.android.api.models.user.User)2 UserEventStreamListener (com.fitpay.android.api.sse.UserEventStreamListener)2 SyncRequest (com.fitpay.android.paymentdevice.models.SyncRequest)2 Activity (android.app.Activity)1 Image (android.media.Image)1 ApiManager (com.fitpay.android.api.ApiManager)1 SyncInitiator (com.fitpay.android.api.enums.SyncInitiator)1 Transaction (com.fitpay.android.api.models.Transaction)1 Reason (com.fitpay.android.api.models.card.Reason)1 VerificationMethod (com.fitpay.android.api.models.card.VerificationMethod)1