跳到主要内容

从 Prime31 到 AndApp IAP 的转换指南

概要​

这是将 Android 用 Prime31 In App Billing Plugin 处理转成 AndApp IAP 流程的转换指南。要从 Prime31 转成 AndApp IAP ,请参考本指南。

处理Prime31 In App Billing PluginAndApp IAP
初始化、可结算检查

QueryInventoryGoogleIAB.init

GoogleIABEventListener.billingSupportedEvent

GoogleIABEventListener.billingNotSupportedEvent

AndApp.Payment.IsBillingSupported

产品信息&

已购买产品查询

GoogleIAB.queryInventory

GoogleIABEventListener.queryInventorySucceededEvent
GoogleIABEventListener.queryInventoryFailedEvent

AndApp.Payment.GetProducts

AndApp.Payment.GetPurchases

 

结算处理

GoogleIAB.purchaseProduct

GoogleIABEventListener.purchaseSucceededEvent

GoogleIABEventListener.purchaseFailedEvent

AndApp.Payment.RequestPurchase
AndApp.Payment.PurchaseSucceededEvent
AndApp.Payment.PurchaseFailedEvent
消费处理

GoogleIAB.consumeProduct / GoogleIAB.consumeProducts

GoogleIABEventListener.consumePurchaseSucceededEvent

GoogleIABEventListener.consumePurchaseFailedEvent

AndApp.Payment.ConsumePurchase

初始化、可结算检查​

Prime31 In App Billing Plugin​

void Start(){
string publicKey = "";
GoogleIAB.init (publicKey);
GoogleIABManager.billingSupportedEvent += billingSupportedEvent;
GoogleIABManager.billingNotSupportedEvent += billingNotSupportedEvent;
}
void billingSupportedEvent(){
//结算可用时
}

void billingNotSupportedEvent(string error){
// 结算不可用时
}

AndApp IAP​

void Start(){
// 通过调用 AndApp.SDK.Initialize 执行初始化
// SDK 初始化完成后,请执行结算模块初始化
if(AndApp.Payment.IsBillingSupported){
// 结算可用时
}else{
// 结算不可用时
}
}

产品信息、已购买产品查询​

Prime31 In App Billing Plugin​

void QueryInventory(){
string[] skus = { "pid100", "pid500", "pid1000" };
GoogleIAB.queryInventory(skus);
GoogleIABManager.queryInventorySucceededEvent += queryInventorySucceededEvent;
GoogleIABManager.queryInventoryFailedEvent += queryInventoryFailedEvent;
}
 
void queryInventorySucceededEvent(List<GooglePurchase> purchases, List<GoogleSkuInfo> skus )){
// puchases 中的已购买产品
// skus 中的产品信息
}
void queryInventoryFailedEvent( string error ) {
// 发生错误时
}

AndApp IAP​

void QueryInventory(){
string[] productIds = { "pid100", "pid500", "pid1000" };
AndApp.Payment.GetProducts (productIds, (products, error) => {
// products 中的产品信息
AndApp.Payment.GetPurchases(productIds, (purchases, errorPurchase) => {
// purchases 中的已购买产品
});
});
}

结算处理​

Prime31 In App Billing Plugin​

void PurchaseProduct() {
GoogleIABManager.purchaseSucceededEvent += purchaseSucceededEvent;
GoogleIABManager.purchaseFailedEvent += purchaseFailedEvent;
GoogleIAB.purchaseProduct (productId);
}
void purchaseSucceededEvent(GooglePurchase purchase) {
// 支付完成时
}

void purchaseFailedEvent(string error) {
// 发生错误时
}

AndApp IAP​

void purchaseProduct() {
AndApp.Payment.PurchaseSucceededEvent += OnPurchaseSucceeded;
AndApp.Payment.PurchaseFailedEvent += OnPurchaseFailed;

AndApp.Payment.RequestPurchase (productId, (error) => {
// 在支付尚未确定但支付手续已完成且UI 已关闭时调用
});
}

void OnPurchaseSucceeded (AndApp.Purchase purchase) {
// 支付完成时
sendReceipt(purchase.Receipt);
}

void OnPurchaseFailed (AndApp.Error error){
// 发生错误时
}

消费处理​

Prime31 In App Billing Plugin​

void ConsumePurchase(string productId) {
GoogleIAB.consumeProduct(productId);
GoogleIABManager.purchaseSucceededEvent += consumePurchaseSucceededEvent;
GoogleIABManager.purchaseFailedEvent += consumePurchaseFailedEvent;
}
void consumePurchaseSucceededEvent( GooglePurchase purchase ) {
// 消费请求成功时
}
void consumePurchaseFailedEvent( string error ) {
// 消费请求发生错误时
}

AndApp IAP​

void ConsumePurchase(string productId){
AndApp.Payment.ConsumePurchase(productId, (AndApp.Error error) => {
if(error == null){
// 消费请求成功时
} else {
// 消费请求发生错误时
}
});
}

更新履历​

  • 2016/06/06
    • 新建