コード例 #1
0
  @Test
  public void testGetTransaction() {

    Gateway beanstream =
        new Gateway(
            "v1",
            300200578,
            "4BaD82D9197b4cc4b70a221911eE9f70", // payments API passcode
            "D97D3BE1EE964A6193D17A571D9FBC80", // profiles API passcode
            "4e6Ff318bee64EA391609de89aD4CF5d"); // reporting API passcode

    CardPaymentRequest paymentRequest = new CardPaymentRequest();
    paymentRequest.setAmount(30.00).setOrderNumber(getRandomOrderId("get"));
    paymentRequest
        .getCard()
        .setName("John Doe")
        .setNumber("5100000010001004")
        .setExpiryMonth("12")
        .setExpiryYear("18")
        .setCvd("123");

    try {
      PaymentResponse response = beanstream.payments().makePayment(paymentRequest);
      Assert.assertTrue(response.isApproved());

      if (response.isApproved()) {
        Transaction transaction = beanstream.reports().getTransaction(response.id);
        System.out.println(
            "Transaction: " + transaction.getAmount() + " approved? " + transaction.getApproved());
      }
    } catch (BeanstreamApiException ex) {
      Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "An error occurred", ex);
      Assert.fail(ex.getMessage());
    }
  }
コード例 #2
0
  @Test
  public void testQueryTransactions() {
    System.out.println("############################################################3");
    System.out.println("############################################################3");
    System.out.println("############################################################3");
    System.out.println("############################################################3");
    Gateway beanstream =
        new Gateway(
            "v1",
            300200578,
            "4BaD82D9197b4cc4b70a221911eE9f70", // payments API passcode
            "D97D3BE1EE964A6193D17A571D9FBC80", // profiles API passcode
            "4e6Ff318bee64EA391609de89aD4CF5d"); // reporting API passcode

    String order = getRandomOrderId("q");
    CardPaymentRequest paymentRequest = new CardPaymentRequest();
    paymentRequest.setAmount(20.50).setOrderNumber(order);
    paymentRequest
        .getCard()
        .setName("Bob Doe")
        .setNumber("5100000010001004")
        .setExpiryMonth("12")
        .setExpiryYear("18")
        .setCvd("123");

    try {
      PaymentResponse response = beanstream.payments().makePayment(paymentRequest);
      if (response.isApproved()) {
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DAY_OF_MONTH, -1);
        Date startDate = cal.getTime(); // yesterday
        cal = Calendar.getInstance();
        cal.add(Calendar.DAY_OF_MONTH, 1);
        Date endDate = cal.getTime(); // tomorrow
        Criteria[] searchFilter =
            new Criteria[] {new Criteria(QueryFields.OrderNumber, Operators.Equals, order)};
        List<TransactionRecord> query =
            beanstream.reports().query(startDate, endDate, 1, 2, searchFilter);
        Assert.assertNotNull(query);
        Assert.assertFalse(query.isEmpty());

        System.out.println("Queried " + query.size() + " items.");

        // print out the first 10 records
        int i = 0;
        for (TransactionRecord tr : query) {
          System.out.println(
              tr.getTransactionId() + " from " + tr.getCardOwner() + " -> $" + tr.getAmount());
          i++;
          if (i > 10) {
            break;
          }
        }
      }
    } catch (BeanstreamApiException ex) {
      Logger.getLogger(this.getClass().getName())
          .log(Level.SEVERE, "An error occurred: " + ex.toString(), ex);
      System.out.println("Error Details: " + ex.getCode() + ", " + ex.getCategory());
      Assert.fail(ex.getMessage());
    }
  }