7.0.0 (Beta)
With RuStore you can integrate payments in your mobile app.
-
If you are in doubt read the instruction in the usage scenarios.
-
If you migrate to Pay SDK from billingClient SDK, please review the migration instructions. For more details, see here.
Prerequisites
- In-app purchases for the app are enabled in RuStore Console.
- The app must not be banned in RuStore.
- The current version of RuStore is installed on the user's device.
- User is authorized in RuStore.
- The user must is not banned in RuStore.
Connect to project
Adding repository
Add our repository as shown in the example below.
repositories {
maven {
url = uri("https://artifactory-external.vkpartner.ru/artifactory/maven")
}
}
Connecting the dependency
Add the following code to your configuration file to add the dependency.
dependencies {
implementation(platform("ru.rustore.sdk:bom:7.0.0"))
implementation("ru.rustore.sdk:pay")
}
Initialization
Initialize the library before calling its methods.
The initialization itself is done automatically, however, for your SDK to work, define console_app_id_key
in your manifest.xml
.
You can so it the following way:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="your.app.package.name">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.App"
tools:targetApi="n">
...
<meta-data
android:name="console_app_id_key"
android:value="@string/CONSOLE_APPLICATION_ID" />
</application>
</manifest>
-
CONSOLE_APPLICATION_ID
— product ID form the RuStore Console.
Where are app IDs in the RuStore Console?
- Navigate to the Applications tab and selected the needed app.
- Copy the ID from the URL address of the app page — it is a set of numbers between
apps/
and/versions
. FOr example, for URL addresshttps://console.rustore.ru/apps/123456/versions
the app ID is123456
.
ApplicationId
specified inbuild.gradle
, must matchapplicationId
of the APK file you published in the RuStore Console.-
The
keystore
signature must match the signature that was used to sign the app published in the RuStore Console. Make sure thatbuildType
used (example:debug
) uses the same signature as the published app (example:release
).
Working with SDK
Available public interactiors:
PurchaseInteractor
- interactor that works with payments and has several public methods.getPurchase(purchaseId: PurchaseId): Task<Purchase>
- gets purchase information by its ID.getPurchases(productType: ProductType? = null): Task<List<Purchase>>
- retrieves the user's purchases. This method supports an optional product type filter (consumable and non-consumable goods). By default, this filter is disabled (regardless of the product type) — that means that all user purchases in thePAID
andCONFIRMED
will be returned.PAID
- the money on the user's account is put on hold, the developer's action is required: purchase confirmation or cancellation.getPurchaseAvailability(): Task<PurchaseAvailabilityResult>
- retrieves purchase availability status: whether the user can make a purchase.purchaseOneStep(params: Produc tPurchaseParams): Task<ProductPurchaseResult>
- starts a one-stage payment. With this method, the transaction is done without putting the user's money on hold on their account. If a payment is successful, the money is taken from the user's account instantly. You cannot cancel the payment, you can only refund the purchase from the RuStore Console.purchaseTwoStep(params: ProductPurchaseParams): Task<ProductPurchaseResult>
- start a two-stage payment. With this method, the money is put on hold on the user's account. If a purchase is successful, the money is taken from the user's account only after the developer's confirmation.confirmTwoStepPurchase(purchaseId: PurchaseId, developerPayload: DeveloperPayload? = null)
- confirm a two-stage payment.cancelTwoStepPurchase(purchaseId: PurchaseId)
- cancel a two-stage payment.
ProductInteractor
- interactor that works with products and has several public methods:getProducts(productsId: List<ProductId>): Task<List<Product>>
- retrieves information about active products published in the RuStore Console.
ImportantThis method returns up to 1000 products.
- the
RuStoreUtils
block - a set of public methods, such as:isRuStoreInstalled
- checks if the RuStore app is installed on the user's device.openRuStoreDownloadInstruction
- opens RuStore download page.openRuStore
- starts the RuStore app.openRuStoreAuthorization
- starts the RuStore for authorization. The RuStore app will be automatically closed after successful authorization.
Payments availability check
- Kotlin
- Java
To check purchase availability, call the getPurchaseAvailability
methods from PurchaseInteractor
. On calling, the following conditions are checked:
- The current version of RuStore is installed on the user's device.
- User is authorized in RuStore.
- The user and the app are not banned in RuStore.
- Monetization is enabled in the RuStore Console.
If all conditions are met, PurchaseAvailabilityResult.Available
is returned.
Otherwise, PurchaseAvailabilityResult.Unavailable(val cause: Throwable)
is returned, where cause
is an error of unmet conditions.
To figure out the cause of the error, check its type for RuStoreException
.
See Error handling.
RuStorePayClient.instance.getPurchaseInteractor().getPurchaseAvailability()
.addOnSuccessListener { result ->
when (result) {
is PurchaseAvailabilityResult.Available -> {
// Process purchases available
}
is PurchaseAvailabilityResult.Unavailable -> {
// Process purchases unavailable
}
}
}.addOnFailureListener { throwable ->
// Process unknown error
}
To check purchase availability, call the getPurchaseAvailability
methods from PurchaseInteractor
. On calling, the following conditions are checked:
- The current version of RuStore is installed on the user's device.
- User is authorized in RuStore.
- The user and the app are not banned in RuStore.
- Monetization is enabled in the RuStore Console.
If all conditions are met, PurchaseAvailabilityResult.Available
is returned.
Otherwise, PurchaseAvailabilityResult.Unavailable(val cause: Throwable)
is returned, where cause
is an error of unmet conditions.
To figure out the cause of the error, check its type for RuStoreException
.
See Error handling.
PurchaseInteractor purchaseInteractor = RuStorePayClient.Companion.getInstance().getPurchaseInteractor();
purchaseInteractor.getPurchaseAvailability()
.addOnSuccessListener(result -> {
if (result instanceof PurchaseAvailabilityResult.Available) {
// Process purchases available
} else if (result instanceof PurchaseAvailabilityResult.Unavailable) {
// Process purchases unavailable
}
})
.addOnFailureListener(throwable -> {
// Process unknown error
});