Java developers can easily integrate with Heartland Payment Systems through our stream-lined SDK.
Below is one of the delegate methods for PKPaymentAuthorizationViewControllerDelegate
. It is called after the iOS user has selected their method of payment and authorized the ApplePay transaction. The first portion converts the payment data to a JSON string, which is what is expected when you create a new PaymentToken
object in our Java SDK.
- (void) paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller
didAuthorizePayment:(PKPayment *)payment
completion:(void (^)(PKPaymentAuthorizationStatus))completion
{
NSString *json = [[NSString alloc] initWithData:payment.token.paymentData
encoding:NSUTF8StringEncoding];
// Here is where you might post the json to a service for decryption and authorization.
if( transactionSuccessful ) // pseudo code to complete the transaction in PassKit
{
completion(PKPaymentAuthorizationStatusSuccess);
}
else
{
completion(PKPaymentAuthorizationStatusFailure);
}
}
These three lines of code are all that is required to decrypt your PKPaymentToken. The JSON string in the PaymentToken
constructor represents JSON data obtained from the iOS device as displayed in the previous code block.
PaymentToken token = new PaymentToken("{ data: ..., header: { ... }, signature: ... }");
DecryptService service = new DecryptService("PrivateKeyExport.p12", "PrivateKeyPassword");
PaymentData paymentData = service.decrypt(token);
All you need to authenticate with our gateway is a secret api key. You can obtain a new key for our certification ("sandbox") environment by simply registering and navigating to Account->Profile on our [DeveloperPortal]
HpsServicesConfig config = new HpsServicesConfig();
config.setSecretAPIKey("skapi_cert_...");
The following code illustrates how to properly build out a HpsCardHolder object.
HpsCardHolder cardHolder = new HpsCardHolder();
cardHolder.setFirstName("Bill");
cardHolder.setLastName("Johnson");
HpsAddress address = cardHolder.getAddress();
address.setAddress("6860 Dallas Pkwy");
address.setCity("Irvine");
address.setState("TX");
address.setZip("75024");
address.setCountry("United States");
We can complete our credit sale example now that we have both configuration and cardholder information. Simply create a new HpsCreditService with the configuration object and call the charge() method. The boolean flag indicates that we do not want to allow duplicate transactions on our gateway. This behavior is not desired in most cases, however, some merchants may opt to allow it.
HpsCreditService creditService = new HpsCreditService(config);
HpsCharge response = creditService.charge(paymentData, cardHolder, false);
- Java 1.7
- ApplePay MerchantID Certificate in p12 format
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request [DeveloperPortal]: https://developer.heartlandpaymentsystems.com/securesubmit