Skip to main content

Update to RuStore SDK 2.2.0: Purchase models, dependencies and migration

In version 2.2.0 the 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:2.2.0" )
}

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
}

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.
info

Please, note the purchase confirmation and cancellation scenarios.

### Confirm (consume) 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 one of the following statuses:

    • PurchaseState.CREATED;
    • PurchaseState.INVOICE_CREATED;
  • the purchaseProduct method returned:

    • PaymentResult.Cancelled;
    • PaymentResult.Failure.

Use the (confirmPurchase) method if the (getPurchases) method returned a CONSUMABLE purchase with the PurchaseState.PAID status.