Skip to content

Instantly share code, notes, and snippets.

@vbrazo
Created April 26, 2023 04:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vbrazo/b762bb1282b9eb50a96af9922c9b7184 to your computer and use it in GitHub Desktop.
Save vbrazo/b762bb1282b9eb50a96af9922c9b7184 to your computer and use it in GitHub Desktop.
Ruby Stripe Integration
# Set new Stripe API token
Stripe.api_key = 'sk_test_token'
# create new account
account = Stripe::Account.create({type: 'standard'})
# generate link for user to associate account
account_id = Stripe::AccountLink.create({
account: account.id,
refresh_url: 'https://www.site.tech/refresh_url',
return_url: 'https://www.site.tech/return_url',
type: 'account_onboarding',
})
# give this url to user
account_link["url"]
# create a product on Stripe
product = Stripe::Product.create(
{
name: 'Basic Dashboard',
default_price_data: {
unit_amount: 1000,
currency: 'usd',
recurring: {interval: 'month'},
},
expand: ['default_price'],
},
)
# associate a price to a product
price = Stripe::Price.create(
{
product: product.id,
unit_amount: 1000,
currency: 'usd',
recurring: {interval: 'month'},
lookup_key: 'standard_monthly',
},
)
# make a payment to master account
Stripe::Checkout::Session.create(
{
mode: 'payment',
line_items: [{price: price.id, quantity: 1}],
payment_intent_data: {application_fee_amount: 123},
success_url: 'https://example.com/success',
cancel_url: 'https://example.com/cancel',
},
{stripe_account: account.id},
)
# make a payment using Stripe Connect and
# register the payment in an associated account
Stripe::Checkout::Session.create(
{
mode: 'payment',
line_items: [{price: price.id, quantity: 1}],
payment_intent_data: {application_fee_amount: 123},
success_url: 'https://example.com/success',
cancel_url: 'https://example.com/cancel',
},
{stripe_account: account.id},
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment