Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
86dad78
commit 96bb119
Showing
19 changed files
with
127 additions
and
237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
spec/integration/braintree/settlement_batch_summary_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.