Пример #1
0
        private StripeCustomer createTCGStripeCustomer(StorePaymentMethod_Details details, string sourceToken)
        {
            StripeConfiguration.SetApiKey(secretKey);
            StripeCustomer customer = new StripeCustomer();

            try
            {
                StripeSource source = new StripeSource();
                if (sourceToken == null)
                {
                    source = createStripeSource(details.CardNumber, details.CardExpiryYear, details.CardExpiryMonth, details.CardCVV, details.CardHolderFullName, true);
                }
                else
                {
                    source.Id = sourceToken;
                }
                //ATTACH THE SOURCE TO CUSTOMER
                var customerOptions = new StripeCustomerCreateOptions()
                {
                    SourceToken = source.Id
                };

                var customerService = new StripeCustomerService();
                customer = customerService.Create(customerOptions);
            }
            catch (StripeException e)
            {
                throw new StripeException(e.HttpStatusCode, e.StripeError, e.Message);
            }
            return(customer);
        }
Пример #2
0
        public sources_fixture()
        {
            SourceCreateOptions = new StripeSourceCreateOptions
            {
                Type     = StripeSourceType.AchCreditTransfer,
                Currency = "usd",
                Owner    = new StripeSourceOwner
                {
                    Email      = "*****@*****.**",
                    CityOrTown = "Mayberry",
                    State      = "NC"
                }
            };

            SourceUpdateOptions = new StripeSourceUpdateOptions
            {
                Owner = new StripeSourceOwner
                {
                    Email = "*****@*****.**"
                }
            };

            var service = new StripeSourceService(Cache.ApiKey);

            Source          = service.Create(SourceCreateOptions);
            SourceUpdated   = service.Update(Source.Id, SourceUpdateOptions);
            SourceRetrieved = service.Get(Source.Id);
        }
        public static StripeSource CreateSource(string token, int amount, string redirectUrl)
        {
            StripeConfiguration.SetApiKey(MasterStrings.StripeSecretKey);

            var sourceOptions = new StripeSourceCreateOptions
            {
                Amount   = amount,
                Currency = "gbp",
                Type     = "three_d_secure",
                ThreeDSecureCardOrSourceId = token,
                RedirectReturnUrl          = redirectUrl
            };

            var sourceService = new StripeSourceService();

            try
            {
                StripeSource source = sourceService.Create(sourceOptions);

                return(source);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Пример #4
0
        public sources_fixture()
        {
            SourceCreateOptions = new StripeSourceCreateOptions
            {
                Type     = StripeSourceType.Bitcoin,
                Amount   = 1,
                Currency = "usd",
                Owner    = new StripeSourceOwner
                {
                    Email      = "*****@*****.**",
                    CityOrTown = "Mayberry",
                    State      = "NC"
                }
            };

            SourceUpdateOptions = new StripeSourceUpdateOptions
            {
                Owner = new StripeSourceOwner
                {
                    Email = "*****@*****.**"
                }
            };

            var service = new StripeSourceService(Cache.ApiKey);

            Source          = service.Create(SourceCreateOptions);
            SourceUpdated   = service.Update(Source.Id, SourceUpdateOptions);
            SourceRetrieved = service.Get(Source.Id);
        }
        public attaching_and_detaching_sources()
        {
            var SourceCardCreateOptions = new StripeSourceCreateOptions
            {
                Type  = StripeSourceType.Card,
                Token = "tok_visa"
            };

            var CustomerCreateOptions = new StripeCustomerCreateOptions
            {
                Email = "*****@*****.**",
            };

            var sourceService   = new StripeSourceService(Cache.ApiKey);
            var customerService = new StripeCustomerService(Cache.ApiKey);

            var SourceCard = sourceService.Create(SourceCardCreateOptions);

            Customer = customerService.Create(CustomerCreateOptions);

            var SourceAttachOptions = new StripeSourceAttachOptions
            {
                Source = SourceCard.Id
            };

            SourceAttached = sourceService.Attach(Customer.Id, SourceAttachOptions);
            SourceDetached = sourceService.Detach(Customer.Id, SourceAttached.Id);
        }
Пример #6
0
        public creating_three_d_secure_source()
        {
            var sourceCreateOptions = new StripeSourceCreateOptions
            {
                Type              = StripeSourceType.Card,
                Amount            = 1234,
                Currency          = "eur",
                RedirectReturnUrl = "http://no.where/webhooks",
                Card              = new StripeCreditCardOptions
                {
                    // Using PAN as we don't have a 3DS test token yet
                    Number          = "4000000000003063",
                    ExpirationMonth = 12,
                    ExpirationYear  = 2020
                }
            };

            var threeDSCreateOptions = new StripeSourceCreateOptions
            {
                Type              = StripeSourceType.ThreeDSecure,
                Amount            = 8675309,
                Currency          = "eur",
                RedirectReturnUrl = "http://no.where/webhooks",
            };

            var sourceService   = new StripeSourceService(Cache.ApiKey);
            var customerService = new StripeCustomerService(Cache.ApiKey);

            Customer = customerService.Create(new StripeCustomerCreateOptions {
            });

            Source = sourceService.Create(sourceCreateOptions);
            threeDSCreateOptions.ThreeDSecureCardOrSourceId = Source.Id;
            ThreeDSecure = sourceService.Create(threeDSCreateOptions);

            SourceCustomer = sourceService.Create(sourceCreateOptions);
            var SourceAttachOptions = new StripeSourceAttachOptions
            {
                Source = SourceCustomer.Id
            };

            sourceService.Attach(Customer.Id, SourceAttachOptions);

            threeDSCreateOptions.ThreeDSecureCardOrSourceId = SourceCustomer.Id;
            threeDSCreateOptions.ThreeDSecureCustomer       = Customer.Id;
            ThreeDSecureCustomer = sourceService.Create(threeDSCreateOptions);


            // from here, you have to go to the threeDSecure.Redirect.Url and click success

            //var charge = new StripeChargeService(Cache.ApiKey).Create(
            //    new StripeChargeCreateOptions
            //    {
            //        Amount = 8675309,
            //        Currency = "eur",
            //        SourceTokenOrExistingSourceId = threeDSecure.Id
            //    }
            //);
        }
Пример #7
0
        public creating_reusable_card_source()
        {
            var options = new StripeSourceCreateOptions
            {
                Type  = StripeSourceType.Card,
                Usage = StripeSourceUsage.Reusable,
                Token = "tok_visa",
            };

            Source = new StripeSourceService(Cache.ApiKey).Create(options);
        }
 public StripeSource GetStripeSource3d(StripeSource source, string redirectUrl)
 {
     return(_stripeSourceService.Create(new StripeSourceCreateOptions()
     {
         Amount = source.Amount,
         Type = "three_d_secure",
         Currency = source.Currency,
         ThreeDSecureCardOrSourceId = source.Id,
         RedirectReturnUrl = redirectUrl, //,
     }));
 }
        public static StripeOutcome ChargeSource(string source, bool livemode, string client_secret, long id, string idType)
        {
            // Set your secret key: remember to change this to your live secret key in production
            // See your keys here: https://dashboard.stripe.com/account/apikeys
            StripeConfiguration.SetApiKey(MasterStrings.StripeSecretKey);

            var          service       = new StripeSourceService();
            StripeSource sourceService = service.Get(source);

            if (sourceService.Status == "chargeable")
            {
                var options = new StripeChargeCreateOptions
                {
                    Amount   = sourceService.Amount,
                    Currency = sourceService.Currency,
                    SourceTokenOrExistingSourceId = source,
                    Description = "Charge for Order Id " + id.ToString(),
                    Metadata    = new Dictionary <String, String>()
                    {
                        { idType, id.ToString() }
                    }
                };

                var serviceCharge = new StripeChargeService();

                try
                {
                    StripeCharge charge = serviceCharge.Create(options);

                    if (charge.Outcome.Reason == "approve_with_id" || charge.Outcome.Reason == "issuer_not_available" ||
                        charge.Outcome.Reason == "processing_error" || charge.Outcome.Reason == "reenter_transaction" ||
                        charge.Outcome.Reason == "try_again_later")
                    {
                        charge = serviceCharge.Create(options);
                    }

                    charge.Outcome.Id = charge.Id;
                    return(charge.Outcome);
                }
                catch (Exception ex)
                {
                    throw new StripeException(ex.Message);
                }
            }

            return(new StripeOutcome()
            {
                NetworkStatus = MasterStrings.StripeNotSent,
                SellerMessage = "Card not yet chargeable.",
                Type = "pending"
            });
        }
Пример #10
0
        public creating_and_updating_card_source()
        {
            var options = new StripeSourceCreateOptions
            {
                Type              = StripeSourceType.Card,
                Amount            = 100,
                Currency          = "usd",
                Token             = Cache.GetToken().Id,
                RedirectReturnUrl = "http://no.where/webhooks"
            };

            Source = new StripeSourceService(Cache.ApiKey).Create(options);
        }
Пример #11
0
        public creating_and_updating_ideal_source()
        {
            var options = new StripeSourceCreateOptions
            {
                Type      = StripeSourceType.Ideal,
                IdealBank = "ing",
                IdealStatementDescriptor = "finished",
                Amount            = 1,
                Currency          = "eur",
                RedirectReturnUrl = "http://no.where/webhooks"
            };

            Source = new StripeSourceService(Cache.ApiKey).Create(options);
        }
Пример #12
0
        public creating_and_updating_sofort_source()
        {
            var options = new StripeSourceCreateOptions
            {
                Type                      = StripeSourceType.Sofort,
                SofortCountry             = "DE",
                SofortStatementDescriptor = "soforty!",
                Amount                    = 500,
                Currency                  = "eur",
                RedirectReturnUrl         = "http://no.where/webhooks"
            };

            Source = new StripeSourceService(Cache.ApiKey).Create(options);
        }
        public creating_and_updating_bancontact_source()
        {
            var options = new StripeSourceCreateOptions
            {
                Type     = StripeSourceType.Bancontact,
                Amount   = 500,
                Currency = "eur",
                Owner    = new StripeSourceOwner {
                    Name = "Joe Biden"
                },
                RedirectReturnUrl             = "http://no.where/webhooks",
                BancontactStatementDescriptor = "test statement descriptor"
            };

            Source = new StripeSourceService(Cache.ApiKey).Create(options);
        }
        public creating_and_updating_bitcoin_source()
        {
            var options = new StripeSourceCreateOptions
            {
                Type     = StripeSourceType.Bitcoin,
                Amount   = 100101,
                Currency = "usd",
                Owner    = new StripeSourceOwner
                {
                    Name  = "Satoshi Nakamoto",
                    Email = "*****@*****.**"
                },
                RedirectReturnUrl = "http://no.where/webhooks"
            };

            Source = new StripeSourceService(Cache.ApiKey).Create(options);
        }
Пример #15
0
        private StripeSource createStripeSource(string cardNo, int?expirationYear, int?expirationMonth, string ccv, string cardHolderFullName, bool isReusable)
        {
            StripeSource source = new StripeSource();

            try
            {
                var tokenOptions = new StripeTokenCreateOptions()
                {
                    Card = new StripeCreditCardOptions()
                    {
                        Number          = cardNo,
                        ExpirationYear  = expirationYear,
                        ExpirationMonth = expirationMonth,
                        Cvc             = ccv
                    }
                };
                var         tokenService = new StripeTokenService(secretKey);
                StripeToken stripeToken  = tokenService.Create(tokenOptions);
                string      usage        = "reusable";
                if (!isReusable)
                {
                    usage = "single_use";
                }
                var sourceOptions = new StripeSourceCreateOptions()
                {
                    Type  = StripeSourceType.Card,
                    Owner = new StripeSourceOwner()
                    {
                        Name = cardHolderFullName
                    },
                    Token = stripeToken.Id,
                    Usage = usage
                };
                var sourceService = new StripeSourceService(secretKey);
                //CREATE A SOURCE
                source = sourceService.Create(sourceOptions);
            }
            catch (StripeException e)
            {
                throw new StripeException(e.HttpStatusCode, e.StripeError, e.Message);
            }
            return(source);
        }
Пример #16
0
        public creating_three_d_secure_source()
        {
            Source = new StripeSourceService(Cache.ApiKey).Create(
                new StripeSourceCreateOptions
            {
                Type              = StripeSourceType.Card,
                Amount            = 8675309,
                Currency          = "eur",
                RedirectReturnUrl = "http://no.where/webhooks",
                Card              = new StripeCreditCardOptions
                {
                    Number          = "4000000000003063",
                    ExpirationMonth = 12,
                    ExpirationYear  = 2020
                }
            }
                );

            ThreeDSecure = new StripeSourceService(Cache.ApiKey).Create(
                new StripeSourceCreateOptions
            {
                Type                       = StripeSourceType.ThreeDSecure,
                Amount                     = 8675309,
                Currency                   = "eur",
                RedirectReturnUrl          = "http://no.where/webhooks",
                ThreeDSecureCardOrSourceId = Source.Id
            }
                );

            // from here, you have to go to the threeDSecure.Redirect.Url and click success

            //var charge = new StripeChargeService(Cache.ApiKey).Create(
            //    new StripeChargeCreateOptions
            //    {
            //        Amount = 8675309,
            //        Currency = "eur",
            //        SourceTokenOrExistingSourceId = threeDSecure.Id
            //    }
            //);
        }
Пример #17
0
        public creating_and_updating_card_source()
        {
            SourceCardCreateOptions = new StripeSourceCreateOptions
            {
                Type  = StripeSourceType.Card,
                Token = "tok_visa"
            };

            SourceCardUpdateOptions = new StripeSourceUpdateOptions
            {
                Card = new StripeSourceCardUpdateOptions
                {
                    ExpirationMonth = 12,
                    ExpirationYear  = 2028
                }
            };

            var service = new StripeSourceService(Cache.ApiKey);

            SourceCard        = service.Create(SourceCardCreateOptions);
            SourceCardUpdated = service.Update(SourceCard.Id, SourceCardUpdateOptions);
        }
        public ProcessPaymentRequest SetCheckoutDetails(StripeSource stripeSource)
        {
            // get customer & cart
            //var customer = customer;
            int customerId = Convert.ToInt32(_workContext.CurrentCustomer.Id.ToString());
            var customer   = _customerService.GetCustomerById(customerId);

            _workContext.CurrentCustomer = customer;

            var cart = customer.ShoppingCartItems.Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart).ToList();

            if (customer.BillingAddress == null)
            {
                // get/update billing address
                string name                   = stripeSource.Owner.Name;
                string billingEmail           = customer.Email;
                string billingAddress1        = stripeSource.Owner.Address.Line1;
                string billingAddress2        = stripeSource.Owner.Address.Line2;
                string billingCity            = stripeSource.Owner.Address.City;
                int?   billingStateProvinceId = null;
                var    billingStateProvince   = _stateProvinceService.GetStateProvinceByAbbreviation(stripeSource.Owner.Address.State);
                if (billingStateProvince != null)
                {
                    billingStateProvinceId = billingStateProvince.Id;
                }
                string billingZipPostalCode = stripeSource.Owner.Address.PostalCode;
                int?   billingCountryId     = null;
                var    billingCountry       = _countryService.GetCountryByTwoLetterIsoCode(stripeSource.Owner.Address.Country);
                if (billingCountry != null)
                {
                    billingCountryId = billingCountry.Id;
                }

                var billingAddress = customer.Addresses.ToList().FindAddress(
                    null, null, null,
                    billingEmail, string.Empty, string.Empty, billingAddress1, billingAddress2, billingCity,
                    billingStateProvinceId, billingZipPostalCode, billingCountryId,
                    //TODO process custom attributes
                    null);

                billingAddress = new Core.Domain.Common.Address()
                {
                    FirstName       = null,
                    LastName        = null,
                    PhoneNumber     = null,
                    Email           = billingEmail,
                    FaxNumber       = string.Empty,
                    Company         = string.Empty,
                    Address1        = billingAddress1,
                    Address2        = billingAddress2,
                    City            = billingCity,
                    StateProvinceId = billingStateProvinceId,
                    ZipPostalCode   = billingZipPostalCode,
                    CountryId       = billingCountryId,
                    CreatedOnUtc    = DateTime.UtcNow,
                };
                customer.Addresses.Add(billingAddress);

                //set default billing address
                customer.BillingAddress = billingAddress;

                _customerService.UpdateCustomer(customer);
            }


            _genericAttributeService.SaveAttribute <ShippingOption>(customer, SystemCustomerAttributeNames.SelectedShippingOption, null);

            var processPaymentRequest = new ProcessPaymentRequest {
                CustomerId = customerId
            };

            processPaymentRequest.CustomValues["StripeSourceId"] = stripeSource.Id;
            return(processPaymentRequest);
        }
Пример #19
0
        public Transaction_Result Auth(Sale_Details details)
        {
            bool isApproved = false;
            bool isPending  = false;
            bool failed     = false;

            try
            {
                StripeConfiguration.SetApiKey(secretKey);
                if (details.ProviderToken == null || details.ProviderToken.Length <= 1)
                {
                    try
                    {
                        StripeSource source = createStripeSource(details.CardNumber, details.CardExpiryYear, details.CardExpiryMonth, details.CardCCV, details.CardHolderName + " " + details.CardHolderLastName, false);
                        details.ProviderToken = source.Id;
                    }
                    catch (StripeException e)
                    {
                        return(new Transaction_Result()
                        {
                            isApproved = false,
                            hasServerError = true,
                            ErrorCode = e.StripeError.Code,
                            ErrorText = e.StripeError.Message,
                            FullResponse = e.StripeError.StripeResponse.ResponseJson
                        });
                    }
                }
                StripeCustomer customer = new StripeCustomer();
                if (details.ProviderToken.IndexOf("cus") > -1)
                {
                    customer = getTCGStripeCustomer(details.ProviderToken);
                }
                else
                {
                    customer = createTCGStripeCustomer(new StorePaymentMethod_Details()
                    {
                        CardCVV           = details.CardCCV,
                        CardExpiryMonth   = details.CardExpiryMonth,
                        CardExpiryYear    = details.CardExpiryYear,
                        CardHolderName    = details.CardHolderName,
                        CardNumber        = details.CardNumber,
                        CardHolderSurname = details.CardHolderLastName
                    }, details.ProviderToken);
                }
                details.ProviderToken = customer.DefaultSourceId;
                var chargeOptions = new StripeChargeCreateOptions()
                {
                    Amount      = calculateAmount(details.Amount, details.CurrencyCode),
                    Currency    = details.CurrencyCode.ToLower(), //SHOULD BE LOWER CASE
                    Description = "Authentication for " + details.CustomerLastName + ", " + details.CustomerFirstName,
                    SourceTokenOrExistingSourceId = details.ProviderToken,
                    CustomerId = customer.Id,
                    Capture    = false
                };
                var          chargeService = new StripeChargeService();
                StripeCharge charge        = chargeService.Create(chargeOptions);
                string       status        = charge.Status;
                if (status.Contains("succeeded"))
                {
                    isApproved = true;
                }
                else if (status.Contains("pending"))
                {
                    isPending = true;
                }
                else
                {
                    failed = true;
                }
                return(new Transaction_Result
                {
                    isApproved = isApproved,
                    hasServerError = failed,
                    ErrorText = charge.FailureMessage,
                    ResultText = charge.Status,
                    isPending = isPending,
                    ProviderToken = charge.Id,
                    FullResponse = charge.StripeResponse.ResponseJson,
                    ApprovalCode = charge.Status
                });
            }
            catch (StripeException e)
            {
                return(new Transaction_Result
                {
                    isApproved = false,
                    hasServerError = true,
                    ErrorText = e.StripeError.Message,
                    ProviderToken = null,
                    ErrorCode = e.StripeError.Code,
                    FullResponse = e.StripeError.StripeResponse.ResponseJson
                });
            }
        }
Пример #20
0
        public Transaction_Result Sale(Sale_Details details)
        {
            StripeConfiguration.SetApiKey(secretKey);
            //ONCE-OFF PAYMENT
            if (details.ProviderToken == null || details.ProviderToken.Length <= 1)
            {
                try
                {
                    StripeSource source = createStripeSource(details.CardNumber, details.CardExpiryYear, details.CardExpiryMonth, details.CardCCV, details.CardHolderName + " " + details.CardHolderLastName, false);
                    details.ProviderToken = source.Id;
                }
                catch (StripeException e)
                {
                    return(new Transaction_Result()
                    {
                        isApproved = false,
                        hasServerError = true,
                        ErrorCode = e.StripeError.Code,
                        ErrorText = e.StripeError.Message,
                        FullResponse = e.StripeError.StripeResponse.ResponseJson
                    });
                }
            }

            //INITIATING A CHARGE
            var          chargeOptions = new StripeChargeCreateOptions();
            var          chargeService = new StripeChargeService();
            StripeCharge charge        = new StripeCharge();

            chargeOptions.Capture = true;
            bool isApproved = false;
            bool isPending  = false;

            try
            {
                //IF A SOURCE TOKEN IS PROVIDED >>>> ONCE-OFF PAYMENT

                if (details.ProviderToken.IndexOf("src") > -1)
                {
                    var          sourceService = new StripeSourceService();
                    StripeSource source        = sourceService.Get(details.ProviderToken);
                    chargeOptions.SourceTokenOrExistingSourceId = source.Id;
                    chargeOptions.Amount   = calculateAmount(details.Amount, details.CurrencyCode); // $1.00 = 100 cents
                    chargeOptions.Currency = details.CurrencyCode.ToLower();                        //SHOULD BE LOWER CASE
                    charge = chargeService.Create(chargeOptions);
                }

                //ONCE-OFF PAYMENT

                else if (details.ProviderToken.IndexOf("tok") > -1)
                {
                    var sourceService = new StripeSourceService();
                    chargeOptions.SourceTokenOrExistingSourceId = details.ProviderToken;
                    chargeOptions.Amount   = calculateAmount(details.Amount, details.CurrencyCode); // $1.00 = 100 cents
                    chargeOptions.Currency = details.CurrencyCode.ToLower();                        //SHOULD BE LOWER CASE
                    charge = chargeService.Create(chargeOptions);
                }

                //A REUSABLE CUSTOMER (OR A CARD)

                else if (details.ProviderToken.IndexOf("cus") > -1)
                {
                    var            customerService = new StripeCustomerService();
                    StripeCustomer customer        = customerService.Get(details.ProviderToken);
                    chargeOptions.SourceTokenOrExistingSourceId = customer.DefaultSourceId;
                    chargeOptions.CustomerId = details.ProviderToken;
                    chargeOptions.Amount     = calculateAmount(details.Amount, details.CurrencyCode); // $1.00 = 100 cents
                    chargeOptions.Currency   = details.CurrencyCode.ToLower();                        //SHOULD BE LOWER CASE
                    charge = chargeService.Create(chargeOptions);
                }
                string status = charge.Status;
                if (status.Contains("succeeded"))
                {
                    isApproved = true;
                }
                else if (status.Contains("pending"))
                {
                    isPending = true;
                }
                return(new Transaction_Result
                {
                    isApproved = isApproved,
                    hasServerError = isPending,
                    ErrorText = charge.FailureMessage,
                    ErrorCode = charge.FailureCode,
                    TransactionIndex = charge.BalanceTransactionId,
                    ProviderToken = charge.Id,
                    ResultText = charge.Status,
                    FullResponse = charge.StripeResponse.ResponseJson
                });
            }
            catch (StripeException e)
            {
                return(new Transaction_Result
                {
                    isApproved = false,
                    hasServerError = true,
                    ErrorText = e.StripeError.Message,
                    ProviderToken = null,
                    ErrorCode = e.StripeError.Code,
                    FullResponse = e.StripeError.StripeResponse.ResponseJson
                });
            }
        }