예제 #1
0
        public static string GetToken(TiqetsTransaction tiqetsTransaction, string privateKey)
        {
            ConfirmOrderRequestModel requestModel = new ConfirmOrderRequestModel();

            requestModel.payment_confirmation_token = tiqetsTransaction.PaymentConfirmationToken;
            RSAParameters rsaParams;

            using (var tr = new StringReader(privateKey))
            {
                var pemReader = new PemReader(tr);
                var keyPair   = pemReader.ReadObject() as AsymmetricCipherKeyPair;
                if (keyPair == null)
                {
                    throw new Exception("Could not read RSA private key");
                }
                var privateRsaParams = keyPair.Private as RsaPrivateCrtKeyParameters;
                rsaParams = DotNetUtilities.ToRSAParameters(privateRsaParams);
            }
            using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())
            {
                rsa.ImportParameters(rsaParams);
                var json = JsonConvert.SerializeObject(requestModel);
                return(Jose.JWT.Encode(json, rsa, Jose.JwsAlgorithm.RS256));
            }
        }
예제 #2
0
        public async Task <IActionResult> Put(Guid id, ConfirmOrderRequestModel model)
        {
            if (ModelState.IsValid)
            {
                var order = await _context.Orders.FirstOrDefaultAsync(e => e.Id == id);

                if (model.Complete)
                {
                    order.Status = OrderStatus.Completed;
                }
                else
                {
                    order.ShipmentDate = model.ShipmentDate;
                    order.Status       = OrderStatus.Performed;
                }

                await _context.SaveChangesAsync();

                return(Ok());
            }

            return(BadRequest()); //TODO Specify errors
        }