92 lines
3.4 KiB
Lua
92 lines
3.4 KiB
Lua
|
--[[
|
|||
|
* @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()
|
|||
|
|
|||
|
end
|
|||
|
----- 请求支付
|
|||
|
----- @param context
|
|||
|
---- {
|
|||
|
---- Id, -- required, 商品ID
|
|||
|
---- BuyNum, -- optional, 购买个数(默认1)
|
|||
|
---- }
|
|||
|
function this.Pay(context)
|
|||
|
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
|
|||
|
this.RequestPay(payData)
|
|||
|
end
|
|||
|
|
|||
|
function this.RequestPay(context)
|
|||
|
KTSDK.Helper.Instance.onPayCallback = function(payResp)
|
|||
|
local str = string.split(payResp, "#")
|
|||
|
local code = tonumber(str[1])
|
|||
|
local result = str[2]
|
|||
|
if code == SDKCodeResult.CODE_PAY_SUCCESS then
|
|||
|
--PopupTipPanel.ShowTip("充值成功" .. result)
|
|||
|
--Game.GlobalEvent:DispatchEvent(GameEvent.MoneyPay.OnPayResultSuccess,context.Id)
|
|||
|
--FirstRechargeManager.RefreshAccumRechargeValue(context.Id)
|
|||
|
DataCenterManager.CommitPayStatus(
|
|||
|
"IN_GAME_"..context.Type,
|
|||
|
KTSDK.Helper.Instance:GetPayOrderID(),
|
|||
|
"VALID",
|
|||
|
tostring(context.Price)
|
|||
|
)
|
|||
|
elseif code == SDKCodeResult.CODE_PAY_FAIL then
|
|||
|
--PopupTipPanel.ShowTip("充值失败" .. result)
|
|||
|
DataCenterManager.CommitPayStatus(
|
|||
|
"IN_GAME_"..context.Type,
|
|||
|
KTSDK.Helper.Instance:GetPayOrderID(),
|
|||
|
"INVALID",
|
|||
|
tostring(context.Price)
|
|||
|
)
|
|||
|
elseif code == SDKCodeResult.CODE_PAYING then
|
|||
|
--PopupTipPanel.ShowTip("正在充值中" .. result)
|
|||
|
elseif code == SDKCodeResult.CODE_PAY_CANCEL then
|
|||
|
--PopupTipPanel.ShowTip("取消充值" .. result)
|
|||
|
DataCenterManager.CommitPayStatus(
|
|||
|
"IN_GAME_"..context.Type,
|
|||
|
KTSDK.Helper.Instance:GetPayOrderID(),
|
|||
|
"INVALID",
|
|||
|
tostring(context.Price)
|
|||
|
)
|
|||
|
elseif code == SDKCodeResult.CODE_PAY_UNKNOWN then
|
|||
|
--PopupTipPanel.ShowTip("未知" .. result)
|
|||
|
end
|
|||
|
end
|
|||
|
local params = KTSDK.KTSDKPayArgs.New()
|
|||
|
params.productId = context.Id
|
|||
|
params.productName = context.Name or ""
|
|||
|
params.productDesc = context.Desc or ""
|
|||
|
params.price = context.Price
|
|||
|
params.ratio = 1
|
|||
|
params.buyNum = context.BuyNum or 1
|
|||
|
params.coinNum = BagManager.GetItemCountById(16)
|
|||
|
params.zoneId = PlayerManager.serverInfo.server_id
|
|||
|
params.serverID = PlayerManager.serverInfo.server_id
|
|||
|
params.serverName = PlayerManager.serverInfo.name
|
|||
|
params.roleID = tostring(PlayerManager.uid)
|
|||
|
params.roleName = PlayerManager.nickName
|
|||
|
params.roleLevel = PlayerManager.level
|
|||
|
params.vip = tostring(VipManager.GetVipLevel())
|
|||
|
params.guildID = PlayerManager.familyId
|
|||
|
params.payNotifyUrl = ""
|
|||
|
params.extension = string.format("%s_%s_%s_%s_%s_%s",
|
|||
|
AppConst.OpenId,context.Id,context.Price,PlayerManager.uid,
|
|||
|
PlayerManager.serverInfo.server_id,PlayerManager.serverInfo.name)
|
|||
|
KTSDK.Helper.Instance:Pay(params)
|
|||
|
end
|
|||
|
|
|||
|
return this
|