#jamie88_error

1 messages ยท Page 1 of 1 (latest)

zenith tokenBOT
vocal sierraBOT
#

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.

zenith tokenBOT
#

๐Ÿ‘‹ 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.

idle phoenix
#

๐Ÿ‘‹ happy to help

#

would you mind sharing your code please?

glass pecan
#

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>

fresh musk
#

hi! I'm taking over this thread.

#

what is this: await stripe.accountOnboarding()? this is not a Stripe function.

glass pecan
#

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.

fresh musk
#

what's your goal here? to onboard a connected account?

glass pecan
#

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

fresh musk
#

thanks for the added conext, give me a few minutes to look into this

glass pecan
#

brilliant thank you @fresh musk

fresh musk
glass pecan
#

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);

fresh musk
#

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

glass pecan
#

ok thank you for your assistance and time on this, i will reread throguh everything and reconstruct it all