/// <summary>
        /// Make a recurring payment
        /// It is with this resource that we carry out our purchases on a recurring basis.
        /// The checkout resource is used when we want to make a payment or schedule a recurring payment from A (buyer) to B (seller).
        /// A checkout has a monetary value in currency (value), acronym for currency (currency), blockchain for transaction (blockchain),
        /// card number (pan), card password (password), period for execution (period), a frequency in numeral (frequency),
        /// a boolean to execute or not the payment at the time (execute) and a vendor identifier (vendorKey)
        /// </summary>
        /// <param name="makeRecurringPayment"></param>
        /// <returns>Checkout</returns>
        public Checkout MakeRecurringPayment(MakeRecurringPayment makeRecurringPayment)
        {
            try
            {
                //Convert to Sha256
                makeRecurringPayment.pan      = Converts.ComputeSha256Hash(makeRecurringPayment.pan);
                makeRecurringPayment.password = Converts.ComputeSha256Hash(makeRecurringPayment.password);

                string urlBase = this.SandBox ? GlobalType.URL_BASE_SANDBOX : GlobalType.URL_BASE_DEFAULT;

                string strJson = JsonConvert.SerializeObject(makeRecurringPayment);

                byte[] buffer = Encoding.UTF8.GetBytes(strJson);

                HttpWebRequest httpWebRequest = HttpWebRequest.CreateHttp(urlBase + GlobalType.URL_CHECKOUT_RECURRENT);
                httpWebRequest.Method        = "POST";
                httpWebRequest.Accept        = "application/json";
                httpWebRequest.ContentType   = "application/json";
                httpWebRequest.ContentLength = buffer.Length;
                httpWebRequest.GetRequestStream().Write(buffer, 0, buffer.Length);

                using (HttpWebResponse objResponse = httpWebRequest.GetResponse() as HttpWebResponse)
                {
                    using (StreamReader strReader = new StreamReader(objResponse.GetResponseStream()))
                        return(JsonConvert.DeserializeObject <Checkout>(strReader.ReadToEnd()));
                }
            }
            catch (Exception ex)
            {
                return(new Checkout()
                {
                    status = new Status()
                    {
                        code = "-1", message = ex.Message
                    }
                });
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            ApusPaymentsAPI apusPaymentsAPI = new ApusPaymentsAPI(EnviromentType.SandBox);

            string pan      = "9999999999999999";
            string password = "******";

            string vendorKey      = "5f5bdaed-f82b-4b82-b3f5-1d562633da5b";
            string vendorPassword = "******";

            // Make a payment
            MakePayment makePayment = new MakePayment();

            makePayment.pan        = pan;
            makePayment.password   = password;
            makePayment.blockchain = BlockChainType.LTC;
            makePayment.amount     = 13.88;
            makePayment.currency   = CurrencyType.BRL;
            makePayment.vendorKey  = vendorKey;

            var makePaymentReturn = apusPaymentsAPI.MakePayment(makePayment);

            Console.WriteLine("MakePayment: " + JsonConvert.SerializeObject(makePaymentReturn));
            Console.WriteLine("");

            // Make a recurring payment
            MakeRecurringPayment makeRecurringPayment = new MakeRecurringPayment();

            makeRecurringPayment.pan        = pan;
            makeRecurringPayment.password   = password;
            makeRecurringPayment.blockchain = BlockChainType.LTC;
            makeRecurringPayment.amount     = 13.88;
            makeRecurringPayment.currency   = CurrencyType.BRL;
            makeRecurringPayment.period     = PeriodType.M;
            makeRecurringPayment.vendorKey  = vendorKey;

            var makeRecurringPaymentReturn = apusPaymentsAPI.MakeRecurringPayment(makeRecurringPayment);

            Console.WriteLine("Make a Recurring Payment: " + JsonConvert.SerializeObject(makeRecurringPaymentReturn));
            Console.WriteLine("");

            // Search payment
            SearchPayment searchPayment = new SearchPayment();

            searchPayment.vendorKey      = vendorKey;
            searchPayment.txId           = "";
            searchPayment.timestamp      = "";
            searchPayment.blockchain     = BlockChainType.LTC;
            searchPayment.currency       = CurrencyType.BRL;
            searchPayment.coinAmount     = "";
            searchPayment.currencyAmount = "";
            searchPayment.buyer          = "";

            var searchPaymentReturn = apusPaymentsAPI.SearchPayment(searchPayment);

            Console.WriteLine("Search Payment: " + JsonConvert.SerializeObject(searchPaymentReturn));
            Console.WriteLine("");

            // Cancel
            CancelPayment cancelPayment = new CancelPayment();

            cancelPayment.txId      = "2bf779e2a311c2629df977b0bb105879411fd71f5839972c4ed1d3278f80170f";
            cancelPayment.password  = vendorPassword;
            cancelPayment.vendorKey = vendorKey;

            var cancelPaymentReturn = apusPaymentsAPI.CancelPayment(cancelPayment);

            Console.WriteLine("Cancel a Payment: " + JsonConvert.SerializeObject(cancelPaymentReturn));
            Console.WriteLine("");

            RechargeCryptoBalance rechargeCryptoBalance = new RechargeCryptoBalance();

            rechargeCryptoBalance.pan        = pan;
            rechargeCryptoBalance.password   = password;
            rechargeCryptoBalance.blockchain = BlockChainType.LTC;
            rechargeCryptoBalance.amount     = 13.88;
            rechargeCryptoBalance.currency   = CurrencyType.BRL;
            rechargeCryptoBalance.vendorKey  = vendorKey;

            var rechargeCryptoBalanceReturn = apusPaymentsAPI.RechargeCryptoBalance(rechargeCryptoBalance);

            Console.WriteLine("Recharge of Crypto Balance: " + JsonConvert.SerializeObject(rechargeCryptoBalanceReturn));
            Console.WriteLine("");

            Console.ReadKey();
        }