5.0.0
该门户网站正在开发中。文档的完整版本请看这里.
为了进行支付,必须遵守以下条件:
- 用户的设备上必须安装 RuStore。
- 用户必须在 RuStore 中获得授权。
- 用户和应用程序不应在RuStore中被封锁。
- 应用程序必须在 RuStore 控制台系统中启用购买功能。
- Unreal Engine 4.26或更高版本。
在项目中集成
- 从RuStore的官方gitflic仓库复制*'Plugins'文件夹的内容到您项目中的'Plugins'*文件夹。重启Unreal Engine,在插件列表中(Edit → Plugins → Project → Mobile),选择'RuStoreBilling'和'RuStoreCore'插件。
- 在*'YourProject.Build.cs'*文件中,将'RuStoreCore'和'RuStoreBilling'模块添加到PublicDependencyModuleNames列表中。
- 在项目设置中(Edit → Project Settings → Android),设置Minimum SDK Version为不低于24,Target SDK Version为不低于31。
处理deeplink
当用户通过SberPay支付时,会跳转到俄罗斯储蓄银行应用程序。支付完成后,应使用deeplink返回原应用程序。为了处理deeplink,RuStore Billing插件会自动在AndroidManifest.xml中为主要activity添加android:exported='true'属性和以下intent-filter:
AndroidManifest.xml
\< 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 = \"yourscheme\" /\>\</ intent-filter \>
中yourscheme - 你的deeplink方案,可以更改为其他方案,并且应该与在初始化billing客户端库时指定的deeplinkSheme值相匹配。
您可以在'RuStoreCore_UPL_Android.xml'文件中更 改'yourscheme'到您的方案。
初始化
在调用库的方法之前,需要先进行其初始化。初始化将使用的参数由FURuStoreBillingClientConfig结构进行设置。
初始化
FURuStoreBillingClientConfig config;config.consoleApplicationId = \"111111\" ;config.deeplinkScheme = \"yourscheme\" ;URuStoreBillingClient::Instance()-\>Init(config);
有与客户端的操作也可以通过Blueprints进行。初始化的例子:
consoleApplicationId
- 来自RuStore开发者控制台的应用程序代码(例如:https://console.rustore.ru/apps/111111)\"deeplinkSheme
- url用于实现deeplink的url 。可以使用任何唯一的名称作为名称(例如:yourappscheme)。allowAllowNativeErrorHandling
- 允许在原生SDK中处理错误(详见错误处理部分)enableLogs
- 启用事件日志记录
要提示:
- 传递给deeplinkPrefix的deeplink方案,需要与AndroidManifest.xml中指定的方案相匹配(详见"处理deeplink"部分)。
- 调用Init()将对象绑定到场景的根部,如果之后不再计划使用该对象,为了释放内存,需要执行Dispose()方法。
用Dispose()方法会将对象从根部解绑,并安全地完成所有已发送的请求。
反初始化
URuStoreBillingClient::Instance()-\>Dispose();
如果您需要检查库的初始化情况,请使用 URuStoreBillingClient::Instance()->getIsInitialized() 属性。如果库已初始化,其值为 true;如果尚未调用 Init,则为 false。
检查初始化情况
bool isInitialized = URuStoreBillingClient::Instance()-\>IsIninialized();
检查支付功能的可用性
要检查支付功能的可用性,请调用 checkPurchasesAvailability 方法。在调用时,将检查以下条件:
- 用户的设备上必须安装 RuStore。
- RuStore 必须支持支付功能。
- 用户必须在 RuStore 中获得授权。
- 用户和应用程序不应在RuStore中被封锁。
- 应用程序必须在 RuStore 控制台系统中启用购买功能。
次调用 CheckPurchasesAvailability() 都会返回一个在应用程序单次启动期间唯一的 requestId。每个事件都会返回触发该事件的请求的 requestId。
调用方法CheckPurchasesAvailability
long requestId = URuStoreBillingClient::Instance()-\>CheckPurchasesAvailability( \`\`\[\]( long requestId, TSharedPtr\<FURuStoreFeatureAvailabilityResult, ESPMode::ThreadSafe\> response) { \`\`// Process response \`\`}, \`\`\[\]( long requestId, TSharedPtr\<FURuStoreError, ESPMode::ThreadSafe\> error) { \`\`// Process error \`\`});
blueprint实现:
Success回调返回FURuStoreFeatureAvailabilityResult结构体,在Response参数中:
响应CheckPurchasesAvailability
USTRUCT(BlueprintType)struct RUSTORECORE_API FURuStoreFeatureAvailabilityResult{ \`\`GENERATED_USTRUCT_BODY() \`\`FURuStoreFeatureAvailabilityResult() \`\`{ \`\`isAvailable = false ; \`\`} \`\`UPROPERTY(BlueprintReadWrite) \`\`bool isAvailable; \`\`UPROPERTY(BlueprintReadWrite) \`\`FURuStoreError cause;};
sAvailable表示是否满足执行支付的条件。
cause错误信息。
Failure回调返回FURuStoreError结构体,包含错误信息,在Error参数中。所有可能的FURuStoreException错误在错误处理部分有描述。
错误结构体
USTRUCT(BlueprintType)struct RUSTORECORE_API FURuStoreError{ \`\`GENERATED_USTRUCT_BODY() \`\`FURuStoreError() \`\`{ \`\`name = \"\" ; \`\`description = \"\" ; \`\`} \`\`UPROPERTY(BlueprintReadOnly) \`\`FString name; \`\`UPROPERTY(BlueprintReadOnly) \`\`FString description;};
name
错误名称。description
- 错误描述。
获取产品列表
要获取产品,使用GetProducts()方法:
调用方法GetProducts
long requestId = URuStoreBillingClient::Instance()-\>GetProducts( \`\`productIds, \`\`\[\]( long requestId, TSharedPtr\<FURuStoreProductsResponse, ESPMode::ThreadSafe\> response) { \`\`// Process response \`\`}, \`\`\[\]( long requestId, TSharedPtr\<FURuStoreError, ESPMode::ThreadSafe\> error) { \`\`// Process error \`\`});
TArrayproductIds-- 产品标识符列表。
blueprint实现:
Success回调返回FURuStoreProductsResponse结构体,在Response参数中:
响应GetProducts
USTRUCT(BlueprintType)struct FURuStoreProductsResponse{ \`\`GENERATED_USTRUCT_BODY() \`\`UPROPERTY(BlueprintReadOnly) \`\`TArray\<FURuStoreProduct\> products;};
products-- 产品列表。
产品结构
USTRUCT(BlueprintType)struct FURuStoreProduct{ \`\`GENERATED_USTRUCT_BODY() \`\`FURuStoreProduct() \`\`{ \`\`productId = \"\" ; \`\`productType = EURuStoreProductType::NON_CONSUMABLE; \`\`productStatus = EURuStoreProductStatus::INACTIVE; \`\`priceLabel = \"\" ; \`\`price = 0; \`\`currency = \"\" ; \`\`language = \"\" ; \`\`title = \"\" ; \`\`description = \"\" ; \`\`imageUrl = \"\" ; \`\`promoImageUrl = \"\" ; \`\`} \`\`UPROPERTY(BlueprintReadOnly) \`\`FString productId; \`\`UPROPERTY(BlueprintReadOnly) \`\`EURuStoreProductType productType; \`\`UPROPERTY(BlueprintReadOnly) \`\`EURuStoreProductStatus productStatus; \`\`UPROPERTY(BlueprintReadOnly) \`\`FString priceLabel; \`\`UPROPERTY(BlueprintReadOnly) \`\`int price; \`\`UPROPERTY(BlueprintReadOnly) \`\`FString currency; \`\`UPROPERTY(BlueprintReadOnly) \`\`FString language; \`\`UPROPERTY(BlueprintReadOnly) \`\`FString title; \`\`UPROPERTY(BlueprintReadOnly) \`\`FString description; \`\`UPROPERTY(BlueprintReadOnly) \`\`FString imageUrl; \`\`UPROPERTY(BlueprintReadOnly) \`\`FString promoImageUrl; \`\`UPROPERTY(BlueprintReadOnly) \`\`FURuStoreProductSubscription subscription;};
productId
- 产品标识符。productType
- 产品类型。productStatus
- 产品状态。priceLable
- 格式化的产品 价格,包括[language]语言的货币符号。price
- 以货币最小单位(戈比)表示的价格。currency
- 货币代码ISO 4217。language
使用 BCP 47编码指定的语言。title
产品名称,以FURuStoreProduct::language语言表示。description
产品描述,以FURuStoreProduct::language语言表示。imageUrl
- 图片链接。promoImageUrl
- 促销图片链接。subscription
- 订阅描述,仅对于类型为 subscription 的产品返回。
产品类型
UENUM(BlueprintType)enum class EURuStoreProductType : uint8{ \`\`NON_CONSUMABLE UMETA(DisplayName = \"NON_CONSUMABLE\" ), \`\`CONSUMABLE UMETA(DisplayName = \"CONSUMABLE\" ), \`\`SUBSCRIPTION UMETA(DisplayName = \"SUBSCRIPTION\" )};
产品状态
UENUM(BlueprintType)enum class EURuStoreProductStatus : uint8{ \`\`ACTIVE UMETA(DisplayName = \"ACTIVE\" ), \`\`INACTIVE UMETA(DisplayName = \"INACTIVE\" )};
订阅结构
USTRUCT(BlueprintType)struct FURuStoreProductSubscription{ \`\`GENERATED_USTRUCT_BODY() \`\`FURuStoreProductSubscription() \`\`{ \`\`introductoryPrice = \"\" ; \`\`introductoryPriceAmount = \"\" ; \`\`} \`\`UPROPERTY(BlueprintReadOnly) \`\`FURuStoreSubscriptionPeriod subscriptionPeriod; \`\`UPROPERTY(BlueprintReadOnly) \`\`FURuStoreSubscriptionPeriod freeTrialPeriod; \`\`UPROPERTY(BlueprintReadOnly) \`\`FURuStoreSubscriptionPeriod gracePeriod; \`\`UPROPERTY(BlueprintReadOnly) \`\`FString introductoryPrice; \`\`UPROPERTY(BlueprintReadOnly) \`\`FString introductoryPriceAmount; \`\`UPROPERTY(BlueprintReadOnly) \`\`FURuStoreSubscriptionPeriod introductoryPricePeriod;};
subscriptionPeriod订阅宽限期。
freeTrialPeriod
- 订阅试用期。gracePeriod
- 订阅宽限期。introductoryPrice
- 格式化的介绍性订阅价格,包括FURuStoreProduct::language语言的货币符号。introductoryPriceAmount
- 以货币最小单位(戈比)表示的介绍性价格。introductoryPricePeriod
- 介绍性价格计算周期。
订阅周期的期限结构体
USTRUCT(BlueprintType)struct FURuStoreSubscriptionPeriod{ \`\`GENERATED_USTRUCT_BODY() \`\`FURuStoreSubscriptionPeriod() \`\`{ \`\`years = 1970; \`\`months = 1; \`\`days = 1; \`\`} \`\`UPROPERTY(BlueprintReadOnly) \`\`int years; \`\`UPROPERTY(BlueprintReadOnly) \`\`int months; \`\`UPROPERTY(BlueprintReadOnly) \`\`int days;};
years-- 年数。
- months-- 月数。
- days-- 天数。
ailure回调返回FURuStoreError结构体,包含错误信息,在Error参数中。
所有可能的FURuStoreException错误在错误处理部分有描述。
错误结构体
USTRUCT(BlueprintType)struct RUSTORECORE_API FURuStoreError{ \`\`GENERATED_USTRUCT_BODY() \`\`FURuStoreError() \`\`{ \`\`name = \"\" ; \`\`description = \"\" ; \`\`} \`\`UPROPERTY(BlueprintReadOnly) \`\`FString name; \`\`UPROPERTY(BlueprintReadOnly) \`\`FString description;};
name
- 错误名称。description
- 错误描述。
获取购买列表
要获取购买列表,请使用GetPurchases()方法:
调用获取用户购买列表的方法
long requestId = URuStoreBillingClient::Instance()-\>GetPurchases( \`\`\[\]( long requestId, TSharedPtr\<FURuStorePurchasesResponse, ESPMode::ThreadSafe\> response) { \`\`// Process response \`\`}, \`\`\[\]( long requestId, TSharedPtr\<FURuStoreRuStoreError, ESPMode::ThreadSafe\> error) { \`\`// Process error \`\`});
blueprint实现:
Success回调返回FURuStorePurchasesResponse结构体,在Response参数中:
响应GetPurchases
USTRUCT(BlueprintType)struct FURuStorePurchasesResponse{ \`\`GENERATED_USTRUCT_BODY() \`\`UPROPERTY(BlueprintReadOnly) \`\`TArray\<FURuStorePurchase\> purchases;};
purchases-- 购买列表。
结构体包含关于购买的信息
USTRUCT(BlueprintType)struct FURuStorePurchase{ \`\`GENERATED_USTRUCT_BODY() \`\`FURuStorePurchase() \`\`{ \`\`purchaseId = \"\" ; \`\`productId = \"\" ; \`\`invoiceId = \"\" ; \`\`description = \"\" ; \`\`language = \"\" ; \`\`purchaseTime = FDateTime(0); \`\`orderId = \"\" ; \`\`amountLabel = \"\" ; \`\`amount = 0; \`\`currency = \"\" ; \`\`quantity = 0; \`\`purchaseState = EURuStorePurchaseState::CANCELLED; \`\`developerPayload = \"\" ; \`\`subscriptionToken = \"\" ; \`\`} \`\`UPROPERTY(BlueprintReadOnly) \`\`FString purchaseId; \`\`UPROPERTY(BlueprintReadOnly) \`\`FString productId; \`\`UPROPERTY(BlueprintReadOnly) \`\`FString invoiceId; \`\`UPROPERTY(BlueprintReadOnly) \`\`FString description; \`\`UPROPERTY(BlueprintReadOnly) \`\`FString language; \`\`UPROPERTY(BlueprintReadOnly) \`\`FDateTime purchaseTime; \`\`UPROPERTY(BlueprintReadOnly) \`\`FString purchaseTimeLabel; \`\`UPROPERTY(BlueprintReadOnly) \`\`FString orderId; \`\`UPROPERTY(BlueprintReadOnly) \`\`FString amountLabel; \`\`UPROPERTY(BlueprintReadOnly) \`\`int amount; \`\`UPROPERTY(BlueprintReadOnly) \`\`FString currency; \`\`UPROPERTY(BlueprintReadOnly) \`\`int quantity; \`\`UPROPERTY(BlueprintReadOnly) \`\`EURuStorePurchaseState purchaseState; \`\`UPROPERTY(BlueprintReadOnly) \`\`FString developerPayload; \`\`UPROPERTY(BlueprintReadOnly) \`\`FString subscriptionToken;};
purchaseId
- 购买标识符。productId
- 产品标识符。description
- 购买描述。invoiceId
- 发票标识符。language
使用 BCP 47 编码指定的语言。purchaseTime
- 购买时间purchaseTimeLabel
- 购买时间(格式)DD.MM.YYYYHH:MM:SSorderId
- 应用程序生成的唯一支付标识符(uuid)。amountLable
- 格式化的购买价格,包括FURuStorePurchase::language语言的货币符号。amount
- 以货币最小单位表示的介绍性价格。currency
- 货币代码ISO 4217。quantity
- 产品数量。purchaseState
- 购买状态。developerPayload
- 开发者指定的字符串,包含关于订单的附加信息。subscriptionToken
- 用于在服务器端验证购买的令牌。
购买状态
UENUM(BlueprintType)enum class EURuStorePurchaseState : uint8{ \`\`CREATED UMETA(DisplayName = \"CREATED\" ), \`\`INVOICE_CREATED UMETA(DisplayName = \"INVOICE_CREATED\" ), \`\`CONFIRMED UMETA(DisplayName = \"CONFIRMED\" ), \`\`PAID UMETA(DisplayName = \"PAID UMETA\" ), \`\`CANCELLED UMETA(DisplayName = \"CANCELLED\" ), \`\`CONSUMED UMETA(DisplayName = \"CONSUMED\" ), \`\`CLOSED UMETA(DisplayName = \"CLOSED\" )};
CREATED
- 已创建。INVOICE_CREATED
- 已创建,等待支付。CONFIRMED
- 已确认。PAID
- 已支付。CANCELLED
- 购买已取消。CONSUMED
- 已确认购买消耗。CLOSED
- 订阅已取消。
ailure回调返回FURuStoreError结构体,包含错误信息,在Error参数中。
所有可能的FURuStoreException错误在错误处理部分有描述。
错误结构体
USTRUCT(BlueprintType)struct RUSTORECORE_API FURuStoreError{ \`\`GENERATED_USTRUCT_BODY() \`\`FURuStoreError() \`\`{ \`\`name = \"\" ; \`\`description = \"\" ; \`\`} \`\`UPROPERTY(BlueprintReadOnly) \`\`FString name; \`\`UPROPERTY(BlueprintReadOnly) \`\`FString description;};
name
- 错误名称。description
- 错误描述。
获取购买信息
要获取关于购买的信息,请使用 GetPurchaseInfo 方法:
调用取消购买方法。
long requestId = URuStoreBillingClient::Instance()-\>GetPurchaseInfo( \`\`purchaseId, \`\`\[\]( long requestId, TSharedPtr\<FURuStorePurchase, ESPMode::ThreadSafe\> response) { \`\`// Process response \`\`}, \`\`\[\]( long requestId, TSharedPtr\<FURuStoreError, ESPMode::ThreadSafe\> error) { \`\`// Process error \`\`});
purchaseId
- 购买标识符。
blueprint实现:
Success回调返回FURuStorePurchase结构体,在Response参数中:
结构体包含关于购买的信息
USTRUCT(BlueprintType)struct FURuStorePurchase{ \`\`GENERATED_USTRUCT_BODY() \`\`FURuStorePurchase() \`\`{ \`\`purchaseId = \"\" ; \`\`productId = \"\" ; \`\`invoiceId = \"\" ; \`\`description = \"\" ; \`\`language = \"\" ; \`\`purchaseTime = FDateTime(0); \`\`orderId = \"\" ; \`\`amountLabel = \"\" ; \`\`amount = 0; \`\`currency = \"\" ; \`\`quantity = 0; \`\`purchaseState = EURuStorePurchaseState::CANCELLED; \`\`developerPayload = \"\" ; \`\`subscriptionToken = \"\" ; \`\`} \`\`UPROPERTY(BlueprintReadOnly) \`\`FString purchaseId; \`\`UPROPERTY(BlueprintReadOnly) \`\`FString productId; \`\`UPROPERTY(BlueprintReadOnly) \`\`FString invoiceId; \`\`UPROPERTY(BlueprintReadOnly) \`\`FString description; \`\`UPROPERTY(BlueprintReadOnly) \`\`FString language; \`\`UPROPERTY(BlueprintReadOnly) \`\`FDateTime purchaseTime; \`\`UPROPERTY(BlueprintReadOnly) \`\`FString purchaseTimeLabel; \`\`UPROPERTY(BlueprintReadOnly) \`\`FString orderId; \`\`UPROPERTY(BlueprintReadOnly) \`\`FString amountLabel; \`\`UPROPERTY(BlueprintReadOnly) \`\`int amount; \`\`UPROPERTY(BlueprintReadOnly) \`\`FString currency; \`\`UPROPERTY(BlueprintReadOnly) \`\`int quantity; \`\`UPROPERTY(BlueprintReadOnly) \`\`EURuStorePurchaseState purchaseState; \`\`UPROPERTY(BlueprintReadOnly) \`\`FString developerPayload; \`\`UPROPERTY(BlueprintReadOnly) \`\`FString subscriptionToken;};
ailure回调返回FURuStoreError结构体,包含错误信息。
所有可能的FURuStoreException错误在错误处理部分有描述。
错误结构体
USTRUCT(BlueprintType)struct RUSTORECORE_API FURuStoreError{ \`\`GENERATED_USTRUCT_BODY() \`\`FURuStoreError() \`\`{ \`\`name = \"\" ; \`\`description = \"\" ; \`\`} \`\`UPROPERTY(BlueprintReadOnly) \`\`FString name; \`\`UPROPERTY(BlueprintReadOnly) \`\`FString description;};
name
错误名称。description
- 错误描述。
购买产品
要调用购买产品,请使用 PurchaseProduct() 方法。
调用购买产品的方法
long requestId = URuStoreBillingClient::Instance()-\>PurchaseProduct( \`\`productId, \`\`orderId, \`\`quantity, \`\`developerPayload, \`\`\[\]( long requestId, TShardPtr\<FURuStorePaymentResult, ESPMode::ThreadSafe\> response) { \`\`// Process response \`\`}, \`\`\[\]( long requestId, TSharedPtr\<FURuStoreError, ESPMode::ThreadSafe\> error) { \`\`// Process error \`\`});
stringproductId-- 产品标识符。
- intquantity-- 产品数量。
- stringdeveloperPayload-- AnyApp开发者的附加信息。
blueprint实现:
Success 回调返回由 UE 管理的指针(无需手动删除)到 URuStorePaymentResultClass 类在 Response 参数中:
购买结果的结构体
UCLASS(BlueprintType)class RUSTOREBILLING_API URuStorePaymentResultClass : public UObject{ \`\`GENERATED_BODY()};USTRUCT(BlueprintType)struct RUSTOREBILLING_API FURuStorePaymentResult{ \`\`GENERATED_USTRUCT_BODY() \`\`virtual \~FURuStorePaymentResult() {} \`\`virtual FString GetTypeName() { return \"FURuStorePaymentResult\" ; }};
购买结果的结构体
UCLASS(BlueprintType)class RUSTOREBILLING_API URuStoreSuccess : public URuStorePaymentResultClass{ \`\`GENERATED_BODY()public : \`\`UPROPERTY(BlueprintReadOnly) \`\`FURuStoreSuccess value;};USTRUCT(BlueprintType)struct RUSTOREBILLING_API FURuStoreSuccess : public FURuStorePaymentResult{ \`\`GENERATED_USTRUCT_BODY() \`\`FURuStoreSuccess() \`\`{ \`\`orderId = \"\" ; \`\`purchaseId = \"\" ; \`\`productId = \"\" ; \`\`invoiceId = \"\" ; \`\`subscriptionToken = \"\" ; \`\`} \`\`UPROPERTY(BlueprintReadOnly) \`\`FString orderId; \`\`UPROPERTY(BlueprintReadOnly) \`\`FString purchaseId; \`\`UPROPERTY(BlueprintReadOnly) \`\`FString productId; \`\`UPROPERTY(BlueprintReadOnly) \`\`FString invoiceId; \`\`UPROPERTY(BlueprintReadOnly) \`\`FString subscriptionToken; \`\`virtual FString GetTypeName() override { return \"FURuStoreSuccess\" ; }};
购买结果的结构体
UCLASS(BlueprintType)class RUSTOREBILLING_API URuStoreCancelled : public URuStorePaymentResultClass{ \`\`GENERATED_BODY()public : \`\`UPROPERTY(BlueprintReadOnly) \`\`FURuStoreCancelled value;};USTRUCT(BlueprintType)struct RUSTOREBILLING_API FURuStoreCancelled : public FURuStorePaymentResult{ \`\`GENERATED_USTRUCT_BODY() \`\`FURuStoreCancelled() \`\`{ \`\`purchaseId = \"\" ; \`\`} \`\`UPROPERTY(BlueprintReadOnly) \`\`FString purchaseId; \`\`virtual FString GetTypeName() override { return \"FURuStoreCancelled\" ; }};
购买结果的结构体
UCLASS(BlueprintType)class RUSTOREBILLING_API URuStoreFailure : public URuStorePaymentResultClass{ \`\`GENERATED_BODY()public : \`\`UPROPERTY(BlueprintReadOnly) \`\`FURuStoreFailure value;};USTRUCT(BlueprintType)struct RUSTOREBILLING_API FURuStoreFailure : public FURuStorePaymentResult{ \`\`GENERATED_USTRUCT_BODY()public : \`\`FURuStoreFailure() \`\`{ \`\`purchaseId = \"\" ; \`\`invoiceId = \"\" ; \`\`orderId = \"\" ; \`\`quantity = 0; \`\`productId = \"\" ; \`\`errorCode = 0; \`\`} \`\`UPROPERTY(BlueprintReadOnly) \`\`FString purchaseId; \`\`UPROPERTY(BlueprintReadOnly) \`\`FString invoiceId; \`\`UPROPERTY(BlueprintReadOnly) \`\`FString orderId; \`\`UPROPERTY(BlueprintReadOnly) \`\`int quantity; \`\`UPROPERTY(BlueprintReadOnly) \`\`FString productId; \`\`UPROPERTY(BlueprintReadOnly) \`\`int errorCode; \`\`virtual FString GetTypeName() override { return \"FURuStoreFailure\" ; }};
购买结果的结构体
UCLASS(BlueprintType)class RUSTOREBILLING_API URuStoreInvalidPaymentState : public URuStorePaymentResultBase{ \`\`GENERATED_BODY()public : \`\`UPROPERTY(BlueprintReadOnly) \`\`FURuStoreInvalidPaymentState value;};USTRUCT(BlueprintType)struct RUSTOREBILLING_API FURuStoreInvalidPaymentState : public FURuStorePaymentResult{ \`\`GENERATED_USTRUCT_BODY() \`\`virtual FString GetTypeName() override { return \"FURuStoreInvalidPaymentState\" ; }};
Success成功完成数字产品购买的结果。
- Failure购买数字产品时错误的结果。
- Cancelled数字产品购买被取消的结果。
- InvalidPaymentStateSDK支付错误。可能因deeplink回调不正确而发生。
ailure回调返回FURuStoreError结构体,包含错误信息,在Error参数中。
所有可能的FURuStoreException错误在错误处理部分有描述。
错误结构体
USTRUCT(BlueprintType)struct RUSTORECORE_API FURuStoreError{ \`\`GENERATED_USTRUCT_BODY() \`\`FURuStoreError() \`\`{ \`\`name = \"\" ; \`\`description = \"\" ; \`\`} \`\`UPROPERTY(BlueprintReadOnly) \`\`FString name; \`\`UPROPERTY(BlueprintReadOnly) \`\`FString description;};
name
错误名称。description
- 错误描述。
购买消耗(确认)
RuStore 包含以下类型的产品:
CONSUMABLE
- 消耗的(可以多次购买,例如应用 中的水晶)。NON_CONSUMABLE
- 非消耗的(只能购买一次,例如禁用应用程序中的广告)。SUBSCRIPTION
- 订阅(可以购买一段时间,例如流媒体服务的订阅)。
有处于 PurchaseState.PAID
状态的 CONSUMABLE
类型产品需要消耗。
您可以使用 confirmPurchase 方法来消耗购买:
调用确认方法
long requestId = RuStoreBillingClient::Instance()-\>ConfirmPurchase( \`\`purchaseId, \`\`\[\]( long requestId) { \`\`// Process error \`\`}, \`\`\[\]( long requestId, TSharedPtr\<FURuStoreConfirmPurchaseResponse, ESPMode::ThreadSafe\> response) { \`\`// Process response \`\`});
purchaseId
- 购买标识符。
blueprint实现:
Failure回调返回FURuStoreError结构体,包含错误信息,在Error参数中。
所有可能的FURuStoreException错误在错误处理部分有描述。
错误结构体
USTRUCT(BlueprintType)struct RUSTORECORE_API FURuStoreError{ \`\`GENERATED_USTRUCT_BODY() \`\`FURuStoreError() \`\`{ \`\`name = \"\" ; \`\`description = \"\" ; \`\`} \`\`UPROPERTY(BlueprintReadOnly) \`\`FString name; \`\`UPROPERTY(BlueprintReadOnly) \`\`FString description;};
name
错误名称。description
- 错误描述。
取消购买
要取消购买,您可以使用 DeletePurchase 方法:
调用取消购买方法。
long requestId = URuStoreBillingClient::Instance()-\>DeletePurchase( \`\`purchaseId, \`\`\[\]( long requestId) { \`\`// Process response \`\`}, \`\`\[\]( long requestId, TSharedPtr\<FURuStoreRuStoreError, ESPMode::ThreadSafe\> error) { \`\`// Process error \`\`});
purchaseId
- 购买标识符。
果您有与删除购买相关的逻辑,请使用此方法。
购买将在20分钟后自动取消,或者在同一客户端进行重复购买时取消。
Blueprint实现:
Failure回调返回FURuStoreError结构体,包含错误信息,在Error参数中。
所有可能的FURuStoreException错误在错误处理部分有描述。
错误结构体
USTRUCT(BlueprintType)struct RUSTORECORE_API FURuStoreError{ \`\`GENERATED_USTRUCT_BODY() \`\`FURuStoreError() \`\`{ \`\`name = \"\" ; \`\`description = \"\" ; \`\`} \`\`UPROPERTY(BlueprintReadOnly) \`\`FString name; \`\`UPROPERTY(BlueprintReadOnly) \`\`FString description;};
name
错误名称。description
- 错误描述。
购买消耗和取消的流程
由于产品购买结果模型发生了变化,因此购买的消耗和取消的逻辑也随之发生了变化。
如果出现以下情况,应使用取消购买方法DeletePurchase():
- 获取购买列表方法
GetPurchases()
返回了具有以下状态的购买:FURuStorePurchaseState::CREATED
.FURuStorePurchaseState::INVOICE_CREATED
.
- 购买方法
PurchaseProduct()
返回FURuStorePaymentResult::CANCELLED
。 - 购买方法
PurchaseProduct()
返回FURuStorePaymentResult::FAILURE
。
果获取购买列表的方法 GetPurchases() 返回了类型为 CONSUMABLE
且状态为 FURuStorePurchaseState::PAID 的购买,则需要使用产品消耗方法 ConfirmPurchase()。
错误处理
在 SDK 方法的 onFailure
处理程序中传递发生的错误。
错误结构体
USTRUCT(BlueprintType)struct RUSTORECORE_API FURuStoreRuStoreError{ \`\`GENERATED_USTRUCT_BODY() \`\`FURuStoreRuStoreError() \`\`{ \`\`name = \"\" ; \`\`description = \"\" ; \`\`} \`\`UPROPERTY(BlueprintReadOnly) \`\`FString name; \`\`UPROPERTY(BlueprintReadOnly) \`\`FString description;};
name
错误名称。description
- 错误描述。
能的错误:
RuStoreNotInstalledException
-- 用户设备上未安装 RuStore。RuStoreOutdatedException
-- 用户设备上安装的 RuStore应用程序不支持支付。RuStoreUserUnauthorizedException
--用户未在 RuStore 中授权。- RuStoreApplicationBannedException -- 应用程序在 RuStore 中被 禁止。
- RuStoreUserBannedException -- 用户在 RuStore 中被禁止。
RuStoreException
-- RuStore的基本错误,其他错误均继承自此。
用 PurchaseProduct 方法时,错误会自动处理。
如果在 SDK 初始化时传递了参数 allowNativeErrorHandling == true,在出现错误时,除了调用相应的 onFailure
处理程序外,该错误还会传递到原生 SDK 的 resolveForBilling 方法中,以便向用户显示错误对话框:
错误处理
public fun RuStoreException.resolveForBilling(context: Context)
初始化后,可以通过设置 AllowNativeErrorHandling 属性来更改此行为:
禁止原生的错误处理
RuStoreBillingClient::Instance()-\>SetAllowNativeErrorHandling( false );
更换主题
为了动态更换主题,必须使用 SetTheme 方法:
调用主题安装方法
EURuStoreTheme theme = EURuStoreTheme::DARK;URuStoreBillingClient::Instance()-\>SetTheme(theme);
theme-- 来自 EURuStoreTheme 枚举的主题类型。
blueprint实现:
可以使用 GetTheme 方法获取关于已设置的主题的信息:
调用主题安装方法
EURuStoreTheme theme = URuStoreBillingClient::Instance()-\>GetTheme();
blueprint实现:
主题类型
UENUM(BlueprintType)enum class EURuStoreTheme : uint8{ \`\`DARK UMETA(DisplayName = \"DARK\" ), \`\`LIGHT UMETA(DisplayName = \"LIGHT\" )};