Next: Configuring your application

This section would guide you on how to make payments using the iPayy SDK.

Before you start

  1. You should already have a Merchant Key and an Application Key for your application.
  2. You should have white-listed some mobile numbers for testing.
  3. You should have downloaded the iPayy SDK jar. 

 

Including the SDK jar in your application project

Client application needs to generate the request-id (client transaction id). This would help in reconciliation of the transaction status (via server-side api’s). The request-id must be unique for the specified merchant and application (across devices and transactions).

A combination of Android-ID, UUID and nano-time converted to md5 should be fine in the normal case.

A better approach would be to have the id generated from the server side of the merchant application for production use-cases. Network failures etc. can cause the transaction status from reaching the app. In such a case, the server to server api’s can be used for reconciliation once the request-id is known to the client (merchant).

Sample code:

 

The Payment service can be invoked as:-

 

Eclipse

Copy  ipayy-sdk-android.jar to the lib folder in the application project OR Project -> Properties -> Java Build Path -> libraries -> add external JARs -> (Browse to downloaded iPayy SDK location) -> OK

Netbeans

Project -> Properties -> Libraries -> Add JAR/Folder -> (Browse to downloaded iPayy SDK location) -> OK

 

To tackle screen orientation issue

iPayy page gets reloaded and the data entered by user is lost in the process in case the screen orientation changes from landscape to portrait and vice-versa. This needs to be fixed by the client on their application.

To fix screen orientation issues, the client application should add the configChages attribute (like the following for the PaymentActivity):

 

Payment Process

The iPayy SDK provides a PaymentActivity class which accepts the payment request from the merchant application and communicates with the iPayy server to process the request. Once the payment flow is completed, the activity invokes the relevant payment handler methods (if a handler is specified) and then passes back the result to the application activity.

 

 payment process - New Page

Creating an Item to purchase

The iPayy SDK provides two classes to specify what is being purchased. The ItemDetail class allows you to specify an item code, item name (displayed to the end-user), item price and optionally a discount. The discount is automatically applied by the iPayy server when it receives the request.

The Item class accepts an ItemDetail object and a currency parameter. Currently, only Currency.INR is accepted.

Starting the payment process

The payment process is initiated by starting the activity PaymentActivity. The payment activity requires some information like the credentials, response handler etc. to function properly.These parameters are read from the intent which is obtained by invoking  PaymentService.getInstance().getPaymentIntent()  method.To obtain the intent object,you need to pass a payment request object as an argument.The payment request object can be created using the RequestBuilder.buildRequest() method.The RequestBuilder class allows you to specify the credentials and item to be purchased using the setCredentials() and setItem() methods respectively.

Steps to obtain intent object

1.Creating an Intent Object

Permissions Required :

Declare the internet permission :

The code below shows how to start the PaymentActivity.

The startActivityForResult method accepts the intent  object (payment intent obtained from PaymentService) and a request code which would be passed back when the onActivityResult method is invoked if the value of this integer is greater than zero.

Handling the payment response

The payment response can be handled in two ways:-

  1. Overriding and implementing the onActivityResult method in the activity which invoked the payment activity.
  2. Implementing the IPayyHandler interface and passing the instance to the getPaymentIntent() method.

Overriding onActivityResult method

PaymentService.RESULT_OK – Indicates the end-user billing was successful. SuccessPaymentResponse object contains the transaction response details.

PaymentService.RESULT_FAILURE – Indicates the end-user billing failed. The FailedPaymentResponse object contains the details of the failed transaction along with failure and error codes to identify the type of failure.

PaymentService.RESULT_CANCELED – Indicates the end-user billing was canceled. The Item object contains the item details which the user was trying to purchase before he canceled the payment.

Implementing the IPayyHandler interface 

For Payment actions, the requestType contains the value “NEW_PAYMENT”.

The onIPayySuccess method is invoked when the end-user billing was successful. The SuccessPaymentResponse object contains the transaction response details.

In the event of a billing failure due to any reason, the onIPayyFailure method is invoked. The FailedPaymentResponse object contains the details of the failed transaction along with failure and error codes to identify the type of failure.

If the end user cancels the payment at any stage, the onIPayyCancel method is invoked. The Item object contains the item details which the user was trying to purchase before he canceled the payment.

 

Example


MainActivity.java



SuccessActivity.java

 

FailureActivity.java

CanceledActivity.java

Next: Configuring your application