测试
This commit is contained in:
parent
dc963e943f
commit
ff3f51c90d
@ -19,6 +19,7 @@
|
||||
use App\Http\Controllers\Controller;
|
||||
use Yansongda\LaravelPay\Facades\Pay;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Yansongda\Pay\Exception\InvalidResponseException;
|
||||
|
||||
class BalanceController extends Controller
|
||||
{
|
||||
@ -56,7 +57,7 @@ public function store(Request $request)
|
||||
|
||||
|
||||
return $pay;
|
||||
|
||||
|
||||
|
||||
// if local
|
||||
// if (env('APP_ENV') == 'local') {
|
||||
@ -120,11 +121,20 @@ public function return(Request $request)
|
||||
'out_trade_no' => 'required',
|
||||
]);
|
||||
|
||||
$alipay = Pay::alipay();
|
||||
|
||||
$data = $alipay->callback();
|
||||
|
||||
Log::debug($data);
|
||||
|
||||
dd($data);
|
||||
|
||||
return;
|
||||
// 检测订单是否存在
|
||||
$balance = Balance::where('order_id', $request->out_trade_no)->with('user')->first();
|
||||
if (!$balance) {
|
||||
return $this->notFound('balance not found');
|
||||
}
|
||||
// $balance = Balance::where('order_id', $request->out_trade_no)->with('user')->first();
|
||||
// if (!$balance) {
|
||||
// return $this->notFound('balance not found');
|
||||
// }
|
||||
|
||||
// 检测订单是否已支付
|
||||
if ($balance->paid_at !== null) {
|
||||
@ -162,29 +172,45 @@ public function notify(Request $request)
|
||||
}
|
||||
}
|
||||
|
||||
public function checkAndCharge(Balance $balance)
|
||||
public function checkAndCharge(Balance $balance, $check = false)
|
||||
{
|
||||
// AlipayFactory::setOptions($this->alipayOptions());
|
||||
|
||||
// $trade = AlipayFactory::payment()->common()->query($balance->order_id);
|
||||
if ($check) {
|
||||
$alipay = Pay::alipay()->find(['out_trade_no' => $balance->order_id,]);
|
||||
|
||||
// if ($trade->code == "10000" && $trade->tradeStatus == "TRADE_SUCCESS") {
|
||||
// $balance->paid_at = now();
|
||||
// $balance->save();
|
||||
if ($alipay->trade_status !== 'TRADE_SUCCESS') {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// $transaction = new Transaction();
|
||||
try {
|
||||
|
||||
// try {
|
||||
// $transaction->addAmount($balance->user_id, 'alipay', $trade->totalAmount);
|
||||
// } catch (ChargeException $e) {
|
||||
// AlipayFactory::payment()->common()->refund($balance->order_id, $trade->totalAmount);
|
||||
// return $this->error($e->getMessage());
|
||||
// }
|
||||
// 请自行对 trade_status 进行判断及其它逻辑进行判断,在支付宝的业务通知中,只有交易通知状态为 TRADE_SUCCESS 或 TRADE_FINISHED 时,支付宝才会认定为买家付款成功。
|
||||
// 1、商户需要验证该通知数据中的out_trade_no是否为商户系统中创建的订单号;
|
||||
// 2、判断total_amount是否确实为该订单的实际金额(即商户订单创建时的金额);
|
||||
// 3、校验通知中的seller_id(或者seller_email) 是否为out_trade_no这笔单据的对应的操作方(有的时候,一个商户可能有多个seller_id/seller_email);
|
||||
// 4、验证app_id是否为该商户本身。
|
||||
// 5、其它业务逻辑情况
|
||||
|
||||
// return true;
|
||||
// } else {
|
||||
// return false;
|
||||
// }
|
||||
// 验证 商户
|
||||
// if ($data['app_id'] != config('pay.alipay.app_id')) {
|
||||
// throw new ChargeException('商户不匹配');
|
||||
// }
|
||||
|
||||
// if ((int) $data->total_amount != (int) $balance->amount) {
|
||||
// throw new ChargeException('金额不一致');
|
||||
// }
|
||||
|
||||
$balance->update([
|
||||
'paid_at' => now()
|
||||
]);
|
||||
|
||||
(new Transaction)->addAmount($balance->user_id, 'alipay', $data->totalAmount);
|
||||
} catch (InvalidResponseException) {
|
||||
return $this->error('无法验证支付结果');
|
||||
}
|
||||
|
||||
return $alipay->success();
|
||||
}
|
||||
|
||||
// // 转换为 drops
|
||||
|
@ -16,6 +16,7 @@
|
||||
*/
|
||||
|
||||
'name' => env('APP_NAME', 'LAECLOUD'),
|
||||
'display_name' => env('APP_DISPLAY_NAME', env('APP_NAME', 'LAECLOUD')),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
@ -22,13 +22,14 @@
|
||||
// 选填-服务商模式下的服务商 id,当 mode 为 Pay::MODE_SERVICE 时使用该参数
|
||||
'service_provider_id' => '',
|
||||
// 选填-默认为正常模式。可选为: MODE_NORMAL, MODE_SANDBOX, MODE_SERVICE
|
||||
'mode' => Pay::MODE_NORMAL,
|
||||
// 如果应用程序环境为 local,自动切换为沙箱模式
|
||||
'mode' => env('APP_ENV') == 'local' ? Pay::MODE_SANDBOX : Pay::MODE_NORMAL,
|
||||
],
|
||||
],
|
||||
'wechat' => [
|
||||
'default' => [
|
||||
// 必填-商户号,服务商模式下为服务商商户号
|
||||
'mch_id' => '',
|
||||
'mch_id' => env('WECHAT_MENCENT_ID'),
|
||||
// 必填-商户秘钥
|
||||
'mch_secret_key' => '',
|
||||
// 必填-商户私钥 字符串或路径
|
||||
|
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('balances', function (Blueprint $table) {
|
||||
//
|
||||
$table->decimal('remaining_amount', 10, 2)->default(0)->after('amount');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('balances', function (Blueprint $table) {
|
||||
//
|
||||
});
|
||||
}
|
||||
};
|
33
database/migrations/2022_11_06_205958_drop_drops_table.php
Normal file
33
database/migrations/2022_11_06_205958_drop_drops_table.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
//
|
||||
|
||||
// Drop table
|
||||
Schema::dropIfExists('drops');
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
|
||||
// 不可逆
|
||||
}
|
||||
};
|
@ -29,5 +29,25 @@
|
||||
|
||||
|
||||
Route::get('/pay', function () {
|
||||
$pay = Pay::alipay()->web([
|
||||
'out_trade_no' => 'lae-' . time(),
|
||||
'total_amount' => 10,
|
||||
'subject' => config('app.display_name') . ' 充值',
|
||||
]);
|
||||
|
||||
return $pay;
|
||||
});
|
||||
|
||||
Route::get('/t', function () {
|
||||
return Pay::alipay()->transfer([
|
||||
'out_biz_no' => '202106051432',
|
||||
'trans_amount' => '0.01',
|
||||
'product_code' => 'TRANS_ACCOUNT_NO_PWD',
|
||||
'biz_scene' => 'DIRECT_TRANSFER',
|
||||
'payee_info' => [
|
||||
'identity' => '2088622956327844',
|
||||
'identity_type' => 'ALIPAY_USER_ID',
|
||||
'name' => 'vsjnhi5180'
|
||||
],
|
||||
]);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user