spec/integration/braintree/subscription_spec.rb in braintree-3.3.0 vs spec/integration/braintree/subscription_spec.rb in braintree-3.4.0

- old
+ new

@@ -6,19 +6,19 @@ before(:each) do @credit_card = Braintree::Customer.create!( :credit_card => { :number => Braintree::Test::CreditCardNumbers::Visa, :expiration_date => "05/2010" - } + }, ).credit_cards[0] end describe "self.create" do it "is successful with a minimum of params" do result = Braintree::Subscription.create( :payment_method_token => @credit_card.token, - :plan_id => SpecHelper::TriallessPlan[:id] + :plan_id => SpecHelper::TriallessPlan[:id], ) result.success?.should == true result.subscription.id.should =~ /^\w{6}$/ result.subscription.status.should == Braintree::Subscription::Status::Active @@ -45,11 +45,11 @@ end it "returns a transaction with billing period populated" do result = Braintree::Subscription.create( :payment_method_token => @credit_card.token, - :plan_id => SpecHelper::TriallessPlan[:id] + :plan_id => SpecHelper::TriallessPlan[:id], ) result.success?.should == true subscription = result.subscription transaction = subscription.transactions.first @@ -61,11 +61,11 @@ it "can set the id" do new_id = rand(36**9).to_s(36) result = Braintree::Subscription.create( :payment_method_token => @credit_card.token, :plan_id => SpecHelper::TrialPlan[:id], - :id => new_id + :id => new_id, ) result.success?.should == true result.subscription.id.should == new_id end @@ -78,15 +78,15 @@ :expiration_month => "11", :expiration_year => "2099", }, :client_token_options => { :customer_id => @credit_card.customer_id - } + }, ) result = Braintree::Subscription.create( :payment_method_nonce => nonce, - :plan_id => SpecHelper::TriallessPlan[:id] + :plan_id => SpecHelper::TriallessPlan[:id], ) result.success?.should == true transaction = result.subscription.transactions[0] transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6] @@ -95,16 +95,16 @@ it "creates a subscription when given a paypal account payment_method_nonce" do customer = Braintree::Customer.create! payment_method_result = Braintree::PaymentMethod.create( :payment_method_nonce => Braintree::Test::Nonce::PayPalFuturePayment, - :customer_id => customer.id + :customer_id => customer.id, ) result = Braintree::Subscription.create( :payment_method_token => payment_method_result.payment_method.token, - :plan_id => SpecHelper::TriallessPlan[:id] + :plan_id => SpecHelper::TriallessPlan[:id], ) result.should be_success transaction = result.subscription.transactions[0] transaction.paypal_details.payer_email.should == "payer@example.com" @@ -112,11 +112,11 @@ it "creates a subscription when given a paypal description" do customer = Braintree::Customer.create! payment_method_result = Braintree::PaymentMethod.create( :payment_method_nonce => Braintree::Test::Nonce::PayPalFuturePayment, - :customer_id => customer.id + :customer_id => customer.id, ) result = Braintree::Subscription.create( :payment_method_token => payment_method_result.payment_method.token, :plan_id => SpecHelper::TriallessPlan[:id], @@ -137,34 +137,34 @@ it "returns an error if the payment_method_nonce hasn't been vaulted" do customer = Braintree::Customer.create! result = Braintree::Subscription.create( :payment_method_nonce => Braintree::Test::Nonce::PayPalFuturePayment, - :plan_id => SpecHelper::TriallessPlan[:id] + :plan_id => SpecHelper::TriallessPlan[:id], ) result.should_not be_success - result.errors.for(:subscription).on(:payment_method_nonce).first.code.should == '91925' + result.errors.for(:subscription).on(:payment_method_nonce).first.code.should == "91925" end end context "billing_day_of_month" do it "inherits from the plan if not provided" do result = Braintree::Subscription.create( :payment_method_token => @credit_card.token, - :plan_id => SpecHelper::BillingDayOfMonthPlan[:id] + :plan_id => SpecHelper::BillingDayOfMonthPlan[:id], ) result.success?.should == true result.subscription.billing_day_of_month.should == 5 end it "allows overriding" do result = Braintree::Subscription.create( :payment_method_token => @credit_card.token, :plan_id => SpecHelper::BillingDayOfMonthPlan[:id], - :billing_day_of_month => 25 + :billing_day_of_month => 25, ) result.success?.should == true result.subscription.billing_day_of_month.should == 25 end @@ -173,11 +173,11 @@ result = Braintree::Subscription.create( :payment_method_token => @credit_card.token, :plan_id => SpecHelper::BillingDayOfMonthPlan[:id], :options => { :start_immediately => true - } + }, ) result.success?.should == true result.subscription.transactions.size.should == 1 end @@ -186,11 +186,11 @@ context "first_billing_date" do it "allows specifying" do result = Braintree::Subscription.create( :payment_method_token => @credit_card.token, :plan_id => SpecHelper::BillingDayOfMonthPlan[:id], - :first_billing_date => Date.today + 3 + :first_billing_date => Date.today + 3, ) result.success?.should == true result.subscription.first_billing_date.should == Date.today + 3 result.subscription.status.should == Braintree::Subscription::Status::Pending @@ -198,11 +198,11 @@ it "returns an error if the date is in the past" do result = Braintree::Subscription.create( :payment_method_token => @credit_card.token, :plan_id => SpecHelper::BillingDayOfMonthPlan[:id], - :first_billing_date => Date.today - 3 + :first_billing_date => Date.today - 3, ) result.success?.should == false result.errors.for(:subscription).on(:first_billing_date).first.code.should == Braintree::ErrorCodes::Subscription::FirstBillingDateCannotBeInThePast end @@ -210,22 +210,22 @@ context "merchant_account_id" do it "defaults to the default merchant account if no merchant_account_id is provided" do result = Braintree::Subscription.create( :payment_method_token => @credit_card.token, - :plan_id => SpecHelper::TrialPlan[:id] + :plan_id => SpecHelper::TrialPlan[:id], ) result.success?.should == true result.subscription.merchant_account_id.should == SpecHelper::DefaultMerchantAccountId end it "allows setting the merchant_account_id" do result = Braintree::Subscription.create( :payment_method_token => @credit_card.token, :plan_id => SpecHelper::TrialPlan[:id], - :merchant_account_id => SpecHelper::NonDefaultMerchantAccountId + :merchant_account_id => SpecHelper::NonDefaultMerchantAccountId, ) result.success?.should == true result.subscription.merchant_account_id.should == SpecHelper::NonDefaultMerchantAccountId end @@ -234,22 +234,22 @@ context "number_of_billing_cycles" do it "sets the number of billing cycles on the subscription when provided" do result = Braintree::Subscription.create( :payment_method_token => @credit_card.token, :plan_id => SpecHelper::TrialPlan[:id], - :number_of_billing_cycles => 10 + :number_of_billing_cycles => 10, ) result.success?.should == true result.subscription.number_of_billing_cycles.should == 10 end it "sets the number of billing cycles to nil if :never_expires => true" do result = Braintree::Subscription.create( :payment_method_token => @credit_card.token, :plan_id => SpecHelper::TrialPlan[:id], - :never_expires => true + :never_expires => true, ) result.success?.should == true result.subscription.number_of_billing_cycles.should == nil end @@ -258,22 +258,22 @@ context "trial period" do context "defaults to the plan's trial period settings" do it "with no trial" do result = Braintree::Subscription.create( :payment_method_token => @credit_card.token, - :plan_id => SpecHelper::TriallessPlan[:id] + :plan_id => SpecHelper::TriallessPlan[:id], ) result.subscription.trial_period.should == false result.subscription.trial_duration.should == nil result.subscription.trial_duration_unit.should == nil end it "with a trial" do result = Braintree::Subscription.create( :payment_method_token => @credit_card.token, - :plan_id => SpecHelper::TrialPlan[:id] + :plan_id => SpecHelper::TrialPlan[:id], ) result.subscription.trial_period.should == true result.subscription.trial_duration.should == 2 result.subscription.trial_duration_unit.should == Braintree::Subscription::TrialDurationUnit::Day @@ -282,11 +282,11 @@ it "can alter the trial period params" do result = Braintree::Subscription.create( :payment_method_token => @credit_card.token, :plan_id => SpecHelper::TrialPlan[:id], :trial_duration => 5, - :trial_duration_unit => Braintree::Subscription::TrialDurationUnit::Month + :trial_duration_unit => Braintree::Subscription::TrialDurationUnit::Month, ) result.subscription.trial_period.should == true result.subscription.trial_duration.should == 5 result.subscription.trial_duration_unit.should == Braintree::Subscription::TrialDurationUnit::Month @@ -294,31 +294,31 @@ it "can override the trial_period param" do result = Braintree::Subscription.create( :payment_method_token => @credit_card.token, :plan_id => SpecHelper::TrialPlan[:id], - :trial_period => false + :trial_period => false, ) result.subscription.trial_period.should == false end it "doesn't create a transaction if there's a trial period" do result = Braintree::Subscription.create( :payment_method_token => @credit_card.token, - :plan_id => SpecHelper::TrialPlan[:id] + :plan_id => SpecHelper::TrialPlan[:id], ) result.subscription.transactions.size.should == 0 end end context "no trial period" do it "creates a transaction if no trial period" do result = Braintree::Subscription.create( :payment_method_token => @credit_card.token, - :plan_id => SpecHelper::TriallessPlan[:id] + :plan_id => SpecHelper::TriallessPlan[:id], ) result.subscription.transactions.size.should == 1 result.subscription.transactions.first.should be_a(Braintree::Transaction) result.subscription.transactions.first.amount.should == SpecHelper::TriallessPlan[:price] @@ -328,11 +328,11 @@ it "does not create the subscription and returns the transaction if the transaction is not successful" do result = Braintree::Subscription.create( :payment_method_token => @credit_card.token, :plan_id => SpecHelper::TriallessPlan[:id], - :price => Braintree::Test::TransactionAmounts::Decline + :price => Braintree::Test::TransactionAmounts::Decline, ) result.success?.should be(false) result.transaction.status.should == Braintree::Transaction::Status::ProcessorDeclined result.message.should == "Do Not Honor" @@ -341,21 +341,21 @@ context "price" do it "defaults to the plan's price" do result = Braintree::Subscription.create( :payment_method_token => @credit_card.token, - :plan_id => SpecHelper::TrialPlan[:id] + :plan_id => SpecHelper::TrialPlan[:id], ) result.subscription.price.should == SpecHelper::TrialPlan[:price] end it "can be overridden" do result = Braintree::Subscription.create( :payment_method_token => @credit_card.token, :plan_id => SpecHelper::TrialPlan[:id], - :price => 98.76 + :price => 98.76, ) result.subscription.price.should == BigDecimal("98.76") end end @@ -364,40 +364,40 @@ context "validation errors" do it "has validation errors on id" do result = Braintree::Subscription.create( :payment_method_token => @credit_card.token, :plan_id => SpecHelper::TrialPlan[:id], - :id => "invalid token" + :id => "invalid token", ) result.success?.should == false result.errors.for(:subscription).on(:id)[0].message.should == "ID is invalid (use only letters, numbers, '-', and '_')." end it "has validation errors on duplicate id" do duplicate_token = "duplicate_token_#{rand(36**8).to_s(36)}" result = Braintree::Subscription.create( :payment_method_token => @credit_card.token, :plan_id => SpecHelper::TrialPlan[:id], - :id => duplicate_token + :id => duplicate_token, ) result.success?.should == true result = Braintree::Subscription.create( :payment_method_token => @credit_card.token, :plan_id => SpecHelper::TrialPlan[:id], - :id => duplicate_token + :id => duplicate_token, ) result.success?.should == false result.errors.for(:subscription).on(:id)[0].message.should == "ID has already been taken." end it "trial duration required" do result = Braintree::Subscription.create( :payment_method_token => @credit_card.token, :plan_id => SpecHelper::TrialPlan[:id], :trial_period => true, - :trial_duration => nil + :trial_duration => nil, ) result.success?.should == false result.errors.for(:subscription).on(:trial_duration)[0].message.should == "Trial Duration is required." end @@ -405,11 +405,11 @@ result = Braintree::Subscription.create( :payment_method_token => @credit_card.token, :plan_id => SpecHelper::TrialPlan[:id], :trial_period => true, :trial_duration => 2, - :trial_duration_unit => nil + :trial_duration_unit => nil, ) result.success?.should == false result.errors.for(:subscription).on(:trial_duration_unit)[0].message.should == "Trial Duration Unit is invalid." end end @@ -417,11 +417,11 @@ context "add_ons and discounts" do it "does not inherit the add_ons and discounts from the plan when do_not_inherit_add_ons_or_discounts is set" do result = Braintree::Subscription.create( :payment_method_token => @credit_card.token, :plan_id => SpecHelper::AddOnDiscountPlan[:id], - :options => {:do_not_inherit_add_ons_or_discounts => true} + :options => {:do_not_inherit_add_ons_or_discounts => true}, ) result.success?.should == true subscription = result.subscription @@ -430,11 +430,11 @@ end it "inherits the add_ons and discounts from the plan when not specified" do result = Braintree::Subscription.create( :payment_method_token => @credit_card.token, - :plan_id => SpecHelper::AddOnDiscountPlan[:id] + :plan_id => SpecHelper::AddOnDiscountPlan[:id], ) result.success?.should == true subscription = result.subscription @@ -494,11 +494,11 @@ :existing_id => SpecHelper::Discount7, :quantity => 3, :never_expires => true } ] - } + }, ) result.success?.should == true subscription = result.subscription @@ -540,11 +540,11 @@ :add_ons => { :remove => [SpecHelper::AddOnIncrease10] }, :discounts => { :remove => [SpecHelper::Discount7] - } + }, ) result.success?.should == true subscription = result.subscription @@ -568,11 +568,11 @@ :add_ons => { :add => [{:inherited_from_id => SpecHelper::AddOnIncrease30}] }, :discounts => { :add => [{:inherited_from_id => SpecHelper::Discount15}] - } + }, ) result.success?.should == true subscription = result.subscription subscription.add_ons.size.should == 3 @@ -619,11 +619,11 @@ { :existing_id => SpecHelper::AddOnIncrease20, :quantity => -10, } ] - } + }, ) result.success?.should == false result.errors.for(:subscription).for(:add_ons).for(:update).for_index(0).on(:amount)[0].code.should == Braintree::ErrorCodes::Subscription::Modification::AmountIsInvalid result.errors.for(:subscription).for(:add_ons).for(:update).for_index(1).on(:quantity)[0].code.should == Braintree::ErrorCodes::Subscription::Modification::QuantityIsInvalid end @@ -633,34 +633,34 @@ it "accepts name and phone and copies them to the transaction" do result = Braintree::Subscription.create( :payment_method_token => @credit_card.token, :plan_id => SpecHelper::TriallessPlan[:id], :descriptor => { - :name => '123*123456789012345678', - :phone => '3334445555' - } + :name => "123*123456789012345678", + :phone => "3334445555" + }, ) result.success?.should == true - result.subscription.descriptor.name.should == '123*123456789012345678' - result.subscription.descriptor.phone.should == '3334445555' + result.subscription.descriptor.name.should == "123*123456789012345678" + result.subscription.descriptor.phone.should == "3334445555" result.subscription.transactions.size.should == 1 transaction = result.subscription.transactions.first - transaction.descriptor.name.should == '123*123456789012345678' - transaction.descriptor.phone.should == '3334445555' + transaction.descriptor.name.should == "123*123456789012345678" + transaction.descriptor.phone.should == "3334445555" end it "has validation errors if format is invalid" do result = Braintree::Subscription.create( :payment_method_token => @credit_card.token, :plan_id => SpecHelper::TriallessPlan[:id], :descriptor => { - :name => 'badcompanyname12*badproduct12', - :phone => '%bad4445555', + :name => "badcompanyname12*badproduct12", + :phone => "%bad4445555", :url => "12345678901234" - } + }, ) result.success?.should == false result.errors.for(:subscription).for(:descriptor).on(:name)[0].code.should == Braintree::ErrorCodes::Descriptor::NameFormatIsInvalid result.errors.for(:subscription).for(:descriptor).on(:phone)[0].code.should == Braintree::ErrorCodes::Descriptor::PhoneFormatIsInvalid result.errors.for(:subscription).for(:descriptor).on(:url)[0].code.should == Braintree::ErrorCodes::Descriptor::UrlFormatIsInvalid @@ -670,11 +670,11 @@ 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] + :plan_id => SpecHelper::TriallessPlan[:id], ) subscription.id.should =~ /^\w{6}$/ subscription.status.should == Braintree::Subscription::Status::Active subscription.plan_id.should == "integration_trialless_plan" @@ -693,61 +693,61 @@ it "raises a ValidationsFailed if invalid" do expect do Braintree::Subscription.create!( :payment_method_token => @credit_card.token, - :plan_id => 'not_a_plan_id' + :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( :payment_method_token => @credit_card.token, - :plan_id => SpecHelper::TrialPlan[:id] + :plan_id => SpecHelper::TrialPlan[:id], ) result.success?.should == true Braintree::Subscription.find(result.subscription.id).should == result.subscription end it "raises Braintree::NotFoundError if it cannot find" do expect { - Braintree::Subscription.find('noSuchSubscription') + Braintree::Subscription.find("noSuchSubscription") }.to raise_error(Braintree::NotFoundError, 'subscription with id "noSuchSubscription" not found') 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] + :plan_id => SpecHelper::TriallessPlan[:id], ).subscription end it "allows changing the merchant_account_id" do result = Braintree::Subscription.update(@subscription.id, - :merchant_account_id => SpecHelper::NonDefaultMerchantAccountId + :merchant_account_id => SpecHelper::NonDefaultMerchantAccountId, ) result.success?.should == true result.subscription.merchant_account_id.should == SpecHelper::NonDefaultMerchantAccountId end it "allows changing the payment method by payment_method_token" do new_credit_card = Braintree::CreditCard.create!( :customer_id => @credit_card.customer_id, :number => Braintree::Test::CreditCardNumbers::Visa, - :expiration_date => "05/2010" + :expiration_date => "05/2010", ) result = Braintree::Subscription.update(@subscription.id, - :payment_method_token => new_credit_card.token + :payment_method_token => new_credit_card.token, ) result.subscription.payment_method_token.should == new_credit_card.token end @@ -757,65 +757,65 @@ :number => Braintree::Test::CreditCardNumbers::MasterCard, :expiration_date => "05/2010" }, :client_token_options => { :customer_id => @credit_card.customer_id, - } + }, ) result = Braintree::Subscription.update(@subscription.id, :payment_method_nonce => nonce) result.subscription.transactions[0].credit_card_details.token.should == @credit_card.token result.subscription.payment_method_token.should_not == @credit_card.token end it "allows changing the descriptors" do result = Braintree::Subscription.update(@subscription.id, :descriptor => { - :name => 'aaa*1234', - :phone => '3334443333', + :name => "aaa*1234", + :phone => "3334443333", :url => "ebay.com" - } + }, ) result.success?.should == true - result.subscription.descriptor.name.should == 'aaa*1234' - result.subscription.descriptor.phone.should == '3334443333' - result.subscription.descriptor.url.should == 'ebay.com' + result.subscription.descriptor.name.should == "aaa*1234" + result.subscription.descriptor.phone.should == "3334443333" + result.subscription.descriptor.url.should == "ebay.com" end it "allows changing the paypal description" do customer = Braintree::Customer.create! payment_method = Braintree::PaymentMethod.create( :payment_method_nonce => Braintree::Test::Nonce::PayPalFuturePayment, - :customer_id => customer.id + :customer_id => customer.id, ).payment_method subscription = Braintree::Subscription.create( :payment_method_token => payment_method.token, - :plan_id => SpecHelper::TriallessPlan[:id] + :plan_id => SpecHelper::TriallessPlan[:id], ).subscription result = Braintree::Subscription.update( subscription.id, :options => { :paypal => { - :description => 'A great product', + :description => "A great product", }, }, ) result.success?.should == true - result.subscription.description.should == 'A great product' + result.subscription.description.should == "A great product" end context "when successful" do it "returns a success response with the updated subscription if valid" do new_id = rand(36**9).to_s(36) result = Braintree::Subscription.update(@subscription.id, :id => new_id, :price => 9999.88, - :plan_id => SpecHelper::TrialPlan[:id] + :plan_id => SpecHelper::TrialPlan[:id], ) result.success?.should == true result.subscription.id.should =~ /#{new_id}/ result.subscription.plan_id.should == SpecHelper::TrialPlan[:id] @@ -823,43 +823,43 @@ end context "proration" do it "prorates if there is a charge (because merchant has proration option enabled in control panel)" do result = Braintree::Subscription.update(@subscription.id, - :price => @subscription.price.to_f + 1 + :price => @subscription.price.to_f + 1, ) result.success?.should == true result.subscription.price.to_f.should == @subscription.price.to_f + 1 result.subscription.transactions.size.should == @subscription.transactions.size + 1 end it "allows the user to force proration if there is a charge" do result = Braintree::Subscription.update(@subscription.id, :price => @subscription.price.to_f + 1, - :options => { :prorate_charges => true } + :options => {:prorate_charges => true}, ) result.success?.should == true result.subscription.price.to_f.should == @subscription.price.to_f + 1 result.subscription.transactions.size.should == @subscription.transactions.size + 1 end it "allows the user to prevent proration if there is a charge" do result = Braintree::Subscription.update(@subscription.id, :price => @subscription.price.to_f + 1, - :options => { :prorate_charges => false } + :options => {:prorate_charges => false}, ) result.success?.should == true result.subscription.price.to_f.should == @subscription.price.to_f + 1 result.subscription.transactions.size.should == @subscription.transactions.size end it "doesn't prorate if price decreases" do result = Braintree::Subscription.update(@subscription.id, - :price => @subscription.price.to_f - 1 + :price => @subscription.price.to_f - 1, ) result.success?.should == true result.subscription.price.to_f.should == @subscription.price.to_f - 1 result.subscription.transactions.size.should == @subscription.transactions.size @@ -868,11 +868,11 @@ it "updates the subscription if the proration fails and revert_subscription_on_proration_failure => false" do result = Braintree::Subscription.update(@subscription.id, :price => @subscription.price.to_f + 2100, :options => { :revert_subscription_on_proration_failure => false - } + }, ) result.success?.should == true result.subscription.price.to_f.should == @subscription.price.to_f + 2100 @@ -885,11 +885,11 @@ it "does not update the subscription if the proration fails and revert_subscription_on_proration_failure => true" do result = Braintree::Subscription.update(@subscription.id, :price => @subscription.price.to_f + 2100, :options => { :revert_subscription_on_proration_failure => true - } + }, ) result.success?.should == false result.subscription.price.to_f.should == @subscription.price.to_f @@ -903,18 +903,18 @@ context "when unsuccessful" do before(:each) do @subscription = Braintree::Subscription.create( :payment_method_token => @credit_card.token, - :plan_id => SpecHelper::TrialPlan[:id] + :plan_id => SpecHelper::TrialPlan[:id], ).subscription end it "raises NotFoundError if the subscription can't be found" do expect { Braintree::Subscription.update(rand(36**9).to_s(36), - :price => 58.20 + :price => 58.20, ) }.to raise_error(Braintree::NotFoundError) end it "has validation errors on id" do @@ -938,32 +938,32 @@ it "has validation errors on duplicate id" do duplicate_id = "new_id_#{rand(36**6).to_s(36)}" duplicate = Braintree::Subscription.create( :payment_method_token => @credit_card.token, :plan_id => SpecHelper::TrialPlan[:id], - :id => duplicate_id + :id => duplicate_id, ) result = Braintree::Subscription.update( @subscription.id, - :id => duplicate_id + :id => duplicate_id, ) result.success?.should == false result.errors.for(:subscription).on(:id)[0].code.should == Braintree::ErrorCodes::Subscription::IdIsInUse end it "cannot update a canceled subscription" do subscription = Braintree::Subscription.create( :payment_method_token => @credit_card.token, :price => 54.32, - :plan_id => SpecHelper::TriallessPlan[:id] + :plan_id => SpecHelper::TriallessPlan[:id], ).subscription result = Braintree::Subscription.cancel(subscription.id) result.success?.should == true result = Braintree::Subscription.update(subscription.id, - :price => 123.45 + :price => 123.45, ) result.success?.should == false result.errors.for(:subscription)[0].code.should == Braintree::ErrorCodes::Subscription::CannotEditCanceledSubscription end end @@ -971,31 +971,31 @@ context "number_of_billing_cycles" do it "sets the number of billing cycles on the subscription when provided" do subscription = Braintree::Subscription.create( :payment_method_token => @credit_card.token, :plan_id => SpecHelper::TriallessPlan[:id], - :number_of_billing_cycles => 10 + :number_of_billing_cycles => 10, ).subscription result = Braintree::Subscription.update( subscription.id, - :number_of_billing_cycles => 5 + :number_of_billing_cycles => 5, ) result.subscription.number_of_billing_cycles.should == 5 end it "sets the number of billing cycles to nil if :never_expires => true" do subscription = Braintree::Subscription.create( :payment_method_token => @credit_card.token, :plan_id => SpecHelper::TriallessPlan[:id], - :number_of_billing_cycles => 10 + :number_of_billing_cycles => 10, ).subscription result = Braintree::Subscription.update( subscription.id, - :never_expires => true + :never_expires => true, ) result.success?.should == true result.subscription.number_of_billing_cycles.should == nil result.subscription.never_expires?.should be(true) @@ -1004,11 +1004,11 @@ context "add_ons and discounts" do it "can update add_ons and discounts" do result = Braintree::Subscription.create( :payment_method_token => @credit_card.token, - :plan_id => SpecHelper::AddOnDiscountPlan[:id] + :plan_id => SpecHelper::AddOnDiscountPlan[:id], ) result.success?.should == true subscription = result.subscription result = Braintree::Subscription.update( @@ -1028,11 +1028,11 @@ :existing_id => subscription.discounts.first.id, :amount => BigDecimal("88.88"), :quantity => 9 } ] - } + }, ) subscription = result.subscription subscription.add_ons.size.should == 2 @@ -1049,20 +1049,20 @@ end it "allows adding new add_ons and discounts" do subscription = Braintree::Subscription.create( :payment_method_token => @credit_card.token, - :plan_id => SpecHelper::AddOnDiscountPlan[:id] + :plan_id => SpecHelper::AddOnDiscountPlan[:id], ).subscription result = Braintree::Subscription.update(subscription.id, :add_ons => { :add => [{:inherited_from_id => SpecHelper::AddOnIncrease30}] }, :discounts => { :add => [{:inherited_from_id => SpecHelper::Discount15}] - } + }, ) result.success?.should == true subscription = result.subscription @@ -1098,21 +1098,21 @@ end it "allows replacing entire set of add_ons and discounts" do subscription = Braintree::Subscription.create( :payment_method_token => @credit_card.token, - :plan_id => SpecHelper::AddOnDiscountPlan[:id] + :plan_id => SpecHelper::AddOnDiscountPlan[:id], ).subscription result = Braintree::Subscription.update(subscription.id, :add_ons => { :add => [{:inherited_from_id => SpecHelper::AddOnIncrease30}] }, :discounts => { :add => [{:inherited_from_id => SpecHelper::Discount15}] }, - :options => {:replace_all_add_ons_and_discounts => true} + :options => {:replace_all_add_ons_and_discounts => true}, ) result.success?.should == true subscription = result.subscription @@ -1128,20 +1128,20 @@ end it "allows deleting of add_ons and discounts" do subscription = Braintree::Subscription.create( :payment_method_token => @credit_card.token, - :plan_id => SpecHelper::AddOnDiscountPlan[:id] + :plan_id => SpecHelper::AddOnDiscountPlan[:id], ).subscription result = Braintree::Subscription.update(subscription.id, :add_ons => { :remove => [SpecHelper::AddOnIncrease10] }, :discounts => { :remove => [SpecHelper::Discount7] - } + }, ) result.success?.should == true subscription = result.subscription @@ -1159,31 +1159,31 @@ 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] + :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] + :plan_id => SpecHelper::TrialPlan[:id], ) subscription.id.should =~ /#{new_id}/ subscription.plan_id.should == SpecHelper::TrialPlan[:id] subscription.price.should == BigDecimal("9999.88") end it "raises a ValidationsFailed if invalid" do expect do Braintree::Subscription.update!(@subscription.id, - :plan_id => 'not_a_plan_id' + :plan_id => "not_a_plan_id", ) end.to raise_error(Braintree::ValidationsFailed) end end @@ -1191,29 +1191,29 @@ describe "self.cancel" do it "returns a success response with the updated subscription if valid" do subscription = Braintree::Subscription.create( :payment_method_token => @credit_card.token, :price => 54.32, - :plan_id => SpecHelper::TriallessPlan[:id] + :plan_id => SpecHelper::TriallessPlan[:id], ).subscription result = Braintree::Subscription.cancel(subscription.id) result.success?.should == true result.subscription.status.should == Braintree::Subscription::Status::Canceled end it "returns a validation error if record not found" do expect { - r = Braintree::Subscription.cancel('noSuchSubscription') + r = Braintree::Subscription.cancel("noSuchSubscription") }.to raise_error(Braintree::NotFoundError, 'subscription with id "noSuchSubscription" not found') end it "cannot be canceled if already canceled" do subscription = Braintree::Subscription.create( :payment_method_token => @credit_card.token, :price => 54.32, - :plan_id => SpecHelper::TriallessPlan[:id] + :plan_id => SpecHelper::TriallessPlan[:id], ).subscription result = Braintree::Subscription.cancel(subscription.id) result.success?.should == true result.subscription.status.should == Braintree::Subscription::Status::Canceled @@ -1227,11 +1227,11 @@ describe "self.cancel!" do it "returns a updated subscription if valid" do subscription = Braintree::Subscription.create!( :payment_method_token => @credit_card.token, :price => 54.32, - :plan_id => SpecHelper::TriallessPlan[:id] + :plan_id => SpecHelper::TriallessPlan[:id], ) updated_subscription = Braintree::Subscription.cancel!(subscription.id) updated_subscription.status.should == Braintree::Subscription::Status::Canceled end @@ -1242,17 +1242,17 @@ 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}" + :id => "subscription1_#{id}", ).subscription subscription_without_trial = Braintree::Subscription.create( :payment_method_token => @credit_card.token, :plan_id => SpecHelper::TriallessPlan[:id], - :id => "subscription2_#{id}" + :id => "subscription2_#{id}", ).subscription subscriptions_in_trial_period = Braintree::Subscription.search do |search| search.in_trial_period.is true end @@ -1274,11 +1274,11 @@ id = rand(36**8).to_s(36) subscription = Braintree::Subscription.create( :payment_method_token => @credit_card.token, :plan_id => SpecHelper::TrialPlan[:id], :id => "subscription1_#{id}", - :price => "11.38" + :price => "11.38", ).subscription collection = Braintree::Subscription.search do |search| search.merchant_account_id.is subscription.merchant_account_id search.price.is "11.38" @@ -1308,17 +1308,17 @@ it "works using the is operator" do id = rand(36**8).to_s(36) subscription1 = Braintree::Subscription.create( :payment_method_token => @credit_card.token, :plan_id => SpecHelper::TrialPlan[:id], - :id => "subscription1_#{id}" + :id => "subscription1_#{id}", ).subscription subscription2 = Braintree::Subscription.create( :payment_method_token => @credit_card.token, :plan_id => SpecHelper::TrialPlan[:id], - :id => "subscription2_#{id}" + :id => "subscription2_#{id}", ).subscription collection = Braintree::Subscription.search do |search| search.id.is "subscription1_#{id}" end @@ -1332,18 +1332,18 @@ it "is searchable using the is or in operator" do subscription1 = Braintree::Subscription.create( :payment_method_token => @credit_card.token, :plan_id => SpecHelper::TrialPlan[:id], :merchant_account_id => SpecHelper::DefaultMerchantAccountId, - :price => "1" + :price => "1", ).subscription subscription2 = Braintree::Subscription.create( :payment_method_token => @credit_card.token, :plan_id => SpecHelper::TrialPlan[:id], :merchant_account_id => SpecHelper::NonDefaultMerchantAccountId, - :price => "1" + :price => "1", ).subscription collection = Braintree::Subscription.search do |search| search.merchant_account_id.is SpecHelper::DefaultMerchantAccountId search.price.is "1" @@ -1365,17 +1365,17 @@ describe "plan_id" do it "works using the is operator" do trialless_subscription = Braintree::Subscription.create( :payment_method_token => @credit_card.token, :plan_id => SpecHelper::TriallessPlan[:id], - :price => "2" + :price => "2", ).subscription trial_subscription = Braintree::Subscription.create( :payment_method_token => @credit_card.token, :plan_id => SpecHelper::TrialPlan[:id], - :price => "2" + :price => "2", ).subscription collection = Braintree::Subscription.search do |search| search.plan_id.is SpecHelper::TriallessPlan[:id] search.price.is "2" @@ -1389,17 +1389,17 @@ describe "price" do it "works using the is operator" do subscription_500 = Braintree::Subscription.create( :payment_method_token => @credit_card.token, :plan_id => SpecHelper::TrialPlan[:id], - :price => "5.00" + :price => "5.00", ).subscription subscription_501 = Braintree::Subscription.create( :payment_method_token => @credit_card.token, :plan_id => SpecHelper::TrialPlan[:id], - :price => "5.01" + :price => "5.01", ).subscription collection = Braintree::Subscription.search do |search| search.price.is "5.00" end @@ -1412,17 +1412,17 @@ describe "days_past_due" do it "is backwards-compatible for 'is'" do active_subscription = Braintree::Subscription.create( :payment_method_token => @credit_card.token, :plan_id => SpecHelper::TrialPlan[:id], - :price => "6" + :price => "6", ).subscription past_due_subscription = Braintree::Subscription.create( :payment_method_token => @credit_card.token, :plan_id => SpecHelper::TrialPlan[:id], - :price => "6" + :price => "6", ).subscription SpecHelper.make_past_due(past_due_subscription, 5) collection = Braintree::Subscription.search do |search| @@ -1439,11 +1439,11 @@ end it "passes a smoke test" do subscription = Braintree::Subscription.create( :payment_method_token => @credit_card.token, - :plan_id => SpecHelper::TrialPlan[:id] + :plan_id => SpecHelper::TrialPlan[:id], ).subscription collection = Braintree::Subscription.search do |search| search.days_past_due.between 1, 20 end @@ -1459,23 +1459,23 @@ describe "billing_cycles_remaining" do it "passes a smoke test" do subscription_5 = Braintree::Subscription.create( :payment_method_token => @credit_card.token, :plan_id => SpecHelper::TrialPlan[:id], - :number_of_billing_cycles => 5 + :number_of_billing_cycles => 5, ).subscription subscription_9 = Braintree::Subscription.create( :payment_method_token => @credit_card.token, :plan_id => SpecHelper::TriallessPlan[:id], - :number_of_billing_cycles => 10 + :number_of_billing_cycles => 10, ).subscription subscription_15 = Braintree::Subscription.create( :payment_method_token => @credit_card.token, :plan_id => SpecHelper::TriallessPlan[:id], - :number_of_billing_cycles => 15 + :number_of_billing_cycles => 15, ).subscription collection = Braintree::Subscription.search do |search| search.billing_cycles_remaining.between 5, 10 end @@ -1488,16 +1488,16 @@ describe "transaction_id" do it "returns matching results" do matching_subscription = Braintree::Subscription.create( :payment_method_token => @credit_card.token, - :plan_id => SpecHelper::TriallessPlan[:id] + :plan_id => SpecHelper::TriallessPlan[:id], ).subscription non_matching_subscription = Braintree::Subscription.create( :payment_method_token => @credit_card.token, - :plan_id => SpecHelper::TriallessPlan[:id] + :plan_id => SpecHelper::TriallessPlan[:id], ).subscription collection = Braintree::Subscription.search do |search| search.transaction_id.is matching_subscription.transactions.first.id end @@ -1509,16 +1509,16 @@ describe "next_billing_date" do it "returns matching results" do matching_subscription = Braintree::Subscription.create( :payment_method_token => @credit_card.token, - :plan_id => SpecHelper::TriallessPlan[:id] + :plan_id => SpecHelper::TriallessPlan[:id], ).subscription non_matching_subscription = Braintree::Subscription.create( :payment_method_token => @credit_card.token, - :plan_id => SpecHelper::TrialPlan[:id] + :plan_id => SpecHelper::TrialPlan[:id], ).subscription five_days_from_now = Time.now + (5 * 24 * 60 * 60) collection = Braintree::Subscription.search do |search| search.next_billing_date >= five_days_from_now @@ -1531,11 +1531,11 @@ context "created_at" do before(:each) do @subscription = Braintree::Subscription.create( :payment_method_token => @credit_card.token, - :plan_id => SpecHelper::TriallessPlan[:id] + :plan_id => SpecHelper::TriallessPlan[:id], ).subscription @created_at = @subscription.created_at end it "searches on created_at in UTC using between" do @@ -1543,11 +1543,11 @@ collection = Braintree::Subscription.search do |search| search.id.is @subscription.id search.created_at.between( @created_at - 60, - @created_at + 60 + @created_at + 60, ) end collection.maximum_size.should == 1 collection.first.id.should == @subscription.id @@ -1576,11 +1576,11 @@ it "searches on created_at in UTC and finds nothing" do collection = Braintree::Subscription.search do |search| search.id.is @subscription.id search.created_at.between( @created_at + 300, - @created_at + 400 + @created_at + 400, ) end collection.maximum_size.should == 0 end @@ -1600,11 +1600,11 @@ collection = Braintree::Subscription.search do |search| search.id.is @subscription.id search.created_at.between( now - 60, - now + 60 + now + 60, ) end collection.maximum_size.should == 1 collection.first.id.should == @subscription.id @@ -1639,11 +1639,11 @@ collection = Braintree::Subscription.search do |search| search.id.is @subscription.id search.created_at.between( now + 300, - now + 400 + now + 400, ) end collection.maximum_size.should == 0 end @@ -1651,11 +1651,11 @@ it "searches on created_at with dates" do collection = Braintree::Subscription.search do |search| search.id.is @subscription.id search.created_at.between( Date.today - 1, - Date.today + 1 + Date.today + 1, ) end collection.maximum_size.should == 1 collection.first.id.should == @subscription.id @@ -1668,20 +1668,20 @@ end collection = Braintree::Subscription.search collection.maximum_size.should > 100 - subscriptions_ids = collection.map {|t| t.id }.uniq.compact + subscriptions_ids = collection.map { |t| t.id }.uniq.compact subscriptions_ids.size.should == collection.maximum_size end end describe "self.retry_charge" do it "is successful with only subscription id" do subscription = Braintree::Subscription.create( :payment_method_token => @credit_card.token, - :plan_id => SpecHelper::TriallessPlan[:id] + :plan_id => SpecHelper::TriallessPlan[:id], ).subscription SpecHelper.make_past_due(subscription) result = Braintree::Subscription.retry_charge(subscription.id) @@ -1695,11 +1695,11 @@ end it "is successful with subscription id and amount" do subscription = Braintree::Subscription.create( :payment_method_token => @credit_card.token, - :plan_id => SpecHelper::TriallessPlan[:id] + :plan_id => SpecHelper::TriallessPlan[:id], ).subscription SpecHelper.make_past_due(subscription) result = Braintree::Subscription.retry_charge(subscription.id, Braintree::Test::TransactionAmounts::Authorize) @@ -1713,11 +1713,11 @@ end it "is successful with subscription id and submit_for_settlement" do subscription = Braintree::Subscription.create( :payment_method_token => @credit_card.token, - :plan_id => SpecHelper::TriallessPlan[:id] + :plan_id => SpecHelper::TriallessPlan[:id], ).subscription SpecHelper.make_past_due(subscription) result = Braintree::Subscription.retry_charge(subscription.id, Braintree::Test::TransactionAmounts::Authorize, true) @@ -1731,10 +1731,10 @@ end it "is successful with subscription id, amount and submit_for_settlement" do subscription = Braintree::Subscription.create( :payment_method_token => @credit_card.token, - :plan_id => SpecHelper::TriallessPlan[:id] + :plan_id => SpecHelper::TriallessPlan[:id], ).subscription SpecHelper.make_past_due(subscription) result = Braintree::Subscription.retry_charge(subscription.id, Braintree::Test::TransactionAmounts::Authorize, true)