Project

midpay

0.0
No commit activity in last 3 years
No release in over 3 years
midpay
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
 Dependencies

Development

~> 1.3
>= 0

Runtime

>= 0
>= 1.4
 Project Readme

Midpay

Code Climate

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

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request