PayInterface.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. using FrameWork.SDKManager;
  2. using HDJ.Framework.Utils;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. namespace FrameWork.SDKManager
  7. {
  8. public abstract class PayInterface : SDKInterfaceBase
  9. {
  10. /// <summary>
  11. /// 验证回调,参数:string(商店名),string(订单凭据,base64加密串)
  12. /// </summary>
  13. //public CallBack<StoreName, string> m_ConfirmCallBack;
  14. protected List<LocalizedGoodsInfo> productDefinitions = new List<LocalizedGoodsInfo>();
  15. public virtual StoreName GetStoreName()
  16. {
  17. return StoreName.None;
  18. }
  19. public override void ExtraInit(string tag)
  20. {
  21. if (!string.IsNullOrEmpty(tag))
  22. {
  23. productDefinitions = JsonUtils.FromJson<List<LocalizedGoodsInfo>>(tag);
  24. }
  25. ExtraInit();
  26. }
  27. protected virtual void ExtraInit()
  28. {
  29. }
  30. virtual public void Pay(string goodsID, string tag, GoodsType goodsType = GoodsType.NORMAL, string orderID = null)
  31. {
  32. }
  33. virtual public void ConfirmPay(string goodsID, string tag)
  34. {
  35. }
  36. virtual public LocalizedGoodsInfo GetGoodsInfo(string goodsID)
  37. {
  38. for (int i = 0; i < productDefinitions.Count; i++)
  39. {
  40. if(productDefinitions[i].goodsID == goodsID)
  41. {
  42. return productDefinitions[i];
  43. }
  44. }
  45. return null;
  46. }
  47. virtual public List<LocalizedGoodsInfo> GetAllGoodsInfo()
  48. {
  49. return productDefinitions;
  50. }
  51. public override void Init()
  52. {
  53. }
  54. protected void PayCallBack(OnPayInfo info)
  55. {
  56. info.storeName = GetStoreName();
  57. if (SDKManager.PayCallBack != null)
  58. SDKManager.PayCallBack(info);
  59. }
  60. /// <summary>
  61. /// 获取商品类型
  62. /// </summary>
  63. /// <param name="goodID"></param>
  64. /// <returns></returns>
  65. public GoodsType GetGoodType(string goodID)
  66. {
  67. for (int i = 0; i < productDefinitions.Count; i++)
  68. {
  69. if (productDefinitions[i].goodsID == goodID)
  70. {
  71. return productDefinitions[i].goodsType;
  72. }
  73. }
  74. Debug.LogError(" pay productDefinitions goodID is not found" + "id: " + goodID + " count: " + productDefinitions.Count);
  75. return GoodsType.NORMAL;
  76. }
  77. }
  78. /// <summary>
  79. /// 本地化商品信息,来自SDK平台的后台,如:
  80. /// localizedPriceString :¥6.00
  81. ///localizedTitle :小包钻石
  82. ///localizedDescription :钻石可以在游戏内用于购买各项商品
  83. ///isoCurrencyCode :CNY
  84. ///localizedPrice :6
  85. /// </summary>
  86. public class LocalizedGoodsInfo
  87. {
  88. public LocalizedGoodsInfo()
  89. {
  90. }
  91. public LocalizedGoodsInfo(string goodsID, GoodsType goodsType, float price,string isoCurrencyCode = "CNY")
  92. {
  93. this.goodsID = goodsID;
  94. this.goodsType = goodsType;
  95. this.localizedPrice = price;
  96. this.isoCurrencyCode = isoCurrencyCode; //默认人民币
  97. }
  98. /// <summary>
  99. /// id
  100. /// </summary>
  101. public string goodsID;
  102. /// <summary>
  103. /// 描述串
  104. /// </summary>
  105. public string localizedPriceString;
  106. /// <summary>
  107. /// 标题
  108. /// </summary>
  109. public string localizedTitle;
  110. /// <summary>
  111. /// 商店描述
  112. /// </summary>
  113. public string localizedDescription;
  114. /// <summary>
  115. /// 货币类型
  116. /// </summary>
  117. public string isoCurrencyCode;
  118. /// <summary>
  119. /// 价格
  120. /// </summary>
  121. public float localizedPrice;
  122. /// <summary>
  123. /// 商品类型
  124. /// </summary>
  125. public GoodsType goodsType;
  126. }
  127. }