<commit_before>= wepay-rails

Wepay-Rails allows your rails app to accept payments with Wepay (http://www.wepay.com).

= Features

* Built in IPN that listens to push notifications from wepay and updates saved checkout records for you
* Allows you to fetch your access token easily through a web interface
* Built in API tools to allow you to make all wepay-api calls easily
* Built in ability to send your customers to wepay to make payments and handles their trip back for you
* Saves the current state of every checkout
* Configurable

= Installation

To install it, add this to your Gemfile

    gem 'wepay-rails'

To create your WepayCheckoutRecord model and migration:

    script/rails g wepay_rails:install

This will create 3 files for you, a migration file for a table to hold the checkout results, the model and a wepay.yml.example file. Next run:

    rake db:migrate

WepayCheckoutRecord will be updated by wepay's IPN system as changes to the checkout change - such as the status.
Wepay-rails handles those IPN notifications for you. You can write observers watching the WepayCheckoutRecord model if you need to have
something specific occur when the checkout changes. Also, since a model is created for you, you can also track changes to it's state
through state machine or paper trail or some other gem of your liking. Hook up WepayCheckoutRecord how you like.

Modify config/wepay.yml.example to your needs and copy it to config/wepay.yml.

Assuming that you have:

1. created an account on wepay
2. created a user to accept the payments
3. created your application for your account
4. set your wepay.yml file with the info it needs to talk to the wepay api minus the access_token

You can now get your access token.

To fetch your access_token, open a browser and go to:

    your.railsapp.com/wepay/authorize

Login at the prompt or register. You will be sent back to your app and you should have gotten an access_token. Copy it to your wepay.yml
file and restart your app.

= Example

I created a controller called finalize_controller and I use it for a landing page when the customer is finished paying
their order. The other controller I created is a checkout_controller - I send my customers to it when they click checkout
in the cart. Your app is surely different than mine. Do what makes sense to you.
For now, here's a small example...

  app
    |_ controllers
                 |_ purchase
                        |_ checkout_controller.rb
                        |_ finalize_controller.rb

Tell wepay-rails where to send the customer after they come back from wepay with a complete payment. Open wepay.yml:

    after_checkout_redirect_uri: "http://www.example.com/purchase/finalize"

Create a controller that will send the user to wepay - notice it includes WepayRails::Payments:

    class Purchase::CheckoutController < ApplicationController
        include WepayRails::Payments

        def index
            cart = current_user.cart # EXAMPLE - get my shopping cart

            checkout_params = {
                :amount => cart.grand_total,
                :short_description => cart.short_description,
                :long_description => cart.long_description,
            }

            # 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

Finally, the controller I use for finalizing the checkout - AKA - the controller the user is sent back to after his/her trip back from
wepay. A checkout_id is passed in through params so you can access the WepayCheckoutRecord, make a call to
wepay to get the checkout info - whatever you want to do (See the wiki for more info on API calls):

    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


== Special Thanks to additional contributers of Wepay-Rails
* lucisferre (<NAME>) https://github.com/lucisferre
* mindeavor (Gilbert) https://github.com/mindeavor
* ustorf (<NAME>) https://github.com/ustorf


== Contributing to wepay-rails
 
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
* Fork the project<commit_msg>Added dragonstarwebdesign to list of contributors<commit_after>= wepay-rails

Wepay-Rails allows your rails app to accept payments with Wepay (http://www.wepay.com).

= Features

* Built in IPN that listens to push notifications from wepay and updates saved checkout records for you
* Allows you to fetch your access token easily through a web interface
* Built in API tools to allow you to make all wepay-api calls easily
* Built in ability to send your customers to wepay to make payments and handles their trip back for you
* Saves the current state of every checkout
* Configurable

= Installation

To install it, add this to your Gemfile

    gem 'wepay-rails'

To create your WepayCheckoutRecord model and migration:

    script/rails g wepay_rails:install

This will create 3 files for you, a migration file for a table to hold the checkout results, the model and a wepay.yml.example file. Next run:

    rake db:migrate

WepayCheckoutRecord will be updated by wepay's IPN system as changes to the checkout change - such as the status.
Wepay-rails handles those IPN notifications for you. You can write observers watching the WepayCheckoutRecord model if you need to have
something specific occur when the checkout changes. Also, since a model is created for you, you can also track changes to it's state
through state machine or paper trail or some other gem of your liking. Hook up WepayCheckoutRecord how you like.

Modify config/wepay.yml.example to your needs and copy it to config/wepay.yml.

Assuming that you have:

1. created an account on wepay
2. created a user to accept the payments
3. created your application for your account
4. set your wepay.yml file with the info it needs to talk to the wepay api minus the access_token

You can now get your access token.

To fetch your access_token, open a browser and go to:

    your.railsapp.com/wepay/authorize

Login at the prompt or register. You will be sent back to your app and you should have gotten an access_token. Copy it to your wepay.yml
file and restart your app.

= Example

I created a controller called finalize_controller and I use it for a landing page when the customer is finished paying
their order. The other controller I created is a checkout_controller - I send my customers to it when they click checkout
in the cart. Your app is surely different than mine. Do what makes sense to you.
For now, here's a small example...

  app
    |_ controllers
                 |_ purchase
                        |_ checkout_controller.rb
                        |_ finalize_controller.rb

Tell wepay-rails where to send the customer after they come back from wepay with a complete payment. Open wepay.yml:

    after_checkout_redirect_uri: "http://www.example.com/purchase/finalize"

Create a controller that will send the user to wepay - notice it includes WepayRails::Payments:

    class Purchase::CheckoutController < ApplicationController
        include WepayRails::Payments

        def index
            cart = current_user.cart # EXAMPLE - get my shopping cart

            checkout_params = {
                :amount => cart.grand_total,
                :short_description => cart.short_description,
                :long_description => cart.long_description,
            }

            # 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

Finally, the controller I use for finalizing the checkout - AKA - the controller the user is sent back to after his/her trip back from
wepay. A checkout_id is passed in through params so you can access the WepayCheckoutRecord, make a call to
wepay to get the checkout info - whatever you want to do (See the wiki for more info on API calls):

    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


== Special Thanks to additional contributers of Wepay-Rails
* lucisferre (<NAME>) https://github.com/lucisferre
* mindeavor (Gilbert) https://github.com/mindeavor
* ustorf (<NAME>) https://github.com/ustorf
* dragonstarwebdesign (<NAME>) https://github.com/dragonstarwebdesign


== Contributing to wepay-rails
 
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
* Fork the project
{'fraction_non_alphanumeric': 0.04779336994102095, 'fraction_numerical': 0.001016880211511084, 'mean_word_length': 3.2798085291557877, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 16, 'https://': 7, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '284591', 'n_tokens_mistral': 2720, 'n_tokens_neox': 2560, 'n_words': 1277}