adamthedeveloper / wepay-rails

Collect payments from wepay in your rails application.
MIT License
32 stars 24 forks source link

wepay_checkout_records being saved without checkout_uri #29

Closed fredguest closed 11 years ago

fredguest commented 11 years ago

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.

fredguest commented 11 years ago

that last bit is in my routes.rb not config.rb obv. brain is fried

adamthedeveloper commented 11 years ago

Hi Fred,

Did you close this because you figured out what was wrong or are you still stuck? Thanks!

Adam

fredguest commented 11 years ago

i never did figure out what i was doing wrong, but i realized i didn't really need a robust gem, i just need to make a few straightforward calls, and i couldn't really use the official wepay documentation because i was interacting with their API through the gem's code more than my own, so i tried just using the wepay SDK instead of wepay-rails and it's worked out much better in my particular case. i definitely appreciate that this gem is here in case i need it in the future though, it seems like you've done a nice job with it.