예제 #1
0
        public ChargeTester(ServerTester serverTester, string environmentName, string defaultValue, string defaultHost, Network network)
        {
            this._Parent = serverTester;
            var url = serverTester.GetEnvironment(environmentName, defaultValue);

            Client  = new ChargeClient(new Uri(url), network);
            P2PHost = _Parent.GetEnvironment(environmentName + "_HOST", defaultHost);
        }
예제 #2
0
        public WebPayClient(string apikey)
        {
            this.ApiKey  = apikey;
            this.BaseUri = new Uri("https://api.webpay.jp/v1/");
            this.Handler = new HttpClientHandler();

            this.Customer = new CustomerClient(this);
            this.Token    = new TokenClient(this);
            this.Charge   = new ChargeClient(this);
            this.Account  = new AccountClient(this);
        }
예제 #3
0
        //MultiValueDictionary<string,string>
        private async Task Listen(InvoiceEntity invoice, PaymentMethod paymentMethod, BTCPayNetwork network)
        {
            var lightningMethod = paymentMethod.GetPaymentMethodDetails() as LightningLikePaymentMethodDetails;

            if (lightningMethod == null)
            {
                return;
            }
            var lightningSupportedMethod = invoice.GetSupportedPaymentMethod <LightningSupportedPaymentMethod>(_NetworkProvider)
                                           .FirstOrDefault(c => c.CryptoCode == network.CryptoCode);

            if (lightningSupportedMethod == null)
            {
                return;
            }

            var charge  = new ChargeClient(lightningSupportedMethod.GetLightningChargeUrl(true), network.NBitcoinNetwork);
            var session = await charge.Listen();

            while (true)
            {
                var notification = await session.NextEvent();

                if (notification.Id == lightningMethod.InvoiceId &&
                    notification.PaymentRequest == lightningMethod.BOLT11)
                {
                    if (notification.Status == "paid" && notification.PaidAt.HasValue)
                    {
                        await _InvoiceRepository.AddPayment(invoice.Id, notification.PaidAt.Value, new LightningLikePaymentData()
                        {
                            BOLT11 = notification.PaymentRequest,
                            Amount = notification.MilliSatoshi
                        }, network.CryptoCode, accounted : true);

                        _Aggregator.Publish(new InvoiceEvent(invoice.Id, 1002, "invoice_receivedPayment"));
                        break;
                    }
                    if (notification.Status == "expired")
                    {
                        break;
                    }
                }
            }
        }