Class: Braintree::TransparentRedirectGateway
- Inherits:
-
Object
- Object
- Braintree::TransparentRedirectGateway
- Defined in:
- lib/braintree/transparent_redirect_gateway.rb
Overview
:nodoc
Constant Summary
- TransparentRedirectKeys =
:nodoc:
[:redirect_url]
- CreateCustomerSignature =
:nodoc:
TransparentRedirectKeys + [{:customer => CustomerGateway._create_signature}]
- UpdateCustomerSignature =
:nodoc:
TransparentRedirectKeys + [:customer_id, {:customer => CustomerGateway._update_signature}]
- TransactionSignature =
:nodoc:
TransparentRedirectKeys + [{:transaction => TransactionGateway._create_signature}]
- CreateCreditCardSignature =
:nodoc:
TransparentRedirectKeys + [{:credit_card => CreditCardGateway._create_signature}]
- UpdateCreditCardSignature =
:nodoc:
TransparentRedirectKeys + [:payment_method_token, {:credit_card => CreditCardGateway._update_signature}]
Instance Method Summary (collapse)
-
- (Object) _data(params)
:nodoc:.
-
- (Object) _hash(string)
:nodoc:.
- - (Object) confirm(query_string)
- - (Object) create_credit_card_data(params)
- - (Object) create_customer_data(params)
-
- (TransparentRedirectGateway) initialize(gateway)
constructor
A new instance of TransparentRedirectGateway.
-
- (Object) parse_and_validate_query_string(query_string)
:nodoc:.
- - (Object) transaction_data(params)
- - (Object) update_credit_card_data(params)
- - (Object) update_customer_data(params)
- - (Object) url
Constructor Details
- (TransparentRedirectGateway) initialize(gateway)
A new instance of TransparentRedirectGateway
10 11 12 13 |
# File 'lib/braintree/transparent_redirect_gateway.rb', line 10 def initialize(gateway) @gateway = gateway @config = gateway.config end |
Instance Method Details
- (Object) _data(params)
:nodoc:
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/braintree/transparent_redirect_gateway.rb', line 89 def _data(params) # :nodoc: raise ArgumentError, "expected params to contain :redirect_url" unless params[:redirect_url] tr_data_segment = Util.hash_to_query_string(params.merge( :api_version => @config.api_version, :time => Time.now.utc.strftime("%Y%m%d%H%M%S"), :public_key => @config.public_key )) tr_data_hash = _hash(tr_data_segment) "#{tr_data_hash}|#{tr_data_segment}" end |
- (Object) _hash(string)
:nodoc:
100 101 102 |
# File 'lib/braintree/transparent_redirect_gateway.rb', line 100 def _hash(string) # :nodoc: ::Braintree::Digest.hexdigest(@config.private_key, string) end |
- (Object) confirm(query_string)
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/braintree/transparent_redirect_gateway.rb', line 15 def confirm(query_string) params = @gateway.transparent_redirect.parse_and_validate_query_string query_string confirmation_gateway = { TransparentRedirect::Kind::CreateCustomer => :customer, TransparentRedirect::Kind::UpdateCustomer => :customer, TransparentRedirect::Kind::CreatePaymentMethod => :credit_card, TransparentRedirect::Kind::UpdatePaymentMethod => :credit_card, TransparentRedirect::Kind::CreateTransaction => :transaction }[params[:kind]] @gateway.send(confirmation_gateway)._do_create("/transparent_redirect_requests/#{params[:id]}/confirm") end |
- (Object) create_credit_card_data(params)
28 29 30 31 32 |
# File 'lib/braintree/transparent_redirect_gateway.rb', line 28 def create_credit_card_data(params) Util.verify_keys(CreateCreditCardSignature, params) params[:kind] = TransparentRedirect::Kind::CreatePaymentMethod _data(params) end |
- (Object) create_customer_data(params)
34 35 36 37 38 |
# File 'lib/braintree/transparent_redirect_gateway.rb', line 34 def create_customer_data(params) Util.verify_keys(CreateCustomerSignature, params) params[:kind] = TransparentRedirect::Kind::CreateCustomer _data(params) end |
- (Object) parse_and_validate_query_string(query_string)
:nodoc:
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/braintree/transparent_redirect_gateway.rb', line 40 def parse_and_validate_query_string(query_string) # :nodoc: params = Util.symbolize_keys(Util.parse_query_string(query_string)) query_string_without_hash = query_string[/(.*)&hash=.*/, 1] if params[:http_status] == nil raise UnexpectedError, "expected query string to have an http_status param" elsif params[:http_status] != '200' Util.raise_exception_for_status_code(params[:http_status], params[:bt_message]) end if _hash(query_string_without_hash) == params[:hash] params else raise ForgedQueryString end end |
- (Object) transaction_data(params)
57 58 59 60 61 62 63 64 65 |
# File 'lib/braintree/transparent_redirect_gateway.rb', line 57 def transaction_data(params) Util.verify_keys(TransactionSignature, params) params[:kind] = TransparentRedirect::Kind::CreateTransaction transaction_type = params[:transaction] && params[:transaction][:type] unless %w[sale credit].include?(transaction_type) raise ArgumentError, "expected transaction[type] of sale or credit, was: #{transaction_type.inspect}" end _data(params) end |
- (Object) update_credit_card_data(params)
67 68 69 70 71 72 73 74 |
# File 'lib/braintree/transparent_redirect_gateway.rb', line 67 def update_credit_card_data(params) Util.verify_keys(UpdateCreditCardSignature, params) unless params[:payment_method_token] raise ArgumentError, "expected params to contain :payment_method_token of payment method to update" end params[:kind] = TransparentRedirect::Kind::UpdatePaymentMethod _data(params) end |
- (Object) update_customer_data(params)
76 77 78 79 80 81 82 83 |
# File 'lib/braintree/transparent_redirect_gateway.rb', line 76 def update_customer_data(params) Util.verify_keys(UpdateCustomerSignature, params) unless params[:customer_id] raise ArgumentError, "expected params to contain :customer_id of customer to update" end params[:kind] = TransparentRedirect::Kind::UpdateCustomer _data(params) end |
- (Object) url
85 86 87 |
# File 'lib/braintree/transparent_redirect_gateway.rb', line 85 def url "#{@config.base_merchant_url}/transparent_redirect_requests" end |