adamthedeveloper / wepay-rails Goto Github PK
View Code? Open in Web Editor NEWCollect payments from wepay in your rails application.
License: MIT License
Collect payments from wepay in your rails application.
License: MIT License
In the WePayCheckoutRecords migration, there is no definition to the precision and scale attributes on the :decimal columns, so Rails assumes a precision of 10 and a scale of 0, truncating any cents returned from Wepay.
I would suggest you put in a precision of 10, and scale of 2 in those columns.
Tests are indeed needed. I will create some - OR - if someone out there would like to create some tests, please do so and send me a pull request. Thanks for helping.
I'm working on setting up Preapprovals and delayed Charges with Wepay-Rails as a plugin for the open source Catarse Crowdfunding platform.
By copying the Checkout methods am able to get some test preapprovals flowing properly, and now need to call the :preapproval_id and :preapproval_uri to make a payment/capture.
Sorry for the silly question, but I am looking for the code that saves the :preapproval_id and :preapproval_uri in the database in the same manner as the checkout_id. In my tests, It seems they are not saving to the database on the callback. Is that something I need to setup in the lib/wepay_checkout_methods model through the gem or do I need to code it in one of my models in my app?
The :preapproval_id and :preapproval_uri columns have been added to the wepay_checkout_records table, but do not show when I call the records in the console after a successful callback from Wepay.
I should add I'm using this sort of code in my preapproval_controller which admittedly is a very ugly stab in the dark:
def success
response = WepayCheckoutRecord.find_by_preapproval_id(params[:preapproval_id])
logger.info response.inspect
if response[:state] == 'approved'
response.update_attributes :preapproval_id => :preapproval_id
response.save!
#@user.build_payment_detail
#@user.confirm!
#flash[:notice] = "Successful Approval"
render :success
end
end
My fork of the gem is here: https://github.com/lvxn0va/wepay-rails
hi, having some trouble with implementing a preapproval, the call:
response = wepay_gateway.perform_preapproval(checkout_params)
in init_preapproval returns:
undefined method `merge' for nil:NilClass
it works great for checkout.. any ideas?
Hi,
I have another issue with wepay-rails that I wonder if anyone else has seen. I'm trying to pass in some user info to the checkout so at least some of the fields are prefilled, but I'm getting the following error no matter what I've tried:
WepayRails::Exceptions::WepayCheckoutError
An error occurred: {:error=>"invalid_request", :error_description=>"expecting JSON object for parameter prefill_info", :security_token=>"10138d3836223d54bb9bfbd3cf71e532f9f333b14de2b9bd5406562e59083960"}
I'm using the following for the params, where the prefill_info is the sample provided by WePay.
checkout_params = {
:account_id => @owner.wepay_account,
:amount => @price,
:short_description => "An order",
:app_fee => (@price * 0.1),
:fee_payer => "Payer",
:mode => 'iframe',
:prefill_info => '{"name":"Bill Clerico","phone_number":"855-469-3729"}'
}
Any help would be appreciated. Thanks!
Just an update for everyone using this gem, WePay is experiencing some intermittent timeout errors on the staging site, production apps should be unaffected. I'm just opening and closing this so people know, it's not related to our gem.
Note that any attempt to push an update will result in errors on tests and obviously tests on Travis, so I'll reopen, update, and close this issue when things are working.
Hello,
I was wondering what I need to do to use the wepay-rails gem in my Rails 4 application. It seems that the generators create Rails 3 type syntax. Are there plans for Rails 4 compatibility with this gem? Surprisingly, I can't find anything on wepay and Rails 4 specifically
A change was needed in app/controllers/wepay/authorize_controller.rb to protect against unwanted access_token changes.
Please upgrade to version 2.2.9 to get the change.
Adam
It looks like the wepay.yml file from install initializer outputs wepay_api_url for the WePay API endpoint, but the lib/wepay-rails.rb references @wepay_config[:wepay_api_endpoint] and @wepay_config[:wepay_ui_endpoint]. This is causing the all environments to default to WePay's production endpoint if you use the default configuration structure that is output by the install initializer.
Everything works fine if you specify the correct config variables in wepay.yml, but it took a while to realize that my development environment issues were coming from the fact that the config variables I had set were not referenced.
Hello!
First off, I want to say thank you for this gem, I have been using it for a project and it has been working nicely. I have been running into 1 problem however and I was hoping someone could point me in the right direction of patching it. I followed the setup example on the homepage however I noticed that in doing so I opened up a bit of a security hole in my site.
I have modified my checkout controller to be as follows
class Purchase::CheckoutController < ApplicationController
include WepayRails::Payments
def index
begin
@order = Order.find(session[:order_id])
rescue
redirect_to :root
flash[:warning] = "You do not currently have any pending orders."
return
end
@item = Item.find(@order.item_id)
checkout_params = {
:amount => @order.total.to_f,
:short_description => "Order",
:long_description => "Your order for #{@order.quantity} #{@item.name.pluralize(@order.quantity)} ",
}
init_checkout_and_send_user_to_wepay(checkout_params)
end
end
and my finalize controller to be:
class Purchase::FinalizeController < ApplicationController
def index
# Fetch the WepayCheckoutRecord that was stored for the checkout
wcr = WepayCheckoutRecord.find_by_checkout_id(params[:checkout_id])
@order = Order.find(session[:order_id])
@order.wepay_checkout_record = wcr
@order.paid = true if wcr.state == 'authorized'
@order.save
redirect_to :root, :notice => "You have completed your purchase."
end
end
However I have noticed that since I am using the session, if a user goes back and creates a new order then they are able to override the first order stored in the session. I have tried looking into a way to save the session in the checkout controller however I have not found a way to do so. Am I missing something here that might work to get rid of this issue?
Sorry I didn't catch it sooner Steve. This is file to be removed:
lib/wepay-rails.rb~
Notice the '~'. Your IDE must have created and added a swap file.
While you are at it, please add a line to the contributors section of the README for yourself - that way, we don't have too many version updates.
Thanks again for you contributions.
Adam
In my application, we are sending out an estimate with a button to allow the recipient to pay via the WePay iframe, the full amount of the estimate.
This seems to work, however we would also like to add the ability to make an auto-recurring payment, so we would split up the invoice total in thirds, and let the recipient pay in 3 monthly installments.
When I pass into the checkout_params, the keys of :period, :auto_recur, and :end_time, the Rails Gem coughs it back. I wonder if this is just something the current Gem doesn't support, or do I need to issue it another way?
Hi,
I'm having some trouble with creating a checkout. The install went fine and I've got the user authorization and account creation all working. However, now when I try to call init_checkout, I get the following error:
uninitialized constant WepayRails::Helpers::ControllerHelpers::WepayCheckoutRecord
The model is in lib/models as created by the installer. The controller itself has "include WepayRails::Payments". What am I missing?
Thanks in advance!
Let's discuss what we need to change in wepay-rails to accommodate the new feature of the wepay api:
https://stage.wepay.com/developer/tutorial/tokenization
Thanks in advance!
Adam
so i'm having an issue completing a checkout call, and i'm sure it's user error rather than the gem, but i can't figure out what i'm screwing up.
the first error i was getting when i hit the checkout url was this:
NameError (uninitialized constant WepayRails::Helpers::ControllerHelpers::WepayCheckoutRecord):
which i fixed by adding this:
config.autoload_paths += %W(#{config.root}/lib/models)
to my application.rb, but it might be worth adding that step to the readme.
so now that's fixed but the new error i'm getting is this:
ActionController::ActionControllerError (Cannot redirect to nil!):
and after looking at controller_helpers.rb inside the wepay-rails gem it seems pretty clear that the init_checkout(params, access_token=nil) method is failing to return a record with a value in the checkout_uri column to the init_checkout_and_send_user_to_wepay(params, access_token=nil) method, so when init_checkout_and_send_user_to_wepay calls redirct_to record.checkout_uri it's getting nil.
if i log into my developer console on stage.wepay.com and look at the API calls i can see the call i just made. here are the details of the call:
Call ID 2129758 Request Argument {
"callback_uri": "http://owmee.herokuapp.com/wepay/ipn?security_token=3a2a4d0271105199cb2981b2d8fa3bc4f2324b7db1bec6afdd37dbd35a747cb6",
"redirect_uri": "http://owmee.herokuapp.com/wepay/checkout?security_token=3a2a4d0271105199cb2981b2d8fa3bc4f2324b7db1bec6afdd37dbd35a747cb6",
"fee_payer": "Payee",
"type": "PERSONAL",
"charge_tax": "0",
"app_fee": "0",
"auto_capture": "1",
"require_shipping": "0",
"shipping_fee": "0",
"account_id": "123456789", #faked obv so i could share this
"amount": "100.00",
"short_description": "wepay test call",
"long_description": "i have no idea what i'm doing"
} Response Argument {
"checkout_id": 1655086542,
"checkout_uri": "https://stage.wepay.com/api/checkout/1655086542/fce808a1"
}
and if i open a heroku pg:psql session and run SELECT * FROM wepay_checkout_records; i can see records are being created in my database for all the calls i've made, but none of the columns have any data in them except created_at and update_at. somehow i'm creating wepay_checkout_records with a bunch of nil params.
here is the checkout_controller in my app:
class Purchase::CheckoutController < ApplicationController
include WepayRails::Payments
def index
# cart = current_user.cart # EXAMPLE - get my shopping cart
checkout_params = {
:amount => "100.00",
:short_description => "wepay test call",
:long_description => "i have no idea what i'm doing"
}
# Finally, send the user off to wepay so you can get paid! - CASH MONEY
init_checkout_and_send_user_to_wepay(checkout_params)
end
end
here is the finalize_controller in my app:
class Purchase::FinalizeController < ApplicationController
def index
# Fetch the WepayCheckoutRecord that was stored for the checkout
# wcr = WepayCheckoutRecord.find_by_checkout_id(params[:checkout_id])
# Example: Set the association of the wepay checkout record to my cart - then, on to order.
# cart = current_account.cart
# cart.wepay_checkout_record = wcr
# cart.save!
# Convert cart to an order?? Move to observer of WepayCheckoutRecord??
# cart.convert_cart_to_order if wcr.state == 'authorized'
render :text => "Hooray - you bought some widgets!"
end
end
here's what i have in my config.rb:
namespace :purchase do
resources :checkout, :finalize, only: :index
end
…any help would be greatly appreciated, i'm out of ideas at the moment.
With the wepay-rails gem installed, I get an error every time I run "rails generate migration":
/Users/Sacha/.rvm/gems/ruby-1.9.2-p180/gems/wepay-rails-0.1.114/lib/wepay-rails.rb:48:in `<class:Gateway>': uninitialized constant WepayRails::Payments::Gateway::HTTParty (NameError)
Any idea why that's happening? I'm quite new to Rails, so it's entirely possible that I've made a mistake somewhere, but as far as I can tell all I did was install the gem.
I am accessing the link that should redirect me to WePay, but keep getting this error message in Rails: Errno::ECONNRESET in Purchase::CheckoutController#index
Connection reset by peer
I'm assuming this is due to some bad auth. Am I correct in this assumption, and if so, is there an easy way to triangulate what's going wrong?
Someone added a models directory to the gem. Get rid of that.
In my crowdfunding app, we are nesting the oauth2 authorization url in routes.rb to attach each authorization to a certain project.
This allows each user to have multiple projects, and multiple wepay payment accounts, each attached to it's own individual project. Users are able to use a button to connect and disconnect each project's payment account in their profile.
The routing for this looks like so:
match "/projects/:project_id/gateways/wepay_auth" => "projects/gateways#wepay_auth", :as :wepay_auth
http://example.com/projects/:project_id/gateways/wepay_auth
But the wepay.yml file only accepts a full URL as a http string, so my :redirect_uri shows:
in my custom wepay-rails gem:
params[:redirect_uri] ||= @wepay_config[:auth_redirect_uri]
in wepay.yml
:auth_redirect_uri: "http://localhost:3000/wepay_auth"
which returns the browser to:
http://localhost:3000/wepay_auth?code:xxxxxxxxxxxxxxxx
Which then can't find the correct project_id to attach the wepay_access_token to.
I've tried passing some ruby code in the wepay.yml file like so:
:auth_redirect_uri: <%= wepay_auth_url =>
But get an error stating that the redirect_uri must be a full url
Do I need to create a helper in the gem and/or hardcode the url there in wepay-rails.rb or is it possible to do it in the yaml file using .erb and I'm just not seeing it?
thanks so much
When I run 'script/rails g wepay_rails:install' it says that wepay.yml doesnt exist.
Any suggestions?
$ rails c
Loading development environment (Rails 3.2.3)
1.9.3-p0 :001 > wepay_gateway = WepayRails::Payments::Gateway.new <--- this line is from the wiki example
NoMethodError: undefined method []' for nil:NilClass from /Users/nitin/.rvm/gems/ruby-1.9.3-p0/gems/wepay-rails-2.2.9/lib/wepay-rails.rb:53:in
initialize'
from (irb):1:in new' from (irb):1 from /Users/nitin/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.3/lib/rails/commands/console.rb:47:in
start'
from /Users/nitin/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.3/lib/rails/commands/console.rb:8:in start' from /Users/nitin/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.3/lib/rails/commands.rb:41:in
<top (required)>'
from script/rails:6:in require' from script/rails:6:in
line 53 in wepay-rails.rb is expecting an access_token in args but the wiki example doesn't pass in any params to new
A file was missing from the gem - namely the app/controllers/wepay/checkout_controller.rb file. I added it in.
I also wanted to add an additional security check to the IPN and checkout controller - if you are using a version prior to 2.2.0, and you want to use the latest version, you will need to add a migration to your rails app to add a security_token column to wepay_checkout_records. Create a migration and add this line:
add_column :wepay_checkout_records, :security_token, :string
New installs of version 2.2.0 will already have this column since I added the additional column to the migration template.
Please let me know if you run into problems and I will help out.
script/rails g wepay_rails:install
/Library/Ruby/Gems/1.8/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb:206:in `const_missing': uninitialized constant WepayRails::Payments::Gateway::HTTParty (NameError)
from /Library/Ruby/Gems/1.8/gems/wepay-rails-2.1.0/lib/wepay-rails.rb:36
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.15/lib/bundler/runtime.rb:68:in `require'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.15/lib/bundler/runtime.rb:68:in `require'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.15/lib/bundler/runtime.rb:66:in `each'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.15/lib/bundler/runtime.rb:66:in `require'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.15/lib/bundler/runtime.rb:55:in `each'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.15/lib/bundler/runtime.rb:55:in `require'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.15/lib/bundler.rb:120:in `require'
I tried adding httparty to the gemfile and that didn't help.
Not sure what the issue is... I'm running Ruby 1.8.7 and Rails 3.0.9
I am encountering some bug and I am almost 100% certain that it has something to do with the way I name my controllers and my routing configuration.
Can you provide additional detail in the README? It would be great if you could list out your file names and routes.rb as well.
Hey Adam,
Just started messing around with the gem today and got pretty far: thanks for the good work.
Had one problem though: I called init_checkout_and_send_user_to_wepay and the response came back fine, however, I got an AR error when the WepayCheckoutRecord was being created saying that there is no such attribute as access_token. If I remove that assignment (by remming out line 49 in lib/helpers/controller_helpers.rb) checkout seems to work and a valid WepayCheckoutRecord is created.
Am I doing something wrong?
Hope all is well,
Bernd
Hi,
I am doing testing of my app on a number of servers, including localhost, so it'd be nice if there was a way to have the callback_uri reflect that, instead of having to hardcode it in the yaml file. Does anyone know how I could go about doing that?
Thanks,
Alex
a) when I am using this multiple user dynamic auth approach, in the
wepay.yml I only provide client_id and client_secret right? Because I don't
have a token yet and when I get token(s) there will be multiple and so the
yml as defined is somewhat tied to the single user case correct? Also
account_id comes after I get a token. So I dont have an account_id either.
b) the wiki says at one point
"Calling get_access_token with a valid access key in the params hash will
return the :access_toeknattribute, and also set the :account_id attribute to
the user's WePay user id."
I assume "valid access key" refers to the 'code' param returned by WePay
which is in params[:code] yes?
Also it should be account_id not user id in the last few words yes?
account_id as returned by WePay when an account is created
via /v2/account/create yes?
Thanks much.
Not sure the best way to handle this one, but I'd like to store sensitive data (namely production client_id and client_secret) in a variable and call it in wepay.yml with ruby. This is trivial using yml.erb, however the initialization mechanism for WepayRails only looks for "wepay.yml" and thus fails when you add .erb to the file name.
I don't have much experience messing with YAML loading and such, but I found out how to load the file with .erb. I'm sure there is a more elegant way to solve this but my proposed solution is to edit wepay-rails.rb as follows:
class Engine < Rails::Engine
# Initializers
initializer "WepayRails.initialize_wepay_rails" do |app|
yml = Rails.root.join('config', 'wepay.yml').to_s
if File.exists?(yml)
settings = YAML.load_file(yml)[Rails.env].symbolize_keys
elsif File.exists?(yml+".erb")
settings = YAML::load(ERB.new(IO.read(yml+".erb")).result)[Rails.env].symbolize_keys
end
Configuration.init_conf(settings) unless settings.nil?
end
...
end
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.