@Test
 public void testDeleteCustomer() {
   Customer c1 = getNewCustomerWithUniqueName();
   Customer c1FromDb = getCustomerComponent().getById(c1.getId());
   getCustomerComponent().delete(c1FromDb);
   Customer c1FromDbAgain = getCustomerComponent().getById(c1.getId());
   assertNull(c1FromDbAgain);
 }
  @Test
  public void testCustomerInsertAndGet() {
    Customer c1 = getNewCustomerWithUniqueName();
    Customer c2 = getNewCustomerWithUniqueName();

    assertEquals(c1.getId() + 1, c2.getId());

    Customer c1FromDb = getCustomerComponent().getById(c1.getId());
    assertEquals(c1.getName(), c1FromDb.getName());
  }
 @Test
 public void testCustomerUpdateAndGet() {
   Customer c1 = getNewCustomerWithUniqueName();
   Customer c1FromDb = getCustomerComponent().getById(c1.getId());
   String NEW_PHONE = "415-555-1212";
   c1FromDb.setPhoneNumber(NEW_PHONE);
   getCustomerComponent().persist(c1FromDb);
   Customer c1FromDbAgain = getCustomerComponent().getById(c1.getId());
   assertEquals(NEW_PHONE, c1FromDbAgain.getPhoneNumber());
 }
  @Test
  public void updateCreditCardFromTransparentRedirect() {
    Customer customer = gateway.customer().create(new CustomerRequest()).getTarget();
    CreditCardRequest request =
        new CreditCardRequest()
            .customerId(customer.getId())
            .number("5105105105105100")
            .expirationDate("05/12");
    CreditCard card = gateway.creditCard().create(request).getTarget();

    CreditCardRequest updateRequest = new CreditCardRequest();
    CreditCardRequest trParams =
        new CreditCardRequest()
            .paymentMethodToken(card.getToken())
            .number("4111111111111111")
            .expirationDate("10/10");
    String queryString =
        TestHelper.simulateFormPostForTR(
            gateway, trParams, updateRequest, gateway.transparentRedirect().url());

    Result<CreditCard> result = gateway.transparentRedirect().confirmCreditCard(queryString);

    assertTrue(result.isSuccess());
    CreditCard updatedCreditCard = gateway.creditCard().find(card.getToken());
    assertEquals("411111", updatedCreditCard.getBin());
    assertEquals("1111", updatedCreditCard.getLast4());
    assertEquals("10/2010", updatedCreditCard.getExpirationDate());
  }
예제 #5
0
  @Test
  public void onCustomer() {
    Result<Customer> customerResult =
        gateway.customer().create(new CustomerRequest().paymentMethodNonce(Nonce.Coinbase));
    assertTrue(customerResult.isSuccess());
    Customer customer = customerResult.getTarget();

    List<CoinbaseAccount> accounts =
        gateway.customer().find(customer.getId()).getCoinbaseAccounts();
    assertEquals(1, accounts.size());

    CoinbaseAccount account = accounts.get(0);
    assertNotNull(account);
    assertNotNull(account.getToken());
    assertNotNull(account.getUserId());
    assertThat(account.getUserId(), not(equalTo("")));
    assertNotNull(account.getUserName());
    assertThat(account.getUserName(), not(equalTo("")));
    assertNotNull(account.getUserEmail());
    assertThat(account.getUserEmail(), not(equalTo("")));

    String token = account.getToken();

    gateway.paymentMethod().delete(token);

    exception.expect(NotFoundException.class);
    gateway.paymentMethod().find(token);
  }
  @Test
  public void updateCustomerFromTransparentRedirect() {
    CustomerRequest request = new CustomerRequest().firstName("John").lastName("Doe");
    Customer customer = gateway.customer().create(request).getTarget();

    CustomerRequest updateRequest = new CustomerRequest().firstName("Jane");
    CustomerRequest trParams = new CustomerRequest().customerId(customer.getId()).lastName("Dough");
    String queryString =
        TestHelper.simulateFormPostForTR(
            gateway, trParams, updateRequest, gateway.transparentRedirect().url());

    Result<Customer> result = gateway.transparentRedirect().confirmCustomer(queryString);

    assertTrue(result.isSuccess());
    Customer updatedCustomer = gateway.customer().find(customer.getId());
    assertEquals("Jane", updatedCustomer.getFirstName());
    assertEquals("Dough", updatedCustomer.getLastName());
  }
예제 #7
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 case to show that automatically generated ids are assigned to the domain objects. */
  @Test
  public void setsIdOnSave() {

    Customer dave = repository.save(new Customer("Dave", "Matthews"));
    assertThat(dave.getId(), is(notNullValue()));
  }