Project

jpay

0.0
No commit activity in last 3 years
No release in over 3 years
the Jpay gem provides Ruby APIs for proccessing payments, transactions and verifications using JahanPay's Merchant APIs. For more information please visit JahanPay website
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.7
~> 10.0

Runtime

>= 2.11.1, ~> 2.11
 Project Readme

Jpay

JahanPay payment gateway gem for rails

the Jpay gem provides Ruby APIs for proccessing payments, transactions and verifications using JahanPay's Merchant APIs. For more information please visit JahanPay website

NOTE: Jpay is highly inspired by Zarinpal gem

Installation

Add this line to your application's Gemfile:

gem 'jpay'

And then execute:

$ bundle

Or install it yourself as:

$ gem install jpay

Configuration

rails g jpay:install

Configure 'config/initializers/jpay.rb':

Jpay.configure do |config|

  config.api = "xxxxx" # your jahanpay api
  config.callback_url = "localhost:3000/verify"

end

Example

Payment Request:

class PurchaseController < ApplicationController
  ...
  def payment
    ...
    # payment request action
    requeset = Jpay::PaymentRequest.new({
      amount: 100, # must be in toman
      order_id: 1, # your order id
      text: 1, # any description for your order
      # callback_url: 'localhost:3000/verifyProducts' #this is not needed as you already defined callback url in 'config/initializers/jpay.rb'
      # but you can define it for every purchase if you want to have different callbacks for every purchase
    })

    response = request.pay
    response.valid?
    # if response is valid, it returns your jahanpay invoice number (response.invoice).
    # you must redirect_to "http://jahanpay.com/pay_invoice/#{response.invoice}"
    # or you can do as following:
    redirect_to response.url if response.valid?
    # this will redirect user to jahanpay.
  end
end

Payment Verification:

class PurchaseController < ApplicationController
  ...
  # verify callback action
  def verify
    # jahanpay sends 'authority' code to your callback_url by GET method as 'au' param
    authority_code = params[:au]

    verification = Jpay::PaymentVerification.new({
      amount: 100, # must be equal to request amount
      authority: authority_code
    })

    response = verification.verify

    response.status   # return 1 for successful transaction, error number for unsuccessful one
    response.message  # returns status message
    response.valid?   # returns 'true' for successful transaction
  end

end

Contributing

  1. Fork it ( http://github.com/rezam90/jpay/fork )
  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

##Copyright Copyright © 2015 Reza Morsali.