PayPal

Purpose: PayPal payments

Add PayPal Widget to Layout

<io.hyperswitch.view.BasePaymentWidget
    android:id="@+id/payPalButton"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:paymentMethod="paypal" />

Initialize PayPal Launcher

private lateinit var payPalButton: BasePaymentWidget
private lateinit var payPalLauncherInstance: UnifiedPaymentLauncher

private fun setupPayPalLauncher() {
    payPalButton = findViewById(R.id.payPalButton)
    payPalButton.isEnabled = false
    
    payPalLauncherInstance = UnifiedPaymentLauncher.createPayPalLauncher(
        activity = this,
        clientSecret = paymentIntentClientSecret,
        readyCallback = ::onPayPalReady,
        resultCallback = ::onPayPalResult
    )

    payPalButton.setOnClickListener {
        if (::payPalLauncherInstance.isInitialized) {
            payPalLauncherInstance.presentForPayment(paymentIntentClientSecret)
        } else {
            Toast.makeText(this, "PayPal Launcher not initialized", Toast.LENGTH_SHORT).show()
        }
    }
}

Handle PayPal Callbacks

Last updated

Was this helpful?