sharee.bike-App/Set-MerchantId.ps1
2024-04-09 12:53:23 +02:00

46 lines
1.1 KiB
PowerShell

[cmdletbinding()]
Param($appName, $merchantId)
# Sets a text to a given value.
function Update-Text()
{
param(
[String] $TargetFileName,
[String] $FindText,
[String] $ReplaceText)
if (-not(Test-Path -Path $TargetFileName)) {
Write-Host "File " + $TargetFileName + " not found!"
return -1
}
((Get-Content -path $TargetFileName -Raw) -replace $FindText, $ReplaceText) | Set-Content -Path $TargetFileName -Encoding utf8 -NoNewline
return 0
}
# Sets merchant-id for a single app to a given value.
function Set-MerchantId()
{
param(
[String] $ProjectName,
[String] $MerchantId)
if ($MerchantId.Length -le 2)
{
Write-Host "Merchant id api key must not be of lenght <= 2"
return -1
}
$fileName = Convert-Path ('.\' + $ProjectName + '\ShareeBike\App.xaml.cs')
$retVal = Update-Text $fileName "const string MERCHANTID = `".*`"" "const string MERCHANTID = `"$MerchantId`""
if ($retVal -ne 0)
{
return $retVal
}
Write-Host "File `"$fileName`" updated sucessfully (.."$MerchantId.Substring($MerchantId.Length - 2, 2)")."
return 0
}
return Set-MerchantId $appName $merchantId