Exemplo n.º 1
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.º 2
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.º 3
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.º 4
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.º 5
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);
    }