Hinzufügen der Schaltfläche Google Pay zur Drop-In-Ansicht für Android SDK

  Zuletzt aktualisiert: 

 

 

Erstens müssen Sie Folgendes hinzufügen DropInPaymentView in der xml-Datei Ihrer Aktivität:

<com.trustpayments.mobile.ui.dropin.DropInPaymentView
android:id="@+id/dropInPaymentView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp" />

 

Der folgende Beispielcode zeigt, wie Sie die Schaltfläche Google Pay in die vorgefertigte Drop-In-Ansicht des Payment SDK einfügen können. Die onActivityResult (d. h. das Google Pay Wallet-Token) muss in einer Zahlungsanforderung Autorisierung an Trust Payments übermittelt werden, damit eine Zahlung abgeschlossen werden kann. Bitte beachten Sie die Anforderung einer Zahlung Autorisierung Seite, wenn Sie bereit sind, eine Zahlung zu verarbeiten.

// 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
}
}
War dieser Artikel hilfreich?
0 von 0 Personen fanden dies hilfreich