Skip to main content
Version: Lab (preview)

Activity & Interface Setup

To use the Pay Theory SDK, your activity must extend PayTheoryMerchantActivity and implement the Payable interface. This setup is crucial for handling payment responses and managing the payment flow.

Implementation Requirements​

class YourActivity : PayTheoryMerchantActivity(), Payable {
// Your activity implementation
}

PayTheoryMerchantActivity​

The PayTheoryMerchantActivity class provides essential functionality for managing the Pay Theory payment flow:

  • Manages the PayTheoryFragment lifecycle
  • Provides access to payment form operations
  • Handles UI thread operations for payment responses

Key Methods​

MethodDescription
initializePayTheoryActivity(fragment: PayTheoryFragment)Initializes the activity with a PayTheoryFragment instance
clearFields()Clears all payment form fields on the UI thread

Payable Interface​

The Payable interface defines callback methods for handling various payment states and responses. Your activity must implement these methods to handle payment results.

Required Handlers​

interface Payable {
// Payment State Handlers
fun handleReady(isReady: Boolean)
fun handlePaymentStart(paymentType: String)
fun handleTokenStart(paymentType: String)

// Success Handlers
fun handleSuccess(successfulTransactionResult: SuccessfulTransactionResult)
fun handleBarcodeSuccess(barcodeResult: BarcodeResult)
fun handleTokenizeSuccess(paymentMethodToken: PaymentMethodTokenResults)

// Failure/Error Handlers
fun handleFailure(failedTransactionResult: FailedTransactionResult)
fun handleError(error: PTError)
}

Handler Details​

State Handlers​

HandlerDescription
handleReadyCalled when the SDK is ready to accept payments
handlePaymentStartCalled when a payment transaction begins
handleTokenStartCalled when a tokenization process begins

Success Handlers​

HandlerDescription
handleSuccessCalled after a successful card/bank payment
handleBarcodeSuccessCalled after successful cash barcode generation
handleTokenizeSuccessCalled after successful payment method tokenization

Failure/Error Handlers​

HandlerDescription
handleFailureCalled when a transaction fails but completes
handleErrorCalled when a system error occurs during processing

Example Implementation​

Here's a complete example showing how to implement the activity and interface:

class PaymentActivity : PayTheoryMerchantActivity(), Payable {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_payment)

if (savedInstanceState == null) {
// Create PayTheoryFragment
val payTheoryFragment = PayTheoryFragment()

// Add fragment to container
supportFragmentManager.beginTransaction()
.replace(R.id.payment_fragment, payTheoryFragment)
.commit()
}
}

// Required Payable interface handlers
override fun handleReady(isReady: Boolean) {
// Handle ready state
}

override fun handleError(error: PTError) {
// Handle error
}

override fun handleSuccess(successfulTransactionResult: SuccessfulTransactionResult) {
// Handle success
}

override fun handleFailure(failedTransactionResult: FailedTransactionResult) {
// Handle failure
}

override fun handlePaymentStart(paymentType: String) {
// Handle payment start
}

override fun handleTokenStart(paymentType: String) {
// Handle token start
}

override fun handleBarcodeSuccess(barcodeResult: BarcodeResult) {
// Handle barcode success
}

override fun handleTokenizeSuccess(paymentMethodToken: PaymentMethodTokenResults) {
// Handle tokenization success
}
}