public async Task <MChatResponse> UpdateTransaction(MChatRequestUpdateTransaction requestBody) { var response = await httpClient.PostAsync("https://" + domain + "/v1/api/worker/update/transaction", new StringContent(requestBody.json(), Encoding.UTF8, "application/json")); if (response.StatusCode == System.Net.HttpStatusCode.OK) { var responseBody = await response.Content.ReadAsStringAsync(); MChatResponse mChatResponse = JsonConvert.DeserializeObject <MChatResponse>(responseBody); return(mChatResponse); } else { var responseBody = await response.Content.ReadAsStringAsync(); MChatResponse mChatResponse = JsonConvert.DeserializeObject <MChatResponse>(responseBody); return(mChatResponse); } }
public void ConnectToBusinessNotificationService() { this.businessNotificationService.connectionState = (MChatBusinessNotificationService service, BNSProtocolConnectionState state) => { if (state == BNSProtocolConnectionState.Connected) { this.stateChanged?.Invoke(this, BNSState.Connected, mChatResponseGenerateQRCode.generatedQRCode, null); } else if (state == BNSProtocolConnectionState.Disconnected) { this.stateChanged?.Invoke(this, BNSState.Disconnected, mChatResponseGenerateQRCode.generatedQRCode, null); } else if (state == BNSProtocolConnectionState.Timeout) { MChatResponse timeoutRes = new MChatResponse(); timeoutRes.code = 408; timeoutRes.message = "Time Out"; this.stateChanged?.Invoke(this, BNSState.ErrorOccured, mChatResponseGenerateQRCode.generatedQRCode, timeoutRes); } }; this.businessNotificationService.protocolResponse = (BNSProtocolState state, MChatResponse res) => { if (state == BNSProtocolState.Registration && res.code == 200) { this.stateChanged?.Invoke(this, BNSState.Ready, mChatResponseGenerateQRCode.generatedQRCode, res); } else if (state == BNSProtocolState.PaymentNotification && res.code == 200) { this.stateChanged?.Invoke(this, BNSState.PaymentSuccessful, mChatResponseGenerateQRCode.generatedQRCode, res); } else if (res.code != 200) { this.stateChanged?.Invoke(this, BNSState.ErrorOccured, mChatResponseGenerateQRCode.generatedQRCode, res); } }; Thread connectionThread = new Thread(() => { this.businessNotificationService.connect(mChatResponseGenerateQRCode.generatedQRCode); }); connectionThread.Start(); }
private void packet(String data) { XElement xmlData = XElement.Parse(data); switch (xmlData.Name.LocalName) { case "biznot": protocolVersion = xmlData.Attribute("version").Value; connected(); break; case "auth": { var response = xmlData.Elements(); foreach (XElement element in response) { if (element.Name.LocalName == "response") { MChatResponse mChatResponse = new MChatResponse { code = int.Parse(element.Attribute("code").Value), message = element.Value }; protocolResponse?.Invoke(BNSProtocolState.Authentication, mChatResponse); if (mChatResponse.code == 200) { register(); } } } } break; case "register": { var response = xmlData.Elements(); foreach (XElement element in response) { if (element.Name.LocalName == "response") { MChatResponse mChatResponse = new MChatResponse { code = int.Parse(element.Attribute("code").Value), message = element.Value }; protocolResponse?.Invoke(BNSProtocolState.Registration, mChatResponse); } } } break; case "payment": { var response = xmlData.Elements(); foreach (XElement element in response) { if (element.Name.LocalName == "response") { MChatResponse mChatResponse = new MChatResponse { code = int.Parse(element.Attribute("code").Value), message = element.Value }; protocolResponse?.Invoke(BNSProtocolState.PaymentNotification, mChatResponse); Disconnect(); } } } break; default: break; } }