// +---------------------------------------------------------------------- declare (strict_types=1); namespace app\common\library\payment\gateway; use cores\traits\ErrorTrait; use cores\exception\BaseException; /** * 第三方支付驱动基类 * Class Driver * @package app\common\library\payment\gateway\driver */ abstract class Driver { use ErrorTrait; /** * 驱动句柄 * @var Driver|null */ protected ?Driver $handler = null; /** * 支付的客户端 * @var string|null */ protected ?string $client = null; /** * 支付配置参数 * @var array */ protected array $options = []; /** * 设置支付配置参数 * @param array $options 配置信息 * @param string $client 下单客户端 * @return static|null */ public function setOptions(array $options, string $client): ?Driver { $this->client = $client ?: null; $this->options = $options; return $this; } /** * 统一下单API * @param string $outTradeNo 第三方交易单号 * @param string $totalFee 实际付款金额 * @param array $extra 附加的数据 (需要携带openid) * @return bool * @throws BaseException */ abstract public function addReceiver(string $type, string $account, string $name, string $relation_type = "HEADQUARTER", string $custom_relation = ""): bool; abstract public function profitsharing(string $transaction_id, string $out_order_no, array $receivers): bool; abstract public function profitsharingQuery(string $out_order_no, string $transaction_id): ?array; abstract public function unify(string $outTradeNo, string $totalFee, array $extra = []): bool; /** * 交易查询 (主动查询订单支付状态) * @param string $outTradeNo 第三方交易单号 * @return array|null * @throws BaseException */ abstract public function tradeQuery(string $outTradeNo): ?array; /** * 获取异步回调的请求参数 * @return array */ abstract public function getNotifyParams(): array; /** * 返回异步通知结果的输出内容 * @return mixed */ abstract public function getNotifyResponse(); /** * 统一下单API * @param string $outTradeNo 第三方交易单号 * @param string $refundAmount 退款金额 * @param array $extra 附加的数据 (需要携带订单付款总金额) * @return bool * @throws BaseException */ abstract public function refund(string $outTradeNo, string $refundAmount, array $extra = []): bool; }