Example #1
0
        /// <summary>
        /// Creates an invoice using the BitPay Payment Gateway API.
        /// </summary>
        /// <param name="price">This is the amount that is required to be collected from the buyer. Note, if this
        /// is specified in a currency other than BTC, the price will be converted into BTC at market exchange
        /// rates to determine the amount collected from the buyer.</param>
        /// <param name="parameters">Optional payment notification (IPN) parameters.</param>
        /// <returns>A BitPay server populated Invoice object.</returns>
        /// <exception cref="BitPayAPI.BitPayException">Handles only errors that occur in the returned data.
        /// Does not handle programming or communication errors.</exception>
        public Invoice createInvoice(double price, InvoiceParams parameters)
        {
            if (currency.Length > 3)
            {
                throw new ArgumentException("Must be a valid currency code");
            }

            var content = new FormUrlEncodedContent(this.getParams(price, this.currency, parameters));
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", this.auth);

            var result = client.PostAsync("invoice", content).Result;
            HttpContent response = result.Content;

            return createInvoiceObjectFromResponse(response);
        }
Example #2
0
        /// <summary>
        /// Creates an invoice using the BitPay Payment Gateway API.
        /// </summary>
        /// <param name="price">This is the amount that is required to be collected from the buyer. Note, if this
        /// is specified in a currency other than BTC, the price will be converted into BTC at market exchange
        /// rates to determine the amount collected from the buyer.</param>
        /// <param name="parameters">Optional payment notification (IPN) parameters.</param>
        /// <returns>A BitPay server populated Invoice object.</returns>
        /// <exception cref="BitPayAPI.BitPayException">Handles only errors that occur in the returned data.
        /// Does not handle programming or communication errors.</exception>
        public Invoice createInvoice(decimal price, string currency, InvoiceParams parameters)
        {
            if (currency.Length > 3)
            {
                throw new ArgumentException("Must be a valid currency code");
            }

            var content = new FormUrlEncodedContent(this.getParams(price, currency, parameters));

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", this.auth);
            client.DefaultRequestHeaders.Add("X-BitPay-Plugin-Info", "CSharplib");

            var         result   = client.PostAsync("invoice", content).Result;
            HttpContent response = result.Content;

            return(createInvoiceObjectFromResponse(response));
        }
Example #3
0
 /// <summary>
 /// Creates a list of key/value parameters including optional API parameters.
 /// </summary>
 /// <param name="price">The invoice price.</param>
 /// <param name="currency">The invoice currency.</param>
 /// <param name="optionalParams">A populated InvoiceParams object.</param>
 /// <returns>A list of key/value pairs.</returns>
 private Dictionary<string, string> getParams(double price, string currency, InvoiceParams invoiceParams)
 {
     var parameters = invoiceParams.getDictionary();
     parameters.Add("price", price.ToString());
     parameters.Add("currency", currency);
     return parameters;
 }
Example #4
0
        public void testShouldCreateInvoiceWithAdditionalParams()
        {
            try
            {
                // Arrange
                double price = 100.0;
                InvoiceParams parameters = new InvoiceParams();
                parameters.buyerName = "Satoshi";
                parameters.buyerEmail = "*****@*****.**";
                parameters.fullNotifications = true;
                parameters.notificationEmail = "*****@*****.**";

                // Act
                this.bitpay = new BitPay(API_KEY);
                Invoice invoice = this.bitpay.createInvoice(price, "USD", parameters);

                // Assert
                Assert.IsNotNull(invoice, "Invoice not created");
            }
            catch (BitPayException ex)
            {
                Assert.Fail(ex.getMessage());
            }
        }
Example #5
0
        /// <summary>
        /// Creates a list of key/value parameters including optional API parameters.
        /// </summary>
        /// <param name="price">The invoice price.</param>
        /// <param name="currency">The invoice currency.</param>
        /// <param name="optionalParams">A populated InvoiceParams object.</param>
        /// <returns>A list of key/value pairs.</returns>
        private Dictionary <string, string> getParams(decimal price, string currency, InvoiceParams invoiceParams)
        {
            var parameters = invoiceParams.getDictionary();

            parameters.Add("price", price.ToString());
            parameters.Add("currency", currency);
            return(parameters);
        }