Midpay
A Rack Middleware for E-Commerce Payment Base-Strategy
Installation
Add this line to your application's Gemfile:
gem 'midpay'
And then execute:
$ bundle
Or install it yourself as:
$ gem install midpay
Usage
For example, we have a strategy named Foo as following:
class Foo
include ::Midpay::Strategy
def request_phase response
response.write("You are being redirected to a payment gateway......")
response.redirect a_url_for_payment_gateway_with_some_parameters
end
def callback_phase payment_info
payment_info.extra = EXTRA_INFO #... whatever
payment_info.raw_data = RAW_DATA #... whatever
payment_info.success = true
end
end
#register your strategy
::Midpay[:foo] = ::Foo
In your rack app:
use ::Midpay[:foo], YOUR_APPID, YOUR_KEY, :request_params_proc => {|params|
obj = BarModel.find(params[:bar_id])
{
:key1 => obj.value1,
:key2 => obj.value2
# all of the params to be sent to your payment gateway on request phase
}
}
Send a request to Payment Gateway:
get '/midpay/foo?bar_id=123'
Handle gateway callback request in your controller:
def callback
current_strategy = request.env['midpay.strategy']
callback_data = request.env['midpay.callback']
# handle the callback logic
end
For more details at WIKI
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request