Skip to content

Instantly share code, notes, and snippets.

View MittalPatel-BTC's full-sized avatar

Mittal Patel MittalPatel-BTC

View GitHub Profile
@MittalPatel-BTC
MittalPatel-BTC / event_subscribe.rb
Last active August 25, 2019 16:36
Events subscribe
events.subscribe 'charge.dispute.', Stripe::EventHandler.new
@MittalPatel-BTC
MittalPatel-BTC / stripe.rb
Last active August 25, 2019 16:37
Configure the credential
Stripe.api_key = ENV['STRIPE_SECRET_KEY']
StripeEvent.signing_secret = ENV['STRIPE_SIGNING_SECRET']
StripeEvent.configure do |events|
events.subscribe 'charge.dispute.created', Stripe::EventHandler.new
end
@MittalPatel-BTC
MittalPatel-BTC / routes.rb
Created August 25, 2019 16:06
Add routes to handle webhook request
mount StripeEvent::Engine, at: '/stripe/webhook' # you can change this url
@MittalPatel-BTC
MittalPatel-BTC / routes.demo.rb
Created August 25, 2019 16:03
Pattern of defining route
mount StripeEvent::Engine, at: '/any-path-you-want'
@MittalPatel-BTC
MittalPatel-BTC / Gemfile
Created August 25, 2019 16:01
Installing dependency for stripe webhook
gem 'stripe_event'
@MittalPatel-BTC
MittalPatel-BTC / indifferent_access_library.rb
Created June 30, 2019 10:54
Library for indifferent_access which used when you want to access the method outside of the rails code.
require "active_support/core_ext/hash/indifferent_access"
@MittalPatel-BTC
MittalPatel-BTC / hash_with_in_different_access_ex.rb
Created June 30, 2019 10:52
Demo for how to use the ActiveSupport::HashWithIndifferentAccess method of ActiveSupport class
symbolic_hash = {a: 1, b: 2, c: 3}
string_hash = {"a" => 1, "b" => 2, "c" => 3}
new_hash = ActiveSupport::HashWithIndifferentAccess.new(symbolic_hash)
new_hash[:a] # 1
new_hash["a"] # 1
# same for other hash string_hash
new_hash = ActiveSupport::HashWithIndifferentAccess.new(string_hash)
new_hash["a"] # 1
@MittalPatel-BTC
MittalPatel-BTC / fetch_value_and_keys.rb
Created June 30, 2019 10:50
Fetching hash value and its keys
string_hash["a"] # 1
string_hash[:a] # nil
string_hash.keys # ["a", "b", "c"]
@MittalPatel-BTC
MittalPatel-BTC / fetch_keys.rb
Created June 30, 2019 10:47
Fetching keys from hash
symbolic_hash.keys # [:a, :b, :c]
@MittalPatel-BTC
MittalPatel-BTC / get_hash_value.rb
Created June 30, 2019 10:47
Retrieve hash value using its key
symbolic_hash[:a] # 1
symbolic_hash["a"] # nil