diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index 0a872f73..7e687310 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -1,3 +1,15 @@ +== 2.6.0 + +* Added ability to perform multiple partial refunds on Transactions +* Deprecated Transaction refund_id in favor of refund_ids +* Added Braintree::Address::CountryNames, a list of the country names/codes that the gateway accepts (thanks r38y[http://github.com/r38y]) +* Added revert_subscription_on_proration_failure flag to Subscription update that specifies how a Subscription should react to a failed proration charge +* Deprecated Subscription next_bill_amount in favor of next_billing_period_amount +* Added new fields to Subscription: + * balance + * paid_through_date + * next_billing_period_amount + == 2.5.2 * removed ssl expiration check diff --git a/lib/braintree.rb b/lib/braintree.rb index 39009e97..8a08e47f 100644 --- a/lib/braintree.rb +++ b/lib/braintree.rb @@ -22,6 +22,7 @@ module Braintree require "braintree/modification" require "braintree/add_on" +require "braintree/address/country_names" require "braintree/address" require "braintree/address_gateway" require "braintree/advanced_search" diff --git a/lib/braintree/address.rb b/lib/braintree/address.rb index 3f992fbd..be754db1 100644 --- a/lib/braintree/address.rb +++ b/lib/braintree/address.rb @@ -43,13 +43,13 @@ def ==(other) # :nodoc: # Deprecated. Use Braintree::Address.delete def delete - warn "[DEPRECATED] delete as an instance method is deprecated. Please use CreditCard.delete" + warn "[DEPRECATED] delete as an instance method is deprecated. Please use Address.delete" @gateway.address.delete(customer_id, self.id) end # Deprecated. Use Braintree::Address.update def update(attributes) - warn "[DEPRECATED] update as an instance method is deprecated. Please use CreditCard.update" + warn "[DEPRECATED] update as an instance method is deprecated. Please use Address.update" result = @gateway.address.update(customer_id, id, attributes) if result.success? copy_instance_variables_from_object result.address @@ -59,7 +59,7 @@ def update(attributes) # Deprecated. Use Braintree::Address.update! def update!(attributes) - warn "[DEPRECATED] update! as an instance method is deprecated. Please use CreditCard.update!" + warn "[DEPRECATED] update! as an instance method is deprecated. Please use Address.update!" return_object_or_raise(:address) { update(attributes) } end diff --git a/lib/braintree/address/country_names.rb b/lib/braintree/address/country_names.rb new file mode 100644 index 00000000..bd39e72d --- /dev/null +++ b/lib/braintree/address/country_names.rb @@ -0,0 +1,251 @@ +module Braintree + class Address + CountryNames = [ + ["Afghanistan", "AF", "AFG", "004"], + ["Åland", "AX", "ALA", "248"], + ["Albania", "AL", "ALB", "008"], + ["Algeria", "DZ", "DZA", "012"], + ["American Samoa", "AS", "ASM", "016"], + ["Andorra", "AD", "AND", "020"], + ["Angola", "AO", "AGO", "024"], + ["Anguilla", "AI", "AIA", "660"], + ["Antarctica", "AQ", "ATA", "010"], + ["Antigua and Barbuda", "AG", "ATG", "028"], + ["Argentina", "AR", "ARG", "032"], + ["Armenia", "AM", "ARM", "051"], + ["Aruba", "AW", "ABW", "533"], + ["Australia", "AU", "AUS", "036"], + ["Austria", "AT", "AUT", "040"], + ["Azerbaijan", "AZ", "AZE", "031"], + ["Bahamas", "BS", "BHS", "044"], + ["Bahrain", "BH", "BHR", "048"], + ["Bangladesh", "BD", "BGD", "050"], + ["Barbados", "BB", "BRB", "052"], + ["Belarus", "BY", "BLR", "112"], + ["Belgium", "BE", "BEL", "056"], + ["Belize", "BZ", "BLZ", "084"], + ["Benin", "BJ", "BEN", "204"], + ["Bermuda", "BM", "BMU", "060"], + ["Bhutan", "BT", "BTN", "064"], + ["Bolivia", "BO", "BOL", "068"], + ["Bosnia and Herzegovina", "BA", "BIH", "070"], + ["Botswana", "BW", "BWA", "072"], + ["Bouvet Island", "BV", "BVT", "074"], + ["Brazil", "BR", "BRA", "076"], + ["British Indian Ocean Territory", "IO", "IOT", "086"], + ["Brunei Darussalam", "BN", "BRN", "096"], + ["Bulgaria", "BG", "BGR", "100"], + ["Burkina Faso", "BF", "BFA", "854"], + ["Burundi", "BI", "BDI", "108"], + ["Cambodia", "KH", "KHM", "116"], + ["Cameroon", "CM", "CMR", "120"], + ["Canada", "CA", "CAN", "124"], + ["Cape Verde", "CV", "CPV", "132"], + ["Cayman Islands", "KY", "CYM", "136"], + ["Central African Republic", "CF", "CAF", "140"], + ["Chad", "TD", "TCD", "148"], + ["Chile", "CL", "CHL", "152"], + ["China", "CN", "CHN", "156"], + ["Christmas Island", "CX", "CXR", "162"], + ["Cocos (Keeling) Islands", "CC", "CCK", "166"], + ["Colombia", "CO", "COL", "170"], + ["Comoros", "KM", "COM", "174"], + ["Congo (Brazzaville)", "CG", "COG", "178"], + ["Congo (Kinshasa)", "CD", "COD", "180"], + ["Cook Islands", "CK", "COK", "184"], + ["Costa Rica", "CR", "CRI", "188"], + ["Côte d'Ivoire", "CI", "CIV", "384"], + ["Croatia", "HR", "HRV", "191"], + ["Cuba", "CU", "CUB", "192"], + ["Cyprus", "CY", "CYP", "196"], + ["Czech Republic", "CZ", "CZE", "203"], + ["Denmark", "DK", "DNK", "208"], + ["Djibouti", "DJ", "DJI", "262"], + ["Dominica", "DM", "DMA", "212"], + ["Dominican Republic", "DO", "DOM", "214"], + ["Ecuador", "EC", "ECU", "218"], + ["Egypt", "EG", "EGY", "818"], + ["El Salvador", "SV", "SLV", "222"], + ["Equatorial Guinea", "GQ", "GNQ", "226"], + ["Eritrea", "ER", "ERI", "232"], + ["Estonia", "EE", "EST", "233"], + ["Ethiopia", "ET", "ETH", "231"], + ["Falkland Islands", "FK", "FLK", "238"], + ["Faroe Islands", "FO", "FRO", "234"], + ["Fiji", "FJ", "FJI", "242"], + ["Finland", "FI", "FIN", "246"], + ["France", "FR", "FRA", "250"], + ["French Guiana", "GF", "GUF", "254"], + ["French Polynesia", "PF", "PYF", "258"], + ["French Southern Lands", "TF", "ATF", "260"], + ["Gabon", "GA", "GAB", "266"], + ["Gambia", "GM", "GMB", "270"], + ["Georgia", "GE", "GEO", "268"], + ["Germany", "DE", "DEU", "276"], + ["Ghana", "GH", "GHA", "288"], + ["Gibraltar", "GI", "GIB", "292"], + ["Greece", "GR", "GRC", "300"], + ["Greenland", "GL", "GRL", "304"], + ["Grenada", "GD", "GRD", "308"], + ["Guadeloupe", "GP", "GLP", "312"], + ["Guam", "GU", "GUM", "316"], + ["Guatemala", "GT", "GTM", "320"], + ["Guernsey", "GG", "GGY", "831"], + ["Guinea", "GN", "GIN", "324"], + ["Guinea-Bissau", "GW", "GNB", "624"], + ["Guyana", "GY", "GUY", "328"], + ["Haiti", "HT", "HTI", "332"], + ["Heard and McDonald Islands", "HM", "HMD", "334"], + ["Honduras", "HN", "HND", "340"], + ["Hong Kong", "HK", "HKG", "344"], + ["Hungary", "HU", "HUN", "348"], + ["Iceland", "IS", "ISL", "352"], + ["India", "IN", "IND", "356"], + ["Indonesia", "ID", "IDN", "360"], + ["Iran", "IR", "IRN", "364"], + ["Iraq", "IQ", "IRQ", "368"], + ["Ireland", "IE", "IRL", "372"], + ["Isle of Man", "IM", "IMN", "833"], + ["Israel", "IL", "ISR", "376"], + ["Italy", "IT", "ITA", "380"], + ["Jamaica", "JM", "JAM", "388"], + ["Japan", "JP", "JPN", "392"], + ["Jersey", "JE", "JEY", "832"], + ["Jordan", "JO", "JOR", "400"], + ["Kazakhstan", "KZ", "KAZ", "398"], + ["Kenya", "KE", "KEN", "404"], + ["Kiribati", "KI", "KIR", "296"], + ["Korea, North", "KP", "PRK", "408"], + ["Korea, South", "KR", "KOR", "410"], + ["Kuwait", "KW", "KWT", "414"], + ["Kyrgyzstan", "KG", "KGZ", "417"], + ["Laos", "LA", "LAO", "418"], + ["Latvia", "LV", "LVA", "428"], + ["Lebanon", "LB", "LBN", "422"], + ["Lesotho", "LS", "LSO", "426"], + ["Liberia", "LR", "LBR", "430"], + ["Libya", "LY", "LBY", "434"], + ["Liechtenstein", "LI", "LIE", "438"], + ["Lithuania", "LT", "LTU", "440"], + ["Luxembourg", "LU", "LUX", "442"], + ["Macau", "MO", "MAC", "446"], + ["Macedonia", "MK", "MKD", "807"], + ["Madagascar", "MG", "MDG", "450"], + ["Malawi", "MW", "MWI", "454"], + ["Malaysia", "MY", "MYS", "458"], + ["Maldives", "MV", "MDV", "462"], + ["Mali", "ML", "MLI", "466"], + ["Malta", "MT", "MLT", "470"], + ["Marshall Islands", "MH", "MHL", "584"], + ["Martinique", "MQ", "MTQ", "474"], + ["Mauritania", "MR", "MRT", "478"], + ["Mauritius", "MU", "MUS", "480"], + ["Mayotte", "YT", "MYT", "175"], + ["Mexico", "MX", "MEX", "484"], + ["Micronesia", "FM", "FSM", "583"], + ["Moldova", "MD", "MDA", "498"], + ["Monaco", "MC", "MCO", "492"], + ["Mongolia", "MN", "MNG", "496"], + ["Montenegro", "ME", "MNE", "499"], + ["Montserrat", "MS", "MSR", "500"], + ["Morocco", "MA", "MAR", "504"], + ["Mozambique", "MZ", "MOZ", "508"], + ["Myanmar", "MM", "MMR", "104"], + ["Namibia", "NA", "NAM", "516"], + ["Nauru", "NR", "NRU", "520"], + ["Nepal", "NP", "NPL", "524"], + ["Netherlands", "NL", "NLD", "528"], + ["Netherlands Antilles", "AN", "ANT", "530"], + ["New Caledonia", "NC", "NCL", "540"], + ["New Zealand", "NZ", "NZL", "554"], + ["Nicaragua", "NI", "NIC", "558"], + ["Niger", "NE", "NER", "562"], + ["Nigeria", "NG", "NGA", "566"], + ["Niue", "NU", "NIU", "570"], + ["Norfolk Island", "NF", "NFK", "574"], + ["Northern Mariana Islands", "MP", "MNP", "580"], + ["Norway", "NO", "NOR", "578"], + ["Oman", "OM", "OMN", "512"], + ["Pakistan", "PK", "PAK", "586"], + ["Palau", "PW", "PLW", "585"], + ["Palestine", "PS", "PSE", "275"], + ["Panama", "PA", "PAN", "591"], + ["Papua New Guinea", "PG", "PNG", "598"], + ["Paraguay", "PY", "PRY", "600"], + ["Peru", "PE", "PER", "604"], + ["Philippines", "PH", "PHL", "608"], + ["Pitcairn", "PN", "PCN", "612"], + ["Poland", "PL", "POL", "616"], + ["Portugal", "PT", "PRT", "620"], + ["Puerto Rico", "PR", "PRI", "630"], + ["Qatar", "QA", "QAT", "634"], + ["Reunion", "RE", "REU", "638"], + ["Romania", "RO", "ROU", "642"], + ["Russian Federation", "RU", "RUS", "643"], + ["Rwanda", "RW", "RWA", "646"], + ["Saint Barthélemy", "BL", "BLM", "652"], + ["Saint Helena", "SH", "SHN", "654"], + ["Saint Kitts and Nevis", "KN", "KNA", "659"], + ["Saint Lucia", "LC", "LCA", "662"], + ["Saint Martin (French part)", "MF", "MAF", "663"], + ["Saint Pierre and Miquelon", "PM", "SPM", "666"], + ["Saint Vincent and the Grenadines", "VC", "VCT", "670"], + ["Samoa", "WS", "WSM", "882"], + ["San Marino", "SM", "SMR", "674"], + ["Sao Tome and Principe", "ST", "STP", "678"], + ["Saudi Arabia", "SA", "SAU", "682"], + ["Senegal", "SN", "SEN", "686"], + ["Serbia", "RS", "SRB", "688"], + ["Seychelles", "SC", "SYC", "690"], + ["Sierra Leone", "SL", "SLE", "694"], + ["Singapore", "SG", "SGP", "702"], + ["Slovakia", "SK", "SVK", "703"], + ["Slovenia", "SI", "SVN", "705"], + ["Solomon Islands", "SB", "SLB", "090"], + ["Somalia", "SO", "SOM", "706"], + ["South Africa", "ZA", "ZAF", "710"], + ["South Georgia and South Sandwich Islands", "GS", "SGS", "239"], + ["Spain", "ES", "ESP", "724"], + ["Sri Lanka", "LK", "LKA", "144"], + ["Sudan", "SD", "SDN", "736"], + ["Suriname", "SR", "SUR", "740"], + ["Svalbard and Jan Mayen Islands", "SJ", "SJM", "744"], + ["Swaziland", "SZ", "SWZ", "748"], + ["Sweden", "SE", "SWE", "752"], + ["Switzerland", "CH", "CHE", "756"], + ["Syria", "SY", "SYR", "760"], + ["Taiwan", "TW", "TWN", "158"], + ["Tajikistan", "TJ", "TJK", "762"], + ["Tanzania", "TZ", "TZA", "834"], + ["Thailand", "TH", "THA", "764"], + ["Timor-Leste", "TL", "TLS", "626"], + ["Togo", "TG", "TGO", "768"], + ["Tokelau", "TK", "TKL", "772"], + ["Tonga", "TO", "TON", "776"], + ["Trinidad and Tobago", "TT", "TTO", "780"], + ["Tunisia", "TN", "TUN", "788"], + ["Turkey", "TR", "TUR", "792"], + ["Turkmenistan", "TM", "TKM", "795"], + ["Turks and Caicos Islands", "TC", "TCA", "796"], + ["Tuvalu", "TV", "TUV", "798"], + ["Uganda", "UG", "UGA", "800"], + ["Ukraine", "UA", "UKR", "804"], + ["United Arab Emirates", "AE", "ARE", "784"], + ["United Kingdom", "GB", "GBR", "826"], + ["United States Minor Outlying Islands", "UM", "UMI", "581"], + ["United States of America", "US", "USA", "840"], + ["Uruguay", "UY", "URY", "858"], + ["Uzbekistan", "UZ", "UZB", "860"], + ["Vanuatu", "VU", "VUT", "548"], + ["Vatican City", "VA", "VAT", "336"], + ["Venezuela", "VE", "VEN", "862"], + ["Vietnam", "VN", "VNM", "704"], + ["Virgin Islands, British", "VG", "VGB", "092"], + ["Virgin Islands, U.S.", "VI", "VIR", "850"], + ["Wallis and Futuna Islands", "WF", "WLF", "876"], + ["Western Sahara", "EH", "ESH", "732"], + ["Yemen", "YE", "YEM", "887"], + ["Zambia", "ZM", "ZMB", "894"], + ["Zimbabwe", "ZW", "ZWE", "716"]] + end +end \ No newline at end of file diff --git a/lib/braintree/customer.rb b/lib/braintree/customer.rb index 985ab481..2a22167d 100644 --- a/lib/braintree/customer.rb +++ b/lib/braintree/customer.rb @@ -134,7 +134,7 @@ def inspect # :nodoc: # # See http://www.braintreepaymentsolutions.com/docs/ruby/transactions/create_from_vault def sale(transaction_attributes) - warn "[DEPRECATED] sale as an instance method is deprecated. Please use CreditCard.sale" + warn "[DEPRECATED] sale as an instance method is deprecated. Please use Customer.sale" @gateway.transaction.sale(transaction_attributes.merge(:customer_id => id)) end @@ -142,7 +142,7 @@ def sale(transaction_attributes) # # See http://www.braintreepaymentsolutions.com/docs/ruby/transactions/create_from_vault def sale!(transaction_attributes) - warn "[DEPRECATED] sale! as an instance method is deprecated. Please use CreditCard.sale!" + warn "[DEPRECATED] sale! as an instance method is deprecated. Please use Customer.sale!" return_object_or_raise(:transaction) { sale(transaction_attributes) } end @@ -155,7 +155,7 @@ def transactions(options = {}) # # See http://www.braintreepaymentsolutions.com/docs/ruby/customers/update def update(attributes) - warn "[DEPRECATED] update as an instance method is deprecated. Please use CreditCard.update" + warn "[DEPRECATED] update as an instance method is deprecated. Please use Customer.update" result = @gateway.customer.update(id, attributes) if result.success? copy_instance_variables_from_object result.customer @@ -167,7 +167,7 @@ def update(attributes) # # See http://www.braintreepaymentsolutions.com/docs/ruby/customers/update def update!(attributes) - warn "[DEPRECATED] update! as an instance method is deprecated. Please use CreditCard.update!" + warn "[DEPRECATED] update! as an instance method is deprecated. Please use Customer.update!" return_object_or_raise(:customer) { update(attributes) } end diff --git a/lib/braintree/error_codes.rb b/lib/braintree/error_codes.rb index fd892efd..b994db25 100644 --- a/lib/braintree/error_codes.rb +++ b/lib/braintree/error_codes.rb @@ -93,6 +93,7 @@ module Subscription IdIsInUse = "81902" InconsistentNumberOfBillingCycles = "91908" InconsistentStartDate = "91917" + InvalidRequestFormat = "91921" MerchantAccountIdIsInvalid = "91901" NumberOfBillingCyclesCannotBeBlank = "91912" NumberOfBillingCyclesIsTooSmall = "91909" diff --git a/lib/braintree/error_result.rb b/lib/braintree/error_result.rb index bfc47e4a..d918abf9 100644 --- a/lib/braintree/error_result.rb +++ b/lib/braintree/error_result.rb @@ -2,7 +2,7 @@ module Braintree # See http://www.braintreepaymentsolutions.com/docs/ruby/general/result_objects class ErrorResult - attr_reader :credit_card_verification, :transaction, :errors, :params, :message + attr_reader :credit_card_verification, :transaction, :subscription, :errors, :params, :message def initialize(gateway, data) # :nodoc: @gateway = gateway @@ -10,6 +10,7 @@ def initialize(gateway, data) # :nodoc: @credit_card_verification = CreditCardVerification._new(data[:verification]) if data[:verification] @message = data[:message] @transaction = Transaction._new(gateway, data[:transaction]) if data[:transaction] + @subscription = Subscription._new(gateway, data[:subscription]) if data[:subscription] @errors = Errors.new(data[:errors]) end diff --git a/lib/braintree/subscription.rb b/lib/braintree/subscription.rb index efa772d8..a834cf7f 100644 --- a/lib/braintree/subscription.rb +++ b/lib/braintree/subscription.rb @@ -20,10 +20,11 @@ module TrialDurationUnit attr_reader :days_past_due, :price, :plan_id, :id, :status, :payment_method_token, :merchant_account_id attr_reader :first_billing_date, :next_billing_date, :billing_period_start_date, :billing_period_end_date + attr_reader :paid_through_date, :balance attr_reader :trial_period, :trial_duration, :trial_duration_unit attr_reader :failure_count attr_reader :transactions - attr_reader :next_bill_amount + attr_reader :next_billing_period_amount attr_reader :number_of_billing_cycles, :billing_day_of_month attr_reader :add_ons, :discounts @@ -59,12 +60,18 @@ def self.update(subscription_id, attributes) def initialize(gateway, attributes) # :nodoc: @gateway = gateway set_instance_variables_from_hash(attributes) + @balance = Util.to_big_decimal(balance) @price = Util.to_big_decimal(price) transactions.map! { |attrs| Transaction._new(gateway, attrs) } add_ons.map! { |attrs| AddOn._new(attrs) } discounts.map! { |attrs| Discount._new(attrs) } end + def next_bill_amount + warn "[DEPRECATED] Subscription.next_bill_amount is deprecated. Please use Subscription.next_billing_period_amount" + @next_bill_amount + end + def never_expires? @never_expires end diff --git a/lib/braintree/subscription_gateway.rb b/lib/braintree/subscription_gateway.rb index 049da98a..ce1cd0be 100644 --- a/lib/braintree/subscription_gateway.rb +++ b/lib/braintree/subscription_gateway.rb @@ -64,7 +64,7 @@ def self._create_signature # :nodoc: :trial_duration, :trial_duration_unit, :trial_period, - {:options => [:do_not_inherit_add_ons_or_discounts, :start_immediately]}, + {:options => [:do_not_inherit_add_ons_or_discounts, :start_immediately]} ] + _add_on_discount_signature end @@ -77,7 +77,11 @@ def self._update_signature # :nodoc: :payment_method_token, :plan_id, :price, - {:options => [:prorate_charges, :replace_all_add_ons_and_discounts]}, + {:options => [ + :prorate_charges, + :replace_all_add_ons_and_discounts, + :revert_subscription_on_proration_failure + ]} ] + _add_on_discount_signature end diff --git a/lib/braintree/transaction.rb b/lib/braintree/transaction.rb index d5454105..1bb8bfc2 100644 --- a/lib/braintree/transaction.rb +++ b/lib/braintree/transaction.rb @@ -55,7 +55,7 @@ module Type # :nodoc: attr_reader :processor_response_code # The response text from the processor. attr_reader :processor_response_text - attr_reader :refund_id, :refunded_transaction_id + attr_reader :refund_ids, :refunded_transaction_id attr_reader :settlement_batch_id # See Transaction::Status attr_reader :status @@ -181,7 +181,7 @@ def inspect # :nodoc: # # See http://www.braintreepaymentsolutions.com/docs/ruby/transactions/refund def refund(amount = nil) - warn "[DEPRECATED] refund as an instance method is deprecated. Please use CreditCard.refund" + warn "[DEPRECATED] refund as an instance method is deprecated. Please use Transaction.refund" result = @gateway.transaction.refund(id, amount) if result.success? @@ -196,11 +196,16 @@ def refunded? !@refund_id.nil? end + def refund_id + warn "[DEPRECATED] Transaction.refund_id is deprecated. Please use TransparentRedirect.refund_ids" + @refund_id + end + # Deprecated. Use Braintree::Transaction.submit_for_settlement # # See http://www.braintreepaymentsolutions.com/docs/ruby/transactions/submit_for_settlement def submit_for_settlement(amount = nil) - warn "[DEPRECATED] submit_for_settlement as an instance method is deprecated. Please use CreditCard.submit_for_settlement" + warn "[DEPRECATED] submit_for_settlement as an instance method is deprecated. Please use Transaction.submit_for_settlement" result = @gateway.transaction.submit_for_settlement(id, amount) if result.success? copy_instance_variables_from_object result.transaction @@ -212,7 +217,7 @@ def submit_for_settlement(amount = nil) # # See http://www.braintreepaymentsolutions.com/docs/ruby/transactions/submit_for_settlement def submit_for_settlement!(amount = nil) - warn "[DEPRECATED] submit_for_settlement! as an instance method is deprecated. Please use CreditCard.submit_for_settlement!" + warn "[DEPRECATED] submit_for_settlement! as an instance method is deprecated. Please use Transaction.submit_for_settlement!" return_object_or_raise(:transaction) { submit_for_settlement(amount) } end @@ -256,7 +261,7 @@ def vault_shipping_address # # See http://www.braintreepaymentsolutions.com/docs/ruby/transactions/void def void - warn "[DEPRECATED] void as an instance method is deprecated. Please use CreditCard.void" + warn "[DEPRECATED] void as an instance method is deprecated. Please use Transaction.void" result = @gateway.transaction.void(id) if result.success? copy_instance_variables_from_object result.transaction @@ -268,7 +273,7 @@ def void # # See http://www.braintreepaymentsolutions.com/docs/ruby/transactions/void def void! - warn "[DEPRECATED] void! as an instance method is deprecated. Please use CreditCard.void!" + warn "[DEPRECATED] void! as an instance method is deprecated. Please use Transaction.void!" return_object_or_raise(:transaction) { void } end diff --git a/lib/braintree/version.rb b/lib/braintree/version.rb index 7dbf928a..6b32e1c7 100644 --- a/lib/braintree/version.rb +++ b/lib/braintree/version.rb @@ -1,8 +1,8 @@ module Braintree module Version Major = 2 - Minor = 5 - Tiny = 2 + Minor = 6 + Tiny = 0 String = "#{Major}.#{Minor}.#{Tiny}" end diff --git a/spec/integration/braintree/subscription_spec.rb b/spec/integration/braintree/subscription_spec.rb index b1052c3a..8de2afe8 100644 --- a/spec/integration/braintree/subscription_spec.rb +++ b/spec/integration/braintree/subscription_spec.rb @@ -28,9 +28,11 @@ 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 @@ -585,46 +587,82 @@ 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 @@ -1050,6 +1088,7 @@ 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 diff --git a/spec/integration/braintree/transaction_search_spec.rb b/spec/integration/braintree/transaction_search_spec.rb index 4f3edda5..5459b7a4 100644 --- a/spec/integration/braintree/transaction_search_spec.rb +++ b/spec/integration/braintree/transaction_search_spec.rb @@ -562,6 +562,14 @@ end collection.maximum_size.should == 0 + + collection = Braintree::Transaction.search do |search| + search.id.is transaction.id + search.created_at.is created_at + end + + collection.maximum_size.should == 1 + collection.first.id.should == transaction.id end it "searches on created_at in local time" do diff --git a/spec/integration/braintree/transaction_spec.rb b/spec/integration/braintree/transaction_spec.rb index dd51b619..60dc7b92 100644 --- a/spec/integration/braintree/transaction_spec.rb +++ b/spec/integration/braintree/transaction_spec.rb @@ -555,12 +555,13 @@ result.transaction.type.should == "credit" end - it "does not allow multiple refunds" do + it "allows multiple partial refunds" do transaction = create_transaction_to_refund - Braintree::Transaction.refund(transaction.id, transaction.amount / 2) - result = Braintree::Transaction.refund(transaction.id, BigDecimal.new("1")) - result.success?.should == false - result.errors.for(:transaction).on(:base)[0].code.should == Braintree::ErrorCodes::Transaction::HasAlreadyBeenRefunded + transaction_1 = Braintree::Transaction.refund(transaction.id, transaction.amount / 2).transaction + transaction_2 = Braintree::Transaction.refund(transaction.id, transaction.amount / 2).transaction + + transaction = Braintree::Transaction.find(transaction.id) + transaction.refund_ids.sort.should == [transaction_1.id, transaction_2.id].sort end end @@ -1390,14 +1391,6 @@ result.success?.should == true result.new_transaction.type.should == "credit" end - - it "does not allow multiple refunds" do - transaction = create_transaction_to_refund - transaction.refund(transaction.amount / 2) - result = transaction.refund(BigDecimal.new("1")) - result.success?.should == false - result.errors.for(:transaction).on(:base)[0].code.should == Braintree::ErrorCodes::Transaction::HasAlreadyBeenRefunded - end end it "returns a successful result if successful" do