braintree 3.3.0 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. checksums.yaml +4 -4
  2. data/braintree.gemspec +1 -1
  3. data/lib/braintree.rb +2 -1
  4. data/lib/braintree/account_updater_daily_report.rb +1 -1
  5. data/lib/braintree/address.rb +1 -1
  6. data/lib/braintree/apple_pay.rb +1 -1
  7. data/lib/braintree/apple_pay_card.rb +1 -1
  8. data/lib/braintree/apple_pay_options.rb +1 -1
  9. data/lib/braintree/authorization_adjustment.rb +1 -1
  10. data/lib/braintree/client_token.rb +1 -1
  11. data/lib/braintree/configuration.rb +11 -11
  12. data/lib/braintree/connected_merchant_paypal_status_changed.rb +1 -1
  13. data/lib/braintree/connected_merchant_status_transitioned.rb +1 -1
  14. data/lib/braintree/credit_card.rb +2 -2
  15. data/lib/braintree/credit_card_gateway.rb +3 -3
  16. data/lib/braintree/credit_card_verification.rb +5 -5
  17. data/lib/braintree/credit_card_verification_search.rb +1 -1
  18. data/lib/braintree/customer.rb +2 -2
  19. data/lib/braintree/customer_search.rb +1 -1
  20. data/lib/braintree/disbursement.rb +1 -1
  21. data/lib/braintree/dispute.rb +1 -1
  22. data/lib/braintree/dispute_gateway.rb +2 -2
  23. data/lib/braintree/dispute_search.rb +2 -2
  24. data/lib/braintree/document_upload.rb +1 -1
  25. data/lib/braintree/error_codes.rb +7 -0
  26. data/lib/braintree/google_pay_card.rb +1 -1
  27. data/lib/braintree/granted_payment_instrument_update.rb +1 -1
  28. data/lib/braintree/graphql_client.rb +7 -7
  29. data/lib/braintree/http.rb +3 -3
  30. data/lib/braintree/local_payment_completed.rb +1 -1
  31. data/lib/braintree/local_payment_reversed.rb +19 -0
  32. data/lib/braintree/merchant.rb +1 -1
  33. data/lib/braintree/merchant_account.rb +1 -1
  34. data/lib/braintree/merchant_account_gateway.rb +1 -1
  35. data/lib/braintree/merchant_gateway.rb +1 -1
  36. data/lib/braintree/modification.rb +1 -1
  37. data/lib/braintree/oauth_credentials.rb +1 -1
  38. data/lib/braintree/oauth_gateway.rb +5 -5
  39. data/lib/braintree/payment_instrument_type.rb +10 -10
  40. data/lib/braintree/payment_method_gateway.rb +3 -3
  41. data/lib/braintree/payment_method_nonce_gateway.rb +1 -1
  42. data/lib/braintree/plan.rb +1 -1
  43. data/lib/braintree/processor_response_types.rb +3 -3
  44. data/lib/braintree/revoked_payment_method_metadata.rb +1 -1
  45. data/lib/braintree/samsung_pay_card.rb +1 -1
  46. data/lib/braintree/settlement_batch_summary.rb +2 -2
  47. data/lib/braintree/subscription.rb +6 -6
  48. data/lib/braintree/transaction.rb +32 -24
  49. data/lib/braintree/transaction_gateway.rb +23 -4
  50. data/lib/braintree/transaction_line_item.rb +1 -1
  51. data/lib/braintree/transaction_search.rb +3 -1
  52. data/lib/braintree/unknown_payment_method.rb +1 -1
  53. data/lib/braintree/us_bank_account.rb +3 -3
  54. data/lib/braintree/us_bank_account_verification.rb +1 -1
  55. data/lib/braintree/us_bank_account_verification_gateway.rb +1 -1
  56. data/lib/braintree/util.rb +4 -4
  57. data/lib/braintree/venmo_account.rb +1 -1
  58. data/lib/braintree/version.rb +1 -1
  59. data/lib/braintree/visa_checkout_card.rb +2 -2
  60. data/lib/braintree/webhook_notification.rb +28 -19
  61. data/lib/braintree/webhook_notification_gateway.rb +5 -5
  62. data/lib/braintree/webhook_testing_gateway.rb +10 -0
  63. data/lib/braintree/xml/generator.rb +5 -4
  64. data/lib/braintree/xml/libxml.rb +1 -1
  65. data/lib/braintree/xml/parser.rb +10 -10
  66. data/spec/integration/braintree/add_on_spec.rb +1 -1
  67. data/spec/integration/braintree/address_spec.rb +24 -24
  68. data/spec/integration/braintree/advanced_search_spec.rb +45 -45
  69. data/spec/integration/braintree/apple_pay_spec.rb +3 -3
  70. data/spec/integration/braintree/braintree_gateway_spec.rb +2 -1
  71. data/spec/integration/braintree/client_api/client_token_spec.rb +14 -14
  72. data/spec/integration/braintree/client_api/spec_helper.rb +5 -5
  73. data/spec/integration/braintree/credit_card_spec.rb +119 -119
  74. data/spec/integration/braintree/credit_card_verification_search_spec.rb +2 -2
  75. data/spec/integration/braintree/credit_card_verification_spec.rb +1 -1
  76. data/spec/integration/braintree/customer_search_spec.rb +8 -8
  77. data/spec/integration/braintree/customer_spec.rb +165 -165
  78. data/spec/integration/braintree/dispute_search_spec.rb +3 -3
  79. data/spec/integration/braintree/dispute_spec.rb +6 -6
  80. data/spec/integration/braintree/error_codes_spec.rb +1 -1
  81. data/spec/integration/braintree/http_spec.rb +2 -2
  82. data/spec/integration/braintree/merchant_account_spec.rb +25 -26
  83. data/spec/integration/braintree/merchant_spec.rb +12 -12
  84. data/spec/integration/braintree/oauth_spec.rb +11 -11
  85. data/spec/integration/braintree/payment_method_nonce_spec.rb +12 -12
  86. data/spec/integration/braintree/payment_method_spec.rb +165 -165
  87. data/spec/integration/braintree/payment_method_us_bank_account_spec.rb +9 -9
  88. data/spec/integration/braintree/paypal_account_spec.rb +28 -28
  89. data/spec/integration/braintree/samsung_pay_card_spec.rb +9 -9
  90. data/spec/integration/braintree/settlement_batch_summary_spec.rb +8 -8
  91. data/spec/integration/braintree/subscription_spec.rb +133 -133
  92. data/spec/integration/braintree/test/transaction_amounts_spec.rb +2 -2
  93. data/spec/integration/braintree/test_transaction_spec.rb +10 -10
  94. data/spec/integration/braintree/transaction_search_spec.rb +93 -67
  95. data/spec/integration/braintree/transaction_spec.rb +498 -344
  96. data/spec/integration/braintree/transaction_us_bank_account_spec.rb +20 -20
  97. data/spec/integration/braintree/us_bank_account_spec.rb +6 -6
  98. data/spec/integration/braintree/us_bank_account_verification_search_spec.rb +7 -7
  99. data/spec/integration/braintree/us_bank_account_verification_spec.rb +8 -8
  100. data/spec/integration/braintree/visa_checkout_card_spec.rb +5 -5
  101. data/spec/integration/spec_helper.rb +2 -2
  102. data/spec/oauth_test_helper.rb +1 -1
  103. data/spec/script/httpsd.rb +6 -6
  104. data/spec/spec_helper.rb +4 -3
  105. data/spec/unit/braintree/address_spec.rb +1 -1
  106. data/spec/unit/braintree/apple_pay_card_spec.rb +1 -1
  107. data/spec/unit/braintree/client_token_spec.rb +2 -2
  108. data/spec/unit/braintree/configuration_spec.rb +42 -42
  109. data/spec/unit/braintree/credit_card_spec.rb +7 -7
  110. data/spec/unit/braintree/credit_card_verification_search_spec.rb +1 -1
  111. data/spec/unit/braintree/credit_card_verification_spec.rb +2 -2
  112. data/spec/unit/braintree/customer_spec.rb +3 -3
  113. data/spec/unit/braintree/disbursement_spec.rb +7 -7
  114. data/spec/unit/braintree/dispute_spec.rb +8 -8
  115. data/spec/unit/braintree/error_result_spec.rb +5 -5
  116. data/spec/unit/braintree/errors_spec.rb +8 -8
  117. data/spec/unit/braintree/http_spec.rb +5 -5
  118. data/spec/unit/braintree/merchant_account_spec.rb +1 -1
  119. data/spec/unit/braintree/payment_method_spec.rb +1 -1
  120. data/spec/unit/braintree/paypal_account_spec.rb +2 -2
  121. data/spec/unit/braintree/resource_collection_spec.rb +9 -9
  122. data/spec/unit/braintree/subscription_search_spec.rb +1 -1
  123. data/spec/unit/braintree/successful_result_spec.rb +1 -1
  124. data/spec/unit/braintree/three_d_secure_info_spec.rb +1 -1
  125. data/spec/unit/braintree/transaction/credit_card_details_spec.rb +3 -3
  126. data/spec/unit/braintree/transaction/customer_details_spec.rb +1 -1
  127. data/spec/unit/braintree/transaction/deposit_details_spec.rb +2 -2
  128. data/spec/unit/braintree/transaction/paypal_details_spec.rb +1 -1
  129. data/spec/unit/braintree/transaction_search_spec.rb +12 -12
  130. data/spec/unit/braintree/transaction_spec.rb +25 -17
  131. data/spec/unit/braintree/util_spec.rb +18 -18
  132. data/spec/unit/braintree/validation_error_collection_spec.rb +36 -36
  133. data/spec/unit/braintree/webhook_notification_spec.rb +72 -56
  134. data/spec/unit/braintree/xml_spec.rb +31 -31
  135. metadata +3 -3
  136. data/lib/braintree/settlement_batch.rb +0 -0
@@ -37,7 +37,8 @@ module Braintree
37
37
  :shipping_locality,
38
38
  :shipping_postal_code,
39
39
  :shipping_region,
40
- :shipping_street_address
40
+ :shipping_street_address,
41
+ :store_id,
41
42
  )
42
43
 
43
44
  equality_fields :credit_card_expiration_date
@@ -59,6 +60,7 @@ module Braintree
59
60
  multiple_value_field :status, :allows => Transaction::Status::All
60
61
  multiple_value_field :source
61
62
  multiple_value_field :type, :allows => Transaction::Type::All
63
+ multiple_value_field :store_ids
62
64
 
63
65
  key_value_fields :refund
64
66
 
@@ -20,7 +20,7 @@ module Braintree
20
20
  end
21
21
 
22
22
  def self._new(*args) # :nodoc:
23
- self.new *args
23
+ self.new(*args)
24
24
  end
25
25
  end
26
26
  end
@@ -35,7 +35,7 @@ module Braintree
35
35
  end
36
36
 
37
37
  def self._new(*args) # :nodoc:
38
- self.new *args
38
+ self.new(*args)
39
39
  end
40
40
 
41
41
  def self.find(*args)
@@ -45,8 +45,8 @@ module Braintree
45
45
  def self.sale(token, transaction_attributes)
46
46
  Configuration.gateway.transaction.sale(transaction_attributes.merge(
47
47
  :payment_method_token => token,
48
- :options => { :submit_for_settlement => true }
49
- )
48
+ :options => {:submit_for_settlement => true},
49
+ ),
50
50
  )
51
51
  end
52
52
 
@@ -63,7 +63,7 @@ module Braintree
63
63
  end
64
64
 
65
65
  def self._new(*args) # :nodoc:
66
- self.new *args
66
+ self.new(*args)
67
67
  end
68
68
 
69
69
  def self.confirm_micro_transfer_amounts(*args)
@@ -18,7 +18,7 @@ module Braintree
18
18
  ErrorResult.new(@gateway, response[:api_error_response])
19
19
  else
20
20
  SuccessfulResult.new(
21
- :us_bank_account_verification => UsBankAccountVerification._new(response[:us_bank_account_verification])
21
+ :us_bank_account_verification => UsBankAccountVerification._new(response[:us_bank_account_verification]),
22
22
  )
23
23
  end
24
24
  rescue NotFoundError
@@ -14,13 +14,13 @@ module Braintree
14
14
  else
15
15
  url_encode(full_key) + "=" + url_encode(value)
16
16
  end
17
- end.sort * '&'
17
+ end.sort * "&"
18
18
  end
19
19
 
20
20
  def self.parse_query_string(qs)
21
- qs.split('&').inject({}) do |result, couplet|
22
- pair = couplet.split('=')
23
- result[CGI.unescape(pair[0]).to_sym] = CGI.unescape(pair[1] || '')
21
+ qs.split("&").inject({}) do |result, couplet|
22
+ pair = couplet.split("=")
23
+ result[CGI.unescape(pair[0]).to_sym] = CGI.unescape(pair[1] || "")
24
24
  result
25
25
  end
26
26
  end
@@ -28,7 +28,7 @@ module Braintree
28
28
  end
29
29
 
30
30
  def self._new(*args) # :nodoc:
31
- self.new *args
31
+ self.new(*args)
32
32
  end
33
33
  end
34
34
  end
@@ -1,7 +1,7 @@
1
1
  module Braintree
2
2
  module Version
3
3
  Major = 3
4
- Minor = 3
4
+ Minor = 4
5
5
  Tiny = 0
6
6
 
7
7
  String = "#{Major}.#{Minor}.#{Tiny}"
@@ -39,7 +39,7 @@ module Braintree
39
39
  end
40
40
 
41
41
  def _most_recent_verification(attributes)
42
- verification = (attributes[:verifications] || []).sort_by{ |verification| verification[:created_at] }.reverse.first
42
+ verification = (attributes[:verifications] || []).sort_by { |verification| verification[:created_at] }.reverse.first
43
43
  CreditCardVerification._new(verification) if verification
44
44
  end
45
45
 
@@ -84,7 +84,7 @@ module Braintree
84
84
  end
85
85
 
86
86
  def self._new(*args) # :nodoc:
87
- self.new *args
87
+ self.new(*args)
88
88
  end
89
89
  end
90
90
  end
@@ -1,12 +1,17 @@
1
- require 'ostruct'
1
+ require "ostruct"
2
2
 
3
3
  module Braintree
4
4
  class WebhookNotification
5
5
  include BaseModule
6
6
 
7
7
  module Kind
8
+
9
+ AccountUpdaterDailyReport = "account_updater_daily_report"
10
+
8
11
  Check = "check"
9
12
 
13
+ ConnectedMerchantPayPalStatusChanged = "connected_merchant_paypal_status_changed"
14
+ ConnectedMerchantStatusTransitioned = "connected_merchant_status_transitioned"
10
15
  Disbursement = "disbursement"
11
16
  DisbursementException = "disbursement_exception"
12
17
 
@@ -17,6 +22,23 @@ module Braintree
17
22
  DisputeDisputed = "dispute_disputed"
18
23
  DisputeExpired = "dispute_expired"
19
24
 
25
+ GrantedPaymentInstrumentRevoked = "granted_payment_instrument_revoked"
26
+
27
+ GrantorUpdatedGrantedPaymentMethod = "grantor_updated_granted_payment_method"
28
+
29
+ LocalPaymentCompleted = "local_payment_completed"
30
+ LocalPaymentReversed = "local_payment_reversed"
31
+
32
+ OAuthAccessRevoked = "oauth_access_revoked"
33
+
34
+ PartnerMerchantConnected = "partner_merchant_connected"
35
+ PartnerMerchantDisconnected = "partner_merchant_disconnected"
36
+ PartnerMerchantDeclined = "partner_merchant_declined"
37
+
38
+ PaymentMethodRevokedByCustomer = "payment_method_revoked_by_customer"
39
+
40
+ RecipientUpdatedGrantedPaymentMethod = "recipient_updated_granted_payment_method"
41
+
20
42
  SubscriptionCanceled = "subscription_canceled"
21
43
  SubscriptionChargedSuccessfully = "subscription_charged_successfully"
22
44
  SubscriptionChargedUnsuccessfully = "subscription_charged_unsuccessfully"
@@ -27,25 +49,10 @@ module Braintree
27
49
 
28
50
  SubMerchantAccountApproved = "sub_merchant_account_approved"
29
51
  SubMerchantAccountDeclined = "sub_merchant_account_declined"
52
+
30
53
  TransactionDisbursed = "transaction_disbursed"
31
54
  TransactionSettlementDeclined = "transaction_settlement_declined"
32
55
  TransactionSettled = "transaction_settled"
33
- PartnerMerchantConnected = "partner_merchant_connected"
34
- PartnerMerchantDisconnected = "partner_merchant_disconnected"
35
- PartnerMerchantDeclined = "partner_merchant_declined"
36
-
37
- AccountUpdaterDailyReport = "account_updater_daily_report"
38
-
39
- OAuthAccessRevoked = "oauth_access_revoked"
40
- ConnectedMerchantStatusTransitioned = "connected_merchant_status_transitioned"
41
- ConnectedMerchantPayPalStatusChanged = "connected_merchant_paypal_status_changed"
42
-
43
- GrantorUpdatedGrantedPaymentMethod = "grantor_updated_granted_payment_method"
44
- RecipientUpdatedGrantedPaymentMethod = "recipient_updated_granted_payment_method"
45
- GrantedPaymentInstrumentRevoked = "granted_payment_instrument_revoked"
46
- PaymentMethodRevokedByCustomer = "payment_method_revoked_by_customer"
47
-
48
- LocalPaymentCompleted = "local_payment_completed"
49
56
  end
50
57
 
51
58
  attr_reader :account_updater_daily_report
@@ -57,6 +64,7 @@ module Braintree
57
64
  attr_reader :revoked_payment_method_metadata
58
65
  attr_reader :kind
59
66
  attr_reader :local_payment_completed
67
+ attr_reader :local_payment_reversed
60
68
  attr_reader :oauth_access_revocation
61
69
  attr_reader :partner_merchant
62
70
  attr_reader :source_merchant_id
@@ -88,7 +96,8 @@ module Braintree
88
96
  @connected_merchant_paypal_status_changed = ConnectedMerchantPayPalStatusChanged._new(@subject[:connected_merchant_paypal_status_changed]) if @subject.has_key?(:connected_merchant_paypal_status_changed)
89
97
  @granted_payment_instrument_update = GrantedPaymentInstrumentUpdate._new(@subject[:granted_payment_instrument_update]) if @subject.has_key?(:granted_payment_instrument_update)
90
98
  @revoked_payment_method_metadata = RevokedPaymentMethodMetadata._new(gateway, @subject) if [Kind::GrantedPaymentInstrumentRevoked, Kind::PaymentMethodRevokedByCustomer].include?(@kind)
91
- @local_payment_completed = LocalPaymentCompleted._new(@subject[:local_payment]) if @subject.has_key?(:local_payment)
99
+ @local_payment_completed = LocalPaymentCompleted._new(@subject[:local_payment]) if @subject.has_key?(:local_payment) && Kind::LocalPaymentCompleted == @kind
100
+ @local_payment_reversed = LocalPaymentReversed._new(@subject[:local_payment_reversed]) if @subject.has_key?(:local_payment_reversed) && Kind::LocalPaymentReversed == @kind
92
101
  end
93
102
 
94
103
  def merchant_account
@@ -110,7 +119,7 @@ module Braintree
110
119
  class << self
111
120
  protected :new
112
121
  def _new(*args) # :nodoc:
113
- self.new *args
122
+ self.new(*args)
114
123
  end
115
124
  end
116
125
  end
@@ -7,8 +7,8 @@ module Braintree
7
7
  end
8
8
 
9
9
  def parse(signature_string, payload)
10
- raise InvalidSignature, 'signature cannot be nil' if signature_string.nil?
11
- raise InvalidSignature, 'payload cannot be nil' if payload.nil?
10
+ raise InvalidSignature, "signature cannot be nil" if signature_string.nil?
11
+ raise InvalidSignature, "payload cannot be nil" if payload.nil?
12
12
  if payload =~ /[^A-Za-z0-9+=\/\n]/
13
13
  raise InvalidSignature, "payload contains illegal characters"
14
14
  end
@@ -18,7 +18,7 @@ module Braintree
18
18
  end
19
19
 
20
20
  def verify(challenge)
21
- raise InvalidChallenge, 'challenge contains non-hex characters' unless challenge =~ /\A[a-f0-9]{20,32}\z/
21
+ raise InvalidChallenge, "challenge contains non-hex characters" unless challenge =~ /\A[a-f0-9]{20,32}\z/
22
22
  digest = Braintree::Digest.hexdigest(@config.private_key, challenge)
23
23
  "#{@config.public_key}|#{digest}"
24
24
  end
@@ -34,13 +34,13 @@ module Braintree
34
34
 
35
35
  def _verify_signature(signature_string, payload)
36
36
  public_key, signature = _matching_signature_pair(signature_string)
37
- raise InvalidSignature, 'no matching public key' if public_key.nil?
37
+ raise InvalidSignature, "no matching public key" if public_key.nil?
38
38
 
39
39
  signature_matches = [payload, payload + "\n"].any? do |payload|
40
40
  payload_signature = Braintree::Digest.hexdigest(@config.private_key, payload)
41
41
  Braintree::Digest.secure_compare(signature, payload_signature)
42
42
  end
43
- raise InvalidSignature, 'signature does not match payload - one has been modified' unless signature_matches
43
+ raise InvalidSignature, "signature does not match payload - one has been modified" unless signature_matches
44
44
  end
45
45
  end
46
46
  end
@@ -86,6 +86,8 @@ module Braintree
86
86
  _payment_method_revoked_by_customer_sample_xml(id)
87
87
  when Braintree::WebhookNotification::Kind::LocalPaymentCompleted
88
88
  _local_payment_completed_sample_xml(id)
89
+ when Braintree::WebhookNotification::Kind::LocalPaymentReversed
90
+ _local_payment_reversed_sample_xml(id)
89
91
  else
90
92
  _subscription_sample_xml(id)
91
93
  end
@@ -912,5 +914,13 @@ module Braintree
912
914
  </local-payment>
913
915
  XML
914
916
  end
917
+
918
+ def _local_payment_reversed_sample_xml(id)
919
+ <<-XML
920
+ <local-payment-reversed>
921
+ <payment-id>PAY-XYZ123</payment-id>
922
+ </local-payment-reversed>
923
+ XML
924
+ end
915
925
  end
916
926
  end
@@ -12,6 +12,7 @@ module Braintree
12
12
  "Date" => "datetime",
13
13
  "DateTime" => "datetime",
14
14
  "Time" => "datetime",
15
+ "ActiveSupport::TimeWithZone" => "datetime"
15
16
  }
16
17
 
17
18
  XML_FORMATTING_NAMES = {
@@ -25,7 +26,7 @@ module Braintree
25
26
  date_or_time.respond_to?(:xmlschema) ? date_or_time.xmlschema : date_or_time.to_s
26
27
  end,
27
28
  "bigdecimal" => Proc.new do |bigdecimal|
28
- str = bigdecimal.to_s('F')
29
+ str = bigdecimal.to_s("F")
29
30
  if str =~ /\.\d$/
30
31
  str += "0"
31
32
  end
@@ -61,15 +62,15 @@ module Braintree
61
62
  else
62
63
  type_name = XML_TYPE_NAMES[value.class.name]
63
64
 
64
- attributes = ((value.nil? || type_name.nil?) ? {} : { :type => type_name })
65
+ attributes = ((value.nil? || type_name.nil?) ? {} : {:type => type_name})
65
66
  if value.nil?
66
67
  attributes[:nil] = true
67
68
  end
68
69
 
69
- formatting_name = XML_FORMATTING_NAMES[value.class.name]
70
+ formatting_name = XML_FORMATTING_NAMES[value.class.name]
70
71
  options[:builder].tag!(_xml_escape(key),
71
72
  XML_FORMATTING[formatting_name] ? XML_FORMATTING[formatting_name].call(value) : value,
72
- attributes
73
+ attributes,
73
74
  )
74
75
  end
75
76
  end
@@ -1,4 +1,4 @@
1
- require 'libxml'
1
+ require "libxml"
2
2
  # Portions of this code were copied and modified from Ruby on Rails, released
3
3
  # under the MIT license, copyright (c) 2005-2009 David Heinemeier Hansson
4
4
  module Braintree
@@ -2,7 +2,7 @@
2
2
  # under the MIT license, copyright (c) 2005-2009 David Heinemeier Hansson
3
3
  module Braintree
4
4
  module Xml # :nodoc:
5
- CONTENT_ROOT = '__content__'
5
+ CONTENT_ROOT = "__content__"
6
6
 
7
7
  module Parser # :nodoc:
8
8
  XML_PARSING = {
@@ -20,9 +20,9 @@ module Braintree
20
20
  # Transform into standard Ruby types and convert all keys to snake_case instead of dash-case
21
21
  def self._transform_xml(value)
22
22
  case value.class.to_s
23
- when 'Hash'
24
- if value['type'] == 'array'
25
- child_key, entries = value.detect { |k,v| k != 'type' } # child_key is throwaway
23
+ when "Hash"
24
+ if value["type"] == "array"
25
+ child_key, entries = value.detect { |k,v| k != "type" } # child_key is throwaway
26
26
  if entries.nil? || ((c = value[CONTENT_ROOT]) && c.strip.empty?)
27
27
  []
28
28
  else
@@ -37,21 +37,21 @@ module Braintree
37
37
  end
38
38
  elsif value.has_key?(CONTENT_ROOT)
39
39
  content = value[CONTENT_ROOT]
40
- if parser = XML_PARSING[value["type"]]
40
+ if (parser = XML_PARSING[value["type"]])
41
41
  XML_PARSING[value["type"]].call(content)
42
42
  else
43
43
  content
44
44
  end
45
- elsif value['type'] == 'string' && value['nil'] != 'true'
45
+ elsif value["type"] == "string" && value["nil"] != "true"
46
46
  ""
47
47
  elsif value == {}
48
48
  ""
49
- elsif value.nil? || value['nil'] == 'true'
49
+ elsif value.nil? || value["nil"] == "true"
50
50
  nil
51
51
  # If the type is the only element which makes it then
52
52
  # this still makes the value nil, except if type is
53
53
  # a XML node(where type['value'] is a Hash)
54
- elsif value['type'] && value.size == 1 && !value['type'].is_a?(::Hash)
54
+ elsif value["type"] && value.size == 1 && !value["type"].is_a?(::Hash)
55
55
  raise "is this needed?"
56
56
  nil
57
57
  else
@@ -61,14 +61,14 @@ module Braintree
61
61
  end
62
62
  xml_value
63
63
  end
64
- when 'Array'
64
+ when "Array"
65
65
  value.map! { |i| _transform_xml(i) }
66
66
  case value.length
67
67
  when 0 then nil
68
68
  when 1 then value.first
69
69
  else value
70
70
  end
71
- when 'String'
71
+ when "String"
72
72
  value
73
73
  else
74
74
  raise "can't transform #{value.class.name} - #{value.inspect}"
@@ -35,7 +35,7 @@ describe Braintree::AddOn do
35
35
  gateway = Braintree::Gateway.new(
36
36
  :client_id => "client_id$#{Braintree::Configuration.environment}$integration_client_id",
37
37
  :client_secret => "client_secret$#{Braintree::Configuration.environment}$integration_client_secret",
38
- :logger => Logger.new("/dev/null")
38
+ :logger => Logger.new("/dev/null"),
39
39
  )
40
40
 
41
41
  expect do
@@ -15,7 +15,7 @@ describe Braintree::Address do
15
15
  :locality => "Chicago",
16
16
  :region => "Illinois",
17
17
  :postal_code => "60622",
18
- :country_name => "United States of America"
18
+ :country_name => "United States of America",
19
19
  )
20
20
  result.success?.should == true
21
21
  result.address.customer_id.should == customer.id
@@ -39,7 +39,7 @@ describe Braintree::Address do
39
39
  :customer_id => customer.id,
40
40
  :country_code_alpha2 => "AS",
41
41
  :country_code_alpha3 => "ASM",
42
- :country_code_numeric => "16"
42
+ :country_code_numeric => "16",
43
43
  )
44
44
  result.success?.should == true
45
45
  result.address.country_name.should == "American Samoa"
@@ -52,7 +52,7 @@ describe Braintree::Address do
52
52
  customer = Braintree::Customer.create!
53
53
  result = Braintree::Address.create(
54
54
  :customer_id => customer.id,
55
- :country_name => "Åland"
55
+ :country_name => "Åland",
56
56
  )
57
57
  result.success?.should == true
58
58
  result.address.country_name.should == "Åland"
@@ -63,47 +63,47 @@ describe Braintree::Address do
63
63
  result = Braintree::Address.create(
64
64
  :customer_id => customer.id,
65
65
  :country_code_alpha2 => "AS",
66
- :country_code_alpha3 => "USA"
66
+ :country_code_alpha3 => "USA",
67
67
  )
68
68
  result.success?.should == false
69
- result.errors.for(:address).on(:base).map {|e| e.code}.should include(Braintree::ErrorCodes::Address::InconsistentCountry)
69
+ result.errors.for(:address).on(:base).map { |e| e.code }.should include(Braintree::ErrorCodes::Address::InconsistentCountry)
70
70
  end
71
71
 
72
72
  it "returns an error response given an invalid country_code_alpha2" do
73
73
  customer = Braintree::Customer.create!
74
74
  result = Braintree::Address.create(
75
75
  :customer_id => customer.id,
76
- :country_code_alpha2 => "zz"
76
+ :country_code_alpha2 => "zz",
77
77
  )
78
78
  result.success?.should == false
79
- result.errors.for(:address).on(:country_code_alpha2).map {|e| e.code}.should include(Braintree::ErrorCodes::Address::CountryCodeAlpha2IsNotAccepted)
79
+ result.errors.for(:address).on(:country_code_alpha2).map { |e| e.code }.should include(Braintree::ErrorCodes::Address::CountryCodeAlpha2IsNotAccepted)
80
80
  end
81
81
 
82
82
  it "returns an error response given an invalid country_code_alpha3" do
83
83
  customer = Braintree::Customer.create!
84
84
  result = Braintree::Address.create(
85
85
  :customer_id => customer.id,
86
- :country_code_alpha3 => "zzz"
86
+ :country_code_alpha3 => "zzz",
87
87
  )
88
88
  result.success?.should == false
89
- result.errors.for(:address).on(:country_code_alpha3).map {|e| e.code}.should include(Braintree::ErrorCodes::Address::CountryCodeAlpha3IsNotAccepted)
89
+ result.errors.for(:address).on(:country_code_alpha3).map { |e| e.code }.should include(Braintree::ErrorCodes::Address::CountryCodeAlpha3IsNotAccepted)
90
90
  end
91
91
 
92
92
  it "returns an error response given an invalid country_code_numeric" do
93
93
  customer = Braintree::Customer.create!
94
94
  result = Braintree::Address.create(
95
95
  :customer_id => customer.id,
96
- :country_code_numeric => "zz"
96
+ :country_code_numeric => "zz",
97
97
  )
98
98
  result.success?.should == false
99
- result.errors.for(:address).on(:country_code_numeric).map {|e| e.code}.should include(Braintree::ErrorCodes::Address::CountryCodeNumericIsNotAccepted)
99
+ result.errors.for(:address).on(:country_code_numeric).map { |e| e.code }.should include(Braintree::ErrorCodes::Address::CountryCodeNumericIsNotAccepted)
100
100
  end
101
101
 
102
102
  it "returns an error response if invalid" do
103
103
  customer = Braintree::Customer.create!(:last_name => "Wilson")
104
104
  result = Braintree::Address.create(
105
105
  :customer_id => customer.id,
106
- :country_name => "United States of Invalid"
106
+ :country_name => "United States of Invalid",
107
107
  )
108
108
  result.success?.should == false
109
109
  result.errors.for(:address).on(:country_name)[0].message.should == "Country name is not an accepted country."
@@ -132,7 +132,7 @@ describe Braintree::Address do
132
132
  :locality => "Bartlett",
133
133
  :region => "IL",
134
134
  :postal_code => "60623",
135
- :country_name => "United States of America"
135
+ :country_name => "United States of America",
136
136
  )
137
137
  address.customer_id.should == customer.id
138
138
  address.street_address.should == "1812 E Main St"
@@ -148,7 +148,7 @@ describe Braintree::Address do
148
148
  expect do
149
149
  Braintree::Address.create!(
150
150
  :customer_id => customer.id,
151
- :country_name => "United States of Invalid"
151
+ :country_name => "United States of Invalid",
152
152
  )
153
153
  end.to raise_error(Braintree::ValidationsFailed)
154
154
  end
@@ -226,7 +226,7 @@ describe Braintree::Address do
226
226
  :locality => "Old Chicago",
227
227
  :region => "IL",
228
228
  :postal_code => "60620",
229
- :country_name => "United States of America"
229
+ :country_name => "United States of America",
230
230
  )
231
231
  result = Braintree::Address.update(
232
232
  customer.id,
@@ -236,7 +236,7 @@ describe Braintree::Address do
236
236
  :locality => "Chicago",
237
237
  :region => "Illinois",
238
238
  :postal_code => "60621",
239
- :country_name => "United States of America"
239
+ :country_name => "United States of America",
240
240
  )
241
241
  result.success?.should == true
242
242
  result.address.street_address.should == "123 E New St"
@@ -254,12 +254,12 @@ describe Braintree::Address do
254
254
  customer = Braintree::Customer.create!(:last_name => "Miller")
255
255
  address = Braintree::Address.create!(
256
256
  :customer_id => customer.id,
257
- :country_name => "Angola"
257
+ :country_name => "Angola",
258
258
  )
259
259
  result = Braintree::Address.update(
260
260
  customer.id,
261
261
  address.id,
262
- :country_name => "Azerbaijan"
262
+ :country_name => "Azerbaijan",
263
263
  )
264
264
 
265
265
  result.success?.should == true
@@ -273,13 +273,13 @@ describe Braintree::Address do
273
273
  customer = Braintree::Customer.create!(:last_name => "Miller")
274
274
  address = Braintree::Address.create!(
275
275
  :customer_id => customer.id,
276
- :country_name => "United States of America"
276
+ :country_name => "United States of America",
277
277
  )
278
278
  result = Braintree::Address.update(
279
279
  customer.id,
280
280
  address.id,
281
281
  :street_address => "123 E New St",
282
- :country_name => "United States of Invalid"
282
+ :country_name => "United States of Invalid",
283
283
  )
284
284
  result.success?.should == false
285
285
  result.errors.for(:address).on(:country_name)[0].message.should == "Country name is not an accepted country."
@@ -304,7 +304,7 @@ describe Braintree::Address do
304
304
  :locality => "Old Chicago",
305
305
  :region => "IL",
306
306
  :postal_code => "60620",
307
- :country_name => "United States of America"
307
+ :country_name => "United States of America",
308
308
  )
309
309
  updated_address = Braintree::Address.update!(
310
310
  customer.id,
@@ -314,7 +314,7 @@ describe Braintree::Address do
314
314
  :locality => "Chicago",
315
315
  :region => "Illinois",
316
316
  :postal_code => "60621",
317
- :country_name => "United States of America"
317
+ :country_name => "United States of America",
318
318
  )
319
319
  updated_address.should == address
320
320
  updated_address.street_address.should == "123 E New St"
@@ -329,14 +329,14 @@ describe Braintree::Address do
329
329
  customer = Braintree::Customer.create!(:last_name => "Miller")
330
330
  address = Braintree::Address.create!(
331
331
  :customer_id => customer.id,
332
- :country_name => "United States of America"
332
+ :country_name => "United States of America",
333
333
  )
334
334
  expect do
335
335
  Braintree::Address.update!(
336
336
  customer.id,
337
337
  address.id,
338
338
  :street_address => "123 E New St",
339
- :country_name => "United States of Invalid"
339
+ :country_name => "United States of Invalid",
340
340
  )
341
341
  end.to raise_error(Braintree::ValidationsFailed)
342
342
  end