Migrating to version 2.2.0
In version 2.2.0 thePaymentResult
models were significantly changed.
Use this manual to switch to new SDK version.
Dependency update
- Kotlin
- Java
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" )
}
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
- Kotlin
- Java
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
}
The model of the receiving products list result has changed. Now the getProducts()
method instantly returns the products list.
ProductsUseCase productsUseCase = billingClient.getProducts();
productsUseCase.getProducts(Arrays.asList("id1" , "id2")).addOnCompleteListener( new OnCompleteListener<List<Product>>() {
@Override
public void onFailure( @NonNull Throwable throwable) {
// Process error
}
@Override
public void onSuccess(List<Product> products) {
// Process success
}
});
Purchasing product
- Kotlin
- Java
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.
The model of the purchase result has changed. Below is the updated model.
interface PaymentResult {
interface Success extends PaymentResult {
@Nullable
public String getOrderId();
public String getPurchaseId();
public String getProductId();
public String getInvoiceId();
@Nullable
public String getSubscriptionToken();
}
interface Failure extends PaymentResult {
@Nullable
public String getPurchaseId();
@Nullable
public String getInvoiceId();
@Nullable
public String getOrderId();
@Nullable
public Integer getQuantity();
@Nullable
public String getProductId();
@Nullable
public Integer getErrorCode();
}
interface Cancelled extends PaymentResult {
public String getPurchaseId();
}
interface InvalidPaymentState extends 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
- Kotlin
- Java
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
}
The state model of the purchase confirmation result has changed. Now confirmation may complete either successfully or with an error.
PurchasesUseCase purchasesUseCase = billingClient.getPurchases();
purchasesUseCase.confirmPurchase("purchaseId", "developerPayload").addOnCompleteListener( new OnCompleteListener<Unit>() {
@Override
public void onFailure( @NonNull Throwable throwable) {
// Process error
}
@Override
public void onSuccess(Unit result) {
// Process success
}
});
Purchase cancellation
- Kotlin
- Java
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
}
The model of the purchase cancellation result has changed. Now cancellation may end either successfully or with an error.
PurchasesUseCase purchasesUseCase = billingClient.getPurchases();
purchasesUseCase.deletePurchase("purchaseId").addOnCompleteListener( new OnCompleteListener<Unit>() {
@Override
public void onFailure( @NonNull Throwable throwable) {
// Process error
}
@Override
public void onSuccess(Unit result) {
// Process success
}
});
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.