Skip to content

Instantly share code, notes, and snippets.

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

Adam Stevenson adamjstevenson

🏄‍♂️
View GitHub Profile
@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 / 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_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 / 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 / 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 / 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 / metadata.php
Last active September 21, 2016 22:53
Add Stripe's processing fee and your platform application fee as metadata
<?php
$charge = \Stripe\Charge::create(array(
"amount" => $db->amount, // The total amount to charge the customer, in cents
"currency" => "usd",
"source" => $token, // The token submitted from Checkout or Stripe.js
"application_fee" => $application_fee,
"destination" => $db->connected_account_id, // The account ID, retrieved from your database
"metadata" => array(
// Calculate Stripe's processing fee based on the total charge amount
"stripe fee" => ($db->amount/100 * .029 + .30) * 100,
@adamjstevenson
adamjstevenson / create_charge_with_tiered_app_fee.php
Created September 21, 2016 22:25
Create a charge with a custom tiered application fee
<?php
// Include Stripe's library and set your API key.
require('./config.php');
// Retrieve the account ID and application fee tier details from your own database...
// In this example $db is an object containing the attributes you retrieve from your database.
// Calculate the app fee to charge based on the pricing tier
if ($db->pricing_tier == 1){
// Charge 2.9% + $.30 per charge (passing Stripe's default processing fees)
@adamjstevenson
adamjstevenson / create_charge_with_custom_app_fee.php
Last active September 21, 2016 21:52
Charge a custom application fee for a connected account
<?php
// Include Stripe's library and set your API key.
require('./config.php');
// Retrieve the amount and application fee details from your own database...
// Ex: $db is an object containing the attributes you retrieve from your database.
// Calculate the application fee to charge, in cents
$application_fee = ($db->amount/100 * $db->percent_fee + $db->flat_fee) * 100;
@adamjstevenson
adamjstevenson / config.php
Created September 21, 2016 02:58
Example Stripe PHP config file
<?php
// Including the library instead of using Composer
// Read more about installing this library here: https://github.com/stripe/stripe-php
require_once('stripe-php/init.php');
// Replace with your API keys
$stripe = array(
"secret_key" => "YOUR-SECRET-API-KEY",
"publishable_key" => "YOUR-PUBLISHABLE-API-KEY"