jpay 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d2ac5aa7a2da7f074f1c07f2867e68c530383bc7
4
+ data.tar.gz: 53e28aa9a257ed6e15a445161691b74f199cc693
5
+ SHA512:
6
+ metadata.gz: 5c33aca71a43f2ac603692ecb8d22f51116578844dc201e137a9249bf1ec96f6d299fecc1c40a4ba281d65fbfbc9acf07e39616b6c20b55c2cdea73baa7f0a88
7
+ data.tar.gz: d875cf611b1a965ed348ee9553d1c3d863810dfc82be900361ddb5ae81a934d187d56cb05a3465eae75e1ce9057429eeebaa727338dbf49ee47c11fe083b49f8
@@ -0,0 +1,35 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /vendor/bundle
26
+ /lib/bundler/man/
27
+
28
+ # for a library or gem, you might want to ignore these files since the code is
29
+ # intended to run in multiple environments; otherwise, check them in:
30
+ # Gemfile.lock
31
+ # .ruby-version
32
+ # .ruby-gemset
33
+
34
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
35
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jpay.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 rezam90
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Reza
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,109 @@
1
+ # Jpay
2
+
3
+ ### JahanPay payment gateway gem for rails
4
+
5
+ the Jpay gem provides Ruby APIs for proccessing payments, transactions and verifications using JahanPay's Merchant APIs. For more information please visit [JahanPay](http://jahanpay.com) website
6
+
7
+ ##### NOTE: [Jpay](https://github.com/rezam90/jpay) is highly inspired by [Zarinpal](https://github.com/arashm/zarinpal) gem
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'jpay'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ ```sh
20
+ $ bundle
21
+ ```
22
+
23
+ Or install it yourself as:
24
+
25
+ ```sh
26
+ $ gem install jpay
27
+ ```
28
+
29
+ ## Configuration
30
+
31
+ ```sh
32
+ rails g jpay:install
33
+ ```
34
+
35
+ Configure 'config/initializers/jpay.rb':
36
+
37
+ ```ruby
38
+ Jpay.configure do |config|
39
+
40
+ config.api = "xxxxx" # your jahanpay api
41
+ config.callback_url = "localhost:3000/verify"
42
+
43
+ end
44
+ ```
45
+
46
+ ## Example
47
+
48
+ Payment Request:
49
+
50
+ ```ruby
51
+ class PurchaseController < ApplicationController
52
+ ...
53
+ def payment
54
+ ...
55
+ # payment request action
56
+ requeset = Jpay::PaymentRequest.new({
57
+ amount: 100, # must be in toman
58
+ order_id: 1, # your order id
59
+ text: 1, # any description for your order
60
+ # callback_url: 'localhost:3000/verifyProducts' #this is not needed as you already defined callback url in 'config/initializers/jpay.rb'
61
+ # but you can define it for every purchase if you want to have different callbacks for every purchase
62
+ })
63
+
64
+ response = request.pay
65
+ response.valid?
66
+ # if response is valid, it returns your jahanpay invoice number (response.invoice).
67
+ # you must redirect_to "http://jahanpay.com/pay_invoice/#{response.invoice}"
68
+ # or you can do as following:
69
+ redirect_to response.url if response.valid?
70
+ # this will redirect user to jahanpay.
71
+ end
72
+ end
73
+ ```
74
+ Payment Verification:
75
+
76
+ ```ruby
77
+ class PurchaseController < ApplicationController
78
+ ...
79
+ # verify callback action
80
+ def verify
81
+ # jahanpay sends 'authority' code to your callback_url by GET method as 'au' param
82
+ authority_code = params[:au]
83
+
84
+ verification = Jpay::PaymentVerification.new({
85
+ amount: 100, # must be equal to request amount
86
+ authority: authority_code
87
+ })
88
+
89
+ response = verification.verify
90
+
91
+ response.status # return 1 for successful transaction, error number for unsuccessful one
92
+ response.message # returns status message
93
+ response.valid? # returns 'true' for successful transaction
94
+ end
95
+
96
+ end
97
+ ```
98
+
99
+ ## Contributing
100
+
101
+ 1. Fork it ( http://github.com/rezam90/jpay/fork )
102
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
103
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
104
+ 4. Push to the branch (`git push origin my-new-feature`)
105
+ 5. Create new Pull Request
106
+
107
+
108
+ ##Copyright
109
+ Copyright © 2015 Reza Morsali.
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jpay/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jpay"
8
+ spec.version = Jpay::VERSION
9
+ spec.authors = ["Reza Morsali"]
10
+ spec.email = ["light.reza@gmail.com"]
11
+ spec.summary = %q{JahanPay payment gem}
12
+ spec.description = %q{JahanPay payment gem}
13
+ spec.homepage = "https://github.com/rezam90/jpay"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = '~> 2.0.0'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "savon", "~> 2.11.1"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.7"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ end
@@ -0,0 +1,18 @@
1
+ require 'rails/generators/base'
2
+
3
+ module Jpay
4
+ module Generators
5
+ class InstallGenerator < Rails::Generators::Base
6
+ source_root File.expand_path("../../templates", __FILE__)
7
+ desc "Creates Jpay initializer for your application"
8
+
9
+ def copy_initializer
10
+ template "jpay_initializer.rb", "config/initializers/jpay.rb"
11
+ # puts "add your Jahanpay 'api' to config/initializers/jpay.rb"
12
+ # puts "add 'callback_url' to config/initializers/jpay.rb"
13
+ puts "Install complete!"
14
+
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,14 @@
1
+ Jpay.configure do |config|
2
+
3
+ # your jahanpay api
4
+ config.api = "xxxxx"
5
+
6
+ # your callback_url: example:
7
+ # config.callback_url = verify_purchase_url
8
+ config.callback_url = "localhost:3000"
9
+ # you can send specific callback_url for every purchase if you want.
10
+ # this means every purchase can have it's own callback_url.
11
+ # you can do this by adding 'callback_url' arg to PaymentRequest.new() method
12
+ # along with other args (amount, callback_url, order_id, text)
13
+
14
+ end
@@ -0,0 +1,35 @@
1
+ require "jpay/version"
2
+ require 'jpay/payment_request'
3
+ require 'jpay/response'
4
+ require 'jpay/payment_verification'
5
+ require 'jpay/errors'
6
+
7
+ module Jpay
8
+ class << self
9
+ attr_accessor :configuration
10
+ end
11
+
12
+ def self.configure
13
+ self.configuration ||= Configuration.new
14
+ yield configuration
15
+ end
16
+
17
+ # Configures the gem
18
+ #
19
+ # @example
20
+ # Jpay.configure do |config|
21
+ # config.merchant_id = 'XXXXXXXX'
22
+ # config.callback_url = 'http://example.com/call_back'
23
+ # config.client = 'http://www.jahanpay.com/webservice?wsdl'
24
+ # end
25
+ class Configuration
26
+ attr_accessor :api, :callback_url, :client
27
+
28
+ def initialize
29
+ @api = 'randome-api-xyz'
30
+ @client = 'http://www.jahanpay.com/webservice?wsdl'
31
+ @callback_url = 'localhost:3000/verify'
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,19 @@
1
+ module Jpay
2
+ module Errors
3
+ IDS = {
4
+ '-32' => 'Amount does not match',
5
+ '-31' => 'Unsuccessful transaction',
6
+ '-30' => 'Invalid transaction',
7
+ '-29' => 'CallBack was not specified',
8
+ '-27' => 'your IP is blocked',
9
+ '-26' => 'Gateway is deactivated',
10
+ '-24' => 'Invalid amount',
11
+ '-23' => 'Too much amount',
12
+ '-22' => 'Amount should be greater than 100 Toman',
13
+ '-21' => 'Invalid IP for this Gateway',
14
+ '-20' => 'Invalid API',
15
+ '-6' => 'Bank connection error',
16
+ '-9' => 'System error',
17
+ }
18
+ end
19
+ end
@@ -0,0 +1,41 @@
1
+ require "savon"
2
+
3
+ module Jpay
4
+ class PaymentRequest
5
+
6
+ attr_accessor :amount, :order_id, :text
7
+ attr_reader :response
8
+
9
+ # @note A hash of parametes should be send to this class
10
+ # @example
11
+ # PaymentRequest.new(amount: 1000, callback_url: 'localhost:3000/verify', order_id: 12, text: 'sample text')
12
+ #
13
+ # @param args [Hash] hash of params to send requests
14
+ # @option args [Integer] :amount price in Toman
15
+ # @option args [String] :callback_url callback_url url for verification redirect
16
+ # @option args [Integer] :order_id your order id
17
+ # @option args [string] :text payment description
18
+
19
+ def initialize(args = {})
20
+ @amount = args[:amount]
21
+ @callback_url = args[:callback_url] || Jpay.configuration.callback_url
22
+ @order_id = args[:order_id]
23
+ @text = args[:text]
24
+ @client ||= Savon.client(wsdl: Jpay.configuration.client, pretty_print_xml: true)
25
+ @response = Response.new
26
+ end
27
+
28
+ def pay
29
+ response = @client.call :requestpayment, message: {
30
+ 'api' => Jpay.configuration.api,
31
+ 'amount' => @amount,
32
+ 'callback' => @callback_url,
33
+ 'orderid' => @order_id,
34
+ 'txt' => @text
35
+ }
36
+
37
+ @response.validate(response.body)
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,34 @@
1
+ require "savon"
2
+
3
+ module Jpay
4
+ # Verifies transaction with jahanpay
5
+ class PaymentVerification
6
+ attr_reader :status
7
+
8
+ # @note A hash of parameters should be send to this class
9
+ # @example
10
+ # PaymentVerification.new(authority: 'xxx-xxx', amount: 10000)
11
+ #
12
+ # @param args [Hash] hash of params to verify transaction
13
+ # @option args [String] :authority Authority code returned by verify url params
14
+ # @option args [Integer] :amount price of the request
15
+ def initialize(args = {})
16
+ @authority = args.fetch(:authority)
17
+ @amount = args.fetch(:amount)
18
+ @client ||= Savon.client(wsdl: Jpay.configuration.client, pretty_print_xml: true)
19
+ @response = Response.new
20
+ end
21
+
22
+ # Send verification request to jahanpay
23
+ #
24
+ # @return [Jpay::Response]
25
+ def verify
26
+ response = @client.call :verification, message: {
27
+ 'api' => Jpay.configuration.api,
28
+ 'amount' => @amount,
29
+ 'authority' => @authority,
30
+ }
31
+ @response.validate(response.body)
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,49 @@
1
+ module Jpay
2
+ class Response
3
+ class ResponseError < RuntimeError; end
4
+ attr_reader :response, :invoice, :status, :url, :message
5
+
6
+ # Checks if the transaction response returned from PaymentRequest
7
+ # or PaymentVerification is valid
8
+ #
9
+ # @param [#response Hash]
10
+ # @raise [ArgumentError] if response is nil
11
+ # @raise [ResponseError] if response is not valid
12
+ # @return [Response]
13
+ def validate(response = nil)
14
+ @response = response
15
+ perform_validation
16
+
17
+ return self
18
+ end
19
+
20
+ # Returns the validation status of response
21
+ #
22
+ # @return [boolean]
23
+ def valid?
24
+ @valid
25
+ end
26
+
27
+ private
28
+ def perform_validation
29
+ raise ArgumentError, 'not a valid response' if @response.nil?
30
+
31
+ body = @response[:requestpayment_response] || @response[:verification_response]
32
+ @status = body[:return].to_i
33
+ @message = Errors::IDS[body[:return]]
34
+
35
+ if body[:return].to_i < 0
36
+ @valid = false
37
+ # raise ResponseError, Errors::IDS[body[:return]]
38
+ elsif body[:return].to_i == 1
39
+ @valid = true
40
+ @message = "Successful transaction"
41
+ else
42
+ @valid = true
43
+ @invoice = body[:return]
44
+ @url = "http://www.jahanpay.com/pay_invoice/#{@invoice}"
45
+ @message = 'got invoice url'
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,3 @@
1
+ module Jpay
2
+ VERSION = "0.0.3"
3
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jpay
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Reza Morsali
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-10-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: savon
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.11.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.11.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: JahanPay payment gem
56
+ email:
57
+ - light.reza@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - jpay.gemspec
69
+ - lib/generators/jpay/install_generator.rb
70
+ - lib/generators/templates/jpay_initializer.rb
71
+ - lib/jpay.rb
72
+ - lib/jpay/errors.rb
73
+ - lib/jpay/payment_request.rb
74
+ - lib/jpay/payment_verification.rb
75
+ - lib/jpay/response.rb
76
+ - lib/jpay/version.rb
77
+ homepage: https://github.com/rezam90/jpay
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 2.0.0
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.4.8
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: JahanPay payment gem
101
+ test_files: []