payhyper 0.1.0 → 0.1.1
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.
- data/lib/payhyper/version.rb +1 -1
- data/lib/payhyper.rb +14 -6
- data/payhyper.gemspec +1 -1
- metadata +2 -2
data/lib/payhyper/version.rb
CHANGED
data/lib/payhyper.rb
CHANGED
@@ -10,10 +10,17 @@ require 'payhyper/security'
|
|
10
10
|
|
11
11
|
module PayHyper
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
unless defined?(DEBUG)
|
14
|
+
BASE_URLS = {
|
15
|
+
:live => "http://api.payhyper.com",
|
16
|
+
:sandbox => "http://api.sandbox.payhyper.com",
|
17
|
+
}
|
18
|
+
else
|
19
|
+
BASE_URLS = {
|
20
|
+
:live => "http://api.local.local:3000",
|
21
|
+
:sandbox => "http://api.sandbox.local.local:3001",
|
22
|
+
}
|
23
|
+
end
|
17
24
|
|
18
25
|
def self.setup(access_key_id, access_key_secret, mode)
|
19
26
|
raise PayHyperError, "Mode must be one of #{BASE_URLS.keys.map { |k| k.inspect }.join(" or ")}" unless BASE_URLS.keys.include?(mode)
|
@@ -30,10 +37,11 @@ module PayHyper
|
|
30
37
|
raise_if_not_setup!
|
31
38
|
# == Validate ==
|
32
39
|
raise ValidationError, "Incorrect amount." if params[:amount].to_i <= 0
|
40
|
+
raise ValidationError, "Incorrect currency." unless %w{JOD USD BHD GBP EGP KWD QMR QAR SAR TRY AED}.include?(params[:currency].upcase)
|
33
41
|
raise ValidationError, "Incorrect email." if params[:email].nil? || !params[:email].match(/\A[^@\s]+@([^@\s]+\.)+[^@\s]+\z/)
|
34
42
|
raise ValidationError, "Incorrect phone." if params[:phone].nil? || !params[:phone].match(/\A\+962[0-9]{8,9}\z/)
|
35
43
|
# == Do the request ==
|
36
|
-
body = JSON.dump({ :email => params[:email], :phone => params[:phone], :amount => params[:amount] })
|
44
|
+
body = JSON.dump({ :email => params[:email], :phone => params[:phone], :amount => params[:amount], :currency => params[:currency] })
|
37
45
|
failure = "Unknown error"
|
38
46
|
begin
|
39
47
|
uri = URI.parse(@base_url + "/v1/orders")
|
@@ -45,7 +53,7 @@ module PayHyper
|
|
45
53
|
if e.http_code && e.http_code.to_i == 422 && e.http_body
|
46
54
|
raise ValidationError, JSON.load(e.http_body)["error"]
|
47
55
|
else
|
48
|
-
failure = "Remote returned HTTP status code #{e.http_code}"
|
56
|
+
failure = "Remote returned HTTP status code #{e.http_code} (#{e.http_body})"
|
49
57
|
end
|
50
58
|
rescue SocketError => e
|
51
59
|
if e.message.match(/getaddrinfo: (.*?)/)
|
data/payhyper.gemspec
CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
|
|
6
6
|
|
7
7
|
s.name = 'payhyper'
|
8
8
|
s.version = PayHyper::VERSION
|
9
|
-
s.date = '2013-
|
9
|
+
s.date = '2013-08-07'
|
10
10
|
s.summary = 'The Ruby bindings of the Hyper API'
|
11
11
|
s.description = 'Hyper is an API for cash collection. See http://payhyper.com for more.'
|
12
12
|
s.authors = ["Sinan Taifour"]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: payhyper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-08-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|