payhyper 0.1.1 → 0.2.0
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.
- checksums.yaml +15 -0
- data/lib/payhyper/version.rb +1 -1
- data/lib/payhyper.rb +28 -10
- metadata +4 -10
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YTJkOTg5N2Q0ZTMwNjI5ZmE0MmM2OGIyNmNlMzg5ZTQ0N2NlZTE4Mg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NjNkODQwYmQ4MGM2NjY0Y2ZkNjI1YzRlOGU1MWVmMjMxZTc0N2VlYw==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NWRjNDE5ZDA3ZjBiZDlmODJkNzU1ZWUzZjhhZDVkYTUwZjE4NDBkZWIwNTM3
|
10
|
+
NTU3MWNjYWY5ZjVmYjFhMjNjODZjNDE3MzlkNmM3NGQ0MDA4YzEwZGJkZjdi
|
11
|
+
ZWYyNGI1ZmU5YjU1OTdhMDk4NzY1MmI5ZmRkZmU0Zjc4NGNiMzQ=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ODhhYjAwYWM4ZGMzZGQ4YzE2ZDE3NTdhZjNhYjgzNGYwNjQwZTM1NzU0ZTgx
|
14
|
+
ZjIyMWQyYzJjMjVhZTI5YzVkZmNlZGEzMmE1YTg2ZTZiZDFjMDBmYmEzNGI4
|
15
|
+
NDc3YjUyZGExYjkxOWM0ZTYxMzQwOWZlMTI0ZmRlODRmM2MwZDc=
|
data/lib/payhyper/version.rb
CHANGED
data/lib/payhyper.rb
CHANGED
@@ -13,15 +13,21 @@ module PayHyper
|
|
13
13
|
unless defined?(DEBUG)
|
14
14
|
BASE_URLS = {
|
15
15
|
:live => "http://api.payhyper.com",
|
16
|
-
:sandbox => "http://api.
|
16
|
+
:sandbox => "http://sandbox-api.payhyper.com",
|
17
17
|
}
|
18
18
|
else
|
19
19
|
BASE_URLS = {
|
20
20
|
:live => "http://api.local.local:3000",
|
21
|
-
:sandbox => "http://api.
|
21
|
+
:sandbox => "http://sandbox-api.local.local:3001",
|
22
22
|
}
|
23
23
|
end
|
24
24
|
|
25
|
+
CURRENCIES = %w{JOD USD BHD GBP EGP KWD OMR QAR SAR TRY AED}
|
26
|
+
COUNTRY_CODES = {
|
27
|
+
"JO" => "962",
|
28
|
+
}
|
29
|
+
COUNTRIES = COUNTRY_CODES.keys
|
30
|
+
|
25
31
|
def self.setup(access_key_id, access_key_secret, mode)
|
26
32
|
raise PayHyperError, "Mode must be one of #{BASE_URLS.keys.map { |k| k.inspect }.join(" or ")}" unless BASE_URLS.keys.include?(mode)
|
27
33
|
@access_key_id = access_key_id
|
@@ -33,15 +39,28 @@ module PayHyper
|
|
33
39
|
raise PayHyperError, "Must call setup() first" if @access_key_id.nil? || @access_key_secret.nil? || @base_url.nil?
|
34
40
|
end
|
35
41
|
|
36
|
-
def self.create_order!(
|
42
|
+
def self.create_order!(service, country, amount, currency, phone, email, tag = nil)
|
37
43
|
raise_if_not_setup!
|
44
|
+
# == Clean-up fields ==
|
45
|
+
service = service.to_s.gsub("_", "-") if [:at_door, :in_store].include?(service)
|
46
|
+
currency = currency.upcase if currency && currency.is_a?(String)
|
47
|
+
country = country.upcase if country && country.is_a?(String)
|
48
|
+
if phone && phone.is_a?(String)
|
49
|
+
phone = phone(/[^0-9]/, "") # Remove non-numeric characters.
|
50
|
+
phone = phone.gsub(/^0*/, "") # Remove leading zeros.
|
51
|
+
if country && COUNTRY_CODES[country] && !phone.start_with?(COUNTRY_CODES[country])
|
52
|
+
phone = COUNTRY_CODES[country] + phone # Add country code.
|
53
|
+
end
|
54
|
+
end
|
38
55
|
# == Validate ==
|
39
|
-
raise ValidationError, "Incorrect
|
40
|
-
raise ValidationError, "
|
41
|
-
raise ValidationError, "Incorrect
|
42
|
-
raise ValidationError, "
|
56
|
+
raise ValidationError, "Incorrect service specified." unless ["at-door", "in-store"].include?(service)
|
57
|
+
raise ValidationError, "Country specified is incorrect or not supported." unless COUNTRIES.include?(country)
|
58
|
+
raise ValidationError, "Incorrect amount, must be positive." if amount.to_i <= 0
|
59
|
+
raise ValidationError, "Currency is incorrect or not supported." unless CURRENCIES.include?(currency)
|
60
|
+
raise ValidationError, "Incorrect phone, or not in a supported country." if phone.nil? || !phone.match(/\A\+962[0-9]{8,9}\z/)
|
61
|
+
raise ValidationError, "Invalid email." if email.nil? || !email.match(/\A[^@\s]+@([^@\s]+\.)+[^@\s]+\z/)
|
43
62
|
# == Do the request ==
|
44
|
-
body = JSON.dump({ :
|
63
|
+
body = JSON.dump({ :service => service, :country => country, :amount => amount, :currency => currency, :phone => phone, :email => email, :tag => tag })
|
45
64
|
failure = "Unknown error"
|
46
65
|
begin
|
47
66
|
uri = URI.parse(@base_url + "/v1/orders")
|
@@ -88,7 +107,7 @@ module PayHyper
|
|
88
107
|
request.env["rack.input"].rewind # In case someone forgot to rewind the input.
|
89
108
|
body = request.env["rack.input"].read
|
90
109
|
request.env["rack.input"].rewind # Be nice to others.
|
91
|
-
canonical_request_representation = [request.env["REQUEST_METHOD"], request.env["HTTP_HOST"], request.env["PATH_INFO"], request.env["CONTENT_TYPE"], body].join("\n")
|
110
|
+
canonical_request_representation = [request.env["REQUEST_METHOD"], request.env["HTTP_HOST"], request.env["PATH_INFO"], request.env["CONTENT_TYPE"], body].join("\n") # TODO: security bug if the webserver doesn't check host headers.
|
92
111
|
correct_signature = Security.sign(@access_key_secret, canonical_request_representation)
|
93
112
|
return Security.secure_compare(correct_signature, input_signature)
|
94
113
|
end
|
@@ -106,7 +125,6 @@ module PayHyper
|
|
106
125
|
end
|
107
126
|
|
108
127
|
class PayHyperError < StandardError; end
|
109
|
-
class AuthenticationError < PayHyperError; end
|
110
128
|
class ValidationError < PayHyperError; end
|
111
129
|
class CommunicationError < PayHyperError; end
|
112
130
|
end
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: payhyper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Sinan Taifour
|
@@ -14,7 +13,6 @@ dependencies:
|
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rest-client
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ~>
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ~>
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -30,7 +27,6 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: multi_json
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
31
|
- - ! '>='
|
36
32
|
- !ruby/object:Gem::Version
|
@@ -41,7 +37,6 @@ dependencies:
|
|
41
37
|
type: :runtime
|
42
38
|
prerelease: false
|
43
39
|
version_requirements: !ruby/object:Gem::Requirement
|
44
|
-
none: false
|
45
40
|
requirements:
|
46
41
|
- - ! '>='
|
47
42
|
- !ruby/object:Gem::Version
|
@@ -63,26 +58,25 @@ files:
|
|
63
58
|
- payhyper.gemspec
|
64
59
|
homepage: http://payhyper.com
|
65
60
|
licenses: []
|
61
|
+
metadata: {}
|
66
62
|
post_install_message:
|
67
63
|
rdoc_options: []
|
68
64
|
require_paths:
|
69
65
|
- lib
|
70
66
|
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
-
none: false
|
72
67
|
requirements:
|
73
68
|
- - ! '>='
|
74
69
|
- !ruby/object:Gem::Version
|
75
70
|
version: '0'
|
76
71
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
-
none: false
|
78
72
|
requirements:
|
79
73
|
- - ! '>='
|
80
74
|
- !ruby/object:Gem::Version
|
81
75
|
version: '0'
|
82
76
|
requirements: []
|
83
77
|
rubyforge_project:
|
84
|
-
rubygems_version:
|
78
|
+
rubygems_version: 2.0.7
|
85
79
|
signing_key:
|
86
|
-
specification_version:
|
80
|
+
specification_version: 4
|
87
81
|
summary: The Ruby bindings of the Hyper API
|
88
82
|
test_files: []
|