forked from helei112g/payment
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueryContext.php
More file actions
104 lines (96 loc) · 3.09 KB
/
QueryContext.php
File metadata and controls
104 lines (96 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
namespace Payment;
use Payment\Common\BaseStrategy;
use Payment\Common\PayException;
use Payment\Query\Ali\AliChargeQuery;
use Payment\Query\Ali\AliRefundQuery;
use Payment\Query\Ali\AliTransferQuery;
use Payment\Query\Cmb\CmbChargeQuery;
use Payment\Query\Cmb\CmbRefundQuery;
use Payment\Query\Wx\WxChargeQuery;
use Payment\Query\Wx\WxRefundQuery;
use Payment\Query\Wx\WxTransferQuery;
/**
* 查询上下文
* @link https://www.gitbook.com/book/helei112g1/payment-sdk/details
* @link https://helei112g.github.io/
* Class QueryContext
* @package Payment
*/
class QueryContext
{
/**
* 查询的渠道
* @var BaseStrategy
*/
protected $query;
/**
* 设置对应的查询渠道
* @param string $channel 查询渠道
* - @see Config
*
* @param array $config 配置文件
* @throws PayException
* @author helei
*/
public function initQuery($channel, array $config)
{
try {
switch ($channel) {
case Config::ALI_CHARGE:
$this->query = new AliChargeQuery($config);
break;
case Config::ALI_REFUND:// 支付宝退款订单查询
$this->query = new AliRefundQuery($config);
break;
case Config::ALI_TRANSFER:
$this->query = new AliTransferQuery($config);
break;
case Config::WX_CHARGE:// 微信支付订单查询
$this->query = new WxChargeQuery($config);
break;
case Config::WX_REFUND:// 微信退款订单查询
$this->query = new WxRefundQuery($config);
break;
case Config::WX_TRANSFER:// 微信转款订单查询
$this->query = new WxTransferQuery($config);
break;
case Config::CMB_CHARGE:// 招商支付查询
$this->query = new CmbChargeQuery($config);
break;
case Config::CMB_REFUND:// 招商退款查询
$this->query = new CmbRefundQuery($config);
break;
default:
throw new PayException('当前仅支持:ALI_CHARGE ALI_REFUND WX_CHARGE WX_REFUND WX_TRANSFER CMB_CHARGE CMB_REFUND');
}
} catch (PayException $e) {
throw $e;
}
}
/**
* 通过环境类调用支付异步通知
*
* @param array $data
* // 二者设置一个即可
* $data => [
* 'transaction_id' => '原付款支付宝交易号',
* 'order_no' => '商户订单号',
* ];
*
* @return array
* @throws PayException
* @author helei
*/
public function query(array $data)
{
if (! $this->query instanceof BaseStrategy) {
throw new PayException('请检查初始化是否正确');
}
try {
return $this->query->handle($data);
} catch (PayException $e) {
throw $e;
}
}
}