satispay 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +69 -0
  3. data/lib/satispay.rb +110 -0
  4. metadata +88 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 78b49774ee1e0462c47bc2c06c86d00e9ff9dfa1
4
+ data.tar.gz: 4f8fc32a045608b3c8500da03a4c7f6e02f14fa6
5
+ SHA512:
6
+ metadata.gz: 326b8379d35a9ca500b54cb583f56d6c91ab5eeaa169d5e1409f8c5775988da6d5d13afce796e7aefb0b189b69d9ad380498763da77425acb56ad408df9447ba
7
+ data.tar.gz: f5d8f3f5d55e6a46664bdbca7e010e4da51450b5d7b4db183729a5ded4e7684afdee20f43dba3b7abf2ca9b0b4d79d0da7a57ee61b36224270e1e638578010ae
@@ -0,0 +1,69 @@
1
+ # Satispay Ruby API
2
+
3
+ ## Usage
4
+
5
+ To use the API you need to initialize a new instance
6
+
7
+ ```ruby
8
+ satispay = Satispay.new(env, security_bearer)
9
+
10
+ # NB: env sholud be 'prod' or 'staging'
11
+ ```
12
+
13
+ ### Check bearer
14
+
15
+ Allow application to check if bearer is valid.
16
+
17
+ ```ruby
18
+ response = satispay.check_bearer
19
+ ```
20
+
21
+ ### Get all users
22
+
23
+ ```ruby
24
+ response = satispay.all_users(*extra_params)
25
+ ```
26
+
27
+ ### Create new user
28
+
29
+ ```ruby
30
+ response = satispay.create_user(phone_number: user_phone_number, *extra_params)
31
+ ```
32
+
33
+ ### Get user
34
+
35
+ ```ruby
36
+ response = satispay.get_user(user_id: user_satispay_id)
37
+ ```
38
+
39
+ ### Get all chanrges
40
+
41
+ ```ruby
42
+ response = satispay.all_charges(*extra_params)
43
+ ```
44
+
45
+ ### Create new charges
46
+
47
+ ```ruby
48
+ response = satispay.create_charge(user_id: user_id, currency: 'EUR', amount: 100, *extra_params)
49
+ ```
50
+
51
+ ### Get charge
52
+
53
+ ```ruby
54
+ response = satispay.get_charge(charge_id: charge_id)
55
+ ```
56
+
57
+ ### Update charge
58
+
59
+
60
+ ```ruby
61
+ response = satispay.update_charge(charge_id: charge_id, *extra_params)
62
+ ```
63
+
64
+ ### Get all refunds
65
+
66
+ ```ruby
67
+ response = satispay.all_refunds(*extra_params)
68
+ ```
69
+
@@ -0,0 +1,110 @@
1
+ require 'rest-client'
2
+ require 'json'
3
+
4
+ class Satispay
5
+
6
+ def initialize(env, security_bearer)
7
+ @env = (env == 'prod' ? :production : :staging)
8
+ @url = (env == 'prod' ? 'https://authservices.satispay.com' : 'https://staging.authservices.satispay.com')
9
+ @security_bearer = security_bearer
10
+ end
11
+
12
+ # Bearer requests:
13
+
14
+ def check_bearer
15
+ send_request('/wally-services/protocol/authenticated', :get, {})
16
+ end
17
+
18
+ # User requests:
19
+
20
+ def all_users
21
+ send_request('/online/v1/users', :get, {})
22
+ end
23
+
24
+ def create_user(args)
25
+ args = validate_args(args, [:phone_number])
26
+ send_request('/online/v1/users', :post, args)
27
+ end
28
+
29
+ def get_user(args)
30
+ args = validate_args(args, [:user_id])
31
+ send_request("/online/v1/users/#{args[:user_id]}", :get, {})
32
+ end
33
+
34
+ # Charge requests:
35
+
36
+ def all_charges
37
+ send_request('/online/v1/charges', :get, {})
38
+ end
39
+
40
+ def create_charge(args)
41
+ args = validate_args(args, [:user_id, :currency, :amount])
42
+ send_request('/online/v1/charges', :post, args)
43
+ end
44
+
45
+ def get_charge(args)
46
+ args = validate_args(args, [:charge_id])
47
+ send_request("/online/v1/charges/#{args[:charge_id]}", :get, {})
48
+ end
49
+
50
+ def update_charge(args)
51
+ args = validate_args(args, [:charge_id])
52
+ send_request("/online/v1/charges/#{args[:charge_id]}", :put, args)
53
+ end
54
+
55
+ # Refund requests:
56
+
57
+ def all_refunds
58
+ send_request('/online/v1/refunds', :get, {})
59
+ end
60
+
61
+ private
62
+
63
+ # This function send a request to a specific url and return the response or
64
+ # the error.
65
+ def send_request(path, method, body)
66
+ url = "#{@url}#{path}"
67
+ response = (method == :get ? send_get_request(url) : send_post_request(url, body, method))
68
+ JSON.parse(response.body) if response.body && !response.body.empty?
69
+ rescue RestClient::ExceptionWithResponse => e
70
+ error = JSON.parse(e.response)
71
+ raise e.response
72
+ end
73
+
74
+ # This function send a GET request.
75
+ def send_get_request(url)
76
+ response = RestClient::Request.execute(
77
+ method: :get,
78
+ url: url,
79
+ verify_ssl: false,
80
+ headers: {
81
+ 'Content-Type' => 'application/json',
82
+ 'Authorization' => "Bearer #{@security_bearer}"
83
+ }
84
+ )
85
+ end
86
+
87
+ # This function send a POST request.
88
+ def send_post_request(url, body, method)
89
+ response = RestClient::Request.execute(
90
+ method: method,
91
+ url: url,
92
+ verify_ssl: false,
93
+ headers: {
94
+ 'Content-Type' => 'application/json',
95
+ 'Authorization' => "Bearer #{@security_bearer}"
96
+ },
97
+ payload: body.to_json
98
+ )
99
+ end
100
+
101
+ # This function validates an hash of arguments and raise an error if required
102
+ # arguments are not present.
103
+ def validate_args(args, required)
104
+ required.each do |required_arg|
105
+ raise 'Missing required argument' if args[required_arg] == nil
106
+ end
107
+ args
108
+ end
109
+
110
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: satispay
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ideonetwork
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-08-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Unofficial Satispay API for Ruby (porting from https://github.com/satispay/online-api-php-sdk)
56
+ email:
57
+ - info@ideonetwork.it
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - README.md
63
+ - lib/satispay.rb
64
+ homepage: http://naturaldesign.cc/
65
+ licenses:
66
+ - MIT
67
+ metadata: {}
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubyforge_project:
84
+ rubygems_version: 2.6.12
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: Unofficial Satispay API for Ruby
88
+ test_files: []