2021-06-08 19:29:21 +08:00
--[[
2020-05-09 13:31:21 +08:00
* @ ClassName PayManager
* @ Description 支 付 管 理 系 统
* @ Date 2019 / 6 / 25 20 : 14
* @ Author MagicianJoker , fengliudianshao @ outlook.com
* @ Copyright Copyright ( c ) 2019 , MagicianJoker
--]]
PayManager = { }
local this = PayManager
--初始化
function this . Initialize ( )
2020-09-09 18:47:17 +08:00
Game.GlobalEvent : AddEvent ( GameEvent.MoneyPay . OnPayResultSuccess , this.onSdkPayResult )
2020-05-09 13:31:21 +08:00
end
----- 请求支付
----- @param context
---- {
---- Id, -- required, 商品ID
---- BuyNum, -- optional, 购买个数(默认1)
---- }
2020-09-09 18:47:17 +08:00
----
----
this.EventTrigger = { }
function this . onSdkPayResult ( id )
2021-08-02 17:02:22 +08:00
LogRed ( " 收到sdk支付成功回调, 商品id = " .. id )
2020-09-09 18:47:17 +08:00
if this.EventTrigger [ id ] then
this.EventTrigger [ id ] ( id )
this.EventTrigger [ id ] = nil
end
2021-03-17 17:36:50 +08:00
local rechargeConfig = ConfigManager.GetConfigData ( ConfigName.RechargeCommodityConfig , id )
if rechargeConfig then
local Price = tostring ( rechargeConfig.Price )
CustomEventManager.SendCustomEvent ( " mhtPay " , Price , " 4 " )
end
2020-09-09 18:47:17 +08:00
end
2021-08-02 17:02:22 +08:00
-- 这里发过来的是sdk的orderID
2021-03-20 22:12:51 +08:00
function this . RechargeSuccessOrder ( msg )
2021-08-02 17:02:22 +08:00
LogRed ( " 充值成功, orderId = " .. tostring ( msg.orderId ) )
2021-03-20 22:12:51 +08:00
-- 订单id特殊传值
CustomEventManager.SendCustomEvent ( " PayOrderId " , tostring ( msg.orderId ) , " 0 " )
end
2020-09-09 18:47:17 +08:00
function this . Pay ( id , func )
2022-03-28 18:18:19 +08:00
if not RECHARGEABLE then
return
end
2021-08-02 17:02:22 +08:00
LogRed ( " 发起购买商品的请求, 商品id = " .. id )
2020-09-09 18:47:17 +08:00
if not func then
func = function ( ) end
end
2021-08-02 17:02:22 +08:00
-- 请求游戏服务器的orderId
NetManager.RequestPayOrderId ( id , function ( orderId )
-- if this.EventTrigger[id] then
-- LogError("重复发起购买商品的请求, 商品id = "..id..", uid = "..PlayerManager.uid)
-- PopupTipPanel.ShowTip("您有一个相同的订单正在处理,请稍后再试")
-- return
-- end
LogRed ( " 发起购买商品的请求, 订单id = " .. orderId )
this.EventTrigger [ id ] = func
CheckRedPointStatus ( RedPointType.GrowthPackage ) --成长礼包的红点检测
--直购商品
local rechargeConfig = ConfigManager.GetConfigData ( ConfigName.RechargeCommodityConfig , id )
2023-08-29 17:58:24 +08:00
local yhqNum = BagManager.GetItemCountById ( 108 )
if yhqNum >= rechargeConfig.Price and rechargeConfig.Price > 0 then
local sureFunc = function ( )
NetManager.SendYHQBuyGoodRequest ( id )
end
local cancelFunc = function ( )
if AppConst.isSDKLogin and rechargeConfig.Price > 0 then
PayManager.SdkPay ( { Id = id , orderId = orderId } )
else
NetManager.RequestBuyGiftGoods ( id , function ( msg )
this.onSdkPayResult ( id )
end )
end
end
local args = { }
args [ 1 ] = " 该礼包可通过消耗代金券获得,是否继续充值 "
args [ 2 ] = " 代金券购买 "
args [ 3 ] = " 直接充值 "
args [ 4 ] = sureFunc
args [ 5 ] = cancelFunc
UIManager.OpenPanel ( UIName.GMCommonConfirmPanel , args )
return
end
2022-09-20 17:04:48 +08:00
if rechargeConfig.BuyType == 1 then --人民币
if AppConst.isSDKLogin and rechargeConfig.Price > 0 then
PayManager.SdkPay ( { Id = id , orderId = orderId } )
else
NetManager.RequestBuyGiftGoods ( id , function ( msg )
this.onSdkPayResult ( id )
end )
end
elseif rechargeConfig.BuyType == 2 then --gm余额购买
NetManager.SendGmBuyGoodRequest ( id )
elseif rechargeConfig.BuyType == 3 then --rmb/gm余额购买
local sureFunc = function ( )
2022-11-10 13:45:03 +08:00
NetManager.SendGmBuyGoodRequest ( id )
2022-09-20 17:04:48 +08:00
end
local cancelFunc = function ( )
if AppConst.isSDKLogin and rechargeConfig.Price > 0 then
PayManager.SdkPay ( { Id = id , orderId = orderId } )
else
NetManager.RequestBuyGiftGoods ( id , function ( msg )
this.onSdkPayResult ( id )
end )
end
end
local args = { }
args [ 1 ] = " 该福利可以通过GM修改器获得, 是否继续充值 "
args [ 2 ] = " GM修改器 "
args [ 3 ] = " 直接充值 "
args [ 4 ] = sureFunc
args [ 5 ] = cancelFunc
UIManager.OpenPanel ( UIName.GMCommonConfirmPanel , args )
2021-08-02 17:02:22 +08:00
end
2022-09-20 17:04:48 +08:00
2021-08-02 17:02:22 +08:00
end )
2020-09-09 18:47:17 +08:00
end
function this . SdkPay ( context )
2020-05-09 13:31:21 +08:00
local rechargeConfig = ConfigManager.GetConfigData ( ConfigName.RechargeCommodityConfig , context.Id )
local payData = table.clone ( context )
payData.Name = rechargeConfig.Name
payData.Desc = rechargeConfig.Desc
payData.Price = rechargeConfig.Price
payData.Type = rechargeConfig.Type
2020-08-27 19:18:31 +08:00
-- 判断计费点
2021-05-31 17:31:31 +08:00
local field = PackageManager.GetRechargeField ( )
if field and rechargeConfig [ field ] and rechargeConfig [ field ] ~= " " then
payData.RechargeId = rechargeConfig [ field ]
2020-08-27 19:18:31 +08:00
else
payData.RechargeId = rechargeConfig.Id
end
2023-06-12 14:31:23 +08:00
LogError ( " paydata.RechargeId== " .. payData.RechargeId )
2020-05-09 13:31:21 +08:00
this.RequestPay ( payData )
end
function this . RequestPay ( context )
2020-08-22 15:31:14 +08:00
local price = MoneyUtil.GetMoney ( context.Price )
2020-07-15 13:44:37 +08:00
SDKMgr.onPayCallback = function ( payResp )
2020-07-18 19:24:19 +08:00
Log ( " onPayCallback:: " .. payResp )
2020-05-09 13:31:21 +08:00
local str = string.split ( payResp , " # " )
2020-07-17 11:39:24 +08:00
local result = tonumber ( str [ 1 ] )
2020-08-22 15:31:14 +08:00
-- local orderId = str[2]
2020-07-18 19:24:19 +08:00
if result == SDK_RESULT.SUCCESS then
2020-08-22 15:31:14 +08:00
2020-07-18 19:24:19 +08:00
elseif result == SDK_RESULT.FAILED then
2020-08-22 15:31:14 +08:00
2020-07-17 11:39:24 +08:00
else
2020-05-09 13:31:21 +08:00
--PopupTipPanel.ShowTip("取消充值" .. result)
2020-07-17 11:39:24 +08:00
-- DataCenterManager.CommitPayStatus(
-- "IN_GAME_"..context.Type,
-- SDKMgr:GetPayOrderID(),
-- "INVALID",
-- tostring(context.Price)
-- )
2020-05-09 13:31:21 +08:00
end
end
2020-07-15 13:44:37 +08:00
local params = SDK.SDKPayArgs . New ( )
2020-08-27 19:18:31 +08:00
params.productId = context.RechargeId
2020-05-09 13:31:21 +08:00
params.productName = context.Name or " "
params.productDesc = context.Desc or " "
2022-12-06 16:45:40 +08:00
params.price = price -- 以分为单位
2020-05-09 13:31:21 +08:00
params.ratio = 1
params.buyNum = context.BuyNum or 1
params.coinNum = BagManager.GetItemCountById ( 16 )
2020-07-17 11:39:24 +08:00
-- 服务器相关
2020-05-09 13:31:21 +08:00
params.zoneId = PlayerManager.serverInfo . server_id
params.serverID = PlayerManager.serverInfo . server_id
params.serverName = PlayerManager.serverInfo . name
2020-07-17 11:39:24 +08:00
-- 角色相关
2021-08-02 17:02:22 +08:00
params.roleID = tostring ( PlayerManager.uid ) .. " _ " .. tostring ( context.Id ) .. " _ " .. PackageManager.GetCCCode ( ) .. " _ " .. AppConst.Platform --.."_"..tostring(context.orderId or "0").."_"..tostring(LoginManager.ServerId)
2020-05-09 13:31:21 +08:00
params.roleName = PlayerManager.nickName
params.roleLevel = PlayerManager.level
params.vip = tostring ( VipManager.GetVipLevel ( ) )
params.guildID = PlayerManager.familyId
2020-07-17 11:39:24 +08:00
-- 其他
2020-05-09 13:31:21 +08:00
params.payNotifyUrl = " "
2021-08-02 17:02:22 +08:00
params.extension = tostring ( PlayerManager.uid ) .. " _ " .. tostring ( context.Id ) .. " _ " .. PackageManager.GetCCCode ( ) .. " _ " .. AppConst.Platform --.."_"..tostring(context.orderId or "0").."_"..tostring(LoginManager.ServerId)
2020-07-15 13:44:37 +08:00
SDKMgr : Pay ( params )
2020-07-18 19:24:19 +08:00
--
ThinkingAnalyticsManager.Track ( " create_order " , {
goods_id = context.Id ,
2020-07-23 20:04:25 +08:00
goods_name = context.Name ,
2020-08-22 15:31:14 +08:00
order_money_amount = price ,
2020-07-27 17:48:33 +08:00
Bundle_id = AppConst.SdkPackageName ,
2020-07-18 19:24:19 +08:00
} )
2020-05-09 13:31:21 +08:00
end
2020-06-23 18:36:24 +08:00
return this