braintree 2.9.1 → 2.10.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -52,6 +52,7 @@ require File.dirname(__FILE__) + "/braintree/transaction"
52
52
  require File.dirname(__FILE__) + "/braintree/transaction/address_details"
53
53
  require File.dirname(__FILE__) + "/braintree/transaction/credit_card_details"
54
54
  require File.dirname(__FILE__) + "/braintree/transaction/customer_details"
55
+ require File.dirname(__FILE__) + "/braintree/transaction/subscription_details"
55
56
  require File.dirname(__FILE__) + "/braintree/transaction_gateway"
56
57
  require File.dirname(__FILE__) + "/braintree/transaction_search"
57
58
  require File.dirname(__FILE__) + "/braintree/transaction/status_details"
@@ -7,10 +7,10 @@ module Braintree
7
7
  module Address
8
8
  CannotBeBlank = "81801"
9
9
  CompanyIsTooLong = "81802"
10
- CountryNameIsNotAccepted = "91803"
11
10
  CountryCodeAlpha2IsNotAccepted = "91814"
12
11
  CountryCodeAlpha3IsNotAccepted = "91816"
13
12
  CountryCodeNumericIsNotAccepted = "91817"
13
+ CountryNameIsNotAccepted = "91803"
14
14
  ExtendedAddressIsTooLong = "81804"
15
15
  FirstNameIsTooLong = "81805"
16
16
  InconsistentCountry = "91815"
@@ -22,6 +22,7 @@ module Braintree
22
22
  RegionIsTooLong = "81810"
23
23
  StreetAddressIsRequired = "81811"
24
24
  StreetAddressIsTooLong = "81812"
25
+ TooManyAddressesPerCustomer = "91818"
25
26
  end
26
27
 
27
28
  # See http://www.braintreepaymentsolutions.com/docs/ruby/credit_cards/validations
@@ -42,7 +42,7 @@ module Braintree
42
42
  end
43
43
 
44
44
  attr_reader :avs_error_response_code, :avs_postal_code_response_code, :avs_street_address_response_code
45
- attr_reader :amount, :created_at, :credit_card_details, :customer_details, :id
45
+ attr_reader :amount, :created_at, :credit_card_details, :customer_details, :subscription_details, :id
46
46
  attr_reader :currency_iso_code
47
47
  attr_reader :custom_fields
48
48
  attr_reader :cvv_response_code
@@ -155,6 +155,7 @@ module Braintree
155
155
  set_instance_variables_from_hash(attributes)
156
156
  @amount = Util.to_big_decimal(amount)
157
157
  @credit_card_details = CreditCardDetails.new(@credit_card)
158
+ @subscription_details = SubscriptionDetails.new(@subscription)
158
159
  @customer_details = CustomerDetails.new(@customer)
159
160
  @billing_details = AddressDetails.new(@billing)
160
161
  @shipping_details = AddressDetails.new(@shipping)
@@ -292,7 +293,7 @@ module Braintree
292
293
  end
293
294
 
294
295
  def self._attributes # :nodoc:
295
- [:amount, :created_at, :credit_card_details, :customer_details, :id, :status, :type, :updated_at]
296
+ [:amount, :created_at, :credit_card_details, :customer_details, :id, :status, :subscription_details, :type, :updated_at]
296
297
  end
297
298
  end
298
299
  end
@@ -0,0 +1,13 @@
1
+ module Braintree
2
+ class Transaction
3
+ class SubscriptionDetails # :nodoc:
4
+ include BaseModule
5
+
6
+ attr_reader :billing_period_start_date, :billing_period_end_date
7
+
8
+ def initialize(attributes)
9
+ set_instance_variables_from_hash attributes unless attributes.nil?
10
+ end
11
+ end
12
+ end
13
+ end
@@ -99,7 +99,7 @@ module Braintree
99
99
  {
100
100
  :shipping => AddressGateway._shared_signature
101
101
  },
102
- {:options => [:store_in_vault, :submit_for_settlement, :add_billing_address_to_payment_method, :store_shipping_address_in_vault]},
102
+ {:options => [:store_in_vault, :store_in_vault_on_success, :submit_for_settlement, :add_billing_address_to_payment_method, :store_shipping_address_in_vault]},
103
103
  {:custom_fields => :_any_key_},
104
104
  {:descriptor => [:name, :phone]}
105
105
  ]
@@ -1,8 +1,8 @@
1
1
  module Braintree
2
2
  module Version
3
3
  Major = 2
4
- Minor = 9
5
- Tiny = 1
4
+ Minor = 10
5
+ Tiny = 0
6
6
 
7
7
  String = "#{Major}.#{Minor}.#{Tiny}"
8
8
  end
@@ -947,6 +947,28 @@ describe Braintree::CreditCard do
947
947
  result.transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
948
948
  result.transaction.credit_card_details.expiration_date.should == "05/2010"
949
949
  end
950
+
951
+ it "allows passing a cvv in addition to the token" do
952
+ customer = Braintree::Customer.create!(
953
+ :credit_card => {
954
+ :number => Braintree::Test::CreditCardNumbers::Visa,
955
+ :expiration_date => "05/2010"
956
+ }
957
+ )
958
+ result = Braintree::CreditCard.sale(customer.credit_cards[0].token,
959
+ :amount => "100.00",
960
+ :credit_card => {
961
+ :cvv => "301"
962
+ }
963
+ )
964
+
965
+ result.success?.should == true
966
+ result.transaction.amount.should == BigDecimal.new("100.00")
967
+ result.transaction.type.should == "sale"
968
+ result.transaction.customer_details.id.should == customer.id
969
+ result.transaction.credit_card_details.token.should == customer.credit_cards[0].token
970
+ result.transaction.cvv_response_code.should == "S"
971
+ end
950
972
  end
951
973
 
952
974
  describe "self.sale!" do
@@ -36,6 +36,20 @@ describe Braintree::Subscription do
36
36
  result.subscription.payment_method_token.should == @credit_card.token
37
37
  end
38
38
 
39
+ it "returns a transaction with billing period populated" do
40
+ result = Braintree::Subscription.create(
41
+ :payment_method_token => @credit_card.token,
42
+ :plan_id => SpecHelper::TriallessPlan[:id]
43
+ )
44
+
45
+ result.success?.should == true
46
+ subscription = result.subscription
47
+ transaction = subscription.transactions.first
48
+
49
+ transaction.subscription_details.billing_period_start_date.should == subscription.billing_period_start_date
50
+ transaction.subscription_details.billing_period_end_date.should == subscription.billing_period_end_date
51
+ end
52
+
39
53
  it "can set the id" do
40
54
  new_id = rand(36**9).to_s(36)
41
55
  result = Braintree::Subscription.create(
@@ -598,6 +598,84 @@ describe Braintree::Transaction do
598
598
  result.errors.for(:transaction).on(:purchase_order_number)[0].code.should == Braintree::ErrorCodes::Transaction::PurchaseOrderNumberIsTooLong
599
599
  end
600
600
  end
601
+
602
+ context "store_in_vault_on_success" do
603
+ context "passed as true" do
604
+ it "stores vault records when transaction succeeds" do
605
+ result = Braintree::Transaction.create(
606
+ :type => "sale",
607
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
608
+ :customer => {
609
+ :last_name => "Doe"
610
+ },
611
+ :credit_card => {
612
+ :number => Braintree::Test::CreditCardNumbers::Visa,
613
+ :expiration_date => "12/12",
614
+ },
615
+ :options => { :store_in_vault_on_success => true }
616
+ )
617
+ result.success?.should == true
618
+ result.transaction.vault_customer.last_name.should == "Doe"
619
+ result.transaction.vault_credit_card.masked_number.should == "401288******1881"
620
+ end
621
+
622
+ it "does not store vault records when true and transaction fails" do
623
+ result = Braintree::Transaction.create(
624
+ :type => "sale",
625
+ :amount => Braintree::Test::TransactionAmounts::Decline,
626
+ :customer => {
627
+ :last_name => "Doe"
628
+ },
629
+ :credit_card => {
630
+ :number => Braintree::Test::CreditCardNumbers::Visa,
631
+ :expiration_date => "12/12",
632
+ },
633
+ :options => { :store_in_vault_on_success => true }
634
+ )
635
+ result.success?.should == false
636
+ result.transaction.vault_customer.should be_nil
637
+ result.transaction.vault_credit_card.should be_nil
638
+ end
639
+ end
640
+
641
+ context "passed as false" do
642
+ it "does not store vault records when transaction succeeds" do
643
+ result = Braintree::Transaction.create(
644
+ :type => "sale",
645
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
646
+ :customer => {
647
+ :last_name => "Doe"
648
+ },
649
+ :credit_card => {
650
+ :number => Braintree::Test::CreditCardNumbers::Visa,
651
+ :expiration_date => "12/12",
652
+ },
653
+ :options => { :store_in_vault_on_success => false }
654
+ )
655
+ result.success?.should == true
656
+ result.transaction.vault_customer.should be_nil
657
+ result.transaction.vault_credit_card.should be_nil
658
+ end
659
+
660
+ it "does not store vault records when transaction fails" do
661
+ result = Braintree::Transaction.create(
662
+ :type => "sale",
663
+ :amount => Braintree::Test::TransactionAmounts::Decline,
664
+ :customer => {
665
+ :last_name => "Doe"
666
+ },
667
+ :credit_card => {
668
+ :number => Braintree::Test::CreditCardNumbers::Visa,
669
+ :expiration_date => "12/12",
670
+ },
671
+ :options => { :store_in_vault_on_success => false }
672
+ )
673
+ result.success?.should == false
674
+ result.transaction.vault_customer.should be_nil
675
+ result.transaction.vault_credit_card.should be_nil
676
+ end
677
+ end
678
+ end
601
679
  end
602
680
 
603
681
  describe "self.create!" do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: braintree
3
3
  version: !ruby/object:Gem::Version
4
- hash: 41
4
+ hash: 39
5
5
  prerelease: false
6
6
  segments:
7
7
  - 2
8
- - 9
9
- - 1
10
- version: 2.9.1
8
+ - 10
9
+ - 0
10
+ version: 2.10.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Braintree Payment Solutions
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-25 00:00:00 -05:00
18
+ date: 2011-04-26 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -77,6 +77,7 @@ files:
77
77
  - lib/braintree/transaction/credit_card_details.rb
78
78
  - lib/braintree/transaction/customer_details.rb
79
79
  - lib/braintree/transaction/status_details.rb
80
+ - lib/braintree/transaction/subscription_details.rb
80
81
  - lib/braintree/transaction.rb
81
82
  - lib/braintree/transaction_gateway.rb
82
83
  - lib/braintree/transaction_search.rb