braintree 2.104.0 → 4.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (213) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/braintree.gemspec +7 -4
  4. data/lib/braintree/account_updater_daily_report.rb +1 -1
  5. data/lib/braintree/address.rb +2 -23
  6. data/lib/braintree/apple_pay.rb +1 -1
  7. data/lib/braintree/apple_pay_card.rb +11 -1
  8. data/lib/braintree/apple_pay_options.rb +1 -1
  9. data/lib/braintree/authorization_adjustment.rb +1 -1
  10. data/lib/braintree/base_module.rb +6 -0
  11. data/lib/braintree/bin_data.rb +9 -2
  12. data/lib/braintree/client_token.rb +1 -1
  13. data/lib/braintree/configuration.rb +12 -12
  14. data/lib/braintree/connected_merchant_paypal_status_changed.rb +1 -1
  15. data/lib/braintree/connected_merchant_status_transitioned.rb +1 -1
  16. data/lib/braintree/credit_card.rb +2 -77
  17. data/lib/braintree/credit_card_gateway.rb +17 -36
  18. data/lib/braintree/credit_card_verification.rb +18 -5
  19. data/lib/braintree/credit_card_verification_search.rb +1 -1
  20. data/lib/braintree/customer.rb +9 -78
  21. data/lib/braintree/customer_gateway.rb +2 -23
  22. data/lib/braintree/customer_search.rb +1 -1
  23. data/lib/braintree/disbursement.rb +1 -1
  24. data/lib/braintree/{transaction/coinbase_details.rb → dispute/paypal_message.rb} +5 -6
  25. data/lib/braintree/dispute/{history_event.rb → status_history.rb} +3 -1
  26. data/lib/braintree/dispute.rb +32 -8
  27. data/lib/braintree/dispute_gateway.rb +4 -9
  28. data/lib/braintree/dispute_search.rb +6 -3
  29. data/lib/braintree/document_upload.rb +1 -1
  30. data/lib/braintree/enriched_customer_data.rb +21 -0
  31. data/lib/braintree/error_codes.rb +150 -171
  32. data/lib/braintree/exceptions.rb +5 -3
  33. data/lib/braintree/exchange_rate.rb +13 -0
  34. data/lib/braintree/exchange_rate_quote.rb +24 -0
  35. data/lib/braintree/exchange_rate_quote_gateway.rb +35 -0
  36. data/lib/braintree/exchange_rate_quote_input.rb +21 -0
  37. data/lib/braintree/exchange_rate_quote_request.rb +18 -0
  38. data/lib/braintree/exchange_rate_quote_response.rb +18 -0
  39. data/lib/braintree/gateway.rb +4 -14
  40. data/lib/braintree/{android_pay_card.rb → google_pay_card.rb} +11 -3
  41. data/lib/braintree/granted_payment_instrument_update.rb +1 -1
  42. data/lib/braintree/graphql_client.rb +7 -7
  43. data/lib/braintree/http.rb +4 -3
  44. data/lib/braintree/local_payment_completed.rb +2 -2
  45. data/lib/braintree/local_payment_expired.rb +21 -0
  46. data/lib/braintree/local_payment_funded.rb +22 -0
  47. data/lib/braintree/local_payment_reversed.rb +19 -0
  48. data/lib/braintree/merchant.rb +1 -1
  49. data/lib/braintree/merchant_account.rb +1 -1
  50. data/lib/braintree/merchant_account_gateway.rb +3 -1
  51. data/lib/braintree/merchant_gateway.rb +1 -1
  52. data/lib/braintree/modification.rb +1 -1
  53. data/lib/braintree/oauth_credentials.rb +1 -1
  54. data/lib/braintree/oauth_gateway.rb +5 -5
  55. data/lib/braintree/payment_instrument_type.rb +10 -14
  56. data/lib/braintree/payment_method_customer_data_updated_metadata.rb +24 -0
  57. data/lib/braintree/payment_method_gateway.rb +15 -17
  58. data/lib/braintree/payment_method_nonce.rb +7 -4
  59. data/lib/braintree/payment_method_nonce_details.rb +37 -0
  60. data/lib/braintree/payment_method_nonce_details_payer_info.rb +32 -0
  61. data/lib/braintree/payment_method_nonce_gateway.rb +1 -1
  62. data/lib/braintree/payment_method_parser.rb +1 -8
  63. data/lib/braintree/plan.rb +21 -1
  64. data/lib/braintree/plan_gateway.rb +100 -0
  65. data/lib/braintree/processor_response_types.rb +3 -3
  66. data/lib/braintree/resource_collection.rb +8 -3
  67. data/lib/braintree/revoked_payment_method_metadata.rb +1 -1
  68. data/lib/braintree/risk_data/liability_shift.rb +22 -0
  69. data/lib/braintree/risk_data.rb +5 -1
  70. data/lib/braintree/samsung_pay_card.rb +1 -1
  71. data/lib/braintree/settlement_batch_summary.rb +2 -2
  72. data/lib/braintree/subscription.rb +11 -11
  73. data/lib/braintree/successful_result.rb +3 -2
  74. data/lib/braintree/test/credit_card.rb +1 -0
  75. data/lib/braintree/test/nonce.rb +4 -23
  76. data/lib/braintree/three_d_secure_info.rb +22 -12
  77. data/lib/braintree/transaction/disbursement_details.rb +1 -0
  78. data/lib/braintree/transaction/{android_pay_details.rb → google_pay_details.rb} +1 -1
  79. data/lib/braintree/transaction/installment/adjustment.rb +33 -0
  80. data/lib/braintree/transaction/installment.rb +28 -0
  81. data/lib/braintree/transaction/paypal_details.rb +3 -0
  82. data/lib/braintree/transaction/subscription_details.rb +2 -0
  83. data/lib/braintree/transaction.rb +65 -120
  84. data/lib/braintree/transaction_gateway.rb +39 -27
  85. data/lib/braintree/transaction_line_item.rb +1 -1
  86. data/lib/braintree/transaction_review.rb +18 -0
  87. data/lib/braintree/transaction_search.rb +5 -3
  88. data/lib/braintree/unknown_payment_method.rb +1 -1
  89. data/lib/braintree/us_bank_account.rb +3 -3
  90. data/lib/braintree/us_bank_account_verification.rb +1 -1
  91. data/lib/braintree/us_bank_account_verification_gateway.rb +1 -1
  92. data/lib/braintree/util.rb +21 -6
  93. data/lib/braintree/venmo_account.rb +1 -1
  94. data/lib/braintree/venmo_profile_data.rb +23 -0
  95. data/lib/braintree/version.rb +2 -2
  96. data/lib/braintree/visa_checkout_card.rb +2 -2
  97. data/lib/braintree/webhook_notification.rb +44 -30
  98. data/lib/braintree/webhook_notification_gateway.rb +5 -5
  99. data/lib/braintree/webhook_testing_gateway.rb +104 -43
  100. data/lib/braintree/xml/generator.rb +5 -4
  101. data/lib/braintree/xml/parser.rb +22 -35
  102. data/lib/braintree/xml/rexml.rb +4 -5
  103. data/lib/braintree.rb +28 -23
  104. data/spec/integration/braintree/add_on_spec.rb +1 -1
  105. data/spec/integration/braintree/address_spec.rb +30 -113
  106. data/spec/integration/braintree/advanced_search_spec.rb +45 -45
  107. data/spec/integration/braintree/apple_pay_spec.rb +3 -3
  108. data/spec/integration/braintree/braintree_gateway_spec.rb +2 -1
  109. data/spec/integration/braintree/client_api/client_token_spec.rb +14 -14
  110. data/spec/integration/braintree/client_api/spec_helper.rb +5 -31
  111. data/spec/integration/braintree/credit_card_spec.rb +219 -593
  112. data/spec/integration/braintree/credit_card_verification_search_spec.rb +2 -2
  113. data/spec/integration/braintree/credit_card_verification_spec.rb +1 -1
  114. data/spec/integration/braintree/customer_search_spec.rb +8 -8
  115. data/spec/integration/braintree/customer_spec.rb +484 -513
  116. data/spec/integration/braintree/dispute_search_spec.rb +35 -6
  117. data/spec/integration/braintree/dispute_spec.rb +6 -7
  118. data/spec/integration/braintree/error_codes_spec.rb +1 -1
  119. data/spec/integration/braintree/exchange_rate_quote_spec.rb +97 -0
  120. data/spec/integration/braintree/graphql_client_spec.rb +0 -2
  121. data/spec/integration/braintree/http_spec.rb +2 -2
  122. data/spec/integration/braintree/merchant_account_spec.rb +28 -29
  123. data/spec/integration/braintree/merchant_spec.rb +14 -14
  124. data/spec/integration/braintree/oauth_spec.rb +11 -11
  125. data/spec/integration/braintree/payment_method_nonce_spec.rb +29 -35
  126. data/spec/integration/braintree/payment_method_spec.rb +535 -270
  127. data/spec/integration/braintree/payment_method_us_bank_account_spec.rb +17 -13
  128. data/spec/integration/braintree/paypal_account_spec.rb +28 -28
  129. data/spec/integration/braintree/plan_spec.rb +82 -0
  130. data/spec/integration/braintree/samsung_pay_card_spec.rb +9 -9
  131. data/spec/integration/braintree/settlement_batch_summary_spec.rb +8 -8
  132. data/spec/integration/braintree/subscription_spec.rb +144 -149
  133. data/spec/integration/braintree/test/transaction_amounts_spec.rb +2 -2
  134. data/spec/integration/braintree/test_transaction_spec.rb +10 -10
  135. data/spec/integration/braintree/transaction_search_spec.rb +175 -70
  136. data/spec/integration/braintree/transaction_spec.rb +955 -894
  137. data/spec/integration/braintree/transaction_us_bank_account_spec.rb +32 -26
  138. data/spec/integration/braintree/us_bank_account_spec.rb +6 -6
  139. data/spec/integration/braintree/us_bank_account_verification_search_spec.rb +7 -7
  140. data/spec/integration/braintree/us_bank_account_verification_spec.rb +8 -8
  141. data/spec/integration/braintree/visa_checkout_card_spec.rb +5 -5
  142. data/spec/integration/spec_helper.rb +16 -7
  143. data/spec/oauth_test_helper.rb +1 -1
  144. data/spec/script/httpsd.rb +6 -6
  145. data/spec/spec_helper.rb +8 -14
  146. data/spec/unit/braintree/address_spec.rb +1 -9
  147. data/spec/unit/braintree/apple_pay_card_spec.rb +7 -1
  148. data/spec/unit/braintree/client_token_spec.rb +2 -2
  149. data/spec/unit/braintree/configuration_spec.rb +42 -42
  150. data/spec/unit/braintree/credit_card_spec.rb +13 -32
  151. data/spec/unit/braintree/credit_card_verification_search_spec.rb +1 -1
  152. data/spec/unit/braintree/credit_card_verification_spec.rb +8 -4
  153. data/spec/unit/braintree/customer_spec.rb +21 -22
  154. data/spec/unit/braintree/disbursement_spec.rb +7 -7
  155. data/spec/unit/braintree/dispute_search_spec.rb +3 -0
  156. data/spec/unit/braintree/dispute_spec.rb +75 -21
  157. data/spec/unit/braintree/enriched_customer_data_spec.rb +32 -0
  158. data/spec/unit/braintree/error_result_spec.rb +5 -5
  159. data/spec/unit/braintree/errors_spec.rb +8 -8
  160. data/spec/unit/braintree/exchange_rate_quote_input_spec.rb +42 -0
  161. data/spec/unit/braintree/exchange_rate_quote_request_spec.rb +82 -0
  162. data/spec/unit/braintree/exchange_rate_quote_response_spec.rb +52 -0
  163. data/spec/unit/braintree/exchange_rate_quote_spec.rb +42 -0
  164. data/spec/unit/braintree/exchange_rate_spec.rb +23 -0
  165. data/spec/unit/braintree/http_spec.rb +10 -8
  166. data/spec/unit/braintree/local_payment_completed_spec.rb +14 -0
  167. data/spec/unit/braintree/local_payment_expired_spec.rb +24 -0
  168. data/spec/unit/braintree/local_payment_funded_spec.rb +34 -0
  169. data/spec/unit/braintree/merchant_account_spec.rb +1 -1
  170. data/spec/unit/braintree/payment_method_customer_data_updated_metadata_spec.rb +45 -0
  171. data/spec/unit/braintree/payment_method_nonce_details_payer_info_spec.rb +31 -0
  172. data/spec/unit/braintree/payment_method_nonce_details_spec.rb +43 -0
  173. data/spec/unit/braintree/payment_method_nonce_spec.rb +40 -0
  174. data/spec/unit/braintree/payment_method_spec.rb +1 -1
  175. data/spec/unit/braintree/paypal_account_spec.rb +2 -2
  176. data/spec/unit/braintree/resource_collection_spec.rb +30 -1
  177. data/spec/unit/braintree/risk_data/liability_shift.rb +26 -0
  178. data/spec/unit/braintree/risk_data_spec.rb +38 -8
  179. data/spec/unit/braintree/subscription_search_spec.rb +1 -1
  180. data/spec/unit/braintree/successful_result_spec.rb +1 -1
  181. data/spec/unit/braintree/three_d_secure_info_spec.rb +32 -14
  182. data/spec/unit/braintree/transaction/credit_card_details_spec.rb +3 -3
  183. data/spec/unit/braintree/transaction/customer_details_spec.rb +1 -1
  184. data/spec/unit/braintree/transaction/deposit_details_spec.rb +2 -2
  185. data/spec/unit/braintree/transaction/installment_spec.rb +25 -0
  186. data/spec/unit/braintree/transaction/paypal_details_spec.rb +7 -1
  187. data/spec/unit/braintree/transaction_search_spec.rb +12 -12
  188. data/spec/unit/braintree/transaction_spec.rb +36 -54
  189. data/spec/unit/braintree/util_spec.rb +55 -21
  190. data/spec/unit/braintree/validation_error_collection_spec.rb +36 -36
  191. data/spec/unit/braintree/venmo_profile_data_spec.rb +32 -0
  192. data/spec/unit/braintree/webhook_notification_spec.rb +166 -57
  193. data/spec/unit/braintree/xml/parser_spec.rb +21 -16
  194. data/spec/unit/braintree/xml_spec.rb +31 -31
  195. metadata +62 -30
  196. data/lib/braintree/amex_express_checkout_card.rb +0 -40
  197. data/lib/braintree/coinbase_account.rb +0 -34
  198. data/lib/braintree/europe_bank_account.rb +0 -36
  199. data/lib/braintree/europe_bank_account_gateway.rb +0 -17
  200. data/lib/braintree/ideal_payment.rb +0 -61
  201. data/lib/braintree/ideal_payment_gateway.rb +0 -19
  202. data/lib/braintree/masterpass_card.rb +0 -83
  203. data/lib/braintree/settlement_batch.rb +0 -0
  204. data/lib/braintree/transaction/amex_express_checkout_details.rb +0 -21
  205. data/lib/braintree/transaction/ideal_payment_details.rb +0 -19
  206. data/lib/braintree/transaction/masterpass_card_details.rb +0 -49
  207. data/lib/braintree/transparent_redirect.rb +0 -40
  208. data/lib/braintree/transparent_redirect_gateway.rb +0 -105
  209. data/spec/hacks/tcp_socket.rb +0 -18
  210. data/spec/integration/braintree/coinbase_spec.rb +0 -34
  211. data/spec/integration/braintree/masterpass_card_spec.rb +0 -97
  212. data/spec/integration/braintree/transparent_redirect_spec.rb +0 -268
  213. data/spec/unit/braintree/transparent_redirect_spec.rb +0 -223
@@ -1,40 +0,0 @@
1
- module Braintree
2
- module TransparentRedirect
3
- module Kind # :nodoc:
4
- CreateCustomer = "create_customer"
5
- UpdateCustomer = "update_customer"
6
- CreatePaymentMethod = "create_payment_method"
7
- UpdatePaymentMethod = "update_payment_method"
8
- CreateTransaction = "create_transaction"
9
- end
10
-
11
- def self.confirm(*args)
12
- Configuration.gateway.transparent_redirect.confirm(*args)
13
- end
14
-
15
- def self.create_credit_card_data(*args)
16
- Configuration.gateway.transparent_redirect.create_credit_card_data(*args)
17
- end
18
-
19
- def self.create_customer_data(*args)
20
- Configuration.gateway.transparent_redirect.create_customer_data(*args)
21
- end
22
-
23
- def self.transaction_data(*args)
24
- Configuration.gateway.transparent_redirect.transaction_data(*args)
25
- end
26
-
27
- def self.update_credit_card_data(*args)
28
- Configuration.gateway.transparent_redirect.update_credit_card_data(*args)
29
- end
30
-
31
- def self.update_customer_data(*args)
32
- Configuration.gateway.transparent_redirect.update_customer_data(*args)
33
- end
34
-
35
- # Returns the URL to which Transparent Redirect Requests should be posted
36
- def self.url
37
- Configuration.gateway.transparent_redirect.url
38
- end
39
- end
40
- end
@@ -1,105 +0,0 @@
1
- module Braintree
2
- class TransparentRedirectGateway # :nodoc
3
- TransparentRedirectKeys = [:redirect_url] # :nodoc:
4
- CreateCustomerSignature = TransparentRedirectKeys + [{:customer => CustomerGateway._create_signature}] # :nodoc:
5
- UpdateCustomerSignature = TransparentRedirectKeys + [:customer_id, {:customer => CustomerGateway._update_signature}] # :nodoc:
6
- TransactionSignature = TransparentRedirectKeys + [{:transaction => TransactionGateway._create_signature}] # :nodoc:
7
- CreateCreditCardSignature = TransparentRedirectKeys + [{:credit_card => CreditCardGateway._create_signature}] # :nodoc:
8
- UpdateCreditCardSignature = TransparentRedirectKeys + [:payment_method_token, {:credit_card => CreditCardGateway._update_signature}] # :nodoc:
9
-
10
- def initialize(gateway)
11
- @gateway = gateway
12
- @config = gateway.config
13
- @config.assert_has_access_token_or_keys
14
- end
15
-
16
- def confirm(query_string)
17
- params = @gateway.transparent_redirect.parse_and_validate_query_string query_string
18
- confirmation_gateway = {
19
- TransparentRedirect::Kind::CreateCustomer => :customer,
20
- TransparentRedirect::Kind::UpdateCustomer => :customer,
21
- TransparentRedirect::Kind::CreatePaymentMethod => :credit_card,
22
- TransparentRedirect::Kind::UpdatePaymentMethod => :credit_card,
23
- TransparentRedirect::Kind::CreateTransaction => :transaction
24
- }[params[:kind]]
25
-
26
- @gateway.send(confirmation_gateway)._do_create("/transparent_redirect_requests/#{params[:id]}/confirm")
27
- end
28
-
29
- def create_credit_card_data(params)
30
- Util.verify_keys(CreateCreditCardSignature, params)
31
- params[:kind] = TransparentRedirect::Kind::CreatePaymentMethod
32
- _data(params)
33
- end
34
-
35
- def create_customer_data(params)
36
- Util.verify_keys(CreateCustomerSignature, params)
37
- params[:kind] = TransparentRedirect::Kind::CreateCustomer
38
- _data(params)
39
- end
40
-
41
- def parse_and_validate_query_string(query_string) # :nodoc:
42
- params = Util.symbolize_keys(Util.parse_query_string(query_string))
43
- query_string_without_hash = query_string.split("&").reject{|param| param =~ /\Ahash=/}.join("&")
44
- decoded_query_string_without_hash = Util.url_decode(query_string_without_hash)
45
- encoded_query_string_without_hash = Util.url_encode(query_string_without_hash)
46
-
47
- if params[:http_status] == nil
48
- raise UnexpectedError, "expected query string to have an http_status param"
49
- elsif params[:http_status] != '200'
50
- Util.raise_exception_for_status_code(params[:http_status], params[:bt_message])
51
- end
52
-
53
- query_strings_without_hash = [query_string_without_hash, encoded_query_string_without_hash, decoded_query_string_without_hash]
54
-
55
- if query_strings_without_hash.any? { |query_string| @config.signature_service.hash(query_string) == params[:hash] }
56
- params
57
- else
58
- raise ForgedQueryString
59
- end
60
- end
61
-
62
- def transaction_data(params)
63
- Util.verify_keys(TransactionSignature, params)
64
- params[:kind] = TransparentRedirect::Kind::CreateTransaction
65
- transaction_type = params[:transaction] && params[:transaction][:type]
66
- unless %w[sale credit].include?(transaction_type)
67
- raise ArgumentError, "expected transaction[type] of sale or credit, was: #{transaction_type.inspect}"
68
- end
69
- _data(params)
70
- end
71
-
72
- def update_credit_card_data(params)
73
- Util.verify_keys(UpdateCreditCardSignature, params)
74
- unless params[:payment_method_token]
75
- raise ArgumentError, "expected params to contain :payment_method_token of payment method to update"
76
- end
77
- params[:kind] = TransparentRedirect::Kind::UpdatePaymentMethod
78
- _data(params)
79
- end
80
-
81
- def update_customer_data(params)
82
- Util.verify_keys(UpdateCustomerSignature, params)
83
- unless params[:customer_id]
84
- raise ArgumentError, "expected params to contain :customer_id of customer to update"
85
- end
86
- params[:kind] = TransparentRedirect::Kind::UpdateCustomer
87
- _data(params)
88
- end
89
-
90
- def url
91
- "#{@config.base_merchant_url}/transparent_redirect_requests"
92
- end
93
-
94
- def _data(params) # :nodoc:
95
- raise ArgumentError, "expected params to contain :redirect_url" unless params[:redirect_url]
96
-
97
- @config.signature_service.sign(params.merge(
98
- :api_version => @config.api_version,
99
- :time => Time.now.utc.strftime("%Y%m%d%H%M%S"),
100
- :public_key => @config.public_key
101
- ))
102
- end
103
- end
104
- end
105
-
@@ -1,18 +0,0 @@
1
- require 'timeout'
2
- require 'socket'
3
-
4
- TCPSocket.class_eval do
5
- def self.wait_for_service(options)
6
- Timeout::timeout(options[:timeout] || 20) do
7
- loop do
8
- begin
9
- socket = TCPSocket.new(options[:host], options[:port])
10
- socket.close
11
- return
12
- rescue Errno::ECONNREFUSED
13
- sleep 0.5
14
- end
15
- end
16
- end
17
- end
18
- end
@@ -1,34 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
-
3
- describe "Coinbase" do
4
-
5
- def assert_valid_coinbase_attrs(account_or_details)
6
- [:user_id, :user_name, :user_email].each do |attr|
7
- [nil,""].should_not include(account_or_details.send(attr))
8
- end
9
- end
10
-
11
- it "is no longer supported with transaction#create" do
12
- result = Braintree::Transaction.sale(:payment_method_nonce => Braintree::Test::Nonce::Coinbase, :amount => "0.02")
13
- result.should_not be_success
14
-
15
- result.errors.for(:transaction).first.code.should == Braintree::ErrorCodes::PaymentMethod::PaymentMethodNoLongerSupported
16
- end
17
-
18
- it "is no longer supported for vaulting" do
19
- customer = Braintree::Customer.create!
20
- result = Braintree::PaymentMethod.create(:customer_id => customer.id, :payment_method_nonce => Braintree::Test::Nonce::Coinbase)
21
- result.should_not be_success
22
-
23
- result.errors.for(:coinbase_account).first.code.should == Braintree::ErrorCodes::PaymentMethod::PaymentMethodNoLongerSupported
24
- end
25
-
26
- it "is no longer supported when creating a Customer with a Coinbase payment method nonce" do
27
- expect do
28
- Braintree::Customer.create!(:payment_method_nonce => Braintree::Test::Nonce::Coinbase)
29
- end.to raise_error { |error|
30
- error.should be_a(Braintree::ValidationsFailed)
31
- error.error_result.errors.for(:coinbase_account).first.code.should == Braintree::ErrorCodes::PaymentMethod::PaymentMethodNoLongerSupported
32
- }
33
- end
34
- end
@@ -1,97 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
- require File.expand_path(File.dirname(__FILE__) + "/client_api/spec_helper")
3
-
4
- describe Braintree::MasterpassCard do
5
- it "can create from a payment method nonce" do
6
- customer = Braintree::Customer.create!
7
-
8
- result = Braintree::PaymentMethod.create(
9
- :payment_method_nonce => Braintree::Test::Nonce::MasterpassDiscover,
10
- :customer_id => customer.id
11
- )
12
- result.should be_success
13
-
14
- masterpass_card = result.payment_method
15
- masterpass_card.should be_a(Braintree::MasterpassCard)
16
- masterpass_card.billing_address.should_not be_nil
17
- masterpass_card.bin.should_not be_nil
18
- masterpass_card.card_type.should_not be_nil
19
- masterpass_card.cardholder_name.should_not be_nil
20
- masterpass_card.commercial.should_not be_nil
21
- masterpass_card.country_of_issuance.should_not be_nil
22
- masterpass_card.created_at.should_not be_nil
23
- masterpass_card.customer_id.should_not be_nil
24
- masterpass_card.customer_location.should_not be_nil
25
- masterpass_card.debit.should_not be_nil
26
- masterpass_card.default?.should_not be_nil
27
- masterpass_card.durbin_regulated.should_not be_nil
28
- masterpass_card.expiration_date.should_not be_nil
29
- masterpass_card.expiration_month.should_not be_nil
30
- masterpass_card.expiration_year.should_not be_nil
31
- masterpass_card.expired?.should_not be_nil
32
- masterpass_card.healthcare.should_not be_nil
33
- masterpass_card.image_url.should_not be_nil
34
- masterpass_card.issuing_bank.should_not be_nil
35
- masterpass_card.last_4.should_not be_nil
36
- masterpass_card.payroll.should_not be_nil
37
- masterpass_card.prepaid.should_not be_nil
38
- masterpass_card.product_id.should_not be_nil
39
- masterpass_card.subscriptions.should_not be_nil
40
- masterpass_card.token.should_not be_nil
41
- masterpass_card.unique_number_identifier.should_not be_nil
42
- masterpass_card.updated_at.should_not be_nil
43
-
44
- customer = Braintree::Customer.find(customer.id)
45
- customer.masterpass_cards.size.should == 1
46
- customer.masterpass_cards.first.should == masterpass_card
47
- end
48
-
49
- it "can search for transactions" do
50
- transaction_create_result = Braintree::Transaction.sale(
51
- :payment_method_nonce => Braintree::Test::Nonce::MasterpassDiscover,
52
- :amount => '47.00',
53
- )
54
- transaction_create_result.should be_success
55
- transaction_id = transaction_create_result.transaction.id
56
-
57
- search_results = Braintree::Transaction.search do |search|
58
- search.id.is transaction_id
59
- search.payment_instrument_type.is Braintree::PaymentInstrumentType::MasterpassCard
60
- end
61
- search_results.first.id.should == transaction_id
62
- end
63
-
64
- it "can create transaction from nonce and vault" do
65
- customer = Braintree::Customer.create!
66
-
67
- result = Braintree::Transaction.sale(
68
- :payment_method_nonce => Braintree::Test::Nonce::MasterpassDiscover,
69
- :customer_id => customer.id,
70
- :amount => '47.00',
71
- :options => { :store_in_vault => true },
72
- )
73
- result.should be_success
74
-
75
- masterpass_card_details = result.transaction.masterpass_card_details
76
- masterpass_card_details.bin.should_not be_nil
77
- masterpass_card_details.card_type.should_not be_nil
78
- masterpass_card_details.cardholder_name.should_not be_nil
79
- masterpass_card_details.commercial.should_not be_nil
80
- masterpass_card_details.country_of_issuance.should_not be_nil
81
- masterpass_card_details.customer_location.should_not be_nil
82
- masterpass_card_details.debit.should_not be_nil
83
- masterpass_card_details.durbin_regulated.should_not be_nil
84
- masterpass_card_details.expiration_date.should_not be_nil
85
- masterpass_card_details.expiration_month.should_not be_nil
86
- masterpass_card_details.expiration_year.should_not be_nil
87
- masterpass_card_details.healthcare.should_not be_nil
88
- masterpass_card_details.image_url.should_not be_nil
89
- masterpass_card_details.issuing_bank.should_not be_nil
90
- masterpass_card_details.last_4.should_not be_nil
91
- masterpass_card_details.payroll.should_not be_nil
92
- masterpass_card_details.prepaid.should_not be_nil
93
- masterpass_card_details.product_id.should_not be_nil
94
- masterpass_card_details.token.should_not be_nil
95
- end
96
- end
97
-
@@ -1,268 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
-
3
- describe Braintree::TransparentRedirect do
4
- it "raises a DownForMaintenanceError when app is in maintenance mode on TR requests" do
5
- tr_data = Braintree::TransparentRedirect.create_customer_data({:redirect_url => "http://example.com"}.merge({}))
6
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, {}, Braintree::Configuration.instantiate.base_merchant_url + "/test/maintenance")
7
- expect do
8
- Braintree::Customer.create_from_transparent_redirect(query_string_response)
9
- end.to raise_error(Braintree::DownForMaintenanceError)
10
- end
11
-
12
- it "raises a DownForMaintenanceError when the request times out", :if => ENV['UNICORN'] do
13
- tr_data = Braintree::TransparentRedirect.create_customer_data({:redirect_url => "http://example.com"}.merge({}))
14
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, {}, Braintree::Configuration.instantiate.base_merchant_url + "/test/die")
15
- expect do
16
- Braintree::Customer.create_from_transparent_redirect(query_string_response)
17
- end.to raise_error(Braintree::DownForMaintenanceError)
18
- end
19
-
20
- it "raises an AuthenticationError when authentication fails on TR requests" do
21
- SpecHelper.using_configuration(:private_key => "incorrect") do
22
- tr_data = Braintree::TransparentRedirect.create_customer_data({:redirect_url => "http://example.com"}.merge({}))
23
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, {}, Braintree::Customer.create_customer_url)
24
- expect do
25
- Braintree::Customer.create_from_transparent_redirect(query_string_response)
26
- end.to raise_error(Braintree::AuthenticationError)
27
- end
28
- end
29
-
30
- describe "self.confirm" do
31
- context "transaction" do
32
- it "successfully confirms a transaction create" do
33
- params = {
34
- :transaction => {
35
- :amount => Braintree::Test::TransactionAmounts::Authorize,
36
- :credit_card => {
37
- :number => Braintree::Test::CreditCardNumbers::Visa,
38
- :expiration_date => "05/2009"
39
- }
40
- }
41
- }
42
- tr_data_params = {
43
- :transaction => {
44
- :type => "sale"
45
- }
46
- }
47
- tr_data = Braintree::TransparentRedirect.transaction_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
48
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params)
49
- result = Braintree::TransparentRedirect.confirm(query_string_response)
50
-
51
- result.success?.should == true
52
- transaction = result.transaction
53
- transaction.type.should == "sale"
54
- transaction.amount.should == BigDecimal("1000.00")
55
- transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
56
- transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
57
- transaction.credit_card_details.expiration_date.should == "05/2009"
58
- end
59
-
60
- it "allows specifying a service fee" do
61
- params = {
62
- :transaction => {
63
- :amount => Braintree::Test::TransactionAmounts::Authorize,
64
- :merchant_account_id => SpecHelper::NonDefaultSubMerchantAccountId,
65
- :credit_card => {
66
- :number => Braintree::Test::CreditCardNumbers::Visa,
67
- :expiration_date => "05/2009"
68
- },
69
- :service_fee_amount => "1.00"
70
- }
71
- }
72
- tr_data_params = {
73
- :transaction => {
74
- :type => "sale"
75
- }
76
- }
77
- tr_data = Braintree::TransparentRedirect.transaction_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
78
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params)
79
- result = Braintree::TransparentRedirect.confirm(query_string_response)
80
- result.success?.should == true
81
- result.transaction.service_fee_amount.should == BigDecimal("1.00")
82
- end
83
-
84
- it "returns an error when there's an error" do
85
- params = {
86
- :transaction => {
87
- :amount => Braintree::Test::TransactionAmounts::Authorize,
88
- :credit_card => {
89
- :number => "abc",
90
- :expiration_date => "05/2009"
91
- }
92
- }
93
- }
94
- tr_data_params = {
95
- :transaction => {
96
- :type => "sale"
97
- }
98
- }
99
- tr_data = Braintree::TransparentRedirect.transaction_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
100
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params)
101
- result = Braintree::TransparentRedirect.confirm(query_string_response)
102
-
103
- result.success?.should == false
104
- result.errors.for(:transaction).for(:credit_card).on(:number).size.should > 0
105
- end
106
- end
107
-
108
- context "customer" do
109
- it "successfully confirms a customer create" do
110
- params = {
111
- :customer => {
112
- :first_name => "John",
113
- }
114
- }
115
- tr_data_params = {
116
- :customer => {
117
- :last_name => "Doe",
118
- }
119
- }
120
- tr_data = Braintree::TransparentRedirect.create_customer_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
121
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params)
122
- result = Braintree::TransparentRedirect.confirm(query_string_response)
123
-
124
- result.success?.should == true
125
- customer = result.customer
126
- customer.first_name.should == "John"
127
- customer.last_name.should == "Doe"
128
- end
129
-
130
- it "successfully confirms a customer update" do
131
- customer = Braintree::Customer.create(
132
- :first_name => "Joe",
133
- :last_name => "Cool"
134
- ).customer
135
-
136
- params = {
137
- :customer => {
138
- :first_name => "John",
139
- }
140
- }
141
- tr_data_params = {
142
- :customer_id => customer.id,
143
- :customer => {
144
- :last_name => "Uncool",
145
- }
146
- }
147
- tr_data = Braintree::TransparentRedirect.update_customer_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
148
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params)
149
- result = Braintree::TransparentRedirect.confirm(query_string_response)
150
-
151
- result.success?.should == true
152
- customer = Braintree::Customer.find(customer.id)
153
- customer.first_name.should == "John"
154
- customer.last_name.should == "Uncool"
155
- end
156
-
157
- it "returns an error result when there are errors" do
158
- params = {
159
- :customer => {
160
- :first_name => "John",
161
- }
162
- }
163
- tr_data_params = {
164
- :customer => {
165
- :last_name => "Doe",
166
- :email => "invalid"
167
- }
168
- }
169
- tr_data = Braintree::TransparentRedirect.create_customer_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
170
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params)
171
- result = Braintree::TransparentRedirect.confirm(query_string_response)
172
-
173
- result.success?.should == false
174
- result.errors.for(:customer).on(:email).size.should > 0
175
- end
176
- end
177
-
178
- context "credit_card" do
179
- it "successfully confirms a credit_card create" do
180
- customer = Braintree::Customer.create(:first_name => "John", :last_name => "Doe").customer
181
-
182
- params = {
183
- :credit_card => {
184
- :cardholder_name => "John Doe"
185
- }
186
- }
187
- tr_data_params = {
188
- :credit_card => {
189
- :customer_id => customer.id,
190
- :number => Braintree::Test::CreditCardNumbers::Visa,
191
- :expiration_date => "10/10"
192
- }
193
- }
194
- tr_data = Braintree::TransparentRedirect.create_credit_card_data(
195
- {:redirect_url => "http://example.com"}.merge(tr_data_params)
196
- )
197
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params)
198
- result = Braintree::TransparentRedirect.confirm(query_string_response)
199
-
200
- result.success?.should == true
201
- credit_card = result.credit_card
202
- credit_card.cardholder_name.should == "John Doe"
203
- credit_card.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
204
- credit_card.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
205
- credit_card.expiration_date.should == "10/2010"
206
- end
207
-
208
- it "successfully confirms a credit_card update" do
209
- customer = Braintree::Customer.create(:first_name => "John", :last_name => "Doe").customer
210
- credit_card = Braintree::CreditCard.create(
211
- :customer_id => customer.id,
212
- :number => Braintree::Test::CreditCardNumbers::Visa,
213
- :expiration_date => "10/10"
214
- ).credit_card
215
-
216
- params = {
217
- :credit_card => {
218
- :cardholder_name => "John Doe"
219
- }
220
- }
221
- tr_data_params = {
222
- :payment_method_token => credit_card.token,
223
- :credit_card => {
224
- :number => Braintree::Test::CreditCardNumbers::MasterCard,
225
- :expiration_date => "11/11"
226
- }
227
- }
228
- tr_data = Braintree::TransparentRedirect.update_credit_card_data(
229
- {:redirect_url => "http://example.com"}.merge(tr_data_params)
230
- )
231
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params)
232
- result = Braintree::TransparentRedirect.confirm(query_string_response)
233
-
234
- result.success?.should == true
235
- credit_card = result.credit_card
236
- credit_card.cardholder_name.should == "John Doe"
237
- credit_card.bin.should == Braintree::Test::CreditCardNumbers::MasterCard[0, 6]
238
- credit_card.last_4.should == Braintree::Test::CreditCardNumbers::MasterCard[-4..-1]
239
- credit_card.expiration_date.should == "11/2011"
240
- end
241
-
242
- it "returns an error result where there are errors" do
243
- customer = Braintree::Customer.create(:first_name => "John", :last_name => "Doe").customer
244
-
245
- params = {
246
- :credit_card => {
247
- :cardholder_name => "John Doe"
248
- }
249
- }
250
- tr_data_params = {
251
- :credit_card => {
252
- :customer_id => customer.id,
253
- :number => Braintree::Test::CreditCardNumbers::Visa,
254
- :expiration_date => "123"
255
- }
256
- }
257
- tr_data = Braintree::TransparentRedirect.create_credit_card_data(
258
- {:redirect_url => "http://example.com"}.merge(tr_data_params)
259
- )
260
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params)
261
- result = Braintree::TransparentRedirect.confirm(query_string_response)
262
-
263
- result.success?.should == false
264
- result.errors.for(:credit_card).size.should > 0
265
- end
266
- end
267
- end
268
- end