支付宝退款
parent
1b8de36a8d
commit
c002f70ed9
|
|
@ -6,6 +6,7 @@ use App\Exceptions\BizException;
|
||||||
use App\Models\BalanceLog;
|
use App\Models\BalanceLog;
|
||||||
use App\Models\OrderRefundLog;
|
use App\Models\OrderRefundLog;
|
||||||
use App\Models\WalletLog;
|
use App\Models\WalletLog;
|
||||||
|
use App\Services\AlipayService;
|
||||||
use App\Services\BalanceService;
|
use App\Services\BalanceService;
|
||||||
use App\Services\WalletService;
|
use App\Services\WalletService;
|
||||||
use App\Services\WeChatPayService;
|
use App\Services\WeChatPayService;
|
||||||
|
|
@ -87,6 +88,29 @@ class OrderRefundCommand extends Command
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付宝退款
|
||||||
|
*
|
||||||
|
* @param \App\Models\OrderRefundLog $log
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function refundByAlipay(OrderRefundLog $log)
|
||||||
|
{
|
||||||
|
$order = $log->order;
|
||||||
|
|
||||||
|
(new AlipayService())->refund(
|
||||||
|
$order->pay_sn,
|
||||||
|
$log->sn,
|
||||||
|
bcdiv($log->amount, 100, 2),
|
||||||
|
$log->reason,
|
||||||
|
);
|
||||||
|
|
||||||
|
$log->update([
|
||||||
|
'status' => OrderRefundLog::STATUS_SUCCESS,
|
||||||
|
'failed_reason' => null,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 可提支付退款
|
* 可提支付退款
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,10 @@ namespace App\Services;
|
||||||
use Alipay\EasySDK\Kernel\CertEnvironment;
|
use Alipay\EasySDK\Kernel\CertEnvironment;
|
||||||
use Alipay\EasySDK\Kernel\Config;
|
use Alipay\EasySDK\Kernel\Config;
|
||||||
use Alipay\EasySDK\Kernel\EasySDKKernel;
|
use Alipay\EasySDK\Kernel\EasySDKKernel;
|
||||||
|
use Alipay\EasySDK\Kernel\Util\ResponseChecker;
|
||||||
use Alipay\EasySDK\Payment\App\Client as AppClient;
|
use Alipay\EasySDK\Payment\App\Client as AppClient;
|
||||||
use Alipay\EasySDK\Payment\Common\Client as CommonClient;
|
use Alipay\EasySDK\Payment\Common\Client as CommonClient;
|
||||||
|
use App\Exceptions\BizException;
|
||||||
|
|
||||||
class AlipayService
|
class AlipayService
|
||||||
{
|
{
|
||||||
|
|
@ -20,17 +22,44 @@ class AlipayService
|
||||||
{
|
{
|
||||||
$kernel = $this->getKernel();
|
$kernel = $this->getKernel();
|
||||||
|
|
||||||
$result = (new AppClient($kernel))->pay(
|
$response = (new AppClient($kernel))->pay(
|
||||||
$params['subject'],
|
$params['subject'],
|
||||||
$params['out_trade_no'],
|
$params['out_trade_no'],
|
||||||
$params['total_amount'],
|
$params['total_amount'],
|
||||||
);
|
);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'body' => $result->body,
|
'body' => $response->body,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 退款
|
||||||
|
*
|
||||||
|
* @param string $outTradeNo
|
||||||
|
* @param string $refundSerialNumber
|
||||||
|
* @param float $refundAmount
|
||||||
|
* @param string $refundReason
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function refund(
|
||||||
|
string $outTradeNo,
|
||||||
|
string $refundSerialNumber,
|
||||||
|
$refundAmount,
|
||||||
|
?string $refundReason = null
|
||||||
|
) {
|
||||||
|
$kernel = $this->getKernel();
|
||||||
|
|
||||||
|
$response = (new CommonClient($kernel))
|
||||||
|
->optional('out_request_no', $refundSerialNumber)
|
||||||
|
->optional('refund_reason', $refundReason)
|
||||||
|
->refund($outTradeNo, $refundAmount);
|
||||||
|
|
||||||
|
if (! (new ResponseChecker())->success($response)) {
|
||||||
|
throw new BizException($response->msg.','.$response->subMsg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证回调通知
|
* 验证回调通知
|
||||||
*
|
*
|
||||||
|
|
@ -72,7 +101,7 @@ class AlipayService
|
||||||
$cfg->merchantCertPath = $configs['app_public_cert_path'];
|
$cfg->merchantCertPath = $configs['app_public_cert_path'];
|
||||||
$cfg->alipayCertPath = $configs['public_cert_path'];
|
$cfg->alipayCertPath = $configs['public_cert_path'];
|
||||||
$cfg->alipayRootCertPath = $configs['root_cert_path'];
|
$cfg->alipayRootCertPath = $configs['root_cert_path'];
|
||||||
$cfg->notifyUrl = $configs['notify_url'] ?? url(route('alipay.notify', [], false), [], true);
|
$cfg->notifyUrl = 'https://zichunsheng.cn/callback/alipay' ?? url(route('alipay.notify', [], false), [], true);
|
||||||
|
|
||||||
$certEnvironment = new CertEnvironment();
|
$certEnvironment = new CertEnvironment();
|
||||||
$certEnvironment->certEnvironment(
|
$certEnvironment->certEnvironment(
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,9 @@ class PayService
|
||||||
} elseif ($payLog->isBalance()) {
|
} elseif ($payLog->isBalance()) {
|
||||||
// 余额支付
|
// 余额支付
|
||||||
$payWay = Order::PAY_WAY_BALANCE;
|
$payWay = Order::PAY_WAY_BALANCE;
|
||||||
|
} elseif ($payLog->isAlipay()) {
|
||||||
|
// 支付宝
|
||||||
|
$payWay = Order::PAY_WAY_ALIPAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
$payable->update([
|
$payable->update([
|
||||||
|
|
@ -84,7 +87,6 @@ class PayService
|
||||||
'pay_at' => $payLog->pay_at,
|
'pay_at' => $payLog->pay_at,
|
||||||
'out_trade_no' => $payLog->out_trade_no,
|
'out_trade_no' => $payLog->out_trade_no,
|
||||||
'status' => Order::STATUS_PAID,
|
'status' => Order::STATUS_PAID,
|
||||||
'auto_complete_at' => now()->addDays(app_settings('app.order_auto_complete_days', 7)),
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// 增加用户的预成长值
|
// 增加用户的预成长值
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue