Android – Using the JPPaymentContext 2017-05-15T11:49:54+00:00

Android – Using the JPPaymentContext 

JPPaymentContext is a singleton model object used to collect together all data required to make a COMPLETE and VALID transaction payment.  In addition, you can copy additional data into the JPPaymentContext which can be used at a later time to relate transaction data with data structures in your own application.

Example data would be transaction amount, a payment card and customer details.

Data can be added to JPPaymentContext directly by your app via a well defined API and set of read/write properties. In addition, when using SDK UI elements to collect data on your behalf, this data may be copied into the JPPaymentContext automatically or you must move these data from these SDK UI elements into the JPPaymentContext yourself.

Once all data for your current transaction has been collected (i.e. stored in JPPaymentContext), your app can request JPPaymentContext to submit the transaction to the JetPay gateway for processing. At this point, JPPaymentContext will verify that all required data is present, validate this data and submit the transaction request.

Invalid or incomplete data is NOT submitted. All feedback is through the JPPaymentContextListener interface. In addition, the JPPaymentContext always maintains a current state – which can be interrogated by you for status of data or error conditions when the JPPaymentContext POSTed the last transaction request.

Once a transaction has been made by JPPaymentContext, the context is NOT cleared. You are responsible for doing this yourself. Part of the reason for this is if you want to reference the successful transaction back to your own data objects. JPPaymentContext holds it’s context data until you clear it.

JPPaymentContext can ONLY make one transaction request at a time. When requested to POST a transaction request JPPaymentContext effectively “locks” the context – any attempt to change context data is silently ignored. The JPPaymentContext is only unlocked once a transaction POST has completed (either successfully or with failure).

For more details, please see the JetPay Full Android SDK Reference.

This snippet illustrates directly loading JPPaymentContext with data, requesting a transaction to be processed, and receiving feedback via the JPPaymentContextDelegate interface:

void postExampleTransaction() {

   JPPaymentContext payContext = JPPaymentContext.sharedContext;
   payContext.setListener( this );

   /* create and load customer data into the payment context */
   JPCustomer customer = JPCustomer( “your customer ID”, “Jon”, “Appleseed”);
   payContext.setCustomer( customer );

   /* create and load payment card information */
   JPCardParams payCard = JPCardParams( “4242 1111 2222 3333”, 06, 2017, “123”);
   payContext.setPaymentCard( payCard )

   /* set a transaction amount - currency independent */
   payContext.setPaymentAmount( 15.00 )

        /* set the transactionId */
        payContext.setTransactionId( “010327153017T10017” )

   if ( payContext.isValid() ) {
      payContext.postSaleTransaction();	/* feedback via the JPPaymentContextListener interface */

/* feedback from the JPPaymentContextListener interface */

void paymentContextDidPostTransaction( JPPaymentContext paymentContext ) {
   /* payment request has been POSTed - awaiting response form Jetpay gateway */

void paymentContextDidCancelPostAsPaymentAmountIsInvalid( JPPaymentContext paymentContext ) {
   /* payment request NOT POSTed - as payment amount is invalid

void paymentContextDidCancelPostAsPaymentCardIsInvalid( JPPaymentContext paymentContext ) {
   /* payment request NOT POSTed - as payment card is invalid

void paymentContextDidCancelPostAsPaymentCardIsUnsupported( JPPaymentContext paymentContext ) {
   /* payment request NOT POSTed - as payment card is valid BUT UNSUPPORTED by the Jetpay gateway */

void paymentContextDidCancelPostAsTransactionIdIsInvalid( JPPaymentContext paymentContext ) {
   /* payment request NOT POSTed - as transactionId is invalid  */

void paymentContextDidCancelPostAsPostCurrentlyInProgress( JPPaymentContext paymentContext ) {
   /* payment request NOT POSTed - as a transaction request post is currently awaiting a response  */

void paymentContextDidCancelPostReceivedTransactionResponse( JPPaymentContext paymentContext ) {
   /* a previously POSTed transaction request has received a response from the Jetpay gateway  */

void paymentContextDidCancelPostDidNotReceiveTransactionResponse( JPPaymentContext paymentContext ) {
   /* a previously POSTed transaction request has NOT received a response from the Jetpay gateway. This is often the result of a network timeout before the response has been received */