google play in-app billing api version is less than 3
biling server is not available
biling服务不可用一般都是因为Google政策问题 大路用不了的 删除google应用数据缓存和所有数据操作如下:
谷歌账号从申请之后全程翻墙 不能连国内的运营商 因为谷歌不让大路完成内购 香港地区最好也不用 最后还是连接美国的的服务器 谷歌账号没有加入许可测试 不是内部测试 加入许可测试等待两个小时左右 移除账号 删除数据和缓存 所有和google相关的 重新登录google商店 能在谷歌商店看到付费分类下有东西证明付费可用 能够拉起支付 重新进入应用 拉起支付
注: 这里是我之前20年的时候及融入google使用 的 太古老了 现在unity已经修复了这个问题 直接更新unity版本 然后升级IAP的版本就可以
https://developer.android.com/google/play/billing/unity
里面有对应的插件
第二步吧第一步导入的文件全部选中apply一下 才会出现第三部的页面 点击同意即可
第六步我在unity 没有找到 猜测是被墙了 在网上随便搜了一个 git上的 clone下来放入unity plugins文件夹
还有一处不同
以上是我20年接入走的流程 现在我们团队使用的unity版本是2020.3.38 IAP版本直接升级 比如下图:
可以看到IAP 4.3 支持 google biling v3
iap 5.0的时候就支持 biling v6了 结算库6 google应用审核有个规矩 每年升级结算库 结算库太低的 就不让你上架了 甚至一定时间之后就会给你主动下架 所以你要一直升级IAp版本 跟着google的节奏走 没办法 洋大人的钱也不好赚;
其他根据unity IAP流程走即可
版本号要加一个并且通过内部测试审核
续unity IAP流程
IAP可以自动恢复交易 只要没有ConfirmPendingPurchase()完成订单
using LitJson;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using UnityEngine.Purchasing;
using Google.Play.Billing;
using Google.Play.Billing.Internal;
public class PayManager : MonoBehaviour, IStoreListener
{
public static PayManager manager;
private IStoreController appStoreController;
private void Awake()
{
if (manager == null)
{
manager = this;
DontDestroyOnLoad(gameObject);
}
else if (manager != this)
{
Destroy(gameObject);
}
}
public void InitPayment()
{
ConfigurationBuilder builder;
if (Application.platform == RuntimePlatform.Android)
{
builder = ConfigurationBuilder.Instance(Google.Play.Billing.GooglePlayStoreModule.Instance());
}
else
{
builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
}
for (int i = 0; i < GameController.manager.subscribeMan.subInfoList.Count; i++)
{
if (Application.platform == RuntimePlatform.Android)
builder.AddProduct(GameController.manager.subscribeMan.subInfoList[i].goodId, ProductType.Consumable);
else
builder.AddProduct(GameController.manager.subscribeMan.subInfoList[i].goodId, ProductType.Subscription);
}
UnityPurchasing.Initialize(this, builder);
Debug.Log("Initialize");
}
public void Pay(string goodId, PayType type, Utils.Util.NoneParamFunction _paySucCallback = null)
{
if (appStoreController == null)
{
GameController.manager.loadingUI.Hide();
Debug.Log("appStoreController==null");
return;
}
Product product = appStoreController.products.WithID(goodId);
if (product != null && product.availableToPurchase)
{
appStoreController.InitiatePurchase(product);
}
}
void IStoreListener.OnInitialized(IStoreController controller, IExtensionProvider extensions)
{
Debug.Log("OnInitialized");
appStoreController = controller;
}
void IStoreListener.OnInitializeFailed(InitializationFailureReason error)
{
Debug.Log("OnInitializeFailed InitializationFailureReason:" + error);
GameController.manager.loadingUI.ShowWithText("付费功能初始化失败,请重新进入本页面");
if (error == InitializationFailureReason.AppNotKnown)
{
//
}
else if (error == InitializationFailureReason.NoProductsAvailable)
{
//
}
else if (error == InitializationFailureReason.PurchasingUnavailable)
{
//
}
}
void IStoreListener.OnPurchaseFailed(Product product, PurchaseFailureReason failureReason)
{
//支付失败
GameController.manager.loadingUI.Hide();
Debug.Log(string.Format("OnPurchaseFailed: FAIL. Product: '{0}', PurchaseFailureReason: {1}", product.definition.storeSpecificId, failureReason));
if (failureReason == PurchaseFailureReason.UserCancelled)
{
//用户取消交易
}
else if (failureReason == PurchaseFailureReason.ExistingPurchasePending)
{
//上一笔交易还未完成
}
else if (failureReason == PurchaseFailureReason.PaymentDeclined)
{
//拒绝付款
}
else if (failureReason == PurchaseFailureReason.ProductUnavailable)
{
//商品不可用
}
else if (failureReason == PurchaseFailureReason.PurchasingUnavailable)
{
//支付不可用
}
else
{
//位置错误
}
}
PurchaseProcessingResult IStoreListener.ProcessPurchase(PurchaseEventArgs e)
{
Debug.Log("ProcessPurchase : " + e.purchasedProduct.receipt);
PayCheck(e.purchasedProduct.receipt, e.purchasedProduct);
return PurchaseProcessingResult.Pending;
}
public void PayCheck(string receipt, Product product)
{
GameController.manager.loadingUI.ShowWithText("");
byte[] bytes = Encoding.UTF8.GetBytes(receipt);
string URL="";
StartCoroutine(SmartHTTP.SmartHTTP.POST(url,
serverToken, bytes, (JsonData data) =>
{
appStoreController.ConfirmPendingPurchase(product);
("支付完成");
//验证成功
}, (long code) =>
{
GameController.manager.fullScreenWarningAlert.Show("支付异常");
Debug.Log("code : " + code);
GameController.manager.loadingUI.Hide();
}));
}
}
续:初始化只初始化一次就可以 iOS 无问题但是Google每初始化一次都会多给你发一条购买的回调消息 即凭证 猜测 google没有过滤但是iOS过滤了 要不然会报一个错误 finish failed purchasing debug message server error ,please try again