Skip to content

Instantly share code, notes, and snippets.

View adamjstevenson's full-sized avatar
🏄‍♂️

Adam Stevenson adamjstevenson

🏄‍♂️
View GitHub Profile
@adamjstevenson
adamjstevenson / split_payments.rb
Created October 22, 2017 18:28
Split payments between sellers
# Create a charge for $10
charge = Stripe::Charge.create({
amount: 1000,
currency: "usd",
source: "src_1BF7yx2jy8PDLWD6TFmguGn0",
transfer_group: "notes_328324"
})
# Send $4 to one account
transfer = Stripe::Transfer.create({
@adamjstevenson
adamjstevenson / destination_charge.rb
Last active December 15, 2017 12:56
Create a destination charge with a 10% platform commission
charge = Stripe::Charge.create({
amount: 1000, # The total amount of the charge
currency: "usd",
source: "src_1BF7yx2jy8PDLWD6TFmguGn0", # A token representing the customer's payment details
destination: {
amount: 900, # The amount the connected user gets
account: "acct_1BF8VRBAxruRdpTq", # The ID of the connected user
}
})
@adamjstevenson
adamjstevenson / fields_needed.rb
Created October 21, 2017 16:55
Retrieve fields needed for a Stripe account
# Retrieve the account
account = Stripe::Account.retrieve("acct_1BF8VRBAxruRdpTq")
# Grab the fields needed
fields_needed = account.verification.fields_needed
# ...later in your form, display an account update form based on the fields needed for verification
<% if fields_needed.include?('legal_entity.business_name') %>
<div class="form-group">
<%= f.label :business_name, "Business name (as it appears to the IRS)" %>
@adamjstevenson
adamjstevenson / account_create.rb
Created October 20, 2017 23:13
Create Stripe account
# Creates a Stripe account with some minimal account information submitted from a form
stripe_account = Stripe::Account.create(
type: "custom",
legal_entity: {
first_name: account_params[:first_name].capitalize,
last_name: account_params[:last_name].capitalize,
type: account_params[:account_type],
dob: {
day: account_params[:dob_day],
@adamjstevenson
adamjstevenson / create_subscription.rb
Last active December 15, 2017 12:58
Create a subscription on a connected account
# Create a subscription and take a 10% commission
subscription = Stripe::Subscription.create(
{
customer: "cus_BcNDyG0NuHZn4i", # The ID of the customer on the connected account to charge
items: [
{
plan: "29_monthly" # The ID of the plan to which the customer will be subscribed
}
],
@adamjstevenson
adamjstevenson / create_customer.rb
Last active December 15, 2017 12:58
Create a customer on a connected account
# Create a customer on a connected account
customer = Stripe::Customer.create(
{
description: "Customer for [email protected]",
source: "src_1BF7yx2jy8PDLWD6TFmguGn0", # The secure token representing the payment details
},
{
stripe_account: "acct_j1cXUEAksEpalsjc3Xl3" # The ID of the Stripe account connected to your platform
}
@adamjstevenson
adamjstevenson / refund_charge.rb
Created October 20, 2017 21:35
Create a refund on a connected account
# Refund a charge
refund = Stripe::Refund.create(
{
charge: "ch_1BAkyv2jy8PDLWD6E4t2XxPX", # The ID of the charge to refund
refund_application_fee: true # Optionally give your platform commission back to the user
},
{
stripe_account: "acct_j1cXUEAksEpalsjc3Xl3" # The ID of the Stripe account connected to your platform
}
@adamjstevenson
adamjstevenson / direct_charge.rb
Last active December 15, 2017 12:59
Create a direct charge on a Connected account
# Create a charge for $100 and take a $10 commission for the platform
charge = Stripe::Charge.create(
{
amount: 10000, # Charge amount in cents
currency: "usd", # The currency of the charge
source: "src_1BF7yx2jy8PDLWD6TFmguGn0", # A source token representing a Visa card
application_fee: 1000 # The commission your platform is taking
},
{
@adamjstevenson
adamjstevenson / 01-force-https.config
Created April 30, 2017 21:31
Elastic Beanstalk HTTPS configuration
files:
"/tmp/45_nginx_https_rw.sh":
owner: root
group: root
mode: "000644"
content: |
#! /bin/bash
CONFIGURED=`grep -c "return 301 https" /opt/elasticbeanstalk/support/conf/webapp_healthd.conf`
@adamjstevenson
adamjstevenson / auto-paginate_charges.py
Created November 12, 2016 17:18
Stripe: Auto-paginate and print charge IDs
import stripe
stripe.api_key = "YOUR-TEST-KEY"
# Retrieve all charges
charges = stripe.Charge.all(limit=100)
# Use auto-pagination to iterate through them
for charge in charges.auto_paging_iter():
# Output charge IDs
print(charge.id)