I have translated the code from an console project and seem to get a deadlock since the code doesnt send a request to the server, their logs show nothing. Nothing happens when i debug, its just waiting for something.
How do i alter this for web.forms or any other web based handler?
Public Function MakePaymentRequest(ByVal swishNumberToPay As String, ByVal amount As Decimal, ByVal message As String, ByVal instructionUUID As String) As PaymentRequestECommerceResponse
Try
Dim requestData = New PaymentRequestECommerceData() With {
.payeePaymentReference = _payeePaymentReference,
.callbackUrl = _callbackUrl,
.payerAlias = swishNumberToPay,
.payeeAlias = _merchantAlias,
.amount = Math.Round(amount, 2).ToString().Replace(",", "."),
.currency = "SEK",
.message = message
}
Dim handler As New HttpClientHandler
Dim client As New HttpClient
PrepareHttpClientAndHandler(handler, client)
Dim requestURL As String = URL.ProductionPaymentRequest & instructionUUID
Dim mhttpMethod = HttpMethod.Put
Select Case _environment
Case "EMULATOR"
requestURL = URL.EmulatorPaymentRequest & instructionUUID
Case "SANDBOX"
requestURL = URL.SandboxPaymentRequest
mhttpMethod = HttpMethod.Post
End Select
Dim httpRequestMessage = New HttpRequestMessage With {
.Method = mhttpMethod,
.RequestUri = New Uri(requestURL),
.Content = New StringContent(JsonConvert.SerializeObject(requestData), Encoding.UTF8, "application/json")
}
httpRequestMessage.Headers.Add("host", httpRequestMessage.RequestUri.Host)
Dim response = client.SendAsync(httpRequestMessage).Result <-- I cant get past here. Nothing happens at this step and i think its deadlocked.
Dim errorMessage As String = String.Empty
Dim location As String = String.Empty
If response.IsSuccessStatusCode Then
Dim headers = response.Headers.ToList()
If headers.Any(Function(x) x.Key = "Location") Then
location = response.Headers.GetValues("Location").FirstOrDefault()
End If
Else
Dim readAsStringAsync = response.Content.ReadAsStringAsync()
errorMessage = readAsStringAsync.Result
End If
client.Dispose()
handler.Dispose()
Return New PaymentRequestECommerceResponse() With {
.[Error] = errorMessage,
.Location = location
}
Catch ex As Exception
Return New PaymentRequestECommerceResponse() With {
.[Error] = ex.ToString(),
.Location = ""
}
End Try
End Function