Migrating to version 3.2.0
Code samples for Kotlin.
PaymentResult
models were significantly changed.
Use this manual to switch to new SDK version.
Dependency update
To update the dependency, increase the billingclient
version in the dependencies
block of your build.gradle
.
dependencies {
implementation( "ru.rustore.sdk:billingclient:3.2.0" )
}
Product model and error model remain the same.
Retrieving products list
The model of the receiving products list result has changed. Now the getProducts()
method instantly returns the products list.
val productsUseCase: ProductsUseCase = billingClient.products
productsUseCase.getProducts(productIds = listOf("id1", "id2"))
.addOnSuccessListener { products: List<Product> ->
// Process success
}
.addOnFailureListener { throwable: Throwable ->
// Process error
}
Product model and error model remain the same.
Getting products list
Getting purchase information result model has changed. Now the getPurchasecaution()
method instantly returns purchase model.
Retrieving purchases list
val purchasesUseCase: PurchasesUseCase = billingClient.purchases
purchasesUseCase.getPurchasecaution("purchaseId")
.addOnSuccessListener { purchase: Purchase ->
// Process success
}
.addOnFailureListener { throwable: Throwable ->
// Process error
}
Error models remain were not changed.
Purchasing product
The model of the purchase result has changed. Below is the updated model.
public sealed interface PaymentResult {
public data class Success(
val orderId: String?,
val purchaseId: String,
val productId: String,
val invoiceId: String,
val subscriptionToken: String? = null ,
) : PaymentResult
public data class Cancelled(
val purchaseId: String,
) : PaymentResult
public data class Failure(
val purchaseId: String?,
val invoiceId: String?,
val orderId: String?,
val quantity: Int?,
val productId: String?,
val errorCode: Int?,
) : PaymentResult
public object InvalidPaymentState : PaymentResult()
}
Success
- successful purchase result.Failure
- there was a problem during sending payment request or receiving payment status, purchase status unknown.Cancelled
— payment request sent, although, the user closed the payment screen on their app, thus, the payment result is unknown.InvalidPaymentState
— SDK payments error. May occur due to an incorrect return deeplink.
Please, note the purchase confirmation and cancellation scenarios.
### Consume (confirm) purchase
The state model of the purchase confirmation result has changed. Now confirmation may complete either successfully or with an error.
val purchasesUseCase: PurchasesUseCase = billingClient.purchases
purchasesUseCase.confirmPurchase(purchaseId = "purchaseId" , developerPayload = null )
.addOnSuccessListener {
// Process success
}.addOnFailureListener { throwable: Throwable ->
// Process error
}
Purchase cancellation
The model of the purchase cancellation result has changed. Now cancellation may end either successfully or with an error.
val purchasesUseCase: PurchasesUseCase = billingClient.purchases
purchasesUseCase.deletePurchase(purchaseId = "purchaseId" )
.addOnSuccessListener {
// Process success
}.addOnFailureListener { throwable: Throwable ->
// Process error
}
Purchase confirmation and cancellation scenario
Due to the change of the product purchase model result, the business logic of the purchase confirmation and cancellation was also changed.
Use the deletePurchase
method in the following cases.
- The
getPurchases
method returned a purchase with thePurchaseState.CREATED
orPurchaseState.INVOICE_CREATED
status.
In some cases, after paying with a bank app (SBP, SberPay, T-Pay etc. ), the payment status may still be PurchaseState.INVOICE_CREATED
after returning to the app. This is caused by the purchase processing time by the bank. In this case, you need to adapt your screen lifecycle to the product list retrieval logic. Alternatively, you can implement cancellation of purchases in the PurchaseState.INVOICE_CREATED
state only through user action in your app. For example, create a dedicated button for this purpose.
- The
purchaseProduct
method returnedPaymentResult.Cancelled
. - The
purchaseProduct
returnedPaymentResult.Failure
.
Use the confirmPurchase
method if the getPurchases
method returned a CONSUMABLE
purchase with the PurchaseState.PAID
status.