Module: Pay::Braintree

Extended by:
Env
Defined in:
lib/pay/braintree.rb,
app/models/pay/braintree/charge.rb,
app/models/pay/braintree/customer.rb,
app/models/pay/braintree/subscription.rb,
app/models/pay/braintree/payment_method.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, Charge, Customer, Error, PaymentMethod, Subscription

Class Method Summary collapse

Class Method Details

.configure_webhooksObject



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/pay/braintree.rb', line 72

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)


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

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



68
69
70
# File 'lib/pay/braintree.rb', line 68

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

.merchant_idObject



64
65
66
# File 'lib/pay/braintree.rb', line 64

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

.private_keyObject



60
61
62
# File 'lib/pay/braintree.rb', line 60

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

.public_keyObject



56
57
58
# File 'lib/pay/braintree.rb', line 56

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

.setupObject



47
48
49
50
51
52
53
54
# File 'lib/pay/braintree.rb', line 47

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