Exemplo n.º 1
0
  private static String generatePayPalNonce(BraintreeGateway gateway, QueryString payload) {
    String encodedClientToken = gateway.clientToken().generate();
    String clientToken = TestHelper.decodeClientToken(encodedClientToken);

    String authorizationFingerprint = extractParamFromJson("authorizationFingerprint", clientToken);
    Configuration configuration = gateway.getConfiguration();
    String url =
        configuration.getBaseURL()
            + configuration.getMerchantPath()
            + "/client_api/v1/payment_methods/paypal_accounts";

    payload
        .append("authorization_fingerprint", authorizationFingerprint)
        .append("shared_customer_identifier_type", "testing")
        .append("shared_customer_identifier", "test-identifier")
        .append("paypal_account[options][validate]", "false");

    String responseBody;
    String nonce = "";
    try {
      responseBody = HttpHelper.post(url, payload.toString());
      nonce = extractParamFromJson("nonce", responseBody);
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
    return nonce;
  }
Exemplo n.º 2
0
  public static String generateNonceForCreditCard(
      BraintreeGateway gateway,
      CreditCardRequest creditCardRequest,
      String customerId,
      boolean validate) {
    ClientTokenRequest clientTokenRequest = new ClientTokenRequest().customerId(customerId);

    String encodedClientToken = gateway.clientToken().generate(clientTokenRequest);
    String clientToken = TestHelper.decodeClientToken(encodedClientToken);

    String authorizationFingerprint = extractParamFromJson("authorizationFingerprint", clientToken);
    Configuration configuration = gateway.getConfiguration();
    String url =
        configuration.getBaseURL()
            + configuration.getMerchantPath()
            + "/client_api/v1/payment_methods/credit_cards";
    QueryString payload = new QueryString();
    payload
        .append("authorization_fingerprint", authorizationFingerprint)
        .append("shared_customer_identifier_type", "testing")
        .append("shared_customer_identifier", "fake_identifier")
        .append("credit_card[options][validate]", new Boolean(validate).toString());

    String responseBody;
    String nonce = "";
    try {
      String payloadString = payload.toString();
      payloadString += "&" + creditCardRequest.toQueryString();
      responseBody = HttpHelper.post(url, payloadString);
      nonce = extractParamFromJson("nonce", responseBody);
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
    return nonce;
  }
Exemplo n.º 3
0
  public static String generateUnlockedNonce(
      BraintreeGateway gateway, String customerId, String creditCardNumber) {
    ClientTokenRequest request = new ClientTokenRequest();
    if (customerId != null) {
      request = request.customerId(customerId);
    }
    String encodedClientToken = gateway.clientToken().generate(request);
    String clientToken = TestHelper.decodeClientToken(encodedClientToken);

    String authorizationFingerprint = extractParamFromJson("authorizationFingerprint", clientToken);
    Configuration configuration = gateway.getConfiguration();
    String url =
        configuration.getBaseURL() + configuration.getMerchantPath() + "/client_api/nonces.json";
    QueryString payload = new QueryString();
    payload
        .append("authorization_fingerprint", authorizationFingerprint)
        .append("shared_customer_identifier_type", "testing")
        .append("shared_customer_identifier", "test-identifier")
        .append("credit_card[number]", creditCardNumber)
        .append("credit_card[expiration_month]", "11")
        .append("share", "true")
        .append("credit_card[expiration_year]", "2099");

    String responseBody;
    String nonce = "";
    try {
      responseBody = HttpHelper.post(url, payload.toString());
      nonce = extractParamFromJson("nonce", responseBody);
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
    return nonce;
  }
Exemplo n.º 4
0
  /**
   * Test that the constructor reads the system property and set the htmlOutputDirectory correctly.
   */
  @Test
  public void htmlOutputDirectoryConfiguration() {
    Configuration configuration = new Configuration();
    assertTrue(
        configuration.getHtmlOutputDirectory().endsWith(Configuration.DEFAULT_HTML_OUTPUT_DIR));

    System.setProperty(Configuration.PROPERTY_HTML_OUTPUT_DIR, TEST_OUTPUT_DIR_PATH);
    configuration = new Configuration();
    assertTrue(configuration.getHtmlOutputDirectory().endsWith(TEST_OUTPUT_DIR_PATH));
    Properties sysProps = System.getProperties();
    sysProps.remove(Configuration.PROPERTY_HTML_OUTPUT_DIR);
  }
 @Test(expected = DownForMaintenanceException.class)
 public void downForMaintenanceExceptionRaisedWhenAppInMaintenanceModeUsingNewTR() {
   CustomerRequest request = new CustomerRequest();
   CustomerRequest trParams = new CustomerRequest();
   Configuration configuration = gateway.getConfiguration();
   String queryString =
       TestHelper.simulateFormPostForTR(
           gateway,
           trParams,
           request,
           configuration.getBaseURL() + configuration.getMerchantPath() + "/test/maintenance");
   gateway.transparentRedirect().confirmCustomer(queryString);
 }
 @Test
 public void testXMLencdec() throws IOException {
   Configuration c = new Configuration();
   String m = c.getXMLRepresentationAsString();
   Configuration o = Configuration.makeXMLStringAsConfiguration(m);
   assertNotNull(o);
   m = m.replace('a', 'm');
   try {
     o = Configuration.makeXMLStringAsConfiguration(m);
     fail("makeXmlStringsAsConfiguration should throw exception");
   } catch (Throwable t) {
   }
 }
Exemplo n.º 7
0
  @Test
  public void testApiClient() {
    // the default api client is used
    assertEquals(Configuration.getDefaultApiClient(), api.getApiClient());
    assertNotNull(api.getApiClient());
    assertEquals("http://petstore.swagger.io/v2", api.getApiClient().getBasePath());
    assertFalse(api.getApiClient().isDebugging());

    ApiClient oldClient = api.getApiClient();

    ApiClient newClient = new ApiClient();
    newClient.setBasePath("http://example.com");
    newClient.setDebugging(true);

    // set api client via constructor
    api = new PetApi(newClient);
    assertNotNull(api.getApiClient());
    assertEquals("http://example.com", api.getApiClient().getBasePath());
    assertTrue(api.getApiClient().isDebugging());

    // set api client via setter method
    api.setApiClient(oldClient);
    assertNotNull(api.getApiClient());
    assertEquals("http://petstore.swagger.io/v2", api.getApiClient().getBasePath());
    assertFalse(api.getApiClient().isDebugging());
  }
Exemplo n.º 8
0
  public static String generateEuropeBankAccountNonce(BraintreeGateway gateway, Customer customer) {
    SEPAClientTokenRequest request = new SEPAClientTokenRequest();
    request.customerId(customer.getId());
    request.mandateType(EuropeBankAccount.MandateType.BUSINESS);
    request.mandateAcceptanceLocation("Rostock, Germany");

    String encodedClientToken = gateway.clientToken().generate(request);
    String clientToken = TestHelper.decodeClientToken(encodedClientToken);

    String authorizationFingerprint = extractParamFromJson("authorizationFingerprint", clientToken);
    Configuration configuration = gateway.getConfiguration();
    String url =
        configuration.getBaseURL()
            + configuration.getMerchantPath()
            + "/client_api/v1/sepa_mandates";
    QueryString payload = new QueryString();
    payload
        .append("authorization_fingerprint", authorizationFingerprint)
        .append("sepa_mandate[locale]", "de-DE")
        .append("sepa_mandate[bic]", "DEUTDEFF")
        .append("sepa_mandate[iban]", "DE89370400440532013000")
        .append("sepa_mandate[accountHolderName]", "Bob Holder")
        .append("sepa_mandate[billingAddress][streetAddress]", "123 Currywurst Way")
        .append("sepa_mandate[billingAddress][extendedAddress]", "Lager Suite")
        .append("sepa_mandate[billingAddress][firstName]", "Wilhelm")
        .append("sepa_mandate[billingAddress][lastName]", "Dix")
        .append("sepa_mandate[billingAddress][locality]", "Frankfurt")
        .append("sepa_mandate[billingAddress][postalCode]", "60001")
        .append("sepa_mandate[billingAddress][countryCodeAlpha2]", "DE")
        .append("sepa_mandate[billingAddress][region]", "Hesse");

    String responseBody;
    String nonce = "";
    try {
      responseBody = HttpHelper.post(url, payload.toString());
      nonce = extractParamFromJson("nonce", responseBody);
    } catch (Exception e) {
      throw new RuntimeException(e);
    }

    return nonce;
  }
  @Test
  public void testParsingCommandLineArguments() {

    String[] args = {"-f", "hello.txt", "-v", "--version"};
    Configuration c = new Configuration();
    c.processArguments(args);

    assertEquals("hello.txt", c.getFileName());
    assertFalse(c.isDebuggingEnabled());
    assertFalse(c.isWarningsEnabled());
    assertTrue(c.isVerbose());
    assertTrue(c.shouldShowVersion());

    c = new Configuration();
    try {
      c.processArguments(new String[] {"-f"});
      fail("Should have failed");
    } catch (InvalidArgumentException e) {
      // expected
    }
  }
Exemplo n.º 10
0
 public static void assertValidTrData(Configuration configuration, String trData) {
   String[] dataSections = trData.split("\\|");
   String trHash = dataSections[0];
   String trContent = dataSections[1];
   assertEquals(trHash, new Sha1Hasher().hmacHash(configuration.getPrivateKey(), trContent));
 }