Search in sources :

Example 6 with Device

use of com.fitpay.android.api.models.device.Device 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 Device

use of com.fitpay.android.api.models.device.Device 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 Device

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

the class Steps method selfDevice.

public void selfDevice() throws InterruptedException {
    Assert.assertNotNull(currentDevice);
    final CountDownLatch latch = new CountDownLatch(1);
    final boolean[] isRequestSuccess = { false };
    currentDevice.self(new ApiCallback<Device>() {

        @Override
        public void onSuccess(Device result) {
            isRequestSuccess[0] = true;
            currentDevice = 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(currentDevice);
}
Also used : PaymentDevice(com.fitpay.android.api.models.device.PaymentDevice) Device(com.fitpay.android.api.models.device.Device) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 9 with Device

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

the class Steps method createDevice.

public void createDevice() throws InterruptedException {
    Assert.assertNotNull(currentUser);
    final CountDownLatch latch = new CountDownLatch(1);
    String manufacturerName = "X111";
    String deviceName = "TEST_DEVICE";
    String firmwareRevision = "111.111";
    String hardwareRevision = "1.1.1";
    String modelNumber = "AB111";
    String serialNumber = "1111AB";
    String softwareRevision = "1.1.1";
    String systemId = "0x111AA";
    String oSName = "A1111";
    String licenseKey = "aaaaaa-1111-1111-1111-111111111111";
    String bdAddress = "bbbbbb-1111-1111-1111-111111111111";
    long pairingTs = System.currentTimeMillis();
    String stringTimestamp = TimestampUtils.getISO8601StringForTime(pairingTs);
    Device newDevice = new Device.Builder().setDeviceType(DeviceTypes.ACTIVITY_TRACKER).setManufacturerName(manufacturerName).setDeviceName(deviceName).setFirmwareRevision(firmwareRevision).setHardwareRevision(hardwareRevision).setModelNumber(modelNumber).setSerialNumber(serialNumber).setSoftwareRevision(softwareRevision).setSystemId(systemId).setOSName(oSName).setLicenseKey(licenseKey).setBdAddress(bdAddress).setPairingTs(pairingTs).setSecureElement(new PaymentDevice.SecureElement(SecureElementDataProvider.generateCasd(), SecureElementDataProvider.generateRandomSecureElementId())).build();
    final String[] errors = { "" };
    final int[] errorCodes = { -1 };
    currentUser.createDevice(newDevice, new ApiCallback<Device>() {

        @Override
        public void onSuccess(Device result) {
            currentDevice = result;
            latch.countDown();
        }

        @Override
        public void onFailure(@ResultCode.Code int errorCode, String errorMessage) {
            errors[0] = errorMessage;
            errorCodes[0] = errorCode;
            latch.countDown();
        }
    });
    latch.await(TIMEOUT, TimeUnit.SECONDS);
    assertEquals("build device had an error.  (Message: " + errors[0] + ")", -1, errorCodes[0]);
    Assert.assertNotNull(currentDevice);
    Assert.assertEquals(manufacturerName, currentDevice.getManufacturerName());
    Assert.assertEquals(deviceName, currentDevice.getDeviceName());
    Assert.assertEquals(firmwareRevision, currentDevice.getFirmwareRevision());
    Assert.assertEquals(hardwareRevision, currentDevice.getHardwareRevision());
    Assert.assertEquals(modelNumber, currentDevice.getModelNumber());
    Assert.assertEquals(serialNumber, currentDevice.getSerialNumber());
    Assert.assertEquals(softwareRevision, currentDevice.getSoftwareRevision());
    Assert.assertEquals(systemId, currentDevice.getSystemId());
    Assert.assertEquals(oSName, currentDevice.getOsName());
    if (DeviceTypes.SMART_STRAP.equals(currentDevice.getDeviceType())) {
        // todo check
        Assert.assertEquals(licenseKey, currentDevice.getLicenseKey());
        Assert.assertEquals(bdAddress, currentDevice.getBdAddress());
    }
    Assert.assertEquals(stringTimestamp, currentDevice.getPairingTs());
    Assert.assertEquals(newDevice.getSecureElementId(), currentDevice.getSecureElementId());
}
Also used : PaymentDevice(com.fitpay.android.api.models.device.PaymentDevice) Device(com.fitpay.android.api.models.device.Device) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 10 with Device

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

the class UserEventStreamSyncTest method testWebviewCommunicatorUsesUserEventStream.

@Test
public void testWebviewCommunicatorUsesUserEventStream() throws Exception {
    // setup a user and device
    this.user = getUser();
    assertNotNull(user);
    Device device = createDevice(user, getTestDevice());
    Activity context = Mockito.mock(Activity.class);
    DeviceService deviceService = new DeviceService();
    deviceService.setPaymentDeviceConnector(new MockPaymentDeviceConnector());
    // pretend to launch the webview and act like the user has logged into the WV, this should
    // cause the user event stream subscription to occur
    WebViewCommunicatorImpl wvc = new WebViewCommunicatorImpl(context, -1);
    wvc.setDeviceService(deviceService);
    wvc.sendUserData(null, device.getDeviceIdentifier(), ApiManager.getInstance().getApiService().getToken().getAccessToken(), user.getId());
    boolean subscribed = false;
    for (int i = 0; i < 10; i++) {
        subscribed = UserEventStreamManager.isSubscribed(user.getId());
        if (!subscribed) {
            Thread.sleep(500);
        }
    }
    assertTrue(UserEventStreamManager.isSubscribed(user.getId()));
    // now let's get the platform to initiate a SYNC by adding a card, the automatic sync
    // from user event stream is enabled by default, therefore we should see a sync requeset
    // come out onto the RxBus
    final CountDownLatch syncLatch = new CountDownLatch(1);
    final List<SyncRequest> syncRequests = new ArrayList<>();
    NotificationManager.getInstance().addListener(new Listener() {

        @Override
        public Map<Class, Command> getCommands() {
            mCommands.put(SyncRequest.class, data -> handleSyncRequest((SyncRequest) data));
            return mCommands;
        }

        public void handleSyncRequest(SyncRequest request) {
            syncRequests.add(request);
            syncLatch.countDown();
        }
    });
    CreditCard createdCard = createCreditCard(user, getTestCreditCard("9999504454545450"));
    final CountDownLatch latch = new CountDownLatch(1);
    createdCard.acceptTerms(new ApiCallback<CreditCard>() {

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

        @Override
        public void onFailure(int errorCode, String errorMessage) {
            latch.countDown();
        }
    });
    syncLatch.await(30000, TimeUnit.MILLISECONDS);
    assertTrue(syncRequests.size() > 0);
    SyncRequest syncRequest = syncRequests.get(0);
    assertNotNull(syncRequest.getSyncId());
    assertNotNull(syncRequest.getSyncInfo());
    assertEquals(user.getId(), syncRequest.getSyncInfo().getUserId());
    assertEquals(device.getDeviceIdentifier(), syncRequest.getSyncInfo().getDeviceId());
    assertEquals(SyncInitiator.PLATFORM, syncRequest.getSyncInfo().getInitiator());
    assertEquals(syncRequest.getSyncId(), syncRequest.getSyncInfo().getSyncId());
    assertEquals(ApiManager.getConfig().get("clientId"), syncRequest.getSyncInfo().getClientId());
    assertNotNull(syncRequest.getConnector());
    assertNotNull(syncRequest.getDevice());
    assertEquals(device.getDeviceIdentifier(), syncRequest.getDevice().getDeviceIdentifier());
    assertNotNull(syncRequest.getUser());
    assertEquals(user.getId(), syncRequest.getUser().getId());
    // now let's close the webview and ensure the subscription is removed
    wvc.close();
    assertFalse(UserEventStreamManager.isSubscribed(user.getId()));
}
Also used : Assert.assertEquals(junit.framework.Assert.assertEquals) UserEventStreamManager(com.fitpay.android.api.sse.UserEventStreamManager) WebViewCommunicatorImpl(com.fitpay.android.webview.impl.WebViewCommunicatorImpl) NotificationManager(com.fitpay.android.utils.NotificationManager) ArrayList(java.util.ArrayList) Assert.assertTrue(junit.framework.Assert.assertTrue) UserStreamEvent(com.fitpay.android.api.models.UserStreamEvent) ApiCallback(com.fitpay.android.api.callbacks.ApiCallback) CreditCard(com.fitpay.android.api.models.card.CreditCard) MockPaymentDeviceConnector(com.fitpay.android.paymentdevice.impl.mock.MockPaymentDeviceConnector) Assert.assertNotNull(junit.framework.Assert.assertNotNull) ApiManager(com.fitpay.android.api.ApiManager) DeviceService(com.fitpay.android.paymentdevice.DeviceService) Map(java.util.Map) UserEventStreamListener(com.fitpay.android.api.sse.UserEventStreamListener) Listener(com.fitpay.android.utils.Listener) SyncRequest(com.fitpay.android.paymentdevice.models.SyncRequest) Test(org.junit.Test) Device(com.fitpay.android.api.models.device.Device) TimeUnit(java.util.concurrent.TimeUnit) Mockito(org.mockito.Mockito) CountDownLatch(java.util.concurrent.CountDownLatch) Command(com.fitpay.android.utils.Command) List(java.util.List) SyncInitiator(com.fitpay.android.api.enums.SyncInitiator) Activity(android.app.Activity) Assert.assertFalse(junit.framework.Assert.assertFalse) UserEventStreamListener(com.fitpay.android.api.sse.UserEventStreamListener) Listener(com.fitpay.android.utils.Listener) Device(com.fitpay.android.api.models.device.Device) DeviceService(com.fitpay.android.paymentdevice.DeviceService) MockPaymentDeviceConnector(com.fitpay.android.paymentdevice.impl.mock.MockPaymentDeviceConnector) ArrayList(java.util.ArrayList) Activity(android.app.Activity) CountDownLatch(java.util.concurrent.CountDownLatch) CreditCard(com.fitpay.android.api.models.card.CreditCard) WebViewCommunicatorImpl(com.fitpay.android.webview.impl.WebViewCommunicatorImpl) SyncRequest(com.fitpay.android.paymentdevice.models.SyncRequest) Map(java.util.Map) Test(org.junit.Test)

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