dragon_pay 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +32 -0
- data/lib/dragon_pay/client.rb +87 -0
- data/lib/dragon_pay/configuration.rb +16 -0
- data/lib/dragon_pay/currency_code.rb +17 -0
- data/lib/dragon_pay/version.rb +3 -0
- data/lib/dragon_pay.rb +19 -0
- data/lib/tasks/dragon_pay_tasks.rake +4 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b1c7ef088c2759a43df50eb3329bf37df571234f
|
4
|
+
data.tar.gz: 6a78ff3787249d7b4d7b58af1b46da0b738d1115
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1b76ebd161d9a7bf04df24d7ec396dc758a18655ae11282336b2d1f85283f18272f795a0763bc995e641ba90fae80d5510f06d802e425cf0a6a301ae9642851c
|
7
|
+
data.tar.gz: 27560eca9b699a035d15eff4ad39cae5ec771c9172b3f739a53e963a3f4d9a299a215bb3831f8fe2d79fb6e1ddae2776f407c7dce5dfd09e3cb28c71f47f7ed7
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2013 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'DragonPay'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
Bundler::GemHelper.install_tasks
|
21
|
+
|
22
|
+
require 'rake/testtask'
|
23
|
+
|
24
|
+
Rake::TestTask.new(:test) do |t|
|
25
|
+
t.libs << 'lib'
|
26
|
+
t.libs << 'test'
|
27
|
+
t.pattern = 'test/**/*_test.rb'
|
28
|
+
t.verbose = false
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
task default: :test
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'digest/sha1'
|
2
|
+
|
3
|
+
class DragonPay::Client
|
4
|
+
|
5
|
+
# attributes that can be given default value
|
6
|
+
attr_accessor :merchant_id, :secret_key, :currency, :digest, :param1, :param2
|
7
|
+
|
8
|
+
# attributes that can be generated from other attributes
|
9
|
+
attr_accessor :payment_description
|
10
|
+
|
11
|
+
# attributes that are required
|
12
|
+
attr_accessor :transaction_id, :amount, :customer_email_address
|
13
|
+
|
14
|
+
def initialize(options)
|
15
|
+
self.transaction_id = options[:transaction_id]
|
16
|
+
self.amount = options[:amount]
|
17
|
+
self.customer_email_address = options[:customer_email_address]
|
18
|
+
fill_in_defaults(options)
|
19
|
+
end
|
20
|
+
|
21
|
+
def generate_request_url
|
22
|
+
%Q{
|
23
|
+
#{payment_switch_url}?
|
24
|
+
merchantid = #{merchant_id}&
|
25
|
+
txnid = #{transaction_id}&
|
26
|
+
amount = #{amount}&
|
27
|
+
ccy = #{currency}&
|
28
|
+
description = #{uri_encode(payment_description)}&
|
29
|
+
email = #{uri_encode(customer_email_address)}&
|
30
|
+
digest = #{digest}&
|
31
|
+
param1 = #{param1}&
|
32
|
+
param2 = #{param2}
|
33
|
+
}.split.join
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def payment_switch_url
|
41
|
+
"#{DragonPay.configuration.payment_switch_domain}/Pay.aspx"
|
42
|
+
end
|
43
|
+
|
44
|
+
# fields that can be assigned default values
|
45
|
+
def fill_in_defaults(options)
|
46
|
+
self.merchant_id = options[:merchant_id] || DragonPay.configuration.merchant_id
|
47
|
+
self.secret_key = options[:secret_key] || DragonPay.configuration.secret_key
|
48
|
+
self.currency = options[:currency] || DragonPay.configuration.currency
|
49
|
+
self.param1 = options[:param1] || ''
|
50
|
+
self.param2 = options[:param2] || ''
|
51
|
+
|
52
|
+
description = generate_payment_description unless options[:payment_description]
|
53
|
+
self.payment_description = uri_encode(description)
|
54
|
+
end
|
55
|
+
|
56
|
+
# generates description based on param values
|
57
|
+
def generate_payment_description
|
58
|
+
"Payment of #{currency}#{amount} from buyer #{customer_email_address} to merchant #{merchant_id}"
|
59
|
+
end
|
60
|
+
|
61
|
+
# calculates the sha1 digest of all the parameters
|
62
|
+
def digest
|
63
|
+
Digest::SHA1.hexdigest(digestable_parameters)
|
64
|
+
end
|
65
|
+
|
66
|
+
# combines all the parameters into 1 so that it can be SHA1 digested
|
67
|
+
def digestable_parameters
|
68
|
+
%Q{
|
69
|
+
#{merchant_id}:
|
70
|
+
#{transaction_id}:
|
71
|
+
#{amount}:
|
72
|
+
#{currency}:
|
73
|
+
#{payment_description}:
|
74
|
+
#{customer_email_address}:
|
75
|
+
#{secret_key}
|
76
|
+
}.split.join
|
77
|
+
end
|
78
|
+
|
79
|
+
def amount
|
80
|
+
"%.2f" % @amount
|
81
|
+
end
|
82
|
+
|
83
|
+
def uri_encode(string)
|
84
|
+
CGI::escape(string)
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class DragonPay::Configuration
|
2
|
+
|
3
|
+
attr_accessor :test_mode, :merchant_id, :secret_key, :currency
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@test_mode = true
|
7
|
+
@merchant_id = 'APPSOURCE'
|
8
|
+
@secret_key = 'Jy$mV8qL'
|
9
|
+
@currency = 'PHP'
|
10
|
+
end
|
11
|
+
|
12
|
+
def payment_switch_domain
|
13
|
+
test_mode ? 'http://test.dragonpay.ph' : 'https://secure.dragonpay.ph'
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
data/lib/dragon_pay.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module DragonPay
|
2
|
+
|
3
|
+
autoload :Configuration, 'dragon_pay/configuration'
|
4
|
+
autoload :CurrencyCode, 'dragon_pay/currency_code'
|
5
|
+
autoload :Client, 'dragon_pay/client'
|
6
|
+
|
7
|
+
class << self
|
8
|
+
attr_accessor :configuration
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.configuration
|
12
|
+
@configuration ||= Configuration.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.configure
|
16
|
+
yield(configuration)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dragon_pay
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Reynan Albaredo
|
8
|
+
- Kenneth Lindsey Calamay
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-11-29 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ~>
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 4.0.1
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 4.0.1
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: sqlite3
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rspec-rails
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
description: ''
|
57
|
+
email:
|
58
|
+
- ralbaredo@appsource.biz
|
59
|
+
- rubygems@kennethcalamay.com
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- lib/dragon_pay/client.rb
|
65
|
+
- lib/dragon_pay/configuration.rb
|
66
|
+
- lib/dragon_pay/currency_code.rb
|
67
|
+
- lib/dragon_pay/version.rb
|
68
|
+
- lib/dragon_pay.rb
|
69
|
+
- lib/tasks/dragon_pay_tasks.rake
|
70
|
+
- MIT-LICENSE
|
71
|
+
- Rakefile
|
72
|
+
homepage: https://github.com/kennethcalamay/dragon_pay
|
73
|
+
licenses:
|
74
|
+
- MIT License
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.1.11
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: Ruby wrapper for DragonPay's API
|
96
|
+
test_files: []
|