weizong song 5 years ago
parent aac1a0ba53
commit fef9c47c07

@ -7,6 +7,7 @@ use Alipay\EasySDK\Kernel\Util\ResponseChecker;
use Alipay\EasySDK\Kernel\Config;
use App\Events\RechargeSucceed;
use App\Models\Recharge;
use App\Models\Refund;
use Illuminate\Support\Facades\Log;
class AlipayF2F
@ -51,6 +52,33 @@ class AlipayF2F
}
}
public function refund(Refund $refund) {
try {
$config = $this->getOptions();
$result = Factory::setOptions($config)::payment()
->common()
->refund($refund->serial,$refund->money);
$responseChecker = new ResponseChecker();
//处理响应或异常
if ($responseChecker->success($result)) {
$transaction_id = $result->tradeNo;
$update = [
"paid_at" => date("Y-m-d H:i:s"),
"payment_serial" => $transaction_id
];
$refund->update($update);
} else {
Log::info("支付宝退款失败:".$result->code."".$result->msg);
$refund->increment("try_times");
return false;
}
} catch (\Exception $exception) {
Log::info("支付宝退款失败:".$exception->getCode()."".$exception->getMessage());
$refund->increment("try_times");
return false;
}
}
public function getOptions()
{
$options = new Config();

@ -3,6 +3,7 @@
namespace App\Models;
use App\Customer;
use App\Libs\AlipayF2F;
use App\Manager;
use Illuminate\Support\Facades\Log;
@ -43,8 +44,9 @@ class Refund extends SoftDeletesModel
return $this->belongsTo(Orders::class);
}
public function patient() {
return $this->hasOneThrough(Patient::class, Orders::class,"id","id","order_id","patient_id");
public function patient()
{
return $this->hasOneThrough(Patient::class, Orders::class, "id", "id", "order_id", "patient_id");
}
public function relatedRecharge()
@ -76,12 +78,17 @@ class Refund extends SoftDeletesModel
$refund->weixinRefund();
break;
case "alipay":
//todo:
$refund->alipayRefund();
break;
}
}
}
public function alipayRefund()
{
return (new AlipayF2F())->refund($this);
}
/**
*
* 申请微信退款WxPayRefund中out_trade_no、transaction_id至少填一个且

Loading…
Cancel
Save