Esempio n. 1
0
        /// <summary>
        /// Create an invoice using the specified facade.
        /// </summary>
        /// <param name="invoice">An invoice request object.</param>
        /// <returns>A new invoice object returned from the server.</returns>
        public IEnumerator createInvoice(Invoice invoice, Action <Invoice> invoiceAction, String facade = FACADE_MERCHANT)
        {
            Debug.Log("createInvoice(): Curr" + invoice.Currency + " Price:" + invoice.Price + " " + invoice.BuyerEmail + " " + invoice.ItemDesc);

            invoice.Token = this.getAccessToken(facade);//get token by facade type
            invoice.Guid  = Guid.NewGuid().ToString();
            String json = JsonConvert.SerializeObject(invoice);

            Debug.Log("createInvoice(): About to post an initial Invoice " + json);

            CoroutineWithData cd = new CoroutineWithData(_owner, post("invoices", json, true));

            yield return(cd.coroutine);

            string responseStr = (string)cd.result;

            Debug.Log("createInvoice():  response:" + responseStr);

            JsonConvert.PopulateObject(this.responseToJsonString(responseStr), invoice);
            Debug.Log("createInvoice():  responsejson to Invoice Object done token1:id=" + invoice.Id + " token=" + invoice.Token + " json=" + JsonConvert.SerializeObject(invoice) + " toString:" + invoice.ToString());
            invoice = JsonConvert.DeserializeObject <Invoice>(this.responseToJsonString(responseStr));
            Debug.Log("createInvoice():  responsejson to Invoice Object done token2:id=" + invoice.Id + " token=" + invoice.Token + " json=" + JsonConvert.SerializeObject(invoice) + " toString:" + invoice.ToString());

            // Track the token for this invoice
            cacheToken(invoice.Id, invoice.Token);
            //
            Debug.Log("createInvoice():  Taking InvoiceAction callback BEFORE");
            invoiceAction(invoice);
            Debug.Log("createInvoice():  Taking InvoiceAction callback AFTER");
        }
Esempio n. 2
0
        /// <summary>
        /// Retrieve an invoice by id and token.
        /// </summary>
        /// <param name="invoiceId">The id of the requested invoice.</param>
        /// <returns>The invoice object retrieved from the server.</returns>
        public IEnumerator getInvoice(String invoiceId, Action <Invoice> invoiceAction, String facade = FACADE_MERCHANT)
        {
            // Provide the merchant token when the merchant facade is being used.
            // GET/invoices expects the merchant token and not the merchant/invoice token.
            Dictionary <string, string> parameters = null;

//            if (facade == FACADE_MERCHANT)
//            {
            try
            {
                parameters = new Dictionary <string, string>();
//                    parameters.Add("token", getAccessToken(FACADE_MERCHANT));
                parameters.Add("token", getAccessToken(facade));
                Debug.Log("getInvoice():  add param: token=" + getAccessToken(facade));
            }
            catch (BitPayException)
            {
                // No token for invoice.
                Debug.Log("getInvoice():  add param: NO TOKEN for " + facade);
                parameters = null;
            }
            //           }
            CoroutineWithData cd = new CoroutineWithData(_owner, get("invoices/" + invoiceId, parameters));

            yield return(cd.coroutine);

            String invoiceStr = (string)cd.result;

            Debug.Log("getInvoice():  Invoice Json :" + invoiceStr);
            Invoice invoice = JsonConvert.DeserializeObject <Invoice>(responseToJsonString(invoiceStr));

            invoiceAction(invoice);
        }
Esempio n. 3
0
        /// <summary>
        /// Retrieve the exchange rate table using the public facade.
        /// </summary>
        /// <returns>The rate table as an object retrieved from the server.</returns>
        public IEnumerator getRates(Action <Rates> ratesAction)
        {
            CoroutineWithData cd = new CoroutineWithData(_owner, get("rates"));

            yield return(cd.coroutine);

            String ratesStr = (string)cd.result;

            List <Rate> rates = JsonConvert.DeserializeObject <List <Rate> >(ratesStr);

            ratesAction(new Rates(rates, this));
        }
Esempio n. 4
0
        private IEnumerator getAccessTokens()
        {
            this.clearAccessTokenCache();//empty token map
            Dictionary <String, String> parameters = this.getParams();

            //yield return this.get("tokens", parameters);
            //_tokenCache = responseToTokenCache(response);

            CoroutineWithData cd = new CoroutineWithData(_owner, get("tokens", parameters));

            yield return(cd.coroutine);

            string tokensStr = (string)cd.result;

            Debug.Log("getAccessTokens() tokensStr: " + tokensStr);
            _tokenCache = responseToTokenCache(tokensStr);

            yield return(_tokenCache.Count);
        }
Esempio n. 5
0
        /// <summary>
        /// Authorize (pair) this client with the server using the specified pairing code.
        /// </summary>
        /// <param name="pairingCode">A code obtained from the server; typically from bitpay.com/api-tokens.</param>
        public IEnumerator authorizeClient(String pairingCode)
        {
            Token token = new Token();

            token.Id          = _identity;
            token.Guid        = Guid.NewGuid().ToString();
            token.PairingCode = pairingCode;
            token.Label       = _clientName;
            String json = JsonConvert.SerializeObject(token);

            CoroutineWithData cd = new CoroutineWithData(_owner, post("tokens", json));

            yield return(cd.coroutine);

            string tokenStr = (string)cd.result;

            tokenStr = responseToJsonString(tokenStr);
            Debug.Log("authorizeClient(): tokenStr:" + tokenStr);

            cacheTokens(tokenStr);
        }