Exemplo n.º 1
0
 private static StripePlan CreatePlan(StripePayment payment)
 {
     StripePlan plan = payment.CreatePlan(GetPlanInfo());
     StripePlan plan2 = payment.GetPlan(plan.Id);
     //DeletePlan (plan2, payment);
     return plan2;
 }
Exemplo n.º 2
0
 static void Main(string [] args)
 {
     StripePayment payment = new StripePayment ("YOURSECRETKEYGOESHERE");
     TestSimpleCharge (payment);
     TestCustomer (payment);
     TestCustomerAndCharge (payment);
     TestGetCharges (payment);
     TestGetCustomers (payment);
 }
Exemplo n.º 3
0
 static void TestCustomer(StripePayment payment)
 {
     StripeCustomerInfo customer = new StripeCustomerInfo ();
     //customer.Card = GetCC ();
     StripeCustomer customer_resp = payment.CreateCustomer (customer);
     string customer_id = customer_resp.ID;
     StripeCustomer customer_info = payment.GetCustomer (customer_id);
     Console.WriteLine (customer_info);
     StripeCustomer ci2 = payment.DeleteCustomer (customer_id);
     if (ci2.Deleted == false)
         throw new Exception ("Failed to delete " + customer_id);
 }
Exemplo n.º 4
0
 static void Main(string [] args)
 {
     StripePayment payment = new StripePayment ("vtUQeOtUnYr7PGCLQ96Ul4zqpDUO4sOE");
     TestSimpleCharge (payment);
     //TestPartialRefund (payment);
     //TestCustomer (payment);
     TestCustomerAndCharge (payment);
     //TestGetCharges (payment);
     TestGetCustomers (payment);
     //TestCreateGetToken (payment);
     //TestCreatePlanGetPlan (payment);
     //TestCreateSubscription (payment);
     //TestCreateInvoiceItems (payment);
     //TestInvoices (payment);
     //TestInvoices2 (payment);
     TestDeserializePastDue ();
 }
Exemplo n.º 5
0
 static void TestCustomerAndCharge(StripePayment payment)
 {
     StripeCustomerInfo customer = new StripeCustomerInfo ();
     //customer.Card = GetCC ();
     StripeCustomer response = payment.CreateCustomer (customer);
     string customer_id = response.ID;
     StripeCustomer customer_info = payment.GetCustomer (customer_id);
     Console.WriteLine (customer_info);
     StripeCustomerInfo info_update = new StripeCustomerInfo ();
     info_update.Card = GetCC ();
     StripeCustomer update_resp = payment.UpdateCustomer (customer_id, info_update);
     Console.Write ("Customer updated with CC. Press ENTER to continue...");
     Console.Out.Flush ();
     Console.ReadLine ();
     StripeCustomer ci2 = payment.DeleteCustomer (customer_id);
     if (ci2.Deleted == false)
         throw new Exception ("Failed to delete " + customer_id);
 }
Exemplo n.º 6
0
 public string ProcessPayment(string FirstName, string LastName, string EmailAddress, string CardNumber, string ExpMonth, string ExpYear, string Cvv)
 {
     StripePayment payment = new StripePayment("OxGcTunKYwFuBr6JPDpX1mehWlXHIJ7k");
     StripeCustomerInfo customer = new StripeCustomerInfo
                                       {
                                           Email = EmailAddress,
                                           Card =
                                               new StripeCreditCardInfo
                                                   {
                                                       Number = CardNumber,
                                                       ExpirationMonth = Convert.ToInt32(ExpMonth),
                                                       ExpirationYear = Convert.ToInt32(ExpYear),
                                                       FullName = FirstName + " " + LastName
                                                   }
                                       };
     StripeCustomer response = payment.CreateCustomer(customer);
     string customerId = response.ID;
     return payment.Charge(2500, "usd", customerId, "QuadAutomotive Group Application Fee").ID;            
 }
Exemplo n.º 7
0
        private static void TestInvoices2(StripePayment payment)
        {
            StripeCustomer cust = payment.GetCustomer("cus_ulcOcy5Seu2dpq");
            StripePlanInfo planInfo = new StripePlanInfo
                {
                    Amount = 1999,
                    Id = "testplan",
                    Interval = StripePlanInterval.month,
                    Name = "The Test Plan",
                    //TrialPeriod = 7
                };
            //payment.DeletePlan (planInfo.Id);
            StripePlan plan = payment.CreatePlan(planInfo);
            StripeSubscriptionInfo subInfo = new StripeSubscriptionInfo
                { Card = GetCC(), Plan = planInfo.Id, Prorate = true };
            StripeSubscription sub = payment.Subscribe(cust.Id, subInfo);
            payment.CreateInvoiceItem(
                new StripeInvoiceItemInfo { CustomerId = cust.Id, Amount = 1337, Description = "Test single charge" });

            int total;
            List<StripeInvoice> invoices = payment.GetInvoices(0, 10, cust.Id, out total);
            StripeInvoice upcoming = payment.GetUpcomingInvoice(cust.Id);
            payment.Unsubscribe(cust.Id, true);
            payment.DeletePlan(planInfo.Id);
            foreach (StripeInvoiceLineItem line in upcoming)
            {
                Console.WriteLine("{0} for type {1}", line.Amount, line.GetType());
            }
        }
Exemplo n.º 8
0
 private static void TestInvoices(StripePayment payment)
 {
     List<StripeInvoice> invoices = payment.GetInvoices(10, 10);
     StripeInvoice inv = payment.GetInvoice(invoices[0].Id);
     StripeCustomer cust = payment.CreateCustomer(new StripeCustomerInfo());
     StripeSubscription sub = payment.Subscribe(cust.Id, new StripeSubscriptionInfo { Card = GetCC() });
     StripeInvoice inv2 = payment.GetUpcomingInvoice(cust.Id);
     payment.Unsubscribe(cust.Id, true);
     payment.DeleteCustomer(cust.Id);
 }
Exemplo n.º 9
0
 private static void TestGetCustomers(StripePayment payment)
 {
     List<StripeCustomer> customers = payment.GetCustomers(0, 10);
     Console.WriteLine(customers.Count);
 }
Exemplo n.º 10
0
 private static void TestGetCharges(StripePayment payment)
 {
     List<StripeCharge> charges = payment.GetCharges(0, 10);
     Console.WriteLine(charges.Count);
 }
Exemplo n.º 11
0
 private static StripeSubscription TestDeleteSubscription(StripeCustomer customer, StripePayment payment)
 {
     return payment.Unsubscribe(customer.Id, true);
 }
Exemplo n.º 12
0
        private static void TestCreateSubscription(StripePayment payment)
        {
            StripeCustomer cust = payment.CreateCustomer(new StripeCustomerInfo { Card = GetCC() });
            //StripePlan temp = new StripePlan { Id = "myplan" };
            //DeletePlan (temp, payment);
            StripePlan plan = CreatePlan(payment);
            StripeSubscription sub = payment.Subscribe(
                cust.Id, new StripeSubscriptionInfo { Card = GetCC(), Plan = "myplan", Prorate = true });

            StripeSubscription sub2 = payment.GetSubscription(sub.CustomerID);

            TestDeleteSubscription(cust, payment);
            DeletePlan(plan, payment);
        }
Exemplo n.º 13
0
 private static void TestCreatePlanGetPlan(StripePayment payment)
 {
     StripePlan plan = CreatePlan(payment);
     int total;
     List<StripePlan> plans = payment.GetPlans(10, 10, out total);
     Console.WriteLine(total);
 }
Exemplo n.º 14
0
 public void Setup()
 {
     _payment = new StripePayment("opWnpofZHJ9tqEnGszFZTfZAmHKmz9Yz");
 }
Exemplo n.º 15
0
        private static void Main(string[] args)
        {
            var payment = new StripePayment("opWnpofZHJ9tqEnGszFZTfZAmHKmz9Yz");
            TestSimpleCharge(payment);
            TestPartialRefund(payment);
            TestCustomer(payment);
            TestCustomerAndCharge(payment);
            TestGetCharges(payment);
            TestGetCustomers(payment);
            TestCreateGetToken(payment);
            TestCreatePlanGetPlan(payment);
            TestCreateSubscription(payment);
            TestCreateInvoiceItems(payment);
            TestInvoices(payment);
            TestInvoices2(payment);
            TestDeserializePastDue();

            Console.ReadKey();
        }
Exemplo n.º 16
0
    private void TestStripePayment()
    {
        string stripeApiKey = Util.GetAppSetting(Constants.AppSettingKeys.StripeApiKey);
        StripePayment payment = new StripePayment(stripeApiKey);

        StripeCreditCardInfo cc = new StripeCreditCardInfo();
        cc.CVC = "1234";
        cc.ExpirationMonth = 6;
        cc.ExpirationYear = 2013;
        cc.Number = "4242424242424242";

        StripeCustomerInfo customerInfo = new StripeCustomerInfo();
        customerInfo.Card = cc;
        customerInfo.Description = "Test User";
        customerInfo.Email = UserSession.Current.Email;
        customerInfo.Validate = false;

        try
        {
            StripeCustomer customer = payment.CreateCustomer(customerInfo);

            int userID = UserSession.Current.UserID;

            StripeUser stripeUser = new StripeUser()
            {
                UserID = userID,
                StripeCustomerID = customer.ID,
                LiveMode = customer.LiveMode,
                Description = customer.Description,
                DateCreated = DateTime.UtcNow
            };

            int stripeUserID = StripeUserService.AddStripeUser(stripeUser);

            StripeCustomer customerFromPayment = payment.GetCustomer(customer.ID);

            customerInfo.Description = "Other Description";
            StripeCustomer updatedCustomer = payment.UpdateCustomer(customerFromPayment.ID, customerInfo);

            StripeCharge charge = payment.Charge(5001, "usd", customer.ID, "Another Test Charge");

            List<StripeUser> stripeUsers = StripeUserService.GetStripeUsers(userID, customer.ID);

        }
        catch (Exception ex)
        {
            string error = "Error Processing Request";
            LoggingFactory.GetLogger().LogError(error, ex);
        }

        //StripeCharge charge = payment.Charge(5001, "usd", cc, "Test charge");
        //string charge_id = charge.ID;
        //StripeCharge charge_info = payment.GetCharge(charge_id);
        //StripeCharge refund = payment.Refund(charge_info.ID);
    }
Exemplo n.º 17
0
 private static void TestPartialRefund(StripePayment payment)
 {
     StripeCreditCardInfo cc = GetCC();
     StripeCharge charge = payment.Charge(5001, "usd", cc, "Test partial refund");
     Console.WriteLine(charge.Id);
     StripeCharge refund = payment.Refund(charge.Id, 2499);
     Console.WriteLine(refund.Amount);
 }
Exemplo n.º 18
0
 static void TestCreatePlanGetPlan(StripePayment payment)
 {
     StripePlan plan = CreatePlan (payment);
     var plans = payment.GetPlans (10, 10);
     Console.WriteLine (plans.Total);
 }
Exemplo n.º 19
0
 static StripeSubscription TestDeleteSubscription(StripeCustomer customer, StripePayment payment)
 {
     StripeSubscription sub = payment.Unsubscribe (customer.ID, true);
     return sub;
 }
Exemplo n.º 20
0
 static void TestGetCustomers(StripePayment payment)
 {
     var customers = payment.GetCustomers (0, 10);
     Console.WriteLine (customers.Data.Count);
 }
Exemplo n.º 21
0
 static void TestGetCharges(StripePayment payment)
 {
     var charges = payment.GetCharges (0, 10);
     Console.WriteLine (charges.Data.Count);
 }
Exemplo n.º 22
0
        private static void TestSimpleCharge(StripePayment payment)
        {
            StripeCreditCardInfo cc = GetCC();
            StripeCharge charge = payment.Charge(5001, "usd", cc, "Test charge");
            Console.WriteLine(charge);
            string charge_id = charge.Id;
            StripeCharge charge_info = payment.GetCharge(charge_id);
            Console.WriteLine(charge_info);

            StripeCharge refund = payment.Refund(charge_info.Id);
            Console.WriteLine(refund.Created);
        }
Exemplo n.º 23
0
 private static void TestCreateGetToken(StripePayment payment)
 {
     StripeCreditCardToken tok = payment.CreateToken(GetCC());
     StripeCreditCardToken tok2 = payment.GetToken(tok.Id);
 }
Exemplo n.º 24
0
 private static StripePlan DeletePlan(StripePlan plan, StripePayment payment)
 {
     StripePlan deleted = payment.DeletePlan(plan.Id);
     return deleted;
 }
Exemplo n.º 25
0
        private static void TestCreateInvoiceItems(StripePayment payment)
        {
            StripeCustomer cust = payment.CreateCustomer(new StripeCustomerInfo());
            StripeInvoiceItemInfo info = GetInvoiceItemInfo();
            info.CustomerId = cust.Id;
            StripeInvoiceItem item = payment.CreateInvoiceItem(info);
            StripeInvoiceItemUpdateInfo updateInfo = GetInvoiceItemUpdateInfo();
            updateInfo.Description = "Invoice item: " + Guid.NewGuid().ToString();
            StripeInvoiceItem item2 = payment.UpdateInvoiceItem(item.Id, updateInfo);
            StripeInvoiceItem item3 = payment.GetInvoiceItem(item2.Id);
            if (item.Description == item3.Description) throw new Exception("Update failed");
            StripeInvoiceItem deleted = payment.DeleteInvoiceItem(item2.Id);
            if (!deleted.Deleted.HasValue && deleted.Deleted.Value) throw new Exception("Delete failed");
            int total;

            var items = payment.GetInvoiceItems(10, 10, null, out total);
            Console.WriteLine(total);
            payment.DeleteCustomer(cust.Id);
        }
Exemplo n.º 26
0
        /// <summary>
        /// Process a payment
        /// </summary>
        /// <param name="processPaymentRequest">Payment info required for an order processing</param>
        /// <returns>Process payment result</returns>
        public ProcessPaymentResult ProcessPayment(ProcessPaymentRequest processPaymentRequest)
        {
            var result = new ProcessPaymentResult();
            
            var customer = _customerService.GetCustomerById(processPaymentRequest.CustomerId);
            //var orderTotal = Math.Round(processPaymentRequest.OrderTotal, 2);

            StripeCreditCardInfo cc = new StripeCreditCardInfo();
            cc.CVC = processPaymentRequest.CreditCardCvv2;
            cc.FullName = customer.BillingAddress.FirstName + " " + customer.BillingAddress.LastName;
            
            cc.Number = processPaymentRequest.CreditCardNumber;
            cc.ExpirationMonth = processPaymentRequest.CreditCardExpireMonth;
            cc.ExpirationYear = processPaymentRequest.CreditCardExpireYear;
            cc.AddressLine1 = customer.BillingAddress.Address1;
            cc.AddressLine2 = customer.BillingAddress.Address2;
            if (customer.BillingAddress.Country.TwoLetterIsoCode.ToLower() == "us")
            {
                cc.StateOrProvince = customer.BillingAddress.StateProvince.Abbreviation;
            }
            else
            {
                cc.StateOrProvince = "ot";
            }

            cc.ZipCode = customer.BillingAddress.ZipPostalCode;
            
            cc.Country = customer.BillingAddress.Country.TwoLetterIsoCode;
            
            StripePayment payment = new StripePayment(_stripePaymentSettings.TransactionKey);
            
            try
            {
                StripeCharge charge = payment.Charge((int)(processPaymentRequest.OrderTotal * 100),
                    _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode.ToLower(), 
                    cc, string.Format("charge for {0} - {1}",
                    cc.FullName, processPaymentRequest.PurchaseOrderNumber));
            
                if (charge != null)
                {
                    result.NewPaymentStatus = PaymentStatus.Paid;
                    _stripePaymentSettings.TransactMode = TransactMode.AuthorizeAndCapture;
                    result.AuthorizationTransactionId = charge.ID;
                    result.AuthorizationTransactionResult = StripeChargeStatus.SUCCESS;
                    //need this for refund
                    result.AuthorizationTransactionCode = _stripePaymentSettings.TransactionKey;
                }
            }
            catch (StripeException stripeException)
            {
                result.AuthorizationTransactionResult = stripeException.StripeError.Message;
                result.AuthorizationTransactionCode = stripeException.StripeError.Code;
                result.AuthorizationTransactionId = "-1";
                result.AddError(string.Format("Declined ({0}: {1} - {2})", result.AuthorizationTransactionCode,
                    result.AuthorizationTransactionResult, _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode));
            }

            return result;
        }
Exemplo n.º 27
0
 public static StripePlan DeletePlan(StripePlan plan, StripePayment payment)
 {
     var deleted = payment.DeletePlan(plan.Id);
     return deleted;
 }