@Test public void testPreAuthorization() { Gateway beanstream = new Gateway("v1", 300200578, "4BaD82D9197b4cc4b70a221911eE9f70"); CardPaymentRequest paymentRequest = new CardPaymentRequest(); paymentRequest.setAmount(90.00); paymentRequest.setOrderNumber(getRandomOrderId("GAS")); paymentRequest .getCard() .setName("John Doe") .setNumber("5100000010001004") .setExpiryMonth("12") .setExpiryYear("18") .setCvd("123"); try { PaymentResponse response = beanstream.payments().preAuth(paymentRequest); PaymentResponse authResp = beanstream.payments().preAuthCompletion(response.id, 43.50); if (!authResp.isApproved()) { Assert.fail( "This auth completion should be approved because a greater amount has been pre authorized"); } } catch (BeanstreamApiException ex) { System.out.println(BeanstreamResponse.fromException(ex)); Assert.fail(ex.getMessage()); } // Pre-auth and complete again but supply PaymentRequest details in the complete CardPaymentRequest paymentRequest2 = new CardPaymentRequest(); paymentRequest2.setAmount(30.00); paymentRequest2.setOrderNumber(getRandomOrderId("Pumpkins")); paymentRequest2 .getCard() .setName("John Doe") .setNumber("5100000010001004") .setExpiryMonth("12") .setExpiryYear("18") .setCvd("123"); try { PaymentResponse response = beanstream.payments().preAuth(paymentRequest2); paymentRequest2.setAmount(4.00); PaymentResponse authResp = beanstream.payments().preAuthCompletion(response.id, paymentRequest2); if (!authResp.isApproved()) { Assert.fail( "This auth completion should be approved because a greater amount has been pre authorized"); } } catch (BeanstreamApiException ex) { System.out.println(BeanstreamResponse.fromException(ex)); Assert.fail(ex.getMessage()); } }
@Test public void testReturnPayment() { Gateway beanstream = new Gateway("v1", 300200578, "4BaD82D9197b4cc4b70a221911eE9f70"); CardPaymentRequest paymentRequest = new CardPaymentRequest(); paymentRequest.setAmount(70.00); paymentRequest.setOrderNumber(getRandomOrderId("PEDRO")); paymentRequest .getCard() .setName("John Doe") .setNumber("5100000010001004") .setExpiryMonth("12") .setExpiryYear("18") .setCvd("123"); try { PaymentResponse response = beanstream.payments().makePayment(paymentRequest); if (response.isApproved()) { Gson gsonpp = new GsonBuilder().setPrettyPrinting().create(); System.out.println("Your Payment has been approved response: \n" + gsonpp.toJson(response)); response = beanstream.payments().returnPayment(response.id, 70.00); if ("R".equals(response.type)) { System.out.println("The payment was retuned"); } else { System.out.println("The payment was not returned"); } } } catch (BeanstreamApiException ex) { Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "An error occurred", ex); Assert.fail(ex.getMessage()); } }