This commit is contained in:
chenxi 2023-06-14 18:57:09 +08:00
commit 119a6eaa27
5 changed files with 55 additions and 176 deletions

View File

@ -145,12 +145,9 @@ function PayManager:purchasePackage(id, purchaseType)
self:checkAndPay(productId, id, purchaseType, rechargeId)
end
function PayManager:requestRewards(purchaseToken, orderId, originOrderId, notShowRewardsBox, callback)
function PayManager:requestRewards(purchaseToken, orderId, originOrderId, productId, notShowRewardsBox, callback)
self:sendMsgToServer(purchaseToken, orderId, originOrderId, function(binder, msgData)
if msgData.status == 0 then
if Platform:isIosPlatform() then
SDKManager:delIosPayInfo(purchaseToken)
end
local showRewards = not notShowRewardsBox
if DataManager.TutorialData and DataManager.TutorialData:getIsInTutorial() then -- 引导时不弹
showRewards = false
@ -190,18 +187,39 @@ function PayManager:requestRewards(purchaseToken, orderId, originOrderId, notSho
BIReport:postAdjustSimpleTrackEvent("rumq9q", {})
end
-- 支付上报
local data = {}
data.pay_money = DataManager.PlayerData:getTotalPayAmount()
data.pay_count = DataManager.PlayerData:getPayCount()
CS.ThinkingAnalytics.ThinkingAnalyticsAPI.UserSet(data)
-- 支付验证成功后消耗此订单
if purchaseToken then
SDKManager:consumePurchase(purchaseToken)
if CS.UnityEngine.Application.platform == CS.UnityEngine.RuntimePlatform.Android then
if purchaseToken then
SDKManager:consumePurchase(purchaseToken)
end
elseif CS.UnityEngine.Application.platform == CS.UnityEngine.RuntimePlatform.IPhonePlayer then
if productId then
SDKManager:consumePurchase(productId)
SDKManager:delIosOrder(productId)
end
if originOrderId ~= "gm" then
SDKManager:delIosPayInfo(originOrderId)
end
end
elseif msgData.status == 1008 then -- 验证异常,但是需要消耗订单
if purchaseToken then
SDKManager:consumePurchase(purchaseToken)
if CS.UnityEngine.Application.platform == CS.UnityEngine.RuntimePlatform.Android then
if purchaseToken then
SDKManager:consumePurchase(purchaseToken)
end
elseif CS.UnityEngine.Application.platform == CS.UnityEngine.RuntimePlatform.IPhonePlayer then
if productId then
SDKManager:consumePurchase(productId)
SDKManager:delIosOrder(productId)
end
if originOrderId ~= "gm" then
SDKManager:delIosPayInfo(originOrderId)
end
end
Logger.logError("重复验证")
else
@ -230,7 +248,7 @@ function PayManager:checkAndPay(productId, id, purchaseType, rechargeId)
BIReport:postPayTurn(giftType, id, rechargeId)
SDKManager:pay(productId, msgData.uuid, rechargeId, giftType, purchaseType, id, function(purchaseToken, orderId, originOrderId)
if purchaseToken and orderId then
self:requestRewards(purchaseToken, orderId, originOrderId)
self:requestRewards(purchaseToken, orderId, originOrderId, productId)
end
end)
else -- 没有支付信息,直接发奖

View File

@ -186,6 +186,12 @@ function SDKManager:delIosPayInfo(transactionID)
end
end
function SDKManager:delIosOrder(productId)
if SDKPayMgr.delIosOrder then
return SDKPayMgr:delIosOrder(productId)
end
end
-- 支付相关接口 ********************************************************************** 结束
-- 获取设备语言

View File

@ -130,7 +130,7 @@ function SDKPayGoogleManager:reqPayReward(uncompleteList, productId, callback)
handleOrder(uncompleteList[index])
end)
else
SDKManager:consumePurchase(uncompleteOrder.purchaseToken, function()
self:consumePurchase(uncompleteOrder.purchaseToken, function()
index = index + 1
handleOrder(uncompleteList[index])
end)
@ -392,76 +392,4 @@ function SDKPayGoogleManager:doUncompletePay(callback)
end
end
-- 第一步向服务器验证订单号
-- function SDKPayGoogleManager:_checkPurchaseOrder(result, productId, callback)
-- -- SDKPayGoogleManager:saveOrderId(result.orderId)
-- if DataManager.PlayerData:isInPermanentOrders(result.obfuscatedAccountId) then
-- return
-- end
-- local params = {}
-- params.receipt = {}
-- params.receipt.packageName = Platform:getIdentifier()
-- params.receipt.productId = productId
-- params.receipt.purchaseToken = result.purchaseToken
-- params.receipt.subscription = false
-- CS.BF.BFMain.Instance.ParseClientMgr:SetLuaCheckPurchaseOrderCallback(function (msg)
-- local serverResult = json.decode(msg)
-- local _result = serverResult.result
-- Logger.printTable(serverResult)
-- if _result and _result.data then
-- if _result.code == 0 then
-- -- SDKPayGoogleManager:delOrderId(_result.data.orderId)
-- SDKPayGoogleManager:saveOrderId(_result.data.obfuscatedExternalAccountId, params)
-- SDKPayGoogleManager:checkPurchaseConsume(_result.data.obfuscatedExternalAccountId, params, callback)
-- -- if callback then
-- -- callback(_result.data.purchaseToken, _result.data.obfuscatedAccountId, _result.data.orderId)
-- -- end
-- elseif _result.code == 137 then
-- -- SDKPayGoogleManager:delOrderId(_result.data.orderId)
-- SDKPayGoogleManager:consumePurchase(_result.data.purchaseToken)
-- else
-- -- @TODO 重试
-- end
-- end
-- end)
-- CS.BF.BFMain.Instance.ParseClientMgr:CheckPurchaseGPOrder(json.encode(params))
-- end
-- 第二步向服务器申请消耗订单
-- function SDKPayGoogleManager:checkPurchaseConsume(orderId, params, callback, callback1)
-- if not orderId or not params then
-- return
-- end
-- CS.BF.BFMain.Instance.ParseClientMgr:SetLuaCheckPurchaseConsumeCallback(function (msg)
-- local serverResult = json.decode(msg)
-- local _result = serverResult.result
-- Logger.printTable(serverResult)
-- if _result and _result.data then
-- if _result.code == 0 or _result.code == 137 then
-- SDKPayGoogleManager:delOrderId(orderId)
-- SDKPayGoogleManager:savePermanentOrderId(orderId)
-- if callback then
-- callback(_result.data.purchaseToken, _result.data.obfuscatedExternalAccountId, _result.data.orderId)
-- else
-- PayManager:requestRewards(_result.data.purchaseToken, orderId)
-- SDKPayGoogleManager:consumePurchase(_result.data.purchaseToken)
-- if callback1 then
-- callback1()
-- end
-- end
-- -- elseif _result.code == 137 then
-- -- SDKPayGoogleManager:delOrderId(orderId)
-- -- SDKPayGoogleManager:consumePurchase(_result.data.purchaseToken)
-- else
-- -- @TODO 重试
-- end
-- end
-- end)
-- CS.BF.BFMain.Instance.ParseClientMgr:CheckPurchaseGPConsume(json.encode(params))
-- end
-- 支付相关接口 ********************************************************************** 结束
return SDKPayGoogleManager

View File

@ -30,16 +30,15 @@ function SDKPayiOSManager:initPay(callback)
local payParams = self.iosPayInfos[result.transactionID]
local needConsumePurchase = true
if payParams ~= nil and payParams.order then
PayManager:requestRewards(result.receipt, payParams.order, result.transactionID)
PayManager:requestRewards(result.receipt, payParams.order, result.transactionID, payParams.productId)
needConsumePurchase = false
end
if needConsumePurchase then
self:delIosPayInfo(result.transactionID)
self:delIosOrder(result.definition.id)
self:consumePurchase(result.definition.id)
local arr = string.split(payParams.order, "|")
local giftId = tonumber(arr[2])
local purchaseType = tonumber(arr[1])
local giftId = tonumber(payParams.giftId)
local purchaseType = tonumber(payParams.purchaseType)
local giftType = PayManager:getGiftType(purchaseType, giftId)
local rechargeId = PayManager:getPackageRechargeId(purchaseType, giftId)
BIReport:postPayFailed(result.definition.id, result.transactionID, rechargeId, "error order", giftType, giftId)
@ -48,7 +47,7 @@ function SDKPayiOSManager:initPay(callback)
-- 回调时机太早的话,就先保存起来,等后续补单的时候一起补
local order = self.iosOrders[result.definition.id]
if order then
self:saveIosPayInfo(result.transactionID, result.receipt, order, result.definition.id)
self:saveIosPayInfo(result.transactionID, result.receipt, order.order, result.definition.id, order.purchaseType, order.giftId)
self:delIosOrder(result.definition.id)
else
-- 之前没有记录只能算掉单了
@ -115,7 +114,7 @@ function SDKPayiOSManager:doUncompleteOrder(callback, productId)
end
-- 去服务器验证
if uncompleteOrder.order then
PayManager:requestRewards(uncompleteOrder.receipt, uncompleteOrder.order, uncompleteOrder.transactionID, true, function()
PayManager:requestRewards(uncompleteOrder.receipt, uncompleteOrder.order, uncompleteOrder.transactionID, uncompleteOrder.productId, true, function()
index = index + 1
handleOrder(uncompleteList[index])
end)
@ -240,8 +239,8 @@ function SDKPayiOSManager:pay(productId, orderId, rechargeId, giftType, purchase
end
-- sdk将已完成的订单消耗掉
function SDKPayiOSManager:consumePurchase(token, callback)
CS.BF.BFMain.Instance.SDKMgr.IosPaySDKMgr:ConsumePurchase(token)
function SDKPayiOSManager:consumePurchase(productId, callback)
CS.BF.BFMain.Instance.SDKMgr.IosPaySDKMgr:ConsumePurchase(productId)
if callback then
callback(0)
end
@ -260,7 +259,7 @@ function SDKPayiOSManager:doIosPay(productId, orderId, rechargeId, giftType, pur
Logger.log("ios pay transactionID = %s", result.transactionID)
Logger.log("ios pay hasReceipt = %s", result.hasReceipt)
Logger.log("ios pay receipt = %s", result.receipt)
self:saveIosPayInfo(result.transactionID, result.receipt, purchaseType .. "|" .. giftId, productId)
self:saveIosPayInfo(result.transactionID, result.receipt, orderId, productId, purchaseType, giftId)
if callback then
callback(result.receipt, orderId, result.transactionID)
end
@ -273,7 +272,7 @@ function SDKPayiOSManager:doIosPay(productId, orderId, rechargeId, giftType, pur
end
self:delIosOrder(productId)
end
self:saveIosOrder(productId, purchaseType .. "|" .. giftId)
self:saveIosOrder(productId, orderId, purchaseType, giftId)
CS.BF.BFMain.Instance.SDKMgr.IosPaySDKMgr:Buy(productId, orderId)
end
@ -298,12 +297,14 @@ end
function SDKPayiOSManager:checkPurchaseOrder(result, productId, callback)
end
function SDKPayiOSManager:saveIosPayInfo(transactionID, receipt, order, productId)
function SDKPayiOSManager:saveIosPayInfo(transactionID, receipt, order, productId, purchaseType, giftId)
self.iosPayInfos[transactionID] = {
order = order,
receipt = receipt,
transactionID = transactionID,
productId = productId
productId = productId,
purchaseType = purchaseType,
giftId = giftId
}
LocalData:setIosPayInfo(self.iosPayInfos)
LocalData:save()
@ -319,8 +320,12 @@ function SDKPayiOSManager:getIosPayInfo(transactionID)
return self.iosPayInfos[transactionID]
end
function SDKPayiOSManager:saveIosOrder(productId, order)
self.iosOrders[productId] = order
function SDKPayiOSManager:saveIosOrder(productId, order, purchaseType, giftId)
self.iosOrders[productId] = {
order = order,
purchaseType = purchaseType,
giftId = giftId
}
LocalData:setIosOrders(self.iosOrders)
LocalData:save()
end
@ -331,82 +336,4 @@ function SDKPayiOSManager:delIosOrder(productId)
LocalData:save()
end
-- 第一步向服务器验证订单号
-- function SDKPayiOSManager:checkPurchaseIOSOrder(result, productId, callback)
-- Logger.printTable(result)
-- Logger.log(productId)
-- local orderId = DataManager.PlayerData:getIosOrderId(result.transactionID)
-- if not orderId then
-- return
-- end
-- if DataManager.PlayerData:isInPermanentOrders(result.transactionID) then
-- return
-- end
-- local params = {}
-- -- params.receipt.packageName = Platform:getIdentifier()
-- -- params.receipt.productId = productId
-- params.receipt = result.receipt
-- params.transaction_id = result.transactionID
-- CS.BF.BFMain.Instance.ParseClientMgr:SetLuaCheckPurchaseIOSOrderCallback(function (msg)
-- local serverResult = json.decode(msg)
-- local _result = serverResult.result
-- Logger.printTable(serverResult)
-- -- 后端返回latest_receipt_info
-- if _result and _result.data then
-- if _result.code == 0 then
-- SDKPayiOSManager:saveOrderId(result.transactionID, params)
-- -- 第二次验证
-- SDKPayiOSManager:checkPurchaseConsume(result, params, callback)
-- elseif _result.code == 137 then
-- -- SDKPayiOSManager:delOrderId(_result.data.orderId)
-- -- 消耗订单
-- -- SDKPayiOSManager:consumePurchase(_result.data.purchaseToken)
-- else
-- -- @TODO 重试
-- end
-- end
-- end)
-- CS.BF.BFMain.Instance.ParseClientMgr:CheckPurchaseIOSOrder(json.encode(params))
-- end
-- 第二步向服务器申请消耗订单
-- function SDKPayiOSManager:checkPurchaseConsume(result, params, callback, callback1)
-- if not result or not params then
-- return
-- end
-- local orderId = DataManager.PlayerData:getIosOrderId(result.transactionID)
-- if not orderId then
-- return
-- end
-- CS.BF.BFMain.Instance.ParseClientMgr:SetLuaCheckPurchaseIOSConsumeCallback(function (msg)
-- local serverResult = json.decode(msg)
-- local _result = serverResult.result
-- Logger.printTable(serverResult)
-- if _result and _result.data then
-- if _result.code == 0 then
-- -- 处理本地存储订单
-- SDKPayiOSManager:delIosOrderId(result.transactionID)
-- SDKPayiOSManager:delOrderId(result.transactionID)
-- SDKPayiOSManager:savePermanentOrderId(result.transactionID)
-- if callback then
-- callback(result.receipt, orderId, result.transactionID)
-- else
-- -- SDKPayiOSManager:consumePurchase(_result.data.purchaseToken)
-- PayManager:requestRewards(_result.data.purchaseToken, orderId)
-- if callback1 then
-- callback1()
-- end
-- end
-- elseif _result.code == 137 then
-- else
-- -- @TODO 重试
-- end
-- end
-- end)
-- CS.BF.BFMain.Instance.ParseClientMgr:CheckPurchaseIOSConsume(json.encode(params))
-- end
-- 支付相关接口 ********************************************************************** 结束
return SDKPayiOSManager

View File

@ -174,11 +174,11 @@ function GameSettingUI:_addListeners()
end)
self.uiMap["game_setting_ui.bg.tx_1"]:addClickListener(function()
GFunc.openUrl("http://agileliongames.com/AgileLionGames%27sPrivacyPolicy.html")
GFunc.openUrl("https://perfeggsgame.com/tos.html")
end)
self.uiMap["game_setting_ui.bg.tx_2"]:addClickListener(function()
GFunc.openUrl("http://agileliongames.com/AgileLionGames%27sPrivacyPolicy.html")
GFunc.openUrl("https://perfeggsgame.com/pp.html")
end)
end