Module: Pay::Braintree

Extended by:
Env
Defined in:
lib/pay/braintree.rb,
lib/pay/braintree/error.rb,
lib/pay/braintree/charge.rb,
lib/pay/braintree/billable.rb,
lib/pay/braintree/subscription.rb,
lib/pay/braintree/payment_method.rb,
lib/pay/braintree/authorization_error.rb,
lib/pay/braintree/webhooks/subscription_expired.rb,
lib/pay/braintree/webhooks/subscription_canceled.rb,
lib/pay/braintree/webhooks/subscription_trial_ended.rb,
lib/pay/braintree/webhooks/subscription_went_active.rb,
lib/pay/braintree/webhooks/subscription_went_past_due.rb,
lib/pay/braintree/webhooks/subscription_charged_successfully.rb,
lib/pay/braintree/webhooks/subscription_charged_unsuccessfully.rb

Defined Under Namespace

Modules: Webhooks Classes: AuthorizationError, Billable, Charge, Error, PaymentMethod, Subscription

Class Method Summary collapse

Class Method Details

.configure_webhooksObject



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/pay/braintree.rb', line 53

def self.configure_webhooks
  Pay::Webhooks.configure do |events|
    events.subscribe "braintree.subscription_canceled", Pay::Braintree::Webhooks::SubscriptionCanceled.new
    events.subscribe "braintree.subscription_charged_successfully", Pay::Braintree::Webhooks::SubscriptionChargedSuccessfully.new
    events.subscribe "braintree.subscription_charged_unsuccessfully", Pay::Braintree::Webhooks::SubscriptionChargedUnsuccessfully.new
    events.subscribe "braintree.subscription_expired", Pay::Braintree::Webhooks::SubscriptionExpired.new
    events.subscribe "braintree.subscription_trial_ended", Pay::Braintree::Webhooks::SubscriptionTrialEnded.new
    events.subscribe "braintree.subscription_went_active", Pay::Braintree::Webhooks::SubscriptionWentActive.new
    events.subscribe "braintree.subscription_went_past_due", Pay::Braintree::Webhooks::SubscriptionWentPastDue.new
  end
end

.enabled?Boolean

Returns:

  • (Boolean)


22
23
24
25
26
# File 'lib/pay/braintree.rb', line 22

def self.enabled?
  return false unless Pay.enabled_processors.include?(:braintree) && defined?(::Braintree)

  Pay::Engine.version_matches?(required: "~> 4", current: ::Braintree::Version::String) || (raise "[Pay] braintree gem must be version ~> 4")
end

.environmentObject



49
50
51
# File 'lib/pay/braintree.rb', line 49

def self.environment
  find_value_by_name(:braintree, :environment) || "sandbox"
end

.merchant_idObject



45
46
47
# File 'lib/pay/braintree.rb', line 45

def self.merchant_id
  find_value_by_name(:braintree, :merchant_id)
end

.private_keyObject



41
42
43
# File 'lib/pay/braintree.rb', line 41

def self.private_key
  find_value_by_name(:braintree, :private_key)
end

.public_keyObject



37
38
39
# File 'lib/pay/braintree.rb', line 37

def self.public_key
  find_value_by_name(:braintree, :public_key)
end

.setupObject



28
29
30
31
32
33
34
35
# File 'lib/pay/braintree.rb', line 28

def self.setup
  Pay.braintree_gateway = ::Braintree::Gateway.new(
    environment: environment.to_sym,
    merchant_id: merchant_id,
    public_key: public_key,
    private_key: private_key
  )
end