Esempio n. 1
0
        //public async Task<Member> AddBankToAccount(Member Member, Token token)
        //{

        //    //NOTE 2.5  failing with StripeException: Missing required param: external_account.
        //    if (Member is null || Member.StripeAccountId is null || Member.StripeAccountSecKey is null)
        //        throw new Exception($"SmStipeService.AddBankToAccount : Bad input parameters on member : {Member.Id}");

        //

        //    var options = new ExternalAccountCreateOptions
        //    {
        //        ExternalAccountTokenId = token.Id,
        //        //ExternalAccountBankAccount = new AccountBankAccountOptions()
        //        //{
        //        //    AccountHolderName = Member.BusinessName,
        //        //    AccountHolderType = "individual",
        //        //    AccountNumber = BankAccount,
        //        //    RoutingNumber = RoutingNumber,
        //        //    Country = "US",
        //        //    Currency = "usd"
        //        //},

        //    };

        //    var service = new ExternalAccountService();
        //    var bankAccount = await service.CreateAsync(Member.StripeAccountId, options);

        //    if (bankAccount is null || bankAccount.Id is null)
        //        throw new Exception($"SmStipeService.AddBankToAccount : Add bank account fails for member : {Member.Id}");

        //    Member.StripeBankAccountId = bankAccount.Id;
        //    return Member;
        //}


        // NOTE: switched to CreateAccountAddCard because of following....
        //Error(1.31.19 after upgrading to latest Stripe):
        // StripeException: This account can only be updated with an account token, because it was
        // originally created with an account token. (Attempted to update param 'account_token' directly.)

        //public async Task<Account> CreateAccount(Member Member,
        //                                               string token)
        //{
        //

        //    var accountOptions = new AccountCreateOptions()
        //    {
        //        AccountToken=token,

        //        Email = Member.Email,
        //        Type = AccountType.Custom,
        //        Country = "US",
        //        LegalEntity = new AccountLegalEntityOptions
        //        {
        //             Dob=new AccountDobOptions()
        //             {
        //                  Day=Member.BirthDay,
        //                  Month=Member.BirthMonth,
        //                  Year=Member.BirthYear
        //             },
        //              Address=new AddressOptions()
        //              {
        //                  City = Member.Address.City,
        //                  Line1 = Member.Address.AddrLine,
        //                  Line2 = Member.Address.AddrLine2 ?? string.Empty,
        //                  PostalCode = Member.Address.Zip,
        //                  State = Member.Address.State,
        //                  Country= "US"
        //              },

        //            FirstName = Member.FirstName,
        //            LastName = Member.LastName,
        //            BusinessName = Member.BusinessName,
        //            PersonalIdNumber=Member.SSNum,
        //            Type = "individual"  // or 'company'
        //        },
        //        TosAcceptance=new AccountTosAcceptanceOptions() {  Date= Member.StripeTosDate, Ip= Member.StripeTosIp },
        //        BusinessName = Member.BusinessName,
        //        BusinessUrl = "https://simple-market.com"
        //    };
        //    var accountService = new AccountService();
        //    return await accountService.CreateAsync(accountOptions);
        //}

        public ResultAndMessage CreditCardPurchase(string vendorCustId,
                                                   decimal purchaseAmount,
                                                   decimal smFee,
                                                   string stripeToken)
        {
            var result = new ResultAndMessage();

            int amt = (int)(purchaseAmount * 100);

            var chargeOptions = new ChargeCreateOptions()
            {
                Amount      = amt,
                Currency    = "usd",
                Description = "Charge for [email protected]",
                // NOTE comment out because latest stripe change - don't know what to do ???
                //SourceTokenOrExistingSourceId = stripeToken,
                Destination = new ChargeDestinationCreateOptions()
                {
                    Account = vendorCustId, Amount = 0
                }
            };
            var    chargeService = new ChargeService();
            Charge charge        = chargeService.Create(chargeOptions);

            return(result);
        }
Esempio n. 2
0
        public async Task <ResultAndMessage> CreateContribution(ContributeVm vm)
        {
            ResultAndMessage result = new ResultAndMessage();

            int amt       = vm.Amount * 100;
            var customers = new CustomerService();
            var charges   = new ChargeService();

            var customer = await customers.CreateAsync(new CustomerCreateOptions
            {
                Email  = vm.StripeEmail,
                Source = vm.StripeToken
            });

            if (customer != null)
            {
                var charge = await charges.CreateAsync(new ChargeCreateOptions
                {
                    Amount      = amt,
                    Description = "MasterMind Contribution",
                    Currency    = "usd",
                    Customer    = customer.Id
                });

                result.exData  = customer.Id;
                result.success = (charge != null);
            }
            return(result);
        }
Esempio n. 3
0
        // Charge called only when vendor confirms product shipped
        //  - order transaction records one buyer purchase, may be multiple
        //     transactions as shopping cart supports multiple product purchase
        //     requests in one order.
        public ResultAndMessage CreateCharge(SmChargeInfo data)
        {
            ResultAndMessage result = new ResultAndMessage();

            if (data.Tran.OrderItem.Price > 0)
            {
                //// no account balance monitoring until Mango

                // Testing
                if (data.BuyerMemberType == MemberType.Vendor)
                {
                    var chargeResult = ChargeAccountToAccount(data.BuyerStripeCustId,
                                                              data.VendorStripeAcctId,
                                                              data.Tran.TotalAmount,
                                                              data.Tran.OrderItem.SmFee);
                    if (!chargeResult.success)
                    {
                        result.message = $"SmTransService.ChargeAccount : Charge failed for Tran {data.Tran.Id}";
                        return(result);
                    }
                    // credit tran.VendorId
                }
                if (data.BuyerMemberType == MemberType.Member)
                {
                    // TODO get Stripe key
                    string key          = "adsfsdf";
                    var    stripeResult = ChargeCustomerToAccount(data.BuyerStripeCustId,
                                                                  data.VendorStripeAcctId,
                                                                  key,
                                                                  data.Tran.TotalAmount,
                                                                  data.Tran.OrderItem.SmFee);
                    if (!stripeResult.success)
                    {
                        result.message += $"SmTransService.ChargeCard : Charge failed for Tran {data.Tran.Id}";
                        return(stripeResult);
                    }
                }

                // interesting idea here of  tran history as a separate collection of records
                // tied by tranid to order tran.
                // Another approach might be to convert TranStateElement into an array of state-change entries

                //TranStatusHistory charge = new TranStatusHistory()
                //{
                //    DateCreated = DateTime.UtcNow,
                //    TranId = tran.TranId,
                //    tranEvent = OrderEventType.Charge,
                //    EventName = OrderEventType.Charge.ToString()

                //};
                //result.success = AddTranHistory(charge);
                return(result);
            }
            return(result);
        }
Esempio n. 4
0
        public ResultAndMessage ChargeCustomerToAccount(string BuyerCustId,
                                                        string VendorAcctId,
                                                        string StripeKey,
                                                        decimal purchaseAmount,
                                                        decimal smFee)
        {
            ResultAndMessage result = new ResultAndMessage();

            // setting up the card
            var charge = new ChargeCreateOptions
            {
                // always set these properties ( ??? old Stripe comments - do we put amount in two places now??[see just below]
                Amount   = purchaseAmount.ToPennies(),
                Currency = "usd",

                Description = "simple-market purchase",

                // set this property if using a customer
                Customer = BuyerCustId,

                // fund receiver
                Destination = new ChargeDestinationCreateOptions()
                {
                    Account = VendorAcctId, Amount = purchaseAmount.ToPennies()
                },

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

                ApplicationFeeAmount = smFee.ToPennies()
            };

            var    chargeService = new ChargeService();
            Charge stripeCharge  = chargeService.Create(charge);

            result.success = true;

            return(result);
        }
Esempio n. 5
0
        public ResultAndMessage ChargeAccountToAccount(string BuyerCustId,
                                                       string VendorAcctId,
                                                       decimal purchaseAmount,
                                                       decimal smFee)
        {
            ResultAndMessage result = new ResultAndMessage();

            var charge = new ChargeCreateOptions
            {
                //  What is this property?
                //----------------------------------------
                //charge.OnBehalfOf = stripeAcctId;
                //-----------------------------------
                //   When you create destination charges on the platform account,
                //  Stripe automatically:
                //     -Settles charges in the country of the specified account,
                //        thereby minimizing declines
                //     -Uses the connected account’s currency for settlement,
                //        often avoiding currency conversions
                //     -Uses the fee structure for the connected account’s country
                // This same functionality is not automatically provided when creating
                //   separate charges and transfers, but you can replicate it using
                //   the on_behalf_of attribute when creating the charge.
                //   Setting on_behalf_of defines the business of record for the charge
                //   and funds will be settled using that account.

                //  For Custom Accounts, simplest route
                //  create the charge on platform’s account
                //  destination parm - connected account that receives funds.
                Destination = new ChargeDestinationCreateOptions()
                {
                    Account = VendorAcctId
                },

                // always set these properties
                Amount   = purchaseAmount.ToPennies(),
                Currency = "usd",

                //  two-step payments: you can first authorize a charge
                //  on your customer’s card, then wait to settle (capture)
                //  it later. When a charge is authorized, the funds are guaranteed
                //  by the issuing bank and the amount held on the customer’s card
                // for up to seven days. If the charge is not captured within this time,
                // the authorization is canceled and funds released.
                // To authorize a payment without capturing it, make a charge request
                // that also includes the capture parameter with a value of false.
                // This instructs Stripe to only authorize the amount
                // on the customer’s card.

                //charge.Capture = false;

                // Here's second step if two-step is employed
                //var chargeService = new StripeChargeService();
                //charge = chargeService.Capture({ CHARGE_ID});

                // set this if you want to
                Description = "simple-market purchase",

                //charge.SourceTokenOrExistingSourceId = BuyerAcctId;

                // set this property if using a customer
                // - this MUST be set if you are using an existing source!
                Customer             = BuyerCustId,
                ApplicationFeeAmount = smFee.ToPennies()
            };

            //string secKey = _cntxt.smAdmin.Single(r => r.type == AdminRecType.secKey).strData;
            //if (string.IsNullOrEmpty(secKey))
            //{
            //    result.message = "failure to fetch stripe key.";
            //    return result;
            //}
            //StripeConfiguration.SetApiKey(secKey);

            var    chargeService = new ChargeService();
            Charge stripeCharge  = chargeService.Create(charge);

            result.success = true;

            return(result);
        }