PaymentVerificationManager.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using FrameWork.SDKManager;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using UnityEngine;
  7. /// <summary>
  8. /// 管理支付验证
  9. /// </summary>
  10. public class PaymentVerificationManager
  11. {
  12. public static CallBack<int, string> onVerificationResultCallBack;
  13. private static PaymentVerificationInterface verificationInterface;
  14. public static void Init(PaymentVerificationInterface verificationInterface)
  15. {
  16. PaymentVerificationManager.verificationInterface = verificationInterface;
  17. verificationInterface.Init();
  18. SDKManager.PayCallBack += PayCallBack;
  19. }
  20. private static void PayCallBack(OnPayInfo info)
  21. {
  22. if (info.isSuccess)
  23. {
  24. verificationInterface.CheckRecipe(info);
  25. }
  26. else
  27. {
  28. Debug.LogWarning("PaymentVerificationManager PayCallBack=========" + info.goodsId);
  29. int code = info.isSuccess ? 0 : -1;
  30. OnVerificationResult(code, info.goodsId,false,info.receipt);
  31. }
  32. }
  33. /// <summary>
  34. /// 验证结果调用
  35. /// </summary>
  36. /// <param name="code">是否成功</param>
  37. /// <param name="goodsID">物品ID</param>
  38. /// <param name="repeatReceipt">是否是重复的订单凭据</param>
  39. /// <param name="receipt">回执,商户订单号等</param>
  40. public static void OnVerificationResult(int code,string goodsID, bool repeatReceipt,string receipt)
  41. {
  42. if (onVerificationResultCallBack != null)
  43. {
  44. Debug.LogWarning("验证回调code=========" + code + "-------goodsID=========" + goodsID);
  45. onVerificationResultCallBack(code, goodsID);
  46. }
  47. if (code==0 || repeatReceipt)
  48. SDKManager.ConfirmPay(goodsID, receipt);
  49. //验证成功
  50. if (code!=0)
  51. {
  52. Debug.LogError("凭据验证失败! goodID:" + goodsID);
  53. }
  54. }
  55. }