コード例 #1
0
  /**
   * Test Case to Create Single Use Token with Missing Card Expiry Year Field.
   *
   * @throws Exception
   */
  public void testMissingCardExpiryYear() throws Exception {

    client = new OptimalApiClient(apiKey, apiPassword, Environment.TEST, accountNumber);

    try {
      SingleUseToken sObjResponse =
          client
              .customerVaultService()
              .createSingleUseToken(
                  SingleUseToken.builder()
                      .card()
                      .holderName("Mr. John Smith")
                      .cardNum("4917480000000008")
                      .cardExpiry()
                      .month(7)
                      .done()
                      .billingAddress()
                      .street("100 Queen Street West")
                      .street2("Unit 201")
                      .city("Toronto")
                      .country("CA")
                      .state("ON")
                      .zip("M5H 2N2")
                      .done()
                      .done()
                      .build());

      Assert.assertEquals("5068", sObjResponse.getError().getCode());
      Assert.assertEquals(
          "card.cardExpiry.year", sObjResponse.getError().getFieldErrors().get(0).getField());
      Assert.assertEquals(
          "must be greater than or equal to 1900",
          sObjResponse.getError().getFieldErrors().get(0).getError());
      Assert.assertEquals("cardExpiry", sObjResponse.getError().getFieldErrors().get(1).getField());
      Assert.assertEquals(
          "Card expired", sObjResponse.getError().getFieldErrors().get(1).getError());

    } catch (IOException ioExp) {
      // Log IO Exception
      if (Constants.TAG_LOG) Log.e(LOG_APPLICATION_TEST, ioExp.getMessage());
    } catch (OptimalException oExp) {
      // Log Optimal Exception
      if (Constants.TAG_LOG) Log.e(LOG_APPLICATION_TEST, oExp.getMessage());
    } catch (Exception e) {
      // Log Exception
      if (Constants.TAG_LOG) Log.e(LOG_APPLICATION_TEST, e.getMessage());
    }
  } // end of testMissingCardExpiryYear()
コード例 #2
0
  /**
   * Test Case to Create Single Use Token With All Fields.
   *
   * @throws Exception
   */
  public void testCreateSingleUseToken() throws Exception {

    client = new OptimalApiClient(apiKey, apiPassword, Environment.TEST, accountNumber);

    try {
      SingleUseToken sObjResponse =
          client
              .customerVaultService()
              .createSingleUseToken(
                  SingleUseToken.builder()
                      .card()
                      .holderName("Mr. John Smith")
                      .cardNum("4917480000000008")
                      .cardExpiry()
                      .month(7)
                      .year(2019)
                      .done()
                      .billingAddress()
                      .street("100 Queen Street West")
                      .street2("Unit 201")
                      .city("Toronto")
                      .country("CA")
                      .state("ON")
                      .zip("M5H 2N2")
                      .done()
                      .done()
                      .build());

      Assert.assertNotNull("Single Use Token should have an id", sObjResponse.getId());

    } catch (IOException ioExp) {
      // Log IO Exception
      if (Constants.TAG_LOG) Log.e(LOG_APPLICATION_TEST, ioExp.getMessage());
    } catch (OptimalException oExp) {
      // Log Optimal Exception
      if (Constants.TAG_LOG) Log.e(LOG_APPLICATION_TEST, oExp.getMessage());
    } catch (Exception e) {
      // Log Exception
      if (Constants.TAG_LOG) Log.e(LOG_APPLICATION_TEST, e.getMessage());
    }
  } // end of testCreateSingleUseToken()
コード例 #3
0
  /**
   * Test Case to Create Single Use Token with Missing Billing Address Details.
   *
   * @throws Exception
   */
  public void testMissingBillingAddressDetails() throws Exception {

    client = new OptimalApiClient(apiKey, apiPassword, Environment.TEST, accountNumber);

    try {
      SingleUseToken sObjResponse =
          client
              .customerVaultService()
              .createSingleUseToken(
                  SingleUseToken.builder()
                      .card()
                      .holderName("Mr. John Smith")
                      .cardNum("4917480000000008")
                      .cardExpiry()
                      .month(7)
                      .year(2019)
                      .done()
                      .done()
                      .build());

      Assert.assertEquals("5068", sObjResponse.getError().getCode());
      Assert.assertEquals(
          "card.billingAddress", sObjResponse.getError().getFieldErrors().get(0).getField());
      Assert.assertEquals(
          "Missing billing address details",
          sObjResponse.getError().getFieldErrors().get(0).getError());

    } catch (IOException ioExp) {
      // Log IO Exception
      if (Constants.TAG_LOG) Log.e(LOG_APPLICATION_TEST, ioExp.getMessage());
    } catch (OptimalException oExp) {
      // Log Optimal Exception
      if (Constants.TAG_LOG) Log.e(LOG_APPLICATION_TEST, oExp.getMessage());
    } catch (Exception e) {
      // Log Exception
      if (Constants.TAG_LOG) Log.e(LOG_APPLICATION_TEST, e.getMessage());
    }
  } // end of testMissingBillingAddressDetails()