payment_3p 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in payment_3p.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Eslam Foad
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.
data/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # Payment3p
2
+
3
+ Provides integration with payment gateways (MIGS initially) to perform 3-Party online payment
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'payment_3p'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install payment_3p
18
+
19
+ Now run a generator to create payment_3p.yml configuration file which contains the payment gateway configurations
20
+
21
+ $ rails generate payment3p:config
22
+
23
+ Add your specific configurations for the secure secret, access code and merchant id.
24
+
25
+ That's it, you're now ready to go.
26
+
27
+ ## Usage
28
+
29
+ Generate the payment URL that you'll redirect your users to
30
+
31
+ Payment3p.payment_url(
32
+ vpc_MerchTxnRef: "1",
33
+ vpc_ReturnURL: "http://example.com/payment_callback",
34
+ vpc_OrderInfo: "CART_1",
35
+ vpc_Amount: "100",
36
+ )
37
+
38
+ Where
39
+ - `vpc_MerchTxnRef` usually contains the transaction number used to identify this transaction in your application
40
+ - `vpc_ReturnURL` the callback URL with payment result, the payment gateway will redirect to this URL
41
+ - `vpc_OrderInfo` usually contains additional order information like cart number or order id for example
42
+ - `vpc_Amount` is the amount in CENTS
43
+
44
+ Now validate the payment response in your callback, this validates that the response is a payment gateway response
45
+
46
+ Payment3p.validate_response(response)
47
+
48
+ Which will return a boolean indicating whether the response was validated or not
49
+
50
+ > **NOTE:**
51
+ >
52
+ > You still need to validate that the transaction paid through the payment gateway is the same transaction that was generated by your application, don't just rely on validating the payment gateway response there are a lot of bad people out there!!!
53
+
54
+
55
+ ## Contributing
56
+
57
+ 1. Fork it
58
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
59
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
60
+ 4. Push to the branch (`git push origin my-new-feature`)
61
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/lib/payment_3p.rb ADDED
@@ -0,0 +1,93 @@
1
+ require "payment_3p/version"
2
+ require "payment_3p/generators/config_generator"
3
+ require 'payment_3p/railtie' if defined?(Rails)
4
+
5
+ require 'yaml'
6
+
7
+ module Payment3p
8
+ # Your code goes here...
9
+ def self.gem_root
10
+ File.expand_path '../..', __FILE__
11
+ end
12
+
13
+ @config = HashWithIndifferentAccess.new(YAML.load_file(File.join(gem_root,'lib','payment_3p','generators','templates','payment_3p.yml')))
14
+
15
+ @valid_config_keys = @config.keys
16
+
17
+ # Configure through hash
18
+ def self.configure(opts = {})
19
+ opts.each {|k,v| @config[k] = v if @valid_config_keys.include? k}
20
+ end
21
+
22
+ # Configure through yaml file
23
+ def self.configure_with(path_to_yaml_file)
24
+ begin
25
+ config = HashWithIndifferentAccess.new(YAML::load(IO.read(path_to_yaml_file)))
26
+ rescue Errno::ENOENT
27
+ Rails.logger.warn("YAML configuration file couldn't be found. Using defaults."); return
28
+ rescue Psych::SyntaxError
29
+ Rails.logger.warn("YAML configuration file contains invalid syntax. Using defaults."); return
30
+ end
31
+
32
+ configure(config)
33
+ end
34
+
35
+ def self.config
36
+ @config
37
+ end
38
+
39
+
40
+ #vpc_MerchTxnRef, vpc_ReturnURL, vpc_OrderInfo, vpc_Amount
41
+ def self.payment_url parameters
42
+ vpcURL=@config[:payment_endpoint]
43
+
44
+ md5HashData = @config[:secure_secret]
45
+ vpc_parameters = {vpc_Version: "1", vpc_Command: "pay", vpc_AccessCode: @config[:vpc_AccessCode], vpc_MerchTxnRef: parameters[:vpc_MerchTxnRef], vpc_Merchant: @config[:vpc_Merchant], vpc_OrderInfo: parameters[:vpc_OrderInfo], vpc_Amount: parameters[:vpc_Amount], vpc_Locale: "en", vpc_ReturnURL: parameters[:vpc_ReturnURL]}
46
+
47
+ vpc_ordered_parameters = vpc_parameters.sort_by {|key, value| key} #returns array of arrays
48
+
49
+ url_params = []
50
+ vpc_ordered_parameters.each do |key, value|
51
+ if value.length > 0
52
+ url_params << Rack::Utils.escape(key)+"="+Rack::Utils.escape(value)
53
+ md5HashData += value
54
+ end
55
+ end
56
+ vpcURL += url_params.join("&")
57
+ if(@config[:secure_secret].length > 0)
58
+ vpcURL += "&vpc_SecureHash=" + Digest::MD5.hexdigest(md5HashData).upcase
59
+ end
60
+
61
+ vpcURL
62
+ end
63
+
64
+ #TODO: another validation needs to be added for the transaction number and amount
65
+
66
+ def self.validate_response response
67
+
68
+ #strip the input hash from other parameters than vpc_ parameters
69
+ vpc_response = response.reject{|key,value| !(key =~ /vpc_(.*)/) }
70
+
71
+ vpc_Txn_Secure_Hash = vpc_response.delete(:vpc_SecureHash)
72
+
73
+ if (@config[:secure_secret].length > 0 && vpc_response[:vpc_TxnResponseCode] != "7" && vpc_response[:vpc_TxnResponseCode] != "No Value Returned")
74
+ md5HashData = @config[:secure_secret]
75
+ vpc_response.each do |key, value|
76
+ if (key != "vpc_SecureHash" || value.length > 0)
77
+ md5HashData += value
78
+ end
79
+ end
80
+ if (vpc_Txn_Secure_Hash.upcase == Digest::MD5.hexdigest(md5HashData).upcase)
81
+ true
82
+ else
83
+ false
84
+ end
85
+
86
+ else
87
+ # No 'SECURE_SECRET' present.
88
+ false
89
+ end
90
+ end
91
+
92
+
93
+ end
@@ -0,0 +1,12 @@
1
+ require "rails/generators"
2
+ module Payment3p
3
+ module Generators
4
+ class ConfigGenerator < Rails::Generators::Base
5
+ source_root File.expand_path("../templates", __FILE__)
6
+
7
+ def copy_files
8
+ template "payment_3p.yml", "config/payment_3p.yml"
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,4 @@
1
+ secure_secret: ""
2
+ payment_endpoint: "https://migs.mastercard.com.au/vpcpay?"
3
+ vpc_AccessCode: ""
4
+ vpc_Merchant: ""
@@ -0,0 +1,8 @@
1
+ module Payment3p
2
+ class Railtie < Rails::Railtie
3
+ initializer "my_railtie.configure_rails_initialization" do
4
+ #initialization code (if more lines will be added move this code to a separate file)
5
+ Payment3p.configure_with("#{Rails.root}/config/payment_3p.yml")
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module Payment3p
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'payment_3p/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "payment_3p"
8
+ gem.version = Payment3p::VERSION
9
+ gem.authors = ["Eslam Foad"]
10
+ gem.email = ["eslam.foad@gmail.com"]
11
+ gem.description = "Provides 3-Party online payment with migs network initially"
12
+ gem.summary = "Provides 3-Party online payment"
13
+ gem.homepage = "https://github.com/rayasocialmedia/payment_3p"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: payment_3p
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Eslam Foad
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-02-04 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Provides 3-Party online payment with migs network initially
15
+ email:
16
+ - eslam.foad@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - lib/payment_3p.rb
27
+ - lib/payment_3p/generators/config_generator.rb
28
+ - lib/payment_3p/generators/templates/payment_3p.yml
29
+ - lib/payment_3p/railtie.rb
30
+ - lib/payment_3p/version.rb
31
+ - payment_3p.gemspec
32
+ homepage: https://github.com/rayasocialmedia/payment_3p
33
+ licenses: []
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubyforge_project:
52
+ rubygems_version: 1.8.11
53
+ signing_key:
54
+ specification_version: 3
55
+ summary: Provides 3-Party online payment
56
+ test_files: []
57
+ has_rdoc: