Saving an html form to a table?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
Issue: I want a way to verify if a user has already connected their bank account. What i have isn't saving to the table so i have no way to verify it from the db.
I want: I want to only save a stripe_account_id to the bankaccount table (which is a column) some way through the forms submit. Have it be unique and allowed to be overridden
This is what I have done so far:
Bank Account Controller:
def new
unless current_user.stripe_token
redirect_to new_user_stripe_account_path and return
end
begin
@stripe_account = Stripe::Account.retrieve(current_user.stripe_token)
@bank_account = BankAccount.new
@stripe_account = StripeAccount.find(params[:stripe_account_id])
rescue Stripe::StripeError => e
handle_error(e.message, 'new')
rescue => e
flash[:error] = e.message
end
end
def create
unless params[:token] && current_user.stripe_token
redirect_to new_bank_account_path and return
end
begin
token = params[:token]
stripe_account = Stripe::Account.retrieve(current_user.stripe_token)
stripe_account.external_account = params[:token]
stripe_account.save
flash[:success] = "Your bank account has been added!"
redirect_to dashboard_path
@bank_account = BankAccount.new(bank_account_params)
@bank_account.save!
rescue Stripe::StripeError => e
flash[:error] = e.message
rescue => e
flash[:error] = e.message
end
end
private
def set_bank_account
@bank_account = BankAccount.find(params[:id])
end
def bank_account_params
params.require(:bank_account).permit()
end
end
Routes:
resources :users do
resources :stripe_accounts
end
resources :stripe_accounts do
resources :bank_accounts
end
resources :bank_accounts
Without having the resources by itself, i get an error: "no post /bank_accounts" --- before i realized i had no way to verify a user having a bankaccount connected, it wasn't nested
Here's the gist of the form:
<form action="/bank_accounts" method="POST" id="payment-form-1">
<input type="hidden" name="token" />
<label for="country">Country</label>
<select id="country" class="form-control">
<option value="US">United States</option>
<option value="ES">Spain</option>
</select>
<label for="currency">Currency</label>
<select id="currency" class="form-control">
<option value="EUR">Euro</option>
</select>
<label for="routing-number">Routing Number</label>
<input type="text" class="form-control" id="routing-number" value="110000000" />
<label for="account-number">Account Number</label>
<input type="text" class="form-control" id="account-number" value="000123456789" />
<label for="account-holder-name">Account Holder Name</label>
<input type="text" class="form-control" id="account-holder-name" />
<label for="account-holder-type">Account Holder Type</label>
<select id="account-holder-type" class="form-control">
<option value="individual">Individual</option>
<option value="company">Company</option>
</select>
<%= hidden_field_tag :authenticity_token, form_authenticity_token -%>
<%= hidden_field_tag :stripeToken, current_user.stripe_token -%>
<%= hidden_field_tag :stripe_account_id, :value => @stripe_account_id %>
<button type="submit">Submit</button>
<div class="outcome">
<div class="error"></div>
<div class="success">
Success! Your Stripe token is <span class="token"></span>
</div>
</div>
</form>
The form is then sent using javascript:
<script>
var stripe = Stripe('pk_test_W1234567qTSqQJucPWU8kh');
function setOutcome(result) {
var successElement = document.querySelector('.success');
var errorElement = document.querySelector('.error');
successElement.classList.remove('visible');
errorElement.classList.remove('visible');
if (result.token) {
// In this example, we're simply displaying the token
successElement.querySelector('.token').textContent = result.token.id;
successElement.classList.add('visible');
// In a real integration, you'd submit the form with the token to your backend server
var form = document.querySelector('form');
form.querySelector('input[name="token"]').setAttribute('value', result.token.id);
form.submit();
} else {
errorElement.textContent = result.error.message;
errorElement.classList.add('visible');
}
}
document.querySelector('form').addEventListener('submit', function(e) {
e.preventDefault();
var bankAccountParams = {
country: document.getElementById('country').value,
currency: document.getElementById('currency').value,
account_number: document.getElementById('account-number').value,
account_holder_name: document.getElementById('account-holder-name').value,
account_holder_type: document.getElementById('account-holder-type').value,
}
if (document.getElementById('routing-number').value != '') {
bankAccountParams['routing_number'] = document.getElementById('routing-number').value;
}
stripe.createToken('bank_account', bankAccountParams).then(setOutcome);
});
</script>
Ultimately, I am simply wanting to save a reference to the bankaccount table so i know if an end user has filled out their bank account data yet and for view purposes to remind them they have already.
I would like to save to the bankaccount table the stripe_account.id (this is associated with a user in the stripeaccount table), this way ill know which users have already filled this out. (the bankaccount table has a stripe_account_id column, id, created_at, and updated_at).
Is there way to do this from the html form, from the javascript, etc.? Is my controller just wrong?
javascript ruby-on-rails ruby
add a comment |
Issue: I want a way to verify if a user has already connected their bank account. What i have isn't saving to the table so i have no way to verify it from the db.
I want: I want to only save a stripe_account_id to the bankaccount table (which is a column) some way through the forms submit. Have it be unique and allowed to be overridden
This is what I have done so far:
Bank Account Controller:
def new
unless current_user.stripe_token
redirect_to new_user_stripe_account_path and return
end
begin
@stripe_account = Stripe::Account.retrieve(current_user.stripe_token)
@bank_account = BankAccount.new
@stripe_account = StripeAccount.find(params[:stripe_account_id])
rescue Stripe::StripeError => e
handle_error(e.message, 'new')
rescue => e
flash[:error] = e.message
end
end
def create
unless params[:token] && current_user.stripe_token
redirect_to new_bank_account_path and return
end
begin
token = params[:token]
stripe_account = Stripe::Account.retrieve(current_user.stripe_token)
stripe_account.external_account = params[:token]
stripe_account.save
flash[:success] = "Your bank account has been added!"
redirect_to dashboard_path
@bank_account = BankAccount.new(bank_account_params)
@bank_account.save!
rescue Stripe::StripeError => e
flash[:error] = e.message
rescue => e
flash[:error] = e.message
end
end
private
def set_bank_account
@bank_account = BankAccount.find(params[:id])
end
def bank_account_params
params.require(:bank_account).permit()
end
end
Routes:
resources :users do
resources :stripe_accounts
end
resources :stripe_accounts do
resources :bank_accounts
end
resources :bank_accounts
Without having the resources by itself, i get an error: "no post /bank_accounts" --- before i realized i had no way to verify a user having a bankaccount connected, it wasn't nested
Here's the gist of the form:
<form action="/bank_accounts" method="POST" id="payment-form-1">
<input type="hidden" name="token" />
<label for="country">Country</label>
<select id="country" class="form-control">
<option value="US">United States</option>
<option value="ES">Spain</option>
</select>
<label for="currency">Currency</label>
<select id="currency" class="form-control">
<option value="EUR">Euro</option>
</select>
<label for="routing-number">Routing Number</label>
<input type="text" class="form-control" id="routing-number" value="110000000" />
<label for="account-number">Account Number</label>
<input type="text" class="form-control" id="account-number" value="000123456789" />
<label for="account-holder-name">Account Holder Name</label>
<input type="text" class="form-control" id="account-holder-name" />
<label for="account-holder-type">Account Holder Type</label>
<select id="account-holder-type" class="form-control">
<option value="individual">Individual</option>
<option value="company">Company</option>
</select>
<%= hidden_field_tag :authenticity_token, form_authenticity_token -%>
<%= hidden_field_tag :stripeToken, current_user.stripe_token -%>
<%= hidden_field_tag :stripe_account_id, :value => @stripe_account_id %>
<button type="submit">Submit</button>
<div class="outcome">
<div class="error"></div>
<div class="success">
Success! Your Stripe token is <span class="token"></span>
</div>
</div>
</form>
The form is then sent using javascript:
<script>
var stripe = Stripe('pk_test_W1234567qTSqQJucPWU8kh');
function setOutcome(result) {
var successElement = document.querySelector('.success');
var errorElement = document.querySelector('.error');
successElement.classList.remove('visible');
errorElement.classList.remove('visible');
if (result.token) {
// In this example, we're simply displaying the token
successElement.querySelector('.token').textContent = result.token.id;
successElement.classList.add('visible');
// In a real integration, you'd submit the form with the token to your backend server
var form = document.querySelector('form');
form.querySelector('input[name="token"]').setAttribute('value', result.token.id);
form.submit();
} else {
errorElement.textContent = result.error.message;
errorElement.classList.add('visible');
}
}
document.querySelector('form').addEventListener('submit', function(e) {
e.preventDefault();
var bankAccountParams = {
country: document.getElementById('country').value,
currency: document.getElementById('currency').value,
account_number: document.getElementById('account-number').value,
account_holder_name: document.getElementById('account-holder-name').value,
account_holder_type: document.getElementById('account-holder-type').value,
}
if (document.getElementById('routing-number').value != '') {
bankAccountParams['routing_number'] = document.getElementById('routing-number').value;
}
stripe.createToken('bank_account', bankAccountParams).then(setOutcome);
});
</script>
Ultimately, I am simply wanting to save a reference to the bankaccount table so i know if an end user has filled out their bank account data yet and for view purposes to remind them they have already.
I would like to save to the bankaccount table the stripe_account.id (this is associated with a user in the stripeaccount table), this way ill know which users have already filled this out. (the bankaccount table has a stripe_account_id column, id, created_at, and updated_at).
Is there way to do this from the html form, from the javascript, etc.? Is my controller just wrong?
javascript ruby-on-rails ruby
Proper formatting of your code would help
– Dorian
Nov 17 '18 at 11:36
You should not exposecurrent_user.stripe_tokenand@stripe_account_idto the user (via the form in hidden fields)
– Dorian
Nov 17 '18 at 11:39
YoupreventDefault()on form submit and thensubmit()the form again, I highly doubt this would work, it would just create an infinite loop (look at the network tab, you should see a lot of requests to the Stripe API)
– Dorian
Nov 17 '18 at 11:42
Yeah i don't think thats needed. I originally put that there when i was testing and never tested without it yet (passing the hidden field for stripe token)
– uno
Nov 17 '18 at 12:01
add a comment |
Issue: I want a way to verify if a user has already connected their bank account. What i have isn't saving to the table so i have no way to verify it from the db.
I want: I want to only save a stripe_account_id to the bankaccount table (which is a column) some way through the forms submit. Have it be unique and allowed to be overridden
This is what I have done so far:
Bank Account Controller:
def new
unless current_user.stripe_token
redirect_to new_user_stripe_account_path and return
end
begin
@stripe_account = Stripe::Account.retrieve(current_user.stripe_token)
@bank_account = BankAccount.new
@stripe_account = StripeAccount.find(params[:stripe_account_id])
rescue Stripe::StripeError => e
handle_error(e.message, 'new')
rescue => e
flash[:error] = e.message
end
end
def create
unless params[:token] && current_user.stripe_token
redirect_to new_bank_account_path and return
end
begin
token = params[:token]
stripe_account = Stripe::Account.retrieve(current_user.stripe_token)
stripe_account.external_account = params[:token]
stripe_account.save
flash[:success] = "Your bank account has been added!"
redirect_to dashboard_path
@bank_account = BankAccount.new(bank_account_params)
@bank_account.save!
rescue Stripe::StripeError => e
flash[:error] = e.message
rescue => e
flash[:error] = e.message
end
end
private
def set_bank_account
@bank_account = BankAccount.find(params[:id])
end
def bank_account_params
params.require(:bank_account).permit()
end
end
Routes:
resources :users do
resources :stripe_accounts
end
resources :stripe_accounts do
resources :bank_accounts
end
resources :bank_accounts
Without having the resources by itself, i get an error: "no post /bank_accounts" --- before i realized i had no way to verify a user having a bankaccount connected, it wasn't nested
Here's the gist of the form:
<form action="/bank_accounts" method="POST" id="payment-form-1">
<input type="hidden" name="token" />
<label for="country">Country</label>
<select id="country" class="form-control">
<option value="US">United States</option>
<option value="ES">Spain</option>
</select>
<label for="currency">Currency</label>
<select id="currency" class="form-control">
<option value="EUR">Euro</option>
</select>
<label for="routing-number">Routing Number</label>
<input type="text" class="form-control" id="routing-number" value="110000000" />
<label for="account-number">Account Number</label>
<input type="text" class="form-control" id="account-number" value="000123456789" />
<label for="account-holder-name">Account Holder Name</label>
<input type="text" class="form-control" id="account-holder-name" />
<label for="account-holder-type">Account Holder Type</label>
<select id="account-holder-type" class="form-control">
<option value="individual">Individual</option>
<option value="company">Company</option>
</select>
<%= hidden_field_tag :authenticity_token, form_authenticity_token -%>
<%= hidden_field_tag :stripeToken, current_user.stripe_token -%>
<%= hidden_field_tag :stripe_account_id, :value => @stripe_account_id %>
<button type="submit">Submit</button>
<div class="outcome">
<div class="error"></div>
<div class="success">
Success! Your Stripe token is <span class="token"></span>
</div>
</div>
</form>
The form is then sent using javascript:
<script>
var stripe = Stripe('pk_test_W1234567qTSqQJucPWU8kh');
function setOutcome(result) {
var successElement = document.querySelector('.success');
var errorElement = document.querySelector('.error');
successElement.classList.remove('visible');
errorElement.classList.remove('visible');
if (result.token) {
// In this example, we're simply displaying the token
successElement.querySelector('.token').textContent = result.token.id;
successElement.classList.add('visible');
// In a real integration, you'd submit the form with the token to your backend server
var form = document.querySelector('form');
form.querySelector('input[name="token"]').setAttribute('value', result.token.id);
form.submit();
} else {
errorElement.textContent = result.error.message;
errorElement.classList.add('visible');
}
}
document.querySelector('form').addEventListener('submit', function(e) {
e.preventDefault();
var bankAccountParams = {
country: document.getElementById('country').value,
currency: document.getElementById('currency').value,
account_number: document.getElementById('account-number').value,
account_holder_name: document.getElementById('account-holder-name').value,
account_holder_type: document.getElementById('account-holder-type').value,
}
if (document.getElementById('routing-number').value != '') {
bankAccountParams['routing_number'] = document.getElementById('routing-number').value;
}
stripe.createToken('bank_account', bankAccountParams).then(setOutcome);
});
</script>
Ultimately, I am simply wanting to save a reference to the bankaccount table so i know if an end user has filled out their bank account data yet and for view purposes to remind them they have already.
I would like to save to the bankaccount table the stripe_account.id (this is associated with a user in the stripeaccount table), this way ill know which users have already filled this out. (the bankaccount table has a stripe_account_id column, id, created_at, and updated_at).
Is there way to do this from the html form, from the javascript, etc.? Is my controller just wrong?
javascript ruby-on-rails ruby
Issue: I want a way to verify if a user has already connected their bank account. What i have isn't saving to the table so i have no way to verify it from the db.
I want: I want to only save a stripe_account_id to the bankaccount table (which is a column) some way through the forms submit. Have it be unique and allowed to be overridden
This is what I have done so far:
Bank Account Controller:
def new
unless current_user.stripe_token
redirect_to new_user_stripe_account_path and return
end
begin
@stripe_account = Stripe::Account.retrieve(current_user.stripe_token)
@bank_account = BankAccount.new
@stripe_account = StripeAccount.find(params[:stripe_account_id])
rescue Stripe::StripeError => e
handle_error(e.message, 'new')
rescue => e
flash[:error] = e.message
end
end
def create
unless params[:token] && current_user.stripe_token
redirect_to new_bank_account_path and return
end
begin
token = params[:token]
stripe_account = Stripe::Account.retrieve(current_user.stripe_token)
stripe_account.external_account = params[:token]
stripe_account.save
flash[:success] = "Your bank account has been added!"
redirect_to dashboard_path
@bank_account = BankAccount.new(bank_account_params)
@bank_account.save!
rescue Stripe::StripeError => e
flash[:error] = e.message
rescue => e
flash[:error] = e.message
end
end
private
def set_bank_account
@bank_account = BankAccount.find(params[:id])
end
def bank_account_params
params.require(:bank_account).permit()
end
end
Routes:
resources :users do
resources :stripe_accounts
end
resources :stripe_accounts do
resources :bank_accounts
end
resources :bank_accounts
Without having the resources by itself, i get an error: "no post /bank_accounts" --- before i realized i had no way to verify a user having a bankaccount connected, it wasn't nested
Here's the gist of the form:
<form action="/bank_accounts" method="POST" id="payment-form-1">
<input type="hidden" name="token" />
<label for="country">Country</label>
<select id="country" class="form-control">
<option value="US">United States</option>
<option value="ES">Spain</option>
</select>
<label for="currency">Currency</label>
<select id="currency" class="form-control">
<option value="EUR">Euro</option>
</select>
<label for="routing-number">Routing Number</label>
<input type="text" class="form-control" id="routing-number" value="110000000" />
<label for="account-number">Account Number</label>
<input type="text" class="form-control" id="account-number" value="000123456789" />
<label for="account-holder-name">Account Holder Name</label>
<input type="text" class="form-control" id="account-holder-name" />
<label for="account-holder-type">Account Holder Type</label>
<select id="account-holder-type" class="form-control">
<option value="individual">Individual</option>
<option value="company">Company</option>
</select>
<%= hidden_field_tag :authenticity_token, form_authenticity_token -%>
<%= hidden_field_tag :stripeToken, current_user.stripe_token -%>
<%= hidden_field_tag :stripe_account_id, :value => @stripe_account_id %>
<button type="submit">Submit</button>
<div class="outcome">
<div class="error"></div>
<div class="success">
Success! Your Stripe token is <span class="token"></span>
</div>
</div>
</form>
The form is then sent using javascript:
<script>
var stripe = Stripe('pk_test_W1234567qTSqQJucPWU8kh');
function setOutcome(result) {
var successElement = document.querySelector('.success');
var errorElement = document.querySelector('.error');
successElement.classList.remove('visible');
errorElement.classList.remove('visible');
if (result.token) {
// In this example, we're simply displaying the token
successElement.querySelector('.token').textContent = result.token.id;
successElement.classList.add('visible');
// In a real integration, you'd submit the form with the token to your backend server
var form = document.querySelector('form');
form.querySelector('input[name="token"]').setAttribute('value', result.token.id);
form.submit();
} else {
errorElement.textContent = result.error.message;
errorElement.classList.add('visible');
}
}
document.querySelector('form').addEventListener('submit', function(e) {
e.preventDefault();
var bankAccountParams = {
country: document.getElementById('country').value,
currency: document.getElementById('currency').value,
account_number: document.getElementById('account-number').value,
account_holder_name: document.getElementById('account-holder-name').value,
account_holder_type: document.getElementById('account-holder-type').value,
}
if (document.getElementById('routing-number').value != '') {
bankAccountParams['routing_number'] = document.getElementById('routing-number').value;
}
stripe.createToken('bank_account', bankAccountParams).then(setOutcome);
});
</script>
Ultimately, I am simply wanting to save a reference to the bankaccount table so i know if an end user has filled out their bank account data yet and for view purposes to remind them they have already.
I would like to save to the bankaccount table the stripe_account.id (this is associated with a user in the stripeaccount table), this way ill know which users have already filled this out. (the bankaccount table has a stripe_account_id column, id, created_at, and updated_at).
Is there way to do this from the html form, from the javascript, etc.? Is my controller just wrong?
javascript ruby-on-rails ruby
javascript ruby-on-rails ruby
edited Nov 17 '18 at 7:59
uno
asked Nov 17 '18 at 7:11
unouno
34319
34319
Proper formatting of your code would help
– Dorian
Nov 17 '18 at 11:36
You should not exposecurrent_user.stripe_tokenand@stripe_account_idto the user (via the form in hidden fields)
– Dorian
Nov 17 '18 at 11:39
YoupreventDefault()on form submit and thensubmit()the form again, I highly doubt this would work, it would just create an infinite loop (look at the network tab, you should see a lot of requests to the Stripe API)
– Dorian
Nov 17 '18 at 11:42
Yeah i don't think thats needed. I originally put that there when i was testing and never tested without it yet (passing the hidden field for stripe token)
– uno
Nov 17 '18 at 12:01
add a comment |
Proper formatting of your code would help
– Dorian
Nov 17 '18 at 11:36
You should not exposecurrent_user.stripe_tokenand@stripe_account_idto the user (via the form in hidden fields)
– Dorian
Nov 17 '18 at 11:39
YoupreventDefault()on form submit and thensubmit()the form again, I highly doubt this would work, it would just create an infinite loop (look at the network tab, you should see a lot of requests to the Stripe API)
– Dorian
Nov 17 '18 at 11:42
Yeah i don't think thats needed. I originally put that there when i was testing and never tested without it yet (passing the hidden field for stripe token)
– uno
Nov 17 '18 at 12:01
Proper formatting of your code would help
– Dorian
Nov 17 '18 at 11:36
Proper formatting of your code would help
– Dorian
Nov 17 '18 at 11:36
You should not expose
current_user.stripe_token and @stripe_account_id to the user (via the form in hidden fields)– Dorian
Nov 17 '18 at 11:39
You should not expose
current_user.stripe_token and @stripe_account_id to the user (via the form in hidden fields)– Dorian
Nov 17 '18 at 11:39
You
preventDefault() on form submit and then submit() the form again, I highly doubt this would work, it would just create an infinite loop (look at the network tab, you should see a lot of requests to the Stripe API)– Dorian
Nov 17 '18 at 11:42
You
preventDefault() on form submit and then submit() the form again, I highly doubt this would work, it would just create an infinite loop (look at the network tab, you should see a lot of requests to the Stripe API)– Dorian
Nov 17 '18 at 11:42
Yeah i don't think thats needed. I originally put that there when i was testing and never tested without it yet (passing the hidden field for stripe token)
– uno
Nov 17 '18 at 12:01
Yeah i don't think thats needed. I originally put that there when i was testing and never tested without it yet (passing the hidden field for stripe token)
– uno
Nov 17 '18 at 12:01
add a comment |
1 Answer
1
active
oldest
votes
To save the external accounts ids to the database, you would need to do customer.sources.all(object: "bank_account"), then get the id of each and save it to the associated StripeAccount (I guess) associated to the user (while making sure you are duplicating ids).
https://stripe.com/docs/api/customer_bank_accounts/list
Personally I think you don't need to store the bank account ids in your database, you can just fetch it from Stripe when you need it.
I'm not referring to the id from stripe. I want the id that rails would create and attach it to a stripe_account_id just to i know from the db side that a user has a bank account inputted into their stripe account. but from my code, nothing is entering into my BankAccount table
– uno
Nov 17 '18 at 12:00
It'ssource.id
– Dorian
Nov 17 '18 at 12:02
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53349059%2fsaving-an-html-form-to-a-table%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
To save the external accounts ids to the database, you would need to do customer.sources.all(object: "bank_account"), then get the id of each and save it to the associated StripeAccount (I guess) associated to the user (while making sure you are duplicating ids).
https://stripe.com/docs/api/customer_bank_accounts/list
Personally I think you don't need to store the bank account ids in your database, you can just fetch it from Stripe when you need it.
I'm not referring to the id from stripe. I want the id that rails would create and attach it to a stripe_account_id just to i know from the db side that a user has a bank account inputted into their stripe account. but from my code, nothing is entering into my BankAccount table
– uno
Nov 17 '18 at 12:00
It'ssource.id
– Dorian
Nov 17 '18 at 12:02
add a comment |
To save the external accounts ids to the database, you would need to do customer.sources.all(object: "bank_account"), then get the id of each and save it to the associated StripeAccount (I guess) associated to the user (while making sure you are duplicating ids).
https://stripe.com/docs/api/customer_bank_accounts/list
Personally I think you don't need to store the bank account ids in your database, you can just fetch it from Stripe when you need it.
I'm not referring to the id from stripe. I want the id that rails would create and attach it to a stripe_account_id just to i know from the db side that a user has a bank account inputted into their stripe account. but from my code, nothing is entering into my BankAccount table
– uno
Nov 17 '18 at 12:00
It'ssource.id
– Dorian
Nov 17 '18 at 12:02
add a comment |
To save the external accounts ids to the database, you would need to do customer.sources.all(object: "bank_account"), then get the id of each and save it to the associated StripeAccount (I guess) associated to the user (while making sure you are duplicating ids).
https://stripe.com/docs/api/customer_bank_accounts/list
Personally I think you don't need to store the bank account ids in your database, you can just fetch it from Stripe when you need it.
To save the external accounts ids to the database, you would need to do customer.sources.all(object: "bank_account"), then get the id of each and save it to the associated StripeAccount (I guess) associated to the user (while making sure you are duplicating ids).
https://stripe.com/docs/api/customer_bank_accounts/list
Personally I think you don't need to store the bank account ids in your database, you can just fetch it from Stripe when you need it.
answered Nov 17 '18 at 11:47
DorianDorian
13.4k37890
13.4k37890
I'm not referring to the id from stripe. I want the id that rails would create and attach it to a stripe_account_id just to i know from the db side that a user has a bank account inputted into their stripe account. but from my code, nothing is entering into my BankAccount table
– uno
Nov 17 '18 at 12:00
It'ssource.id
– Dorian
Nov 17 '18 at 12:02
add a comment |
I'm not referring to the id from stripe. I want the id that rails would create and attach it to a stripe_account_id just to i know from the db side that a user has a bank account inputted into their stripe account. but from my code, nothing is entering into my BankAccount table
– uno
Nov 17 '18 at 12:00
It'ssource.id
– Dorian
Nov 17 '18 at 12:02
I'm not referring to the id from stripe. I want the id that rails would create and attach it to a stripe_account_id just to i know from the db side that a user has a bank account inputted into their stripe account. but from my code, nothing is entering into my BankAccount table
– uno
Nov 17 '18 at 12:00
I'm not referring to the id from stripe. I want the id that rails would create and attach it to a stripe_account_id just to i know from the db side that a user has a bank account inputted into their stripe account. but from my code, nothing is entering into my BankAccount table
– uno
Nov 17 '18 at 12:00
It's
source.id– Dorian
Nov 17 '18 at 12:02
It's
source.id– Dorian
Nov 17 '18 at 12:02
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53349059%2fsaving-an-html-form-to-a-table%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Proper formatting of your code would help
– Dorian
Nov 17 '18 at 11:36
You should not expose
current_user.stripe_tokenand@stripe_account_idto the user (via the form in hidden fields)– Dorian
Nov 17 '18 at 11:39
You
preventDefault()on form submit and thensubmit()the form again, I highly doubt this would work, it would just create an infinite loop (look at the network tab, you should see a lot of requests to the Stripe API)– Dorian
Nov 17 '18 at 11:42
Yeah i don't think thats needed. I originally put that there when i was testing and never tested without it yet (passing the hidden field for stripe token)
– uno
Nov 17 '18 at 12:01