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 ⇒ Object
- #create_token_nonce_for_payment_method(payment_method) ⇒ 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 ⇒ 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 JSON.parse(Base64.decode64(base64_token))['authorizationFingerprint'] end |
#create_token_nonce_for_payment_method(payment_method) ⇒ 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}", '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 = json_response.dig('data', 'tokenizeUsBankAccount', 'paymentMethod', 'id') 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 |