An Android SDK to integrate Astrapay QRIS payment services into your mobile application, enabling seamless QRIS transactions.
To install the Astrapay QRIS SDK in your project, follow these steps:
- Open your app/build.gradle file at the app level and ensure that ViewBinding is enabled. If you have already enabled ViewBinding, you can skip this step.
android {
// Enable ViewBinding if not already enabled
buildFeatures {
viewBinding true
}
}- Add the Astrapay QRIS SDK dependency to your project by including the following line in the dependencies section:
dependencies {
implementation "com.astrapay:qris-sdk-android:<version>"
}Note
Note: Replace with the latest version of the Astrapay QRIS SDK. Check Astrapay SDK release for the latest release.
- Sync your project with Gradle to ensure the SDK is correctly installed.
Before starting any QRIS transaction, initialize the SDK with a valid configuration object.
AstraPayQris.initialize(configuration = configuration)| Parameter | Type | Required | Description |
|---|---|---|---|
authToken |
string |
Yes | Authentication token provided by Custommer Astrapay |
sdkToken |
string |
Yes | SDK token provided by registered client |
environment |
string |
Yes | API environment (UAT for testing or PROD for production) |
isSnap |
boolean |
Yes | Boolean flag to indicate if the client already use Snap |
val configuration = QRConfiguration.Builder(
authToken = "",
sdkToken = "",
environment = "UAT",
isSnap = true
)
.setEventListener(this)
.build()Note
Note: Ensure your configuration is accurate. Invalid parameters may lead to failed transactions or improper initialization.
Once the SDK is initialized, you can start a QRIS transaction:
AstraPayQris.getInstance().start(this)Call this method to start a new QRIS transaction.
The SDK provides several methods to facilitate the QRIS transaction flow:
- AstraPayQris.initialize(config): Initializes the SDK with the required configuration parameters.
- AstraPayQris.getInstance(): Retrieves the initialized SDK instance. Must be called after initialize().
- AstraPayQris.startTransaction(context): Starts the QRIS transaction process using the provided context.
The SDK provides listeners for handling various transaction events:
- onTransactionComplete: Triggered when a transaction is successfully completed.
- onTransactionFailed: Triggered when a transaction fails due to an error.
- onTransactionForbidden: Triggered if the transaction is forbidden (e.g., insufficient permissions or invalid tokens).
- onTransactionCanceled: Triggered if the user cancels the transaction.
class MainActivity : AppCompatActivity(), QrisTransactionListener {
private lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
val configuration = QRConfiguration.Builder(
authToken = "yourAuthToken",
sdkToken = "yourSdkToken",
environment = "UAT",
isSnap = true
)
.setEventListener(this) // Register this activity as a listener
.build()
AstraPayQris.initialize(configuration = configuration)
binding.buttonQris.setOnClickListener {
AstraPayQris.getInstance().start(this)
}
}
override fun onTransactionComplete() {
Toast.makeText(this, "Transaction Complete", Toast.LENGTH_LONG).show()
}
override fun onTransactionFailed() {
Toast.makeText(this, "Transaction Failed", Toast.LENGTH_LONG).show()
}
override fun onTransactionForbidden() {
Toast.makeText(this, "Transaction Forbidden", Toast.LENGTH_LONG).show()
}
override fun onTransactionCanceled() {
Toast.makeText(this, "Transaction Canceled", Toast.LENGTH_LONG).show()
}
override fun onTransactionProcessing() {
Toast.makeText(this, "Transaction Processing", Toast.LENGTH_LONG).show()
}
override fun onShowTransactionHistory() {
Toast.makeText(this, "Showing Transaction History", Toast.LENGTH_LONG).show()
}
}