I have fresh solidus installation and added `solid...
# support
s
I have fresh solidus installation and added
solidus_paypal_braintree
gem. I followed instructions from their github: https://github.com/solidusio/solidus_paypal_braintree and it seems to be incomplete. I can’t access any of the routes generated by gem (e.g.
/solidus_paypal_braintree
) and Braintree nav item hasn’t been added to admin dashboard. My routes file have this line but it doesn’t seem to be working
mount SolidusPaypalBraintree::Engine, at: '/solidus_paypal_braintree'
r
Hey @Sebastian 👋 What Solidus and Rails version are you using?
s
gem "solidus", "~> 3.1"
gem 'rails', '~> 6.1.6', '>= 6.1.6.1'
👍 1
r
does
bundle exec rails routes | grep 'solidus_paypal_braintree'
give any results?
s
message has been deleted
👍 1
r
That looks good, so routes should be working, for example:
localhost:3000/solidus_paypal_braintree/configurations/list
But you might have a problem with the views on that route, seeing as Braintree menu item is not appearing 👀
s
Oh. So
<http://localhost:3001/solidus_paypal_braintree/configurations/list>
actually worked. LOL, I tried it like 50 times yesterday. Thanks! Now, I have another problem tho. The docs is saying this: 1. Visit
/admin/payment_methods/new
2. Set
provider
to SolidusPaypalBraintree::Gateway 3. Click “Save” 4. Choose
braintree_credentials
from the
Preference Source
select 5. Click
Update
to save But neither
SolidusPaypalBraintree::Gateway
nor
braintree_credentials
is not there when creating a new payment method.
👍 1
👀 1
r
I am sorry, it looks like the Readme is a little outdated and confusing. When you go to create a payment method in admin, do you see
Braintree
for the
type
?
s
Yes. However in
Preference Source
I can only choose
(custom)
r
I understand. In order for
braintree_credentials
to appear in admin for the
preference_source
of the payment method, this would need to be added to
config/initializers/spree.rb
:
Copy code
# config/initializers/spree.rb
Spree.config do |config|
  config.static_model_preferences.add(
    SolidusPaypalBraintree::Gateway,
    'braintree_credentials', {
      environment: Rails.env.production? ? 'production' : 'sandbox',
      merchant_id: ENV['BRAINTREE_MERCHANT_ID'],
      public_key: ENV['BRAINTREE_PUBLIC_KEY'],
      private_key: ENV['BRAINTREE_PRIVATE_KEY'],
      paypal_flow: 'vault', # 'checkout' is accepted too
      use_data_collector: true # Fingerprint the user's browser when using Paypal
    }
  )
end
What you’re seeing here is Solidus’ static preferences, where preferences are created on load, and they have a key which refers to them, in this case
braintree_credentials
. So it wasn’t appearing as a preference source as it didn’t exist yet. The alternative is to skip this static preference code, and not choose a preference source in admin (
(custom)
). Then you can type/control the credentials/preferences from admin (they get saved on the DB). I have noticed some confusion on this area, so I will make a PR to update it this week 👍
s
It throws an error if I do
Spree::Config.config
`solidus_fresh_test_1/config/initializers/spree.rb77in `<main>': undefined method
config' for #<Spree::AppConfiguration:0x00007f996a60b160> (NoMethodError)
but works when I do
Spree.config
As in I can start the server but
braintree_credentials
is still not appearing on the list
👀 1
r
Ahh, you’re right,
_Spree_.config do |config|
is correct. Thanks 👍 I’ll update that too
s
OMG it’s actually so confusing. Seems like
Braintree
payment method has been automatically added by the gem and it uses
braintree_credentials
. But it’s not appearing if I want to create a new one. That’s fine then
r
I think you may have to save the payment method before being able to see all its preference_sources
s
Now, another thing 😂 On
/checkout/payment
Braintree appears as payment method but it’s not rendering anything to do with paypal. It’s just empty. Console gives me this and when I go to
<http://localhost:3001/solidus_paypal_braintree/client_token>
it actually is saying
No route matches [GET]…
r
This is probably because the Braintree credentials have not been set correctly. 1. Via admin if you are using no preference_source/ custom preferences 2. Via ENV variables if you used static preferences and the initializer snippet from above (e.g.
….ENV['BRAINTREE_MERCHANT_ID']
)
s
My
.env
file. Obviously cropped to hide the credentials
👍 1
r
It’s an internal server error with the app’s endpoint, should be some helpful information there
s
Untitled.txt
That’t the request response. Actually it seems like it’s not recognising the credentials for some reason
I could also give a go setting credentials in admin panel but not sure how to do it. I don’t care how it’s done. I just need it working. That’s the reason I’ve set up this fresh app as I wanted to check if the paypal is working on a fresh installation.
r
1. Does
SolidusPaypalBraintree::Gateway.first.preferences
return the credentials you expect? 2. And are they exactly the same as you see in the Braintree sandbox panel?
s
All of them are
nil
even if I directly put credentials into
spree.rb
instead of reading from ENV file
r
SolidusPaypalBraintree::Gateway.first.update(preference_source: 'braintree_credentials')
But
SolidusPaypalBraintree::Gateway.count
is only
1
right?
s
Yeah, it’s 1. So
SolidusPaypalBraintree::Gateway.first
returns a result where
preference_source
is set to
braintree_credentials
but
SolidusPaypalBraintree::Gateway.first.preferences
is an empty object really
I guess I’ll update it through console manually and will see then.
r
If you hardcode the credentials in the initialiser and reboot the server, you should be good. If this works, then the ENV loading was at fault. If the credentials start appearing on the payment method, but the client token still fails, then there’s something wrong with the keys/the Braintree sandbox setup.
If this is too much, I would just recommend changing the payment method’s
preference_source
to
(custom)
in admin, save it, change the credentials then save it again
s
I tried hardcoding the values here instead of
ENV[…]
but it didn’t work. Will now try directly through the console to DB
That will just sound stupid, but do you know how I can update individual properties inside of
SolidusPaypalBraintree::Gateway.first.preferences
? I’m a front end dev just fighting with Rails unfortunately
r
Easiest way via admin. Otherwise, for example
SolidusPaypalBraintree::Gateway.first.update(preferred_merchant_id: 'new_value'
I recommend checking out: https://guides.solidus.io/developers/preferences/add-model-preferences
w
Sometimes, I have found that you can only see custom sources when updating a custom source, but it doesn’t appear when creating it. So you might need to create it with
(custom)
as source, and then edit it.
r
Thanks @waiting_for_dev! I was looking for documentation about static prefs 😅
👍 1
s
Thank you for your help guys. Managed to get it working in the end. However still didn’t resolve my actual problem which I hoped a fresh installation would resolve. Basically when final
checkout/payment
page loads I get the red error & then when I click on paypal button it shows further 4 warnings about credentials not matching but credentials are definitely correct. This is the exact same thing that happens with the actual project I’m working on. I even created a new Paypal developer account with new credentials and still the same thing is happening.
Literally no idea where it’s taking the
merchant-id=DV33…
or
merchant-id=<mailto:payee@merchant.com|payee@merchant.com>
from as my credentials are completely different.
k
I have the same issue @Sebastian
Been trying to fix for a couple of weeks
🥲
r
I made a new app and I get these 4 JS warnings as well. However, it does not block me from checking out. Are you both able to checkout?
k
Weird @Ryan Woods! I cannot get past checkout unfortunately
I sign it with PayPal, choose payment method, then continue, and get error
Stripe however works fine and goes through to checkout confirmation
r
What’s the error message + stack after you confirm on the dialog @Kurtis? I saw you had a CSRF issue as well, but that’s unrelated to this 🤔 If you are both getting the same issue on paypal checkout and it occurs on a fresh installation, we should make an issue on GH about this 👍
k
Let me spend a bit more time, will see if I can sort out my CSRF issue first
If no luck, will create an issue
Thanks as always @Ryan Woods
👍 1
s
Untitled.txt
I can’t checkout either. After I submit the paypal form in a popup window, I’m getting this response
r
k
I see this, we are using rails_ujs and I tried jquery_ujs, but no luck
I will try again
r
Hmm, the request is being made by Ajax, and Rails is suppose to attach onto the requests with CSRF headers, so that’s what I think is going on. I encountered the same thing on one project before.
I am using the same Rails and SolidusPayPalBraintree versions as you @Kurtis but not getting it, looking into it more 👀
k
Life as developers lol
r
What frontend gem are you using @Kurtis?
k
Not sure we’re using one. I set this app up five years ago and at the time it was all part of solidus. In my Gemfile.lock I only have solidus_core, solidus_backend, solidus_support and solidus_api
I see solidus_frontend is too as part of the solidus 3.1.7 gem
We don’t use any of it though, all a custom built front end
👍 1
r
Do you know where you are requiring jquery in the JS manifests?
//= require rails-ujs
should be after it
Just be careful with duplicate jquery require’s
solidus_frontend
normally has a file that looks like this:
vendor/assets/javascripts/spree/frontend/all.js
Which contains
Copy code
//= require jquery3
//= require rails-ujs
//= require spree/frontend
Then the the Braintree extension adds this to it:
Copy code
//= require_tree .
//= require solidus_paypal_braintree/frontend
s
Atm we’re including it in this order
//= require jquery
here we require jquery_ujs or rails-ujs (getting confused here what is what LOL) as when having both, it shows an error saying to only have rails-ujs
//= require checkout/payment/spree
//= require checkout/payment/braintree
//= require checkout/payment/stripe
r
Ahh right,
jquery_ujs
is the old one, my bad, that’s what I needed a while ago for an old project :grin You’ll need
rails-ujs
s
Tried both tho, same result
We’ve upgraded to jsbundling-rails and cssbundling-rails and we had to hack it a bit to include what’s needed (didn’t find an alternative solution)