private void button_Click(object sender, RoutedEventArgs e) { var customer = new Customer { name = textBoxCustomerName.Text, telephone = textBoxCustomerTelephone.Text }; var creditCard = new CreditCard { CardNumber = textBoxCreditCardNumber.Text, Cvc = textBoxSecurityCode.Text, ExpiryDate = textBoxExpiryDate.Text }; try { bool success = MoneyService.Charge(customer, creditCard, decimal.Parse(textBoxChargeAmount.Text)); if (success) { MessageBox.Show("Payment Successful"); Sms.SendSms(textBoxCustomerTelephone.Text, "Payment Successful"); } else { MessageBox.Show("Payment Not Successful"); Sms.SendSms(textBoxCustomerTelephone.Text, "Payment Not Successful"); } } catch (Exception f) { MessageBox.Show(f.Message); Sms.SendSms(textBoxCustomerTelephone.Text, f.Message); } }
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.ExpiryDate.Substring(0, 2), ExpirationYear = creditcard.ExpiryDate.Substring(3, 2), Cvc = creditcard.Cvc };// var ChargeService = new StripeChargeService(ApiKey); var response = ChargeService.Create(chargeDetails); if (response.Paid == false) { throw new Exception(response.FailureMessage); } return response.Paid; }