promisepay 0.0.3 → 0.0.4

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.
@@ -1,49 +1,49 @@
1
- module Promisepay
2
- # Configuration options for {Client}, defaulting to values in {Default}.
3
- module Configurable
4
- # @!attribute api_domain
5
- # @return [String] Promisepay API domain name. default: api.promisepay.com
6
- # @!attribute environment
7
- # @see http://docs.promisepay.com/v2.2/docs/environments
8
- # @return [String] Promisepay environment. default: test
9
- # @!attribute token
10
- # @see http://docs.promisepay.com/v2.2/docs/overview-2
11
- # @return [String] Promisepay token for Basic Authentication.
12
- # @!attribute username
13
- # @see http://docs.promisepay.com/v2.2/docs/overview-2
14
- # @return [String] Promisepay username for Basic Authentication.
15
-
16
- attr_accessor :api_domain, :environment, :token, :username
17
-
18
- class << self
19
- # List of configurable keys for {Promisepay::Client}.
20
- #
21
- # @return [Array] of option keys
22
- def keys
23
- @keys ||= [
24
- :environment,
25
- :api_domain,
26
- :token,
27
- :username
28
- ]
29
- end
30
- end
31
-
32
- # Reset configuration options to default values.
33
- def reset!
34
- Promisepay::Configurable.keys.each do |key|
35
- instance_variable_set(:"@#{key}", Promisepay::Default.options[key])
36
- end
37
- self
38
- end
39
- alias_method :setup, :reset!
40
-
41
- # API endpoint to be used by {Promisepay::Client}.
42
- # Built from {#environment} and {#api_domain}
43
- #
44
- # @return [String]
45
- def api_endpoint
46
- "https://#{@environment}.#{@api_domain}/"
47
- end
48
- end
49
- end
1
+ module Promisepay
2
+ # Configuration options for {Client}, defaulting to values in {Default}.
3
+ module Configurable
4
+ # @!attribute api_domain
5
+ # @return [String] Promisepay API domain name. default: api.promisepay.com
6
+ # @!attribute environment
7
+ # @see http://docs.promisepay.com/v2.2/docs/environments
8
+ # @return [String] Promisepay environment. default: test
9
+ # @!attribute token
10
+ # @see http://docs.promisepay.com/v2.2/docs/overview-2
11
+ # @return [String] Promisepay token for Basic Authentication.
12
+ # @!attribute username
13
+ # @see http://docs.promisepay.com/v2.2/docs/overview-2
14
+ # @return [String] Promisepay username for Basic Authentication.
15
+
16
+ attr_accessor :api_domain, :environment, :token, :username
17
+
18
+ class << self
19
+ # List of configurable keys for {Promisepay::Client}.
20
+ #
21
+ # @return [Array] of option keys
22
+ def keys
23
+ @keys ||= [
24
+ :environment,
25
+ :api_domain,
26
+ :token,
27
+ :username
28
+ ]
29
+ end
30
+ end
31
+
32
+ # Reset configuration options to default values.
33
+ def reset!
34
+ Promisepay::Configurable.keys.each do |key|
35
+ instance_variable_set(:"@#{key}", Promisepay::Default.options[key])
36
+ end
37
+ self
38
+ end
39
+ alias_method :setup, :reset!
40
+
41
+ # API endpoint to be used by {Promisepay::Client}.
42
+ # Built from {#environment} and {#api_domain}
43
+ #
44
+ # @return [String]
45
+ def api_endpoint
46
+ "https://#{@environment}.#{@api_domain}/"
47
+ end
48
+ end
49
+ end
@@ -1,47 +1,47 @@
1
- module Promisepay
2
- # Default configuration options for {Client}
3
- module Default
4
- # Default API domain
5
- API_DOMAIN = 'api.promisepay.com'.freeze
6
-
7
- # Default environment
8
- ENVIRONMENT = 'test'.freeze
9
-
10
- class << self
11
- # Configuration options.
12
- #
13
- # @return [Hash]
14
- def options
15
- Hash[Promisepay::Configurable.keys.map { |key| [key, send(key)] }]
16
- end
17
-
18
- # Default environment from ENV or {ENVIRONMENT}.
19
- #
20
- # @return [String]
21
- def environment
22
- ENV['PROMISEPAY_ENVIRONMENT'] || ENVIRONMENT
23
- end
24
-
25
- # Default API domain from ENV or {API_DOMAIN}.
26
- #
27
- # @return [String]
28
- def api_domain
29
- ENV['PROMISEPAY_API_DOMAIN'] || API_DOMAIN
30
- end
31
-
32
- # Default token from ENV.
33
- #
34
- # @return [String]
35
- def token
36
- ENV['PROMISEPAY_TOKEN']
37
- end
38
-
39
- # Default username from ENV.
40
- #
41
- # @return [String]
42
- def username
43
- ENV['PROMISEPAY_USERNAME']
44
- end
45
- end
46
- end
47
- end
1
+ module Promisepay
2
+ # Default configuration options for {Client}
3
+ module Default
4
+ # Default API domain
5
+ API_DOMAIN = 'api.promisepay.com'.freeze
6
+
7
+ # Default environment
8
+ ENVIRONMENT = 'test'.freeze
9
+
10
+ class << self
11
+ # Configuration options.
12
+ #
13
+ # @return [Hash]
14
+ def options
15
+ Hash[Promisepay::Configurable.keys.map { |key| [key, send(key)] }]
16
+ end
17
+
18
+ # Default environment from ENV or {ENVIRONMENT}.
19
+ #
20
+ # @return [String]
21
+ def environment
22
+ ENV['PROMISEPAY_ENVIRONMENT'] || ENVIRONMENT
23
+ end
24
+
25
+ # Default API domain from ENV or {API_DOMAIN}.
26
+ #
27
+ # @return [String]
28
+ def api_domain
29
+ ENV['PROMISEPAY_API_DOMAIN'] || API_DOMAIN
30
+ end
31
+
32
+ # Default token from ENV.
33
+ #
34
+ # @return [String]
35
+ def token
36
+ ENV['PROMISEPAY_TOKEN']
37
+ end
38
+
39
+ # Default username from ENV.
40
+ #
41
+ # @return [String]
42
+ def username
43
+ ENV['PROMISEPAY_USERNAME']
44
+ end
45
+ end
46
+ end
47
+ end
@@ -1,92 +1,92 @@
1
- module Promisepay
2
- # Custom error class for rescuing from all Promisepau errors
3
- class Error < StandardError
4
- # Returns the appropriate Promisepay::Error subclass based on status
5
- #
6
- # @param [Faraday::Response] response Faraday HTTP response
7
- # @return [Promisepay::Error]
8
- def self.from_response(response)
9
- klass = case response.status
10
- when 400 then Promisepay::BadRequest
11
- when 401 then Promisepay::Unauthorized
12
- when 403 then Promisepay::Forbidden
13
- when 404 then Promisepay::NotFound
14
- when 405 then Promisepay::MethodNotAllowed
15
- when 406 then Promisepay::NotAcceptable
16
- when 409 then Promisepay::Conflict
17
- when 422 then Promisepay::UnprocessableEntity
18
- when 400..499 then Promisepay::ClientError
19
- when 500 then Promisepay::InternalServerError
20
- when 501 then Promisepay::NotImplemented
21
- when 502 then Promisepay::BadGateway
22
- when 503 then Promisepay::ServiceUnavailable
23
- when 500..599 then Promisepay::ServerError
24
- end
25
- (klass) ? klass.new(response) : new(response)
26
- end
27
-
28
- def initialize(response = nil)
29
- @response = response
30
- super(build_error_message)
31
- end
32
-
33
- private
34
-
35
- def build_error_message
36
- return nil if @response.nil? || @response.body.nil?
37
-
38
- json_response = JSON.parse(@response.body)
39
- message = ''
40
- message << json_response['message'] if json_response.key?('message')
41
- if json_response.key?('errors')
42
- json_response['errors'].each do |attribute, content|
43
- message << "#{attribute}: #{content}"
44
- end
45
- end
46
-
47
- message
48
- end
49
- end
50
-
51
- # Raised on errors in the 400-499 range
52
- class ClientError < Error; end
53
-
54
- # Raised when Promisepay returns a 400 HTTP status code
55
- class BadRequest < ClientError; end
56
-
57
- # Raised when Promisepay returns a 401 HTTP status code
58
- class Unauthorized < ClientError; end
59
-
60
- # Raised when Promisepay returns a 403 HTTP status code
61
- class Forbidden < ClientError; end
62
-
63
- # Raised when Promisepay returns a 404 HTTP status code
64
- class NotFound < ClientError; end
65
-
66
- # Raised when Promisepay returns a 405 HTTP status code
67
- class MethodNotAllowed < ClientError; end
68
-
69
- # Raised when Promisepay returns a 406 HTTP status code
70
- class NotAcceptable < ClientError; end
71
-
72
- # Raised when Promisepay returns a 409 HTTP status code
73
- class Conflict < ClientError; end
74
-
75
- # Raised when Promisepay returns a 422 HTTP status code
76
- class UnprocessableEntity < ClientError; end
77
-
78
- # Raised on errors in the 500-599 range
79
- class ServerError < Error; end
80
-
81
- # Raised when Promisepay returns a 500 HTTP status code
82
- class InternalServerError < ServerError; end
83
-
84
- # Raised when Promisepay returns a 501 HTTP status code
85
- class NotImplemented < ServerError; end
86
-
87
- # Raised when Promisepay returns a 502 HTTP status code
88
- class BadGateway < ServerError; end
89
-
90
- # Raised when Promisepay returns a 503 HTTP status code
91
- class ServiceUnavailable < ServerError; end
92
- end
1
+ module Promisepay
2
+ # Custom error class for rescuing from all Promisepau errors
3
+ class Error < StandardError
4
+ # Returns the appropriate Promisepay::Error subclass based on status
5
+ #
6
+ # @param [Faraday::Response] response Faraday HTTP response
7
+ # @return [Promisepay::Error]
8
+ def self.from_response(response)
9
+ klass = case response.status
10
+ when 400 then Promisepay::BadRequest
11
+ when 401 then Promisepay::Unauthorized
12
+ when 403 then Promisepay::Forbidden
13
+ when 404 then Promisepay::NotFound
14
+ when 405 then Promisepay::MethodNotAllowed
15
+ when 406 then Promisepay::NotAcceptable
16
+ when 409 then Promisepay::Conflict
17
+ when 422 then Promisepay::UnprocessableEntity
18
+ when 400..499 then Promisepay::ClientError
19
+ when 500 then Promisepay::InternalServerError
20
+ when 501 then Promisepay::NotImplemented
21
+ when 502 then Promisepay::BadGateway
22
+ when 503 then Promisepay::ServiceUnavailable
23
+ when 500..599 then Promisepay::ServerError
24
+ end
25
+ (klass) ? klass.new(response) : new(response)
26
+ end
27
+
28
+ def initialize(response = nil)
29
+ @response = response
30
+ super(build_error_message)
31
+ end
32
+
33
+ private
34
+
35
+ def build_error_message
36
+ return nil if @response.nil? || @response.body.nil?
37
+
38
+ json_response = JSON.parse(@response.body)
39
+ message = ''
40
+ message << json_response['message'] if json_response.key?('message')
41
+ if json_response.key?('errors')
42
+ json_response['errors'].each do |attribute, content|
43
+ message << "#{attribute}: #{content}"
44
+ end
45
+ end
46
+
47
+ message
48
+ end
49
+ end
50
+
51
+ # Raised on errors in the 400-499 range
52
+ class ClientError < Error; end
53
+
54
+ # Raised when Promisepay returns a 400 HTTP status code
55
+ class BadRequest < ClientError; end
56
+
57
+ # Raised when Promisepay returns a 401 HTTP status code
58
+ class Unauthorized < ClientError; end
59
+
60
+ # Raised when Promisepay returns a 403 HTTP status code
61
+ class Forbidden < ClientError; end
62
+
63
+ # Raised when Promisepay returns a 404 HTTP status code
64
+ class NotFound < ClientError; end
65
+
66
+ # Raised when Promisepay returns a 405 HTTP status code
67
+ class MethodNotAllowed < ClientError; end
68
+
69
+ # Raised when Promisepay returns a 406 HTTP status code
70
+ class NotAcceptable < ClientError; end
71
+
72
+ # Raised when Promisepay returns a 409 HTTP status code
73
+ class Conflict < ClientError; end
74
+
75
+ # Raised when Promisepay returns a 422 HTTP status code
76
+ class UnprocessableEntity < ClientError; end
77
+
78
+ # Raised on errors in the 500-599 range
79
+ class ServerError < Error; end
80
+
81
+ # Raised when Promisepay returns a 500 HTTP status code
82
+ class InternalServerError < ServerError; end
83
+
84
+ # Raised when Promisepay returns a 501 HTTP status code
85
+ class NotImplemented < ServerError; end
86
+
87
+ # Raised when Promisepay returns a 502 HTTP status code
88
+ class BadGateway < ServerError; end
89
+
90
+ # Raised when Promisepay returns a 503 HTTP status code
91
+ class ServiceUnavailable < ServerError; end
92
+ end
@@ -1,5 +1,5 @@
1
- module Promisepay
2
- # Manage Accounts
3
- class Account < BaseModel
4
- end
5
- end
1
+ module Promisepay
2
+ # Manage Accounts
3
+ class Account < BaseModel
4
+ end
5
+ end
@@ -1,28 +1,28 @@
1
- module Promisepay
2
- # Manage Bank accounts
3
- class BankAccount < Account
4
- # Get the user the bank account belongs to.
5
- #
6
- # @see http://docs.promisepay.com/v2.2/docs/bank_accountsidusers
7
- #
8
- # @return [Promisepay::User]
9
- def user
10
- response = JSON.parse(@client.get("bank_accounts/#{send(:id)}/users").body)
11
- Promisepay::User.new(@client, response['users'])
12
- end
13
-
14
- # Deletes a bank account for a user on a marketplace.
15
- # Sets the account to in-active.
16
- #
17
- # @see http://docs.promisepay.com/v2.2/docs/bank_accountsid
18
- #
19
- # @param mobile_pin [String] Mobile PIN.
20
- #
21
- # @return [Boolean]
22
- def deactivate(mobile_pin)
23
- @client.delete("bank_accounts/#{id}", mobile_pin: mobile_pin)
24
- @attributes['active'] = false
25
- true
26
- end
27
- end
28
- end
1
+ module Promisepay
2
+ # Manage Bank accounts
3
+ class BankAccount < Account
4
+ # Get the user the bank account belongs to.
5
+ #
6
+ # @see http://docs.promisepay.com/v2.2/docs/bank_accountsidusers
7
+ #
8
+ # @return [Promisepay::User]
9
+ def user
10
+ response = JSON.parse(@client.get("bank_accounts/#{send(:id)}/users").body)
11
+ Promisepay::User.new(@client, response['users'])
12
+ end
13
+
14
+ # Deletes a bank account for a user on a marketplace.
15
+ # Sets the account to in-active.
16
+ #
17
+ # @see http://docs.promisepay.com/v2.2/docs/bank_accountsid
18
+ #
19
+ # @param mobile_pin [String] Mobile PIN.
20
+ #
21
+ # @return [Boolean]
22
+ def deactivate(mobile_pin)
23
+ @client.delete("bank_accounts/#{id}", mobile_pin: mobile_pin)
24
+ @attributes['active'] = false
25
+ true
26
+ end
27
+ end
28
+ end
@@ -1,23 +1,23 @@
1
- module Promisepay
2
- # Base model for all the other models to inherit from
3
- class BaseModel
4
- def initialize(client, attributes = {})
5
- @client = client
6
- @attributes = stringify_keys(attributes)
7
- end
8
-
9
- def method_missing(name, *args, &block)
10
- if @attributes.key?(name.to_s)
11
- @attributes[name.to_s]
12
- else
13
- super
14
- end
15
- end
16
-
17
- private
18
-
19
- def stringify_keys(hash)
20
- Hash[hash.map { |k, v| [k.to_s, v] }]
21
- end
22
- end
23
- end
1
+ module Promisepay
2
+ # Base model for all the other models to inherit from
3
+ class BaseModel
4
+ def initialize(client, attributes = {})
5
+ @client = client
6
+ @attributes = stringify_keys(attributes)
7
+ end
8
+
9
+ def method_missing(name, *args, &block)
10
+ if @attributes.key?(name.to_s)
11
+ @attributes[name.to_s]
12
+ else
13
+ super
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def stringify_keys(hash)
20
+ Hash[hash.map { |k, v| [k.to_s, v] }]
21
+ end
22
+ end
23
+ end