use of com.fitpay.android.api.models.card.CreditCard in project fitpay-android-sdk by fitpay.
the class Steps method updateCard.
public void updateCard() throws InterruptedException {
Assert.assertNotNull(currentCard);
final CountDownLatch latch = new CountDownLatch(1);
final boolean[] isRequestSuccess = { false };
String city = "New York";
String state = "NY";
Address address = new Address();
address.setCity(city);
address.setState(state);
CreditCard creditCard = new CreditCard.Builder().setName("Hello").build();
currentCard.updateCard(creditCard, 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":[{"message":"patch request contains unsupported operations: [SecureJsonPatchOperation(op=replace, path=addresscity, value=New York), SecureJsonPatchOperation(op=replace, path=addressstate, value=NY)]"}]}
latch.countDown();
}
});
latch.await(TIMEOUT, TimeUnit.SECONDS);
Assert.assertNotNull(currentCard);
Assert.assertTrue(isRequestSuccess[0]);
Assert.assertEquals(state, currentCard.getAddress().getState());
Assert.assertEquals(city, currentCard.getAddress().getCity());
}
use of com.fitpay.android.api.models.card.CreditCard in project fitpay-android-sdk by fitpay.
the class Steps method deactivateCard.
public void deactivateCard() 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("lost");
reason.setCausedBy(CardInitiators.INITIATOR_CARDHOLDER);
currentCard.deactivate(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 deactivate request: " + errors, isRequestSuccess[0]);
Assert.assertNotNull(currentCard);
}
use of com.fitpay.android.api.models.card.CreditCard 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()));
}
use of com.fitpay.android.api.models.card.CreditCard in project fitpay-android-sdk by fitpay.
the class UserEventStreamSyncTest method testUserEventStreamSubscriptionProducesEvents.
@Test
public void testUserEventStreamSubscriptionProducesEvents() throws Exception {
this.user = getUser();
assertNotNull(user);
createDevice(user, getTestDevice());
// just to ensure events are going out, we'll just wait for the CREDITCARD_CREATED event
final CountDownLatch eventLatch = new CountDownLatch(1);
final List<UserStreamEvent> events = new ArrayList<>();
NotificationManager.getInstance().addListener(new UserEventStreamListener() {
@Override
public void onUserEvent(UserStreamEvent event) {
events.add(event);
if ("CREDITCARD_CREATED".equals(event.getType())) {
eventLatch.countDown();
}
}
});
UserEventStreamManager.subscribe(user.getId());
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();
}
});
eventLatch.await(30000, TimeUnit.MILLISECONDS);
assertTrue(events.size() > 0);
}
use of com.fitpay.android.api.models.card.CreditCard in project fitpay-android-sdk by fitpay.
the class TestActions method declineTerms.
protected CreditCard declineTerms(CreditCard creditCard) throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
ResultProvidingCallback<CreditCard> callback = new ResultProvidingCallback<>(latch);
creditCard.declineTerms(callback);
latch.await(TIMEOUT, TimeUnit.SECONDS);
return callback.getResult();
}
Aggregations