|
|
@@ -1,5 +1,6 @@
|
|
|
<?php
|
|
|
declare(strict_types=1);
|
|
|
+
|
|
|
namespace SixShop\Lakala\Service;
|
|
|
|
|
|
use SixShop\Lakala\Log;
|
|
|
@@ -28,6 +29,7 @@ class TransactionService
|
|
|
private QueryTradequeryApi $queryTradequeryApi;
|
|
|
|
|
|
private LakalaApi $lakalaApi;
|
|
|
+
|
|
|
public function __construct(private Config $config, private Log $log)
|
|
|
{
|
|
|
$this->transPreorderApi = new TransPreorderApi($config->getV3Config());
|
|
|
@@ -52,18 +54,18 @@ class TransactionService
|
|
|
* @link https://o.lakala.com/#/home/document/detail?id=110
|
|
|
*/
|
|
|
public function preOrder(
|
|
|
- string $outTradeNo,
|
|
|
- float $totalAmount,
|
|
|
- LocationInfo $locationInfo,
|
|
|
- string $accountType = 'WECHAT',
|
|
|
- string $transType = '71',
|
|
|
- string $busiMode = 'ACQ',
|
|
|
- string $subject = '',
|
|
|
- string $payOrderNo = '',
|
|
|
- string $settleType = '',
|
|
|
- string $remark = '',
|
|
|
+ string $outTradeNo,
|
|
|
+ float $totalAmount,
|
|
|
+ LocationInfo $locationInfo,
|
|
|
+ string $accountType = 'WECHAT',
|
|
|
+ string $transType = '71',
|
|
|
+ string $busiMode = 'ACQ',
|
|
|
+ string $subject = '',
|
|
|
+ string $payOrderNo = '',
|
|
|
+ string $settleType = '',
|
|
|
+ string $remark = '',
|
|
|
TradeAccBusiFields $accBusiFields = null,
|
|
|
- ):object
|
|
|
+ ): object
|
|
|
{
|
|
|
$request = new TransPreorderRequest();
|
|
|
|
|
|
@@ -85,14 +87,14 @@ class TransactionService
|
|
|
$request->setRemark($remark);
|
|
|
$request->setAccBusiFields($accBusiFields);
|
|
|
$request->setCompleteNotifyUrl($this->config->complete_notify_url);
|
|
|
- $this->log->debug('preOrder request:'.json_encode($request));
|
|
|
+ $this->log->debug('preOrder request:' . json_encode($request));
|
|
|
$response = $this->transPreorderApi->transPreorder($request);
|
|
|
- $this->log->debug('preOrder response:'.json_encode($response->getRespData()));
|
|
|
+ $this->log->debug('preOrder response:' . json_encode($response->getRespData()));
|
|
|
if ($response->getCode() == 'BBS00000') {
|
|
|
return $response->getRespData();
|
|
|
} else {
|
|
|
throw_logic_exception(
|
|
|
- msg:$response->getMsg(),
|
|
|
+ msg: $response->getMsg(),
|
|
|
status: $response->getCode(),
|
|
|
data: $response->getRespData(),
|
|
|
);
|
|
|
@@ -106,12 +108,28 @@ class TransactionService
|
|
|
*
|
|
|
* @param string $tradeNo 拉卡拉订单系统订单号
|
|
|
* @param string $outTradeNo 商户订单号
|
|
|
+ * @param string $merchantNo 商户编号
|
|
|
+ * @param string $termNo 终端编号
|
|
|
+ *
|
|
|
+ * @link https://o.lakala.com/#/home/document/detail?id=116
|
|
|
*/
|
|
|
- public function queryTrade(string $tradeNo = '', string $outTradeNo = ''):object
|
|
|
+ public function queryTrade(string $tradeNo = '', string $outTradeNo = '', string $merchantNo = '', string $termNo = ''): object
|
|
|
{
|
|
|
$request = new QueryTradequeryRequest();
|
|
|
- $request->setMerchantNo($this->config->merchant_no);
|
|
|
- $request->setTermNo($this->config->term_no);
|
|
|
+ if ($merchantNo === '') {
|
|
|
+ $merchantNo = $this->config->merchant_no;
|
|
|
+ $termNo = $this->config->term_no;
|
|
|
+ }
|
|
|
+ $request->setMerchantNo($merchantNo);
|
|
|
+ if ($merchantNo && $termNo === '') {
|
|
|
+ foreach ($this->config->sub_merchant_list as $subMerchant) {
|
|
|
+ if ($subMerchant['merchant_no'] == $merchantNo) {
|
|
|
+ $termNo = $subMerchant['term_no'];
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $request->setTermNo($termNo ?: $this->config->term_no);
|
|
|
$request->setTradeNo($tradeNo);
|
|
|
$request->setOutTradeNo($outTradeNo);
|
|
|
$response = $this->queryTradequeryApi->queryTradequery($request);
|
|
|
@@ -120,7 +138,7 @@ class TransactionService
|
|
|
return $response->getRespData();
|
|
|
} else {
|
|
|
throw_logic_exception(
|
|
|
- msg:$response->getMsg(),
|
|
|
+ msg: $response->getMsg(),
|
|
|
status: $response->getCode(),
|
|
|
data: $response->getRespData(),
|
|
|
);
|
|
|
@@ -139,12 +157,12 @@ class TransactionService
|
|
|
* @link https://o.lakala.com/#/home/document/detail?id=892
|
|
|
*/
|
|
|
public function refund(
|
|
|
- string $refundTradeNo,
|
|
|
- float $refundAmount,
|
|
|
+ string $refundTradeNo,
|
|
|
+ float $refundAmount,
|
|
|
LocationInfo $locationInfo,
|
|
|
- string $originTradeNo = '',
|
|
|
- string $originOutTradeNo = '',
|
|
|
- string $refundReason = '',
|
|
|
+ string $originTradeNo = '',
|
|
|
+ string $originOutTradeNo = '',
|
|
|
+ string $refundReason = '',
|
|
|
)
|
|
|
{
|
|
|
$request = new ModelRequest();
|
|
|
@@ -152,7 +170,7 @@ class TransactionService
|
|
|
'merchant_no' => $this->config->merchant_no,
|
|
|
'term_no' => $this->config->term_no,
|
|
|
'out_trade_no' => $refundTradeNo,
|
|
|
- 'refund_amount' => round($refundAmount*100),
|
|
|
+ 'refund_amount' => round($refundAmount * 100),
|
|
|
'refund_reason' => $refundReason,
|
|
|
'origin_out_trade_no' => $originOutTradeNo,
|
|
|
'origin_trade_no' => $originTradeNo,
|
|
|
@@ -166,7 +184,7 @@ class TransactionService
|
|
|
return $response->getRespData();
|
|
|
} else {
|
|
|
throw_logic_exception(
|
|
|
- msg:$response->getMsg(),
|
|
|
+ msg: $response->getMsg(),
|
|
|
status: $response->getCode(),
|
|
|
data: $response->getRespData(),
|
|
|
);
|