在dotnet中的Stripe Connect帐户中添加银行

时间:2019-03-18 18:52:58

标签: c# .net stripe-payments

我正在动态创建Stripe(自定义)Connect帐户。创建帐户后,我要创建银行帐户并将其添加到“已连接”用户。

这是我的前端:

var form = document.getElementById('bank-add');
    form.addEventListener('submit', function (event) {
        event.preventDefault();

        stripe.createToken('bank_account', {
            country: 'US',
            currency: 'usd',
            routing_number: document.getElementById('routing-number').value,
            account_number: document.getElementById('account-number').value,
            account_holder_name: document.getElementById('name').value,
            account_holder_type: 'individual',
        }).then(function (result) {
            if (result.error) {
                // Inform the customer that there was an error.
                //var errorElement = document.getElementById('card-errors');
                //errorElement.textContent = result.error.message;
            } else {
                // Send the token to your server.
                $('.token').text(result.token);
                stripeTokenHandler(result.token);
            }
        });
    });

    function stripeTokenHandler(token) {
        // Insert the token ID into the form so it gets submitted to the server
        var form = document.getElementById('bank-add');
        var hiddenInput = document.createElement('input');
        hiddenInput.setAttribute('type', 'hidden');
        hiddenInput.setAttribute('name', 'stripeToken');
        hiddenInput.setAttribute('value', token.id);
        form.appendChild(hiddenInput);

        // Submit the form
        form.submit();
    }

这是后端:

public void OnPostAddRoutingNumber()
        {
            var token = Request.Form["stripeToken"];

            var service = new ExternalAccountService();
            var options = new ExternalAccountCreateOptions
            {
                ExternalAccountTokenId = token
            };
            var bankAccount = service.Create(
              "acct_1EFPhvA7tmSzdlaC", 
              options
            );

            var o = new AccountUpdateOptions()
            {
                ExternalAccountId = bankAccount.Id
            };
            var s = new AccountService();
            s.Update("acct_1EFPhvA7tmSzdlaC", o);
        }

所以,我有些困惑。前端代码告诉Stripe为此数据创建令牌,然后我需要在后端使用该令牌创建银行帐户,对吗?然后将其添加到帐户?但是在更新“连接帐户”时,它会显示“没有此类令牌”。

0 个答案:

没有答案