miduo_client/Assets/ManagedResources/~Lua/Modules/Pay/PayManager.lua

134 lines
4.4 KiB
Lua
Raw Normal View History

2020-08-25 15:46:38 +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()
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
---- }
----
----
this.EventTrigger = {}
function this.onSdkPayResult(id)
LogError("收到sdk支付成功回调商品id = "..id)
if this.EventTrigger[id] then
this.EventTrigger[id](id)
this.EventTrigger[id] = nil
end
end
function this.Pay(id, func)
if not func then
func = function()end
end
if this.EventTrigger[id] then
LogError("重复发起购买商品的请求商品id = "..id..", uid = "..PlayerManager.uid)
PopupTipPanel.ShowTip("您有一个相同的订单正在处理,请稍后再试")
return
end
this.EventTrigger[id] = func
LogError("发起购买商品的请求商品id = "..id)
--直购商品
if AppConst.isSDKLogin then
PayManager.SdkPay({ Id = id })
else
NetManager.RequestBuyGiftGoods(id, function(msg)
this.onSdkPayResult(id)
end)
end
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
-- 判断计费点
if AppConst.SdkPackageName == "com.tcxazcsb.pass" or AppConst.SdkPackageName == "com.tcxaz.pass" then -- 海外GP 测试+正式
payData.RechargeId = rechargeConfig.RechargeId
elseif AppConst.SdkPackageName == "com.jltest.www" then -- 海外Ios测试
payData.RechargeId = rechargeConfig.RechargeId2
elseif AppConst.SdkPackageName == "com.tcxhw.project" then -- 海外Ios正式
payData.RechargeId = rechargeConfig.RechargeId3
else
payData.RechargeId = rechargeConfig.Id
end
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)
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]
if result == SDK_RESULT.SUCCESS then
2020-08-22 15:31:14 +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 ""
2020-08-22 15:31:14 +08:00
params.price = price * 100 -- 以分为单位
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
-- 角色相关
2020-09-14 12:59:53 +08:00
params.roleID = tostring(PlayerManager.uid).."_"..tostring(context.Id)
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 = ""
2020-08-27 19:18:31 +08:00
params.extension = tostring(context.Id)--string.format("%s_%s_%s", PlayerManager.uid, context.Id, VersionManager:GetVersionInfo("subChannel"))--tostring(context.Id)
--string.format("%s_%s_%s_%s_%s_%s",
-- AppConst.OpenId,context.Id,context.Price,PlayerManager.uid,
-- PlayerManager.serverInfo.server_id,PlayerManager.serverInfo.name)
2020-07-15 13:44:37 +08:00
SDKMgr:Pay(params)
--
ThinkingAnalyticsManager.Track("create_order", {
goods_id = context.Id,
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-05-09 13:31:21 +08:00
end
2020-06-23 18:36:24 +08:00
return this