Skip to content

Instantly share code, notes, and snippets.

@andrewnelder
Last active August 16, 2016 02:40
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 andrewnelder/e637db3b9ec65b8877e966432b104ba5 to your computer and use it in GitHub Desktop.
Save andrewnelder/e637db3b9ec65b8877e966432b104ba5 to your computer and use it in GitHub Desktop.
# Create an Account
acc = stripe.Account.create(email="platformcharge@test.test", managed=True)
# Destination Charge
ch = stripe.Charge.create(destination=acc.id, description="platform charge", amount=2000, application_fee=1000, currency="usd", source=gentok())
ref = stripe.Refund.create(charge=ch.id, amount=1500, refund_application_fee=True, reverse_transfer=True)
ch = stripe.Charge.retrieve(ch.id, expand=["balance_transaction", "application_fee", "transfer"])
ref = stripe.Refund.retrieve(ref.id, expand=["balance_transaction"])
stripe_fee = -1 * ref.balance_transaction.fee # on the platform account
platform_total = ch.application_fee.amount_refunded - stripe_fee
connected_total = ch.transfer.amount_reversed - ch.application_fee.amount_refunded
print " Stripe Fee: ", stripe_fee
print " Platform Total: ", platform_total
print "Connected Account Total: ", connected_total
# Direct Charge
ch = stripe.Charge.create(description="connected account charge", amount=2000, application_fee=1000, currency="usd", source=gentok(), stripe_account=acc.id)
ref = stripe.Refund.create(charge=ch.id, amount=1500, refund_application_fee=True, stripe_account=acc.id)
ch = stripe.Charge.retrieve(ch.id, expand=["balance_transaction", "application_fee", "transfer"], stripe_account=acc.id)
ref = stripe.Refund.retrieve(ref.id, expand=["balance_transaction"], stripe_account=acc.id)
stripe_fee = -1 * ref.balance_transaction.fee # on the connected account
platform_total = ch.application_fee.amount_refunded
connected_total = ch.amount_refunded - ch.application_fee.amount_refunded - stripe_fee
print " Stripe Fee: ", stripe_fee
print " Platform Total: ", platform_total
print "Connected Account Total: ", connected_total
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment