partial void btnPay_down(UIButton sender)
        {
            Boolean isTestNet = true;

            //const String KEY = "api_key_from_admin_portal";
            //const String PASSWORD = "******";

            String authorization     = String.Format("{0}:{1}", Settings.Key, Settings.Password);
            String base64credentials = Convert.ToBase64String(new ASCIIEncoding().GetBytes(authorization));

            //Note fields mandatory otherwise 500 error
            Int32 amountInCents = Convert.ToInt32(amount * 100);

            Models.BitPOS.OrderRequest request = new Models.BitPOS.OrderRequest()
            {
                amount = amountInCents, currency = "AUD", reference = "BitcoinBrisbane", description = "Test Ticket", failureURL = "https://www.bitcoinbrisbane.com.au/fail/1", successURL = "https://www.bitcoinbrisbane.com.au/greatsuccess/1"
            };
            String json = JsonConvert.SerializeObject(request);

            WebClient webClient = new WebClient()
            {
                Credentials = new NetworkCredential(Settings.Key, Settings.Password)
            };

            webClient.Headers[HttpRequestHeader.Authorization] = string.Format("Basic {0}", base64credentials);
            webClient.Headers[HttpRequestHeader.ContentType]   = "application/json";

            if (isTestNet == true)
            {
                //Use this for test because of SSL issues
                //System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
            }

            String response = webClient.UploadString("https://rest.bitpos.me/services/webpay/order/create", json);

            Models.BitPOS.OrderResponse orderResponse = Newtonsoft.Json.JsonConvert.DeserializeObject <Models.BitPOS.OrderResponse>(response);

//			LoadingOverlay loadingOverlay = new LoadingOverlay();
//
//			// Determine the correct size to start the overlay (depending on device orientation)
//			var bounds = UIScreen.MainScreen.Bounds; // portrait bounds
//			if (UIApplication.SharedApplication.StatusBarOrientation == UIInterfaceOrientation.LandscapeLeft || UIApplication.SharedApplication.StatusBarOrientation == UIInterfaceOrientation.LandscapeRight) {
//				bounds.Size = new CGSize(bounds.Size.Height, bounds.Size.Width);
//			}
//			// show the loading overlay on the UI thread using the correct orientation sizing
//			loadingOverlay = new LoadingOverlay (bounds);
//			this.View.Add ( loadingOverlay.loadPop );

            UIAlertView alert = new UIAlertView("Send BTC", String.Format("Send {0:0.0000} to {1}", Decimal.Divide(orderResponse.satoshis, SATOSHI), orderResponse.bitcoinAddress), null, "Ok", null);

            alert.Show();

            //ShowPopover(btn0, orderResponse.bitcoinAddress, String.Format("bitcoin:{0}", orderResponse.bitcoinAddress));
        }
		public async Task<Models.BitPOS.OrderResponse> CreateOrder(Int32 amountInCents, String reference, String description)
		{
			try
			{
				String authorization = String.Format("{0}:{1}", _key, _password);
				Byte[] base64credentials = System.Text.Encoding.UTF8.GetBytes(authorization);

				//Note fields mandatory otherwise 500 error
				Models.BitPOS.OrderRequest request = new Models.BitPOS.OrderRequest() { amount = amountInCents, currency = "AUD", reference = reference, description = description, failureURL="https://www.bitcoinbrisbane.com.au/fail/1", successURL="https://www.bitcoinbrisbane.com.au/greatsuccess/1" };
				String json = JsonConvert.SerializeObject(request);
					
				_httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(base64credentials));

				if (_testNet == true)
				{
					//TODO REMOVE HTTPS
					//Use this for test because of SSL issues
					//System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
				}

				var response = await _httpClient.PostAsync ("http://rest.test.bitpos.me/services/webpay/order/create", new StringContent (json, Encoding.UTF8, "application/json"));

				response.EnsureSuccessStatusCode();
				String responseBody = await response.Content.ReadAsStringAsync();

				if (!String.IsNullOrEmpty(responseBody))
				{
					Models.BitPOS.OrderResponse orderResponse = Newtonsoft.Json.JsonConvert.DeserializeObject<Models.BitPOS.OrderResponse>(responseBody);
					return orderResponse;
				}
				else
				{
					throw new ArgumentNullException();
				}
			}
			catch (Exception ex) 
			{
				//Xamarin.Insights.Report (ex);
				throw ex;
			}
		}
Example #3
0
        public Models.BitPOS.OrderResponse CreateOrder(Int32 amountInCents)
        {
            Boolean isTestNet = true;

            //const String KEY = "api_key_from_admin_portal";
            //const String PASSWORD = "******";

            String authorization     = String.Format("{0}:{1}", _key, _password);
            String base64credentials = Convert.ToBase64String(new ASCIIEncoding().GetBytes(authorization));

            //Note fields mandatory otherwise 500 error
            Models.BitPOS.OrderRequest request = new Models.BitPOS.OrderRequest()
            {
                amount = amountInCents, currency = "AUD", reference = "BitcoinBrisbane", description = "Test Ticket", failureURL = "https://www.bitcoinbrisbane.com.au/fail/1", successURL = "https://www.bitcoinbrisbane.com.au/greatsuccess/1"
            };
            String json = JsonConvert.SerializeObject(request);

            WebClient webClient = new WebClient()
            {
                Credentials = new NetworkCredential(Settings.Key, Settings.Password)
            };

            webClient.Headers[HttpRequestHeader.Authorization] = string.Format("Basic {0}", base64credentials);
            webClient.Headers[HttpRequestHeader.ContentType]   = "application/json";

            if (isTestNet == true)
            {
                //Use this for test because of SSL issues
                //System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
            }

            String response = webClient.UploadString("https://rest.bitpos.me/services/webpay/order/create", json);

            Models.BitPOS.OrderResponse orderResponse = Newtonsoft.Json.JsonConvert.DeserializeObject <Models.BitPOS.OrderResponse>(response);
            return(orderResponse);
        }