Skip to content

Instantly share code, notes, and snippets.

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

Adam Stevenson adamjstevenson

🏄‍♂️
View GitHub Profile
@adamjstevenson
adamjstevenson / connect_app_fee_by_card_brand.php
Created September 22, 2016 19:01
Charge dynamic application fees based on card brand
<?php
// Include Stripe's library and set your API key.
require('./config.php');
// Retrieve the account ID and amount details from your own database...
// Ex: $db is an object containing the attributes you retrieve from your database.
// Check for a submitted token
if (isset($_POST['stripeToken'])){
@adamjstevenson
adamjstevenson / customer_create_with_shipping.php
Created September 23, 2016 02:41
Creating a customer object with shipping information from Checkout
<?
\Stripe\Customer::create(array(
"source" => $_POST['stripeToken'], // obtained with Checkout
"description" => "Charge for [email protected]",
"shipping" => array(
"name" => $_POST['stripeShippingName'],
"address" => array(
"line1" => $_POST['stripeShippingAddressLine1'],
"apt" => $_POST['stripeShippingAddressApt'],
"postal_code" => $_POST['stripeShippingAddressZip'],
@adamjstevenson
adamjstevenson / list_created_transfers_and_balance_available.rb
Last active December 15, 2017 13:01
List created future transfers and balance available by date on a connected account
require 'stripe'
# Your platform's secret key
Stripe.api_key = "YOUR-SECRET-KEY"
connected_account = "CONNECTED-ACCOUNT-ID"
now = Time.now.to_i
# List `transfer.created` events on the connected account
events = Stripe::Event.list({type: "transfer.created", limit: 100},{stripe_account: connected_account})
@adamjstevenson
adamjstevenson / list_declines.rb
Created October 5, 2016 22:34
Simple Declines Report
require 'stripe'
Stripe.api_key = "YOUR-API-KEY"
declines = Stripe::Charge.list(paid: false, limit: 100)
declines.auto_paging_each do |decline|
puts "#{decline.id},#{decline.failure_code},#{decline.failure_message}"
end
@adamjstevenson
adamjstevenson / advanced_declines.rb
Last active December 15, 2017 13:00
Advanced decline report
require 'stripe'
Stripe.api_key = "YOUR-API-KEY"
declines = Stripe::Charge.list(paid: false, limit: 100)
declines.auto_paging_each do |decline|
# Format the timestamp
formatted_date = Time.at(decline.created)
# Output the date, card id, brand, last 4, and decline message
@adamjstevenson
adamjstevenson / list_transactions_for_transfer.rb
Created October 13, 2016 04:06
List balance transactions for a specific transfer
require 'stripe'
# Your API key
Stripe.api_key = 'YOUR-API-KEY'
# Retrieve the balance transactions associated with a specific transfer
txns = Stripe::BalanceTransaction.list({ transfer: 'tr_18V4GALrKpFcM2405wrIONb9', limit: 100 })
# Iterate through and list each balance transaction
txns.auto_paging_each do | txn |
# Don't include the transfer balance transaction
@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)
@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 / 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 / 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
}