transact
The transact function is a method in the Pay Theory SDK that processes payments. It's called through a configured PayTheoryFragment instance after setting up the necessary payment configuration.
Implementation Flow
- Include PayTheoryFragment in your layout:
<fragment
android:id="@+id/payTheoryFragment"
android:name="com.paytheory.android.sdk.fragments.PayTheoryFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
- Configure the payment:
// Get submit button reference and the PayTheoryFragment
val submitButton = findViewById<PayTheoryButton>(R.id.submit_button)
val payTheoryFragment = supportFragmentManager.findFragmentById(R.id.payment_fragment) as PayTheoryFragment
// Create configuration
val configuration = PayTheoryConfiguration(
apiKey = resources.getString(R.string.api_key),
payTheoryButton = submitButton
).apply {
amount = 1000
paymentMethodType = PaymentMethodType.BANK
}
// Configure the payment after fragment is attached
payTheoryFragment.configurePayment(
merchantActivity = this,
configuration = configuration
)
- Set up transaction trigger:
// Set up button click listener
submitButton.setOnClickListener {
payTheoryFragment.transact()
}
Response Handling
Your activity must extend PayTheoryMerchantActivity and implement the Payable interface to handle transaction responses. The following methods will be called based on the transaction outcome:
class YourActivity : PayTheoryMerchantActivity(), Payable {
override fun handleSuccess(successfulTransactionResult: SuccessfulTransactionResult) {
// Handle successful payment
println("Transaction ID: ${successfulTransactionResult.transactionId}")
}
override fun handleFailure(failedTransactionResult: FailedTransactionResult) {
// Handle failed payment
println("Failure: ${failedTransactionResult.failureText}")
}
override fun handleError(error: PTError) {
// Handle system errors
println("Error: ${error.message}")
}
override fun handleBarcodeSuccess(barcodeResult: BarcodeResult) {
// Handle successful cash barcode generation
// Only triggered for cash payments
}
}
Important Notes
- All amounts should be provided in cents (e.g., $10.00 = 1000)
- The payment configuration must be properly set up before calling transact
- Make sure to implement all required Payable interface methods to handle responses
- For cash payments, the response will come through handleBarcodeSuccess instead of handleSuccess
- The activity must extend PayTheoryMerchantActivity and implement the Payable interface