public StripeCharge Charge(int amount_cents, string currency, StripeCreditCardInfo card, string description) { if (card == null) throw new ArgumentNullException ("card"); return Charge (amount_cents, currency, null, card, description); }
public StripeCharge Charge(int amount_cents, string currency, StripeCreditCardInfo card, string description) { if (card == null) { throw new ArgumentNullException("card"); } return(Charge(amount_cents, currency, null, card, description)); }
private static StripeCreditCardInfo GetCC() { StripeCreditCardInfo cc = new StripeCreditCardInfo(); cc.CVC = "1234"; cc.ExpirationMonth = 6; cc.ExpirationYear = 2012; cc.Number = "4242424242424242"; return cc; }
public StripeCard CreateCard(string customer_id, StripeCreditCardInfo card) { if (string.IsNullOrWhiteSpace(customer_id)) { throw new ArgumentNullException("customer_id"); } StringBuilder str = UrlEncode(card); string ep = String.Format("{0}/customers/{1}/cards", api_endpoint, HttpUtility.UrlEncode(customer_id)); return(DoRequest <StripeCard> (ep, "POST", str.ToString())); }
public StripeCreditCardToken CreateToken(StripeCreditCardInfo card) { if (card == null) { throw new ArgumentNullException("card"); } StringBuilder str = UrlEncode(card); string ep = string.Format("{0}/tokens", api_endpoint); return(DoRequest <StripeCreditCardToken> (ep, "POST", str.ToString())); }
StripeCharge Charge(int amount_cents, string currency, string customer, StripeCreditCardInfo card, string description) { if (amount_cents < 0) { throw new ArgumentOutOfRangeException("amount_cents", "Must be greater than or equal 0"); } if (String.IsNullOrEmpty(currency)) { throw new ArgumentNullException("currency"); } if (currency != "usd") { throw new ArgumentException("The only supported currency is 'usd'"); } StringBuilder str = new StringBuilder(); str.AppendFormat("amount={0}&", amount_cents); str.AppendFormat("currency={0}&", currency); if (!String.IsNullOrEmpty(description)) { str.AppendFormat("description={0}&", HttpUtility.UrlEncode(description)); } if (card != null) { card.UrlEncode(str); } else { // customer is non-empty str.AppendFormat("customer={0}&", HttpUtility.UrlEncode(customer)); } str.Length--; string ep = String.Format("{0}/charges", api_endpoint); string json = DoRequest(ep, "POST", str.ToString()); return(JsonConvert.DeserializeObject <StripeCharge> (json)); }
/// <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; }
StripeCharge Charge(int amount_cents, string currency, string customer, StripeCreditCardInfo card, string description) { if (amount_cents < 0) throw new ArgumentOutOfRangeException ("amount_cents", "Must be greater than or equal 0"); if (String.IsNullOrEmpty (currency)) throw new ArgumentNullException ("currency"); if (currency != "usd") throw new ArgumentException ("The only supported currency is 'usd'"); StringBuilder str = new StringBuilder (); str.AppendFormat ("amount={0}&", amount_cents); str.AppendFormat ("currency={0}&", currency); if (!String.IsNullOrEmpty (description)) { str.AppendFormat ("description={0}&", HttpUtility.UrlEncode (description)); } if (card != null) { card.UrlEncode (str); } else { // customer is non-empty str.AppendFormat ("customer={0}&", HttpUtility.UrlEncode (customer)); } str.Length--; string ep = String.Format ("{0}/charges", api_endpoint); string json = DoRequest (ep, "POST", str.ToString ()); return JsonConvert.DeserializeObject<StripeCharge> (json); }
public StripeCreditCardToken CreateToken(StripeCreditCardInfo card) { if (card == null) throw new ArgumentNullException ("card"); StringBuilder str = UrlEncode (card); string ep = string.Format ("{0}/tokens", api_endpoint); string json = DoRequest (ep, "POST", str.ToString ()); return JsonConvert.DeserializeObject<StripeCreditCardToken> (json); }
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); }