Permalink
Browse files

2.6.2

  • Loading branch information...
braintreeps committed Nov 5, 2010
1 parent efde418 commit bd0c618d9707329557c4adfe457e1018011d5be4
View
@@ -1,3 +1,8 @@
+== 2.6.2
+
+* Added billing_address_id to allowed parameters for credit cards create and update
+* Allow searching on subscriptions that are currently in a trial period using in_trial_period
+
== 2.6.1
* Now supports ruby 1.9.1 and 1.9.2
View
@@ -73,6 +73,7 @@ PID_FILE = "/tmp/gateway_server_#{GATEWAY_PORT}.pid"
task :prep_gateway do
Dir.chdir(GATEWAY_ROOT) do
+ sh "rvm system exec rake log:clear"
sh "git pull"
sh "env RAILS_ENV=integration #{CRUISE_BUILD} rvm system exec rake db:migrate:reset --trace"
sh "env RAILS_ENV=integration #{CRUISE_BUILD} rvm system exec ruby script/populate_data"
@@ -76,7 +76,8 @@ def self._update_signature # :nodoc:
def self._signature(type) # :nodoc:
billing_address_params = AddressGateway._shared_signature
signature = [
- :cardholder_name, :cvv, :expiration_date, :expiration_month, :expiration_year, :number, :token,
+ :billing_address_id, :cardholder_name, :cvv, :expiration_date,
+ :expiration_month, :expiration_year, :number, :token,
{:options => [:make_default, :verification_merchant_account_id, :verify_card]},
{:billing_address => billing_address_params}
]
@@ -38,6 +38,10 @@ def self.create(attributes)
Configuration.gateway.subscription.create(attributes)
end
+ def self.create!(attributes)
+ return_object_or_raise(:subscription) { create(attributes) }
+ end
+
# See http://www.braintreepaymentsolutions.com/docs/ruby/subscriptions/search
def self.find(id)
Configuration.gateway.subscription.find(id)
@@ -57,6 +61,10 @@ def self.update(subscription_id, attributes)
Configuration.gateway.subscription.update(subscription_id, attributes)
end
+ def self.update!(subscription_id, attributes)
+ return_object_or_raise(:subscription) { update(subscription_id, attributes) }
+ end
+
def initialize(gateway, attributes) # :nodoc:
@gateway = gateway
set_instance_variables_from_hash(attributes)
@@ -1,5 +1,6 @@
module Braintree
class SubscriptionSearch < AdvancedSearch # :nodoc:
+ multiple_value_field :in_trial_period
multiple_value_field :ids
text_fields :id
multiple_value_or_text_field :plan_id
@@ -22,7 +22,7 @@ module Status
Failed = 'failed'
ProcessorDeclined = 'processor_declined'
Settled = 'settled'
- SettlementFailed = 'settlement_failed'
+ Settling = 'settling'
SubmittedForSettlement = 'submitted_for_settlement'
Voided = 'voided'
View
@@ -2,7 +2,7 @@ module Braintree
module Version
Major = 2
Minor = 6
- Tiny = 1
+ Tiny = 2
String = "#{Major}.#{Minor}.#{Tiny}"
end
@@ -57,6 +57,22 @@
credit_card.expiration_date.should == "05/2009"
end
+ it "accepts billing_address_id" do
+ customer = Braintree::Customer.create!
+ address = Braintree::Address.create!(:customer_id => customer.id, :first_name => "Bobby", :last_name => "Tables")
+
+ credit_card = Braintree::CreditCard.create(
+ :customer_id => customer.id,
+ :number => Braintree::Test::CreditCardNumbers::FailsSandboxVerification::Visa,
+ :expiration_date => "05/2009",
+ :billing_address_id => address.id
+ ).credit_card
+
+ credit_card.billing_address.id.should == address.id
+ credit_card.billing_address.first_name.should == "Bobby"
+ credit_card.billing_address.last_name.should == "Tables"
+ end
+
it "verifies the credit card if options[verify_card]=true" do
customer = Braintree::Customer.create!
result = Braintree::CreditCard.create(
@@ -744,6 +744,30 @@
credit_card.billing_address.postal_code.should == "60666"
end
+ it "can update the nested billing address with billing_address_id" do
+ customer = Braintree::Customer.create!
+
+ address = Braintree::Address.create!(
+ :customer_id => customer.id,
+ :first_name => "John",
+ :last_name => "Doe"
+ )
+
+ customer = Braintree::Customer.update(
+ customer.id,
+ :credit_card => {
+ :number => Braintree::Test::CreditCardNumbers::Visa,
+ :expiration_date => "12/2009",
+ :billing_address_id => address.id
+ }
+ ).customer
+
+ billing_address = customer.credit_cards.first.billing_address
+ billing_address.id.should == address.id
+ billing_address.first_name.should == "John"
+ billing_address.last_name.should == "Doe"
+ end
+
it "returns an error response if invalid" do
customer = Braintree::Customer.create!(:email => "valid@email.com")
result = Braintree::Customer.update(
@@ -522,6 +522,40 @@
end
end
+ describe "self.create!" do
+ it "returns the subscription if valid" do
+ subscription = Braintree::Subscription.create!(
+ :payment_method_token => @credit_card.token,
+ :plan_id => SpecHelper::TriallessPlan[:id]
+ )
+
+ date_format = /^\d{4}\D\d{1,2}\D\d{1,2}$/
+ subscription.id.should =~ /^\w{6}$/
+ subscription.status.should == Braintree::Subscription::Status::Active
+ subscription.plan_id.should == "integration_trialless_plan"
+
+ subscription.first_billing_date.should match(date_format)
+ subscription.next_billing_date.should match(date_format)
+ subscription.billing_period_start_date.should match(date_format)
+ subscription.billing_period_end_date.should match(date_format)
+ subscription.paid_through_date.should match(date_format)
+
+ subscription.failure_count.should == 0
+ subscription.next_bill_amount.should == "12.34"
+ subscription.next_billing_period_amount.should == "12.34"
+ subscription.payment_method_token.should == @credit_card.token
+ end
+
+ it "raises a ValidationsFailed if invalid" do
+ expect do
+ Braintree::Subscription.create!(
+ :payment_method_token => @credit_card.token,
+ :plan_id => 'not_a_plan_id'
+ )
+ end.to raise_error(Braintree::ValidationsFailed)
+ end
+ end
+
describe "self.find" do
it "finds a subscription" do
result = Braintree::Subscription.create(
@@ -921,6 +955,38 @@
end
end
+ describe "self.update!" do
+ before(:each) do
+ @subscription = Braintree::Subscription.create(
+ :payment_method_token => @credit_card.token,
+ :price => 54.32,
+ :plan_id => SpecHelper::TriallessPlan[:id]
+ ).subscription
+ end
+
+ it "returns the updated subscription if valid" do
+ new_id = rand(36**9).to_s(36)
+ subscription = Braintree::Subscription.update!(@subscription.id,
+ :id => new_id,
+ :price => 9999.88,
+ :plan_id => SpecHelper::TrialPlan[:id]
+ )
+
+ subscription.id.should =~ /#{new_id}/
+ subscription.plan_id.should == SpecHelper::TrialPlan[:id]
+ subscription.price.should == BigDecimal.new("9999.88")
+ end
+
+ it "raises a ValidationsFailed if invalid" do
+ expect do
+ Braintree::Subscription.update!(@subscription.id,
+ :plan_id => 'not_a_plan_id'
+ )
+ end.to raise_error(Braintree::ValidationsFailed)
+ end
+
+ end
+
describe "self.cancel" do
it "returns a success response with the updated subscription if valid" do
subscription = Braintree::Subscription.create(
@@ -958,6 +1024,37 @@
end
describe "self.search" do
+ describe "in_trial_period" do
+ it "works in the affirmative" do
+ id = rand(36**8).to_s(36)
+ subscription_with_trial = Braintree::Subscription.create(
+ :payment_method_token => @credit_card.token,
+ :plan_id => SpecHelper::TrialPlan[:id],
+ :id => "subscription1_#{id}"
+ ).subscription
+
+ subscription_without_trial = Braintree::Subscription.create(
+ :payment_method_token => @credit_card.token,
+ :plan_id => SpecHelper::TriallessPlan[:id],
+ :id => "subscription2_#{id}"
+ ).subscription
+
+ subscriptions_in_trial_period = Braintree::Subscription.search do |search|
+ search.in_trial_period.is true
+ end
+
+ subscriptions_in_trial_period.should include(subscription_with_trial)
+ subscriptions_in_trial_period.should_not include(subscription_without_trial)
+
+ subscriptions_not_in_trial_period = Braintree::Subscription.search do |search|
+ search.in_trial_period.is false
+ end
+
+ subscriptions_not_in_trial_period.should_not include(subscription_with_trial)
+ subscriptions_not_in_trial_period.should include(subscription_without_trial)
+ end
+ end
+
describe "id" do
it "works using the is operator" do
id = rand(36**8).to_s(36)
@@ -12,6 +12,7 @@
describe "self.create_signature" do
it "should be what we expect" do
Braintree::CreditCardGateway._create_signature.should == [
+ :billing_address_id,
:cardholder_name,
:cvv,
:expiration_date,
@@ -42,6 +43,7 @@
describe "self.update_signature" do
it "should be what we expect" do
Braintree::CreditCardGateway._update_signature.should == [
+ :billing_address_id,
:cardholder_name,
:cvv,
:expiration_date,
@@ -61,6 +61,7 @@
:phone,
:website,
{:credit_card => [
+ :billing_address_id,
:cardholder_name,
:cvv,
:expiration_date,
@@ -101,6 +102,7 @@
:phone,
:website,
{:credit_card => [
+ :billing_address_id,
:cardholder_name,
:cvv,
:expiration_date,
@@ -17,6 +17,22 @@ module Braintree
end
end
+ context "in_trial_period" do
+ it "allows true" do
+ search = SubscriptionSearch.new
+ search.in_trial_period.is true
+
+ search.to_hash.should == {:in_trial_period => [true]}
+ end
+
+ it "allows false" do
+ search = SubscriptionSearch.new
+ search.in_trial_period.is false
+
+ search.to_hash.should == {:in_trial_period => [false]}
+ end
+ end
+
context "days_past_due" do
it "correctly builds a hash with the criteria" do
search = SubscriptionSearch.new

0 comments on commit bd0c618

Please sign in to comment.