public static bool Charge(Customer customer, CreditCard creditCard, decimal amount) { var chargeDetails = new StripeChargeCreateOptions(); chargeDetails.Amount = (int)(amount * 100); chargeDetails.Currency = "usd"; chargeDetails.Source = new StripeSourceOptions { Object = "card", Number = creditCard.CardNumber, ExpirationMonth = creditCard.ExpirationDate.Month.ToString(), ExpirationYear = creditCard.ExpirationDate.Year.ToString(), Cvc = creditCard.Cvc }; var chargeService = new StripeChargeService(StripeApiKey); var response = chargeService.Create(chargeDetails); if (response.Paid == false) { throw new Exception(response.FailureMessage); } return response.Paid; }
private void buttonProcessPayemnt_Click(object sender, RoutedEventArgs e) { var customer = new Customer { Name = textBoxCustomerName.Text, Telephone = textBoxCustomerTelephone.Text }; var creditCard = new CreditCard { CardNumber = textBoxCustomerCreditCardNumber.Text, Cvc = textBoxCvc.Text, ExpirationDate = DateTime.Parse(textBoxExpirationDate.Text) }; try { bool success = MoneyService.Charge(customer, creditCard, decimal.Parse(textBoxCustomerAmount.Text)); if (success) { MessageBox.Show("Payment Successful"); var message1 = ("Your account was charged: $" + textBoxCustomerAmount.Text); SmsService.SendSms(textBoxCustomerTelephone.Text, message1); } else { MessageBox.Show("Payment Unsuccessful"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }