spec/integration/braintree/subscription_spec.rb in braintree-2.31.0 vs spec/integration/braintree/subscription_spec.rb in braintree-2.32.1

- old
+ new

@@ -62,30 +62,60 @@ date_format = /^\d{4}\D\d{1,2}\D\d{1,2}$/ result.success?.should == true result.subscription.id.should == new_id end - it "creates a subscription when given a payment_method_nonce" do - nonce = nonce_for_new_credit_card( - :credit_card => { - :number => Braintree::Test::CreditCardNumbers::Visa, - :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] - ) + context "with payment_method_nonces" do + it "creates a subscription when given a credit card payment_method_nonce" do + nonce = nonce_for_new_payment_method( + :credit_card => { + :number => Braintree::Test::CreditCardNumbers::Visa, + :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] + ) - result.success?.should == true - transaction = result.subscription.transactions[0] - transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6] - transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4, 4] + result.success?.should == true + transaction = result.subscription.transactions[0] + transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6] + transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4, 4] + end + + 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 + ) + + result = Braintree::Subscription.create( + :payment_method_token => payment_method_result.payment_method.token, + :plan_id => SpecHelper::TriallessPlan[:id] + ) + + result.should be_success + transaction = result.subscription.transactions[0] + transaction.paypal_details.payer_email.should == "payer@example.com" + end + + 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] + ) + + result.should_not be_success + 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( @@ -689,10 +719,10 @@ result.subscription.payment_method_token.should == new_credit_card.token end it "allows changing the payment_method by payment_method_nonce" do - nonce = nonce_for_new_credit_card( + nonce = nonce_for_new_payment_method( :credit_card => { :number => Braintree::Test::CreditCardNumbers::MasterCard, :expiration_date => "05/2010" }, :client_token_options => {