braintree 2.104.0 → 3.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +1 -1
- data/braintree.gemspec +6 -3
- data/lib/braintree.rb +5 -17
- data/lib/braintree/address.rb +0 -22
- data/lib/braintree/base_module.rb +6 -0
- data/lib/braintree/bin_data.rb +9 -2
- data/lib/braintree/configuration.rb +1 -1
- data/lib/braintree/credit_card.rb +0 -75
- data/lib/braintree/credit_card_gateway.rb +4 -33
- data/lib/braintree/credit_card_verification.rb +13 -0
- data/lib/braintree/customer.rb +3 -74
- data/lib/braintree/customer_gateway.rb +0 -23
- data/lib/braintree/dispute.rb +1 -7
- data/lib/braintree/dispute/{history_event.rb → status_history.rb} +3 -1
- data/lib/braintree/dispute_gateway.rb +2 -7
- data/lib/braintree/error_codes.rb +144 -170
- data/lib/braintree/exceptions.rb +5 -3
- data/lib/braintree/gateway.rb +0 -14
- data/lib/braintree/{android_pay_card.rb → google_pay_card.rb} +1 -2
- data/lib/braintree/local_payment_completed.rb +1 -1
- data/lib/braintree/merchant_account_gateway.rb +2 -0
- data/lib/braintree/payment_instrument_type.rb +1 -5
- data/lib/braintree/payment_method_gateway.rb +5 -10
- data/lib/braintree/payment_method_parser.rb +1 -8
- data/lib/braintree/resource_collection.rb +8 -3
- data/lib/braintree/risk_data.rb +3 -1
- data/lib/braintree/subscription.rb +5 -5
- data/lib/braintree/successful_result.rb +0 -1
- data/lib/braintree/test/credit_card.rb +1 -0
- data/lib/braintree/test/nonce.rb +4 -23
- data/lib/braintree/three_d_secure_info.rb +22 -12
- data/lib/braintree/transaction.rb +12 -80
- data/lib/braintree/transaction/disbursement_details.rb +1 -0
- data/lib/braintree/transaction/{android_pay_details.rb → google_pay_details.rb} +1 -1
- data/lib/braintree/transaction/installment.rb +28 -0
- data/lib/braintree/transaction/installment/adjustment.rb +33 -0
- data/lib/braintree/transaction/paypal_details.rb +1 -0
- data/lib/braintree/transaction/subscription_details.rb +2 -0
- data/lib/braintree/transaction_gateway.rb +14 -21
- data/lib/braintree/transaction_search.rb +0 -1
- data/lib/braintree/util.rb +17 -2
- data/lib/braintree/version.rb +2 -2
- data/lib/braintree/webhook_notification.rb +0 -10
- data/lib/braintree/webhook_testing_gateway.rb +0 -43
- data/lib/braintree/xml/libxml.rb +1 -0
- data/lib/braintree/xml/parser.rb +11 -34
- data/spec/integration/braintree/address_spec.rb +2 -89
- data/spec/integration/braintree/client_api/spec_helper.rb +0 -26
- data/spec/integration/braintree/credit_card_spec.rb +13 -476
- data/spec/integration/braintree/customer_spec.rb +189 -362
- data/spec/integration/braintree/dispute_search_spec.rb +3 -3
- data/spec/integration/braintree/dispute_spec.rb +1 -2
- data/spec/integration/braintree/merchant_spec.rb +2 -2
- data/spec/integration/braintree/payment_method_spec.rb +254 -120
- data/spec/integration/braintree/payment_method_us_bank_account_spec.rb +8 -4
- data/spec/integration/braintree/subscription_spec.rb +11 -16
- data/spec/integration/braintree/transaction_search_spec.rb +3 -3
- data/spec/integration/braintree/transaction_spec.rb +324 -550
- data/spec/integration/braintree/transaction_us_bank_account_spec.rb +12 -6
- data/spec/integration/spec_helper.rb +8 -5
- data/spec/spec_helper.rb +2 -11
- data/spec/unit/braintree/address_spec.rb +0 -8
- data/spec/unit/braintree/credit_card_spec.rb +3 -22
- data/spec/unit/braintree/credit_card_verification_spec.rb +6 -2
- data/spec/unit/braintree/customer_spec.rb +2 -13
- data/spec/unit/braintree/dispute_spec.rb +1 -12
- data/spec/unit/braintree/http_spec.rb +3 -3
- data/spec/unit/braintree/local_payment_completed_spec.rb +14 -0
- data/spec/unit/braintree/resource_collection_spec.rb +29 -0
- data/spec/unit/braintree/risk_data_spec.rb +9 -5
- data/spec/unit/braintree/three_d_secure_info_spec.rb +32 -14
- data/spec/unit/braintree/transaction/installment_spec.rb +25 -0
- data/spec/unit/braintree/transaction/paypal_details_spec.rb +2 -0
- data/spec/unit/braintree/transaction_spec.rb +1 -35
- data/spec/unit/braintree/util_spec.rb +37 -3
- data/spec/unit/braintree/webhook_notification_spec.rb +1 -1
- data/spec/unit/braintree/xml/parser_spec.rb +21 -16
- metadata +29 -30
- data/lib/braintree/amex_express_checkout_card.rb +0 -40
- data/lib/braintree/coinbase_account.rb +0 -34
- data/lib/braintree/europe_bank_account.rb +0 -36
- data/lib/braintree/europe_bank_account_gateway.rb +0 -17
- data/lib/braintree/ideal_payment.rb +0 -61
- data/lib/braintree/ideal_payment_gateway.rb +0 -19
- data/lib/braintree/masterpass_card.rb +0 -83
- data/lib/braintree/transaction/amex_express_checkout_details.rb +0 -21
- data/lib/braintree/transaction/coinbase_details.rb +0 -16
- data/lib/braintree/transaction/ideal_payment_details.rb +0 -19
- data/lib/braintree/transaction/masterpass_card_details.rb +0 -49
- data/lib/braintree/transparent_redirect.rb +0 -40
- data/lib/braintree/transparent_redirect_gateway.rb +0 -105
- data/lib/braintree/xml/rexml.rb +0 -71
- data/spec/hacks/tcp_socket.rb +0 -18
- data/spec/integration/braintree/coinbase_spec.rb +0 -34
- data/spec/integration/braintree/masterpass_card_spec.rb +0 -97
- data/spec/integration/braintree/transparent_redirect_spec.rb +0 -268
- data/spec/unit/braintree/transparent_redirect_spec.rb +0 -223
- data/spec/unit/braintree/xml/rexml_spec.rb +0 -51
@@ -0,0 +1,28 @@
|
|
1
|
+
module Braintree
|
2
|
+
class Transaction
|
3
|
+
class Installment
|
4
|
+
include BaseModule
|
5
|
+
|
6
|
+
attr_reader :id
|
7
|
+
attr_reader :amount
|
8
|
+
attr_reader :projected_disbursement_date
|
9
|
+
attr_reader :actual_disbursement_date
|
10
|
+
attr_reader :adjustments
|
11
|
+
|
12
|
+
def initialize(attributes)
|
13
|
+
set_instance_variables_from_hash attributes unless attributes.nil?
|
14
|
+
@amount = Util.to_big_decimal(amount)
|
15
|
+
adjustments.map! { |attrs| Adjustment.new(attrs) } if adjustments
|
16
|
+
end
|
17
|
+
|
18
|
+
def inspect
|
19
|
+
attrs = [:id, :amount, :projected_disbursement_date, :actual_disbursement_date, :adjustments]
|
20
|
+
formatted_attrs = attrs.map do |attr|
|
21
|
+
"#{attr}: #{send(attr).inspect}"
|
22
|
+
end
|
23
|
+
|
24
|
+
"#<#{formatted_attrs.join(", ")}>"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Braintree
|
2
|
+
class Transaction
|
3
|
+
class Installment
|
4
|
+
class Adjustment
|
5
|
+
include BaseModule
|
6
|
+
|
7
|
+
module Kind
|
8
|
+
Refund = "REFUND"
|
9
|
+
Dispute = "DISPUTE"
|
10
|
+
end
|
11
|
+
|
12
|
+
attr_reader :amount
|
13
|
+
attr_reader :kind
|
14
|
+
attr_reader :projected_disbursement_date
|
15
|
+
attr_reader :actual_disbursement_date
|
16
|
+
|
17
|
+
def initialize(attributes)
|
18
|
+
set_instance_variables_from_hash attributes unless attributes.nil?
|
19
|
+
@amount = Util.to_big_decimal(amount)
|
20
|
+
end
|
21
|
+
|
22
|
+
def inspect
|
23
|
+
attrs = [:amount, :kind, :projected_disbursement_date, :actual_disbursement_date]
|
24
|
+
formatted_attrs = attrs.map do |attr|
|
25
|
+
"#{attr}: #{send(attr).inspect}"
|
26
|
+
end
|
27
|
+
|
28
|
+
"#<#{formatted_attrs.join(", ")}>"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -8,6 +8,8 @@ module Braintree
|
|
8
8
|
|
9
9
|
def initialize(attributes)
|
10
10
|
set_instance_variables_from_hash attributes unless attributes.nil?
|
11
|
+
@billing_period_start_date = Date.parse(billing_period_start_date) unless billing_period_start_date.nil?
|
12
|
+
@billing_period_end_date = Date.parse(billing_period_end_date) unless billing_period_end_date.nil?
|
11
13
|
end
|
12
14
|
end
|
13
15
|
end
|
@@ -52,17 +52,6 @@ module Braintree
|
|
52
52
|
return_object_or_raise(:transaction) { clone_transaction(*args) }
|
53
53
|
end
|
54
54
|
|
55
|
-
# Deprecated
|
56
|
-
def create_from_transparent_redirect(query_string)
|
57
|
-
params = @gateway.transparent_redirect.parse_and_validate_query_string query_string
|
58
|
-
_do_create("/transactions/all/confirm_transparent_redirect_request", :id => params[:id])
|
59
|
-
end
|
60
|
-
|
61
|
-
def create_transaction_url
|
62
|
-
warn "[DEPRECATED] Transaction.create_transaction_url is deprecated. Please use TransparentRedirect.url"
|
63
|
-
"#{@config.base_merchant_url}/transactions/all/create_via_transparent_redirect_request"
|
64
|
-
end
|
65
|
-
|
66
55
|
def credit(attributes)
|
67
56
|
create(attributes.merge(:type => 'credit'))
|
68
57
|
end
|
@@ -124,7 +113,7 @@ module Braintree
|
|
124
113
|
if response.has_key?(:search_results)
|
125
114
|
ResourceCollection.new(response) { |ids| _fetch_transactions(search, ids) }
|
126
115
|
else
|
127
|
-
raise
|
116
|
+
raise UnexpectedError, "expected :search_results"
|
128
117
|
end
|
129
118
|
end
|
130
119
|
|
@@ -184,13 +173,14 @@ module Braintree
|
|
184
173
|
|
185
174
|
def self._create_signature # :nodoc:
|
186
175
|
[
|
187
|
-
:amount, :
|
188
|
-
:
|
189
|
-
:
|
190
|
-
:
|
191
|
-
:
|
192
|
-
:
|
193
|
-
:
|
176
|
+
:amount, :billing_address_id, :channel, :customer_id, :device_data, :discount_amount,
|
177
|
+
:merchant_account_id, :order_id, :payment_method_nonce, :payment_method_token,
|
178
|
+
:product_sku, :purchase_order_number, :service_fee_amount, :shared_billing_address_id,
|
179
|
+
:shared_customer_id, :shared_payment_method_nonce, :shared_payment_method_token,
|
180
|
+
:shared_shipping_address_id, :shipping_address_id, :shipping_amount,
|
181
|
+
:ships_from_postal_code, :tax_amount, :tax_exempt, :three_d_secure_authentication_id,
|
182
|
+
:three_d_secure_token, :transaction_source, :type, :venmo_sdk_payment_method_code,
|
183
|
+
:sca_exemption, :currency_iso_code,
|
194
184
|
{:line_items => [:quantity, :name, :description, :kind, :unit_amount, :unit_tax_amount, :total_amount, :discount_amount, :tax_amount, :unit_of_measure, :product_code, :commodity_code, :url]},
|
195
185
|
{:risk_data => [:customer_browser, :customer_device_id, :customer_ip, :customer_location_zip, :customer_tenure]},
|
196
186
|
{:credit_card => [:token, :cardholder_name, :cvv, :expiration_date, :expiration_month, :expiration_year, :number]},
|
@@ -256,8 +246,8 @@ module Braintree
|
|
256
246
|
]},
|
257
247
|
]},
|
258
248
|
{:apple_pay_card => [:number, :cardholder_name, :cryptogram, :expiration_month, :expiration_year, :eci_indicator]},
|
259
|
-
|
260
|
-
{:
|
249
|
+
{:google_pay_card => [:number, :cryptogram, :google_transaction_id, :expiration_month, :expiration_year, :source_card_type, :source_card_last_four, :eci_indicator]},
|
250
|
+
{:installments => [:count]},
|
261
251
|
]
|
262
252
|
end
|
263
253
|
|
@@ -291,6 +281,9 @@ module Braintree
|
|
291
281
|
end
|
292
282
|
|
293
283
|
def _do_create(path, params=nil) # :nodoc:
|
284
|
+
if !params.nil?
|
285
|
+
params = Util.replace_key(params, :google_pay_card, :android_pay_card)
|
286
|
+
end
|
294
287
|
response = @config.http.post("#{@config.base_merchant_path}#{path}", params)
|
295
288
|
_handle_transaction_response(response)
|
296
289
|
end
|
data/lib/braintree/util.rb
CHANGED
@@ -53,6 +53,8 @@ module Braintree
|
|
53
53
|
raise AuthorizationError, message
|
54
54
|
when 404
|
55
55
|
raise NotFoundError
|
56
|
+
when 408
|
57
|
+
raise RequestTimeoutError
|
56
58
|
when 426
|
57
59
|
raise UpgradeRequiredError, "Please upgrade your client library."
|
58
60
|
when 429
|
@@ -60,7 +62,9 @@ module Braintree
|
|
60
62
|
when 500
|
61
63
|
raise ServerError
|
62
64
|
when 503
|
63
|
-
raise
|
65
|
+
raise ServiceUnavailableError
|
66
|
+
when 504
|
67
|
+
raise GatewayTimeoutError
|
64
68
|
else
|
65
69
|
raise UnexpectedError, "Unexpected HTTP_RESPONSE #{status_code.to_i}"
|
66
70
|
end
|
@@ -87,7 +91,7 @@ module Braintree
|
|
87
91
|
when "INTERNAL"
|
88
92
|
raise ServerError
|
89
93
|
when "SERVICE_AVAILABILITY"
|
90
|
-
raise
|
94
|
+
raise ServiceUnavailableError
|
91
95
|
else
|
92
96
|
raise UnexpectedError, "Unexpected Response: #{error[:message]}"
|
93
97
|
end
|
@@ -126,6 +130,17 @@ module Braintree
|
|
126
130
|
!invalid_keys.any?
|
127
131
|
end
|
128
132
|
|
133
|
+
def self.replace_key(hash, target_key, replacement_key)
|
134
|
+
hash.inject({}) do |new_hash, (key, value)|
|
135
|
+
if value.is_a?(Hash)
|
136
|
+
value = replace_key(value, target_key, replacement_key)
|
137
|
+
end
|
138
|
+
|
139
|
+
key = replacement_key if key == target_key
|
140
|
+
new_hash.merge(key => value)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
129
144
|
def self._flatten_valid_keys(valid_keys, namespace = nil)
|
130
145
|
valid_keys.inject([]) do |result, key|
|
131
146
|
if key.is_a?(Hash)
|
data/lib/braintree/version.rb
CHANGED
@@ -36,18 +36,10 @@ module Braintree
|
|
36
36
|
|
37
37
|
AccountUpdaterDailyReport = "account_updater_daily_report"
|
38
38
|
|
39
|
-
# NEXT_MAJOR_VERSION Remove this class as legacy Ideal has been removed/disabled in the Braintree Gateway
|
40
|
-
# DEPRECATED If you're looking to accept iDEAL as a payment method contact accounts@braintreepayments.com for a solution.
|
41
|
-
IdealPaymentComplete = "ideal_payment_complete"
|
42
|
-
IdealPaymentFailed = "ideal_payment_failed"
|
43
|
-
|
44
39
|
OAuthAccessRevoked = "oauth_access_revoked"
|
45
40
|
ConnectedMerchantStatusTransitioned = "connected_merchant_status_transitioned"
|
46
41
|
ConnectedMerchantPayPalStatusChanged = "connected_merchant_paypal_status_changed"
|
47
42
|
|
48
|
-
# NEXT_MAJOR_VERSION remove GrantedPaymentInstrumentUpdate. Kind is not sent by Braintree Gateway.
|
49
|
-
# Kind will either be GrantorUpdatedGrantedPaymentMethod or RecipientUpdatedGrantedPaymentMethod.
|
50
|
-
GrantedPaymentInstrumentUpdate = "granted_payment_instrument_update"
|
51
43
|
GrantorUpdatedGrantedPaymentMethod = "grantor_updated_granted_payment_method"
|
52
44
|
RecipientUpdatedGrantedPaymentMethod = "recipient_updated_granted_payment_method"
|
53
45
|
GrantedPaymentInstrumentRevoked = "granted_payment_instrument_revoked"
|
@@ -63,7 +55,6 @@ module Braintree
|
|
63
55
|
attr_reader :dispute
|
64
56
|
attr_reader :granted_payment_instrument_update
|
65
57
|
attr_reader :revoked_payment_method_metadata
|
66
|
-
attr_reader :ideal_payment
|
67
58
|
attr_reader :kind
|
68
59
|
attr_reader :local_payment_completed
|
69
60
|
attr_reader :oauth_access_revocation
|
@@ -93,7 +84,6 @@ module Braintree
|
|
93
84
|
@disbursement = Disbursement._new(gateway, @subject[:disbursement]) if @subject.has_key?(:disbursement)
|
94
85
|
@dispute = Dispute._new(@subject[:dispute]) if @subject.has_key?(:dispute)
|
95
86
|
@account_updater_daily_report = AccountUpdaterDailyReport._new(@subject[:account_updater_daily_report]) if @subject.has_key?(:account_updater_daily_report)
|
96
|
-
@ideal_payment = Braintree::IdealPayment._new(gateway, @subject[:ideal_payment]) if @subject.has_key?(:ideal_payment)
|
97
87
|
@connected_merchant_status_transitioned = ConnectedMerchantStatusTransitioned._new(@subject[:connected_merchant_status_transitioned]) if @subject.has_key?(:connected_merchant_status_transitioned)
|
98
88
|
@connected_merchant_paypal_status_changed = ConnectedMerchantPayPalStatusChanged._new(@subject[:connected_merchant_paypal_status_changed]) if @subject.has_key?(:connected_merchant_paypal_status_changed)
|
99
89
|
@granted_payment_instrument_update = GrantedPaymentInstrumentUpdate._new(@subject[:granted_payment_instrument_update]) if @subject.has_key?(:granted_payment_instrument_update)
|
@@ -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
|
@@ -867,38 +856,6 @@ module Braintree
|
|
867
856
|
XML
|
868
857
|
end
|
869
858
|
|
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
859
|
def _granted_payment_instrument_update_sample_xml(id)
|
903
860
|
<<-XML
|
904
861
|
<granted-payment-instrument-update>
|
data/lib/braintree/xml/libxml.rb
CHANGED
data/lib/braintree/xml/parser.rb
CHANGED
@@ -11,23 +11,14 @@ 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
|
15
|
-
standardized_hash_structure =
|
16
|
-
|
17
|
-
|
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
|
-
|
22
|
-
|
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
23
|
when 'Hash'
|
33
24
|
if value['type'] == 'array'
|
@@ -37,9 +28,9 @@ module Braintree
|
|
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|
|
31
|
+
entries.collect { |v| _transform_xml(v) }
|
41
32
|
when "Hash"
|
42
|
-
[
|
33
|
+
[_transform_xml(entries)]
|
43
34
|
else
|
44
35
|
raise "can't typecast #{entries.inspect}"
|
45
36
|
end
|
@@ -65,13 +56,13 @@ module Braintree
|
|
65
56
|
nil
|
66
57
|
else
|
67
58
|
xml_value = value.inject({}) do |h,(k,v)|
|
68
|
-
h[k] =
|
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
64
|
when 'Array'
|
74
|
-
value.map! { |i|
|
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
|
@@ -80,21 +71,7 @@ module Braintree
|
|
80
71
|
when 'String'
|
81
72
|
value
|
82
73
|
else
|
83
|
-
raise "can't
|
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
|
@@ -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
|
-
|
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
|