Permalink
Browse files

2.3.0

  • Loading branch information...
1 parent 2cfda43 commit 0cb22a0e0eed4849ae8d4271f43262b7441e469c @braintreeps braintreeps committed Jun 24, 2010
View
@@ -1,3 +1,12 @@
+== 2.3.0
+
+* Removed dependency on libxml -- it will still be used if libxml is explicitly required or it will fall back on rexml
+* Added unified TransparentRedirect url and confirm methods and deprecated old methods
+* Allow updating the payment_method_token on a subscription
+* Added methods to link a Transaction with its refund and vice versa
+* Allow card verification against a specified merchant account
+* Added ability to update a customer, credit card, and billing address in one request
+
== 2.2.0
* Prevent race condition when pulling back collection results -- search results represent the state of the data at the time the query was run
View
@@ -78,7 +78,6 @@ gem_spec = Gem::Specification.new do |s|
s.has_rdoc = false
s.files = FileList["README.rdoc", "LICENSE", "{lib,spec}/**/*.rb", "lib/**/*.crt"]
s.add_dependency "builder"
- s.add_dependency "libxml-ruby"
end
task :gem do
View
@@ -12,10 +12,6 @@
require "zlib"
require "builder"
-require "libxml"
-unless ::LibXML::XML.respond_to?(:default_keep_blanks=)
- raise LoadError, "The version of libxml that you're using is not compatible with the Braintree gem."
-end
module Braintree
end
@@ -55,6 +51,7 @@ module Braintree
require "braintree/xml.rb"
require "braintree/xml/generator.rb"
require "braintree/xml/libxml.rb"
+require "braintree/xml/rexml.rb"
require "braintree/xml/parser.rb"
Braintree::SSLExpirationCheck.check_dates
@@ -46,10 +46,12 @@ def self.create!(attributes)
# The transparent redirect URL to use to create a credit card.
def self.create_credit_card_url
+ warn "[DEPRECATED] CreditCard.create_credit_card_url is deprecated. Please use TransparentRedirect.url"
"#{Braintree::Configuration.base_merchant_url}/payment_methods/all/create_via_transparent_redirect_request"
end
def self.create_from_transparent_redirect(query_string)
+ warn "[DEPRECATED] CreditCard.create_from_transparent_redirect is deprecated. Please use TransparentRedirect.confirm"
params = TransparentRedirect.parse_and_validate_query_string query_string
_do_create("/payment_methods/all/confirm_transparent_redirect_request", :id => params[:id])
end
@@ -107,12 +109,14 @@ def self.update!(token, attributes)
end
def self.update_from_transparent_redirect(query_string)
+ warn "[DEPRECATED] CreditCard.update_via_transparent_redirect_request is deprecated. Please use TransparentRedirect.confirm"
params = TransparentRedirect.parse_and_validate_query_string query_string
_do_update(:post, "/payment_methods/all/confirm_transparent_redirect_request", :id => params[:id])
end
# The transparent redirect URL to use to update a credit card.
def self.update_credit_card_url
+ warn "[DEPRECATED] CreditCard.update_credit_card_url is deprecated. Please use TransparentRedirect.url"
"#{Braintree::Configuration.base_merchant_url}/payment_methods/all/update_via_transparent_redirect_request"
end
@@ -163,10 +167,7 @@ def expiration_date
# Returns true if the credit card is expired.
def expired?
- if expiration_year.to_i == Time.now.year
- return expiration_month.to_i < Time.now.month
- end
- expiration_year.to_i < Time.now.year
+ @expired
end
def inspect # :nodoc:
@@ -233,7 +234,7 @@ def self._new(*args) # :nodoc:
self.new *args
end
- def self._do_create(url, params) # :nodoc:
+ def self._do_create(url, params=nil) # :nodoc:
response = Http.post url, params
if response[:credit_card]
SuccessfulResult.new(:credit_card => new(response[:credit_card]))
@@ -263,7 +264,7 @@ def self._signature(type) # :nodoc:
billing_address_params = [:company, :country_name, :extended_address, :first_name, :last_name, :locality, :postal_code, :region, :street_address]
signature = [
:cardholder_name, :cvv, :expiration_date, :expiration_month, :expiration_year, :number, :token,
- {:options => [:make_default, :verify_card]},
+ {:options => [:make_default, :verification_merchant_account_id, :verify_card]},
{:billing_address => billing_address_params}
]
@@ -3,7 +3,7 @@ class CreditCardVerification
include BaseModule
attr_reader :avs_error_response_code, :avs_postal_code_response_code, :avs_street_address_response_code,
- :cvv_response_code, :processor_response_code, :processor_response_text, :status
+ :cvv_response_code, :merchant_account_id, :processor_response_code, :processor_response_text, :status
def initialize(attributes) # :nodoc:
set_instance_variables_from_hash(attributes)
@@ -13,7 +13,8 @@ def inspect # :nodoc:
attr_order = [
:status, :processor_response_code, :processor_response_text,
:cvv_response_code, :avs_error_response_code,
- :avs_postal_code_response_code, :avs_street_address_response_code
+ :avs_postal_code_response_code, :avs_street_address_response_code,
+ :merchant_account_id
]
formatted_attrs = attr_order.map do |attr|
"#{attr}: #{send(attr).inspect}"
View
@@ -52,18 +52,16 @@ def self.create!(attributes = {})
end
def self.create_customer_url
+ warn "[DEPRECATED] Customer.create_customer_url is deprecated. Please use TransparentRedirect.url"
"#{Braintree::Configuration.base_merchant_url}/customers/all/create_via_transparent_redirect_request"
end
def self.create_from_transparent_redirect(query_string)
+ warn "[DEPRECATED] Customer.create_from_transparent_redirect is deprecated. Please use TransparentRedirect.confirm"
params = TransparentRedirect.parse_and_validate_query_string query_string
_do_create("/customers/all/confirm_transparent_redirect_request", :id => params[:id])
end
- def self.create_customer_transparent_redirect_url
- "#{Braintree::Configuration.base_merchant_url}/customers"
- end
-
def self.credit(customer_id, transaction_attributes)
Transaction.credit(transaction_attributes.merge(:customer_id => customer_id))
end
@@ -118,10 +116,12 @@ def self.update!(customer_id, attributes)
end
def self.update_customer_url
+ warn "[DEPRECATED] Customer.update_customer_url is deprecated. Please use TransparentRedirect.url"
"#{Braintree::Configuration.base_merchant_url}/customers/all/update_via_transparent_redirect_request"
end
def self.update_from_transparent_redirect(query_string)
+ warn "[DEPRECATED] Customer.update_from_transparent_redirect is deprecated. Please use TransparentRedirect.confirm"
params = TransparentRedirect.parse_and_validate_query_string(query_string)
_do_update(:post, "/customers/all/confirm_transparent_redirect_request", :id => params[:id])
end
@@ -208,7 +208,7 @@ def self._create_signature # :nodoc:
]
end
- def self._do_create(url, params) # :nodoc:
+ def self._do_create(url, params=nil) # :nodoc:
response = Http.post url, params
if response[:customer]
SuccessfulResult.new(:customer => new(response[:customer]))
@@ -235,7 +235,14 @@ def self._new(*args) # :nodoc:
end
def self._update_signature # :nodoc:
- [ :company, :email, :fax, :first_name, :id, :last_name, :phone, :website, {:custom_fields => :_any_key_} ]
+ credit_card_signature = CreditCard._update_signature - [:customer_id]
+ credit_card_options = credit_card_signature.find { |item| item.respond_to?(:keys) && item.keys == [:options] }
+ credit_card_options[:options] << :update_existing_token
+ [
+ :company, :email, :fax, :first_name, :id, :last_name, :phone, :website,
+ {:credit_card => credit_card_signature},
+ {:custom_fields => :_any_key_}
+ ]
end
end
end
@@ -24,29 +24,34 @@ module CreditCard
BillingAddressIdIsInvalid = "91702"
CardholderNameIsTooLong = "81723"
CreditCardTypeIsNotAccepted = "81703"
- CustomerIdIsRequired = "91704"
+ CreditCardTypeIsNotAcceptedBySubscriptionMerchantAccount = "81718"
CustomerIdIsInvalid = "91705"
- CvvIsRequired = "81706"
+ CustomerIdIsRequired = "91704"
CvvIsInvalid = "81707"
+ CvvIsRequired = "81706"
ExpirationDateConflict = "91708"
- ExpirationDateIsRequired = "81709"
ExpirationDateIsInvalid = "81710"
+ ExpirationDateIsRequired = "81709"
ExpirationDateYearIsInvalid = "81711"
ExpirationMonthIsInvalid = "81712"
ExpirationYearIsInvalid = "81713"
- NumberIsRequired = "81714"
- NumberIsInvalid = "81715"
NumberHasInvalidLength = "81716"
+ NumberIsInvalid = "81715"
+ NumberIsRequired = "81714"
NumberMustBeTestNumber = "81717"
TokenInvalid = "91718"
TokenIsInUse = "91719"
- TokenIsTooLong = "91720"
TokenIsNotAllowed = "91721"
TokenIsRequired = "91722"
+ TokenIsTooLong = "91720"
+
+ module Options
+ UpdateExistingTokenIsInvalid = "91723"
+ end
end
module Customer
- CompanyisTooLong = "81601"
+ CompanyIsTooLong = "81601"
CustomFieldIsInvalid = "91602"
CustomFieldIsTooLong = "81603"
EmailIsInvalid = "81604"
@@ -67,6 +72,11 @@ module Customer
module Subscription
CannotEditCanceledSubscription = "81901"
IdIsInUse = "81902"
+ MerchantAccountIdIsInvalid = "91901"
+ PaymentMethodTokenCardTypeIsNotAccepted = "91902"
+ PaymentMethodTokenIsInvalid = "91903"
+ PaymentMethodTokenNotAssociatedWithCustomer = "91905"
+ PlanIdIsInvalid = "91904"
PriceCannotBeBlank = "81903"
PriceFormatIsInvalid = "81904"
StatusIsCanceled = "81905"
@@ -81,6 +91,7 @@ module Transaction
AmountIsRequired = "81502"
AmountIsInvalid = "81503"
AmountIsTooLarge = "81528"
+ BillingAddressConflict = "91530"
CannotBeVoided = "91504"
CannotRefundCredit = "91505"
CannotRefundUnlessSettled = "91506"
@@ -27,7 +27,13 @@ def initialize(data) # :nodoc:
end
def inspect # :nodoc:
- "#<#{self.class} params:{...} errors:<#{@errors._inner_inspect}>>"
+ if @credit_card_verification
+ verification_inspect = " credit_card_verification: #{@credit_card_verification.inspect}"
+ end
+ if @transaction
+ transaction_inspect = " transaction: #{@transaction.inspect}"
+ end
+ "#<#{self.class} params:{...} errors:<#{@errors._inner_inspect}>#{verification_inspect}#{transaction_inspect}>"
end
# Always returns false.
@@ -6,7 +6,6 @@ class << self
def self.check_dates # :nodoc:
{
- "QA" => qa_expiration_date,
"Sandbox" => sandbox_expiration_date,
"Production" => production_expiration_date
}.each do |host, expiration_date|
@@ -24,9 +23,5 @@ def self.production_expiration_date # :nodoc:
def self.sandbox_expiration_date # :nodoc:
Date.civil(2010, 12, 1)
end
-
- def self.qa_expiration_date # :nodoc:
- Date.civil(2010, 12, 1)
- end
end
end
@@ -176,6 +176,7 @@ def self._update_signature # :nodoc:
[
:id,
:merchant_account_id,
+ :payment_method_token,
:plan_id,
:price
]
@@ -156,6 +156,7 @@ module Type # :nodoc:
attr_reader :avs_error_response_code, :avs_postal_code_response_code, :avs_street_address_response_code
attr_reader :amount, :created_at, :credit_card_details, :customer_details, :id
+ attr_reader :currency_iso_code
attr_reader :custom_fields
attr_reader :cvv_response_code
attr_reader :merchant_account_id
@@ -167,9 +168,11 @@ 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
# See Transaction::Status
attr_reader :status
attr_reader :status_history
+ attr_reader :subscription_id
# Will either be "sale" or "credit"
attr_reader :type
attr_reader :updated_at
@@ -184,12 +187,14 @@ def self.create!(attributes)
end
def self.create_from_transparent_redirect(query_string)
+ warn "[DEPRECATED] Transaction.create_from_transparent_redirect is deprecated. Please use TransparentRedirect.confirm"
params = TransparentRedirect.parse_and_validate_query_string query_string
_do_create("/transactions/all/confirm_transparent_redirect_request", :id => params[:id])
end
# The URL to use to create transactions via transparent redirect.
def self.create_transaction_url
+ warn "[DEPRECATED] Transaction.create_transaction_url is deprecated. Please use TransparentRedirect.url"
"#{Braintree::Configuration.base_merchant_url}/transactions/all/create_via_transparent_redirect_request"
end
@@ -383,7 +388,7 @@ def _new(*args) # :nodoc:
end
end
- def self._do_create(url, params) # :nodoc:
+ def self._do_create(url, params=nil) # :nodoc:
response = Http.post url, params
if response[:transaction]
SuccessfulResult.new(:transaction => new(response[:transaction]))
@@ -26,15 +26,38 @@ module TransparentRedirect
CreateCreditCardSignature = TransparentRedirectKeys + [{:credit_card => CreditCard._create_signature}] # :nodoc:
UpdateCreditCardSignature = TransparentRedirectKeys + [:payment_method_token, {:credit_card => CreditCard._update_signature}] # :nodoc:
+ module Kind
+ CreateCustomer = "create_customer"
+ UpdateCustomer = "update_customer"
+ CreatePaymentMethod = "create_payment_method"
+ UpdatePaymentMethod = "update_payment_method"
+ CreateTransaction = "create_transaction"
+ end
+
+ def self.confirm(query_string)
+ params = TransparentRedirect.parse_and_validate_query_string query_string
+ confirmation_klass = {
+ Kind::CreateCustomer => Braintree::Customer,
+ Kind::UpdateCustomer => Braintree::Customer,
+ Kind::CreatePaymentMethod => Braintree::CreditCard,
+ Kind::UpdatePaymentMethod => Braintree::CreditCard,
+ Kind::CreateTransaction => Braintree::Transaction
+ }[params[:kind]]
+
+ confirmation_klass._do_create("/transparent_redirect_requests/#{params[:id]}/confirm")
+ end
+
# Returns the tr_data string for creating a credit card.
def self.create_credit_card_data(params)
Util.verify_keys(CreateCreditCardSignature, params)
+ params[:kind] = Kind::CreatePaymentMethod
_data(params)
end
# Returns the tr_data string for creating a customer.
def self.create_customer_data(params)
Util.verify_keys(CreateCustomerSignature, params)
+ params[:kind] = Kind::CreateCustomer
_data(params)
end
@@ -58,6 +81,7 @@ def self.parse_and_validate_query_string(query_string) # :nodoc:
# Returns the tr_data string for creating a transaction.
def self.transaction_data(params)
Util.verify_keys(TransactionSignature, params)
+ params[:kind] = Kind::CreateTransaction
transaction_type = params[:transaction] && params[:transaction][:type]
unless %w[sale credit].include?(transaction_type)
raise ArgumentError, "expected transaction[type] of sale or credit, was: #{transaction_type.inspect}"
@@ -77,6 +101,7 @@ def self.update_credit_card_data(params)
unless params[:payment_method_token]
raise ArgumentError, "expected params to contain :payment_method_token of payment method to update"
end
+ params[:kind] = Kind::UpdatePaymentMethod
_data(params)
end
@@ -92,9 +117,15 @@ def self.update_customer_data(params)
unless params[:customer_id]
raise ArgumentError, "expected params to contain :customer_id of customer to update"
end
+ params[:kind] = Kind::UpdateCustomer
_data(params)
end
+ # Returns the URL to which Transparent Redirect Requests should be posted
+ def self.url
+ "#{Braintree::Configuration.base_merchant_url}/transparent_redirect_requests"
+ end
+
def self._data(params) # :nodoc:
raise ArgumentError, "expected params to contain :redirect_url" unless params[:redirect_url]
tr_data_segment = Util.hash_to_query_string(params.merge(
Oops, something went wrong.

0 comments on commit 0cb22a0

Please sign in to comment.