param(
|
[string] $BaseUrl = 'http://127.0.0.1:8080',
|
[long] $TalentId = 5,
|
[long] $CardId = 5,
|
[long] $MerchantId = 2,
|
[decimal] $Amount = 0.01
|
)
|
|
$baseUrl = $BaseUrl.TrimEnd('/')
|
if ($Amount -le 0) {
|
throw 'Amount must be greater than zero.'
|
}
|
|
$payload = @{
|
talentId = $TalentId
|
cardId = $CardId
|
benefitId = $null
|
merchantId = $MerchantId
|
storeId = $null
|
orderType = 'GROUP_BUY'
|
orderAmount = $Amount
|
subsidyAmount = 0
|
payAmount = $Amount
|
} | ConvertTo-Json -Compress
|
|
$created = Invoke-RestMethod -Uri "$baseUrl/api/orders" -Method POST -ContentType 'application/json' -Body $payload
|
if ($created.code -ne 0 -or [string]::IsNullOrWhiteSpace($created.data.orderNo)) {
|
throw "Order creation failed: $($created | ConvertTo-Json -Compress)"
|
}
|
|
$orderNo = [string] $created.data.orderNo
|
$detail = Invoke-RestMethod -Uri "$baseUrl/api/app/pending-orders/${orderNo}?talentId=$TalentId" -Method GET
|
if ($detail.code -ne 0 -or $detail.data.canPay -ne $true) {
|
throw "Created order is not payable: $($detail | ConvertTo-Json -Compress)"
|
}
|
|
Write-Output "Created pending payment order: $orderNo"
|
Write-Output "Talent ID: $TalentId"
|
Write-Output "Amount: $($detail.data.payAmount) CNY"
|
Write-Output "Expires at: $($detail.data.expiresAt)"
|