|

|  How to Access Stripe Connect API for Marketplace Payments in Ruby

How to Access Stripe Connect API for Marketplace Payments in Ruby

October 31, 2024

Learn how to integrate Stripe Connect API for marketplace payments in Ruby. Step-by-step guide to simplify implementation and manage transactions effortlessly.

How to Access Stripe Connect API for Marketplace Payments in Ruby

 

Integrate Stripe Connect in Ruby

 

  • Include the Stripe gem in your Ruby application by adding it to your Gemfile:
    gem 'stripe'
    

     

  • Install the gem using bundler:
    bundle install
    

     

  • Require the Stripe library in your application code:
    require 'stripe'
    

 

Configure Stripe

 

  • Set your Stripe API key and client ID. It's essential to store these securely, for example by using environment variables:
    Stripe.api_key = ENV['STRIPE_SECRET_KEY']
    client_id = ENV['STRIPE_CLIENT_ID']
    

 

Create Connected Accounts

 

  • To create a connected account for a user on your platform, use the following code example. This process involves redirecting the user to Stripe's onboarding form:
    account = Stripe::Account.create({
      type: 'express'
      business_type: 'individual',
      country: 'US',
    })
    

     

  • Generate an account link to redirect the user for onboarding:
    account_link = Stripe::AccountLink.create({
      account: account.id,
      refresh_url: 'https://example.com/reauth',
      return_url: 'https://example.com/return',
      type: 'account_onboarding',
    })
    

     

  • Redirect the user to `account_link.url` for completing their Stripe account setup.

 

Handle Marketplace Charges

 

  • Use Stripe's built-in features to charge a customer and transfer funds to the connected account:
    charge = Stripe::Charge.create({
      amount: 1000,
      currency: 'usd',
      customer: 'cus_xxx',
      transfer_data: {
        destination: 'acct_xxx',
      },
    })
    

     

  • To handle marketplace fees, use the `application_fee_amount` attribute:
    charge = Stripe::Charge.create({
      amount: 1000,
      currency: 'usd',
      customer: 'cus_xxx',
      transfer_data: {
        destination: 'acct_xxx',
      },
      application_fee_amount: 123,
    })
    

 

Use Webhooks for Payment Events

 

  • Implement webhooks to listen for events related to your Stripe account and connected accounts.

     

  • Set up a webhook endpoint in your Stripe dashboard and handle the events in your application code. This helps in processing successful transfers, payments, and more:
    webhook_secret = 'whsec_xxx'
    payload = request.body.read
    sig_header = request.env['HTTP_STRIPE_SIGNATURE']
    
    event = nil
    
    begin
      event = Stripe::Webhook.construct_event(
        payload, sig_header, webhook_secret
      )
    rescue JSON::ParserError => e
      status 400
      return
    rescue Stripe::SignatureVerificationError => e
      status 400
      return
    end
    
    case event.type
    when 'charge.succeeded'
      charge = event.data.object
      # Handle successful charge
    when 'account.updated'
      account = event.data.object
      # Handle account updates
    end
    

 

Testing Your Stripe Integration

 

  • Use Stripe's test mode to experiment with API endpoints, webhooks, and transactions without affecting real funds.
  •  

  • Utilize Stripe's test card numbers and accounts for simulating various scenarios, such as successful payments or declined card transactions.

 

Additional Resources

 

  • Refer to the [Stripe Connect documentation](https://stripe.com/docs/connect) for comprehensive details on implementing different features.
  •  

  • Utilize the Ruby SDK's documentation for further customization and advanced use-cases.

 

Pre-order Friend AI Necklace

Pre-Order Friend Dev Kit

Open-source AI wearable
Build using the power of recall

Order Now

OMI AI PLATFORM
Remember Every Moment,
Talk to AI and Get Feedback

Omi Necklace

The #1 Open Source AI necklace: Experiment with how you capture and manage conversations.

Build and test with your own Omi Dev Kit 2.

Omi App

Fully Open-Source AI wearable app: build and use reminders, meeting summaries, task suggestions and more. All in one simple app.

Github →

Join the #1 open-source AI wearable community

Build faster and better with 3900+ community members on Omi Discord

Participate in hackathons to expand the Omi platform and win prizes

Participate in hackathons to expand the Omi platform and win prizes

Get cash bounties, free Omi devices and priority access by taking part in community activities

Join our Discord → 

OMI NECKLACE + OMI APP
First & only open-source AI wearable platform

a person looks into the phone with an app for AI Necklace, looking at notes Friend AI Wearable recorded a person looks into the phone with an app for AI Necklace, looking at notes Friend AI Wearable recorded
a person looks into the phone with an app for AI Necklace, looking at notes Friend AI Wearable recorded a person looks into the phone with an app for AI Necklace, looking at notes Friend AI Wearable recorded
online meeting with AI Wearable, showcasing how it works and helps online meeting with AI Wearable, showcasing how it works and helps
online meeting with AI Wearable, showcasing how it works and helps online meeting with AI Wearable, showcasing how it works and helps
App for Friend AI Necklace, showing notes and topics AI Necklace recorded App for Friend AI Necklace, showing notes and topics AI Necklace recorded
App for Friend AI Necklace, showing notes and topics AI Necklace recorded App for Friend AI Necklace, showing notes and topics AI Necklace recorded

OMI NECKLACE: DEV KIT
Order your Omi Dev Kit 2 now and create your use cases

Omi Dev Kit 2

Endless customization

OMI Necklace

$69.99

Make your life more fun with your AI wearable clone. It gives you thoughts, personalized feedback and becomes your second brain to discuss your thoughts and feelings. Available on iOS and Android.

Your Omi will seamlessly sync with your existing omi persona, giving you a full clone of yourself – with limitless potential for use cases:

  • Real-time conversation transcription and processing;
  • Develop your own use cases for fun and productivity;
  • Hundreds of community apps to make use of your Omi Persona and conversations.

Learn more

Omi Dev Kit 2: build at a new level

Key Specs

OMI DEV KIT

OMI DEV KIT 2

Microphone

Yes

Yes

Battery

4 days (250mAH)

2 days (250mAH)

On-board memory (works without phone)

No

Yes

Speaker

No

Yes

Programmable button

No

Yes

Estimated Delivery 

-

1 week

What people say

“Helping with MEMORY,

COMMUNICATION

with business/life partner,

capturing IDEAS, and solving for

a hearing CHALLENGE."

Nathan Sudds

“I wish I had this device

last summer

to RECORD

A CONVERSATION."

Chris Y.

“Fixed my ADHD and

helped me stay

organized."

David Nigh

OMI NECKLACE: DEV KIT
Take your brain to the next level

LATEST NEWS
Follow and be first in the know

Latest news
FOLLOW AND BE FIRST IN THE KNOW

team@basedhardware.com

company

about

careers

invest

privacy

products

omi

omi dev kit

personas

resources

apps

affiliate

docs

github

help