public static StartTransactionResponse OnStartTransaction(StartTransactionParameters parameters)
        {
            // If navigate to google.com, then print User-Agent header value.
            if (parameters.UrlRequest.Url == "https://www.google.com/")
            {
                IEnumerable <IHttpHeader> headers = parameters.Headers;
                Console.WriteLine("User-Agent: "
                                  + headers.FirstOrDefault(h => h.Name.Equals("User-Agent"))?.Values.FirstOrDefault());
            }

            return(StartTransactionResponse.Continue());
        }
示例#2
0
        public void Parse_FailedValidation_TransactionStart()
        {
            // Arrange
            const string input = "DW_XE_0003 Validation failed, details: {\"outletID\":[\"This outlet does not exist.\"],\"amount\":[\"This outlet does not exist.\",\"Outlet missing, cannot validate.\",\"Pricing agreement not found, cannot validate.\"]}";

            // Act
            StartTransactionResponse model = new StartTransactionResponse(input);

            // Assert
            Assert.AreEqual(StartTransactionResponseCodes.ValidationFailed, model.Status, "Didn't find ValidationFailed statuscode");
            Assert.AreEqual("DW_XE_0003", model.StatusCode, "Didn't correctly map API statuscode to string");
            Assert.IsNull(model.OutboundUrl, "Outbound URL should not be set in failure case.");
        }
示例#3
0
        public void Parse_Succesful_TransactionStart()
        {
            // Arrange
            const string input = "000000 183521787|https://pay.digiwallet.nl/test-transaction?transactionID=183521787&paymethod=IDE&hash=c74ed1eef8ddae675ad2d27d554e6bee491f7ddb2b349f48296983e7c484cd7b";

            // Act
            StartTransactionResponse model = new StartTransactionResponse(input);

            // Assert
            Assert.AreEqual(StartTransactionResponseCodes.Started, model.Status, "Didn't find Started statuscode");
            Assert.AreEqual(183521787, model.TransactionNr, "Didn't parse transactionnr correctly");
            Assert.AreEqual("https://pay.digiwallet.nl/test-transaction?transactionID=183521787&paymethod=IDE&hash=c74ed1eef8ddae675ad2d27d554e6bee491f7ddb2b349f48296983e7c484cd7b", model.OutboundUrl, "Didn't set outbound URL");
            Assert.AreEqual("000000", model.StatusCode, "Didn't correctly map API statuscode to string");
            Assert.IsNull(model.ResponseBody, "Responsebody should not be set in success case.");
        }
示例#4
0
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            StartTransactionResponse response = new StartTransactionResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("TransactionId", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.TransactionId = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
示例#5
0
        public async Task StartTransactionAsync()
        {
            // Arrange
            var clientHandlerStub = new DelegatingHandlerStub();
            var client            = new HttpClient(clientHandlerStub)
            {
                BaseAddress = new System.Uri("https://transaction.digiwallet.nl/")
            };
            var mockFactory = new Mock <IHttpClientFactory>();

            // Always return our mock client
            mockFactory.Setup(_ => _.CreateClient(It.IsAny <string>())).Returns(client);

            IHttpClientFactory mockHttpFactory = mockFactory.Object;

            IDealTransactionService iDealTransactionservice = new IDealTransactionService(mockHttpFactory, Mock.Of <ILogger <IDealTransactionService> >());
            IDealTransaction        transaction             = new IDealTransaction()
            {
                ShopID      = 149631,
                Amount      = 2000,
                Bank        = "ABNAL2A",
                Description = "Testing 1. 2.",
                CancelUrl   = "http://development.woonz.nl/DigiWallet/cancel",
                ReturnUrl   = "http://development.woonz.nl/DigiWallet/return",
                ReportUrl   = "http://development.woonz.nl/DigiWallet/report"
            };

            // Act
            StartTransactionResponse startModel = await iDealTransactionservice.StartTransaction(transaction);

            // Assert
            Assert.AreEqual(startModel.TransactionNr, 103084, "Didn't parse transaction ID correctly");
            Assert.AreEqual(startModel.StatusCode, "000000", "Didn't parse statuscode correctly");
            Assert.AreEqual(startModel.Status, StartTransactionResponseCodes.Started, "Didn't interpret success status correctly");
            Assert.AreEqual(startModel.OutboundUrl, "https://pay.digiwallet.nl/consumer/ideal/launch/103084/da85a5e0-b29e-11e8-9332-ecf4cbbfde30/0", "Didn't read outbound URL correctly");
            Assert.IsNull(startModel.ResponseBody, "Set responsebody when it shouldn't have been set");
        }
示例#6
0
        public string HandleStartTransaction(OCPPMessage msgIn, OCPPMessage msgOut)
        {
            string errorCode = null;
            StartTransactionResponse startTransactionResponse = new StartTransactionResponse();

            int?connectorId = null;

            try
            {
                Logger.LogTrace("Processing startTransaction request...");
                StartTransactionRequest startTransactionRequest = JsonConvert.DeserializeObject <StartTransactionRequest>(msgIn.JsonPayload);
                Logger.LogTrace("StartTransaction => Message deserialized");

                string idTag = Utils.CleanChargeTagId(startTransactionRequest.IdTag, Logger);
                connectorId = startTransactionRequest.ConnectorId;

                startTransactionResponse.IdTagInfo.ParentIdTag = string.Empty;
                startTransactionResponse.IdTagInfo.ExpiryDate  = Utils.MaxExpiryDate;

                if (string.IsNullOrWhiteSpace(idTag))
                {
                    // no RFID-Tag => accept request
                    startTransactionResponse.IdTagInfo.Status = IdTagInfoStatus.Accepted;
                    Logger.LogInformation("StartTransaction => no charge tag => Status: {0}", startTransactionResponse.IdTagInfo.Status);
                }
                else
                {
                    try
                    {
                        using (OCPPCoreContext dbContext = new OCPPCoreContext(Configuration))
                        {
                            ChargeTag ct = dbContext.Find <ChargeTag>(idTag);
                            if (ct != null)
                            {
                                if (ct.ExpiryDate.HasValue)
                                {
                                    startTransactionResponse.IdTagInfo.ExpiryDate = ct.ExpiryDate.Value;
                                }
                                startTransactionResponse.IdTagInfo.ParentIdTag = ct.ParentTagId;
                                if (ct.Blocked.HasValue && ct.Blocked.Value)
                                {
                                    startTransactionResponse.IdTagInfo.Status = IdTagInfoStatus.Blocked;
                                }
                                else if (ct.ExpiryDate.HasValue && ct.ExpiryDate.Value < DateTime.Now)
                                {
                                    startTransactionResponse.IdTagInfo.Status = IdTagInfoStatus.Expired;
                                }
                                else
                                {
                                    startTransactionResponse.IdTagInfo.Status = IdTagInfoStatus.Accepted;
                                }
                            }
                            else
                            {
                                startTransactionResponse.IdTagInfo.Status = IdTagInfoStatus.Invalid;
                            }

                            Logger.LogInformation("StartTransaction => Charge tag='{0}' => Status: {1}", idTag, startTransactionResponse.IdTagInfo.Status);
                        }
                    }
                    catch (Exception exp)
                    {
                        Logger.LogError(exp, "StartTransaction => Exception reading charge tag ({0}): {1}", idTag, exp.Message);
                        startTransactionResponse.IdTagInfo.Status = IdTagInfoStatus.Invalid;
                    }
                }

                if (startTransactionResponse.IdTagInfo.Status == IdTagInfoStatus.Accepted)
                {
                    try
                    {
                        using (OCPPCoreContext dbContext = new OCPPCoreContext(Configuration))
                        {
                            Transaction transaction = new Transaction();
                            transaction.ChargePointId = ChargePointStatus?.Id;
                            transaction.ConnectorId   = startTransactionRequest.ConnectorId;
                            transaction.StartTagId    = idTag;
                            transaction.StartTime     = startTransactionRequest.Timestamp.UtcDateTime;
                            transaction.MeterStart    = (double)startTransactionRequest.MeterStart / 1000; // Meter value here is always Wh
                            transaction.StartResult   = startTransactionResponse.IdTagInfo.Status.ToString();
                            dbContext.Add <Transaction>(transaction);
                            dbContext.SaveChanges();

                            // Return DB-ID as transaction ID
                            startTransactionResponse.TransactionId = transaction.TransactionId;
                        }
                    }
                    catch (Exception exp)
                    {
                        Logger.LogError(exp, "StartTransaction => Exception writing transaction: chargepoint={0} / tag={1}", ChargePointStatus?.Id, idTag);
                        errorCode = ErrorCodes.InternalError;
                    }
                }

                msgOut.JsonPayload = JsonConvert.SerializeObject(startTransactionResponse);
                Logger.LogTrace("StartTransaction => Response serialized");
            }
            catch (Exception exp)
            {
                Logger.LogError(exp, "StartTransaction => Exception: {0}", exp.Message);
                errorCode = ErrorCodes.FormationViolation;
            }

            WriteMessageLog(ChargePointStatus?.Id, connectorId, msgIn.Action, startTransactionResponse.IdTagInfo?.Status.ToString(), errorCode);
            return(errorCode);
        }