Skip to content

Instantly share code, notes, and snippets.

@delba
Created April 22, 2014 14:50
Show Gist options
  • Save delba/11182163 to your computer and use it in GitHub Desktop.
Save delba/11182163 to your computer and use it in GitHub Desktop.
Stripe callback
require 'json'
require 'stripe'
Stripe.api_key = 'sk_test_wEA2idIv05QuQH4RLu8hz8PA'
event = JSON.parse File.read('event.json'),
symbolize_names: true
if event[:type] == 'charge.succeeded'
charge = event[:data][:object]
id = charge[:balance_transaction]
balance = Stripe::BalanceTransaction.retrieve(id)
puts balance.fee_details
puts balance.net
recipient = 'rp_103i6Y22xTRyVwhD8yBWUioN'
transfer = Stripe::Transfer.create(
amount: balance.net,
currency: charge[:currency],
recipient: recipient,
statement_description: 'Wallet'
)
puts "TRANSFER: #{transfer}"
bt = Stripe::BalanceTransaction.retrieve(transfer.balance_transaction)
puts "BALANCE TRANSACTION: #{bt}"
end
{
"id": "evt_103i7a22xTRyVwhDYGecdwDW",
"created": 1395464817,
"livemode": false,
"type": "charge.succeeded",
"data": {
"object": {
"id": "ch_103i7a22xTRyVwhDISWa21wv",
"object": "charge",
"created": 1395464817,
"livemode": false,
"paid": true,
"amount": 1000,
"currency": "usd",
"refunded": false,
"card": {
"id": "card_103i7a22xTRyVwhDoCdJQfkH",
"object": "card",
"last4": "4242",
"type": "Visa",
"exp_month": 12,
"exp_year": 2014,
"fingerprint": "I3xlc1JLL6QNUjTB",
"customer": null,
"country": "US",
"name": null,
"address_line1": null,
"address_line2": null,
"address_city": null,
"address_state": null,
"address_zip": null,
"address_country": null,
"cvc_check": "pass",
"address_line1_check": null,
"address_zip_check": null
},
"captured": true,
"refunds": [
],
"balance_transaction": "txn_103i7a22xTRyVwhDBtMCL7sC",
"failure_message": null,
"failure_code": null,
"amount_refunded": 0,
"customer": null,
"invoice": null,
"description": "1",
"dispute": null,
"metadata": {
},
"statement_description": null
}
},
"object": "event",
"pending_webhooks": 1,
"request": "iar_3i7anI5tfMsFdz"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment