Included Modules

Class/Module Index [+]

Quicksearch

ActiveMerchant::Billing::BraintreeBlueGateway

Public Class Methods

new(options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/braintree_blue.rb, line 18
def initialize(options = {})
  requires!(options, :merchant_id, :public_key, :private_key)
  @options = options
  @merchant_account_id = options[:merchant_account_id]
  Braintree::Configuration.merchant_id = options[:merchant_id]
  Braintree::Configuration.public_key = options[:public_key]
  Braintree::Configuration.private_key = options[:private_key]
  Braintree::Configuration.environment = (options[:environment] || (test? ? :sandbox : :production)).to_sym
  Braintree::Configuration.logger.level = Logger::ERROR if Braintree::Configuration.logger
  Braintree::Configuration.custom_user_agent = "ActiveMerchant #{ActiveMerchant::VERSION}"
  super
end

Public Instance Methods

authorize(money, credit_card_or_vault_id, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/braintree_blue.rb, line 31
def authorize(money, credit_card_or_vault_id, options = {})
  create_transaction(:sale, money, credit_card_or_vault_id, options)
end
capture(money, authorization, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/braintree_blue.rb, line 35
def capture(money, authorization, options = {})
  commit do
    result = Braintree::Transaction.submit_for_settlement(authorization, amount(money).to_s)
    Response.new(result.success?, message_from_result(result))
  end
end
credit(money, credit_card_or_vault_id, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/braintree_blue.rb, line 46
def credit(money, credit_card_or_vault_id, options = {})
  create_transaction(:credit, money, credit_card_or_vault_id, options)
end
delete(customer_vault_id) click to toggle source
Alias for: unstore
purchase(money, credit_card_or_vault_id, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/braintree_blue.rb, line 42
def purchase(money, credit_card_or_vault_id, options = {})
  authorize(money, credit_card_or_vault_id, options.merge(:submit_for_settlement => true))
end
refund(*args) click to toggle source
# File lib/active_merchant/billing/gateways/braintree_blue.rb, line 50
def refund(*args)
  # legacy signature: #refund(transaction_id, options = {})
  # new signature: #refund(money, transaction_id, options = {})
  money, transaction_id, options = extract_refund_args(args)
  money = amount(money).to_s if money

  commit do
    result = Braintree::Transaction.refund(transaction_id, money)
    Response.new(result.success?, message_from_result(result),
      {:braintree_transaction => (transaction_hash(result.transaction) if result.success?)},
      {:authorization => (result.transaction.id if result.success?)}
     )
  end
end
store(creditcard, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/braintree_blue.rb, line 75
def store(creditcard, options = {})
  commit do
    result = Braintree::Customer.create(
      :first_name => creditcard.first_name,
      :last_name => creditcard.last_name,
      :email => options[:email],
      :credit_card => {
        :number => creditcard.number,
        :cvv => creditcard.verification_value,
        :expiration_month => creditcard.month.to_s.rjust(2, "0"),
        :expiration_year => creditcard.year.to_s
      }
    )
    Response.new(result.success?, message_from_result(result),
      {
        :braintree_customer => (customer_hash(result.customer) if result.success?),
        :customer_vault_id => (result.customer.id if result.success?)
      }
    )
  end
end
unstore(customer_vault_id) click to toggle source
# File lib/active_merchant/billing/gateways/braintree_blue.rb, line 124
def unstore(customer_vault_id)
  commit do
    Braintree::Customer.delete(customer_vault_id)
    Response.new(true, "OK")
  end
end
Also aliased as: delete
update(vault_id, creditcard, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/braintree_blue.rb, line 97
def update(vault_id, creditcard, options = {})
  braintree_credit_card = nil
  customer_update_result = commit do
    braintree_credit_card = Braintree::Customer.find(vault_id).credit_cards.detect { |cc| cc.default? }
    return Response.new(false, 'Braintree::NotFoundError') if braintree_credit_card.nil?
    result = Braintree::Customer.update(vault_id,
      :first_name => creditcard.first_name,
      :last_name => creditcard.last_name,
      :email => options[:email]
    )
    Response.new(result.success?, message_from_result(result),
      :braintree_customer => (customer_hash(Braintree::Customer.find(vault_id)) if result.success?)
    )
  end
  return customer_update_result unless customer_update_result.success?
  credit_card_update_result = commit do
    result = Braintree::CreditCard.update(braintree_credit_card.token,
        :number => creditcard.number,
        :expiration_month => creditcard.month.to_s.rjust(2, "0"),
        :expiration_year => creditcard.year.to_s
    )
    Response.new(result.success?, message_from_result(result),
      :braintree_customer => (customer_hash(Braintree::Customer.find(vault_id)) if result.success?)
    )
  end
end
void(authorization, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/braintree_blue.rb, line 65
def void(authorization, options = {})
  commit do
    result = Braintree::Transaction.void(authorization)
    Response.new(result.success?, message_from_result(result),
      {:braintree_transaction => (transaction_hash(result.transaction) if result.success?)},
      {:authorization => (result.transaction.id if result.success?)}
    )
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.