ios支付处理

This commit is contained in:
xiekaidong 2023-06-09 16:08:22 +08:00
parent c300705012
commit 1ddb7bd43b
6 changed files with 72 additions and 21 deletions

View File

@ -136,6 +136,9 @@ end
function PayManager:requestRewards(purchaseToken, orderId, originOrderId, notShowRewardsBox) function PayManager:requestRewards(purchaseToken, orderId, originOrderId, notShowRewardsBox)
self:sendMsgToServer(purchaseToken, orderId, function(binder, msgData) self:sendMsgToServer(purchaseToken, orderId, function(binder, msgData)
if msgData.status == 0 then if msgData.status == 0 then
if Platform:isIosPlatform() then
SDKManager:delIosPayInfo(purchaseToken)
end
local showRewards = not notShowRewardsBox local showRewards = not notShowRewardsBox
if DataManager.TutorialData and DataManager.TutorialData:getIsInTutorial() then -- 引导时不弹 if DataManager.TutorialData and DataManager.TutorialData:getIsInTutorial() then -- 引导时不弹
showRewards = false showRewards = false
@ -204,7 +207,7 @@ function PayManager:checkAndPay(productId, id, purchaseType, rechargeId)
if msgData.uuid and msgData.uuid ~= GConst.EMPTY_STRING then if msgData.uuid and msgData.uuid ~= GConst.EMPTY_STRING then
local giftType = PayManager:getGiftType(purchaseType, id) local giftType = PayManager:getGiftType(purchaseType, id)
BIReport:postPayTurn(giftType, id, rechargeId) BIReport:postPayTurn(giftType, id, rechargeId)
SDKManager:pay(productId, msgData.uuid, rechargeId, giftType, id, function(purchaseToken, orderId, originOrderId) SDKManager:pay(productId, msgData.uuid, rechargeId, giftType, purchaseType, id, function(purchaseToken, orderId, originOrderId)
if purchaseToken and orderId then if purchaseToken and orderId then
self:requestRewards(purchaseToken, orderId, originOrderId) self:requestRewards(purchaseToken, orderId, originOrderId)
end end
@ -229,15 +232,34 @@ function PayManager:checkAndPay(productId, id, purchaseType, rechargeId)
end end
function PayManager:sendMsgToServer(purchaseToken, orderId, callback) function PayManager:sendMsgToServer(purchaseToken, orderId, callback)
local args = { if Platform:isIosPlatform() then
uuid = {orderId}, local payParams = SDKManager:getIosPayInfo(purchaseToken)
channel = SDKManager:getSDKPayType(), if not payParams or not payParams.order then
pay_token = purchaseToken return -- 支付错误
} end
if EDITOR_MODE then local info = string.split(payParams.order, "|")
args.channel = SDKManager.PAY_TYPE.DEBUG local gift_type = tonumber(info[1])
local gift_id = tonumber(info[2])
if not gift_id or not gift_id then
return -- 解析错误
end
local args = {
id = gift_id,
act_type = gift_type,
pay_token = purchaseToken
}
self:sendMessage(ProtoMsgType.FromMsgEnum.AppStorePaidReq, args, {}, callback)
else
local args = {
uuid = {orderId},
channel = SDKManager:getSDKPayType(),
pay_token = purchaseToken
}
if EDITOR_MODE then
args.channel = SDKManager.PAY_TYPE.DEBUG
end
self:sendMessage(ProtoMsgType.FromMsgEnum.ActPaidResultReq, args, {}, callback)
end end
self:sendMessage(ProtoMsgType.FromMsgEnum.ActPaidResultReq, args, {}, callback)
end end
return PayManager return PayManager

View File

@ -166,14 +166,26 @@ function SDKManager:checkPay(productId, callback)
end end
-- 支付 -- 支付
function SDKManager:pay(productId, orderId, rechargeId, giftType, giftId, callback) function SDKManager:pay(productId, orderId, rechargeId, giftType, purchaseType, giftId, callback)
SDKPayMgr:pay(productId, orderId, rechargeId, giftType, giftId, callback) SDKPayMgr:pay(productId, orderId, rechargeId, giftType, purchaseType, giftId, callback)
end end
function SDKManager:doUncompletePay(callback) function SDKManager:doUncompletePay(callback)
SDKPayMgr:doUncompletePay(callback) SDKPayMgr:doUncompletePay(callback)
end end
function SDKManager:getIosPayInfo(transactionID)
if SDKPayMgr.getIosPayInfo then
return SDKPayMgr:getIosPayInfo(transactionID)
end
end
function SDKManager:delIosPayInfo(transactionID)
if SDKPayMgr.delIosPayInfo then
return SDKPayMgr:delIosPayInfo(transactionID)
end
end
-- 支付相关接口 ********************************************************************** 结束 -- 支付相关接口 ********************************************************************** 结束
-- 获取设备语言 -- 获取设备语言

View File

@ -45,7 +45,7 @@ function SDKPayDefaultManager:checkPay(productId, callback)
end end
-- 支付 -- 支付
function SDKPayDefaultManager:pay(productId, orderId, rechargeId, giftType, giftId, callback) function SDKPayDefaultManager:pay(productId, orderId, rechargeId, giftType, purchaseType, giftId, callback)
callback("", orderId) callback("", orderId)
end end

View File

@ -313,8 +313,8 @@ function SDKPayGoogleManager:checkPay(productId, callback)
end end
-- 支付 -- 支付
function SDKPayGoogleManager:pay(productId, orderId, rechargeId, giftType, giftId, callback) function SDKPayGoogleManager:pay(productId, orderId, rechargeId, giftType, purchaseType, giftId, callback)
self:doGooglePay(productId, orderId, rechargeId, giftType, giftId, callback) self:doGooglePay(productId, orderId, rechargeId, giftType, purchaseType, giftId, callback)
end end
-- 连接Google商店 -- 连接Google商店
@ -326,7 +326,7 @@ function SDKPayGoogleManager:connectGoogleStore(callback)
end) end)
end end
function SDKPayGoogleManager:doGooglePay(productId, orderId, rechargeId, giftType, giftId, callback) function SDKPayGoogleManager:doGooglePay(productId, orderId, rechargeId, giftType, purchaseType, giftId, callback)
local payType = PAY_TYPE_IN_APP local payType = PAY_TYPE_IN_APP
local rechargeCfg = ConfigManager:getConfig("recharge")[rechargeId] local rechargeCfg = ConfigManager:getConfig("recharge")[rechargeId]
if rechargeCfg.subscribe then if rechargeCfg.subscribe then

View File

@ -227,8 +227,8 @@ function SDKPayiOSManager:checkPay(productId, callback)
end end
-- 支付 -- 支付
function SDKPayiOSManager:pay(productId, orderId, rechargeId, giftType, giftId, callback) function SDKPayiOSManager:pay(productId, orderId, rechargeId, giftType, purchaseType, giftId, callback)
self:doIosPay(productId, orderId, rechargeId, giftType, giftId, callback) self:doIosPay(productId, orderId, rechargeId, giftType, purchaseType, giftId, callback)
end end
-- sdk将已完成的订单消耗掉 -- sdk将已完成的订单消耗掉
@ -239,7 +239,7 @@ function SDKPayiOSManager:consumePurchase(token, callback)
end end
end end
function SDKPayiOSManager:doIosPay(productId, orderId, rechargeId, giftType, giftId, callback) function SDKPayiOSManager:doIosPay(productId, orderId, rechargeId, giftType, purchaseType, giftId, callback)
self.blockTouch = true self.blockTouch = true
UIManager:showWaitNet() UIManager:showWaitNet()
CS.BF.BFMain.Instance.SDKMgr.IosPaySDKMgr.buyCallback = function(isSuccess, result, errorStr) CS.BF.BFMain.Instance.SDKMgr.IosPaySDKMgr.buyCallback = function(isSuccess, result, errorStr)
@ -252,7 +252,7 @@ function SDKPayiOSManager:doIosPay(productId, orderId, rechargeId, giftType, gif
Logger.log("ios pay transactionID = %s", result.transactionID) Logger.log("ios pay transactionID = %s", result.transactionID)
Logger.log("ios pay hasReceipt = %s", result.hasReceipt) Logger.log("ios pay hasReceipt = %s", result.hasReceipt)
Logger.log("ios pay receipt = %s", result.receipt) Logger.log("ios pay receipt = %s", result.receipt)
self:saveIosPayInfo(result.transactionID, result.receipt, orderId, productId) self:saveIosPayInfo(result.transactionID, result.receipt, purchaseType .. "|" .. giftId, productId)
if callback then if callback then
callback(result.receipt, orderId, result.transactionID) callback(result.receipt, orderId, result.transactionID)
end end
@ -301,6 +301,16 @@ function SDKPayiOSManager:saveIosPayInfo(transactionID, receipt, order, productI
LocalData:save() LocalData:save()
end end
function SDKPayiOSManager:delIosPayInfo(transactionID)
self.iosPayInfos[transactionID] = nil
LocalData:setIosPayInfo(self.iosPayInfos)
LocalData:save()
end
function SDKPayiOSManager:getIosPayInfo(transactionID)
return self.iosPayInfos[transactionID]
end
function SDKPayiOSManager:saveIosOrder(productId, order) function SDKPayiOSManager:saveIosOrder(productId, order)
self.iosOrders[productId] = order self.iosOrders[productId] = order
LocalData:setIosOrders(self.iosOrders) LocalData:setIosOrders(self.iosOrders)

View File

@ -702,7 +702,7 @@ function NetManager:onReceive(msgId, data)
if NOT_PUBLISH then if NOT_PUBLISH then
Logger.printTable(responseData) Logger.printTable(responseData)
end end
if pbData.rewards then if pbData.err_code == GConst.ERROR_STR.SUCCESS and pbData.rewards then
local getType = receiveCallback.getType local getType = receiveCallback.getType
if sendMsgName == "ActPayReq" then if sendMsgName == "ActPayReq" then
getType = PayManager:getItemGetType(pbData.act_type, pbData.id) getType = PayManager:getItemGetType(pbData.act_type, pbData.id)
@ -713,6 +713,13 @@ function NetManager:onReceive(msgId, data)
break break
end end
end end
elseif sendMsgName == "AppStorePaidReq" then -- ios支付上报统一处理
if pbData.gift then
for _, gift in ipairs(pbData.gift) do
getType = PayManager:getItemGetType(gift.act_type, gift.id)
break
end
end
end end
if EDITOR_MODE and not getType then if EDITOR_MODE and not getType then
@ -721,7 +728,7 @@ function NetManager:onReceive(msgId, data)
GFunc.addRewards(pbData.rewards, getType) GFunc.addRewards(pbData.rewards, getType)
end end
if pbData.costs and not self:getNotAddCostsRsp(msgName) then if pbData.err_code == GConst.ERROR_STR.SUCCESS and pbData.costs and not self:getNotAddCostsRsp(msgName) then
local getType = receiveCallback.getType local getType = receiveCallback.getType
if sendMsgName == "ActPayReq" then if sendMsgName == "ActPayReq" then
getType = PayManager:getItemGetType(pbData.mall_type, pbData.id) getType = PayManager:getItemGetType(pbData.mall_type, pbData.id)