#jamie88_error
1 messages ยท Page 1 of 1 (latest)
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- jamie88_code, 21 hours ago, 6 messages
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! We typically respond in a few minutes, but in some cases we might need a bit more time (e.g., server's busy, you've got a complex question, etc.).
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can start a new thread if you have another question.
๐ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1246036696701861948
๐ Have more to share? Add details, code, screenshots, videos, etc. below.
hi @idle phoenix i will provide some code if that asssits, it is a rails app using stimulus
here is the stimulus controller: // app/javascript/controllers/stripe_onboarding_controller.js
import { Controller } from "@hotwired/stimulus";
export default class extends Controller {
static values = {
stripePublishableKey: String,
eventWithdrawalPath: String,
csrfToken: String,
eventId: String,
};
async createAccountSession(event) {
console.log('createAccountSession called');
event.preventDefault();
console.log('Creating account session...');
try {
const response = await fetch(`/events/${this.eventIdValue}/onboarding`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRF-Token': document.querySelector('meta[name="csrf-token"]').getAttribute('content')
},
body: JSON.stringify({})
});
const data = await response.json();
if (response.ok) {
const clientSecret = data.client_secret;
const stripe = Stripe(this.stripePublishableKeyValue);
const accountOnboarding = await stripe.accountOnboarding({
clientSecret: clientSecret
});
accountOnboarding.mount(this.element.querySelector('[data-stripe-onboarding-target="formContainer"]'));
// Redirect to the event withdrawal path after account onboarding is completed
accountOnboarding.on('complete', () => {
window.location.href = this.eventWithdrawalPathValue;
});
} else {
console.error('Error creating account session:', data.error);
// Handle the error, display an error message to the user
}
} catch (error) {
console.error('Error creating account session:', error);
// Handle the error, display an error message to the user
}
}
}
here is the latest version of the rails controller: class StripeConnectController < ApplicationController
def onboarding
logger.info "Starting onboarding process for event: #{params[:event_id]}"
@event = Event.find(params[:event_id])
logger.info "Event found: #{@event.inspect}"
Stripe.api_key = ENV['STRIPE_API_KEY']
begin
# Create a new Stripe account
account = Stripe::Account.create({
type: 'standard',
country: 'GB',
business_type: 'individual',
individual: {
first_name: current_user.first_name,
last_name: current_user.last_name,
email: current_user.email
},
business_profile: {
product_description: 'Personal Fundraising Or Crowdfunding',
}
})
logger.info "Created Stripe account: #{account.id}"
logger.info "Account details: #{account.to_json}"
# Create an Account Link
account_link = Stripe::AccountLink.create({
account: account.id,
refresh_url: events_url,
return_url: event_withdrawal_url(@event),
type: 'account_onboarding'
})
render json: { url: account_link.url, account_id: account.id }
rescue Stripe::StripeError => e
# Handle Stripe errors
logger.error "Stripe error: #{e.message}"
logger.error e.backtrace.join("\n")
render json: { error: e.message }, status: :unprocessable_entity
rescue => e
# Handle other errors
logger.error "Error: #{e.message}"
logger.error e.backtrace.join("\n")
render json: { error: 'An error occurred while connecting Stripe account' }, status: :internal_server_error
end
end
end
this was the one before: # app/controllers/stripe_connect_controller.rb
class StripeConnectController < ApplicationController
def onboarding
logger.info "Starting onboarding process for event: #{params[:event_id]}"
@event = Event.find(params[:event_id])
logger.info "Event found: #{@event.inspect}"
Stripe.api_key = ENV['STRIPE_API_KEY']
begin
# Create a new Stripe account
account = Stripe::Account.create({
type: 'standard',
country: 'GB',
business_type: 'individual',
individual: {
first_name: current_user.first_name,
last_name: current_user.last_name,
email: current_user.email
},
business_profile: {
product_description: 'Personal Fundraising Or Crowdfunding',
}
})
logger.info "Created Stripe account: #{account.id}"
logger.info "Account details: #{account.to_json}"
# Create an Account Session
account_session = Stripe::AccountSession.create({
account: account.id,
components: {
account_onboarding: { enabled: true },
payments: { enabled: true },
payouts: { enabled: true },
balances: { enabled: true }
}
})
client_secret = account_session.client_secret
render json: { client_secret: client_secret, account_id: account.id }
rescue Stripe::StripeError => e
# Handle Stripe errors
logger.error "Stripe error: #{e.message}"
logger.error e.backtrace.join("\n")
render json: { error: e.message }, status: :unprocessable_entity
rescue => e
# Handle other errors
logger.error "Error: #{e.message}"
logger.error e.backtrace.join("\n")
render json: { error: 'An error occurred while connecting Stripe account' }, status: :internal_server_error
end
end
end
tis is the code where the button is in the view: <div class="mt-4">
<% if current_user.stripe_account_id.blank? %>
<!-- Initiate Stripe onboarding if no Stripe account is present -->
<%= form_with url: onboarding_path(event_id: @event.id), method: :post, data: { controller: 'stripe-onboarding', action: 'stripe-onboarding#createAccountSession', 'stripe-onboarding-event-id-value': @event.id, 'stripe-onboarding-stripe-publishable-key-value': ENV['STRIPE_PUBLISHABLE_KEY'], turbo: false } do |form| %>
<%= form.submit "Set up Stripe account", class: "inline-block px-6 py-3 bg-indigo-600 text-white rounded-md hover:bg-indigo-700" %>
<% end %>
<% else %>
<!-- Initiate withdrawal if Stripe account is already set up -->
<%= form_with url: initiate_withdrawal_path(@event), method: :post, data: { controller: 'withdrawal', 'withdrawal-target': 'form' } do |form| %>
<%= form.submit "Initiate Withdrawal", class: "inline-block px-6 py-3 bg-indigo-600 text-white rounded-md hover:bg-indigo-700" %>
<% end %>
<% end %>
</div>
</div>
</div>
</div>
</div>
<script src="https://js.stripe.com/v3/"></script>
hi! I'm taking over this thread.
what is this: await stripe.accountOnboarding()? this is not a Stripe function.
i thought this was how to inititate the account onboarding, what should it be instead? is it completely incorrect then? please could you point me in the correct direction of what to use instead, im not sure how i ahve arrived at that i have been hacking this up a fair bit.
what's your goal here? to onboard a connected account?
yes to onboard connect accounts, so the accounts are created on teh stripe dashboard initally but the connect embed form isnot loaded for the users to fill in the rest of their details
i need to onboard connect account so i can payout individual users
i have been refering to these docs: https://docs.stripe.com/connect/get-started-connect-embedded-components#account-sessions https://docs.stripe.com/connect/supported-embedded-components/account-onboarding?lang=ruby&client=react but clearly getting lost
thanks for the added conext, give me a few minutes to look into this
brilliant thank you @fresh musk
here's the main documentation page for the onboarding embeded component. there I see no mention of accountOnboarding(). so if you try to se a fonction that doesn't exist, it's expected to not work. https://docs.stripe.com/connect/supported-embedded-components/account-onboarding
can you clarify where did you see this function beign used?
im not sure, ive been reading various forums, i will try look back through and see what source lead me tot this; i think i ahve jsut mad a complete error and misinterpretted the docs when trying to adapt it when it didnt initatlly work, by trying to take the documentation notes here: After creating the Account Session and initialising ConnectJS, you can render the Account onboarding component in the front end:
account-onboarding.js
// Include this element in your HTML
const accountOnboarding = stripeConnectInstance.create('account-onboarding');
accountOnboarding.setOnExit(() => {
console.log('User exited the onboarding flow');
});
container.appendChild(accountOnboarding);
notice that the code you shared preivously is calling stripe.accountOnboarding(), which implies that Stripe has a function called accountOnboarding, which is not true. that's why you got the error stripe.accountOnboarding is not a function
I recommend re-reading and following the documentation links you shared
and le tme know if you have specific questions
ok thank you for your assistance and time on this, i will reread throguh everything and reconstruct it all