More commerce helpers
This commit is contained in:
parent
354f9df3ec
commit
95e20e387c
1 changed files with 170 additions and 43 deletions
|
|
@ -315,27 +315,154 @@ function Start-IIS(
|
|||
Start-Process -Wait -NoNewWindow -FilePath "${env:ProgramFiles}\IIS Express\iisexpress.exe" -ArgumentList $iis_args
|
||||
}
|
||||
|
||||
function Get-ProductById(
|
||||
[string]$ProductId,
|
||||
[string]$Market='US',
|
||||
[string]$Language='en-US')
|
||||
{
|
||||
$x = Invoke-WebRequest "https://displaycatalog.md.mp.microsoft.com/products/$($ProductId)?fieldsTemplate=Full&market=$($Market)&language=$($Language)" -Headers @{ 'MS-Contract-Version'=5; }
|
||||
return convertfrom-json $x.Content
|
||||
}
|
||||
|
||||
function Get-ProductByContentId(
|
||||
[string]$ContentId,
|
||||
function Find-CatalogProducts(
|
||||
[string]$CatalogQuery,
|
||||
[switch]$Raw,
|
||||
[string]$Market='US',
|
||||
[string]$Language='en-US')
|
||||
{
|
||||
$x = Invoke-WebRequest "https://displaycatalog.md.mp.microsoft.com/skus?rank=ContentId&count=1&alternateId=$($ContentId)&market=$($Market)&language=$($Language)&fieldsTemplate=Full" -Headers @{ 'MS-Contract-Version'=5; }
|
||||
$local:ErrorActionPreference = "Stop"
|
||||
|
||||
$hdr = @{ 'MS-CV'="LxFzVzL+JUG/kPoc.103"; }
|
||||
$x = Invoke-WebRequest "https://displaycatalog.md.mp.microsoft.com/v6/products?rank=ProductSearchApps&query=$CatalogQuery&market=$Market&languages=$Language&fieldsTemplate=Full" -Headers $hdr
|
||||
if ($Raw) {
|
||||
return $x.Content
|
||||
} else {
|
||||
$y = convertfrom-json $x.Content
|
||||
return $y.DisplaySkuSearchResult.Products[0]
|
||||
return $y.DisplayProductSearchResult.Products
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function Get-CatalogProduct(
|
||||
[string]$ProductId = $null,
|
||||
[string]$PackageFamilyName = $null,
|
||||
[string]$ContentId = $null,
|
||||
[string]$LegacyPhoneProductId = $null,
|
||||
[string]$LegacyDesktopProductId = $null,
|
||||
[switch]$Raw,
|
||||
[string]$Market='US',
|
||||
[string]$Language='en-US')
|
||||
{
|
||||
$hdr = @{ 'MS-CV'="LxFzVzL+JUG/kPoc.99"; }
|
||||
$local:ErrorActionPreference = "Stop"
|
||||
|
||||
if ($ProductId) {
|
||||
$url = "https://displaycatalog.md.mp.microsoft.com/v6.0/products/$($ProductId)?fieldsTemplate=Full&market=$($Market)&languages=$($Language)"
|
||||
} elseif ($PackageFamilyName) {
|
||||
$url = "https://displaycatalog.md.mp.microsoft.com/v6.0/products?rank=PackageFamilyName&alternateId=$($PackageFamilyName)&market=$($Market)&languages=$($Language)&fieldsTemplate=Full"
|
||||
} elseif ($LegacyPhoneProductId) {
|
||||
$url = "https://displaycatalog.md.mp.microsoft.com/v6.0/products?rank=LegacyWindowsPhoneProductId&alternateId=$($LegacyPhoneProductId)&market=$($Market)&languages=$($Language)&fieldsTemplate=Full"
|
||||
} elseif ($LegacyDesktopProductId) {
|
||||
$url = "https://displaycatalog.md.mp.microsoft.com/v6.0/skus?rank=WuCategoryId&alternateId=$($LegacyDesktopProductId)&market=$($Market)&languages=$($Language)&fieldsTemplate=Full"
|
||||
} else {
|
||||
$url = "https://displaycatalog.md.mp.microsoft.com/v6.0/skus?rank=ContentId&alternateId=$($ContentId)&market=$($Market)&languages=$($Language)&fieldsTemplate=Full"
|
||||
}
|
||||
|
||||
write-host $url
|
||||
|
||||
$x = Invoke-WebRequest $url -Headers $hdr
|
||||
if ($Raw) {
|
||||
return $x.Content
|
||||
} else {
|
||||
$y = convertfrom-json $x.Content
|
||||
if ($y.Product) {
|
||||
return $y.Product
|
||||
} elseif ($y.DisplayProductSearchResult) {
|
||||
return $y.DisplayProductSearchResult.Products[0]
|
||||
} elseif ($y.DisplaySkuSearchResult) {
|
||||
return $y.DisplaySkuSearchResult.Products[0]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function Get-MSATicket()
|
||||
{
|
||||
$local:ErrorActionPreference = "Stop"
|
||||
|
||||
# ALL OF THIS IS NECESSARY. (By trial and error.)
|
||||
$req = [Windows.Security.Authentication.OnlineId.OnlineIdServiceTicketRequest,Windows.Security.Authentication.OnlineId,ContentType=WindowsRuntime]::new("www.microsoft.com", "mbi_ssl")
|
||||
|
||||
$x = [System.Collections.Generic.List[Windows.Security.Authentication.OnlineId.OnlineIdServiceTicketRequest]]::new()
|
||||
$x.Add($req)
|
||||
|
||||
$authn = new-object "Windows.Security.Authentication.OnlineId.OnlineIdAuthenticator,Windows.Security.Authentication.OnlineId,ContentType=WindowsRuntime"
|
||||
$authn.ApplicationId = "{d6d5a677-0872-4ab0-9442-bb792fce85c5}"
|
||||
$ar = $authn.AuthenticateUserAsync($x, [Windows.Security.Authentication.OnlineId.CredentialPromptType]::DoNotPrompt)
|
||||
while ($ar.Status -ne [Windows.Foundation.AsyncStatus]::Completed) { start-sleep -milliseconds 10 }
|
||||
return $ar.GetResults().Tickets.Value
|
||||
}
|
||||
|
||||
function Get-Entitlements(
|
||||
$ProductTypes=@('Application','Durable','Consumable','UnmanagedConsumable'),
|
||||
$ProductId=$null,
|
||||
$SkuId=$null,
|
||||
$Market='US'
|
||||
)
|
||||
{
|
||||
$local:ErrorActionPreference = "Stop"
|
||||
$ticket = Get-MSATicket
|
||||
|
||||
$req = @{
|
||||
'beneficiaries' = @(
|
||||
@{
|
||||
'identityType' = 'msa';
|
||||
'identityValue' = Get-MSATicket;
|
||||
'localTicketReference' = 'yes';
|
||||
}
|
||||
);
|
||||
'productTypes' = $ProductTypes;
|
||||
'market' = $Market;
|
||||
'validityType' = 'Valid';
|
||||
}
|
||||
|
||||
if ($ProductId) {
|
||||
$psid = @{ 'productId' = $ProductId; }
|
||||
if ($SkuId) {
|
||||
$psid.skuId = $SkuId
|
||||
}
|
||||
$req.productSkuIds = @( $psid )
|
||||
}
|
||||
|
||||
#TODO: Make the pipeline work for you, man
|
||||
|
||||
$its = @()
|
||||
$ct = $null
|
||||
do {
|
||||
if ($ct) {
|
||||
$req.continuationToken = $ct
|
||||
}
|
||||
$rj = ConvertTo-Json $req
|
||||
|
||||
$result = Invoke-WebRequest -Uri "https://collections.md.mp.microsoft.com/v6.0/collections/query" -Body $rj -ContentType "application/json" -Method "POST"
|
||||
|
||||
$resp = ConvertFrom-Json $result.Content
|
||||
$its = $its + $resp.items
|
||||
$ct = $resp.continuationToken
|
||||
} while($ct)
|
||||
|
||||
return $its
|
||||
}
|
||||
|
||||
function Revoke-Order(
|
||||
$OrderId,
|
||||
$Market='US',
|
||||
$Language='en-us'
|
||||
)
|
||||
{
|
||||
$local:ErrorActionPreference = "Stop"
|
||||
$ticket = Get-MSATicket
|
||||
|
||||
$req = @{
|
||||
'clientContext' = @{
|
||||
'client' = 'DotyPowershellExtravaganza'
|
||||
};
|
||||
'orderState' = 'Refunded';
|
||||
}
|
||||
|
||||
$headers = @{ "Authorization"="WLID1.0=$ticket"; }
|
||||
$body = ConvertTo-Json $req
|
||||
$result = Invoke-WebRequest -Uri "https://purchase.md.mp.microsoft.com/v6.0/users/me/orders/$OrderId" -Body $body -ContentType "application/json" -Method "PUT" -Headers $headers
|
||||
return ConvertFrom-Json $result.Content
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue