<?php
namespace Payment\Query\Ali; use Payment\Common\Ali\AliBaseStrategy; use Payment\Common\Ali\Data\Query\RefundQueryData; use Payment\Common\PayException; use Payment\Config; use Payment\Utils\ArrayUtil; class AliRefundQuery extends AliBaseStrategy { protected $method = 'alipay.trade.fastpay.refund.query'; public function getBuildDataClass() { $this->config->method = $this->method; return RefundQueryData::class; } protected function retData(array $data) { $reqData = parent::retData($data); try { $ret = $this->sendReq($reqData); } catch (PayException $e) { throw $e; } if ($this->config->returnRaw) { $ret['channel'] = Config::ALI_REFUND; return $ret; } return $this->createBackData($ret); } protected function createBackData(array $data) { if ($data['code'] !== '10000') { return $retData = [ 'is_success' => 'F', 'error' => $data['sub_msg'], 'channel' => Config::ALI_REFUND, ]; } if (empty($data['out_trade_no'])) { return [ 'is_success' => 'T', 'msg' => strtolower($data['msg']), 'channel' => Config::ALI_REFUND, ]; } $retData = [ 'is_success' => 'T', 'response' => [ 'transaction_id' => ArrayUtil::get($data, 'trade_no'), 'order_no' => ArrayUtil::get($data, 'out_trade_no'), 'refund_no' => ArrayUtil::get($data, 'out_request_no'), 'reason' => ArrayUtil::get($data, 'refund_reason'), 'amount' => ArrayUtil::get($data, 'total_amount'), 'refund_amount' => ArrayUtil::get($data, 'refund_amount'), 'channel' => Config::ALI_REFUND, ] ]; return $retData; } } 