コード例 #1
0
ファイル: StripeService.cs プロジェクト: anandraj204/First
        public async Task<bool> ChargeCustomer(string tokenId, int amount)
        {
            return await System.Threading.Tasks.Task.Run(() =>
            {
                try
                {

                    var myCharge = new StripeChargeCreateOptions
                    {
                        Amount = amount,
                        Currency = "usd",
                        Description = "Fund Digital Wallet",
                        Source = new StripeSourceOptions() {TokenId = tokenId},
                        Capture = true,
                    };

                    var chargeService = new StripeChargeService();
                    var stripeCharge = chargeService.Create(myCharge);
                    if (stripeCharge.Status == "succeeded" && stripeCharge.Paid == true)
                    {
                        return true;
                    }
                    return false;

                }
                catch (Exception)
                {
                    //log exception here
                    return false;
                }
            });
        }
コード例 #2
0
ファイル: StripeService.cs プロジェクト: anandraj204/First
        public void StripeCharge(string token,int amount)
        {
            var myCharge = new StripeChargeCreateOptions();

            // always set these properties
            myCharge.Amount = amount;
            myCharge.Currency = "usd";

            // set this if you want to
            myCharge.Description = "Digital Wallet fund";

            // setting up the card
            myCharge.Source = new StripeSourceOptions()
            {
                // set this property if using a token
                TokenId = token
            };

            // set this property if using a customer
            //myCharge.CustomerId = *customerId*;

            // set this if you have your own application fees (you must have your application configured first within Stripe)
           // myCharge.ApplicationFee = 25;

            // (not required) set this to false if you don't want to capture the charge yet - requires you call capture later
            myCharge.Capture = true;

            var chargeService = new StripeChargeService();
            StripeCharge stripeCharge = chargeService.Create(myCharge);
        }
コード例 #3
0
        public string ChargeCustomer(string customerId, int cMonth, int cDay, int cYear, int subscriptionDay, int price)
        {
            try
            {
                //Set up charge amount
                int days = DateTime.DaysInMonth(cYear, cMonth);
                double daylyCharge = price / (double)days;
                int chargedDays = days - cDay + 1;
                double proCharge = daylyCharge * chargedDays;

                //Set up charge
                var chargeOptions = new StripeChargeCreateOptions();

                chargeOptions.Amount = (int)proCharge * 100;
                chargeOptions.Currency = "usd";
                chargeOptions.CustomerId = customerId;
                chargeOptions.Capture = true;

                //Create Charge
                StripeCharge charge = charService.Create(chargeOptions);
                return charge.Id;
            }
            catch (Exception ex)
            {
                if (ex is StripeException)
                {
                    StripeException exception = (StripeException)ex;
                    StripeError err = exception.StripeError;
                    return err.ErrorType;
                }
                return null;
            }
        }
コード例 #4
0
        public static bool Charge(Customer cus, CreditCard cc, decimal amount) //PRD)
        {
            var chargeDetails = new StripeChargeCreateOptions();
            chargeDetails.Amount = (int)amount * 100;
            chargeDetails.Currency = "usd";

            chargeDetails.Source = new StripeSourceOptions
            {
                Object = "card",
                Number = cc.CardNum,
                ExpirationMonth = cc.Expiration.Substring(0, 2),
                ExpirationYear = cc.Expiration.Substring(3, 2),
                Cvc = cc.CVC
            };

            var chargeService = new StripeChargeService(APIKey);
            var response = chargeService.Create(chargeDetails);

            if (response.Paid == false)
            {
                throw new Exception(response.FailureMessage);
            }

            return response.Paid;

        }
コード例 #5
0
        private async Task<string> ProcessPayment(CourseRegistrationModel model, int id)
        {
            var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
            var currentUser = manager.FindById(User.Identity.GetUserId());
            string userEmail = currentUser.Email;
            return await Task.Run(() =>
            {
                Course course = db.Courses.Find(id);
                var myCharge = new StripeChargeCreateOptions
                {
                    Amount = (int)(course.Course_Cost * model.NumberOfParticipants * 100),
                    Currency = "usd",
                    Description = "Description for test charge",
                    ReceiptEmail = userEmail,
                    Source = new StripeSourceOptions
                    {
                        TokenId = model.Token
                    }
                };

                var chargeService = new StripeChargeService("sk_test_yPi2XADkAP3wiS1i6tkjErxZ");
                var stripeCharge = chargeService.Create(myCharge);

                return stripeCharge.Id;
            });
        }
コード例 #6
0
        public ActionResult Charge([FromBody]string stripeEmail, string stripeToken)
        {
            try
            {
                var charge = new StripeChargeCreateOptions()
                {
                    Amount = _settings.StripeDonationAmountInCents,
                    Currency = _settings.StripeDonationCurrency,
                    Description = "Donation for An API of Ice And Fire",
                    ReceiptEmail = stripeEmail,
                    Source = new StripeSourceOptions
                    {
                        TokenId = stripeToken
                    }
                };

                var chargeService = new StripeChargeService(_settings.StripePrivateKey);
                chargeService.Create(charge);
            }
            catch (StripeException se)
            {
                //Log error in a better way later on
                Debug.WriteLine(se.StripeError);
            }

            return Redirect("/");
        }
コード例 #7
0
ファイル: Payment.aspx.cs プロジェクト: roneytech/pinzey
        protected bool chargeCard(string tokenId, int amount)
        {
            var pinzeyCharge = new StripeChargeCreateOptions();

            // always set these properties
            pinzeyCharge.Amount = amount;
            pinzeyCharge.Currency = "usd";

            // set this if you want to
            pinzeyCharge.Description = "Charge it like it's hot";

            // setting up the card
            pinzeyCharge.Source = new StripeSourceOptions()
            {
                // set this property if using a token
                TokenId = tokenId
            };

            // set this if you have your own application fees (you must have your application configured first within Stripe)
            //myCharge.ApplicationFee = 25;

            // (not required) set this to false if you don't want to capture the charge yet - requires you call capture later
            //myCharge.Capture = true;

            var chargeService = new StripeChargeService();
            StripeCharge stripeCharge = chargeService.Create(pinzeyCharge);
            return stripeCharge.Paid;
        }
コード例 #8
0
        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;

        }
コード例 #9
0
        public ActionResult Index(FormCollection tokenString)
        {
            if (tokenString == null)
            {
                return View("SecurePayment");
            }

            else
            {
                try
                {
                    var myCharge = new StripeChargeCreateOptions();

                    // always set these properties
                    myCharge.Amount = 120;
                    myCharge.Currency = "eur";

                    // set this if you want to
                    myCharge.Description = "Charge it like it's hot";

                    // setting up the card
                    myCharge.Source = new StripeSourceOptions()
                    {
                        // set this property if using a token
                        TokenId = tokenString[0],

                        // set these properties if passing full card details (do not
                        // set these properties if you set TokenId)
                        //Number = "4242424242424242",
                        //ExpirationYear = "2022",
                        //ExpirationMonth = "10",
                        //AddressCountry = "US",                // optional
                        //AddressLine1 = "24 Beef Flank St",    // optional
                        //AddressLine2 = "Apt 24",              // optional
                        //AddressCity = "Biggie Smalls",        // optional
                        //AddressState = "NC",                  // optional
                        //AddressZip = "27617",                 // optional
                        //Name = "Joe Meatballs",               // optional
                        //Cvc = "1223"                          // optional
                    };

                    // set this property if using a customer
                    //myCharge.CustomerId = *customerId*;

                    // set this if you have your own application fees (you must have your application configured first within Stripe)
                    //myCharge.ApplicationFee = 25;

                    // (not required) set this to false if you don't want to capture the charge yet - requires you call capture later
                    myCharge.Capture = true;

                    var chargeService = new StripeChargeService();
                    StripeCharge stripeCharge = chargeService.Create(myCharge);
                    return View("PaymentSuccess");
                }
                catch
                {
                    return View("SecurePayment");
                }
            }
        }
コード例 #10
0
 //Sync
 public virtual StripeCharge Create(StripeChargeCreateOptions createOptions, StripeRequestOptions requestOptions = null)
 {
     return(Mapper <StripeCharge> .MapFromJson(
                Requestor.PostString(this.ApplyAllParameters(createOptions, Urls.Charges, false),
                                     SetupRequestOptions(requestOptions))
                ));
 }
コード例 #11
0
        public static bool Charge(Customer customer, CreditCard creditcard, decimal amount)
        {
            var myCharge = new StripeChargeCreateOptions();

            // always set these properties
            myCharge.Amount = (int)amount*100;
            myCharge.Currency = "usd";

            // setting up the card
            myCharge.Source = new StripeSourceOptions()
            {
                Object = "card",
                Number = creditcard.creditCardNumber,
                ExpirationMonth = creditcard.expiryDateMonth,
                ExpirationYear = creditcard.expiryDateYear,
                Cvc = creditcard.securityCode                          // optional
            };
            
            var chargeService = new StripeChargeService(StripeApiKey);
            StripeCharge apiResponse = chargeService.Create(myCharge);

            if(apiResponse.Paid == false)
            {
                throw new Exception(apiResponse.FailureMessage);
            }


           
            return apiResponse.Paid;
          


        }
コード例 #12
0
 public virtual async Task<StripeCharge> CreateAsync(StripeChargeCreateOptions createOptions, StripeRequestOptions requestOptions = null)
 {
     return Mapper<StripeCharge>.MapFromJson(
         await Requestor.PostStringAsync(this.ApplyAllParameters(createOptions, Urls.Charges, false),
         SetupRequestOptions(requestOptions))
     );
 }
コード例 #13
0
        public ActionResult Custom(CustomViewModel customViewModel)
        {
            customViewModel.PaymentFormHidden = false;
            var chargeOptions = new StripeChargeCreateOptions()
            {
                //required
                Amount = 3900,
                Currency = "usd",
                Source = new StripeSourceOptions() {TokenId= customViewModel.StripeToken},
                //optional
                Description = string.Format("JavaScript Framework Guide Ebook for {0}", customViewModel.StripeEmail),
                ReceiptEmail = customViewModel.StripeEmail
            };

            var chargeService = new StripeChargeService();

            try
            {
                var stripeCharge = chargeService.Create(chargeOptions);
            }
            catch (StripeException stripeException)
            {
                Debug.WriteLine(stripeException.Message);
                ModelState.AddModelError(string.Empty, stripeException.Message);
                return View(customViewModel);
            }

            return RedirectToAction("Confirmation");
        }
コード例 #14
0
ファイル: ChargeProvider.cs プロジェクト: yonglehou/saas-ecom
        /// <summary>
        /// Creates the charge.
        /// </summary>
        /// <param name="amount">The amount: A positive integer in the smallest currency unit (e.g 100 cents to charge $1.00, or 1 to charge ¥1, a 0-decimal currency) representing how much to charge the card. The minimum amount is $0.50 (or equivalent in charge currency).</param>
        /// <param name="currency">The currency: Three-letter ISO currency code representing the currency in which the charge was made.</param>
        /// <param name="description">The description: An arbitrary string which you can attach to a charge object. It is displayed when in the web interface alongside the charge. Note that if you use Stripe to send automatic email receipts to your customers, your receipt emails will include the description of the charge(s) that they are describing.</param>
        /// <param name="customerId">The customer identifier: The ID of an existing customer that will be charged in this request.</param>
        /// <param name="error">The error.</param>
        /// <returns></returns>
        public bool CreateCharge(int amount, string currency, string description, string customerId, out string error)
        {
            var options = new StripeChargeCreateOptions
            {
                Amount = amount,
                Currency = currency,
                Description = description
            };

            if (!string.IsNullOrEmpty(customerId))
            {
                options.CustomerId = customerId;
            }

            var result = _chargeService.Create(options);

            if (result.Captured != null && result.Captured.Value)
            {
                error = null;
                return true;
            }
            else
            {
                error = result.FailureMessage;
                return false;
            }
        }
コード例 #15
0
        public StripeCharge Create(StripeChargeCreateOptions createOptions)
        {
            var url = ParameterBuilder.ApplyAllParameters(createOptions, Urls.Charges);

            var response = Requestor.PostString(url);

            return PopulateStripeCharge(response);
        }
コード例 #16
0
        public StripeCharge Create(StripeChargeCreateOptions createOptions)
        {
            var url = ParameterBuilder.ApplyAllParameters(createOptions, Urls.Charges);

            var response = Requestor.PostString(url);

            return(PopulateStripeCharge(response));
        }
コード例 #17
0
 //Async
 public virtual async Task <StripeCharge> CreateAsync(StripeChargeCreateOptions createOptions, StripeRequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(Mapper <StripeCharge> .MapFromJson(
                await Requestor.PostStringAsync(this.ApplyAllParameters(createOptions, Urls.Charges, false),
                                                SetupRequestOptions(requestOptions),
                                                cancellationToken)
                ));
 }
コード例 #18
0
        public virtual StripeCharge Create(StripeChargeCreateOptions createOptions)
        {
            var url = this.ApplyAllParameters(createOptions, Urls.Charges, false);

            var response = Requestor.PostString(url, ApiKey);

            return(Mapper <StripeCharge> .MapFromJson(response));
        }
コード例 #19
0
		public virtual StripeCharge Create(StripeChargeCreateOptions createOptions)
		{
			var url = ParameterBuilder.ApplyAllParameters(createOptions, Urls.Charges);

			var response = Requestor.PostString(url, ApiKey);

			return Mapper.MapFromJson<StripeCharge>(response);
		}
コード例 #20
0
        public virtual StripeCharge Create(StripeChargeCreateOptions createOptions)
        {
            var url = ParameterBuilder.ApplyAllParameters(createOptions, Urls.Charges);

            var response = Requestor.PostString(url);

            return(Mapper <StripeCharge> .MapFromJson(response));
        }
コード例 #21
0
        public virtual StripeCharge Create(StripeChargeCreateOptions createOptions, StripeRequestOptions requestOptions = null)
        {
            requestOptions = SetupRequestOptions(requestOptions);

            var url = this.ApplyAllParameters(createOptions, Urls.Charges, false);

            var response = Requestor.PostString(url, requestOptions);

            return(Mapper <StripeCharge> .MapFromJson(response));
        }
コード例 #22
0
        public virtual StripeCharge Create(StripeChargeCreateOptions createOptions, StripeRequestOptions requestOptions = null)
        {
            requestOptions = SetupRequestOptions(requestOptions);

            var url = this.ApplyAllParameters(createOptions, Urls.Charges, false);

            var response = Requestor.PostString(url, requestOptions);

            return Mapper<StripeCharge>.MapFromJson(response);
        }
コード例 #23
0
        private void CreateCharge(Transaction t)
        {
            Stripe.Configuration.SetApiKey(Settings.StripeApiKey);

            var myCharge = new StripeChargeCreateOptions();
            
            // always set these properties
            myCharge.AmountInCents = (int)(t.Amount * 100);
            myCharge.Currency = Settings.CurrencyCode;
            
            // set this if you want to
            myCharge.Description = t.MerchantDescription;
            
            // set these properties if using a card
            myCharge.CardNumber = t.Card.CardNumber;
            myCharge.CardExpirationYear = t.Card.ExpirationYear.ToString();
            myCharge.CardExpirationMonth = t.Card.ExpirationMonthPadded;
            //myCharge.CardAddressCountry = "US";             // optional
            if (t.Customer.Street.Length > 0) myCharge.CardAddressLine1 = t.Customer.Street; // optional
            //myCharge.CardAddressLine2 = "Apt 24";           // optional
            //myCharge.CardAddressState = "NC";               // optional
            if (t.Customer.PostalCode.Length > 0) myCharge.CardAddressZip = t.Customer.PostalCode; // optional
            myCharge.CardName = t.Card.CardHolderName;      // optional
            if (t.Card.SecurityCode.Length > 0)
            {
                myCharge.CardCvc = t.Card.SecurityCode;     // optional
            }
            
            // set this property if using a customer
            //myCharge.CustomerId = *customerId*;
            
            // set this property if using a token
            //myCharge.TokenId = *tokenId*;
            
            var chargeService = new StripeChargeService();
            
            StripeCharge stripeCharge = chargeService.Create(myCharge);

            if (stripeCharge.Id.Length > 0 &&
                stripeCharge.AmountInCents.HasValue && stripeCharge.AmountInCents > 0)
            {
                t.Result.Succeeded = true;
                t.Result.ReferenceNumber = stripeCharge.Id;
            }
            else
            {
                    
            }
            {
                t.Result.Succeeded = false;
                t.Result.ResponseCode = "FAIL";
                t.Result.ResponseCodeDescription = "Stripe Failure";
            }
            
        }
コード例 #24
0
        protected void Page_Load(object sender, EventArgs e)
        {

            #region Working....

            var myCharge = new StripeChargeCreateOptions
            {
                Amount =(int) (29.99 *100),
                Currency = "usd",
                Description = "Charge it like it's hot 2",
                Source = new StripeSourceOptions()
                {
                    // set this property if using a token


                    // set these properties if passing full card details (do not
                    // set these properties if you set TokenId)
                    Object = "card",
                    Number = "4242424242424242",
                    ExpirationYear = "2022",
                    ExpirationMonth = "10",
                    AddressCountry = "US", // optional
                    AddressLine1 = "24 Beef Flank St", // optional
                    AddressLine2 = "Apt 24", // optional
                    AddressCity = "Biggie Smalls", // optional
                    AddressState = "NC", // optional
                    AddressZip = "27617", // optional
                    Name = "Joe Meatballs 2", // optional
                    Cvc = "1223" // optional
                },
                //ApplicationFee = 25,
                Capture = true
            };

            // always set these properties

            // set this if you want to

            // setting up the card

            //set this property if using a customer
            //myCharge.CustomerId = "postman2021";

            // set this if you have your own application fees (you must have your application configured first within Stripe)

            // (not required) set this to false if you don't want to capture the charge yet - requires you call capture later

            var chargeService = new StripeChargeService(ConfigurationManager.AppSettings["StripeApiKey"]);
            var stripeCharge = chargeService.Create(myCharge);
            

            #endregion Working....
        }
コード例 #25
0
        public ActionResult Custom(CustomViewModel customViewModel)
        {
            customViewModel.PaymentFormHidden = false;
            var chargeOptions = new StripeChargeCreateOptions()
            {
                //required
                Amount = 3900,
                Currency = "usd",
                Source = new StripeSourceOptions() { TokenId = customViewModel.StripeToken },
                //optional
                Description = string.Format("JavaScript Framework Guide Ebook for {0}", customViewModel.StripeEmail),
                ReceiptEmail = customViewModel.StripeEmail
            };

            var chargeService = new StripeChargeService();

            try
            {
                StripeCharge stripeCharge = chargeService.Create(chargeOptions);

                //Validate charge
                chargeService.Capture(stripeCharge.Id);

                if (stripeCharge.Status == "succeeded")
                {
                    //creating the customer and add it to stripe
                    var newCustomer = new StripeCustomerService().Create(
                        new StripeCustomerCreateOptions
                        {
                            Email = customViewModel.StripeEmail
                        }
                        );
                    // CREATE NEW INVOICE
                    // var invoiceService = new StripeInvoiceService();
                    // StripeInvoice response = invoiceService.Create(newCustomer.Id); // optional StripeInvoiceCreateOptions
                    //var response = invoiceService.Upcoming(newCustomer.Id);
                    // stripeCharge.InvoiceId = response.Id;

                    //SEND THE CONFIRMATION
                    var emailService = new EmailService();
                    emailService.SendPaymentReceivedFromChargeEmail(stripeCharge);

                }
            }
            catch (StripeException stripeException)
            {
                Debug.WriteLine(stripeException.Message);
                ModelState.AddModelError(string.Empty, stripeException.Message);
                return View(customViewModel);
            }

            return RedirectToAction("Confirmation");
        }
コード例 #26
0
        public virtual StripeCharge Create(StripeChargeCreateOptions createOptions, StripeRequestOptions requestOptions = null)
        {
            requestOptions = SetupRequestOptions(requestOptions);

            var url = this.ApplyAllParameters(createOptions, Urls.Charges, false);
            if (createOptions.Source != null)
                url = ParameterBuilder.ApplyNestedObjectProperties(url, createOptions.Source);
            else
                url = ParameterBuilder.ApplyParameterToUrl(url, "source", createOptions.SourceId);

            var response = Requestor.PostString(url, requestOptions);

            return Mapper<StripeCharge>.MapFromJson(response);
        }
コード例 #27
0
        public HttpResponseMessage Post(StripeOrderDto order)
        {
            var confirmationNumber = GetConfirmationNumber();

            var charge = new StripeChargeCreateOptions
            {
                Amount = 2999,
                Currency = "usd",
                Description = "Test",
                SourceTokenOrExistingSourceId = order.StripeToken,
                Capture = true
            };

            var chargeService = new StripeChargeService();
            var stripeCharge = chargeService.Create(charge);

            var orderEntity = new Order()
            {
                ConfirmationNumber = confirmationNumber,
                BillingAddressCity = order.StripeBillingAddressCity,
                BillingAddressCountry = order.StripeBillingAddressCountry,
                BillingAddressCountryCode = order.StripeBillingAddressCountryCode,
                BillingAddressLine1 = order.StripeBillingAddressLine1,
                BillingAddressLine2 = order.StripeBillingAddressLine2,
                BillingAddressState = order.StripeBillingAddressState,
                BillingAddressZip = order.StripeBillingAddressZip,
                BillingName = order.StripeBillingName,
                Email = order.StripeEmail,
                Fulfilled = false,
                ShippingAddressCity = order.StripeShippingAddressCity,
                ShippingAddressCountry = order.StripeShippingAddressCountry,
                ShippingAddressCountryCode = order.StripeShippingAddressCountryCode,
                ShippingAddressLine1 = order.StripeShippingAddressLine1,
                ShippingAddressLine2 = order.StripeShippingAddressLine2,
                ShippingAddressState = order.StripeShippingAddressState,
                ShippingAddressZip = order.StripeShippingAddressZip,
                ShippingName = order.StripeShippingName,
                Token = stripeCharge.Id
            };

            _orderRepository.Insert(orderEntity);

            var response = Request.CreateResponse(HttpStatusCode.Moved);
            var uri = Request.RequestUri.AbsoluteUri.Replace(Request.RequestUri.AbsolutePath, "/Confirmation/Details/" + confirmationNumber);
            response.Headers.Location = new Uri(uri);
            return response;
        }
        public async Task<string> ExecuteTransaction(string stripeToken, string stripeSecretKey, int amount)
        {
            var chargeOptions = new StripeChargeCreateOptions()
            {
                Amount = amount,
                Currency = "AUD",
                SourceTokenOrExistingSourceId = stripeToken
            };

            var client = new StripeChargeService(stripeSecretKey);
            var result = await client.CreateAsync(chargeOptions);

            if (!result.Paid)
            {
                throw new Exception(result.FailureMessage);
            }

            return result.Id;
        }
コード例 #29
0
        public ActionResult Index(HomeViewModel model)
        {
            // Stripe charge logic
            StripeChargeService chargeService = new StripeChargeService(AppConfig.stripePrivateKey);
            StripeChargeCreateOptions myCharge = new StripeChargeCreateOptions()
            {
                Currency = "aud",
                Description = model.cardDetails.description,
                Amount = model.cardDetails.price,
                Source = new StripeSourceOptions()
                {
                    TokenId = model.cardDetails.stripeToken
                }
            };
            StripeCharge stripeCharge = chargeService.Create(myCharge);

            model.transactions = GetTransactions();

            return View(model);
        }
コード例 #30
0
        private async Task<string> ProcessPayment(StripeChargeModel model)
        {
            return await Task.Run(() =>
            {
                var myCharge = new StripeChargeCreateOptions
                {
                    // convert the amount of £12.50 to pennies i.e. 1250
                    Amount = (int)(model.Amount * 100),
                    Currency = "gbp",
                    Description = "Description for test charge",
                    Source = new StripeSourceOptions{
                        TokenId = model.Token
                    }
                };

                var chargeService = new StripeChargeService("your private key here");
                var stripeCharge = chargeService.Create(myCharge);

                return stripeCharge.Id;
           });
        }
コード例 #31
0
        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.CreditCardNumber,
                ExpirationMonth = creditCard.ExpiryDate.Month.ToString(),
                ExpirationYear = creditCard.ExpiryDate.Year.ToString(),
                Cvc = creditCard.CVC
            };

            var chargeService = new StripeChargeService(StripeApiKey);
            var response = chargeService.Create(chargeDetails);

            return response.Paid;
        }
コード例 #32
0
        public static string ChargeCustomer(paymentrequestforcharge objchargereq)
        {
            var myCharge = new StripeChargeCreateOptions();
            // always set these properties
            myCharge.Amount = ConvertToCents(objchargereq.amount);
            myCharge.Currency = "usd";

            // set this if you want to
            myCharge.Description = objchargereq.description;

            // setting up the card
            // setting up the card
            myCharge.Source = new StripeSourceOptions
            {
                TokenId = objchargereq.tokenid
            };

            var chargeService = new StripeChargeService();
            StripeCharge stripeCharge = chargeService.Create(myCharge);

            return stripeCharge.Id;
        }
コード例 #33
0
        public void Charge(string username, SubscriptionChargeDto subscriptionChargeDto)
        {
            var chargeOptions = new StripeChargeCreateOptions()
            {
                Amount = 18000,
                Currency = "cad",
                Source = new StripeSourceOptions() {  TokenId = subscriptionChargeDto.Token },
                Description = "Membership Payment",
                ReceiptEmail = username
            };

            var chargeService = new StripeChargeService();
            var stripeCharge = chargeService.Create(chargeOptions);

            var user = uow.Users.GetAll()
                .Include(x => x.Accounts)
                .Include("Accounts.Profiles")
                .Single(x => x.Username == username);
            var account = user.Accounts.First();
            account.AccountStatus = AccountStatus.Paid;
            uow.SaveChanges();
        }
コード例 #34
0
        public async Task<string> ProcessPayment(IStripeTransaction transaction, string currency, string privateKey)
        {
            return await Task.Run(() =>
            {
                var myCharge = new StripeChargeCreateOptions
                {
                    Amount = (int)(transaction.Amount * 100),
                    Currency = currency,
                    Description = "",
                    Source = new StripeSourceOptions
                    {
                        TokenId = transaction.Token
                    }
                };

                var chargeService = new StripeChargeService(privateKey);
                var stripeCharge = chargeService.Create(myCharge);

                return stripeCharge.Id;

            });

        }
コード例 #35
0
 public virtual StripeCharge Create(StripeChargeCreateOptions createOptions, StripeRequestOptions requestOptions = null)
 {
     return CreateAsync(createOptions, requestOptions).Result;
 }
コード例 #36
0
ファイル: Stripe.cs プロジェクト: jizepi/Payment-providers
        public override CallbackInfo ProcessCallback( Order order, HttpRequest request, IDictionary<string, string> settings )
        {
            CallbackInfo callbackInfo = null;

              try {
            order.MustNotBeNull( "order" );
            request.MustNotBeNull( "request" );
            settings.MustNotBeNull( "settings" );
            settings.MustContainKey( "mode", "settings" );
            settings.MustContainKey( settings[ "mode" ] + "_secret_key", "settings" );

            // If in test mode, write out the form data to a text file
            if ( settings.ContainsKey( "mode" ) && settings[ "mode" ] == "test" ) {
              LogRequest( request, logPostData: true );
            }

            StripeChargeCreateOptions chargeOptions = new StripeChargeCreateOptions {
              AmountInCents = (int)( order.TotalPrice.Value.WithVat * 100 ),
              Currency = CurrencyService.Instance.Get( order.StoreId, order.CurrencyId ).IsoCode,
              TokenId = request.Form[ "stripeToken" ],
              Description = order.CartNumber,
              Capture = settings.ContainsKey( "capture" ) && ( settings[ "capture" ].TryParse<bool>() ?? false )
            };

            StripeChargeService chargeService = new StripeChargeService( settings[ settings[ "mode" ] + "_secret_key" ] );
            StripeCharge charge = chargeService.Create( chargeOptions );

            if ( charge.AmountInCents != null && charge.Paid != null && charge.Paid.Value ) {
              callbackInfo = new CallbackInfo( (decimal)charge.AmountInCents.Value / 100, charge.Id, charge.Captured != null && charge.Captured.Value ? PaymentState.Captured : PaymentState.Authorized );

            }

              } catch ( StripeException e ) {
            // Pass through request fields
            string requestFields = string.Join( "", request.Form.AllKeys.Select( k => "<input type=\"hidden\" name=\"" + k + "\" value=\"" + request.Form[ k ] + "\" />" ) );

            //Add error details from the exception.
            requestFields = requestFields + "<input type=\"hidden\" name=\"TransactionFailed\" value=\"true\" />";
            requestFields = requestFields + "<input type=\"hidden\" name=\"FailureReason.chargeId\" value=\"" + e.StripeError.ChargeId + "\" />";
            requestFields = requestFields + "<input type=\"hidden\" name=\"FailureReason.Code\" value=\"" + e.StripeError.Code + "\" />";
            requestFields = requestFields + "<input type=\"hidden\" name=\"FailureReason.Error\" value=\"" + e.StripeError.Error + "\" />";
            requestFields = requestFields + "<input type=\"hidden\" name=\"FailureReason.ErrorSubscription\" value=\"" + e.StripeError.ErrorSubscription + "\" />";
            requestFields = requestFields + "<input type=\"hidden\" name=\"FailureReason.ErrorType\" value=\"" + e.StripeError.ErrorType + "\" />";
            requestFields = requestFields + "<input type=\"hidden\" name=\"FailureReason.Message\" value=\"" + e.StripeError.Message + "\" />";
            requestFields = requestFields + "<input type=\"hidden\" name=\"FailureReason.Parameter\" value=\"" + e.StripeError.Parameter + "\" />";

            string paymentForm = PaymentMethodService.Instance.Get( order.StoreId, order.PaymentInformation.PaymentMethodId.Value ).GeneratePaymentForm( order, requestFields );

            //Force the form to auto submit
            paymentForm += "<script type=\"text/javascript\">document.forms[0].submit();</script>";

            //Write out the form
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write( paymentForm );
            HttpContext.Current.Response.End();
              } catch ( Exception exp ) {
            LoggingService.Instance.Log( exp, "Stripe(" + order.CartNumber + ") - ProcessCallback" );
              }

              return callbackInfo;
        }