Firstly you will need to add DropInPaymentView in your activity xml file:
<com.trustpayments.mobile.ui.dropin.DropInPaymentView
android:id="@+id/dropInPaymentView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp" />
The following example code demonstrates how you can add the Google Pay button inside of the payment SDK's pre-built Drop-In view. The onActivityResult (i.e. the Google Pay wallet token) will need to be submitted in a payment authorisation request to Trust Payments for a payment to be completed. Please refer to the Requesting a payment authorisation page when you’re ready to process a payment.
// Need to implement the DropInPaymentView.DropInGooglePayPaymentViewListener
class YourActivity : Activity, DropInPaymentView.DropInGooglePayPaymentViewListener {
private lateinit var tpGooglePayManager : TPGooglePayManager
// Example interface implementation
override fun onGooglePayClicked() {
tpGooglePayManager.requestPayment(priceInCents)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// creating the Google Pay manager instance
tpGooglePayManager = TPGooglePayManager.Builder(
...
).build()
// Verify that Google Pay is supported by customer device & configuration is valid
tpGooglePayManager.possiblyShowGooglePayButton(object : TPGooglePayManager.ShowGooglePayButtonCallback {
override fun canShowButton(boolean: Boolean) {
dropInPaymentView.setupForGooglePayPayment(boolean)
}
})
dropInPaymentView.apply {
setupForTokenizedPayment(emptySet(), null) // Use with the line bellow to hide card payment form
setPayButtonVisibility(View.GONE)
// Register the interface implementation in the drop-in payment view
dropInGooglePayPaymentViewListener = this@YourActivity
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
val googlePayWalletToken = tpGooglePayManager.onActivityResult(requestCode, resultCode, data)
//Use googlePayWalletToken for processing a payment authorisation
}
}