Example #1
0
 /**
  * Print information of a card
  *
  * @param c The card whose information is to be printed
  */
 public static void printCard(CreditCard c) { // Print a card's information
   System.out.println();
   System.out.println("Number = " + c.getNumber());
   System.out.println("Name = " + c.getName());
   System.out.println("Bank = " + c.getBank());
   System.out.println("Balance = " + c.getBalance()); // Implicit cast
   System.out.println("Limit = " + c.getLimit()); // Implicit cast
   System.out.println();
 }
 public static void main(String[] args) {
   CreditCard cc = new CreditCard(4388576018402625L, 12, 2013, 5675, "Mary S. Smtih");
   CreditCard cc1 = new CreditCard(4388576018410707L, 1, 2015, 7656, "Robert A. Jones");
   CreditCard cc2 = new CreditCard(3788576018410707L, 13, 2015, 7676, "Harry A. Lambert");
   System.out.println(cc + "\n" + cc1 + "\n" + cc2);
   System.out.println(cc.typeOfCard());
   System.out.println(cc.getStatus());
   System.out.println(cc2.getStatus());
 }
Example #3
0
 public double getBalance() {
   double totalBal = 0.0;
   if (cardCount() == 0) return 0.0;
   else {
     ListIterator iter = cards.dataIterator();
     while (iter.hasNext()) {
       CreditCard tmp = (CreditCard) iter.next();
       totalBal += tmp.getCredit();
     }
   }
   return totalBal;
 }
  @Test(groups = "unit")
  public void testCvv2() {
    logger.info("**** Test CreditCard CVV2 ****");
    CreditCard creditCard = createDummyCreditCard();

    // empty CVV2
    creditCard.setCvv2(null);
    Assert.assertEquals(-1, creditCard.getCvv2());

    // valid CVV2
    creditCard.setCvv2(123);
    Assert.assertEquals(123, creditCard.getCvv2());
  }
  @Test(
      groups = "integration",
      dependsOnMethods = {"createCreditCardTest"})
  public void testListCreditCard() throws PayPalRESTException {
    logger.info("**** List CreditCard ****");
    logger.info("Generated Access Token = " + TokenHolder.accessToken);

    CreditCardHistory creditCards = CreditCard.list(TokenHolder.accessToken);
    logger.info("Request = " + CreditCard.getLastRequest());
    logger.info("Response = " + CreditCard.getLastResponse());
    logger.info("Retrieved list of credit cards = " + creditCards.getItems());
    Assert.assertTrue(creditCards.getTotalItems() > 0);
  }
Example #6
0
 public static Customer example2() {
   Customer customer = new Customer();
   customer.address = Address.example2();
   customer.email = org.eclipse.persistence.testing.models.events.EmailAccount.example2();
   customer.phoneNumber = Phone.example2();
   ((Vector) customer.orders.getValue()).add(Order.example3());
   ((Vector) customer.orders.getValue()).add(Order.example4());
   customer.associations.add("Masons");
   customer.associations.add("Illuminaty");
   customer.name = "Bobby Ore";
   customer.creditCard = new CreditCard();
   customer.creditCard.number = "456556544565";
   customer.creditCard.expiry = "03/03";
   return customer;
 }
Example #7
0
 public static Customer example1() {
   Customer customer = new Customer();
   customer.address = Address.example1();
   customer.email = org.eclipse.persistence.testing.models.events.EmailAccount.example1();
   customer.phoneNumber = Phone.example1();
   ((Vector) customer.orders.getValue()).add(Order.example2());
   ((Vector) customer.orders.getValue()).add(Order.example1());
   customer.associations.add("Mickey Mouse Club");
   customer.associations.add("Canadian Penitentiary System");
   customer.name = "John Lancy";
   customer.creditCard = new CreditCard();
   customer.creditCard.number = "346556544565";
   customer.creditCard.expiry = "04/03";
   return customer;
 }
 public static CreditCard createCreditCard() {
   CreditCard creditCard = new CreditCard();
   creditCard
       .setBillingAddress(BILLINGADDRESS)
       .setExpireMonth(EXPMONTH)
       .setExpireYear(EXPYEAR)
       .setFirstName(FIRSTNAME)
       .setLastName(LASTNAME)
       .setNumber(NUMBER)
       .setType(TYPE)
       .setCvv2(CVV2)
       .setBillingAddress(BILLINGADDRESS)
       .setId(ID)
       .setState(STATE)
       .setValidUntil(VALIDUNTIL);
   return creditCard;
 }
 @Test
 public void testCreditCardUnknownFileConfiguration() {
   try {
     CreditCard.initConfig(new File("unknown.properties"));
   } catch (PayPalRESTException e) {
     Assert.assertEquals(e.getCause().getClass().getSimpleName(), "FileNotFoundException");
   }
 }
  @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());
  }
 @Test
 public void testCreditCardInputStreamConfiguration() {
   try {
     File testFile = new File(".", "src/test/resources/sdk_config.properties");
     FileInputStream fis = new FileInputStream(testFile);
     CreditCard.initConfig(fis);
   } catch (PayPalRESTException e) {
     Assert.fail("[sdk_config.properties] stream loading failed");
   } catch (FileNotFoundException e) {
     Assert.fail("[sdk_config.properties] file is not available");
   }
 }
 @Test
 public void testCreditCardPropertiesConfiguration() {
   try {
     File testFile = new File(".", "src/test/resources/sdk_config.properties");
     Properties props = new Properties();
     FileInputStream fis = new FileInputStream(testFile);
     props.load(fis);
     CreditCard.initConfig(props);
   } catch (FileNotFoundException e) {
     Assert.fail("[sdk_config.properties] file is not available");
   } catch (IOException e) {
     Assert.fail("[sdk_config.properties] file is not loaded into properties");
   }
 }
  @Test(
      groups = "integration",
      dependsOnMethods = {"testGetCreditCard"})
  public void getCreditCardForNull() {
    logger.info("**** Get CreditCard Null ****");
    logger.info("Generated Access Token = " + TokenHolder.accessToken);

    try {
      CreditCard.get(TokenHolder.accessToken, null);
    } catch (IllegalArgumentException e) {
      Assert.assertTrue(e != null, "Illegal Argument Exception not thrown for null arguments");
    } catch (PayPalRESTException e) {
      Assert.fail();
    }
  }
  @Test(groups = "integration")
  public void createCreditCardTest() throws PayPalRESTException {
    logger.info("**** Create CreditCard ****");
    logger.info("Generated Access Token = " + TokenHolder.accessToken);

    CreditCard creditCard = new CreditCard();
    creditCard.setExpireMonth(EXPMONTH);
    creditCard.setExpireYear(EXPYEAR);
    creditCard.setNumber(NUMBER);
    creditCard.setType(TYPE);
    this.creditCard = creditCard.create(TokenHolder.accessToken);
    logger.info("Request = " + CreditCard.getLastRequest());
    logger.info("Response = " + CreditCard.getLastResponse());
    logger.info("Credit Card created with ID = " + this.creditCard.getId());
    Assert.assertEquals(true, "ok".equalsIgnoreCase(this.creditCard.getState()));
    logger.info("Created Credit Card status = " + this.creditCard.getState());
    createdCreditCardId = this.creditCard.getId();
  }
  @Test(
      groups = "integration",
      dependsOnMethods = {"createCreditCardTest"})
  public void testGetCreditCard() throws PayPalRESTException {
    logger.info("**** Get CreditCard ****");
    logger.info("Generated Access Token = " + TokenHolder.accessToken);

    CreditCard retrievedCreditCard = CreditCard.get(TokenHolder.accessToken, createdCreditCardId);
    logger.info("Request = " + CreditCard.getLastRequest());
    logger.info("Response = " + CreditCard.getLastResponse());
    Assert.assertEquals(
        true, this.creditCard.getId().equalsIgnoreCase(retrievedCreditCard.getId()));
    logger.info("Retrieved Credit Card status = " + retrievedCreditCard.getState());
  }
  @Test(
      groups = "integration",
      dependsOnMethods = {"testUpdateCreditCard"})
  public void deleteCreditCard() throws PayPalRESTException {
    logger.info("**** Delete CreditCard ****");
    logger.info("Generated Access Token = " + TokenHolder.accessToken);

    CreditCard retrievedCreditCard = CreditCard.get(TokenHolder.accessToken, createdCreditCardId);
    retrievedCreditCard.delete(TokenHolder.accessToken);
    logger.info("Request = " + CreditCard.getLastRequest());
    logger.info("Response = " + CreditCard.getLastResponse());
    try {
      CreditCard.get(TokenHolder.accessToken, createdCreditCardId);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Example #17
0
  public static void main(String[] args) {
    CreditCard wallet[] = new CreditCard[10];
    wallet[0] =
        new CreditCard("5391 0375 9387 5309", "John Bowman", "California Savings", 0.0, 2500);
    wallet[1] =
        new CreditCard("3485 0399 3395 1954", "John Bowman", "California Federal", 0.0, 3500);
    wallet[2] =
        new CreditCard("6011 4902 3294 2994", "John Bowman", "California Finance", 0.0, 5000);

    for (int i = 1; i <= 57; i++) {
      wallet[0].chargetIt((double) i);
      wallet[1].chargetIt(2.0 * i); // implicit cast
      wallet[2].chargetIt((double) 3 * i); // explicit cast
    }

    for (int i = 0; i < 3; i++) {
      CreditCard.printCard(wallet[i]);
      while (wallet[i].getBalance() > 100.00) {
        wallet[i].makePayment(100.0);
        System.out.println("New balance = " + wallet[i].getBalance());
      }
    }
  }
  @Test(
      groups = "integration",
      dependsOnMethods = {"testGetCreditCard"})
  public void testUpdateCreditCard() throws PayPalRESTException {
    logger.info("**** Update CreditCard ****");
    logger.info("Generated Access Token = " + TokenHolder.accessToken);

    // set up patch request
    Patch patch = new Patch();
    patch.setOp("replace");
    patch.setPath("/expire_year");
    patch.setValue(new Integer(2020));
    List<Patch> patchRequest = new ArrayList<Patch>();
    patchRequest.add(patch);

    // send patch request
    CreditCard creditCard = new CreditCard();
    creditCard.setId(createdCreditCardId);
    CreditCard retrievedCreditCard = creditCard.update(TokenHolder.accessToken, patchRequest);

    logger.info("Request = " + CreditCard.getLastRequest());
    logger.info("Response = " + CreditCard.getLastResponse());
    Assert.assertEquals(2020, retrievedCreditCard.getExpireYear());
  }
 @Test(groups = "unit")
 public void testConstruction() {
   CreditCard creditCard = createDummyCreditCard();
   Assert.assertEquals(creditCard.getCvv2(), CVV2);
   Assert.assertEquals(creditCard.getExpireMonth(), EXPMONTH);
   Assert.assertEquals(creditCard.getExpireYear(), EXPYEAR);
   Assert.assertEquals(creditCard.getFirstName(), FIRSTNAME);
   Assert.assertEquals(creditCard.getLastName(), LASTNAME);
   Assert.assertEquals(creditCard.getNumber(), NUMBER);
   Assert.assertEquals(creditCard.getType(), TYPE);
   Assert.assertEquals(creditCard.getBillingAddress().getCity(), AddressTestCase.CITY);
   Assert.assertEquals(creditCard.getId(), ID);
   Assert.assertEquals(creditCard.getExternalCustomerId(), EXTERNAL_CUSTOMER_ID);
   Assert.assertEquals(creditCard.getState(), STATE);
   Assert.assertEquals(creditCard.getValidUntil(), VALIDUNTIL);
   Assert.assertEquals(creditCard.getLinks().size(), 1);
 }
Example #20
0
 public void setCreditCardExpiryDate(String creditCardExpiryDate) {
   creditCard.setCreditCardExpDate(creditCardExpiryDate);
 }
Example #21
0
 public String getCreditCardExpiryDate() {
   return creditCard.getCreditCardExpDate();
 }
Example #22
0
 public void setCreditCardType(String creditCardType) {
   creditCard.setCreditCardType(creditCardType);
 }
Example #23
0
 public String getCreditCardType() {
   return creditCard.getCreditCardType();
 }
Example #24
0
 public void setCreditCardNumber(String creditCardNumber) {
   creditCard.setCreditCardNumber(creditCardNumber);
 }
Example #25
0
 public String getCreditCardNumber() {
   return creditCard.getCreditCardNumber();
 }
 @Test
 public void testTOString() {
   CreditCard creditCard = createCreditCard();
   Assert.assertEquals(creditCard.toString().length() == 0, false);
 }
 public InvalidCreditCardNumberException(CreditCard creditCard) {
   super(
       creditCard,
       "Credit card number " + (creditCard != null ? creditCard.toString() : "") + " is invalid.");
 }
 public static CreditCard createDummyCreditCard() {
   CreditCard creditCard = new CreditCard();
   creditCard.setBillingAddress(BILLINGADDRESS);
   creditCard.setExpireMonth(EXPMONTH);
   creditCard.setExpireYear(EXPYEAR);
   creditCard.setFirstName(FIRSTNAME);
   creditCard.setLastName(LASTNAME);
   creditCard.setNumber(NUMBER);
   creditCard.setType(TYPE);
   creditCard.setCvv2(CVV2);
   creditCard.setBillingAddress(BILLINGADDRESS);
   creditCard.setId(ID);
   creditCard.setExternalCustomerId(EXTERNAL_CUSTOMER_ID);
   creditCard.setState(STATE);
   creditCard.setValidUntil(VALIDUNTIL);
   List<Links> links = new ArrayList<Links>();
   links.add(LinksTestCase.createLinks());
   creditCard.setLinks(links);
   return creditCard;
 }
 @Override
 public boolean isValid(CreditCard card) {
   return card.getCardLegth() > 0;
 }
Example #30
0
  public static Customer createCreditCard(EntityManagerFactory factory, Customer cust) {
    CreditCard card = new CreditCard();
    card.setExpirationDate(new java.util.Date());
    card.setNumber("4444-4444-4444-4444");
    card.setNameOnCard("William Burke");
    card.setCreditOrganization("Capital One");
    card.setCustomer(cust);

    EntityManager manager = factory.createEntityManager();
    try {
      manager.getTransaction().begin();
      manager.persist(card);
      manager.getTransaction().commit();

      // Show that card.getCustomer() returns null

      manager.clear();

      CreditCard cardCopy = manager.find(CreditCard.class, card.getId());
      System.out.println("should be null: " + cardCopy.getCustomer());

      manager.getTransaction().begin();
      System.out.println("now set the owning side of the relationship");
      Customer custCopy = manager.find(Customer.class, cust.getId());
      custCopy.setCreditCard(cardCopy);
      manager.getTransaction().commit();

      manager.clear();

      cardCopy = manager.find(CreditCard.class, card.getId());
      System.out.println("should be set now: " + cardCopy.getCustomer().getFirstName());
    } finally {
      manager.close();
    }
    return cust;
  }