8.0.1-alpha01 (Beta)
With RuStore you can integrate payments in your mobile app.
-
If you don't know where to start read the instruction.
-
If you migrate to Pay SDK from billingClient SDK, see the migration instructions. For more details, see here.
Getting Started
- Installation via .unitypackage
- Installation via Package Manager
Download the files below:
Import files to your project with Package Manager (Window > Package Manager > + > Add package from tarball...).
The dependencies are connected automatically with External Dependency Manager.
- Open package manager window (Window > Package Manager > + > Add package from git URL...).
- Use the https://github.com/googlesamples/unity-jar-resolver.git?path=/upm link to connect the External Dependency Manager package.
- To cure the
Google.IOSResolver.dll will not be loaded
error, install the iOS build module for your version of Unity (UnityHub > Installs > Your version of Unity > Add modules > iOS Build Support).
Assembly 'Packages/com.google.external-dependency-manager/ExternalDependencyManager/Editor/1.2.182/Google.IOSResolver.dll' will not be loaded due to errors:
Unable to resolve reference 'UnityEditor.iOS.Extensions.Xcode'. Is the assembly missing or incompatible with the current platform?
Reference validation can be disabled in the Plugin Inspector.
If you use macOS, change Archive Utility settings. Uncheck Keep expanding if possible. Otherwise, the project archive will not be downloaded correctly.
Download RuStoreUnityPaySDK-version.unitypackage
and import it to your project (Assets > Import Package > Custom Package). The dependencies are connected automatically with External Dependency Manager (included in .unitypackage).
If you use macOS, change Archive Utility settings. Uncheck Keep expanding if possible. Otherwise, the project archive will not be downloaded correctly.
For proper SDK dependencies processing set the following settings.
For proper SDK dependencies processing set the following settings.
-
Open project settings: Edit > Project Settings > Player > Android Settings.
-
In the Publishing Settings section enable to following settings.
- Custom Main Manifest.
- Custom Main Gradle Template.
- Custom Gradle Properties Template.
-
In the Other Settings section configure:
- package name.
- Minimum API Level = 24.
- Target API Level = 34.
-
Open the External Dependency Manager settings: Assets > External Dependency Manager > Android Resolver > Settings and enable the following settings.
- Use Jetifier.
- Patch mainTemplate.gradle.
- Patch gradleTemplate.properties.
-
Update project dependencies: Assets > External Dependency Manager > Android Resolver > Force Resolve.
Initialization
Initialize the library before calling its methods. The initialization itself is done automatically, however, for your SDK to work, in your Manifest.xml
file define console_app_id_key
and internal_config_key
.
<!-- Initializing sdk -->
<meta-data android:name="console_app_id_key" android:value="@string/rustore_PayClientSettings_consoleApplicationId" />
<meta-data android:name="internal_config_key" android:value="@string/rustore_PayClientSettings_internalConfigKey" />
Both values must be inside the <application>
tag
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.unity3d.player"
xmlns:tools="http://schemas.android.com/tools">
<application>
<activity android:name="com.unity3d.player.UnityPlayerActivity"
android:theme="@style/UnityThemeSelector">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
</activity>
<!-- Initializing sdk -->
<meta-data android:name="console_app_id_key" android:value="@string/rustore_PayClientSettings_consoleApplicationId" />
<meta-data android:name="internal_config_key" android:value="@string/rustore_PayClientSettings_internalConfigKey" />
</application>
</manifest>
console_app_id_key
— 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
.
- The
ApplicationId
specified inbuild.gradle
must match theapplicationId
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
).
For security purposes, the SDK sets android:usesCleartextTraffic="false"
by default to prevent data transmission over unsecured HTTP and protect against "Man-in-the-Middle" attacks. If your application requires the use of HTTP, you can change this attribute to true
, but do so at your own risk, as it increases the chance of data interception and tampering. We recommend allowing unsecured traffic only in exceptional cases and for trusted domains, preferring HTTPS for all network interactions.
The console_app_id_key
value is set in the PayClientSettings.assets
file. To create the PayClientSettings.assets
file, in the Unity editor select Window > RuStore SDK > Settings > PayClient.
The internal_config_key
value is set in the PayClientSettings.assets
automatically.
Do not specify console_app_id_key
and internal_config_key
in the manifest directly. The strings must be placed in a resource file that is generated automatically based on PayClientSettings.assets
data.
Handling Deeplinks
A deeplink in the RuStore Payments SDK is required for proper interaction with third-party payment applications. It helps users complete purchases faster in an external app and return to your application.
To set up deeplink support in your application and the RuStore SDK, specify the deeplinkScheme
inside your AndroidManifest
file and override the onNewIntent
method of your Activity
. Additionally, for the SDK to work, you need to specify sdk_pay_scheme_value
in your Manifest.xml file.
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.unity3d.player"
xmlns:tools="http://schemas.android.com/tools">
<application>
<activity android:name="ru.rustore.unitysdk.RuStoreUnityPayActivity"
android:theme="@style/UnityThemeSelector"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="@string/rustore_PayClientSettings_deeplinkScheme" />
</intent-filter>
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
</activity>
<meta-data android:name="console_app_id_value" android:value="@string/rustore_PayClientSettings_consoleApplicationId" />
<meta-data android:name="internal_config_key" android:value="@string/rustore_PayClientSettings_internalConfigKey" />
<!-- Deeplink scheme -->
<meta-data android:name="sdk_pay_scheme_value" android:value="@string/rustore_PayClientSettings_deeplinkScheme" />
</application>
</manifest>
The value of sdk_pay_scheme_value
is set in the PayClientSettings.assets
file. To create the PayClientSettings.assets
file, in the Unity editor menu select: Window → RuStore SDK → Settings → PayClient.
Next, extend the UnityPlayerActivity
class and add handling for the incoming intent
in onNewIntent
.
package ru.rustore.unitysdk;
import android.os.Bundle;
import android.content.Intent;
import ru.rustore.unitysdk.payclient.RuStoreUnityPayClient;
import com.unity3d.player.UnityPlayerActivity;
public class RuStoreUnityPayActivity extends UnityPlayerActivity {
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState == null) {
RuStoreUnityPayClient.INSTANCE.proceedIntent(getIntent());
}
}
@Override protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
RuStoreUnityPayClient.INSTANCE.proceedIntent(intent);
}
}
Place the Java file with the extension of UnityPlayerActivity
in the Assets
folder of your project. If you already have your own extension of UnityPlayerActivity
, move the code for the onCreate
and onNewIntent
functions into it.
SDK Methods
Available public methods:
GetPurchase
— allows you to get information about a purchase by its ID.GetPurchases
— allows you to retrieve user purchases. This method supports optional filtering by product type (consumable or non-consumable products), as well as by purchase status (statusesPAID
andCONFIRMED
are supported). By default, the filters are disabled, and all user purchases (regardless of product type) with statusesPAID
andCONFIRMED
will be returned.GetPurchaseAvailability
— returns the result of checking payment availability.Purchase
— allows you to make a product purchase with the desired payment type specified: single-stage (ONE_STEP
) or two-stage (TWO_STEP
). For this method, all payment options are available on the payment sheet. If the parameter is not specified, single-stage payment is used by default.
If the payment type TWO_STEP
is specified, an attempt will be made to initiate a two-stage payment, but the final result will directly depend on the payment method (card, SBP, etc.) selected by the user. Two-stage payment is available only for a specific set of payment methods (currently — only for cards). SBP technologies do not support two-stage payment. If a payment method that does not support holding is selected, the purchase will be processed using the single-stage scenario.
PurchaseTwoStep
— initiates a guaranteed two-stage purchase scenario. When using this method, the payment sheet presents the user only with payment methods that support two-stage payment. During the payment process, the buyer's funds are first held and are debited only after the purchase is confirmed using theConfirmTwoStepPurchase
method.ConfirmTwoStepPurchase
— confirms a purchase made using two-stage payment.CancelTwoStepPurchase
— cancels a purchase made using two-stage payment.GetProducts
— allows you to get information about active products published in the RuStore console.
This method returns no more than 1000 products and works without authorization or the RuStore app being installed on the user's device.
RuStoreCoreClient.Instance
block — a set of public methods, such as:IsRuStoreInstalled
— checks if the RuStore app is installed on the user's device.OpenRuStoreDownloadInstruction
— opens a web page for downloading the RuStore app.OpenRuStore
— launches the RuStore app.OpenRuStoreAuthorization
— launches the RuStore app for authorization. After successful user authorization, the RuStore app will automatically close.
Checking Payment Availability
To check purchase availability, call the GetPurchaseAvailability
method. On calling, the following conditions are checked.
- The current version of RuStore is installed on the user's device.
- RuStore app supports payments.
- User is authorized in RuStore.
- The user and the app are not banned in RuStore.
- In-app purchases for the app are enabled in RuStore Console.
PurchaseAvailabilityResult.Available
is returned.
Otherwise, PurchaseAvailabilityResult.Unavailable(val cause: Throwable)
is returned, where cause
is an error of a failed condition. To check what caused such result, check error type for RuStoreException
(error data is described in Errors).
RuStorePayClient.Instance.GetPurchaseAvailability(
onFailure: (error) => {
// Process error
},
onSuccess: (result) => {
if (result.isAvailable) {
// Process success
}
else {
// Process result.cause
}
});
Retrieving Product List
You checked that payments are available and the users are able to make purchases. Now you can request products list. Use the getProducts
method to request the information about products added to your app in RuStore Console.
ProductId[] ids = ...
RuStorePayClient.Instance.GetProducts(
productIds: ids,
onFailure: (error) => {
// Process error
},
onSuccess: (result) => {
// Process success
});
ProductId[] productIds
— the list of product IDs that are set when products are created in the RuStore Console. The list is limited by 1000 items.
Where are product IDs in the RuStore Console?
- Navigate to the Applications tab and selected the needed app.
- Select Monetization in the left menu.
- Select product type: Subscriptions or In-App purchases.
- Copy the IDs of the required products.
The method returns products list. Below is the product pattern.
public class Product : BaseFields {
public AmountLabel amountLabel { get; }
public Currency currency { get; }
public Description? description { get; }
public Url imageUrl { get; }
public Price? price { get; }
public ProductId productId { get; }
public Title title { get; }
public ProductType type { get; }
...
}
productId
— product ID assigned to product in RuStore Console (mandatory).type
— product type.CONSUMABLE/NON-CONSUMABLE
amountLabel
— formatted purchase price, including currency symbol.price
— price in minimum currency units.currency
— ISO 4217 currency code.title
— product name inlanguage
.description
— descriptions inlanguage
.imageUrl
— image URL.
Retrieving Purchase List
Go get the user's purchases list, use theGetPurchases
method.
RuStorePayClient.Instance.GetPurchases(
onFailure: (error) => {
// Process error
},
onSuccess: (result) => {
// Process success
});
The method supports optional filtering by product type (consumable or non-consumable products).
RuStorePayClient.Instance.GetPurchases(
productType: ProductType.CONSUMABLE_PRODUCT,
onFailure: (error) => {
// Process error
},
onSuccess: (result) => {
// Process success
});
By default, the filter is disabled and will return all user purchases with statuses PAID
and CONFIRMED
. The PAID
status means that the funds have been successfully held and the purchase is awaiting confirmation from the developer. The purchase model is shown below.
public class Purchase : BaseFields {
public PurchaseId purchaseId { get; }
public ProductId productId { get; }
public InvoiceId invoiceId { get; }
public OrderId? orderId { get; }
public PurchaseType purchaseType { get; }
public ProductType productType { get; }
public Description description { get; }
public DateTime? purchaseTime { get; }
public Price price { get; }
public AmountLabel amountLabel { get; }
public Currency currency { get; }
public Quantity quantity { get; }
public PurchaseStatus status { get; }
public DeveloperPayload? developerPayload { get; }
public bool sandbox { get; }
...
}
purchaseId
— product ID. Used to obtain purchase information in the SDK via the purchase information retrieval method.productId
— product ID assigned to product in RuStore Console (mandatory).invoiceId
— invoice ID. Used for server-side payment validation, searching payments in the developer console, and is also displayed to the user in the payment history in the RuStore mobile app.orderId
- unique payment identifier specified by the developer or generated automatically (uuid
).PurchaseType
— purchase type:ONE_STEP
- one-stage payment;TWO_STEP
- two-stage payment;UNDEFINED
— number of payment stages is undefined.
productType
— product type. (CONSUMABLE
/NON-CONSUMABLE
- consumable/non-consumable.)description
- purchase description.purchaseTime
— purchase time.price
— price in minimum currency units.amountLabel
— formatted purchase price, including currency symbol.currency
— ISO 4217 currency code.quantity
— product quantity.status
— purchase state:INVOICE_CREATED
— purchase invoice is created and awaiting payment;CANCELLED
— purchase canceled by the user;PROCESSING
— payment initiated;REJECTED
— purchase rejected (for example: due to insufficient funds);EXPIRED
— payment time expired;PAID
— only for two-stage payments, intermediate status, funds are put on hold on the user's account, the purchase is awaiting confirmation from the developer;CONFIRMED
— purchase successfully paid for;REFUNDING
— refunding initiated, request sent to the acquirer;REFUNDED
— purchase successfully refunded;REVERSED
— only for two-stage payment: wither the purchase was canceled by the developer or there was no payment within 6 hours, the funds on the user's account are put off hold.
-
developerPayload
— a string with additional order information that you can set when confirming the purchase. This string overrides the value set during initialization -
— test payment flag.
true
— test payment,false
— actual payment
Retrieving Purchase Details
Go get purchase information, use thegetPurchase
method.
RuStorePayClient.Instance.GetPurchase(
purchaseId: purchase.purchaseId,
onFailure: (error) => {
// Process error
},
onSuccess: (response) => {
// Process success
});
The method returns information about a specific purchase in any status. The purchase model is shown below.
public class Purchase : BaseFields {
public PurchaseId purchaseId { get; }
public ProductId productId { get; }
public InvoiceId invoiceId { get; }
public OrderId? orderId { get; }
public PurchaseType purchaseType { get; }
public ProductType productType { get; }
public Description description { get; }
public DateTime? purchaseTime { get; }
public Price price { get; }
public AmountLabel amountLabel { get; }
public Currency currency { get; }
public Quantity quantity { get; }
public PurchaseStatus status { get; }
public DeveloperPayload? developerPayload { get; }
public bool sandbox { get; }
...
}
purchaseId
— product ID. Used to obtain purchase information in the SDK via the purchase information retrieval method.productId
— product ID assigned to product in RuStore Console (mandatory).invoiceId
— invoice ID. Used for server-side payment validation, searching payments in the developer console, and is also displayed to the user in the payment history in the RuStore mobile app.orderId
- unique payment identifier specified by the developer or generated automatically (uuid
).PurchaseType
— purchase type:ONE_STEP
- one-stage payment;TWO_STEP
- two-stage payment;UNDEFINED
— number of payment stages is undefined.
productType
— product type. (CONSUMABLE
/NON-CONSUMABLE
- consumable/non-consumable.)description
- purchase description.purchaseTime
— purchase time.price
— price in minimum currency units.amountLabel
— formatted purchase price, including currency symbol.currency
— ISO 4217 currency code.quantity
— product quantity.status
— purchase state:INVOICE_CREATED
— purchase invoice is created and awaiting payment;CANCELLED
— purchase canceled by the user;PROCESSING
— payment initiated;REJECTED
— purchase rejected (for example: due to insufficient funds);EXPIRED
— payment time expired;PAID
— only for two-stage payments, intermediate status, funds are put on hold on the user's account, the purchase is awaiting confirmation from the developer;CONFIRMED
— purchase successfully paid for;REFUNDING
— refunding initiated, request sent to the acquirer;REFUNDED
— purchase successfully refunded;REVERSED
— only for two-stage payment: wither the purchase was canceled by the developer or there was no payment within 6 hours, the funds on the user's account are put off hold.
-
developerPayload
— a string with additional order information that you can set when confirming the purchase. This string overrides the value set during initialization -
— test payment flag.
true
— test payment,false
— actual payment
Purchase Status Model
One-stage payment status model.
Two-stage payment status model.
Product Purchase
- When using a single-stage payment, the purchase does not require confirmation; the funds are immediately debited from the buyer’s account, and a commission is charged to the developer. In this case, if a refund to the customer is required (for example, if the product cannot be delivered for some reason), a refund can only be processed via the RuStore Console, and the funds will be returned to the buyer within a few days. The full purchase amount is refunded, but the commission previously withheld from the developer is not reimbursed.
- In the case of a two-stage payment, the funds are first held (authorized) on the buyer’s account. No commission is charged at this stage. After the hold, the purchase requires either confirmation or cancellation. The commission is charged to the developer upon purchase confirmation. Cancelling the purchase releases the hold, and the funds instantly become available to the buyer again.
Two-stage payment is available only for a specific set of payment methods (currently — only for cards). SBP technologies do not support two-stage payment. If a payment method that does not support holding funds is selected, the purchase will be processed using the single-stage scenario.
Payment with Purchase Type Selection
To initiate a product purchase with the option to select the payment stage, use the Purchase
method:
var parameters = new ProductPurchaseParams(
productId: new ProductId("product_id"),
quantity: new Quantity(1),
appUserId: null,
orderId: null,
developerPayload: null
);
RuStorePayClient.Instance.Purchase(
parameters: parameters,
preferredPurchaseType: PreferredPurchaseType.ONE_STEP,
onFailure: (error) => {
switch (error) {
case RuStorePaymentException.ProductPurchaseCancelled cancelled:
// Handle cancelled purchase
break;
case RuStorePaymentException.ProductPurchaseException exception:
// Handle failed purchase
break;
default:
// Handle other error
break;
}
},
onSuccess: (result) => {
// Process success
});
productId
— product ID assigned to product in RuStore Console (mandatory).quantity
— product amount (optional, value1
will be used if not specified).orderId
— payment ID generated by the app (optional). If you specify this parameter in your system, you will receive it via our API. If not specified, will be generated automatically (uuid). 150 characters max.developerPayload
— a string with additional order information that you can set when confirming the purchase. This string overrides the value set during initialization. Maximum length is 250 characters.-
appUserId
— the internal user ID in your application (optional parameter). A string with a maximum length of 128 characters.tipFor example, this parameter can be used to detect cases of fraud in your application, which will help improve its security.
preferredPurchaseType
— the desired purchase type: single-stage (ONE_STEP
) or two-stage (TWO_STEP
).
This method is launched by default using the single-stage payment scenario (preferredPurchaseType = PreferredPurchaseType.ONE_STEP
), i.e., without funds being held.
For two-stage payment, you need to specify preferredPurchaseType = PreferredPurchaseType.TWO_STEP
. Two-stage payment (i.e., payment with funds being held) is not guaranteed for this method and directly depends on the payment method (card, SPB, etc.) selected by the user.
When launching this method (with the preferred preferredPurchaseType = twoStep
), until the user selects a payment method, the purchase stage will be UNDEFINED
. Please take this behavior into account when handling purchase cancellation results (ProductPurchaseCancelled
) or purchase errors (ProductPurchaseException
).
Two-stage payment (with funds holding)
To initiate a product purchase using the two-stage scenario, use the PurchaseTwoStep
method:
When calling this method, the user will have access to a limited set of payment methods — only those that support two-stage payment.
var parameters = new ProductPurchaseParams(
productId: new ProductId("product_id"),
appUserId: null,
developerPayload: null,
orderId: null,
quantity: new Quantity(1));
RuStorePayClient.Instance.PurchaseTwoStep(
parameters: parameters,
onFailure: (error) => {
switch (error) {
case RuStorePaymentException.ProductPurchaseCancelled cancelled:
// Handle cancelled purchase
break;
case RuStorePaymentException.ProductPurchaseException exception:
// Handle failed purchase
break;
default:
// Handle other error
break;
}
},
onSuccess: (result) => {
// Process success
});
Purchase Parameters Structure
public class ProductPurchaseParams : BaseFields {
public ProductId productId { get; }
public AppUserId? appUserId { get; }
public Quantity? quantity { get; }
public OrderId? orderId { get; }
public DeveloperPayload? developerPayload { get; }
...
}
productId
— product ID assigned to product in RuStore Console (mandatory).quantity
— product amount (optional, value1
will be used if not specified).orderId
— payment ID generated by the app (optional). If you specify this parameter in your system, you will receive it via our API. If not specified, will be generated automatically (uuid). 150 characters max.developerPayload
— a string with additional order information that you can set when confirming the purchase. This string overrides the value set during initialization. Maximum length is 250 characters.-
appUserId
— the internal user ID in your application (optional parameter). A string with a maximum length of 128 characters.tipFor example, this parameter can be used to detect cases of fraud in your application, which will help improve its security.
Purchase Result Structure
public sealed class ProductPurchaseResult : BaseFields {
public PurchaseId purchaseId { get; }
public ProductId productId { get; }
public InvoiceId invoiceId { get; }
public OrderId? orderId { get; }
public PurchaseType purchaseType { get; }
public bool sandbox { get; }
...
}
ProductPurchaseResult
— the result of a successful digital product payment (for single-stage payment) or successful funds holding (for two-stage payment).purchaseId
— purchase identifier. Used to obtain purchase information in the SDK via the purchase information retrieval method.productId
— identifier of the purchased product, specified when created in the RuStore developer console.invoiceId
— invoice identifier. Used for server-side payment validation, searching payments in the developer console, and is also displayed to the user in the payment history in the RuStore mobile app.orderId
— unique payment identifier specified by the developer or generated automatically (uuid
).purchaseType
— purchase type (ONE_STEP
/TWO_STEP
— single-stage/two-stage).sandbox
— flag indicating a test payment in the sandbox. IfTRUE
, the purchase was made in test mode.
Error Handling
If an error occurs during payment or the user cancels the purchase, the execution of the payment method (both with purchase type selection and the two-stage method) will complete with an error:
ProductPurchaseException
— product purchase error.ProductPurchaseCancelled
— error caused by purchase cancellation (the user closed the payment sheet) before receiving the purchase result. In this case, it is recommended to additionally check the purchase status using the purchase information retrieval method.
Error and cancellation structure:
public sealed class ProductPurchaseException : RuStorePaymentException {
public InvoiceId? invoiceId { get; }
public OrderId? orderId { get; }
public ProductId? productId { get; }
public PurchaseId? purchaseId { get; }
public PurchaseType? purchaseType { get; }
public Quantity? quantity { get; }
...
}
public sealed class ProductPurchaseCancelled : RuStorePaymentException {
public PurchaseId? purchaseId { get; }
public PurchaseType? purchaseType { get; }
...
}
Server-Side Purchase Validation
If you need to validate a successful purchase on the RuStore server, you can use the invoiceId
from the SuccessProductPurchaseResult
model returned after a successful product purchase.
var parameters = new ProductPurchaseParams(
productId: new ProductId("product_id"));
RuStorePayClient.Instance.Purchase(
parameters: parameters,
preferredPurchaseType: PreferredPurchaseType.TWO_STEP,
onFailure: (error) => {
// Process error
},
onSuccess: (result) => {
var invoiceId = result.invoiceId.value;
yourApi.validate(invoiceId);
});
You can also get the invoiceId
from the Purchase
model. The Purchase
model can be obtained using the GetPurchases()
method or the GetPurchase
method.
RuStorePayClient.Instance.GetPurchases(
onFailure: (error) => {
// Process error
},
onSuccess: (result) => {
result.ForEach(item => {
yourApi.validate(item.subscriptionToken);
});
});
Confirming (Consuming) a Purchase
Only purchases initiated using the two-stage payment scenario (i.e., with funds being held) require confirmation. Such purchases, after successful holding, will have the status PurchaseStatus.PAID
.
To debit funds from the buyer's card, the purchase must be confirmed. For this, you should use the ConfirmTwoStepPurchase
method.
PurchaseId id = ...
DeveloperPayload payload = ...
RuStorePayClient.Instance.ConfirmTwoStepPurchase(
purchaseId: purchaseId,
developerPayload: payload,
onFailure: (error) => {
// Process error
},
onSuccess: () => {
// Process success
});
purchaseId
— product ID.developerPayload
— a string with additional order information that you can set when confirming the purchase. This string overrides the value set during initialization (optional). Maximum 250 characters. If provided, it replaces the value set at the start of the purchase via thePurchase
/PurchaseTwoStep
method.
Canceling a Purchase
With our SDK you can cancel only the purchases that undergo a two-stage payment process, i.e. when the user's money is put on hold. After a successful hold, such purchases are in the PurchaseStatus.PAID
status. If a purchase is canceled it has the PurchaseStatus.REVERSED
status.
Cancel purchases if you cannot deliver your product after payment is made (when the user's money is put on hold).
To cancel a purchase (put the user's money off hold), use the CancelTwoStepPurchase
method.
PurchaseId id = ...
RuStoreBillingClient.Instance.CancelTwoStepPurchase(
purchaseId: id,
onFailure: (error) => {
// Process error
},
onSuccess: () => {
// Process success
}
);
purchaseId
— product ID.
Error Handling
RuStorePaymentNetworkException
— SDK network communication error;RuStorePaymentCommonException
— general SDK error;RuStorePayClientAlreadyExist
— duplicate initialization error SDK;RuStorePayClientNotCreated
— attempt to access public SDK interface before initialisation;RuStorePayInvalidActivePurchase
— payment initiated for unknown product type;RuStorePayInvalidConsoleAppId
— mandatory parameterсonsole_application_id
for SDK initialisation not set;RuStorePaySignatureException
— invalid signature (occurs because of fraud actions);EmptyPaymentTokenException
— error receiving payment token;RuStoreNotInstalledException
— RuStore is not installed on the user's device;RuStoreOutdatedException
— RuStore version installed on the user's device does not support this SDK;RuStoreUserUnauthorizedException
— user is not authorized in RuStore;RuStoreApplicationBannedException
— app is banned in RuStore RuStore;RuStoreUserBannedException
— user is blocked in RuStore;RuStoreException
— basic RuStore error from which other errors are inherited.