How to Charge Credit Cards from a BIRT Design, and Other Posts From This Week

groupphoto

Last weekend I had the opportunity to attend a local hackathon put together by hackmidwest. If you’re not familiar with hackathons, I encourage you to seek one out. They are a lot of fun. Rules can change from event to event, but typically you have 24 hours to create an application of your choosing, either by yourself or as a team.

For my hack, I used BIRT iHub F-Type and Mastercard’s Simplify API. By leveraging the Simplify API, I was able to charge credit cards directly from a BIRT Design. It was as simple as creating a JAR and including it in my design.

public void chargeCard(String creditcard, long amount, String cvc, int expMonth, int expYear, String desc, String currency) {
  PaymentsApi.PUBLIC_KEY = "PUBLICKEY";
  PaymentsApi.PRIVATE_KEY = "PRIVATEKEY";
		
  try {
    Payment payment = Payment.create(new PaymentsMap()
      .set("amount", amount)
      .set("card.cvc", cvc)
      .set("card.expMonth", expMonth)
      .set("card.expYear", expYear)
      .set("card.number", creditcard)
      .set("description", desc)
      .set("currency", currency));
  }catch(Exception ex) {
    ex.printStackTrace();
  }
}

By creating a JAR with this method, I was able to leverage a few global persistent variables and a simple script like this in the onCreate() of a label.

if(params["Payment"].value == true) {
  var simplify = com.actuate.developer.SimplifyBIRT();
  simplify.chargeCard(reportContext.getPersistentGlobalVariable("card"), 
    reportContext.getPersistentGlobalVariable("amount"), 
    "123", 8, 16, "BIRT Payment", "USD");
  this.text = "Paid"
}else{
  this.text = "Pending"
}params["Payment"].value

This grabs the card number to be charged from the global persistent variable “card” as well as the amount to charge from “amount”. Then I changed the label to show that the credit card has been charged.

report

Now that the card has been charged, let’s check the Simplify website to make sure it has been approved.

backend

And that’s all there is to it! Simplify has several other calls you can use in your BIRT Designs.

This is just a quick and simple example of how you can use third-party APIs in your BIRT Designs. Which third-party APIs have you used in your designs, and which ones are your favorites? I’m always looking for more ways to integrate other libraries with BIRT!

Here are some other BIRT Forum posts worth taking a look at:

Also, here are some unanswered posts from this week:

If you have suggestions or solutions for any of these, please post them in the thread.

As the week comes to an end I hope everyone has a good weekend. Thanks for reading! If you have any questions or comments please feel free to comment below.
-Kris

Group photo courtesy of hackmidwest. Credit card sign photo by Shawn Rossi

Write a Reply or Comment

Your email address will not be published. Required fields are marked *