# PayPal支付测试脚本 # 使用方法: .\test-paypal-payment.ps1 Write-Host "========================================" -ForegroundColor Cyan Write-Host "PayPal支付功能测试" -ForegroundColor Cyan Write-Host "========================================" -ForegroundColor Cyan Write-Host "" # 检查应用是否运行 Write-Host "[1/4] 检查应用状态..." -ForegroundColor Yellow try { $response = Invoke-WebRequest -Uri "http://localhost:8080/actuator/health" -TimeoutSec 3 -ErrorAction SilentlyContinue Write-Host "✓ 应用正在运行" -ForegroundColor Green } catch { Write-Host "✗ 应用未启动,请先运行: mvn spring-boot:run" -ForegroundColor Red exit 1 } Write-Host "" Write-Host "[2/4] 创建PayPal支付..." -ForegroundColor Yellow # 生成随机订单号 $orderId = "TEST" + (Get-Date -Format "yyyyMMddHHmmss") $body = @{ username = "testuser" orderId = $orderId amount = "10.00" method = "PAYPAL" } | ConvertTo-Json try { $result = Invoke-RestMethod -Uri "http://localhost:8080/api/payment/paypal/create" ` -Method Post ` -ContentType "application/json" ` -Body $body Write-Host "✓ 支付创建成功!" -ForegroundColor Green Write-Host "" Write-Host "支付信息:" -ForegroundColor Cyan Write-Host " Payment ID: $($result.paymentId)" -ForegroundColor White Write-Host " 订单号: $orderId" -ForegroundColor White Write-Host " 金额: $10.00 USD" -ForegroundColor White Write-Host " PayPal Payment ID: $($result.externalTransactionId)" -ForegroundColor White Write-Host "" Write-Host "[3/4] 支付URL已生成" -ForegroundColor Yellow Write-Host " $($result.paymentUrl)" -ForegroundColor Cyan Write-Host "" Write-Host "[4/4] 下一步操作:" -ForegroundColor Yellow Write-Host " 1. 在浏览器中打开上面的URL" -ForegroundColor White Write-Host " 2. 使用PayPal Sandbox测试账号登录" -ForegroundColor White Write-Host " 3. 点击 'Pay Now' 完成支付" -ForegroundColor White Write-Host " 4. 支付完成后会自动跳转回应用" -ForegroundColor White Write-Host "" # 询问是否自动打开浏览器 $open = Read-Host "是否在浏览器中打开支付URL? (Y/N)" if ($open -eq "Y" -or $open -eq "y") { Start-Process $result.paymentUrl Write-Host "✓ 已在浏览器中打开支付页面" -ForegroundColor Green } Write-Host "" Write-Host "========================================" -ForegroundColor Cyan Write-Host "提示:" -ForegroundColor Yellow Write-Host "- 如果还没有创建Sandbox测试账号,请访问:" -ForegroundColor White Write-Host " https://developer.paypal.com/dashboard/accounts" -ForegroundColor Cyan Write-Host "- 创建 Personal 账号作为买家" -ForegroundColor White Write-Host "- 使用该账号登录并完成支付测试" -ForegroundColor White Write-Host "========================================" -ForegroundColor Cyan } catch { Write-Host "✗ 创建支付失败" -ForegroundColor Red Write-Host "错误信息: $($_.Exception.Message)" -ForegroundColor Red Write-Host "" Write-Host "可能的原因:" -ForegroundColor Yellow Write-Host "1. PayPal配置未正确加载" -ForegroundColor White Write-Host "2. PayPal Client ID或Secret不正确" -ForegroundColor White Write-Host "3. 网络连接问题" -ForegroundColor White Write-Host "" Write-Host "请检查应用日志获取详细错误信息" -ForegroundColor Yellow }