SDK for Java
SDK for Java is a software development kit for development of web services which are capable of integrating with the ecommpay payment solutions to perform purchases by using Payment Page. This section describes how to use SDK for Java to build purchase experience from inside of your web service.
SDK for Java is compatible with Java SE Development Kit 8 or higher. You can download SDK for Java from GitHub: https://github.com/ITECOMMPAY/paymentpage-sdk-java.
What can I do with SDK for Java?
- Calculate signature and generate an URL for opening the Payment Page.
- Check callback signatures and extract payment details from callbacks
What's inside?
- Libraries for development and automated testing
- Code samples in Java
Using SDK for Java
- Make sure you have you have ready your merchant ID and secret key obtained from ecommpay.
- If your company has never obtained any ID or secret key from ecommpay, you need to submit an application for connecting to the ecommpay payment platform at https://ecommpay.com/apply-now/.
- If your company already has an ID and a secret key to sign messages obtained from ecommpay, you need to notify the ecommpay technical support specialists that you want to use SDK for Java and consult the customer support on how to arrange a test run.
- Integrate the ecommpay payment solution in your web service:
- Install the SDK for Java libraries into a directory inside your web service project.
- Import the libraries you need into your web service application.
- Test and put your web service in production mode.
- Request test card numbers and test project ID from ecommpay, debug and test your web service.
- Once testing is complete, request your production project ID from ecommpay and put your web service in production mode.
With any questions regarding the use of SDK for Java contact the ecommpay technical support specialists at support@ecommpay.com.
Installing and importing libraries
You can install the SDK for Java libraries manually or by using automated procedures supported by the development environment you use.
The following steps describe how to manually install the SDK for Java libraries.
- Download SDK for Java and pack the SDK files into a JAR file.
- If your project directory does not contain a libs directory, create one and move the JAR file into the libs directory.
- Import the file into your web service project by using the procedures pertinent to your development environment.
Opening payment form
A URL for opening Payment Page consists of a set of parameters, which are signed to secure the data transmitted to the ecommpay payment platform. SDK for Java allows you to seamlessly sign parameters and generate URLs. To open the Payment Page payment form by using SDK for Java do the following:
- Create an instance of the
Payment
class and specify payment details.Payment payment = new Payment('186', "pid_1555943554067"); // Project ID and payment ID // Payment ID must be unique within your project scope payment .setParam(Payment.PAYMENT_AMOUNT, 1001) // Amount in minor currency units .setParam(Payment.PAYMENT_CURRENCY, "EUR"); // Currency as per ISO-4217 alpha-3 .setParam(Payment.PAYMENT_DESCRIPTION, "Test payment"); // Payment description (optional)
All parameters in this example, except for the payment description, are mandatory for any purchase. You may also need to pass other parameters, for example, the customer's email or phone number when the 3‑D Secure authentication is required. Such parameters must be specified as follows.
.setParam(Payment.CUSTOMER_PHONE, "The customer's phone number. Must have from 4 to 24 digits") .setParam(Payment.CUSTOMER_EMAIL, "The customer's email")
In addition, for card purchases you are recommended to pass the customer's billing address information: the country code in ISO 3166-1 alpha-2 (details), the postal code, the city, and the street address. Such parameters are specified as follows.
.setParam(Payment.BILLING_POSTAL, "The postal code of the customer's billing address") .setParam(Payment.BILLING_COUNTRY, "The country of the customer's billing address, in ISO 3166-1 alpha-2t") .setParam(Payment.BILLING_CITY, "The city of the customer's billing address") .setParam(Payment.BILLING_ADDRESS, "The street of the customer's billing address")
You can also use any other optional parameters available for Payment Page. For more information about the Payment Page invocation parameters, see Parameters for opening payment form.
- Create a
gate
instance and initiate it with the secret key you obtained from the ecommpay technical support specialists. The secret key is required to sign parameters.Gate gate = new Gate("<secret_key>"); // Secret key you obtained from technical support service
-
Generate the URL for opening the payment form:
String paymentUrl = gate.getPurchasePaymentPageUrl(payment);
The URL must contain payment parameters and signature (abbreviated):
https://paymentpage.ecommpay.com/payment?signature=OEKRlLXQsa2.. ..gWg%3D%3D&payment_id=pid_1555943554067...
- Use the generated URL for opening the payment form (details).
Here is an example of generating a URL for opening a payment form in English. The payment method selection page includes detailed payment information including amount, currency, and short payment description.
Using the test mode
When working with the SDK for Java, you can use the test mode. It allows you to check completeness and correctness of specified parameters and get information about errors if there were any.
Before using the test mode, make sure that the server of the web service can send the HTTP requests to sdk.ecommpay.com
. This allows you to specify various parameters to open the payment form as part of the testing activities (you will be able to use both test and production parameters) and to analyse error information. Use the following code:
Payment payment = new Payment(<project_id>, "<payment_id_in_your_service>"); payment.payment_amount = 1001; payment.payment_currency = "EUR"; payment.payment_description = "Test payment"; Gate gate = new Gate('<secret_key>'); try { return gate.getPurchasePaymentPageUrl(payment); // Receiving the URL to open the payment form } catch (ValidationException e) { // Validating possible exceptions System.out.println(e); // Error message output } return null;
Information about the errors that occurred in testing is provided in error messages as follows:
One or more parameters is not valid: Customer_id: Must be not null // The id of the customer, required for this request, was not specified Account_token: Invalid account token // Incorrect token value was specified
If there are no errors, then the generated URL for opening Payment Page is correct.
Processing callbacks
The ecommpay payment platform sends payment results to the callback URL you specified when connecting to ecommpay. Callback is an HTTP POST request that contains response data in JSON format. To extract payment information from JSON string do the following:
- Create an instance of
Gate
with the secret key if you did not do it earlier.Gate gate = new Gate("<secret_key>");
-
Create an instance of
Callback
by using the JSON string from the callback obtained from the ecommpay payment platform:Callback callback = gate.handleCallback(data);
-
Use methods for extracting callback information. You can get either full payment information or request specific payment parameters:
callback.getPaymentId(); // Getting payment ID callback.getPaymentStatus(); // Getting payment status callback.getPayment(); // Getting payment body
By using SDK for Java, you can automatically check validity of callback signature. Below, you will find an example of callback that includes signature and payment results.