For the complete documentation index, see llms.txt. This page is also available as Markdown.

PayPal

Learn how to integrate the PayPal widget for accepting PayPal payments in your Android app using Juspay Hyperswitch SDK.

PayPal payments with Juspay Hyperswitch.

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?