Search in sources :

Example 1 with VerificationMethod

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

the class CreditCardTest2 method testCanVerifyAndDeactivate.

@Test
public void testCanVerifyAndDeactivate() 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 decline terms", createdCard);
    assertEquals("card state", "PENDING_VERIFICATION", createdCard.getState());
    assertTrue("no verification methods", createdCard.getVerificationMethods().size() > 0);
    assertEquals("verification state", "AVAILABLE_FOR_SELECTION", createdCard.getVerificationMethods().get(0).getState());
    VerificationMethod method = selectVerificationMethod(createdCard.getVerificationMethods().get(0));
    assertEquals("verification state after selection", "AWAITING_VERIFICATION", method.getState());
    CreditCard retrievedCard = getCreditCard(createdCard);
    assertEquals("number of verification methods", createdCard.getVerificationMethods().size(), retrievedCard.getVerificationMethods().size());
    VerificationMethod selectedMethod = null;
    for (VerificationMethod m : retrievedCard.getVerificationMethods()) {
        if (m.getMethodType().equals(method.getMethodType()) && m.getState().equals("AWAITING_VERIFICATION")) {
            selectedMethod = m;
            break;
        }
    }
    assertNotNull("No selected method found", selectedMethod);
    selectedMethod = verifyVerificationMethod(selectedMethod, "12345");
    assertEquals("post verification state", "VERIFIED", selectedMethod.getState());
    retrievedCard = waitForActivation(retrievedCard);
    assertEquals("post verification card state", "ACTIVE", retrievedCard.getState());
    Reason reason = new Reason();
    reason.setCausedBy(CardInitiators.INITIATOR_CARDHOLDER);
    reason.setReason("tired of racking up miles");
    retrievedCard = deactivateCard(retrievedCard, reason);
    assertEquals("post deactivation card state", "DEACTIVATED", retrievedCard.getState());
    retrievedCard = getCreditCard(retrievedCard);
    assertEquals("post deactivation card state", "DEACTIVATED", retrievedCard.getState());
    retrievedCard = reactivateCard(retrievedCard, reason);
    assertEquals("post verification card state", "ACTIVE", retrievedCard.getState());
    retrievedCard = getCreditCard(retrievedCard);
    assertEquals("post reactivation card state", "ACTIVE", retrievedCard.getState());
}
Also used : Device(com.fitpay.android.api.models.device.Device) VerificationMethod(com.fitpay.android.api.models.card.VerificationMethod) Collections(com.fitpay.android.api.models.collection.Collections) CreditCard(com.fitpay.android.api.models.card.CreditCard) Reason(com.fitpay.android.api.models.card.Reason) Test(org.junit.Test)

Example 2 with VerificationMethod

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

the class Steps method selectCard.

public void selectCard() throws InterruptedException {
    Assert.assertNotNull(currentCard);
    final CountDownLatch latch = new CountDownLatch(1);
    final VerificationMethod[] verificationMethods = { null };
    final boolean[] isRequestSuccess = { false };
    currentCard.getVerificationMethods().get(0).select(new ApiCallback<VerificationMethod>() {

        @Override
        public void onSuccess(VerificationMethod result) {
            isRequestSuccess[0] = true;
            verificationMethods[0] = 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("AWAITING_VERIFICATION", verificationMethods[0].getState());
}
Also used : VerificationMethod(com.fitpay.android.api.models.card.VerificationMethod) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 3 with VerificationMethod

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

the class TestActions method selectVerificationMethod.

protected VerificationMethod selectVerificationMethod(VerificationMethod method) throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    ResultProvidingCallback<VerificationMethod> callback = new ResultProvidingCallback<>(latch);
    method.select(callback);
    latch.await(TIMEOUT, TimeUnit.SECONDS);
    return callback.getResult();
}
Also used : ResultProvidingCallback(com.fitpay.android.api.callbacks.ResultProvidingCallback) VerificationMethod(com.fitpay.android.api.models.card.VerificationMethod) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 4 with VerificationMethod

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

the class TestActions method verifyVerificationMethod.

protected VerificationMethod verifyVerificationMethod(VerificationMethod method, String verificationCode) throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    ResultProvidingCallback<VerificationMethod> callback = new ResultProvidingCallback<>(latch);
    method.verify(verificationCode, callback);
    latch.await(TIMEOUT, TimeUnit.SECONDS);
    return callback.getResult();
}
Also used : ResultProvidingCallback(com.fitpay.android.api.callbacks.ResultProvidingCallback) VerificationMethod(com.fitpay.android.api.models.card.VerificationMethod) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 5 with VerificationMethod

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

the class Steps method verifyCard.

public void verifyCard() throws InterruptedException {
    Assert.assertNotNull(currentCard);
    final CountDownLatch latch = new CountDownLatch(1);
    final VerificationMethod[] verificationMethods = { null };
    final boolean[] isRequestSuccess = { false };
    currentCard.getVerificationMethods().get(0).verify("12345", new ApiCallback<VerificationMethod>() {

        @Override
        public void onSuccess(VerificationMethod result) {
            isRequestSuccess[0] = true;
            verificationMethods[0] = 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.assertTrue("VERIFIED".equals(verificationMethods[0].getState()) || "AWAITING_VERIFICATION".equals(verificationMethods[0].getState()));
}
Also used : VerificationMethod(com.fitpay.android.api.models.card.VerificationMethod) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

VerificationMethod (com.fitpay.android.api.models.card.VerificationMethod)5 CountDownLatch (java.util.concurrent.CountDownLatch)4 ResultProvidingCallback (com.fitpay.android.api.callbacks.ResultProvidingCallback)2 CreditCard (com.fitpay.android.api.models.card.CreditCard)1 Reason (com.fitpay.android.api.models.card.Reason)1 Collections (com.fitpay.android.api.models.collection.Collections)1 Device (com.fitpay.android.api.models.device.Device)1 Test (org.junit.Test)1