Skip to content

Commit

Permalink
2.71.0
Browse files Browse the repository at this point in the history
  • Loading branch information
braintreeps committed Jan 10, 2017
1 parent 5896e2c commit 4247c3a
Show file tree
Hide file tree
Showing 13 changed files with 180 additions and 17 deletions.
24 changes: 14 additions & 10 deletions CHANGELOG.rdoc
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
== 2.71.0
* Allow optional configuration of SSL version
* Add functionality to list all merchant accounts for a merchant with `merchant_account.all`

== 2.70.0
* Bugfix: Update UsBank tests to use legal routing numbers
* Add option `skip_advanced_fraud_check` for transaction flows
* Add IdealPayment class with `sale` and `find` methods
* Add option +skip_advanced_fraud_check+ for transaction flows
* Add IdealPayment class with +sale+ and +find+ methods
* Add payer_status accessor to paypal_details object

== 2.69.1
* Bugfix: Allow PaymentMethod.find(token) to return `UsBankAccount`
* Bugfix: Allow PaymentMethod.find(token) to return +UsBankAccount+

== 2.69.0
* Add `default?` support for `UsBankAccount`
* Add `ach_mandate` data to `UsBankAccount` and `UsBankAccountDetails`
* Add +default?+ support for +UsBankAccount+
* Add +ach_mandate+ data to +UsBankAccount+ and +UsBankAccountDetails+

== 2.68.2
* Bugfix: allow Customer#payment_methods to return UsBankAccounts
Expand Down Expand Up @@ -51,9 +55,9 @@
* Fix compatibility in specs with Ruby 1.8.7

== 2.61.0
* Add transaction `UpdateDetails`
* Add transaction +UpdateDetails+
* Support for Too Many Requests response codes
* Add `default?` method to MerchantAccount
* Add +default?+ method to MerchantAccount

== 2.60.0
* Allow Coinbase account to be updated
Expand All @@ -69,7 +73,7 @@

== 2.57.0
* Add Verification#create
* Add options to `submit_for_settlement` transaction flows
* Add options to +submit_for_settlement+ transaction flows
* Upgrade libxml-ruby version to 2.8.0
* Update https certificate bundle

Expand Down Expand Up @@ -112,8 +116,8 @@
== 2.49.0
* Remove Amex Pay with Points response from Transaction.sale response
* Add expired? method to Apple Pay card
* Add customer_id property to `AndroidPayCard`, `ApplePayCard`, `CoinbaseAccount`, `EuropeBankAccount`, `PaypalAccount`, and `UnknownPaymentMethod`
* Add new error `ProcessorDoesNotSupportAuths`
* Add customer_id property to +AndroidPayCard+, +ApplePayCard+, +CoinbaseAccount+, +EuropeBankAccount+, +PaypalAccount+, and +UnknownPaymentMethod+
* Add new error +ProcessorDoesNotSupportAuths+

== 2.48.1
* Fix issue in TestTransaction spec
Expand Down
2 changes: 1 addition & 1 deletion README.rdoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
= Braintree Ruby Client Library
= Braintree Ruby Server Library

The Braintree gem provides integration access to the Braintree Gateway.

Expand Down
2 changes: 2 additions & 0 deletions lib/braintree.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@
require "braintree/settlement_batch_summary"
require "braintree/settlement_batch_summary_gateway"
require "braintree/resource_collection"
require "braintree/paginated_collection"
require "braintree/paginated_result"
require "braintree/europe_bank_account"
require "braintree/europe_bank_account_gateway"
require "braintree/us_bank_account"
Expand Down
9 changes: 6 additions & 3 deletions lib/braintree/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class Configuration
:proxy_address,
:proxy_port,
:proxy_user,
:proxy_pass
:proxy_pass,
:ssl_version
]

WRITABLE_ATTRIBUTES = [
Expand All @@ -33,7 +34,8 @@ class Configuration
:proxy_address,
:proxy_port,
:proxy_user,
:proxy_pass
:proxy_pass,
:ssl_version
]

class << self
Expand Down Expand Up @@ -81,7 +83,8 @@ def self.instantiate # :nodoc:
:proxy_address => proxy_address,
:proxy_port => proxy_port,
:proxy_user => proxy_user,
:proxy_pass => proxy_pass
:proxy_pass => proxy_pass,
:ssl_version => ssl_version
)
end

Expand Down
1 change: 1 addition & 0 deletions lib/braintree/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def _http_do(http_verb, path, body = nil)
connection.read_timeout = @config.http_read_timeout
if @config.ssl?
connection.use_ssl = true
connection.ssl_version = @config.ssl_version if @config.ssl_version
connection.verify_mode = OpenSSL::SSL::VERIFY_PEER
connection.ca_file = @config.ca_file
connection.verify_callback = proc { |preverify_ok, ssl_context| _verify_ssl_certificate(preverify_ok, ssl_context) }
Expand Down
12 changes: 12 additions & 0 deletions lib/braintree/merchant_account_gateway.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ def initialize(gateway)
@config.assert_has_access_token_or_keys
end

def all
pc = PaginatedCollection.new { |page| _fetch_merchant_accounts(page) }
SuccessfulResult.new(:merchant_accounts => pc)
end

def _fetch_merchant_accounts(page_number)
response = @config.http.get("#{@config.base_merchant_path}/merchant_accounts?page=#{page_number}")
body = response[:merchant_accounts]
merchant_accounts = Util.extract_attribute_as_array(body, :merchant_account).map { |merchant_account| MerchantAccount._new(@gateway, merchant_account) }
PaginatedResult.new(body[:total_items], body[:page_size], merchant_accounts)
end

def create(attributes)
signature = MerchantAccountGateway._detect_signature(attributes)
Util.verify_keys(signature, attributes)
Expand Down
25 changes: 25 additions & 0 deletions lib/braintree/paginated_collection.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module Braintree
class PaginatedCollection # :nodoc:
include Enumerable

def initialize(&block) # :nodoc:
@next_page_block = block
end

def each(&block)
current_page = 0
total_items = 0

loop do
current_page += 1

result = @next_page_block.call(current_page)
total_items = result.total_items

result.current_page.each(&block)

break if current_page * result.page_size >= total_items
end
end
end
end
13 changes: 13 additions & 0 deletions lib/braintree/paginated_result.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module Braintree
class PaginatedResult
include BaseModule

attr_reader :total_items, :current_page, :page_size

def initialize(total_items, page_size, current_page) # :nodoc:
@total_items = total_items
@current_page = current_page
@page_size = page_size
end
end
end
2 changes: 1 addition & 1 deletion lib/braintree/successful_result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Braintree
class SuccessfulResult
include BaseModule

attr_reader :address, :credit_card, :customer, :merchant_account, :payment_method, :settlement_batch_summary, :subscription, :new_transaction, :transaction, :payment_method_nonce, :credentials, :merchant, :supported_networks, :paypal_account
attr_reader :address, :credit_card, :customer, :merchant_account, :payment_method, :settlement_batch_summary, :subscription, :new_transaction, :transaction, :payment_method_nonce, :credentials, :merchant, :supported_networks, :paypal_account, :merchant_accounts

def initialize(attributes = {}) # :nodoc:
@attrs = attributes.keys
Expand Down
2 changes: 1 addition & 1 deletion lib/braintree/version.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Braintree
module Version
Major = 2
Minor = 70
Minor = 71
Tiny = 0

String = "#{Major}.#{Minor}.#{Tiny}"
Expand Down
34 changes: 34 additions & 0 deletions spec/integration/braintree/http_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,40 @@
end
end

describe "ssl_version" do
it "causes failed requests to sandbox with incompatible SSL version" do
begin
original_env = Braintree::Configuration.environment
Braintree::Configuration.environment = :sandbox
Braintree::Configuration.ssl_version = :TLSv1
Braintree::Configuration.stub(:base_merchant_path).and_return("/")

expect do
Braintree::Configuration.instantiate.http._http_do(Net::HTTP::Get, "/login")
end.to raise_error(Braintree::SSLCertificateError)
ensure
Braintree::Configuration.environment = original_env
Braintree::Configuration.ssl_version = nil
end
end

it "results in successful requests to sandbox with up-to-date SSL version" do
begin
original_env = Braintree::Configuration.environment
Braintree::Configuration.environment = :sandbox
Braintree::Configuration.ssl_version = :TLSv1_2
Braintree::Configuration.stub(:base_merchant_path).and_return("/")

expect do
Braintree::Configuration.instantiate.http._http_do(Net::HTTP::Get, "/login")
end.to_not raise_error
ensure
Braintree::Configuration.environment = original_env
Braintree::Configuration.ssl_version = nil
end
end
end

describe "ssl verification" do
it "rejects when the certificate isn't verified by our certificate authority (self-signed)" do
begin
Expand Down
55 changes: 55 additions & 0 deletions spec/integration/braintree/merchant_account_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,61 @@
}

describe Braintree::MerchantAccount do
describe "all" do
it "returns all merchant accounts" do
gateway = Braintree::Gateway.new(
:client_id => "client_id$#{Braintree::Configuration.environment}$integration_client_id",
:client_secret => "client_secret$#{Braintree::Configuration.environment}$integration_client_secret",
:logger => Logger.new("/dev/null")
)

code = Braintree::OAuthTestHelper.create_grant(gateway, {
:merchant_public_id => "integration_merchant_id",
:scope => "read_write"
})

result = gateway.oauth.create_token_from_code(
:code => code,
:scope => "read_write"
)

gateway = Braintree::Gateway.new(
:access_token => result.credentials.access_token,
:logger => Logger.new("/dev/null")
)

result = gateway.merchant_account.all
result.should be_success
result.merchant_accounts.count.should > 20
end

it "returns merchant account with correct attributes" do
gateway = Braintree::Gateway.new(
:client_id => "client_id$#{Braintree::Configuration.environment}$integration_client_id",
:client_secret => "client_secret$#{Braintree::Configuration.environment}$integration_client_secret",
:logger => Logger.new("/dev/null")
)

result = gateway.merchant.create(
:email => "name@email.com",
:country_code_alpha3 => "USA",
:payment_methods => ["credit_card", "paypal"]
)

gateway = Braintree::Gateway.new(
:access_token => result.credentials.access_token,
:logger => Logger.new("/dev/null")
)

result = gateway.merchant_account.all
result.should be_success
result.merchant_accounts.count.should == 1
result.merchant_accounts.first.currency_iso_code.should == "USD"
result.merchant_accounts.first.status.should == "active"
result.merchant_accounts.first.default.should == true
end
end

describe "create" do
it "accepts the deprecated parameters" do
result = Braintree::MerchantAccount.create(DEPRECATED_APPLICATION_PARAMS)
Expand Down
16 changes: 15 additions & 1 deletion spec/unit/braintree/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@
config.proxy_user.should == 'user'
config.proxy_pass.should == 'test'
end

it "accepts ssl version" do
config = Braintree::Configuration.new(
:ssl_version => :TLSv1_2
)

config.ssl_version.should == :TLSv1_2
end
end

describe "base_merchant_path" do
Expand Down Expand Up @@ -162,6 +170,13 @@
gateway.config.proxy_user.should == "user"
gateway.config.proxy_pass.should == "test"
end

it "sets the ssl version" do
Braintree::Configuration.ssl_version = :TLSv1_2
gateway = Braintree::Configuration.gateway

gateway.config.ssl_version.should == :TLSv1_2
end
end

describe "self.environment=" do
Expand Down Expand Up @@ -289,7 +304,6 @@
Braintree::Configuration.environment = :sandbox
Braintree::Configuration.instantiate.protocol.should == "https"
end

end

describe "server" do
Expand Down

0 comments on commit 4247c3a

Please sign in to comment.