liberty_reserve_payments 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,19 @@
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
18
+ .idea/
19
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in liberty_reserve_payments.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Patricio Cano
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,82 @@
1
+ # LibertyReservePayments
2
+
3
+ Receive payments via Liberty Reserve. With this gem the user of your shop
4
+ can pay for a digital item (or any type of item) and validate the transaction
5
+ after it was made.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'liberty_reserve_payments'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install liberty_reserve_payments
20
+
21
+ ## Usage
22
+
23
+ After the installation, you still need two files for the gem to work. A Yaml config file and an initializer.
24
+
25
+ ### config/liberty.yml
26
+ ```yaml
27
+ development:
28
+ account_number: U1234567
29
+ store_name: SampleStore
30
+ security_word: test1234
31
+
32
+ production:
33
+ account_number: U1234567
34
+ store_name: SampleStore
35
+ security_word: test1234
36
+ ```
37
+
38
+ ### config/initializers/liberty.rb
39
+ ```ruby
40
+ require 'liberty_reserve_payments/handler'
41
+
42
+ LIBERTY_CONFIG = YAML.load_file("#{Rails.root}/config/liberty.yml")[Rails.env].symbolize_keys
43
+ ```
44
+
45
+ After creating these files you still need to add the methods provided by this gem to your PaymentsController.
46
+ To do this you can add the following template methods to you file:
47
+
48
+ ```ruby
49
+ def pay_item_with_lr
50
+ handler = LibertyReservePayments::Handler.new LIBERTY_CONFIG
51
+ @item = Item.find(params[:id])
52
+ # The payment_request_uri takes the following arguments:
53
+ # amount, currency = 'LRUSD', comments = '', order_id = '', item_name = ''
54
+ # item_name and order_id are baggage fields that should aid you on the validation of the transaction
55
+ # The method will generate a URL containing the parameters for the payment and redirect to the
56
+ # Liberty Reserve website
57
+ redirect_to handler.payment_request_uri(amount: @item.amount, order_id: '1', comment: 'Test Liberty')
58
+ end
59
+ ```
60
+ You should also add a route for Liberty Reserve to send the status of the transactions. It can point to a method
61
+ looking like this:
62
+
63
+ ```ruby
64
+ def validate_payment
65
+ handler = LibertyReservePayments::Handler.new LIBERTY_CONFIG
66
+ if handler.valid?(params)
67
+ # The transaction has been validated. You can perform your own
68
+ # validations now
69
+ else
70
+ # The transaction has been tampered with, you should log it for
71
+ # later verification.
72
+ end
73
+ end
74
+ ```
75
+
76
+ ## Contributing
77
+
78
+ 1. Fork it
79
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
80
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
81
+ 4. Push to the branch (`git push origin my-new-feature`)
82
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,9 @@
1
+ require 'attr_required'
2
+ require 'attr_optional'
3
+ require 'liberty_reserve_payments/version'
4
+ require 'liberty_reserve_payments/base'
5
+ require 'liberty_reserve_payments/handler'
6
+
7
+ module LibertyReservePayments
8
+
9
+ end
@@ -0,0 +1,14 @@
1
+ module LibertyReservePayments
2
+ class Base
3
+ include AttrRequired, AttrOptional
4
+ def initialize(attributes = {})
5
+ if attributes.is_a?(Hash)
6
+ (required_attributes + optional_attributes).each do |key|
7
+ value = attributes[key]
8
+ self.send "#{key}=", value
9
+ end
10
+ end
11
+ attr_missing!
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,33 @@
1
+ require 'digest'
2
+ module LibertyReservePayments
3
+ class Handler < Base
4
+ attr_required :account_number, :store_name, :security_word
5
+
6
+ ENDPOINT = 'https://sci.libertyreserve.com'
7
+
8
+ def initialize(attributes = {})
9
+ super
10
+ end
11
+
12
+ def payment_request_uri(amount, currency = 'LRUSD', comments = '', order_id = '', item_name = '')
13
+ endpoint = URI.parse ENDPOINT
14
+ @query = {lr_acc: self.account_number, lr_store: self.store_name, lr_amnt: amount,
15
+ lr_currency: currency, lr_comments: comments, lr_merchant_ref: "OID_#{order_id}",
16
+ item_name: item_name, order_id: order_id}
17
+ endpoint.query = @query.to_query
18
+ endpoint.to_s
19
+ end
20
+
21
+ def valid?(params)
22
+ sha256 = Digest::SHA256.new
23
+ str = "#{params[:lr_paidto]}:#{params[:lr_paidby]}:#{params[:lr_store].gsub(/\\\//, '')}:#{params[:lr_amnt]}:#{params[:lr_transfer]}:#{params[:lr_currency]}:#{self.security_word}"
24
+ first_hash = sha256.digest(str)
25
+ second_hash = first_hash.unpack('H*').first.upcase
26
+ if params[:lr_encrypted] == second_hash and params[:lr_paidto] == self.account_number
27
+ true
28
+ else
29
+ false
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module LibertyReservePayments
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'liberty_reserve_payments/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = 'liberty_reserve_payments'
8
+ gem.version = LibertyReservePayments::VERSION
9
+ gem.authors = ['Patricio Cano']
10
+ gem.email = %w(suprnova32@gmail.com)
11
+ gem.description = %q{Accept payments from Liberty Reserve}
12
+ gem.summary = %q{You can accept payments from Liberty Reserve and have them validated, so you can activate
13
+ digital items immediately.}
14
+ gem.homepage = 'http://github.com/FreedomVPN/liberty_reserve_payments'
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+ gem.add_development_dependency 'rspec-rails'
21
+ gem.add_development_dependency 'rspec', '>= 2'
22
+ gem.add_dependency 'rails', '>= 3.2.12'
23
+ gem.add_dependency 'haml-rails'
24
+ gem.add_dependency 'attr_required', '>= 0.0.5'
25
+ end
@@ -0,0 +1,7 @@
1
+ require '../spec_helper'
2
+
3
+ describe LibertyReservePayments::Handler do
4
+ describe '.payment_request_uri' do
5
+
6
+ end
7
+ end
@@ -0,0 +1,2 @@
1
+ require 'rspec'
2
+ require 'liberty_reserve_payments'
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: liberty_reserve_payments
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Patricio Cano
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec-rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '2'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '2'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rails
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 3.2.12
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 3.2.12
62
+ - !ruby/object:Gem::Dependency
63
+ name: haml-rails
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: attr_required
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: 0.0.5
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: 0.0.5
94
+ description: Accept payments from Liberty Reserve
95
+ email:
96
+ - suprnova32@gmail.com
97
+ executables: []
98
+ extensions: []
99
+ extra_rdoc_files: []
100
+ files:
101
+ - .gitignore
102
+ - Gemfile
103
+ - LICENSE.txt
104
+ - README.md
105
+ - Rakefile
106
+ - lib/liberty_reserve_payments.rb
107
+ - lib/liberty_reserve_payments/base.rb
108
+ - lib/liberty_reserve_payments/handler.rb
109
+ - lib/liberty_reserve_payments/version.rb
110
+ - liberty_reserve_payments.gemspec
111
+ - spec/liberty_reserve_payments/handler_spec.rb
112
+ - spec/spec_helper.rb
113
+ homepage: http://github.com/FreedomVPN/liberty_reserve_payments
114
+ licenses: []
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ none: false
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ none: false
127
+ requirements:
128
+ - - ! '>='
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ requirements: []
132
+ rubyforge_project:
133
+ rubygems_version: 1.8.25
134
+ signing_key:
135
+ specification_version: 3
136
+ summary: You can accept payments from Liberty Reserve and have them validated, so
137
+ you can activate digital items immediately.
138
+ test_files:
139
+ - spec/liberty_reserve_payments/handler_spec.rb
140
+ - spec/spec_helper.rb
141
+ has_rdoc: