braintree 2.104.1 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (179) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/braintree.gemspec +7 -4
  4. data/lib/braintree.rb +7 -18
  5. data/lib/braintree/account_updater_daily_report.rb +1 -1
  6. data/lib/braintree/address.rb +1 -23
  7. data/lib/braintree/apple_pay.rb +1 -1
  8. data/lib/braintree/apple_pay_card.rb +1 -1
  9. data/lib/braintree/apple_pay_options.rb +1 -1
  10. data/lib/braintree/authorization_adjustment.rb +1 -1
  11. data/lib/braintree/base_module.rb +6 -0
  12. data/lib/braintree/bin_data.rb +9 -2
  13. data/lib/braintree/client_token.rb +1 -1
  14. data/lib/braintree/configuration.rb +12 -12
  15. data/lib/braintree/connected_merchant_paypal_status_changed.rb +1 -1
  16. data/lib/braintree/connected_merchant_status_transitioned.rb +1 -1
  17. data/lib/braintree/credit_card.rb +2 -77
  18. data/lib/braintree/credit_card_gateway.rb +7 -36
  19. data/lib/braintree/credit_card_verification.rb +18 -5
  20. data/lib/braintree/credit_card_verification_search.rb +1 -1
  21. data/lib/braintree/customer.rb +5 -76
  22. data/lib/braintree/customer_gateway.rb +0 -23
  23. data/lib/braintree/customer_search.rb +1 -1
  24. data/lib/braintree/disbursement.rb +1 -1
  25. data/lib/braintree/dispute.rb +2 -8
  26. data/lib/braintree/dispute/{history_event.rb → status_history.rb} +3 -1
  27. data/lib/braintree/dispute_gateway.rb +4 -9
  28. data/lib/braintree/dispute_search.rb +2 -2
  29. data/lib/braintree/document_upload.rb +1 -1
  30. data/lib/braintree/error_codes.rb +151 -170
  31. data/lib/braintree/exceptions.rb +5 -3
  32. data/lib/braintree/gateway.rb +0 -14
  33. data/lib/braintree/{android_pay_card.rb → google_pay_card.rb} +2 -3
  34. data/lib/braintree/granted_payment_instrument_update.rb +1 -1
  35. data/lib/braintree/graphql_client.rb +7 -7
  36. data/lib/braintree/http.rb +3 -3
  37. data/lib/braintree/local_payment_completed.rb +1 -1
  38. data/lib/braintree/local_payment_reversed.rb +19 -0
  39. data/lib/braintree/merchant.rb +1 -1
  40. data/lib/braintree/merchant_account.rb +1 -1
  41. data/lib/braintree/merchant_account_gateway.rb +3 -1
  42. data/lib/braintree/merchant_gateway.rb +1 -1
  43. data/lib/braintree/modification.rb +1 -1
  44. data/lib/braintree/oauth_credentials.rb +1 -1
  45. data/lib/braintree/oauth_gateway.rb +5 -5
  46. data/lib/braintree/payment_instrument_type.rb +10 -14
  47. data/lib/braintree/payment_method_gateway.rb +8 -13
  48. data/lib/braintree/payment_method_nonce_gateway.rb +1 -1
  49. data/lib/braintree/payment_method_parser.rb +1 -8
  50. data/lib/braintree/plan.rb +1 -1
  51. data/lib/braintree/processor_response_types.rb +3 -3
  52. data/lib/braintree/resource_collection.rb +8 -3
  53. data/lib/braintree/revoked_payment_method_metadata.rb +1 -1
  54. data/lib/braintree/risk_data.rb +3 -1
  55. data/lib/braintree/samsung_pay_card.rb +1 -1
  56. data/lib/braintree/settlement_batch_summary.rb +2 -2
  57. data/lib/braintree/subscription.rb +11 -11
  58. data/lib/braintree/successful_result.rb +0 -1
  59. data/lib/braintree/test/credit_card.rb +1 -0
  60. data/lib/braintree/test/nonce.rb +4 -23
  61. data/lib/braintree/three_d_secure_info.rb +22 -12
  62. data/lib/braintree/transaction.rb +44 -104
  63. data/lib/braintree/transaction/disbursement_details.rb +1 -0
  64. data/lib/braintree/transaction/{android_pay_details.rb → google_pay_details.rb} +1 -1
  65. data/lib/braintree/transaction/installment.rb +28 -0
  66. data/lib/braintree/transaction/installment/adjustment.rb +33 -0
  67. data/lib/braintree/transaction/paypal_details.rb +1 -0
  68. data/lib/braintree/transaction/subscription_details.rb +2 -0
  69. data/lib/braintree/transaction_gateway.rb +37 -25
  70. data/lib/braintree/transaction_line_item.rb +1 -1
  71. data/lib/braintree/transaction_search.rb +3 -2
  72. data/lib/braintree/unknown_payment_method.rb +1 -1
  73. data/lib/braintree/us_bank_account.rb +3 -3
  74. data/lib/braintree/us_bank_account_verification.rb +1 -1
  75. data/lib/braintree/us_bank_account_verification_gateway.rb +1 -1
  76. data/lib/braintree/util.rb +21 -6
  77. data/lib/braintree/venmo_account.rb +1 -1
  78. data/lib/braintree/version.rb +3 -3
  79. data/lib/braintree/visa_checkout_card.rb +2 -2
  80. data/lib/braintree/webhook_notification.rb +28 -29
  81. data/lib/braintree/webhook_notification_gateway.rb +5 -5
  82. data/lib/braintree/webhook_testing_gateway.rb +10 -43
  83. data/lib/braintree/xml/generator.rb +5 -4
  84. data/lib/braintree/xml/libxml.rb +1 -0
  85. data/lib/braintree/xml/parser.rb +21 -44
  86. data/spec/integration/braintree/add_on_spec.rb +1 -1
  87. data/spec/integration/braintree/address_spec.rb +26 -113
  88. data/spec/integration/braintree/advanced_search_spec.rb +45 -45
  89. data/spec/integration/braintree/apple_pay_spec.rb +3 -3
  90. data/spec/integration/braintree/braintree_gateway_spec.rb +2 -1
  91. data/spec/integration/braintree/client_api/client_token_spec.rb +14 -14
  92. data/spec/integration/braintree/client_api/spec_helper.rb +5 -31
  93. data/spec/integration/braintree/credit_card_spec.rb +130 -593
  94. data/spec/integration/braintree/credit_card_verification_search_spec.rb +2 -2
  95. data/spec/integration/braintree/credit_card_verification_spec.rb +1 -1
  96. data/spec/integration/braintree/customer_search_spec.rb +8 -8
  97. data/spec/integration/braintree/customer_spec.rb +336 -509
  98. data/spec/integration/braintree/dispute_search_spec.rb +6 -6
  99. data/spec/integration/braintree/dispute_spec.rb +6 -7
  100. data/spec/integration/braintree/error_codes_spec.rb +1 -1
  101. data/spec/integration/braintree/http_spec.rb +2 -2
  102. data/spec/integration/braintree/merchant_account_spec.rb +25 -26
  103. data/spec/integration/braintree/merchant_spec.rb +14 -14
  104. data/spec/integration/braintree/oauth_spec.rb +11 -11
  105. data/spec/integration/braintree/payment_method_nonce_spec.rb +12 -12
  106. data/spec/integration/braintree/payment_method_spec.rb +403 -269
  107. data/spec/integration/braintree/payment_method_us_bank_account_spec.rb +17 -13
  108. data/spec/integration/braintree/paypal_account_spec.rb +28 -28
  109. data/spec/integration/braintree/samsung_pay_card_spec.rb +9 -9
  110. data/spec/integration/braintree/settlement_batch_summary_spec.rb +8 -8
  111. data/spec/integration/braintree/subscription_spec.rb +144 -149
  112. data/spec/integration/braintree/test/transaction_amounts_spec.rb +2 -2
  113. data/spec/integration/braintree/test_transaction_spec.rb +10 -10
  114. data/spec/integration/braintree/transaction_search_spec.rb +96 -70
  115. data/spec/integration/braintree/transaction_spec.rb +832 -904
  116. data/spec/integration/braintree/transaction_us_bank_account_spec.rb +32 -26
  117. data/spec/integration/braintree/us_bank_account_spec.rb +6 -6
  118. data/spec/integration/braintree/us_bank_account_verification_search_spec.rb +7 -7
  119. data/spec/integration/braintree/us_bank_account_verification_spec.rb +8 -8
  120. data/spec/integration/braintree/visa_checkout_card_spec.rb +5 -5
  121. data/spec/integration/spec_helper.rb +10 -7
  122. data/spec/oauth_test_helper.rb +1 -1
  123. data/spec/script/httpsd.rb +6 -6
  124. data/spec/spec_helper.rb +6 -14
  125. data/spec/unit/braintree/address_spec.rb +1 -9
  126. data/spec/unit/braintree/apple_pay_card_spec.rb +1 -1
  127. data/spec/unit/braintree/client_token_spec.rb +2 -2
  128. data/spec/unit/braintree/configuration_spec.rb +42 -42
  129. data/spec/unit/braintree/credit_card_spec.rb +9 -28
  130. data/spec/unit/braintree/credit_card_verification_search_spec.rb +1 -1
  131. data/spec/unit/braintree/credit_card_verification_spec.rb +8 -4
  132. data/spec/unit/braintree/customer_spec.rb +5 -16
  133. data/spec/unit/braintree/disbursement_spec.rb +7 -7
  134. data/spec/unit/braintree/dispute_spec.rb +9 -20
  135. data/spec/unit/braintree/error_result_spec.rb +5 -5
  136. data/spec/unit/braintree/errors_spec.rb +8 -8
  137. data/spec/unit/braintree/http_spec.rb +8 -8
  138. data/spec/unit/braintree/merchant_account_spec.rb +1 -1
  139. data/spec/unit/braintree/payment_method_spec.rb +1 -1
  140. data/spec/unit/braintree/paypal_account_spec.rb +2 -2
  141. data/spec/unit/braintree/resource_collection_spec.rb +30 -1
  142. data/spec/unit/braintree/risk_data_spec.rb +9 -5
  143. data/spec/unit/braintree/subscription_search_spec.rb +1 -1
  144. data/spec/unit/braintree/successful_result_spec.rb +1 -1
  145. data/spec/unit/braintree/three_d_secure_info_spec.rb +32 -14
  146. data/spec/unit/braintree/transaction/credit_card_details_spec.rb +3 -3
  147. data/spec/unit/braintree/transaction/customer_details_spec.rb +1 -1
  148. data/spec/unit/braintree/transaction/deposit_details_spec.rb +2 -2
  149. data/spec/unit/braintree/transaction/installment_spec.rb +25 -0
  150. data/spec/unit/braintree/transaction/paypal_details_spec.rb +3 -1
  151. data/spec/unit/braintree/transaction_search_spec.rb +12 -12
  152. data/spec/unit/braintree/transaction_spec.rb +25 -51
  153. data/spec/unit/braintree/util_spec.rb +55 -21
  154. data/spec/unit/braintree/validation_error_collection_spec.rb +36 -36
  155. data/spec/unit/braintree/webhook_notification_spec.rb +73 -57
  156. data/spec/unit/braintree/xml/parser_spec.rb +21 -16
  157. data/spec/unit/braintree/xml_spec.rb +31 -31
  158. metadata +30 -31
  159. data/lib/braintree/amex_express_checkout_card.rb +0 -40
  160. data/lib/braintree/coinbase_account.rb +0 -34
  161. data/lib/braintree/europe_bank_account.rb +0 -36
  162. data/lib/braintree/europe_bank_account_gateway.rb +0 -17
  163. data/lib/braintree/ideal_payment.rb +0 -61
  164. data/lib/braintree/ideal_payment_gateway.rb +0 -19
  165. data/lib/braintree/masterpass_card.rb +0 -83
  166. data/lib/braintree/settlement_batch.rb +0 -0
  167. data/lib/braintree/transaction/amex_express_checkout_details.rb +0 -21
  168. data/lib/braintree/transaction/coinbase_details.rb +0 -16
  169. data/lib/braintree/transaction/ideal_payment_details.rb +0 -19
  170. data/lib/braintree/transaction/masterpass_card_details.rb +0 -49
  171. data/lib/braintree/transparent_redirect.rb +0 -40
  172. data/lib/braintree/transparent_redirect_gateway.rb +0 -105
  173. data/lib/braintree/xml/rexml.rb +0 -71
  174. data/spec/hacks/tcp_socket.rb +0 -18
  175. data/spec/integration/braintree/coinbase_spec.rb +0 -34
  176. data/spec/integration/braintree/masterpass_card_spec.rb +0 -97
  177. data/spec/integration/braintree/transparent_redirect_spec.rb +0 -268
  178. data/spec/unit/braintree/transparent_redirect_spec.rb +0 -223
  179. data/spec/unit/braintree/xml/rexml_spec.rb +0 -51
@@ -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
@@ -78,17 +78,6 @@ module Braintree
78
78
  _auth_status_transitioned_sample_xml(id)
79
79
  when Braintree::WebhookNotification::Kind::ConnectedMerchantPayPalStatusChanged
80
80
  _auth_paypal_status_changed_sample_xml(id)
81
- # NEXT_MAJOR_VERSION Remove this class as legacy Ideal has been removed/disabled in the Braintree Gateway
82
- # DEPRECATED If you're looking to accept iDEAL as a payment method contact accounts@braintreepayments.com for a solution.
83
- when Braintree::WebhookNotification::Kind::IdealPaymentComplete
84
- _ideal_payment_complete_sample_xml(id)
85
- # NEXT_MAJOR_VERSION Remove this class as legacy Ideal has been removed/disabled in the Braintree Gateway
86
- # DEPRECATED If you're looking to accept iDEAL as a payment method contact accounts@braintreepayments.com for a solution.
87
- when Braintree::WebhookNotification::Kind::IdealPaymentFailed
88
- _ideal_payment_failed_sample_xml(id)
89
- # NEXT_MAJOR_VERSION remove GrantedPaymentInstrumentUpdate
90
- when Braintree::WebhookNotification::Kind::GrantedPaymentInstrumentUpdate
91
- _granted_payment_instrument_update_sample_xml(id)
92
81
  when Braintree::WebhookNotification::Kind::GrantorUpdatedGrantedPaymentMethod
93
82
  _granted_payment_instrument_update_sample_xml(id)
94
83
  when Braintree::WebhookNotification::Kind::RecipientUpdatedGrantedPaymentMethod
@@ -97,6 +86,8 @@ module Braintree
97
86
  _payment_method_revoked_by_customer_sample_xml(id)
98
87
  when Braintree::WebhookNotification::Kind::LocalPaymentCompleted
99
88
  _local_payment_completed_sample_xml(id)
89
+ when Braintree::WebhookNotification::Kind::LocalPaymentReversed
90
+ _local_payment_reversed_sample_xml(id)
100
91
  else
101
92
  _subscription_sample_xml(id)
102
93
  end
@@ -867,38 +858,6 @@ module Braintree
867
858
  XML
868
859
  end
869
860
 
870
- def _ideal_payment_complete_sample_xml(id)
871
- <<-XML
872
- <ideal-payment>
873
- <id>#{id}</id>
874
- <status>COMPLETE</status>
875
- <issuer>ABCISSUER</issuer>
876
- <order-id>ORDERABC</order-id>
877
- <currency>EUR</currency>
878
- <amount>10.00</amount>
879
- <created-at>2016-11-29T23:27:34.547Z</created-at>
880
- <approval-url>https://example.com</approval-url>
881
- <ideal-transaction-id>1234567890</ideal-transaction-id>
882
- </ideal-payment>
883
- XML
884
- end
885
-
886
- def _ideal_payment_failed_sample_xml(id)
887
- <<-XML
888
- <ideal-payment>
889
- <id>#{id}</id>
890
- <status>FAILED</status>
891
- <issuer>ABCISSUER</issuer>
892
- <order-id>ORDERABC</order-id>
893
- <currency>EUR</currency>
894
- <amount>10.00</amount>
895
- <created-at>2016-11-29T23:27:34.547Z</created-at>
896
- <approval-url>https://example.com</approval-url>
897
- <ideal-transaction-id>1234567890</ideal-transaction-id>
898
- </ideal-payment>
899
- XML
900
- end
901
-
902
861
  def _granted_payment_instrument_update_sample_xml(id)
903
862
  <<-XML
904
863
  <granted-payment-instrument-update>
@@ -955,5 +914,13 @@ module Braintree
955
914
  </local-payment>
956
915
  XML
957
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
958
925
  end
959
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,3 +1,4 @@
1
+ require "libxml"
1
2
  # Portions of this code were copied and modified from Ruby on Rails, released
2
3
  # under the MIT license, copyright (c) 2005-2009 David Heinemeier Hansson
3
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 = {
@@ -11,90 +11,67 @@ module Braintree
11
11
  "boolean" => Proc.new { |boolean| %w(1 true).include?(boolean.strip) },
12
12
  }
13
13
 
14
- def self.hash_from_xml(xml, parser = _determine_parser)
15
- standardized_hash_structure = parser.parse(xml)
16
- with_underscores_in_keys = _unrename_keys(standardized_hash_structure)
17
- typecasted_xml = _typecast_xml_value(with_underscores_in_keys)
18
- Util.symbolize_keys(typecasted_xml)
14
+ def self.hash_from_xml(xml)
15
+ standardized_hash_structure = ::Braintree::Xml::Libxml.parse(xml)
16
+ transformed_xml = _transform_xml(standardized_hash_structure)
17
+ Util.symbolize_keys(transformed_xml)
19
18
  end
20
19
 
21
- def self._determine_parser
22
- # LibXML causes a segfault in Ruby 2.0.0. We need to fall back to Rexml to prevent this segfault.
23
- if !RUBY_VERSION.start_with?("2.0") && defined?(::LibXML::XML) && ::LibXML::XML.respond_to?(:default_keep_blanks=)
24
- ::Braintree::Xml::Libxml
25
- else
26
- ::Braintree::Xml::Rexml
27
- end
28
- end
29
-
30
- def self._typecast_xml_value(value)
20
+ # Transform into standard Ruby types and convert all keys to snake_case instead of dash-case
21
+ def self._transform_xml(value)
31
22
  case value.class.to_s
32
- when 'Hash'
33
- if value['type'] == 'array'
34
- 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
35
26
  if entries.nil? || ((c = value[CONTENT_ROOT]) && c.strip.empty?)
36
27
  []
37
28
  else
38
29
  case entries.class.to_s # something weird with classes not matching here. maybe singleton methods breaking is_a?
39
30
  when "Array"
40
- entries.collect { |v| _typecast_xml_value(v) }
31
+ entries.collect { |v| _transform_xml(v) }
41
32
  when "Hash"
42
- [_typecast_xml_value(entries)]
33
+ [_transform_xml(entries)]
43
34
  else
44
35
  raise "can't typecast #{entries.inspect}"
45
36
  end
46
37
  end
47
38
  elsif value.has_key?(CONTENT_ROOT)
48
39
  content = value[CONTENT_ROOT]
49
- if parser = XML_PARSING[value["type"]]
40
+ if (parser = XML_PARSING[value["type"]])
50
41
  XML_PARSING[value["type"]].call(content)
51
42
  else
52
43
  content
53
44
  end
54
- elsif value['type'] == 'string' && value['nil'] != 'true'
45
+ elsif value["type"] == "string" && value["nil"] != "true"
55
46
  ""
56
47
  elsif value == {}
57
48
  ""
58
- elsif value.nil? || value['nil'] == 'true'
49
+ elsif value.nil? || value["nil"] == "true"
59
50
  nil
60
51
  # If the type is the only element which makes it then
61
52
  # this still makes the value nil, except if type is
62
53
  # a XML node(where type['value'] is a Hash)
63
- elsif value['type'] && value.size == 1 && !value['type'].is_a?(::Hash)
54
+ elsif value["type"] && value.size == 1 && !value["type"].is_a?(::Hash)
64
55
  raise "is this needed?"
65
56
  nil
66
57
  else
67
58
  xml_value = value.inject({}) do |h,(k,v)|
68
- h[k] = _typecast_xml_value(v)
59
+ h[k.to_s.tr("-", "_")] = _transform_xml(v) # convert dashes to underscores in keys
69
60
  h
70
61
  end
71
62
  xml_value
72
63
  end
73
- when 'Array'
74
- value.map! { |i| _typecast_xml_value(i) }
64
+ when "Array"
65
+ value.map! { |i| _transform_xml(i) }
75
66
  case value.length
76
67
  when 0 then nil
77
68
  when 1 then value.first
78
69
  else value
79
70
  end
80
- when 'String'
71
+ when "String"
81
72
  value
82
73
  else
83
- raise "can't typecast #{value.class.name} - #{value.inspect}"
84
- end
85
- end
86
-
87
- def self._unrename_keys(params)
88
- case params.class.to_s
89
- when "Hash"
90
- params.inject({}) do |h,(k,v)|
91
- h[k.to_s.tr("-", "_")] = _unrename_keys(v)
92
- h
93
- end
94
- when "Array"
95
- params.map { |v| _unrename_keys(v) }
96
- else
97
- params
74
+ raise "can't transform #{value.class.name} - #{value.inspect}"
98
75
  end
99
76
  end
100
77
  end
@@ -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
@@ -347,98 +347,11 @@ describe Braintree::Address do
347
347
  it "deletes the address" do
348
348
  customer = Braintree::Customer.create!(:last_name => "Wilson")
349
349
  address = Braintree::Address.create!(:customer_id => customer.id, :street_address => "123 E Main St")
350
- address.delete.success?.should == true
350
+ result = Braintree::Address.delete(customer.id, address.id)
351
+ result.success?.should == true
351
352
  expect do
352
353
  Braintree::Address.find(customer.id, address.id)
353
354
  end.to raise_error(Braintree::NotFoundError)
354
355
  end
355
356
  end
356
-
357
- describe "update" do
358
- it "returns a success response and updates the address if valid" do
359
- customer = Braintree::Customer.create!(:last_name => "Miller")
360
- address = Braintree::Address.create!(
361
- :customer_id => customer.id,
362
- :street_address => "1812 E Old St",
363
- :extended_address => "Suite Old 201",
364
- :locality => "Old Chicago",
365
- :region => "IL",
366
- :postal_code => "60620",
367
- :country_name => "United States of America"
368
- )
369
- result = address.update(
370
- :street_address => "123 E New St",
371
- :extended_address => "New Suite 3",
372
- :locality => "Chicago",
373
- :region => "Illinois",
374
- :postal_code => "60621",
375
- :country_name => "United States of America"
376
- )
377
- result.success?.should == true
378
- result.address.should == address
379
- address.street_address.should == "123 E New St"
380
- address.extended_address.should == "New Suite 3"
381
- address.locality.should == "Chicago"
382
- address.region.should == "Illinois"
383
- address.postal_code.should == "60621"
384
- address.country_name.should == "United States of America"
385
- end
386
-
387
- it "returns an error response if invalid" do
388
- customer = Braintree::Customer.create!(:last_name => "Miller")
389
- address = Braintree::Address.create!(
390
- :customer_id => customer.id,
391
- :country_name => "United States of America"
392
- )
393
- result = address.update(
394
- :street_address => "123 E New St",
395
- :country_name => "United States of Invalid"
396
- )
397
- result.success?.should == false
398
- result.errors.for(:address).on(:country_name)[0].message.should == "Country name is not an accepted country."
399
- end
400
- end
401
-
402
- describe "update!" do
403
- it "returns true and updates the address if valid" do
404
- customer = Braintree::Customer.create!(:last_name => "Miller")
405
- address = Braintree::Address.create!(
406
- :customer_id => customer.id,
407
- :street_address => "1812 E Old St",
408
- :extended_address => "Suite Old 201",
409
- :locality => "Old Chicago",
410
- :region => "IL",
411
- :postal_code => "60620",
412
- :country_name => "United States of America"
413
- )
414
- address.update!(
415
- :street_address => "123 E New St",
416
- :extended_address => "New Suite 3",
417
- :locality => "Chicago",
418
- :region => "Illinois",
419
- :postal_code => "60621",
420
- :country_name => "United States of America"
421
- ).should == address
422
- address.street_address.should == "123 E New St"
423
- address.extended_address.should == "New Suite 3"
424
- address.locality.should == "Chicago"
425
- address.region.should == "Illinois"
426
- address.postal_code.should == "60621"
427
- address.country_name.should == "United States of America"
428
- end
429
-
430
- it "raises a ValidationsFailed invalid" do
431
- customer = Braintree::Customer.create!(:last_name => "Miller")
432
- address = Braintree::Address.create!(
433
- :customer_id => customer.id,
434
- :country_name => "United States of America"
435
- )
436
- expect do
437
- address.update!(
438
- :street_address => "123 E New St",
439
- :country_name => "United States of Invalid"
440
- )
441
- end.to raise_error(Braintree::ValidationsFailed)
442
- end
443
- end
444
357
  end