Exemplo n.º 1
0
        public async Task <string> ChargeCustomer(CreditCardOptions card,
                                                  decimal amount, string currency, string description)
        {
            var tokenId = GetTokenId(null, card).Result;
            var options = new RequestOptions
            {
                ApiKey = Keys.PrivateKey
            };

            return(await Task.Run(() =>
            {
                var myCharge = new ChargeCreateOptions
                {
                    Amount = (long)(amount * 100),
                    Currency = currency,
                    Description = description,
                    //Currency = "gbp",
                    //Description = "Charge for property sign and postage",
                    Source = tokenId
                };

                var chargeService = new ChargeService();
                var stripeCharge = chargeService.Create(myCharge, options);

                return stripeCharge.Id;
            }));
        }
Exemplo n.º 2
0
        public static Token CreateToken(CreditCardOptions cardDetails = null)
        {
            TokenService       serviceToken = new TokenService();
            TokenCreateOptions token        = new TokenCreateOptions {
                Card = cardDetails
            };

            return(serviceToken.Create(token));
        }
Exemplo n.º 3
0
 private Token CreateToken(CreditCardOptions card)
 {
     //Assign Card to Token Object and create Token
     Stripe.TokenCreateOptions token = new Stripe.TokenCreateOptions();
     token.Card = card;
     Stripe.TokenService serviceToken = new Stripe.TokenService();
     Stripe.Token        newToken     = serviceToken.Create(token);
     return(newToken);
 }
Exemplo n.º 4
0
        public async Task <OrderModel> PayAsync(PaymentModel model)
        {
            StripeConfiguration.ApiKey = _key;

            var card = new CreditCardOptions
            {
                Number   = model.CardNumber,
                ExpMonth = model.Month,
                ExpYear  = model.Year,
                Cvc      = model.CVC
            };

            var optionsToken = new TokenCreateOptions
            {
                Card = card
            };

            var serviceToken = new Stripe.TokenService();
            var stripeToken  = await serviceToken.CreateAsync(optionsToken);


            var options = new ChargeCreateOptions
            {
                Amount      = model.Value * Constants.Numbers.CONVERT_TO_PRICE,
                Currency    = CurrencyType.USD.ToString(),
                Description = model.Description,
                Source      = stripeToken.Id
            };


            var service = new ChargeService();
            var charge  = await service.CreateAsync(options);


            var payment = await _orderRepository.GetPaymentByOrderIdAsync(model.OrderId);

            payment.TransactionId = charge.Id;

            await _paymentRepository.UpdateAsync(payment);

            var order = await _orderRepository.GetOrderByIdAsync(model.OrderId);

            order.Description = model.Description;
            order.Status      = StatusType.Paid;

            await _orderRepository.UpdateAsync(order);

            if (!charge.Paid)
            {
                throw new ServerException(Constants.Success.UNPAID_ORDER);
            }

            var orderModel = _mapper.Map <OrderModel>(order);

            return(orderModel);
        }
Exemplo n.º 5
0
        public PaymentResultModel ProcessPayment(BasicRequestModel requestModel)
        {
            var result = new PaymentResultModel();

            var paymentData = (StripeBasicRequestModel)requestModel;
            var tokenId     = paymentData.TokenId;

            if (string.IsNullOrWhiteSpace(tokenId))
            {
                var card = new CreditCardOptions
                {
                    Number   = paymentData.CreditCard.cardNumber,
                    ExpYear  = paymentData.CreditCard.ExpiryYear,
                    ExpMonth = paymentData.CreditCard.ExpiryMonth,
                    Cvc      = paymentData.CreditCard.cardCVV
                };

                tokenId = GetTokenId(null, card).Result;
            }

            var options = new RequestOptions
            {
                ApiKey = Keys.PrivateKey
            };

            var myCharge = new ChargeCreateOptions
            {
                Amount      = (long)(paymentData.Amount * 100),
                Currency    = paymentData.Currency.ToString().ToLower(),
                Description = paymentData.Description,
                Source      = tokenId
            };

            var chargeService = new ChargeService();
            var stripeCharge  = chargeService.Create(myCharge, options);

            result = new PaymentResultModel
            {
                Success        = true,
                Message        = "Payment success. ",
                Approved       = stripeCharge.Status == "succeeded",
                AuthCode       = stripeCharge.AuthorizationCode,
                CardToken      = tokenId,
                FailureCode    = stripeCharge.FailureCode,
                FailureMessage = stripeCharge.FailureMessage,
                TransactionId  = stripeCharge.Id,
                Data           = stripeCharge
            };

            return(result);
        }
        public CreditCardDto(CreditCardOptions creditCard)
        {
            if (creditCard == null)
            {
                return;
            }

            MailOrderTelephoneOrder       = creditCard.MailOrderTelephoneOrder;
            RejectAuthenticationStatusA   = creditCard.RejectAuthenticationStatusA;
            RejectAuthenticationStatusU   = creditCard.RejectAuthenticationStatusU;
            RejectCardNot3DSecureEnrolled = creditCard.RejectCardNot3DSecureEnrolled;
            RejectConsumerCards           = creditCard.RejectConsumerCards;
            RejectCorporateCards          = creditCard.RejectCorporateCards;
            RejectCreditCards             = creditCard.RejectCreditCards;
            RejectDebitCards = creditCard.RejectDebitCards;
        }
Exemplo n.º 7
0
        //public static CreditCardOptions CreateCard()
        //{
        //    return new CreditCardOptions
        //    {
        //        Name = "Jane DOe",
        //        Number = "4242424242424242",
        //        ExpYear = 2025,
        //        ExpMonth = 7,
        //        Cvc = "000"
        //    };
        //}

        public static Customer CreateCustomer(string email, CreditCardOptions cardOptions = null)
        {
            Token token = null;

            if (cardOptions != null)
            {
                token = CreateToken(cardOptions);
            }

            CustomerCreateOptions myCustomer = new CustomerCreateOptions
            {
                Email  = email,
                Source = token?.Id,
            };

            var customerService = new CustomerService();

            return(customerService.Create(myCustomer));
        }
Exemplo n.º 8
0
        public async Task <string> GetTokenId(BankAccountOptions bankAccount, CreditCardOptions card)
        {
            return(await Task.Run(() =>
            {
                var myToken = new TokenCreateOptions
                {
                    BankAccount = bankAccount,
                    Card = card
                           //BankAccount = new BankAccountOptions { },
                           //Card = new CreditCardOptions
                           //{
                           //    Number = "4242424242424242",
                           //    ExpYear = 2020,
                           //    ExpMonth = 6,
                           //    Cvc = "123"
                           //}
                };

                var tokenService = new TokenService();
                var stripeToken = tokenService.Create(myToken);

                return stripeToken.Id;
            }));
        }
Exemplo n.º 9
0
 public Orchestrator(CreditCardOptions cardOptions, Customer customer)
 {
     this.cardOptions   = cardOptions;
     this.customer      = customer;
     this.chargeOptions = CreateCharge();
 }
        /// <summary>
        /// Gets the value displayed in one of the grid columns.
        /// Default returns boolean as text, CardTypes and Actions return option lists.
        /// </summary>
        /// <param name="gridCol"></param>
        /// <param name="name">Name of merchant gateway</param>
        /// <returns></returns>
        public string GetGridValue(GridColumns gridCol, string name)
        {
            string value = string.Empty;
            string xPath = ComposeGridLocator(gridCol, name);

            switch (gridCol)
            {
                case GridColumns.Description:
                case GridColumns.Gateway:
                case GridColumns.Currency:
                case GridColumns.ModifiedBy:
                case GridColumns.LastModified:
                    value = UIUtil.DefaultProvider.GetText(xPath, LocateBy.XPath);
                    break;
                case GridColumns.Default:
                    value = UIUtil.DefaultProvider.IsElementPresent(xPath + "/img[@id='imgDefaultGateway']", LocateBy.XPath).ToString();
                    break;
                case GridColumns.CardTypes:
                    CreditCardOptions ccOptions = new CreditCardOptions();
                    ccOptions.Visa = IsVerifiedCC(CCTypes.Visa, name);
                    ccOptions.Mastercard = IsVerifiedCC(CCTypes.Mastercard, name);
                    ccOptions.Amex = IsVerifiedCC(CCTypes.Amex, name);
                    ccOptions.Discover = IsVerifiedCC(CCTypes.Discover, name);
                    ccOptions.Diners = IsVerifiedCC(CCTypes.Diners, name);
                    ccOptions.Switch = IsVerifiedCC(CCTypes.Switch, name);
                    value = ccOptions.ToString();
                    break;
                case GridColumns.Actions:
                    GridActionOptions actionOptions = new GridActionOptions();
                    actionOptions.VerifyCC = IsActionPresent(GridActions.VerifyCC, name);
                    actionOptions.Delete = IsActionPresent(GridActions.Delete, name);
                    actionOptions.AdminDelete = IsActionPresent(GridActions.AdminDelete, name);
                    value = actionOptions.ToString();
                    break;
            }

            return value;
        }
Exemplo n.º 11
0
 /// <summary>
 /// Insttanciates a <see cref="PaymentOrderPaymentOptionsItems"/> with the provided parameters.
 /// </summary>
 /// <param name="creditCard">Credit card options.</param>
 /// <param name="invoice">Invoice options.</param>
 /// <param name="swish">Swish options.</param>
 public PaymentOrderPaymentOptionsItems(CreditCardOptions creditCard, Invoice invoice, Swish swish)
 {
     CreditCard = creditCard;
     Invoice    = invoice;
     Swish      = swish;
 }
        public ResponseModel Payment(PaymentModel paymentModel)
        {
            ResponseModel response = new ResponseModel();

            try
            {
                CreditCardOptions card = new CreditCardOptions();
                card.Name           = "Rafeal Esteves"; // For indian account it's neccessary
                card.AddressCity    = "LA";
                card.AddressState   = "CA";
                card.AddressCountry = "United States";
                card.AddressLine1   = "5765 Valley Ave Suite 100";
                card.AddressZip     = "94566";
                var stripekey = configuration.GetValue <string>("Stripe:secretkey");
                StripeConfiguration.ApiKey = stripekey;
                //card.Number = model.card;
                card.Number = paymentModel.card;
                string   str    = Convert.ToString(paymentModel.ExpiryDetail);
                string[] tokens = str.Split("/");
                card.ExpMonth = Convert.ToInt64(tokens[0]);
                card.ExpYear  = Convert.ToInt64(tokens[1]);
                card.Cvc      = paymentModel.Cvc;
                //Assign Card to Token Object and create Token
                TokenCreateOptions token = new TokenCreateOptions();
                token.Card = card;
                TokenService serviceToken = new TokenService();
                Token        newToken     = serviceToken.Create(token);

                //Create Customer Object and Register it on Stripe
                CustomerCreateOptions myCustomer = new CustomerCreateOptions();
                myCustomer.Email  = paymentModel.Email;
                myCustomer.Source = newToken.Id;
                var      customerService = new CustomerService();
                Customer stripeCustomer  = customerService.Create(myCustomer);

                //Create Charge Object with details of Charge
                var options = new ChargeCreateOptions();
                options.Amount       = Convert.ToInt64(paymentModel.BookingAmount) * 100;//options.Amount = Convert.ToInt64("1");
                options.Currency     = configuration.GetValue <string>("Currency");;
                options.ReceiptEmail = paymentModel.Email;
                options.Customer     = stripeCustomer.Id;
                options.Description  = paymentModel.InstructionMessage;
                options.Capture      = false;

                //and Create Method of this object is doing the payment execution.
                var service = new ChargeService();

                var charge = service.Create(options); // This will do the Payment


                if (charge.Status == "succeeded")
                {
                    response.data       = true;
                    response.StatusCode = Constants.StatusCodes.Success;
                    response.Message    = Constants.Messages.PAYMENT_SUCCESSFULL;
                }
                else
                {
                    response.data       = false;
                    response.StatusCode = Constants.StatusCodes.InternalServerError;
                    response.Message    = Constants.Messages.SOMETHING_WENT_WRONG;
                }
                return(response);
            }catch (StripeException ex)
            {
                response.Message    = ex.Message;
                response.data       = null;
                response.StatusCode = Constants.StatusCodes.InternalServerError;
                return(response);
            }
        }
        public void PayViaStripe()
        {
            StripeConfiguration.ApiKey = "sk_test_LJ2dJvulsi1f4rsGrqLHCKGC*****";

            string cardno   = cardNo.Text;
            string expMonth = expireMonth.Text;
            string expYear  = expireYear.Text;
            string cardCvv  = cvv.Text;

            // Step 1: create card option

            CreditCardOptions stripeOption = new CreditCardOptions();

            stripeOption.Number   = cardno;
            stripeOption.ExpYear  = Convert.ToInt64(expYear);
            stripeOption.ExpMonth = Convert.ToInt64(expMonth);
            stripeOption.Cvc      = cardCvv;

            // step 2: Assign card to token object
            TokenCreateOptions stripeCard = new TokenCreateOptions();

            stripeCard.Card = stripeOption;

            TokenService service  = new TokenService();
            Token        newToken = service.Create(stripeCard);

            // step 3: assign the token to the source
            var option = new SourceCreateOptions
            {
                Type     = SourceType.Card,
                Currency = "inr",
                Token    = newToken.Id
            };

            var    sourceService = new SourceService();
            Source source        = sourceService.Create(option);

            // step 4: create customer
            CustomerCreateOptions customer = new CustomerCreateOptions
            {
                Name        = "SP Tutorial",
                Email       = "*****@*****.**",
                Description = "Paying 10 Rs",
                Address     = new AddressOptions {
                    City = "Kolkata", Country = "India", Line1 = "Sample Address", Line2 = "Sample Address 2", PostalCode = "700030", State = "WB"
                }
            };

            var customerService = new CustomerService();
            var cust            = customerService.Create(customer);

            // step 5: charge option
            var chargeoption = new ChargeCreateOptions
            {
                Amount       = 45000,
                Currency     = "INR",
                ReceiptEmail = "*****@*****.**",
                Customer     = cust.Id,
                Source       = source.Id
            };

            // step 6: charge the customer
            var    chargeService = new ChargeService();
            Charge charge        = chargeService.Create(chargeoption);

            if (charge.Status == "succeeded")
            {
                // success
            }
            else
            {
                // failed
            }
        }