Use the XPay Android SDK to render XPay-hosted payment fields in an Android application and confirm a PaymentIntent created by your backend. Android SDK supports Kotlin and Java integrations.
Outcome
By the end of this guide, your application will render a card payment element, validate the form, and submit the customer's payment details.
Install the SDK
Add JitPack to the repositories available to the application:
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}Add the required HTTP client and the XPay package for the selected environment.
For production:
dependencies {
implementation("com.squareup.okhttp3:okhttp:4.9.2")
implementation("com.github.XStakCommerce:XPay-Element-Android-Native-SDK:3.0.0")
}For staging:
dependencies {
implementation("com.squareup.okhttp3:okhttp:4.9.2")
implementation("com.github.XStakCommerce:XPay-Element-Android-Native-SDK:stage-3.0.0")
}Add a payment container
Add a ViewGroup where the XPay element should appear:
<LinearLayout
android:id="@+id/paymentElementView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />Use a separate container and element instance for each payment method displayed at the same time.
Initialize and render the element
Android SDK requires publicKey, and accountId. Obtain these values from Store settings → Keys in the XPay portal.
import android.view.ViewGroup
import com.xstak.xpay_element.PaymentElement
val paymentContainer: ViewGroup = findViewById(R.id.paymentElementView)
val paymentElement = PaymentElement(
this,
publicKey = "{{publishable_key}}",
accountId = "{{account_id}}"
)
paymentContainer.addView(paymentElement)Use EasyPaisaPaymentElement or JazzCashPaymentElement instead when rendering the corresponding wallet form.
Enable payment submission
Use onReady to reflect the current form-validity state:
paymentElement.onReady { isReady ->
payButton.isEnabled = isReady
}A value of true means all required fields contain valid input and payment can be submitted.
Confirm the payment
First, create a PaymentIntent on the merchant backend. Pass the returned client secret and encryption keys to the application, then confirm through the element used to collect the customer's details.
paymentElement.confirmPayment(
"Customer Name",
piClientSecret,
encryptionKeys
) { response ->
handlePaymentResponse(response)
}The callback receives a JSON string containing error and message. Use it to update the checkout UI, then use payment webhook events to reconcile the final payment outcome on the merchant backend.
Reset the form
paymentElement.clear()What to do next
Run an Android checkout with the documented test scenarios. Before enabling live payments, understand how to reconcile the PaymentIntent lifecycle and use the XPay API reference for complete server schemas.