3.0.0
该门户网站正在开发中。文档的完整版本请看这里.
实现示例
为了正确集成支付,建议您参阅示例应用程序:https://gitflic.ru/project/rustore/flutter-rustore-billing
支付条件
为了进行支付,必须遵守所有条件:
- 用户的设备上安装了RuStore应用程序。
- 用户在RuStore应用程序中已授权。
- 用户和应用程序不应在RuStore中被封锁。
- 在RuStore 控制台系统中为应用程序启用了购买功能。
服务在俄罗斯联邦以外有一些运作限制。
在项目中集成
要将支付包连接到项目,您需要执行以下命令:
flutter pub add flutter_rustore_billing
个命令将在 pubspec.yaml 文件中添加一个字符串。
dependencies: flutter_rustore_billing: ^3.0.0
处理deeplink
为了通过第三方应用程序(如快速支付系统(SBP)或SberPay)正确进行支付,您需要正确实现 deeplink 的处理。为此,您需要在 AndroidManifest.xml 中指定带有您项目scheme的 intent-filter:
AndroidManifest.xml
<activity
android:name=".sample.MainActivity">
<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="yourappscheme"/>
</intent-filter> </activity>
中"yourappscheme" - 您的deeplink方案,可以更改为其他方案。
这个方案应与 initialize() 方法中传递的方案匹配。
初始化
在调用库的方法之前,需要先进行其初始化。为了初始化,请调用 RustoreBillingClient.initialize() 方法:
RustoreBillingClient.initialize(
"123456" ,
"yourappscheme://iamback" ,
).then((value) {
print( "initialize success: $value" );
}, onError: (err) {
print( "initialize err: $err" );});
123456 - 来自RuStore开发者控制台的应用程序代码(例如:https://console.rustore.ru/apps/123456)。
yourappscheme://iamback
- 用于通过第三方应用程序支付后返回您的应用程序的deeplink方案 (例如通过 SberPay 或快速支付系统(SBP))。SDK 会为这个方案生成它自己的宿主。
要的是,传递给 deeplinkScheme 的 deeplink 方案必须与 AndroidManifest.xml 中"[处理] deeplink"部分指定的方案匹配。
检查支付功能的可用性
为了检查支付 的可用性,需要满足以下条件:
- 用户的设备上必须安装 RuStore。
- RuStore 必须支持支付功能。
- 用户必须在 RuStore 中获得授权。
- 用户和应用程序不应在RuStore中被封锁。
- 应用程序必须在 RuStore 控制台系统中启用购买功能。
果所有条件都满足,RustoreBillingClient.available() 方法将返回 true 值。
RustoreBillingClient.available().then((value) {
print("available success $value");
}, onError: (err) {
print("available err: $err");
});
获取产品列表
为了获取产品,您需要使用 RustoreBillingClient.products(ids) 方法。
RustoreBillingClient.products(ids).then((response) {
for ( final product in response.products) {
print(product?.productId);
}
}, onError: (err) {
print("products err: $err");
});
ids: List\<String?\>
- 产品标识符列表。
方法返回ProductsResponse:
class ProductsResponse {
int code;
String? errorMessage;
String? errorDescription;
String? traceId;
List<Product?> products;
List<DigitalShopGeneralError?> errors;
}
code
- 响应代码;errorMessage
- 错误消息;errorDescription
- 错误描述;traceId
- 错误标识符;errors
- 错误列表;products
- 产品列表。
igitalShopGeneralError 错误的结构:
class DigitalShopGeneralError {
String? name;
int ? code;
String? description
}
name
- 错误名称;code
- 错误代码;description
- 错误描述。
品结构Product:
class Product {
String productId;
String? productType;
String productStatus;
String? priceLabel;
int ? price;
String? currency;
String? language;
String? title;
String? description;
String? imageUrl;
String? promoImageUrl;
Subscription? subscription;
}
productId
- 产品标识符;productType
- 产品类型;productStatus
- 产品状态;priceLable
- 格式化的产品价格,包括[language]语言的货币符号;price
- 以最小单位(戈比)表示的价格;currency
- ISO 4217货币代码;language
- 使用 BCP 47 编码指定的语言;title
- 产品名称,以[language]语言表示;description
- 产品描述,以[language]语言表示;imageUrl
- 图片链接;promoImageUrl
- 促销图片链接;subscription
- 订阅描述,仅对于类型为 subscription 的产品返回。
阅结构Subscription:
class Subscription {
SubscriptionPeriod? subscriptionPeriod;
SubscriptionPeriod? freeTrialPeriod;
SubscriptionPeriod? gracePeriod;
String? introductoryPrice;
String? introductoryPriceAmount;
SubscriptionPeriod? introductoryPricePeriod;
}
subscriptionPeriod
- 订阅周期;freeTrialPeriod
- 订阅试用期;gracePeriod
- 订阅宽限期;introductoryPrice
- 格式化的介绍性订阅价格,包括product:language语言的货币符号;introductoryPriceAmount
- 以货币最小单位(戈比)表示的介绍性价格;introductoryPricePeriod
- 介绍性价格计算周期。
阅周期结构SubscriptionPeriod:
class SubscriptionPeriod {
int years;
int months;
int days;
}
years
- 年数;months
- 月数;days
- 天数。
获取购买列表
要获取购买列表,请使用RustoreBillingClient.purchases()方法:
RustoreBillingClient.purchase(id).then((response) {
print("purchase success: $response");
}, onError: (err) {
print("purchase err: $err");
});