新增微信支付
This commit is contained in:
@@ -60,14 +60,68 @@ class VipPaymentIntegrationTest extends TestCase
|
||||
|
||||
$response = $this->actingAs($user)->post(route('vip.payment.store'), [
|
||||
'vip_level_id' => $vipLevel->id,
|
||||
'provider' => 'alipay',
|
||||
]);
|
||||
|
||||
$response->assertRedirect('https://novalink.test/payment/checkout/alipay/PO202604111200001234');
|
||||
Http::assertSent(function ($request) {
|
||||
$data = $request->data();
|
||||
|
||||
return $request->url() === 'https://novalink.test/api/open/v1/pay/orders'
|
||||
&& ($data['provider'] ?? null) === 'alipay';
|
||||
});
|
||||
$this->assertDatabaseHas('vip_payment_orders', [
|
||||
'user_id' => $user->id,
|
||||
'vip_level_id' => $vipLevel->id,
|
||||
'payment_order_no' => 'PO202604111200001234',
|
||||
'status' => 'pending',
|
||||
'provider' => 'alipay',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试用户可以选择微信支付并跳转到平台二维码页面
|
||||
*/
|
||||
public function test_user_can_create_wechat_vip_payment_order_and_redirect_to_wechat_checkout_page(): void
|
||||
{
|
||||
$this->seedVipPaymentConfig();
|
||||
|
||||
$user = User::factory()->create();
|
||||
$vipLevel = VipLevel::factory()->create([
|
||||
'name' => '黄金会员',
|
||||
'price' => 68,
|
||||
'duration_days' => 30,
|
||||
]);
|
||||
|
||||
Http::fake([
|
||||
'https://novalink.test/api/open/v1/pay/orders' => Http::response([
|
||||
'success' => true,
|
||||
'message' => '支付单创建成功',
|
||||
'data' => [
|
||||
'payment_order_no' => 'PO202604131530001234',
|
||||
'pay_url' => 'https://novalink.test/payment/checkout/wechat/PO202604131530001234',
|
||||
],
|
||||
], 201),
|
||||
]);
|
||||
|
||||
$response = $this->actingAs($user)->post(route('vip.payment.store'), [
|
||||
'vip_level_id' => $vipLevel->id,
|
||||
'provider' => 'wechat',
|
||||
]);
|
||||
|
||||
$response->assertRedirect('https://novalink.test/payment/checkout/wechat/PO202604131530001234');
|
||||
Http::assertSent(function ($request) {
|
||||
$data = $request->data();
|
||||
|
||||
return $request->url() === 'https://novalink.test/api/open/v1/pay/orders'
|
||||
&& ($data['provider'] ?? null) === 'wechat';
|
||||
});
|
||||
$this->assertDatabaseHas('vip_payment_orders', [
|
||||
'user_id' => $user->id,
|
||||
'vip_level_id' => $vipLevel->id,
|
||||
'payment_order_no' => 'PO202604131530001234',
|
||||
'status' => 'pending',
|
||||
'provider' => 'wechat',
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -89,6 +143,7 @@ class VipPaymentIntegrationTest extends TestCase
|
||||
'user_id' => $user->id,
|
||||
'vip_level_id' => $vipLevel->id,
|
||||
'amount' => 88.00,
|
||||
'provider' => 'wechat',
|
||||
'vip_name' => $vipLevel->name,
|
||||
'vip_duration_days' => $vipLevel->duration_days,
|
||||
'payment_order_no' => 'PO202604111530001234',
|
||||
@@ -100,8 +155,8 @@ class VipPaymentIntegrationTest extends TestCase
|
||||
'merchant_order_no' => $order->merchant_order_no,
|
||||
'status' => 'paid',
|
||||
'amount' => '88.00',
|
||||
'provider' => 'alipay',
|
||||
'provider_trade_no' => '2026041122001499999999999999',
|
||||
'provider' => 'wechat',
|
||||
'provider_trade_no' => '4200002512202604139876543210',
|
||||
'paid_at' => '2026-04-11 15:35:12',
|
||||
];
|
||||
|
||||
@@ -146,6 +201,7 @@ class VipPaymentIntegrationTest extends TestCase
|
||||
$this->assertDatabaseHas('vip_payment_orders', [
|
||||
'id' => $order->id,
|
||||
'status' => 'paid',
|
||||
'provider' => 'wechat',
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -239,9 +295,14 @@ class VipPaymentIntegrationTest extends TestCase
|
||||
{
|
||||
Sysparam::updateOrCreate(['alias' => 'vip_payment_enabled'], ['body' => '1']);
|
||||
Sysparam::clearCache('vip_payment_enabled');
|
||||
Sysparam::updateOrCreate(['alias' => 'vip_payment_base_url'], ['body' => 'https://novalink.test']);
|
||||
Sysparam::updateOrCreate(['alias' => 'vip_payment_app_key'], ['body' => 'chatroom-app']);
|
||||
Sysparam::updateOrCreate(['alias' => 'vip_payment_app_secret'], ['body' => 'chatroom-secret']);
|
||||
Sysparam::updateOrCreate(['alias' => 'vip_payment_timeout'], ['body' => '10']);
|
||||
|
||||
config(['services.novalink_payment_center.client_id' => 'chatroom-app']);
|
||||
config(['services.novalink_payment_center.client_secret' => 'chatroom-secret']);
|
||||
config(['services.novalink_payment_center.base_url' => 'https://novalink.test/api/open/v1']);
|
||||
Sysparam::clearCache('vip_payment_base_url');
|
||||
Sysparam::clearCache('vip_payment_app_key');
|
||||
Sysparam::clearCache('vip_payment_app_secret');
|
||||
Sysparam::clearCache('vip_payment_timeout');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user