public PayoutServiceTest(
            StripeMockFixture stripeMockFixture,
            MockHttpClientFixture mockHttpClientFixture)
            : base(stripeMockFixture, mockHttpClientFixture)
        {
            this.service = new PayoutService(this.StripeClient);

            this.createOptions = new PayoutCreateOptions
            {
                Amount   = 123,
                Currency = "usd",
            };

            this.updateOptions = new PayoutUpdateOptions
            {
                Metadata = new Dictionary <string, string>
                {
                    { "key", "value" },
                },
            };

            this.listOptions = new PayoutListOptions
            {
                Limit = 1,
            };
        }
        public void Create_Instant_Payout()
        {
            var options = new PayoutCreateOptions
            {
                Amount   = 1000,
                Currency = "usd",
                Method   = "instant",
            };

            var requestOptions = new RequestOptions();

            requestOptions.StripeAccount = "{{CONNECTED_STRIPE_ACCOUNT_ID}}";

            var service = new PayoutService();
            var payout  = service.Create(options, requestOptions);
        }
        public async Task <IActionResult> StartWithdraw([FromBody] WithdrawCreationDto withdrawCreationDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new { message = ModelState.Values.SelectMany(v => v.Errors).Select(e => e.ErrorMessage) }));
            }

            try
            {
                StripeConfiguration.ApiKey = ServiceKey;
                var user = await _accountsRepository.GetByUserId(withdrawCreationDto.UserId);

                var service = new PayoutService();
                var options = new PayoutCreateOptions
                {
                    Amount   = withdrawCreationDto.Amount,
                    Currency = "usd",
                    Metadata = new Dictionary <string, string>()
                    {
                        { "UserId", User.FindFirstValue(ClaimTypes.Name) }
                    },
                };
                var payout = service.Create(options, new RequestOptions {
                    StripeAccount = user.StripeUserId
                });

                return(Ok(new PayoutCreatedDto
                {
                    PayoutId = payout.Id
                }));

                throw new InvalidPayment("Couldn't process withdraw");
            }
            catch (Exception e)
            {
                return(BadRequest(new MessageObj(e.Message)));
            }
        }
示例#4
0
        public PayoutServiceTest()
        {
            this.service = new PayoutService();

            this.createOptions = new PayoutCreateOptions
            {
                Amount   = 123,
                Currency = "usd",
            };

            this.updateOptions = new PayoutUpdateOptions
            {
                Metadata = new Dictionary <string, string>
                {
                    { "key", "value" },
                },
            };

            this.listOptions = new PayoutListOptions
            {
                Limit = 1,
            };
        }
示例#5
0
        public async Task <int> PaymentCredit(string token, int amount,
                                              string bank_account, string routing_number, string account_name)
        {
            try
            {
                long userId       = (long)Session["USER_ID"];
                user residentUser = entities.users.Find(userId);
                // Charge using Credit Card
                StripeConfiguration.SetApiKey(ep.GetStripeSecretKey());
                var chargeOptions = new ChargeCreateOptions
                {
                    Amount      = amount + 20000,
                    Currency    = "usd",
                    Description = "Charge for [email protected]",
                    SourceId    = token // obtained with Stripe.js,
                };
                var    chargeService = new ChargeService();
                Charge charge        = chargeService.Create(chargeOptions);
                // Payout to coamdin bank
                // Get Bank Info
                string bankAccountStr = bank_account;   //"000123456789";//
                string bankRoutingStr = routing_number; // "110000000";//

                // Get self account
                var accountOptions = new AccountCreateOptions
                {
                    Email               = "*****@*****.**",
                    Type                = AccountType.Custom,
                    Country             = "US",
                    ExternalBankAccount = new AccountBankAccountOptions()
                    {
                        Country           = "US",
                        Currency          = "usd",
                        AccountHolderName = "John Brown",//account_name
                        AccountHolderType = "individual",
                        RoutingNumber     = bankRoutingStr,
                        AccountNumber     = bankAccountStr
                    },
                    PayoutSchedule = new AccountPayoutScheduleOptions()
                    {
                        Interval = "daily"
                    },
                    TosAcceptance = new AccountTosAcceptanceOptions()
                    {
                        Date      = DateTime.Now.AddDays(-10),
                        Ip        = "202.47.115.80",
                        UserAgent = "Chrome"
                    },
                    LegalEntity = new AccountLegalEntityOptions()
                    {
                        Dob = new AccountDobOptions()
                        {
                            Day   = 1,
                            Month = 4,
                            Year  = 1991
                        },
                        FirstName = "John",
                        LastName  = "Brown",
                        Type      = "individual"
                    }
                };
                var     accountService = new AccountService();
                Account account        = await accountService.CreateAsync(accountOptions);

                StripeConfiguration.SetApiKey(ep.GetStripeSecretKey());

                var     service = new BalanceService();
                Balance balance = await service.GetAsync();

                var transOptions = new TransferCreateOptions
                {
                    Amount      = amount,
                    Currency    = "usd",
                    Destination = account.Id
                };

                var      transferService = new TransferService();
                Transfer Transfer        = transferService.Create(transOptions);

                var payoutOptions = new PayoutCreateOptions
                {
                    Amount              = amount,
                    Currency            = "usd",
                    Destination         = account.ExternalAccounts.First().Id,
                    SourceType          = "card",
                    StatementDescriptor = "PAYOUT",
                    //Method = "instant"
                };

                var requestOptions = new RequestOptions();
                requestOptions.ApiKey = ep.GetStripeSecretKey();
                requestOptions.StripeConnectAccountId = account.Id;
                var payoutService = new PayoutService();
                var payout        = await payoutService.CreateAsync(payoutOptions, requestOptions);

                return(1);
            }
            catch (Exception ex)
            {
                return(0);
            }
        }
示例#6
0
        public async Task <int> PaymentAch(string bankToken, int amount,
                                           string account_number, string rounting_number)
        {
            try
            {
                // Create an ACH charge
                StripeConfiguration.SetApiKey(ep.GetStripeSecretKey());
                CustomerService customerService = new CustomerService();
                var             customerOptions = new CustomerCreateOptions
                {
                };
                Customer achCustomer = customerService.Create(customerOptions);

                // Create Bank Account
                var bankAccountOptions = new BankAccountCreateOptions
                {
                    SourceToken = bankToken
                };
                var         bankService = new BankAccountService();
                BankAccount bankAccount = bankService.Create(achCustomer.Id, bankAccountOptions);
                // Verify BankAccount
                List <long> Amounts = new List <long>();
                Amounts.Add(32);
                Amounts.Add(45);

                var verifyOptions = new BankAccountVerifyOptions
                {
                    Amounts = Amounts
                };

                bankAccount = bankService.Verify(achCustomer.Id, bankAccount.Id, verifyOptions);
                var chargeOptions = new ChargeCreateOptions
                {
                    Amount      = amount,
                    Currency    = "usd",
                    Description = "Charge for [email protected]",
                    CustomerId  = achCustomer.Id
                };
                var    chargeService = new ChargeService();
                Charge charge        = chargeService.Create(chargeOptions);
                // Payout from Stripe to Bank Account
                string bankAccountStr = account_number;  // "000123456789";
                string bankRoutingStr = rounting_number; // "110000000";

                // Get self account
                var accountOptions = new AccountCreateOptions
                {
                    Email               = "*****@*****.**",
                    Type                = AccountType.Custom,
                    Country             = "US",
                    ExternalBankAccount = new AccountBankAccountOptions()
                    {
                        Country           = "US",
                        Currency          = "usd",
                        AccountHolderName = "John Brown",//account_name
                        AccountHolderType = "individual",
                        RoutingNumber     = bankRoutingStr,
                        AccountNumber     = bankAccountStr
                    },
                    PayoutSchedule = new AccountPayoutScheduleOptions()
                    {
                        Interval = "daily"
                    },
                    TosAcceptance = new AccountTosAcceptanceOptions()
                    {
                        Date      = DateTime.Now.AddDays(-10),
                        Ip        = "202.47.115.80",
                        UserAgent = "Chrome"
                    },
                    LegalEntity = new AccountLegalEntityOptions()
                    {
                        Dob = new AccountDobOptions()
                        {
                            Day   = 1,
                            Month = 4,
                            Year  = 1991
                        },
                        FirstName = "John",
                        LastName  = "Brown",
                        Type      = "individual"
                    }
                };
                var     accountService = new AccountService();
                Account account        = await accountService.CreateAsync(accountOptions);

                StripeConfiguration.SetApiKey(ep.GetStripeSecretKey());

                var     service = new BalanceService();
                Balance balance = await service.GetAsync();

                var transOptions = new TransferCreateOptions
                {
                    Amount      = amount,
                    Currency    = "usd",
                    Destination = account.Id
                };

                var      transferService = new TransferService();
                Transfer Transfer        = transferService.Create(transOptions);

                var payoutOptions = new PayoutCreateOptions
                {
                    Amount              = amount,
                    Currency            = "usd",
                    Destination         = account.ExternalAccounts.First().Id,
                    SourceType          = "card",
                    StatementDescriptor = "PAYOUT",
                    //Method = "instant"
                };

                var requestOptions = new RequestOptions();
                requestOptions.ApiKey = ep.GetStripeSecretKey();
                requestOptions.StripeConnectAccountId = account.Id;
                var payoutService = new PayoutService();
                var payout        = await payoutService.CreateAsync(payoutOptions, requestOptions);

                return(1);
            }
            catch (Exception)
            {
                return(0);
            }
        }