paypal gem multiple accounts ruby on rails - ruby-on-rails

I'm using the paypal-sdk-merchant gem. So far I have set one merchant account with this command:
PayPal::SDK.configure(
:mode => "sandbox",
:app_id => "APP-sdfgjkl",
:username => "lprieto-facilitator_api1.hasu.cl",
:password => "Z7XGVDCHBJN",
:signature => "AFcWxV21C7fd0v3bYYYRCpSSRlXDCFVGBHLBRTnmAzXxHddoa5e",
:sandbox_email_address => "lprieto-facilitator_api1.hasu.cl")
and then create a payment with
api = PayPal::SDK::Merchant::API.new
This have work perfectly so far but now I have to change the paypal account according to the country the person is buying from. If I'm constantly changing the PayPal::SDK.configure will there be any consistence problems??
For example, if a person in Brasil access and the configuration is change. Then a person in Chile access and the configuration is change. After, the brasilian pays. Will it have the brasilian configuration or the chilean one?
What would you recommend for having multiple Paypal accounts in a ruby on rails app?
Thank you in advance.

I recommend taking a look at https://github.com/paypal/PayPal-Ruby-SDK because this gem doesn't support rails 4 and will be deprecated.
As for your problem at hand: Seeing the API, you would indeed need to call PayPal::SDK.configure() for each different type of merchant/country. You can create a YML config file for this something like config/paypal.yml:
chile:
mode: sandbox
app_id: APP-123
username: user1
password: pass1
signature: ABCDEF
sandbox_email_address: test#example.com
brasil:
mode: sandbox
app_id: APP-456
username: user2
password: pass2
signature: GHIJKL
sandbox_email_address: test2#example.com
and use this in your app like:
#api_chile = PayPal::SDK::Merchant::API.new(:chile)
#api_brasil = PayPal::SDK::Merchant::API.new(:brasil)
Hope this helps!

Related

Affiliate Links using GEM: rack-affiliates with localhost - not working

If one could kindly help or advise me, i would be very grateful. I am trying to get the gem "rack-affiliates" to work but unfortunately it is not working and there is not enough help nor documentation out there.
i have bundle installed the gem "rack-affiliates"
i have created the table "affiliates" with the columns name:string, tag:string
for the table "users" i have the columns ref:string, affiliate_tag:string, affiliate_tag_ref:string
the affiliate_tag is automatically produced when a user signups on the platform with the below method is the usr.rb file
class User < ApplicationRecord
before_create :generate_affiliate_tag
def generate_affiliate_tag
begin
reference_length = 6
self.affiliate_tag = "SPz_" + Devise.friendly_token.first(reference_length).tr('+/=-', '0aZ')
end while self.class.exists?(affiliate_tag: affiliate_tag)
end
end
therefore example when user_A registers on the platform, user_A will receive an affiliate_tag: SPz_bpQFGq
with this the user_A [affiliate user] will have the affiliate link: http://localhost:3000/users/sign_up?ref=SPz_bpQFGq
When user_A gives the affiliate link to user_B. After user_B has signuped, i would like the ref in the url SPz_bpQFGq to be stored under the column affiliate_tag_ref:string for user_B (under the users table)
i have done all that the documentation requested:
bundle installed the gem "rack-affiliates"
updated the file config/application.rb with the below code:
but i am sure why it is not working. If i am doing ti all wrong, you advise and guidance will be much much appreciated.
Or if one could direct me to a better documentation on how to build affiliate links and track them successfully i would be grateful
Try
config.middleware.use Rack::Affiliates, { :param => 'ref', :domain => 'localhost', :path => "/" }
instead of
config.middleware.use Rack::Affiliates, { :param => 'ref', :domain => '.localhost', :path => "/" }

When connecting to Linkedin with OAuth, is it possible to get the user's non-primary email addresses?

I'm using Devise and the omniauth-linkedin gem to allow users to log into my Rails app with a LinkedIn account (Rails 4.1.8, Devise 3.4.0, omniauth-linkedin 0.2.0). I've had no trouble getting the user's primary email from LinkedIn, but I'm wondering, is it possible to get a list of ALL the emails associated with the user's LinkedIn account, including non-primary emails?
The LinkedIn docs (https://developer.linkedin.com/documents/authentication) don't say how to do this, but they also don't say that it's impossible.
If it IS possible, what scopes/fields do I need to add to my Devise config? Currently the relevant line in config/devise.rb looks like this:
config.omniauth :linkedin, ENV['LINKEDIN_KEY'], ENV['LINKEDIN_SECRET'],
scope: 'r_fullprofile r_emailaddress r_network w_messages',
fields: ["id", "email-address", "first-name", "last-name", "headline",
"industry", "picture-url", "public-profile-url", "location",
"connections"]
The LinkedIn Profile API does not expose email addresses other than the primary one associated with a member profile.

Authorize.net in Rails - User Authentication failed due to invalid authentication values

I am building a client's ecommerce website. I'm at the latest stages, where I have to integrate the payment system. I signed up for a developer account for Authorize.net in order to test the system. I've ran into a roadblock here
I submitted my payment form, and found the following in my Development Logs
User authentication failed due to invalid authentication values
I set up my gateway as followed, based on my login information to Authorize.net
gateway = ActiveMerchant::Billing::AuthorizeNetGateway.new(
:login => "mylogin",
:password => "mypassword",
:test => false
)
Apparently, I'm missing something, but I'm not sure what it is. I watched the RailsCasts videos 144 and 145. I just substituted the gateway to AuthorizeNetGateWay.
Where am I going wrong here?
Here is my development.rb file
config.after_initialize do
ActiveMerchant::Billing::Base.mode = :test
::GATEWAY = ActiveMerchant::Billing::AuthorizeNetGateway.new(
:login => "mylogin",
:password => "mypassword",
#:signature => "AGjv6SW.mTiKxtkm6L9DcSUCUgePAUDQ3L-kTdszkPG8mRfjaRZDYtSu"
:test_requests => false
)
end
Could the problem be ActiveMerchant::Billing::Base.mode = :test considering this is my Development Environment file?
If you're using a developer account set test to true to use the developer server:
:test => true

Analytics API integration rails failing on heroku production

I am currently developing a ruby on rails application which includes the gattica gem to fetch Google Analytics data. When I fetch my data:
https://github.com/activenetwork/gattica
gs = Gattica.new({:email => 'johndoe#google.com', :password => 'password', :profile_id => 123456})
results = gs.get({ :start_date => '2008-01-01',
:end_date => '2008-02-01',
:dimensions => 'browser',
:metrics => 'pageviews',
:sort => '-pageviews'})
on development I will simply receive a response which I can parse to my application.
However on production the page returns a 500 error and in my Gmail inbox I receive a message about a suspicious login being caught.
Is there any way I can fix this issue?
PS: my application is hosted on Heroku.
With kind regards,
Dennis
You're getting the 500 error because Google is blocking your heroku ip from accessing your account. They aren't sure it's you.
You need to change your activity settings to authorize that ip/domain.
Read this: https://support.google.com/accounts/answer/1144110?hl=en&ref_topic=2401957
Also, its a good idea to read your logs when debugging these kinds of errors. Rails.logger.debug results could shed some light.

How do you add an administratior in a rails 3 appliction

I have just built a rails 3 application by using Mike Hartl's "Learn Rails by Example". I am ready to deploy it but I am confused about how to add the administrator to the application. I will be the only administrator. Will the administrator be added before deployment and if so how do I do this.
What I believe you need when you talk about an "administrator account" is in fact two different things: authentication (the login) & authorization (what a login can/cannot do).
Under rails, one way to do that is by using two different gems. I suggest you have a look at devise, and cancan. They have both been developed and are actively maintained by rails superstars: José Valim and Ryan Bates.
The tutorial doesn't actually go through creating an interface where you can create admins. If you want to test the part where you're not allowed to delete other administrator accounts, you can test it with faker by adding 2 admins to the sample_data.rake file:
def make_users
admin = User.create!(:name => "Example User",
:email => "example#railstutorial.org",
:password => "foobar",
:password_confirmation => "foobar")
admin.toggle!(:admin)
admin2 = User.create!(:name => "Example User2",
:email => "example2#railstutorial.org",
:password => "foobar",
:password_confirmation => "foobar")
admin.toggle!(:admin)
99.times do |n|
name = Faker::Name.name
email = "example-#{n+1}#railstutorial.org"
password = "password"
User.create!(:name => name,
:email => email,
:password => password,
:password_confirmation => password)
end
end
If you want to add an admin to production, I'm guessing you could create your account and toggle the admin function with a database editor and then push the db to the production server? That's what I would do but I'm by no means an expert.
for admin control panel on my web-apps i'm using typus gem https://github.com/fesplugas/typus/
it will generate an admin page and by the default typus will use your model default_scope to fetch data.
I'm busy with the same thing!
I found this on STACK:
rails c
Loading development environment (Rails 3.0.0.beta3)
irb(main):001:0> admin = Admin.create! do |u|
irb(main):002:1* u.email = 'sample#sample.com'
irb(main):003:1> u.password = 'password'
irb(main):004:1> u.password_confirmation = 'password'
irb(main):005:1> end
I changed the Admin to User, but the problem is it creates a normal user not an admin user. Somewhere we need to put in - admin.toggle!(:admin) or make it true. I'll let you know if I find anything else.

Resources