Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new voucher generation instance.
        /// </summary>
        public async Task <(Guid Otc, string Password)> CreatePaymentRequest(
            Pos pointOfService,
            PaymentRegisterPayload.Content creationParameters,
            bool isPreVerified = false
            )
        {
            if (!creationParameters.PosId.Equals(pointOfService.Id.ToString()))
            {
                throw new ArgumentException("Incoherent POS IDs");
            }

            var otc      = Guid.NewGuid();
            var password = creationParameters.Password ?? Random.GeneratePassword(DefaultAutogeneratedPasswordLength);

            var payRequest = new PaymentRequest {
                Otc          = otc,
                Amount       = creationParameters.Amount,
                CreatedAt    = DateTime.UtcNow,
                Verified     = isPreVerified,
                IsPersistent = creationParameters.Persistent,
                PosId        = pointOfService.Id,
                Nonce        = creationParameters.Nonce,
                Password     = password,
                AckUrlPocket = creationParameters.PocketAckUrl,
                AckUrlPos    = creationParameters.PosAckUrl
            };

            if (creationParameters.SimpleFilter != null)
            {
                payRequest.Filter = new Filter {
                    Aims   = creationParameters.SimpleFilter.Aim,
                    Bounds = creationParameters.SimpleFilter.GetBounds(),
                    MaxAge = creationParameters.SimpleFilter.MaxAge
                };
            }
            await Mongo.AddPaymentRequest(payRequest);

            return(otc, password);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new voucher generation instance.
        /// </summary>
        public async Task <(Guid Otc, string Password)> CreatePaymentRequest(
            PaymentRegisterPayload.Content creationParameters,
            bool isPreVerified = false
            )
        {
            var otc      = Guid.NewGuid();
            var password = creationParameters.Password ?? _random.GeneratePassword(DefaultAutogeneratedPasswordLength);

            var payRequest = new PaymentRequest {
                Amount       = creationParameters.Amount,
                JsonFilter   = null,
                OtcPay       = otc,
                UrlAckPocket = creationParameters.PocketAckUrl,
                UrlAckPos    = creationParameters.PosAckUrl,
                CreatedAt    = DateTime.UtcNow,
                Verified     = isPreVerified,
                Persistent   = creationParameters.Persistent,
                Void         = false,
                PosId        = creationParameters.PosId,
                Nonce        = creationParameters.Nonce.FromBase64(),
                Password     = password
            };

            if (creationParameters.SimpleFilter != null)
            {
                payRequest.JsonFilter = JsonSerializer.Serialize(
                    new Filter {
                    Simple = creationParameters.SimpleFilter
                }
                    );
            }
            Data.PaymentRequests.Add(payRequest);
            await Data.SaveChangesAsync();

            return(otc, password);
        }