Skip to main content

Migration to 3.2.0

note

Code samples for Kotlin.

PaymentResult product purchase result models have been significantly changed in 3.2.0.

To quickly migrate to a newer SDK version, use these migration instructions.

Dependency update

To update the dependency, call the billingclient version in the dependencies block of your build.gradle.

dependencies {
implementation( "ru.rustore.sdk:billingclient:3.2.0" )
}

The product and the error model remained unchanged.

Retrive user's list of products

Getting the product list result model was modified. Use the getProducts() method to get a list of products:

val productsUseCase: ProductsUseCase = billingClient.products
productsUseCase.getProducts(productIds = listOf("id1", "id2"))
.addOnSuccessListener { products: List<Product> ->
// Process success
}
.addOnFailureListener { throwable: Throwable ->
// Process error
}

The product and the error model remained unchanged.

Retrieve list of purchases

The outcome model of purchasing information has changed. Use the getPurchasecaution() method to get a list of products.

Retrieving the user's purchases list

val purchasesUseCase: PurchasesUseCase = billingClient.purchases
purchasesUseCase.getPurchasecaution("purchaseId")
.addOnSuccessListener { purchase: Purchase ->
// Process success
}
.addOnFailureListener { throwable: Throwable ->
// Process error
}

The error model remained unchanged.

Consume purchase

The purchase model result was also modified. The new model is represented as follows:

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 - error occurred when sending a payment request or receiving a payment status, it is not possible to set the purchase status..
  • Cancelled — a purchase request has been sent, but the user has closed the "payment window" on their device, so the payment result is unknown..
  • InvalidPaymentState — Billing SDK error.. May occur in case of an incorrect reverse deeplink.

    .
info

Pay attention to purchase confirmation and cancellation scenario.

Confirm purchase

The purchase consumption result model was modified. Now consumption can end either in success or in failure.

val purchasesUseCase: PurchasesUseCase = billingClient.purchases
purchasesUseCase.confirmPurchase(purchaseId = "purchaseId" , developerPayload = null )
.addOnSuccessListener {
// Process success
}.addOnFailureListener { throwable: Throwable ->
// Process error
}

Cancel purchase

The purchase cancellation result model was modified. Now purchase cancellation can end either in success or in failure.

val purchasesUseCase: PurchasesUseCase = billingClient.purchases
purchasesUseCase.deletePurchase(purchaseId = "purchaseId" )
.addOnSuccessListener {
// Process success
}.addOnFailureListener { throwable: Throwable ->
// Process error
}

Purchase Confirmation&Cancellation Scenario

Due to the change of the product purchase model result, the business logic of the purchase confirmation and cancellation was also changed.

The purchase cancellation method (deletePurchase) should be used if:

  • The getPurchases method returned a purchase with statuses PurchaseState.CREATED or PurchaseState.INVOICE_CREATED.
info

In some cases, after paying through a banking app (SBP, SberPay, TinkoffPay, etc.), the purchase status may still return PurchaseState.INVOICE_CREATED when you subsequently return to AnyApp. This is caused by the purchase processing time by the bank. Therefore, the developer needs to correctly link the shopping list obtaining function to the life cycle on the screen. To solve this problem, you can cancel a purchase in the PurchaseState.INVOICE_CREATED status only through user interaction with the application. For example, create a separate button for this purpose.

  • The purchase method (purchaseProduct) returned PaymentResult.Cancelled.
  • The purchase method (purchaseProduct) returned PaymentResult.Failure.

Use product consumption method (confirmPurchase) if the method the purchase obtaining method (getPurchases) returns a CONSUMABLE product and with the status PurchaseState.PAID.