Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

2.11.0

  • Loading branch information...
commit 96bb1196bc8d54712f72a467d82edbd60b4a3fca 1 parent 86dad78
@braintreeps braintreeps authored
View
4 CHANGELOG.rdoc
@@ -1,3 +1,7 @@
+== 2.11.0
+
+* Added SettlementBatchSummary
+
== 2.10.2
* Added support for international Maestro cards with payer authentication
View
4 lib/braintree.rb
@@ -41,8 +41,8 @@ module Braintree
require File.dirname(__FILE__) + "/braintree/errors"
require File.dirname(__FILE__) + "/braintree/gateway"
require File.dirname(__FILE__) + "/braintree/http"
-require File.dirname(__FILE__) + "/braintree/payer_authentication"
-require File.dirname(__FILE__) + "/braintree/payer_authentication_gateway"
+require File.dirname(__FILE__) + "/braintree/settlement_batch_summary"
+require File.dirname(__FILE__) + "/braintree/settlement_batch_summary_gateway"
require File.dirname(__FILE__) + "/braintree/resource_collection"
require File.dirname(__FILE__) + "/braintree/subscription"
require File.dirname(__FILE__) + "/braintree/subscription_gateway"
View
7 lib/braintree/error_codes.rb
@@ -84,6 +84,12 @@ module Descriptor
NameFormatIsInvalid = "92201"
end
+ module SettlementBatchSummary
+ CustomFieldIsInvalid = "82303"
+ SettlementDateIsInvalid = "82302"
+ SettlementDateIsRequired = "82301"
+ end
+
# See http://www.braintreepayments.com/docs/ruby/subscriptions/validations
module Subscription
BillingDayOfMonthCannotBeUpdated = "91918"
@@ -101,6 +107,7 @@ module Subscription
InconsistentStartDate = "91917"
InvalidRequestFormat = "91921"
MerchantAccountIdIsInvalid = "91901"
+ MismatchCurrencyISOCode = "91923"
NumberOfBillingCyclesCannotBeBlank = "91912"
NumberOfBillingCyclesIsTooSmall = "91909"
NumberOfBillingCyclesMustBeGreaterThanZero = "91907"
View
6 lib/braintree/error_result.rb
@@ -3,14 +3,12 @@ module Braintree
class ErrorResult
attr_reader :credit_card_verification, :transaction, :subscription, :errors, :params, :message
- attr_reader :payer_authentication
def initialize(gateway, data) # :nodoc:
@gateway = gateway
@params = data[:params]
@credit_card_verification = CreditCardVerification._new(data[:verification]) if data[:verification]
@message = data[:message]
- @payer_authentication = PayerAuthentication._new(gateway, data[:payer_authentication]) if data[:payer_authentication]
@transaction = Transaction._new(gateway, data[:transaction]) if data[:transaction]
@subscription = Subscription._new(gateway, data[:subscription]) if data[:subscription]
@errors = Errors.new(data[:errors])
@@ -26,10 +24,6 @@ def inspect # :nodoc:
"#<#{self.class} params:{...} errors:<#{@errors._inner_inspect}>#{verification_inspect}#{transaction_inspect}>"
end
- def payer_authentication_required?
- !!@payer_authentication
- end
-
# Always returns false.
def success?
false
View
4 lib/braintree/gateway.rb
@@ -24,8 +24,8 @@ def customer
CustomerGateway.new(self)
end
- def payer_authentication
- PayerAuthenticationGateway.new(self)
+ def settlement_batch_summary
+ SettlementBatchSummaryGateway.new(self)
end
def subscription
View
2  lib/braintree/http.rb
@@ -16,7 +16,7 @@ def delete(path)
def get(path)
response = _http_do Net::HTTP::Get, path
- if response.code.to_i == 200
+ if response.code.to_i == 200 || response.code.to_i == 422
Xml.hash_from_xml(_body(response))
else
Util.raise_exception_for_status_code(response.code)
View
31 lib/braintree/payer_authentication.rb
@@ -1,31 +0,0 @@
-module Braintree
- class PayerAuthentication
- include BaseModule # :nodoc:
-
- attr_reader :id, :post_params, :post_url
-
- def self.authenticate(payer_authentication_id, response_payload)
- Configuration.gateway.payer_authentication.authenticate(
- payer_authentication_id,
- response_payload
- )
- end
-
- def initialize(gateway, attributes) # :nodoc:
- @gateway = gateway
- set_instance_variables_from_hash(attributes)
-
- @post_params = (@post_params || []).map do |params|
- OpenStruct.new(:name => params[:name], :value => params[:value])
- end
- end
-
- class << self
- protected :new
- end
-
- def self._new(*args) # :nodoc:
- self.new *args
- end
- end
-end
View
25 lib/braintree/payer_authentication_gateway.rb
@@ -1,25 +0,0 @@
-module Braintree
- class PayerAuthenticationGateway # :nodoc:
- def initialize(gateway)
- @gateway = gateway
- @config = gateway.config
- end
-
- def authenticate(payer_authentication_id, response_payload)
- response = @config.http.post(
- "/payer_authentications/#{payer_authentication_id}/authenticate",
- :payer_authentication => {
- :response_payload => response_payload
- }
- )
-
- if response[:transaction]
- SuccessfulResult.new(:transaction => Transaction._new(@gateway, response[:transaction]))
- elsif response[:api_error_response]
- ErrorResult.new(@gateway, response[:api_error_response])
- else
- raise UnexpectedError, "expected :transaction or :api_error_response"
- end
- end
- end
-end
View
0  lib/braintree/settlement_batch.rb
No changes.
View
24 lib/braintree/settlement_batch_summary.rb
@@ -0,0 +1,24 @@
+module Braintree
+ class SettlementBatchSummary
+ include BaseModule
+ attr_reader :records
+
+ def self.generate(settlement_date, group_by_custom_field = nil)
+ criteria = { :settlement_date => settlement_date }
+ criteria.merge!({:group_by_custom_field => group_by_custom_field}) if group_by_custom_field
+ Configuration.gateway.settlement_batch_summary.generate(criteria)
+ end
+
+ def initialize(gateway, attributes)
+ @gateway = gateway
+ set_instance_variables_from_hash(attributes)
+ end
+
+ class << self
+ protected :new
+ def _new(*args)
+ self.new(*args)
+ end
+ end
+ end
+end
View
24 lib/braintree/settlement_batch_summary_gateway.rb
@@ -0,0 +1,24 @@
+module Braintree
+ class SettlementBatchSummaryGateway # :nodoc
+ def initialize(gateway)
+ @gateway = gateway
+ @config = gateway.config
+ end
+
+ def generate(criteria)
+ Util.verify_keys(_signature, criteria)
+ response = @config.http.post "/settlement_batch_summary", :settlement_batch_summary => criteria
+ if response[:settlement_batch_summary]
+ SuccessfulResult.new(:settlement_batch_summary => SettlementBatchSummary._new(@gateway, response[:settlement_batch_summary]))
+ elsif response[:api_error_response]
+ ErrorResult.new(@gateway, response[:api_error_response])
+ else
+ raise UnexpectedError, "expected :settlement_batch_summary or :api_error_response"
+ end
+ end
+
+ def _signature
+ [:settlement_date, :group_by_custom_field]
+ end
+ end
+end
View
4 lib/braintree/successful_result.rb
@@ -19,10 +19,6 @@ def inspect # :nodoc:
"#<#{self.class} #{inspected_attributes.join(" ")}>"
end
- def payer_authentication_required?
- false
- end
-
def success?
true
end
View
7 lib/braintree/test/credit_card_numbers.rb
@@ -25,13 +25,6 @@ module CreditCardNumbers
Visas = %w[4009348888881881 4012888888881881 4111111111111111 4000111111111115]
Unknowns = %w[1000000000000008]
- module PayerAuthentication
- ValidMaestro = "6304000000000000"
- InvalidMaestro = "6773900000000000007"
- AuthenticationSuccessfulPayload = "authentication_successful_payload"
- AuthenticationFailedPayload = "authentication_failed_payload"
- end
-
module FailsSandboxVerification
AmEx = "378734493671000"
Discover = "6011000990139424"
View
4 lib/braintree/version.rb
@@ -1,8 +1,8 @@
module Braintree
module Version
Major = 2
- Minor = 10
- Tiny = 2
+ Minor = 11
+ Tiny = 0
String = "#{Major}.#{Minor}.#{Tiny}"
end
View
61 spec/integration/braintree/settlement_batch_summary_spec.rb
@@ -0,0 +1,61 @@
+# encoding: utf-8
+require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
+
+describe Braintree::SettlementBatchSummary do
+ describe "self.generate" do
+ it "returns an empty collection if there is not data" do
+ result = Braintree::SettlementBatchSummary.generate("1979-01-01")
+ result.should be_success
+ result.settlement_batch_summary.records.size.should be_zero
+ end
+
+ it "returns an error response if the date cannot be parsed" do
+ result = Braintree::SettlementBatchSummary.generate("NOT A DATE :(")
+ result.should_not be_success
+ result.errors.for(:settlement_batch_summary).on(:settlement_date).map {|e| e.code}.should include(Braintree::ErrorCodes::SettlementBatchSummary::SettlementDateIsInvalid)
+ end
+
+ it "returns transactions settled on a given day" do
+ transaction = Braintree::Transaction.sale!(
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
+ :credit_card => {
+ :number => Braintree::Test::CreditCardNumbers::AmExes.first,
+ :expiration_date => "05/2012",
+ :cardholder_name => "Sergio Ramos"
+ },
+ :options => { :submit_for_settlement => true }
+ )
+ SpecHelper.settle_transaction transaction.id
+
+ result = Braintree::SettlementBatchSummary.generate(Time.now.strftime("%Y-%m-%d"))
+ result.should be_success
+ amex_records = result.settlement_batch_summary.records.select {|row| row[:card_type] == Braintree::CreditCard::CardType::AmEx }
+ amex_records.first[:count].to_i.should >= 1
+ amex_records.first[:amount_settled].to_i.should >= Braintree::Test::TransactionAmounts::Authorize.to_i
+ end
+
+ it "can be grouped by a custom field" do
+ transaction = Braintree::Transaction.sale!(
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
+ :credit_card => {
+ :number => Braintree::Test::CreditCardNumbers::AmExes.first,
+ :expiration_date => "05/2012",
+ :cardholder_name => "Sergio Ramos"
+ },
+ :custom_fields => {
+ :store_me => "1"
+ },
+ :options => { :submit_for_settlement => true }
+ )
+ SpecHelper.settle_transaction transaction.id
+
+ result = Braintree::SettlementBatchSummary.generate(Time.now.strftime("%Y-%m-%d"), 'store_me')
+ result.should be_success
+
+ amex_records = result.settlement_batch_summary.records.select {|row| row[:store_me] == "1" }
+ amex_records.should_not be_empty
+ amex_records.first[:count].to_i.should >= 1
+ amex_records.first[:amount_settled].to_i.should >= Braintree::Test::TransactionAmounts::Authorize.to_i
+ end
+ end
+end
View
100 spec/integration/braintree/transaction_spec.rb
@@ -152,106 +152,6 @@
codes.should include(Braintree::ErrorCodes::Address::CountryCodeNumericIsNotAccepted)
end
- context "maestro authentication" do
- it "returns an authentication response on successful lookup" do
- result = Braintree::Transaction.create(
- :type => "sale",
- :amount => Braintree::Test::TransactionAmounts::Authorize,
- :merchant_account_id => "secure_code_ma",
- :credit_card => {
- :number => Braintree::Test::CreditCardNumbers::PayerAuthentication::ValidMaestro,
- :expiration_date => "01/2012"
- }
- )
-
- result.success?.should == false
- result.payer_authentication_required?.should == true
-
- payer_authentication = result.payer_authentication
- payer_authentication.id.should match(/\A[a-z0-9]+\z/)
- payer_authentication.post_url.should match(%r{\Ahttps?://})
- payer_authentication.post_params.size.should == 1
- payer_authentication.post_params.first.name.should == "PaReq"
- payer_authentication.post_params.first.value.should_not be_empty
-
- result = Braintree::PayerAuthentication.authenticate(
- payer_authentication.id,
- Braintree::Test::CreditCardNumbers::PayerAuthentication::AuthenticationSuccessfulPayload
- )
-
- result.success?.should == true
- result.transaction.id.should =~ /^\w{6}$/
- result.transaction.type.should == "sale"
- result.transaction.amount.should == BigDecimal.new(Braintree::Test::TransactionAmounts::Authorize)
- result.transaction.processor_authorization_code.should_not be_nil
- result.transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Maestro[0, 6]
- result.transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Maestro[-4..-1]
- result.transaction.credit_card_details.expiration_date.should == "01/2012"
- result.transaction.credit_card_details.customer_location.should == "US"
- end
-
- it "attempts to create the transaction on an unsuccessful authentication" do
- result = Braintree::Transaction.create(
- :type => "sale",
- :amount => Braintree::Test::TransactionAmounts::Authorize,
- :merchant_account_id => "secure_code_ma",
- :credit_card => {
- :number => Braintree::Test::CreditCardNumbers::PayerAuthentication::ValidMaestro,
- :expiration_date => "01/2012"
- }
- )
-
- result.success?.should == false
- result.payer_authentication_required?.should == true
-
- payer_authentication = result.payer_authentication
- payer_authentication.id.should match(/\A[a-z0-9]+\z/)
- payer_authentication.post_url.should match(%r{\Ahttps?://})
- payer_authentication.post_params.size.should == 1
- payer_authentication.post_params.first.name.should == "PaReq"
- payer_authentication.post_params.first.value.should_not be_empty
-
- result = Braintree::PayerAuthentication.authenticate(
- payer_authentication.id,
- Braintree::Test::CreditCardNumbers::PayerAuthentication::AuthenticationFailedPayload
- )
-
- result.success?.should == true
- result.transaction.id.should =~ /^\w{6}$/
- result.transaction.type.should == "sale"
- result.transaction.amount.should == BigDecimal.new(Braintree::Test::TransactionAmounts::Authorize)
- result.transaction.processor_authorization_code.should_not be_nil
- result.transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Maestro[0, 6]
- result.transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Maestro[-4..-1]
- result.transaction.credit_card_details.expiration_date.should == "01/2012"
- result.transaction.credit_card_details.customer_location.should == "US"
- end
-
- it "runs a regular transaction on unsuccessful lookup" do
- cc_number = Braintree::Test::CreditCardNumbers::PayerAuthentication::InvalidMaestro
- result = Braintree::Transaction.create(
- :type => "sale",
- :amount => Braintree::Test::TransactionAmounts::Authorize,
- :merchant_account_id => "secure_code_ma",
- :credit_card => {
- :number => cc_number,
- :expiration_date => "01/2012"
- }
- )
-
- result.payer_authentication_required?.should == false
- result.success?.should == true
- result.transaction.id.should =~ /^\w{6}$/
- result.transaction.type.should == "sale"
- result.transaction.amount.should == BigDecimal.new(Braintree::Test::TransactionAmounts::Authorize)
- result.transaction.processor_authorization_code.should_not be_nil
- result.transaction.credit_card_details.bin.should == cc_number[0, 6]
- result.transaction.credit_card_details.last_4.should == cc_number[-4..-1]
- result.transaction.credit_card_details.expiration_date.should == "01/2012"
- result.transaction.credit_card_details.customer_location.should == "US"
- end
- end
-
context "gateway rejection reason" do
it "exposes the cvv gateway rejection reason" do
old_merchant = Braintree::Configuration.merchant_id
View
13 spec/unit/braintree/error_result_spec.rb
@@ -74,17 +74,4 @@
result.inspect.should_not include("transaction")
end
end
-
- describe "payer_authentication_required?" do
- it "is true if payer_authentication is in the response" do
- result = Braintree::ErrorResult.new(
- :gateway,
- :payer_authentication => {:id => "public_id", :post_url => "post_url", :post_params => []},
- :errors => {},
- :verification => nil,
- :transaction => nil
- )
- result.payer_authentication_required?.should be_true
- end
- end
end
View
38 spec/unit/braintree/payer_authentication_spec.rb
@@ -1,38 +0,0 @@
-require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
-
-describe Braintree::PayerAuthentication do
- describe "id" do
- it "returns the given id" do
- payer_authentication = Braintree::PayerAuthentication._new(
- :gateway,
- :id => :test_id
- )
-
- payer_authentication.id.should == :test_id
- end
- end
-
- describe "post_params" do
- it "returns the given post params" do
- payer_authentication = Braintree::PayerAuthentication._new(
- :gateway,
- :post_params => [{:name => 'imaname', :value => 'andimavalue'}]
- )
-
- post_param = payer_authentication.post_params.first
- post_param.name.should == 'imaname'
- post_param.value.should == 'andimavalue'
- end
- end
-
- describe "post_url" do
- it "returns the given post url" do
- payer_authentication = Braintree::PayerAuthentication._new(
- :gateway,
- :post_url => "http://example.com"
- )
-
- payer_authentication.post_url.should == "http://example.com"
- end
- end
-end
View
6 spec/unit/braintree/successful_result_spec.rb
@@ -24,10 +24,4 @@
result.inspect.should == "#<Braintree::SuccessfulResult foo:\"foo_value\">"
end
end
-
- describe "payer_authentication_required?" do
- it "is always false" do
- Braintree::SuccessfulResult.new.payer_authentication_required?.should be_false
- end
- end
end
Please sign in to comment.
Something went wrong with that request. Please try again.