Example #1
0
        public async Task <IActionResult> CreatePayment(
            string ackUrl,
            int amount = 10,
            [FromBody] SimpleFilter filter = null
            )
        {
            if (!Hosting.IsDevelopment())
            {
                return(Unauthorized());
            }

            if (amount <= 0)
            {
                throw new ArgumentOutOfRangeException("Amount cannot be zero or negative", nameof(amount));
            }
            if (string.IsNullOrWhiteSpace(ackUrl))
            {
                throw new ArgumentException("Acknowledgment URL cannot be void", nameof(ackUrl));
            }

            Logger.LogInformation("Creating payment for {0} vouchers", amount);

            var testPos = await Mongo.GetPosById(_testPosId);

            Logger.LogTrace("Test POS: {0}", testPos.Id);

            (var otcPay, var pwd) = await Operator.CreatePaymentRequest(testPos, new PaymentRegisterPayload.Content {
                Amount       = amount,
                Nonce        = Guid.NewGuid().ToString("N"),
                SimpleFilter = filter,
                PosId        = testPos.Id.ToString(),
                PocketAckUrl = ackUrl
            }, isPreVerified : true);

            Logger.LogDebug("New payment request created with code {0}", otcPay);

            return(Ok(new {
                OtcPay = UrlGenerator.GeneratePaymentUrl(otcPay),
                Pin = pwd
            }));
        }