spec/integration/braintree/subscription_spec.rb in braintree-2.5.2 vs spec/integration/braintree/subscription_spec.rb in braintree-2.6.0
- old
+ new
@@ -26,13 +26,15 @@
result.subscription.first_billing_date.should match(date_format)
result.subscription.next_billing_date.should match(date_format)
result.subscription.billing_period_start_date.should match(date_format)
result.subscription.billing_period_end_date.should match(date_format)
+ result.subscription.paid_through_date.should match(date_format)
result.subscription.failure_count.should == 0
result.subscription.next_bill_amount.should == "12.34"
+ result.subscription.next_billing_period_amount.should == "12.34"
result.subscription.payment_method_token.should == @credit_card.token
end
it "can set the id" do
new_id = rand(36**9).to_s(36)
@@ -583,50 +585,86 @@
result.subscription.id.should =~ /#{new_id}/
result.subscription.plan_id.should == SpecHelper::TrialPlan[:id]
result.subscription.price.should == BigDecimal.new("9999.88")
end
- 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
- )
+ 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
+ )
- 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
+ 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 }
- )
+ 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 }
+ )
- 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
+ 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 }
- )
+ 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 }
+ )
- result.success?.should == true
- result.subscription.price.to_f.should == @subscription.price.to_f + 1
- result.subscription.transactions.size.should == @subscription.transactions.size
- end
+ 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
- )
+ it "doesn't prorate if price decreases" do
+ result = Braintree::Subscription.update(@subscription.id,
+ :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
+ 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 "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
+
+ result.subscription.transactions.size.should == @subscription.transactions.size + 1
+ transaction = result.subscription.transactions.first
+ transaction.status.should == Braintree::Transaction::Status::ProcessorDeclined
+ result.subscription.balance.should == transaction.amount
+ end
+
+ 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
+
+ result.subscription.transactions.size.should == @subscription.transactions.size + 1
+ transaction = result.subscription.transactions.first
+ transaction.status.should == Braintree::Transaction::Status::ProcessorDeclined
+ result.subscription.balance.should == 0
+ end
end
end
context "when unsuccessful" do
before(:each) do
@@ -1048,9 +1086,10 @@
collection.should include(past_due_subscription)
collection.should_not include(active_subscription)
collection.each do |s|
s.status.should == Braintree::Subscription::Status::PastDue
+ s.balance.should == BigDecimal.new("6.00")
end
end
it "passes a smoke test" do
subscription = Braintree::Subscription.create(