Driver.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2024 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\common\library\payment\gateway;
  13. use cores\traits\ErrorTrait;
  14. use cores\exception\BaseException;
  15. /**
  16. * 第三方支付驱动基类
  17. * Class Driver
  18. * @package app\common\library\payment\gateway\driver
  19. */
  20. abstract class Driver
  21. {
  22. use ErrorTrait;
  23. /**
  24. * 驱动句柄
  25. * @var Driver|null
  26. */
  27. protected ?Driver $handler = null;
  28. /**
  29. * 支付的客户端
  30. * @var string|null
  31. */
  32. protected ?string $client = null;
  33. /**
  34. * 支付配置参数
  35. * @var array
  36. */
  37. protected array $options = [];
  38. /**
  39. * 设置支付配置参数
  40. * @param array $options 配置信息
  41. * @param string $client 下单客户端
  42. * @return static|null
  43. */
  44. public function setOptions(array $options, string $client): ?Driver
  45. {
  46. $this->client = $client ?: null;
  47. $this->options = $options;
  48. return $this;
  49. }
  50. /**
  51. * 统一下单API
  52. * @param string $outTradeNo 第三方交易单号
  53. * @param string $totalFee 实际付款金额
  54. * @param array $extra 附加的数据 (需要携带openid)
  55. * @return bool
  56. * @throws BaseException
  57. */
  58. abstract public function unify(string $outTradeNo, string $totalFee, array $extra = []): bool;
  59. /**
  60. * 交易查询 (主动查询订单支付状态)
  61. * @param string $outTradeNo 第三方交易单号
  62. * @return array|null
  63. * @throws BaseException
  64. */
  65. abstract public function tradeQuery(string $outTradeNo): ?array;
  66. /**
  67. * 获取异步回调的请求参数
  68. * @return array
  69. */
  70. abstract public function getNotifyParams(): array;
  71. /**
  72. * 返回异步通知结果的输出内容
  73. * @return mixed
  74. */
  75. abstract public function getNotifyResponse();
  76. /**
  77. * 统一下单API
  78. * @param string $outTradeNo 第三方交易单号
  79. * @param string $refundAmount 退款金额
  80. * @param array $extra 附加的数据 (需要携带订单付款总金额)
  81. * @return bool
  82. * @throws BaseException
  83. */
  84. abstract public function refund(string $outTradeNo, string $refundAmount, array $extra = []): bool;
  85. }