Class: ActiveMerchant::Billing::TokenNonce
- Inherits:
-
Object
- Object
- ActiveMerchant::Billing::TokenNonce
- Includes:
- PostsData
- Defined in:
- lib/active_merchant/billing/gateways/braintree/token_nonce.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#braintree_gateway ⇒ Object
readonly
This class emulates the behavior of the front-end js library to create token nonce for a bank account base on the docs: developer.paypal.com/braintree/docs/guides/ach/client-side.
-
#options ⇒ Object
readonly
This class emulates the behavior of the front-end js library to create token nonce for a bank account base on the docs: developer.paypal.com/braintree/docs/guides/ach/client-side.
Instance Method Summary collapse
- #client_token(options = {}) ⇒ Object
- #create_token_nonce_for_payment_method(payment_method, options = {}) ⇒ Object
-
#initialize(gateway, options = {}) ⇒ TokenNonce
constructor
A new instance of TokenNonce.
- #url ⇒ Object
Methods included from PostsData
included, #raw_ssl_request, #ssl_get, #ssl_post, #ssl_request
Constructor Details
#initialize(gateway, options = {}) ⇒ TokenNonce
Returns a new instance of TokenNonce.
11 12 13 14 |
# File 'lib/active_merchant/billing/gateways/braintree/token_nonce.rb', line 11 def initialize(gateway, = {}) @braintree_gateway = gateway @options = end |
Instance Attribute Details
#braintree_gateway ⇒ Object (readonly)
This class emulates the behavior of the front-end js library to create token nonce for a bank account base on the docs: developer.paypal.com/braintree/docs/guides/ach/client-side
9 10 11 |
# File 'lib/active_merchant/billing/gateways/braintree/token_nonce.rb', line 9 def braintree_gateway @braintree_gateway end |
#options ⇒ Object (readonly)
This class emulates the behavior of the front-end js library to create token nonce for a bank account base on the docs: developer.paypal.com/braintree/docs/guides/ach/client-side
9 10 11 |
# File 'lib/active_merchant/billing/gateways/braintree/token_nonce.rb', line 9 def @options end |
Instance Method Details
#client_token(options = {}) ⇒ Object
37 38 39 40 |
# File 'lib/active_merchant/billing/gateways/braintree/token_nonce.rb', line 37 def client_token( = {}) base64_token = @braintree_gateway.client_token.generate({ merchant_account_id: [:merchant_account_id] || @options[:merchant_account_id] }.compact) JSON.parse(Base64.decode64(base64_token)) end |
#create_token_nonce_for_payment_method(payment_method, options = {}) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/active_merchant/billing/gateways/braintree/token_nonce.rb', line 21 def create_token_nonce_for_payment_method(payment_method, = {}) headers = { 'Accept' => 'application/json', 'Authorization' => "Bearer #{client_token()['authorizationFingerprint']}", 'Content-Type' => 'application/json', 'Braintree-Version' => '2018-05-10' } resp = ssl_post(url, build_nonce_request(payment_method), headers) json_response = JSON.parse(resp) = json_response['errors'].map { |err| err['message'] }.join("\n") if json_response['errors'].present? token = token_from(payment_method, json_response) return token, end |
#url ⇒ Object
16 17 18 19 |
# File 'lib/active_merchant/billing/gateways/braintree/token_nonce.rb', line 16 def url sandbox = @braintree_gateway.config.environment == :sandbox "https://payments#{'.sandbox' if sandbox}.braintree-api.com/graphql" end |