| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292 |
- <?php
- namespace addons\YunfastPay\common\services\trans;
- /**
- * 支付抽象类
- * @package addons\YunfastPay\common\services\trans
- */
- abstract class TransAbstract implements TransInterface
- {
- /**
- * 外部订单号
- *
- * @var string
- */
- protected $outOrderId;
- /**
- * 交易金额(单位元)
- *
- * @var float
- */
- protected $transAmt;
- /**
- * 订单标题
- *
- * @var string
- */
- protected $outOrderTitle;
- /**
- * 订单描述
- *
- * @var string
- */
- protected $outOrderDesc;
- /**
- * 分账对象
- *
- * @var array
- */
- protected $splitBill = [];
- /**
- * 异步通知地址
- *
- * @var string
- */
- protected $notifyUrl;
- /**
- * 是否有异步通知
- *
- * @var boolean
- */
- protected $hasNotify = true;
- /**
- * 当前分账信息
- *
- * @var array
- */
- protected $splitBillItem;
- /**
- * 浏览器,区分消费者支付方式:支付宝:alipay,微信:wxpay
- *
- * @var string
- */
- protected $browser = 'wxpay';
- /**
- * @var array
- */
- protected $config;
- /**
- * 浏览器,区分消费者支付方式:支付宝: alipay, 微信: wxpay
- *
- * @return string
- */
- public function getBrowser()
- {
- return $this->browser;
- }
- /**
- * 浏览器,区分消费者支付方式:支付宝: alipay, 微信: wxpay
- *
- * @param string $browser
- * @return void
- */
- public function setBrowser($browser)
- {
- $this->browser = $browser;
- }
- /**
- * 获取是否拥有异步通知
- *
- * @return boolean
- */
- public function getHasNotify()
- {
- return $this->hasNotify;
- }
- /**
- * 设置分账对象
- *
- * @param array $itemsList
- * @return void
- */
- public function setSplitBill(array $itemsList)
- {
- $this->splitBill = $itemsList;
- }
-
- /**
- * 获取请求参数
- *
- * @return array
- */
- public function getReqData(string $mchtCd)
- {
- $data = $this->getTransData($mchtCd);
-
- // 是否设置回调地址
- if (!empty($this->notifyUrl)) {
- $data = array_merge($data, [
- 'notifyUrl' => $this->notifyUrl
- ]);
- }
- return $data;
- }
- /**
- * 设置每个子分账
- *
- * @param string $item3 分账接收方,接收方商户号。
- * @param float $item10 分账金额,单位(元)
- * @param string $item9 分账描述
- * @param integer $item4 手续费承担方,只能有一方承担,是 0:否,1:是,部分通道不支持,可以先问下业务。
- * @param string $item2 分账角色,服务商:SERVICE_PROVIDER,门店: STORE,员工:STAFF,店主:STORE_OWNER
- * @return void
- */
- public function setSplitBillItem(
- string $item3,
- float $item10,
- string $item9 = '',
- int $item4 = 1,
- string $item2 = 'STORE'
- )
- {
- // 是否子商户,固定1
- $splitBillItem['item1'] = '1';
- /*
- * 分账角色,服务商:SERVICE_PROVIDER,门店: STORE,员工:STAFF,店主:STORE_OWNER
- * 合作伙伴:PARTNER,总部:HEADQUARTER,品牌方:BRAND,分销商:DISTRIBUTOR,用户:USER,供应商:SUPPLIER
- */
- $splitBillItem['item2'] = $item2;
- // 分账接收方,接收方商户号。
- $splitBillItem['item3'] = $item3;
- // 手续费承担方,只能有一方承担,是 0:否,1:是,部分通道不支持,可以先问下业务。
- $splitBillItem['item4'] = $item4;
- // 分账ID类型,固定02,userId:00,loginName:01,商户id:02,个人微信号:03
- $splitBillItem['item5'] = '02';
- // 分账描述
- $splitBillItem['item9'] = $item9;
- // 分账金额,单位(元)
- $splitBillItem['item10'] = $item10;
- // 分账者省代码,可空
- $splitBillItem['item11'] = '';
- // 分账者市代码,可空
- $splitBillItem['item12'] = '';
- // 分账者区代码,可空
- $splitBillItem['item13'] = '';
- $this->splitBillItem = $splitBillItem;
- $this->setSplitBill(array_merge(
- $this->getSplitBill(),
- [$splitBillItem]
- ));
- }
- /**
- * 获取当前子分账内容
- *
- * @return array
- */
- public function getSplitBillItem()
- {
- return $this->splitBillItem;
- }
- /**
- * 获取分账对象
- *
- * @return array
- */
- public function getSplitBill()
- {
- return $this->splitBill;
- }
- /**
- * 订单有效时间
- *
- * @return string
- */
- protected function getExpireTime()
- {
- date_default_timezone_set('PRC');
- return date('YmdHis', strtotime('+ 1hours'));
- }
- /**
- * 是否分账
- *
- * @return int
- */
- protected function getIsSplitBill()
- {
- // 是否分账,0:不分账,1:分账。为空时默认分帐。
- return empty($this->getSplitBill()) ? 0 : 1;
- }
- /**
- * 获取异步通知地址
- *
- * @return string
- */
- public function getNotifyUrl()
- {
- return $this->notifyUrl;
- }
- /**
- * 设置异步通知地址
- *
- * @param string $url
- * @return void
- */
- public function setNotifyUrl(string $url)
- {
- $this->notifyUrl = $url;
- }
- /**
- * @param array $config
- * @return void
- */
- public function setConfig(array $config)
- {
- $this->config = $config;
- }
-
- /**
- * 返回回调处理类型 ['pay', 'agent'] 默认pay 代付agent
- *
- * @return string
- */
- public function getNotifyType()
- {
- return 'pay';
- }
- /**
- * 初始化
- *
- * @param string $outOrderId 外部订单号
- * @param float $transAmt 交易金额, 单位:元
- * @param string $outOrderTitle 订单标题,非必填
- * @param string $outOrderDesc 订单描述,非必填
- */
- public function __construct(
- string $outOrderId,
- float $transAmt,
- string $outOrderTitle,
- string $outOrderDesc = ''
- )
- {
- $this->outOrderId = $outOrderId;
- $this->transAmt = $transAmt;
- $this->outOrderTitle = $outOrderTitle;
- $this->outOrderDesc = $outOrderDesc;
- }
- }
|