moneybookers 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +10 -0
- data/LICENSE +20 -0
- data/README.markdown +35 -0
- data/Rakefile +11 -0
- data/lib/moneybookers.rb +22 -0
- data/lib/moneybookers/api/pay_on_demand.rb +56 -0
- data/lib/moneybookers/payment_gateway/client.rb +20 -0
- data/lib/moneybookers/payment_gateway/response.rb +58 -0
- data/lib/moneybookers/request.rb +33 -0
- data/lib/moneybookers/signature/base.rb +21 -0
- data/lib/moneybookers/signature/secure_url.rb +7 -0
- data/lib/moneybookers/signature/status.rb +16 -0
- data/lib/moneybookers/version.rb +3 -0
- data/moneybookers.gemspec +23 -0
- data/test/config_test.rb +17 -0
- data/test/helper.rb +10 -0
- data/test/signature_test.rb +8 -0
- metadata +82 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Wojciech Wnętrzak
|
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/README.markdown
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Moneybookers #
|
2
|
+
Ruby client for [Moneybookers](http://moneybookers.com/) service.
|
3
|
+
|
4
|
+
Refer to Moneybookers documentation:
|
5
|
+
* [Automated Payment Interface](http://www.moneybookers.com/merchant/pl/automated_payments_interface_manual.pdf)
|
6
|
+
* [Payment Gateway](http://www.moneybookers.com/merchant/pl/moneybookers_gateway_manual.pdf)
|
7
|
+
|
8
|
+
## Configuration ##
|
9
|
+
|
10
|
+
``` ruby
|
11
|
+
require "moneybookers"
|
12
|
+
|
13
|
+
Moneybookers.configure do |config|
|
14
|
+
config.merchant_id = "merchant_id"
|
15
|
+
config.email = "john@doe.com"
|
16
|
+
config.secret_word_md5 = "md5-of-secret-word"
|
17
|
+
config.password = "md5-of-password"
|
18
|
+
config.pay_to_email = "joe@doe.com"
|
19
|
+
end
|
20
|
+
```
|
21
|
+
|
22
|
+
## Payment Gateway ##
|
23
|
+
|
24
|
+
## API ##
|
25
|
+
|
26
|
+
### Pay On Demand ##
|
27
|
+
|
28
|
+
## TODO: ##
|
29
|
+
* Support rest of API
|
30
|
+
* More tests
|
31
|
+
* Docs
|
32
|
+
|
33
|
+
## Copyright ##
|
34
|
+
|
35
|
+
Copyright © 2011 Wojciech Wnętrzak. See LICENSE for details.
|
data/Rakefile
ADDED
data/lib/moneybookers.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require "moneybookers/version"
|
2
|
+
require "moneybookers/request"
|
3
|
+
require "moneybookers/payment_gateway/client"
|
4
|
+
require "moneybookers/payment_gateway/response"
|
5
|
+
require "moneybookers/api/pay_on_demand"
|
6
|
+
require "moneybookers/signature/base"
|
7
|
+
require "moneybookers/signature/secure_url"
|
8
|
+
require "moneybookers/signature/status"
|
9
|
+
|
10
|
+
module Moneybookers
|
11
|
+
HOST = "https://www.moneybookers.com/"
|
12
|
+
SERVICE_IPS = %w{213.129.75.201 213.129.75.203 91.208.28.7 91.208.28.8 91.208.28.9 91.208.28.4 91.208.28.5 91.208.28.6
|
13
|
+
193.105.47.4 193.105.47.5 193.105.47.6 193.105.47.7 193.105.47.8 193.105.47.9}
|
14
|
+
|
15
|
+
class << self
|
16
|
+
attr_accessor :merchant_id, :email, :secret_word_md5, :password
|
17
|
+
|
18
|
+
def configure
|
19
|
+
yield self
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require "rexml/document"
|
2
|
+
|
3
|
+
module Moneybookers::API
|
4
|
+
class PayOnDemand
|
5
|
+
attr_reader :parameters, :prepare_response, :request_response, :session_id, :mb_transaction_id, :amount, :currency, :status, :status_code
|
6
|
+
|
7
|
+
def initialize(params={})
|
8
|
+
params[:password] ||= Moneybookers.password
|
9
|
+
params[:email] ||= Moneybookers.email
|
10
|
+
@parameters = params
|
11
|
+
end
|
12
|
+
|
13
|
+
def prepare
|
14
|
+
validate_prepare_parameters
|
15
|
+
@prepare_response = Moneybookers::Request.new.post("/app/ondemand_request.pl", parameters.merge({:action => "prepare"}))
|
16
|
+
handle_prepare_response
|
17
|
+
end
|
18
|
+
|
19
|
+
def request(params={})
|
20
|
+
params[:action] ||= "request"
|
21
|
+
params[:sid] ||= session_id || raise(ArgumentError.new("You must specify sid for pay-on-demand request transaction"))
|
22
|
+
@request_response = Moneybookers::Request.new.post("/app/ondemand_request.pl", params)
|
23
|
+
handle_request_response
|
24
|
+
end
|
25
|
+
|
26
|
+
# TODO: handle errors - moneybookers returns 200 with xml error_msg
|
27
|
+
def handle_prepare_response
|
28
|
+
document = REXML::Document.new(@prepare_response.body)
|
29
|
+
raise StandardError.new(document.elements["response/error/error_msg"].text) if document.elements["response/error"]
|
30
|
+
@session_id = document.elements["response/sid"].text
|
31
|
+
true
|
32
|
+
end
|
33
|
+
|
34
|
+
def handle_request_response
|
35
|
+
document = REXML::Document.new(@request_response.body)
|
36
|
+
raise StandardError.new(document.elements["response/error/error_msg"].text) if document.elements["response/error"]
|
37
|
+
document = document.elements["response/transaction"]
|
38
|
+
@mb_transaction_id = document.elements["id"].text
|
39
|
+
@amount = document.elements["amount"].text
|
40
|
+
@currency = document.elements["currency"].text
|
41
|
+
@status = document.elements["status_msg"].text
|
42
|
+
@status_code = document.elements["status"].text
|
43
|
+
true
|
44
|
+
end
|
45
|
+
|
46
|
+
def validate_prepare_parameters
|
47
|
+
[:email, :password, :amount, :currency].each do |attribute|
|
48
|
+
raise ArgumentError.new("You must specify #{attribute} for preparing pay-on-demand transaction") unless parameters[attribute]
|
49
|
+
end
|
50
|
+
if !parameters.has_key?(:rec_payment_id) and !parameters.has_key?(:frn_transaction_id)
|
51
|
+
raise ArgumentError.new("You must specify frn_transaction_id or rec_payment_id for preparing pay-on-demand transaction")
|
52
|
+
end
|
53
|
+
true
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "cgi"
|
2
|
+
|
3
|
+
module Moneybookers::PaymentGateway
|
4
|
+
class Client
|
5
|
+
attr_reader :response, :parameters
|
6
|
+
|
7
|
+
def initialize(params={})
|
8
|
+
@parameters = params
|
9
|
+
end
|
10
|
+
|
11
|
+
# TODO: validate required params
|
12
|
+
def prepare
|
13
|
+
@response = Moneybookers::Request.new.post("/app/payment.pl", {:prepare_only => 1}.merge(parameters))
|
14
|
+
end
|
15
|
+
|
16
|
+
def session_id
|
17
|
+
CGI::Cookie.parse(response["Set-Cookie"])["SESSION_ID"].first
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Moneybookers::PaymentGateway
|
2
|
+
class Response
|
3
|
+
attr_reader :params
|
4
|
+
|
5
|
+
def initialize(params)
|
6
|
+
raise ArgumentError.new("Params must be passed as a hash") unless params.kind_of?(Hash)
|
7
|
+
@params = params
|
8
|
+
end
|
9
|
+
|
10
|
+
def status_code
|
11
|
+
params["status"]
|
12
|
+
end
|
13
|
+
|
14
|
+
def status
|
15
|
+
case status_code
|
16
|
+
when "2" then "processed"
|
17
|
+
when "0" then "pending"
|
18
|
+
when "-1" then "cancelled"
|
19
|
+
when "-2" then "failed"
|
20
|
+
when "-3" then "chargeback"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def processed?
|
25
|
+
status == "processed"
|
26
|
+
end
|
27
|
+
|
28
|
+
def pay_on_demand_authorized?
|
29
|
+
processed? and (params["rec_payment_type"] == "on-demand")
|
30
|
+
end
|
31
|
+
|
32
|
+
def pay_on_demand_id
|
33
|
+
params["rec_payment_id"] if pay_on_demand_authorized?
|
34
|
+
end
|
35
|
+
|
36
|
+
def amount
|
37
|
+
params["mb_amount"]
|
38
|
+
end
|
39
|
+
|
40
|
+
def currency
|
41
|
+
params["mb_currency"]
|
42
|
+
end
|
43
|
+
|
44
|
+
def mb_transaction_id
|
45
|
+
params["mb_transaction_id"]
|
46
|
+
end
|
47
|
+
|
48
|
+
def signature_verified?(args={})
|
49
|
+
Moneybookers::Signature::Status.new(signature_params.merge(args)).match?(params["md5sig"])
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def signature_params
|
55
|
+
{:transaction_id => params["transaction_id"], :mb_amount => amount, :mb_currency => currency, :status => status_code}
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "net/http"
|
2
|
+
require "net/https"
|
3
|
+
require "uri"
|
4
|
+
|
5
|
+
module Moneybookers
|
6
|
+
class Request
|
7
|
+
attr_reader :response, :path
|
8
|
+
|
9
|
+
def http
|
10
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
11
|
+
http.use_ssl = true
|
12
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
13
|
+
http
|
14
|
+
end
|
15
|
+
|
16
|
+
def uri
|
17
|
+
@uri ||= URI.parse(Moneybookers::HOST)
|
18
|
+
end
|
19
|
+
|
20
|
+
def post(to, params={})
|
21
|
+
@path = URI.parse(to).path
|
22
|
+
@response = http.post(path, prepare_params(params), headers)
|
23
|
+
end
|
24
|
+
|
25
|
+
def prepare_params(params)
|
26
|
+
params.map { |k, v| "#{k}=#{v}" }.join("&")
|
27
|
+
end
|
28
|
+
|
29
|
+
def headers
|
30
|
+
{"User-Agent" => "ruby-moneybookers-gem"}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "digest/md5"
|
2
|
+
|
3
|
+
module Moneybookers::Signature
|
4
|
+
class Base
|
5
|
+
attr_accessor :merchant_id, :transaction_id, :secret_word_md5
|
6
|
+
|
7
|
+
def initialize(params={})
|
8
|
+
self.merchant_id = params.fetch(:merchant_id, Moneybookers.merchant_id) || raise(ArgumentError, "No merchant_id given")
|
9
|
+
self.secret_word_md5 = params.fetch(:secret_word_md5, Moneybookers.secret_word_md5) || raise(ArgumentError, "No secret_word_md5 given")
|
10
|
+
self.transaction_id = params[:transaction_id] || raise(ArgumentError, "No transaction_id given")
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_s
|
14
|
+
Digest::MD5.hexdigest(params.join).upcase
|
15
|
+
end
|
16
|
+
|
17
|
+
def match?(signature)
|
18
|
+
to_s == signature
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Moneybookers::Signature
|
2
|
+
class Status < Base
|
3
|
+
attr_accessor :mb_amount, :mb_currency, :status
|
4
|
+
|
5
|
+
def initialize(params={})
|
6
|
+
super
|
7
|
+
@mb_amount = params[:mb_amount] || raise(ArgumentError, "No mb_amount given")
|
8
|
+
@mb_currency = params[:mb_currency] || raise(ArgumentError, "No mb_currency given")
|
9
|
+
@status = params[:status] || raise(ArgumentError, "No status given")
|
10
|
+
end
|
11
|
+
|
12
|
+
def params
|
13
|
+
[merchant_id.to_s, transaction_id.to_s, secret_word_md5.upcase, mb_amount.to_s, mb_currency.to_s, status.to_s]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "moneybookers/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "moneybookers"
|
7
|
+
s.version = Moneybookers::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Wojciech Wnętrzak"]
|
10
|
+
s.email = ["w.wnetrzak@gmail.com"]
|
11
|
+
s.homepage = "https://github.com/morgoth/moneybookers"
|
12
|
+
s.summary = %q{Ruby client for Moneybookers}
|
13
|
+
s.description = %q{Ruby client for Moneybookers Automated Payment Interface and Payment Gateway}
|
14
|
+
|
15
|
+
s.rubyforge_project = "moneybookers"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_development_dependency("fakeweb")
|
23
|
+
end
|
data/test/config_test.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
describe "Configuration" do
|
4
|
+
it "should allow to set custom settings" do
|
5
|
+
Moneybookers.configure do |config|
|
6
|
+
config.merchant_id = "fake"
|
7
|
+
config.email = "john@doe.com"
|
8
|
+
config.secret_word_md5 = "md5"
|
9
|
+
config.password = "secretmd5"
|
10
|
+
end
|
11
|
+
|
12
|
+
assert_equal "fake", Moneybookers.merchant_id
|
13
|
+
assert_equal "john@doe.com", Moneybookers.email
|
14
|
+
assert_equal "md5", Moneybookers.secret_word_md5
|
15
|
+
assert_equal "secretmd5", Moneybookers.password
|
16
|
+
end
|
17
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
describe "Signature::SecureUrl" do
|
4
|
+
it "should be calculated" do
|
5
|
+
signature = Moneybookers::Signature::SecureUrl.new({:merchant_id => "20422434", :transaction_id => "s667", :secret_word_md5 => "FB834F96921EA0ACAAB7792BD9A46DD7"})
|
6
|
+
assert_equal "1E9B7834103B2DCAD524544622D41E91", signature.to_s
|
7
|
+
end
|
8
|
+
end
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: moneybookers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- "Wojciech Wn\xC4\x99trzak"
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-06-01 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: fakeweb
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
type: :development
|
25
|
+
version_requirements: *id001
|
26
|
+
description: Ruby client for Moneybookers Automated Payment Interface and Payment Gateway
|
27
|
+
email:
|
28
|
+
- w.wnetrzak@gmail.com
|
29
|
+
executables: []
|
30
|
+
|
31
|
+
extensions: []
|
32
|
+
|
33
|
+
extra_rdoc_files: []
|
34
|
+
|
35
|
+
files:
|
36
|
+
- .gitignore
|
37
|
+
- Gemfile
|
38
|
+
- LICENSE
|
39
|
+
- README.markdown
|
40
|
+
- Rakefile
|
41
|
+
- lib/moneybookers.rb
|
42
|
+
- lib/moneybookers/api/pay_on_demand.rb
|
43
|
+
- lib/moneybookers/payment_gateway/client.rb
|
44
|
+
- lib/moneybookers/payment_gateway/response.rb
|
45
|
+
- lib/moneybookers/request.rb
|
46
|
+
- lib/moneybookers/signature/base.rb
|
47
|
+
- lib/moneybookers/signature/secure_url.rb
|
48
|
+
- lib/moneybookers/signature/status.rb
|
49
|
+
- lib/moneybookers/version.rb
|
50
|
+
- moneybookers.gemspec
|
51
|
+
- test/config_test.rb
|
52
|
+
- test/helper.rb
|
53
|
+
- test/signature_test.rb
|
54
|
+
homepage: https://github.com/morgoth/moneybookers
|
55
|
+
licenses: []
|
56
|
+
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "0"
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: "0"
|
74
|
+
requirements: []
|
75
|
+
|
76
|
+
rubyforge_project: moneybookers
|
77
|
+
rubygems_version: 1.8.4
|
78
|
+
signing_key:
|
79
|
+
specification_version: 3
|
80
|
+
summary: Ruby client for Moneybookers
|
81
|
+
test_files: []
|
82
|
+
|