spec/integration/braintree/subscription_spec.rb in braintree-2.0.0 vs spec/integration/braintree/subscription_spec.rb in braintree-2.1.0
- old
+ new
@@ -15,13 +15,10 @@
:id => "integration_trialless_plan",
:price => BigDecimal.new("12.34"),
:trial_period => false
}
- DefaultMerchantAccountId = "sandbox_credit_card"
- NonDefaultMerchantAccountId = "sandbox_credit_card_non_default"
-
before(:each) do
@credit_card = Braintree::Customer.create!(
:credit_card => {
:number => Braintree::Test::CreditCardNumbers::Visa,
:expiration_date => "05/2010"
@@ -70,22 +67,22 @@
:payment_method_token => @credit_card.token,
:plan_id => TriallessPlan[:id]
)
result.success?.should == true
- result.subscription.merchant_account_id.should == DefaultMerchantAccountId
+ 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 => TriallessPlan[:id],
- :merchant_account_id => NonDefaultMerchantAccountId
+ :merchant_account_id => SpecHelper::NonDefaultMerchantAccountId
)
result.success?.should == true
- result.subscription.merchant_account_id.should == NonDefaultMerchantAccountId
+ result.subscription.merchant_account_id.should == SpecHelper::NonDefaultMerchantAccountId
end
end
context "trial period" do
context "defaults to the plan's trial period settings" do
@@ -261,15 +258,15 @@
end
context "merchant_account_id" do
it "allows changing the merchant_account_id" do
result = Braintree::Subscription.update(@subscription.id,
- :merchant_account_id => NonDefaultMerchantAccountId
+ :merchant_account_id => SpecHelper::NonDefaultMerchantAccountId
)
result.success?.should == true
- result.subscription.merchant_account_id.should == NonDefaultMerchantAccountId
+ result.subscription.merchant_account_id.should == SpecHelper::NonDefaultMerchantAccountId
end
end
context "when successful" do
it "returns a success response with the updated subscription if valid" do
@@ -612,8 +609,42 @@
collection.should include(subscription1)
collection.should include(subscription2)
end
end
+ end
+ end
+
+ describe "self.retry_charge" do
+ it "is successful with only subscription id" do
+ subscription = Braintree::Subscription.search do |search|
+ search.status.in Braintree::Subscription::Status::PastDue
+ end.first
+
+ result = Braintree::Subscription.retry_charge(subscription.id)
+
+ result.success?.should == true
+ transaction = result.transaction
+
+ transaction.amount.should == subscription.price
+ transaction.processor_authorization_code.should_not be_nil
+ transaction.type.should == Braintree::Transaction::Type::Sale
+ transaction.status.should == Braintree::Transaction::Status::Authorized
+ end
+
+ it "is successful with subscription id and amount" do
+ subscription = Braintree::Subscription.search do |search|
+ search.status.in Braintree::Subscription::Status::PastDue
+ end.first
+
+ result = Braintree::Subscription.retry_charge(subscription.id, Braintree::Test::TransactionAmounts::Authorize)
+
+ result.success?.should == true
+ transaction = result.transaction
+
+ transaction.amount.should == BigDecimal.new(Braintree::Test::TransactionAmounts::Authorize)
+ transaction.processor_authorization_code.should_not be_nil
+ transaction.type.should == Braintree::Transaction::Type::Sale
+ transaction.status.should == Braintree::Transaction::Status::Authorized
end
end
end