Giter Site home page Giter Site logo

braintree / braintree_rails_example Goto Github PK

View Code? Open in Web Editor NEW
87.0 74.0 75.0 944 KB

An example Braintree integration for Ruby on Rails

License: MIT License

Ruby 39.06% JavaScript 0.92% CoffeeScript 0.19% CSS 0.62% HTML 58.82% Dockerfile 0.20% SCSS 0.16% Procfile 0.04%

braintree_rails_example's Introduction

Braintree Rails Example test

An example Braintree integration for Ruby on Rails.

Setup Instructions

  1. Install bundler:

    gem install bundler
  2. You may need to install postgresql (a production dependency) and mimemagic. On a mac using Homebrew, run these commands:

brew install shared-mime-info
brew install postgresql
  1. Bundle:

    bundle
  2. Copy the contents of example.env into a new file named .env and fill in your Braintree API credentials. Credentials can be found by navigating to Account > My User > View Authorizations in the Braintree Control Panel. Full instructions can be found on our support site.

  3. Start rails:

    rails server

Running Tests

Running Unit Tests

Unit tests do not make API calls to Braintree and do not require Braintree credentials. You can run this project's unit tests by calling rake (or rails -R spec) on the command line.

Running Integration Tests

Integration tests make API calls to Braintree and require that you set up your Braintree credentials. You can run this project's integration tests by adding your sandbox API credentials to .env and calling rake spec:integration (or rails spec:integration) on the command line.

Running All Tests

You can run both unit and integrations tests by calling rake spec (or rails spec) on the command line.

Testing Transactions

Sandbox transactions must be made with sample credit card numbers, and the response of a Braintree::Transaction.sale() call is dependent on the amount of the transaction.

Pro Tips

  • Run rails s -b 0.0.0.0 when launching Rails server to listen on all interfaces.

Help

Disclaimer

This code is provided as is and is only intended to be used for illustration purposes. This code is not production-ready and is not meant to be used in a production environment. This repository is to be used as a tool to help merchants learn how to integrate with Braintree. Any use of this repository or any of its code in a production environment is highly discouraged.

braintree_rails_example's People

Contributors

baash05 avatar braintreeps avatar crookedneighbor avatar danakatz avatar debrado avatar dependabot[bot] avatar dmillzilla avatar epreuve avatar evanhahn avatar hollabaq86 avatar jackellenberger avatar jferm avatar kexline4710 avatar lilaconlee avatar mtmarsh3 avatar omgrr avatar pblesi avatar phagoth avatar salanoid avatar sestevens avatar translatorzepp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

braintree_rails_example's Issues

Please update your ruby version and gems

Please update your gem

  • Environment:
  • Language, language version, and OS:

Issue description

The version of ruby in this example isn't supported on heroku anymore. :(

paypal error in payment process

General information

  • Environment: Sandbox
    ruby 2.4.1
    rails 5.1.4

Issue description

I set up your braintree example in rails 5.1.4 with ruby 2.4.2
The credit card payment word fine but the paypal checkout is stating something went wrong on our end.

I included the paypal sandbox credentials in my braintree Settings > Processing > Payment Methods > PayPal and linked the PayPal Sandbox

but it is not working.

braintree paypal error

What else can I do to test the paypal checkout?

Notice: Undefined index: payment_method_nonce in /var/www/html/braintree/public_html/checkout.php on line 7

When we run this example this error is generated

Notice: Undefined index: payment_method_nonce in /var/www/html/braintree/public_html/checkout.php on line 7

Fatal error: Uncaught exception 'Braintree\Exception\Configuration' with message 'Braintree\Configuration::merchantId needs to be set (or accessToken needs to be passed to Braintree\Gateway).' in /var/www/html/braintree/vendor/braintree/braintree_php/lib/Braintree/Configuration.php:177 Stack trace: #0 /var/www/html/braintree/vendor/braintree/braintree_php/lib/Braintree/TransactionGateway.php(30): Braintree\Configuration->assertHasAccessTokenOrKeys() #1 /var/www/html/braintree/vendor/braintree/braintree_php/lib/Braintree/Gateway.php(186): Braintree\TransactionGateway->__construct(Object(Braintree\Gateway)) #2 /var/www/html/braintree/vendor/braintree/braintree_php/lib/Braintree/Transaction.php(480): Braintree\Gateway->transaction() #3 /var/www/html/braintree/public_html/checkout.php(12): Braintree\Transaction::sale(Array) #4 {main} thrown in /var/www/html/braintree/vendor/braintree/braintree_php/lib/Braintree/Configuration.php on line 177

Building example app in heroku

General information

Issue description

During creating app I get this error:

  Bundle completed (25.87s)
   Cleaning up the bundler cache.

-----> Installing node-v16.13.1-linux-x64
-----> Detecting rake tasks
!
! Could not detect rake tasks
! ensure you can run $ bundle exec rake -P against your app
! and using the production group of your Gemfile.
! rake aborted!
! TypeError: wrong argument type false (expected Symbol)

Am i doing something wrong or app needs some update?

Unable to complete bundle install

General information

  • Environment: Sandbox
  • Language, language version, and OS: Rails 5 on Mac OSX Big Sur

Issue description

I just cloned the repo and did a bundle install. I got the error

Could not find MIME type database in the following locations: ["/usr/local/share/mime/packages/freedesktop.org.xml", "/opt/homebrew/share/mime/packages/freedesktop.org.xml",
"/opt/local/share/mime/packages/freedesktop.org.xml", "/usr/share/mime/packages/freedesktop.org.xml"]

for mimemagic, and gem installation stopped

404 error not found when creating transaction

I deployed this to heroku and I am working with the demo project in the braintree-android repo. I can get the client_token fine so I know the base URL I'm using is correct but when I get the nonce through the pop-up and try to make a transaction I get a 404 not found error. Any help is greatly appreciated

Error when i do bundle

Hi,

I'm trying to use this repository, I follow the instructions when i do bundle I get this error :

Fetching pg 0.21.0
Installing pg 0.21.0 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory: /Users/Test/.rvm/gems/ruby-2.3.1@braintree_rails_example/gems/pg-0.21.0/ext

/Users/Test/.rvm/rubies/ruby-2.3.1/bin/ruby -r ./siteconf20171228-90072-1w8swcq.rb extconf.rb
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
--with-pg-config=/path/to/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.

Provided configuration options:
--with-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/Users/Test/.rvm/rubies/ruby-2.3.1/bin/$(RUBY_BASE_NAME)
--with-pg
--without-pg
--enable-windows-cross
--disable-windows-cross
--with-pg-config
--without-pg-config
--with-pg_config
--without-pg_config
--with-pg-dir
--without-pg-dir
--with-pg-include
--without-pg-include=${pg-dir}/include
--with-pg-lib
--without-pg-lib=${pg-dir}/lib

To see why this extension failed to compile, please check the mkmf.log which can be found here:

/Users/Test/.rvm/gems/ruby-2.3.1@braintree_rails_example/extensions/x86_64-darwin-16/2.3.0/pg-0.21.0/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Users/Test/.rvm/gems/ruby-2.3.1@braintree_rails_example/gems/pg-0.21.0 for inspection.
Results logged to /Users/Test/.rvm/gems/ruby-2.3.1@braintree_rails_example/extensions/x86_64-darwin-16/2.3.0/pg-0.21.0/gem_make.out

An error occurred while installing pg (0.21.0), and Bundler cannot continue.
Make sure that gem install pg -v '0.21.0' succeeds before bundling.

In Gemfile:
pg

can you let me know what is my issue?

Thanks

Multi-tenancy support / dynamically set merchant id, public key, private key, etc?

I'm currently setting my Braintree merchant_id and public/private keys in a 'braintree.rb' file in config/initializers:

Braintree::Configuration.merchant_id = Rails.application.secrets.braintree_merchant_id Braintree::Configuration.public_key = Rails.application.secrets.braintree_public_key Braintree::Configuration.private_key = Rails.application.secrets.braintree_private_key

This works fine for a single-tenant application. For multi-tenancy, I'm storing this data in the database (with the private key encrypted), like a couple of other integrations my software uses. For example, for Mailgun, I'm setting the account specific info (API Key, etc) dynamically when sending mail.

Is there any way to dynamically set the Braintree configuration keys instead of setting it once/application wide/in an initializer?

Update Ruby to 2.3.1

Hi,

First, thumbs up for the good work!

Second, I just tested your example, and it worked with ruby 2.3.1 without any visible issues. Do you think we can update it within this example project?

Unable to deploy to Heroku

General information

  • Environment: Sandbox
  • Language, language version, and OS: ruby-2.7.4 on Heroku-20 stack

Issue description

Using my sandbox account, I tried and failed to deploy to Heroku. I tried both this repository and a forked repository. Both terminated with the following two errors:
! Push rejected, failed to compile Ruby app.
! Push failed

The full build log follows:

-----> Determining which buildpack to use for this app
-----> Ruby app detected
-----> Installing bundler 2.2.21
-----> Removing BUNDLED WITH version in the Gemfile.lock
-----> Compiling Ruby/Rails
-----> Using Ruby version: ruby-2.7.4
-----> Installing dependencies using bundler 2.2.21
      Running: BUNDLE_WITHOUT='development:test' BUNDLE_PATH=vendor/bundle BUNDLE_BIN=vendor/bundle/bin BUNDLE_DEPLOYMENT=1 bundle install -j4
      Fetching gem metadata from https://rubygems.org/
      Fetching gem metadata from https://rubygems.org/............
      Fetching rake 13.0.3
      Installing rake 13.0.3
      Fetching concurrent-ruby 1.1.8
      Fetching minitest 5.14.4
      Fetching thread_safe 0.3.6
      Fetching builder 3.2.4
      Installing thread_safe 0.3.6
      Installing builder 3.2.4
      Installing minitest 5.14.4
      Fetching erubi 1.10.0
      Installing concurrent-ruby 1.1.8
      Installing erubi 1.10.0
      Fetching mini_portile2 2.6.1
      Fetching racc 1.5.2
      Installing mini_portile2 2.6.1
      Fetching crass 1.0.6
      Installing racc 1.5.2 with native extensions
      Installing crass 1.0.6
      Fetching rack 2.2.3
      Fetching nio4r 2.5.7
      Installing rack 2.2.3
      Installing nio4r 2.5.7 with native extensions
      Fetching websocket-extensions 0.1.5
      Installing websocket-extensions 0.1.5
      Fetching mini_mime 1.0.3
      Fetching arel 9.0.0
      Installing mini_mime 1.0.3
      Installing arel 9.0.0
      Fetching msgpack 1.3.3
      Installing msgpack 1.3.3 with native extensions
      Using bundler 2.2.21
      Fetching coffee-script-source 1.12.2
      Installing coffee-script-source 1.12.2
      Fetching execjs 2.7.0
      Installing execjs 2.7.0
      Fetching method_source 1.0.0
      Installing method_source 1.0.0
      Fetching thor 1.1.0
      Installing thor 1.1.0
      Fetching dotenv 2.7.5
      Installing dotenv 2.7.5
      Fetching ffi 1.13.1
      Installing ffi 1.13.1 with native extensions
      Fetching pg 0.21.0
      Installing pg 0.21.0 with native extensions
      Fetching rails_serve_static_assets 0.0.5
      Installing rails_serve_static_assets 0.0.5
      Fetching rails_stdout_logging 0.0.5
      Installing rails_stdout_logging 0.0.5
      Fetching rb-fsevent 0.10.4
      Installing rb-fsevent 0.10.4
      Fetching tilt 2.0.10
      Installing tilt 2.0.10
      Fetching turbolinks-source 5.2.0
      Installing turbolinks-source 5.2.0
      Fetching braintree 2.102.0
      Installing braintree 2.102.0
      Fetching tzinfo 1.2.9
      Installing tzinfo 1.2.9
      Fetching i18n 1.8.9
      Installing i18n 1.8.9
      Fetching websocket-driver 0.7.3
      Installing websocket-driver 0.7.3 with native extensions
      Fetching rack-test 1.1.0
      Installing rack-test 1.1.0
      Fetching sprockets 3.7.2
      Installing sprockets 3.7.2
      Fetching mail 2.7.1
      Installing mail 2.7.1
      Fetching coffee-script 2.4.1
      Installing coffee-script 2.4.1
      Fetching uglifier 4.2.0
      Installing uglifier 4.2.0
      Fetching nokogiri 1.12.5 (x86_64-linux)
      Installing nokogiri 1.12.5 (x86_64-linux)
      Fetching rails_12factor 0.0.3
      Installing rails_12factor 0.0.3
      Fetching turbolinks 5.2.1
      Installing turbolinks 5.2.1
      Fetching activesupport 5.2.4.5
      Installing activesupport 5.2.4.5
      Fetching bootsnap 1.3.2
      Installing bootsnap 1.3.2 with native extensions
      Fetching loofah 2.9.0
      Installing loofah 2.9.0
      Fetching mimemagic 0.3.10
      Installing mimemagic 0.3.10 with native extensions
      Fetching rails-dom-testing 2.0.3
      Installing rails-dom-testing 2.0.3
      Fetching globalid 0.4.2
      Installing globalid 0.4.2
      Fetching activemodel 5.2.4.5
      Installing activemodel 5.2.4.5
      Fetching jbuilder 2.10.0
      Installing jbuilder 2.10.0
      Fetching rb-inotify 0.10.1
      Installing rb-inotify 0.10.1
      Fetching rails-html-sanitizer 1.3.0
      Installing rails-html-sanitizer 1.3.0
      Fetching activerecord 5.2.4.5
      Fetching activejob 5.2.4.5
      Installing activejob 5.2.4.5
      Installing activerecord 5.2.4.5
      Fetching sass-listen 4.0.0
      Installing sass-listen 4.0.0
      Fetching actionview 5.2.4.5
      Installing actionview 5.2.4.5
      Fetching sass 3.7.4
      Installing sass 3.7.4
      Fetching actionpack 5.2.4.5
      Fetching marcel 0.3.3
      Installing actionpack 5.2.4.5
      Installing marcel 0.3.3
      Fetching actioncable 5.2.4.5
      Fetching actionmailer 5.2.4.5
      Fetching activestorage 5.2.4.5
      Fetching railties 5.2.4.5
      Installing actionmailer 5.2.4.5
      Installing actioncable 5.2.4.5
      Installing activestorage 5.2.4.5
      Fetching sprockets-rails 3.2.2
      Installing railties 5.2.4.5
      Installing sprockets-rails 3.2.2
      Fetching coffee-rails 4.2.2
      Fetching jquery-rails 4.4.0
      Fetching rails 5.2.4.5
      Fetching sass-rails 5.1.0
      Installing sass-rails 5.1.0
      Installing coffee-rails 4.2.2
      Installing rails 5.2.4.5
      Installing jquery-rails 4.4.0
      Bundle complete! 19 Gemfile dependencies, 66 gems now installed.
      Gems in the groups 'development' and 'test' were not installed.
      Bundled gems are installed into `./vendor/bundle`
      Post-install message from sass:
      
      Ruby Sass has reached end-of-life and should no longer be used.
      
      * If you use Sass as a command-line tool, we recommend using Dart Sass, the new
        primary implementation: https://sass-lang.com/install
      
      * If you use Sass as a plug-in for a Ruby web framework, we recommend using the
        sassc gem: https://github.com/sass/sassc-ruby#readme
      
      * For more details, please refer to the Sass blog:
        https://sass-lang.com/blog/posts/7828841
      
      Bundle completed (23.90s)
      Cleaning up the bundler cache.
-----> Installing node-v12.16.2-linux-x64
-----> Detecting rake tasks
!
!     Could not detect rake tasks
!     ensure you can run `$ bundle exec rake -P` against your app
!     and using the production group of your Gemfile.
!     /tmp/build_3908a41b/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require': no implicit conversion of String into Integer (TypeError)
!     from /tmp/build_3908a41b/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
!     from /tmp/build_3908a41b/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register'
!     from /tmp/build_3908a41b/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
!     from /tmp/build_3908a41b/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
!     from /tmp/build_3908a41b/vendor/bundle/ruby/2.7.0/gems/activesupport-5.2.4.5/lib/active_support/dependencies.rb:291:in `block in require'
!     from /tmp/build_3908a41b/vendor/bundle/ruby/2.7.0/gems/activesupport-5.2.4.5/lib/active_support/dependencies.rb:257:in `load_dependency'
!     from /tmp/build_3908a41b/vendor/bundle/ruby/2.7.0/gems/activesupport-5.2.4.5/lib/active_support/dependencies.rb:291:in `require'
!     from /tmp/build_3908a41b/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.3.2/lib/bootsnap/compile_cache/iseq.rb:1:in `<top (required)>'
!     from /tmp/build_3908a41b/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
!     from /tmp/build_3908a41b/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
!     from /tmp/build_3908a41b/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register'
!     from /tmp/build_3908a41b/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
!     from /tmp/build_3908a41b/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
!     from /tmp/build_3908a41b/vendor/bundle/ruby/2.7.0/gems/activesupport-5.2.4.5/lib/active_support/dependencies.rb:291:in `block in require'
!     from /tmp/build_3908a41b/vendor/bundle/ruby/2.7.0/gems/activesupport-5.2.4.5/lib/active_support/dependencies.rb:257:in `load_dependency'
!     from /tmp/build_3908a41b/vendor/bundle/ruby/2.7.0/gems/activesupport-5.2.4.5/lib/active_support/dependencies.rb:291:in `require'
!     from /tmp/build_3908a41b/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:44:in `require_relative'
!     from /tmp/build_3908a41b/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.3.2/lib/bootsnap/compile_cache.rb:5:in `setup'
!     from /tmp/build_3908a41b/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.3.2/lib/bootsnap.rb:30:in `setup'
!     from /tmp/build_3908a41b/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.3.2/lib/bootsnap/setup.rb:33:in `<top (required)>'
!     from /tmp/build_3908a41b/config/boot.rb:4:in `require'
!     from /tmp/build_3908a41b/config/boot.rb:4:in `<top (required)>'
!     from /tmp/build_3908a41b/bin/rake:2:in `require_relative'
!     from /tmp/build_3908a41b/bin/rake:2:in `<main>'
!
/tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/helpers/rake_runner.rb:106:in `load_rake_tasks!': Could not detect rake tasks (LanguagePack::Helpers::RakeRunner::CannotLoadRakefileError)
ensure you can run `$ bundle exec rake -P` against your app
and using the production group of your Gemfile.
/tmp/build_3908a41b/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require': no implicit conversion of String into Integer (TypeError)
   from /tmp/build_3908a41b/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
   from /tmp/build_3908a41b/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register'
   from /tmp/build_3908a41b/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
   from /tmp/build_3908a41b/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
   from /tmp/build_3908a41b/vendor/bundle/ruby/2.7.0/gems/activesupport-5.2.4.5/lib/active_support/dependencies.rb:291:in `block in require'
   from /tmp/build_3908a41b/vendor/bundle/ruby/2.7.0/gems/activesupport-5.2.4.5/lib/active_support/dependencies.rb:257:in `load_dependency'
   from /tmp/build_3908a41b/vendor/bundle/ruby/2.7.0/gems/activesupport-5.2.4.5/lib/active_support/dependencies.rb:291:in `require'
   from /tmp/build_3908a41b/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.3.2/lib/bootsnap/compile_cache/iseq.rb:1:in `<top (required)>'
   from /tmp/build_3908a41b/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
   from /tmp/build_3908a41b/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
   from /tmp/build_3908a41b/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register'
   from /tmp/build_3908a41b/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
   from /tmp/build_3908a41b/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
   from /tmp/build_3908a41b/vendor/bundle/ruby/2.7.0/gems/activesupport-5.2.4.5/lib/active_support/dependencies.rb:291:in `block in require'
   from /tmp/build_3908a41b/vendor/bundle/ruby/2.7.0/gems/activesupport-5.2.4.5/lib/active_support/dependencies.rb:257:in `load_dependency'
   from /tmp/build_3908a41b/vendor/bundle/ruby/2.7.0/gems/activesupport-5.2.4.5/lib/active_support/dependencies.rb:291:in `require'
   from /tmp/build_3908a41b/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:44:in `require_relative'
   from /tmp/build_3908a41b/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.3.2/lib/bootsnap/compile_cache.rb:5:in `setup'
   from /tmp/build_3908a41b/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.3.2/lib/bootsnap.rb:30:in `setup'
   from /tmp/build_3908a41b/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.3.2/lib/bootsnap/setup.rb:33:in `<top (required)>'
   from /tmp/build_3908a41b/config/boot.rb:4:in `require'
   from /tmp/build_3908a41b/config/boot.rb:4:in `<top (required)>'
   from /tmp/build_3908a41b/bin/rake:2:in `require_relative'
   from /tmp/build_3908a41b/bin/rake:2:in `<main>'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/ruby.rb:1009:in `rake'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/rails4.rb:78:in `block (2 levels) in run_assets_precompile_rake_task'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/base.rb:190:in `log'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/rails4.rb:72:in `block in run_assets_precompile_rake_task'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:18:in `block (2 levels) in instrument'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:40:in `yield_with_block_depth'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:17:in `block in instrument'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/vendor/ruby/heroku-20/lib/ruby/2.7.0/benchmark.rb:308:in `realtime'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:16:in `instrument'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/base.rb:50:in `instrument'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/base.rb:46:in `instrument'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/rails4.rb:71:in `run_assets_precompile_rake_task'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/ruby.rb:112:in `block (2 levels) in compile'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/ruby.rb:1030:in `allow_git'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/ruby.rb:105:in `block in compile'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:18:in `block (2 levels) in instrument'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:40:in `yield_with_block_depth'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:17:in `block in instrument'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/vendor/ruby/heroku-20/lib/ruby/2.7.0/benchmark.rb:308:in `realtime'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:16:in `instrument'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/base.rb:50:in `instrument'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/base.rb:46:in `instrument'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/ruby.rb:91:in `compile'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/rails2.rb:62:in `block in compile'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:18:in `block (2 levels) in instrument'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:40:in `yield_with_block_depth'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:17:in `block in instrument'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/vendor/ruby/heroku-20/lib/ruby/2.7.0/benchmark.rb:308:in `realtime'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:16:in `instrument'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/base.rb:50:in `instrument'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/base.rb:46:in `instrument'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/rails2.rb:60:in `compile'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/rails3.rb:42:in `block in compile'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:18:in `block (2 levels) in instrument'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:40:in `yield_with_block_depth'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:17:in `block in instrument'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/vendor/ruby/heroku-20/lib/ruby/2.7.0/benchmark.rb:308:in `realtime'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:16:in `instrument'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/base.rb:50:in `instrument'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/base.rb:46:in `instrument'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/rails3.rb:41:in `compile'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/rails4.rb:35:in `block in compile'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:18:in `block (2 levels) in instrument'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:40:in `yield_with_block_depth'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:17:in `block in instrument'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/vendor/ruby/heroku-20/lib/ruby/2.7.0/benchmark.rb:308:in `realtime'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:16:in `instrument'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/base.rb:50:in `instrument'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/base.rb:46:in `instrument'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/rails4.rb:34:in `compile'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/bin/support/ruby_compile:20:in `block (2 levels) in <main>'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/base.rb:190:in `log'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/bin/support/ruby_compile:19:in `block in <main>'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:35:in `block in trace'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:18:in `block (2 levels) in instrument'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:40:in `yield_with_block_depth'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:17:in `block in instrument'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/vendor/ruby/heroku-20/lib/ruby/2.7.0/benchmark.rb:308:in `realtime'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:16:in `instrument'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:35:in `trace'
   from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/bin/support/ruby_compile:15:in `<main>'
!     Push rejected, failed to compile Ruby app.
!     Push failed```

Error handling code should be improved

This example doesn't do a great job at handling all situations where an error would occur.

This is the code that I ended up creating myself: https://gist.github.com/gregblass/33c92a58187450c82f1eba4e144c680f

I get the whole notion of 'We leave it up to the user to implement the details of error handling.' And that partially makes sense - you may want to show the error code, or not - or write your own messages for certain responses.

However, the issue is that figuring out all the different ways an error could occur takes a decent amount of time to figure out. The documentation is good, but you've still got to read through it all and put together all the different ways a payment could fail.

The SUCCESS_STATUS stuff would have been completely lost if not for this example. But then this example repo doesn't handle any verification failures. So I think this helps to unify things.

Braintree devs - feel free to take this and implement something similar into the example. Something like this would have really helped me and saved me a lot of time.

Problem integrating with IOS client.

Hi, I'm trying to implement this server with a iOS client following the braintree docs

For some reason I don't succeed and I'm not sure why.

is there anything else I need to implement in the clone I made from this repository beside .env implementation ?

This is my iOS contoller :

import UIKit
import Braintree
import BraintreeDropIn

class ViewController: UIViewController {

var paymentMethod : BTPaymentMethodNonce?

override func viewDidLoad() {
    super.viewDidLoad()
    fetchClientToken()
    // Do any additional setup after loading the view, typically from a nib.
}


func fetchClientToken() {
    // TODO: Switch this URL to your own authenticated API
    let clientTokenURL = NSURL(string: "http://localhost:3000/client_token")!
    let clientTokenRequest = NSMutableURLRequest(url: clientTokenURL as URL)
    clientTokenRequest.setValue("text/plain", forHTTPHeaderField: "Accept")
    
    URLSession.shared.dataTask(with: clientTokenRequest as URLRequest) { (data, response, error) -> Void in
        if let err = error {
            print(err.localizedDescription)
            return
        }
        let clientToken = String(data: data!, encoding: String.Encoding.utf8)
       
        self.showDropIn(clientTokenOrTokenizationKey: "sandbox_t45fvztb_245nc5pjv2tyt3n8")
        // As an example, you may wish to present Drop-in at this point.
        // Continue to the next section to learn more...
        }.resume()
}

func showDropIn(clientTokenOrTokenizationKey: String) {
    let request =  BTDropInRequest()
    let dropIn = BTDropInController(authorization: clientTokenOrTokenizationKey, request: request)
    { (controller, result, error) in
        if (error != nil) {
            print("ERROR")
        } else if (result?.isCancelled == true) {
            print("CANCELLED")
        } else if let result = result {
            // Use the BTDropInResult properties to update your UI
            // result.paymentOptionType
            // result.paymentMethod
            // result.paymentIcon
            // result.paymentDescription
        }
        controller.dismiss(animated: true, completion: nil)
    }
    self.present(dropIn!, animated: true, completion: nil)
}

func postNonceToServer(paymentMethodNonce: String) {
    // Update URL with your server
    let paymentURL = URL(string: "http://localhost:3000/client_token/payment-methods")!
    var request = URLRequest(url: paymentURL)
    request.httpBody = "payment_method_nonce=\(paymentMethodNonce)".data(using: String.Encoding.utf8)
    request.httpMethod = "POST"
    
    URLSession.shared.dataTask(with: request) { (data, response, error) -> Void in
        // TODO: Handle success or failure
        if (error != nil) {
            print(error?.localizedDescription)

        }
        }.resume()
    
}

@IBAction func pay(_ sender: UIButton) {
    postNonceToServer(paymentMethodNonce: "fake-valid-nonce")
}

}

This is my server log :

Started GET "/client_token" for ::1 at 2017-12-29 15:30:49 +0200

ActionController::RoutingError (No route matches [GET] "/client_token"):
actionpack (4.2.10) lib/action_dispatch/middleware/debug_exceptions.rb:21:in call' web-console (2.3.0) lib/web_console/middleware.rb:28:in block in call'
web-console (2.3.0) lib/web_console/middleware.rb:18:in catch' web-console (2.3.0) lib/web_console/middleware.rb:18:in call'
actionpack (4.2.10) lib/action_dispatch/middleware/show_exceptions.rb:30:in call' railties (4.2.10) lib/rails/rack/logger.rb:38:in call_app'
railties (4.2.10) lib/rails/rack/logger.rb:20:in block in call' activesupport (4.2.10) lib/active_support/tagged_logging.rb:68:in block in tagged'
activesupport (4.2.10) lib/active_support/tagged_logging.rb:26:in tagged' activesupport (4.2.10) lib/active_support/tagged_logging.rb:68:in tagged'
railties (4.2.10) lib/rails/rack/logger.rb:20:in call' actionpack (4.2.10) lib/action_dispatch/middleware/request_id.rb:21:in call'
rack (1.6.8) lib/rack/methodoverride.rb:22:in call' rack (1.6.8) lib/rack/runtime.rb:18:in call'
activesupport (4.2.10) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in call' rack (1.6.8) lib/rack/lock.rb:17:in call'
actionpack (4.2.10) lib/action_dispatch/middleware/static.rb:120:in call' rack (1.6.8) lib/rack/sendfile.rb:113:in call'
railties (4.2.10) lib/rails/engine.rb:518:in call' railties (4.2.10) lib/rails/application.rb:165:in call'
rack (1.6.8) lib/rack/lock.rb:17:in call' rack (1.6.8) lib/rack/content_length.rb:15:in call'
rack (1.6.8) lib/rack/handler/webrick.rb:88:in service' /Users/Test/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/webrick/httpserver.rb:140:in service'
/Users/Test/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/webrick/httpserver.rb:96:in run' /Users/Test/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/webrick/server.rb:296:in block in start_thread'

Rendered /Users/Test/.rvm/gems/ruby-2.3.1@braintree_rails_example/gems/actionpack-4.2.10/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (2.8ms)
Rendered /Users/Test/.rvm/gems/ruby-2.3.1@braintree_rails_example/gems/actionpack-4.2.10/lib/action_dispatch/middleware/templates/routes/_route.html.erb (3.0ms)
Rendered /Users/Test/.rvm/gems/ruby-2.3.1@braintree_rails_example/gems/actionpack-4.2.10/lib/action_dispatch/middleware/templates/routes/_table.html.erb (17.1ms)
Rendered /Users/Test/.rvm/gems/ruby-2.3.1@braintree_rails_example/gems/actionpack-4.2.10/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.9ms)
Rendered /Users/Test/.rvm/gems/ruby-2.3.1@braintree_rails_example/gems/actionpack-4.2.10/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb within rescues/layout (158.3ms)
Rendered /Users/Test/.rvm/gems/ruby-2.3.1@braintree_rails_example/gems/web-console-2.3.0/lib/web_console/templates/_markup.html.erb (0.5ms)
Rendered /Users/Test/.rvm/gems/ruby-2.3.1@braintree_rails_example/gems/web-console-2.3.0/lib/web_console/templates/_inner_console_markup.html.erb within layouts/inlined_string (0.5ms)
Rendered /Users/Test/.rvm/gems/ruby-2.3.1@braintree_rails_example/gems/web-console-2.3.0/lib/web_console/templates/_prompt_box_markup.html.erb within layouts/inlined_string (1.1ms)
Rendered /Users/Test/.rvm/gems/ruby-2.3.1@braintree_rails_example/gems/web-console-2.3.0/lib/web_console/templates/style.css.erb within layouts/inlined_string (0.6ms)
Rendered /Users/Test/.rvm/gems/ruby-2.3.1@braintree_rails_example/gems/web-console-2.3.0/lib/web_console/templates/console.js.erb within layouts/javascript (102.8ms)
Rendered /Users/Test/.rvm/gems/ruby-2.3.1@braintree_rails_example/gems/web-console-2.3.0/lib/web_console/templates/main.js.erb within layouts/javascript (0.4ms)
Rendered /Users/Test/.rvm/gems/ruby-2.3.1@braintree_rails_example/gems/web-console-2.3.0/lib/web_console/templates/error_page.js.erb within layouts/javascript (0.5ms)
Rendered /Users/Test/.rvm/gems/ruby-2.3.1@braintree_rails_example/gems/web-console-2.3.0/lib/web_console/templates/index.html.erb (261.3ms)

Thanks,
Hadar

Using example produces race condition with loading script

Copy / pasted from this example into our app. Get a race condition where the braintree script is not loaded before it is called. Here's the code from this example repo that I'm suspicious of:

<script src="https://js.braintreegateway.com/web/dropin/1.9.4/js/dropin.min.js"></script>
<script>
  var form = document.querySelector('#payment-form');
  var client_token = "<%= @client_token %>";
  braintree.dropin.create({

image

Seems like a race condition that would always exist in this example repo... ?

Broken on Safari 11.0.1

General information

  • Environment: sandbox
  • Language, language version, and OS: Ruby on Rails, macOS 10.13.1, safari 11.0.1

Issue description

TLDR;
Root issue: Drop In UI does not load in Safari but does in Chrome

Long Version:
Was having issues with the Drop In UI in my rails app not loading (populating the bt-dropin div), cloned and started up your example (this repo) and was having the same issue.

Thought maybe it was a browser issue, sure enough works exactly as expected in Chrome, both for the example and my app.

Screen shot of Safari

image

Screenshot of Chrome

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.