zspay 0.1.8 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +26 -0
- data/.yardopts +1 -0
- data/README.md +106 -0
- data/Rakefile.rb +10 -0
- data/lib/zspay/configuration.rb +10 -5
- data/lib/zspay/resource.rb +84 -12
- data/lib/zspay/resources/bank_account.rb +20 -2
- data/lib/zspay/resources/client.rb +18 -1
- data/lib/zspay/resources/establishment.rb +70 -0
- data/lib/zspay/resources/sale.rb +22 -2
- data/lib/zspay/resources/transfer.rb +24 -1
- data/lib/zspay/resources.rb +5 -5
- data/lib/zspay/version.rb +1 -1
- data/lib/zspay.rb +28 -7
- metadata +24 -32
- data/lib/zspay/resources/establishments.rb +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 180b5f125d68bd72b22362b92793b1870f926ab450a00232d98bf488e18910f0
|
4
|
+
data.tar.gz: 335056151d11456d19ead9d8930496b1fdbb1e8def541b2fb9635bc438e19f35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4a81a5e4670548d4473f2ed29fed0cdaa3a019d44d2444a0aa2821d90166f09e53f7b71a40b3aa20d6e5781e3676b7d439e23ceb0ce9b05986c665c25027b91
|
7
|
+
data.tar.gz: bc21ef4823d88e0401cee6f9dbe914ccc4d01315e89e0cc4bb166e563b6e00baceea8a87ba91b5f01d6749b529c88993447323c88e8160a0695437c4d2135621
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-rake
|
3
|
+
- rubocop-minitest
|
4
|
+
|
5
|
+
AllCops:
|
6
|
+
TargetRubyVersion: 3.0
|
7
|
+
NewCops: enable
|
8
|
+
|
9
|
+
Style/StringLiterals:
|
10
|
+
Enabled: true
|
11
|
+
EnforcedStyle: double_quotes
|
12
|
+
|
13
|
+
Style/StringLiteralsInInterpolation:
|
14
|
+
Enabled: true
|
15
|
+
EnforcedStyle: double_quotes
|
16
|
+
|
17
|
+
Layout/LineLength:
|
18
|
+
Max: 120
|
19
|
+
|
20
|
+
Naming/FileName:
|
21
|
+
Exclude:
|
22
|
+
- Rakefile.rb
|
23
|
+
|
24
|
+
# TODO: replace OpenStruct in version 2
|
25
|
+
Style/OpenStructUse:
|
26
|
+
Enabled: false
|
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--private
|
data/README.md
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
# Zspay Ruby Gem
|
2
|
+
The Zspay Ruby Gem provides an easy-to-use interface for integrating Zspay's payment processing features into Ruby applications. This includes handling clients, bank accounts, sales, transfers, and more.
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
```rb
|
7
|
+
gem 'zspay'
|
8
|
+
```
|
9
|
+
|
10
|
+
And then execute:
|
11
|
+
```shell
|
12
|
+
bundle install
|
13
|
+
```
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
```shell
|
17
|
+
gem install zspay
|
18
|
+
```
|
19
|
+
|
20
|
+
## Configuration
|
21
|
+
|
22
|
+
Before using the Zspay gem, you must configure it with your Zspay API credentials. This is typically done in an initializer in your Ruby application, such as config/initializers/zspay.rb.
|
23
|
+
```rb
|
24
|
+
Zspay.configure do |config|
|
25
|
+
config.token = ENV.fetch('YOUR_TOKEN')
|
26
|
+
end
|
27
|
+
```
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
Here's how to use the Zspay gem to interact with different resources:
|
32
|
+
|
33
|
+
### Clients
|
34
|
+
```rb
|
35
|
+
# Create a new client
|
36
|
+
client = Zspay::Client.create({
|
37
|
+
name: 'John Doe',
|
38
|
+
email: 'john@example.com',
|
39
|
+
document: '12345678900'
|
40
|
+
})
|
41
|
+
|
42
|
+
# Create a new card for a client
|
43
|
+
card = Zspay::Client.create_card(client_id, {
|
44
|
+
number: '4111111111111111',
|
45
|
+
expiry_month: '12',
|
46
|
+
expiry_year: '2030',
|
47
|
+
cvv: '123'
|
48
|
+
})
|
49
|
+
```
|
50
|
+
|
51
|
+
### Bank Accounts
|
52
|
+
|
53
|
+
```rb
|
54
|
+
# List bank accounts
|
55
|
+
accounts = Zspay::BankAccount.index
|
56
|
+
|
57
|
+
# Create a new bank account
|
58
|
+
account = Zspay::BankAccount.create({
|
59
|
+
bank_code: '001',
|
60
|
+
agency: '0001',
|
61
|
+
account: '123456',
|
62
|
+
account_digit: '7'
|
63
|
+
})
|
64
|
+
|
65
|
+
# Activate a bank account
|
66
|
+
Zspay::BankAccount.active(account_id)
|
67
|
+
```
|
68
|
+
|
69
|
+
### Sales
|
70
|
+
```rb
|
71
|
+
# Create a new sale
|
72
|
+
sale = Zspay::Sale.create({
|
73
|
+
amount: 100,
|
74
|
+
currency: 'BRL'
|
75
|
+
})
|
76
|
+
|
77
|
+
# Retrieve details of a sale
|
78
|
+
sale_details = Zspay::Sale.show(sale_id)
|
79
|
+
|
80
|
+
# Refund a sale
|
81
|
+
refund = Zspay::Sale.refund(sale_id)
|
82
|
+
```
|
83
|
+
|
84
|
+
### Transfers
|
85
|
+
```rb
|
86
|
+
# Create a new transfer
|
87
|
+
transfer = Zspay::Transfer.create({
|
88
|
+
amount: 100,
|
89
|
+
recipient_id: 'recipient_id'
|
90
|
+
})
|
91
|
+
|
92
|
+
# Schedule a transfer
|
93
|
+
scheduled_transfer = Zspay::Transfer.schedule_transfer(transfer_id)
|
94
|
+
|
95
|
+
# Remove a scheduled transfer
|
96
|
+
Zspay::Transfer.remove(transfer_id)
|
97
|
+
```
|
98
|
+
|
99
|
+
## Development
|
100
|
+
After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.
|
101
|
+
|
102
|
+
## Contributing
|
103
|
+
Bug reports and pull requests are welcome. This project is intended to be a safe, welcoming space for collaboration.
|
104
|
+
|
105
|
+
## License
|
106
|
+
The gem is available as open source under the terms of the MIT License.
|
data/Rakefile.rb
ADDED
data/lib/zspay/configuration.rb
CHANGED
@@ -1,13 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Zspay
|
4
|
+
# The Configuration class is used to manage configuration settings for the Zspay library.
|
5
|
+
# It provides class-level accessors and methods to set and retrieve the configuration settings.
|
4
6
|
class Configuration
|
5
|
-
|
6
|
-
|
7
|
+
# @!attribute [rw] token
|
8
|
+
# @return [String] the API token used for authenticating requests to the Zspay service.
|
9
|
+
attr_accessor :token
|
7
10
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
+
# Returns the default API endpoint for the Zspay service.
|
12
|
+
#
|
13
|
+
# @return [String] the base URL of the Zspay API endpoint.
|
14
|
+
def endpoint
|
15
|
+
ENV.fetch("Z_SYSTEMS_API", "https://api.zsystems.com.br")
|
11
16
|
end
|
12
17
|
end
|
13
18
|
end
|
data/lib/zspay/resource.rb
CHANGED
@@ -1,46 +1,105 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Zspay
|
4
|
+
# The Resource class provides methods to perform HTTP requests to the Zspay API.
|
5
|
+
# This class is designed to be a base class from which other resource-specific classes can inherit.
|
4
6
|
class Resource
|
5
7
|
class << self
|
6
|
-
|
8
|
+
# Performs a POST request to the specified API path.
|
9
|
+
#
|
10
|
+
# @param path [String] the API path to send the request to.
|
11
|
+
# @param payload [Hash] the request payload, defaults to an empty hash.
|
12
|
+
# @param custom_token [String, nil] an optional custom token to use for the request.
|
13
|
+
# @param body [String] the format of the request body, defaults to 'json'.
|
14
|
+
# @return [OpenStruct] the parsed response.
|
15
|
+
def post(path, payload = {}, custom_token = nil, body: "json")
|
7
16
|
req(:post, path, payload, custom_token, body: body)
|
8
17
|
end
|
9
18
|
|
19
|
+
# Performs a PATCH request to the specified API path.
|
20
|
+
#
|
21
|
+
# @param path [String] the API path to send the request to.
|
22
|
+
# @param payload [Hash] the request payload.
|
23
|
+
# @param custom_token [String, nil] an optional custom token to use for the request.
|
24
|
+
# @return [OpenStruct] the parsed response.
|
10
25
|
def patch(path, payload, custom_token = nil)
|
11
26
|
req(:patch, path, payload, custom_token)
|
12
27
|
end
|
13
28
|
|
29
|
+
# Performs a GET request to the specified API path.
|
30
|
+
#
|
31
|
+
# @param path [String] the API path to send the request to.
|
32
|
+
# @param custom_token [String, nil] an optional custom token to use for the request.
|
33
|
+
# @return [OpenStruct] the parsed response.
|
14
34
|
def get(path, custom_token = nil)
|
15
35
|
req(:get, path, {}, custom_token)
|
16
36
|
end
|
17
37
|
|
38
|
+
# Performs a DELETE request to the specified API path.
|
39
|
+
#
|
40
|
+
# @param path [String] the API path to send the request to.
|
41
|
+
# @param custom_token [String, nil] an optional custom token to use for the request.
|
42
|
+
# @return [OpenStruct] the parsed response.
|
18
43
|
def delete(path, custom_token = nil)
|
19
44
|
req(:delete, path, {}, custom_token)
|
20
45
|
end
|
21
46
|
|
47
|
+
# Performs a PUT request to the specified API path.
|
48
|
+
#
|
49
|
+
# @param path [String] the API path to send the request to.
|
50
|
+
# @param payload [Hash] the request payload, defaults to an empty hash.
|
51
|
+
# @param custom_token [String, nil] an optional custom token to use for the request.
|
52
|
+
# @return [OpenStruct] the parsed response.
|
22
53
|
def put(path, payload = {}, custom_token = nil)
|
23
54
|
req(:put, path, payload, custom_token)
|
24
55
|
end
|
25
56
|
|
26
57
|
private
|
27
58
|
|
28
|
-
|
59
|
+
# A private method to perform an HTTP request using the specified method, path, and payload.
|
60
|
+
#
|
61
|
+
# @param method [Symbol] the HTTP method to use for the request.
|
62
|
+
# @param path [String] the API path to send the request to.
|
63
|
+
# @param payload [Hash] the request payload, defaults to an empty hash.
|
64
|
+
# @param custom_token [String, nil] an optional custom token to use for the request.
|
65
|
+
# @param body [String] the format of the request body, defaults to 'json'.
|
66
|
+
# @return [OpenStruct] the parsed response.
|
67
|
+
def req(method, path, payload = {}, custom_token = nil, body: "json")
|
29
68
|
send("req_#{body}", method, path, payload, custom_token)
|
30
69
|
end
|
31
70
|
|
71
|
+
# A private method to send a request with JSON body format.
|
72
|
+
#
|
73
|
+
# @param method [Symbol] the HTTP method.
|
74
|
+
# @param path [String] the path to send the request to.
|
75
|
+
# @param payload [Hash] the request payload.
|
76
|
+
# @param custom_token [String, nil] an optional custom token for the request.
|
77
|
+
# @return [OpenStruct] the parsed response.
|
32
78
|
def req_json(method, path, payload, custom_token)
|
33
79
|
res = HTTP.headers(headers(custom_token)).send(method, "#{endpoint}#{path}", json: payload)
|
34
80
|
|
35
81
|
parse_body(res)
|
36
82
|
end
|
37
83
|
|
84
|
+
# A private method to send a request with form body format.
|
85
|
+
#
|
86
|
+
# @param method [Symbol] the HTTP method.
|
87
|
+
# @param path [String] the path to send the request to.
|
88
|
+
# @param payload [Hash] the request payload.
|
89
|
+
# @param custom_token [String, nil] an optional custom token for the request.
|
90
|
+
# @return [OpenStruct] the parsed response.
|
38
91
|
def req_form(method, path, payload, custom_token)
|
39
92
|
payload = HTTP::FormData::Multipart.new(payload)
|
40
93
|
res = HTTP.headers(headers(custom_token)).send(method, "#{endpoint}#{path}", form: payload)
|
41
94
|
parse_body(res)
|
42
95
|
end
|
43
96
|
|
97
|
+
# Parses the response body and returns it as an OpenStruct.
|
98
|
+
# If the request was successful, returns the JSON parsed body.
|
99
|
+
# Otherwise, logs the error and returns an error message.
|
100
|
+
#
|
101
|
+
# @param response [HTTP::Response] the HTTP response to parse.
|
102
|
+
# @return [OpenStruct] the parsed response.
|
44
103
|
def parse_body(response)
|
45
104
|
if success_request?(response)
|
46
105
|
body = response.body.to_s
|
@@ -50,34 +109,47 @@ module Zspay
|
|
50
109
|
|
51
110
|
OpenStruct.new({ success: false, error: body })
|
52
111
|
else
|
53
|
-
error_log = Logger.new(
|
54
|
-
error_log.error("
|
55
|
-
" to: #{response.uri}" \
|
56
|
-
" body: #{response.body}" \
|
57
|
-
" status: #{response.code}")
|
112
|
+
error_log = Logger.new($stderr)
|
113
|
+
error_log.error("Request error to: #{response.uri}\ncode: #{response.code}\nbody: #{response.body}")
|
58
114
|
|
59
|
-
OpenStruct.new({ success: false, message:
|
115
|
+
OpenStruct.new({ success: false, message: "An error occurred while making the request" })
|
60
116
|
end
|
61
117
|
end
|
62
118
|
|
119
|
+
# Returns the base endpoint URL from the configuration.
|
120
|
+
#
|
121
|
+
# @return [String] the API endpoint URL.
|
63
122
|
def endpoint
|
64
|
-
Zspay
|
123
|
+
Zspay.configuration.endpoint
|
65
124
|
end
|
66
125
|
|
126
|
+
# Constructs the headers for the request.
|
127
|
+
# If a custom token is provided, it is used; otherwise, the default token from configuration is used.
|
128
|
+
#
|
129
|
+
# @param custom_token [String, nil] an optional custom token for the request.
|
130
|
+
# @return [Hash] the request headers.
|
67
131
|
def headers(custom_token = nil)
|
68
|
-
token =
|
132
|
+
token = "Bearer #{custom_token || Zspay.configuration.token}"
|
69
133
|
{
|
70
|
-
|
134
|
+
Authorization: token
|
71
135
|
}
|
72
136
|
end
|
73
137
|
|
138
|
+
# Determines whether the response was successful based on the status code.
|
139
|
+
#
|
140
|
+
# @param response [HTTP::Response] the response to check.
|
141
|
+
# @return [Boolean] true if the response was successful, false otherwise.
|
74
142
|
def success_request?(response)
|
75
143
|
response.code.to_s =~ /2../ && response
|
76
144
|
end
|
77
145
|
|
146
|
+
# Parses a JSON string into an OpenStruct. If parsing fails, returns the original JSON string.
|
147
|
+
#
|
148
|
+
# @param json [String] the JSON string to parse.
|
149
|
+
# @return [OpenStruct, String] the parsed JSON or the original string if parsing failed.
|
78
150
|
def parse_json(json)
|
79
151
|
JSON.parse(json, object_class: OpenStruct)
|
80
|
-
rescue JSON::ParserError =>
|
152
|
+
rescue JSON::ParserError => _e
|
81
153
|
json
|
82
154
|
end
|
83
155
|
end
|
@@ -1,20 +1,38 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Zspay
|
4
|
+
# The BankAccount class provides methods to manage bank accounts within the Zspay platform.
|
5
|
+
# This class extends the Zspay::Resource class, utilizing its HTTP request methods.
|
4
6
|
class BankAccount < Zspay::Resource
|
5
7
|
class << self
|
8
|
+
# Retrieves a list of all bank accounts associated with the current establishment.
|
9
|
+
#
|
10
|
+
# @return [OpenStruct] A list of bank accounts if the request is successful.
|
6
11
|
def index
|
7
|
-
get(
|
12
|
+
get("/estabelecimentos/contas_bancarias")
|
8
13
|
end
|
9
14
|
|
15
|
+
# Creates a new bank account for the current establishment.
|
16
|
+
#
|
17
|
+
# @param account [Hash] The bank account details required for creation.
|
18
|
+
# @return [OpenStruct] The created bank account details if the request is successful.
|
10
19
|
def create(account)
|
11
|
-
post(
|
20
|
+
post("/estabelecimentos/contas_bancarias", account)
|
12
21
|
end
|
13
22
|
|
23
|
+
# Activates a specific bank account for the current establishment.
|
24
|
+
#
|
25
|
+
# @param account_id [String] The unique identifier of the bank account to be activated.
|
26
|
+
# @return [OpenStruct] The status of the bank account after attempting activation.
|
14
27
|
def active(account_id)
|
15
28
|
post("/estabelecimentos/contas_bancarias/#{account_id}/ativar")
|
16
29
|
end
|
17
30
|
|
31
|
+
# Deletes a specific bank account from the establishment.
|
32
|
+
#
|
33
|
+
# @param establishment_id [String] The unique identifier of the establishment.
|
34
|
+
# @param account_id [String] The unique identifier of the bank account to be deleted.
|
35
|
+
# @return [OpenStruct] The status message indicating the result of the deletion request.
|
18
36
|
def destroy(establishment_id, account_id)
|
19
37
|
delete("/estabelecimentos/#{establishment_id}/contas_bancarias/#{account_id}/excluir")
|
20
38
|
end
|
@@ -1,12 +1,29 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Zspay
|
4
|
+
# The Client class is responsible for handling client-related actions within the Zspay platform.
|
5
|
+
# It allows for creating clients and their associated cards by extending the Zspay::Resource class.
|
4
6
|
class Client < Zspay::Resource
|
5
7
|
class << self
|
8
|
+
# Creates a new client on the Zspay platform.
|
9
|
+
#
|
10
|
+
# This method sends a POST request to the Zspay API to create a new client record.
|
11
|
+
# The client's information should be provided in the form of a hash.
|
12
|
+
#
|
13
|
+
# @param client [Hash] A hash containing the client's information, such as name, email, etc.
|
14
|
+
# @return [OpenStruct] A structure containing the newly created client's details if successful.
|
6
15
|
def create(client)
|
7
|
-
post(
|
16
|
+
post("/clientes", client)
|
8
17
|
end
|
9
18
|
|
19
|
+
# Adds a new card for an existing client on the Zspay platform.
|
20
|
+
#
|
21
|
+
# This method sends a POST request to add a new card to the specified client's account.
|
22
|
+
# The card information, including number, expiry date, and CVV, should be provided in the form of a hash.
|
23
|
+
#
|
24
|
+
# @param client_id [String] The unique identifier of the client to whom the card will be added.
|
25
|
+
# @param card [Hash] A hash containing the card's information, such as number, expiry date, and CVV.
|
26
|
+
# @return [OpenStruct] A structure containing the newly added card's details if successful.
|
10
27
|
def create_card(client_id, card)
|
11
28
|
post("/clientes/#{client_id}/cartoes", card)
|
12
29
|
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Zspay
|
4
|
+
# The Establishment class manages establishment-related actions within the Zspay platform.
|
5
|
+
# It allows for listing, creating, enabling, disabling establishment, and more, extending the functionality
|
6
|
+
# from Zspay::Resource.
|
7
|
+
class Establishment < Zspay::Resource
|
8
|
+
class << self
|
9
|
+
# Retrieves a list of child establishments associated with the current establishment.
|
10
|
+
#
|
11
|
+
# @return [OpenStruct] A structure containing the list of child establishments if the request is successful.
|
12
|
+
def index
|
13
|
+
get("/estabelecimentos/filhos")
|
14
|
+
end
|
15
|
+
|
16
|
+
# Creates a new establishment on the Zspay platform.
|
17
|
+
#
|
18
|
+
# @param establishment [Hash] A hash containing the establishment's information.
|
19
|
+
# @return [OpenStruct] A structure containing the newly created establishment's details if the request
|
20
|
+
# is successful.
|
21
|
+
def create(establishment)
|
22
|
+
post("/estabelecimentos", establishment, body: "form")
|
23
|
+
end
|
24
|
+
|
25
|
+
# Activates an existing establishment on the Zspay platform.
|
26
|
+
#
|
27
|
+
# @param establishment_id [String] The unique identifier of the establishment to be activated.
|
28
|
+
# @return [OpenStruct] A structure indicating the activation status of the establishment if the request
|
29
|
+
# is successful.
|
30
|
+
def active(establishment_id)
|
31
|
+
post("/estabelecimentos/#{establishment_id}/habilitar")
|
32
|
+
end
|
33
|
+
|
34
|
+
# Disables an existing establishment on the Zspay platform.
|
35
|
+
#
|
36
|
+
# @param establishment_id [String] The unique identifier of the establishment to be disabled.
|
37
|
+
# @return [OpenStruct] A structure indicating the disabled status of the establishment if the request
|
38
|
+
# is successful.
|
39
|
+
def disable(establishment_id)
|
40
|
+
delete("/estabelecimentos/#{establishment_id}")
|
41
|
+
end
|
42
|
+
|
43
|
+
# Retrieves the token associated with a specific establishment.
|
44
|
+
#
|
45
|
+
# This token is typically used for authentication in subsequent API requests.
|
46
|
+
#
|
47
|
+
# @param establishment_id [String] The unique identifier of the establishment for which to retrieve the token.
|
48
|
+
# @return [OpenStruct] A structure containing the establishment's token if the request is successful.
|
49
|
+
def token(establishment_id)
|
50
|
+
get("/estabelecimentos/#{establishment_id}/token")
|
51
|
+
end
|
52
|
+
|
53
|
+
# Retrieves the balance of a specific establishment.
|
54
|
+
#
|
55
|
+
# @param establishment_id [String] The unique identifier of the establishment for which to retrieve the balance.
|
56
|
+
# @return [OpenStruct] A structure containing the establishment's balance details if the request is successful.
|
57
|
+
def balance(establishment_id)
|
58
|
+
get("/estabelecimentos/#{establishment_id}/saldo")
|
59
|
+
end
|
60
|
+
|
61
|
+
# Searches for an establishment based on its document number.
|
62
|
+
#
|
63
|
+
# @param document [String] The document number of the establishment to search for.
|
64
|
+
# @return [OpenStruct] A structure containing the establishment's details if found, otherwise an error message.
|
65
|
+
def search_by_document(document)
|
66
|
+
get("/estabelecimentos/por_documento/#{document}")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/lib/zspay/resources/sale.rb
CHANGED
@@ -1,18 +1,38 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Zspay
|
4
|
+
# The Sale class manages sale-related actions within the Zspay platform.
|
5
|
+
# It provides methods to create a sale, retrieve sale details, and refund a sale,
|
6
|
+
# extending the functionality from Zspay::Resource.
|
4
7
|
class Sale < Zspay::Resource
|
5
8
|
class << self
|
9
|
+
# Creates a new sale on the Zspay platform.
|
10
|
+
#
|
11
|
+
# @param sale [Hash] A hash containing the sale information.
|
12
|
+
# @param custom_token [String, nil] An optional custom token to use for the request.
|
13
|
+
# @return [OpenStruct] A structure containing the newly created sale's details if the request is successful.
|
6
14
|
def create(sale, custom_token = nil)
|
7
|
-
post(
|
15
|
+
post("/vendas", sale, custom_token)
|
8
16
|
end
|
9
17
|
|
18
|
+
# Retrieves details of a specific sale.
|
19
|
+
#
|
20
|
+
# @param sale_id [String] The unique identifier of the sale to retrieve.
|
21
|
+
# @param custom_token [String, nil] An optional custom token to use for the request.
|
22
|
+
# @return [OpenStruct] A structure containing the sale's details if the request is successful.
|
10
23
|
def show(sale_id, custom_token = nil)
|
11
24
|
get("/vendas/#{sale_id}", custom_token)
|
12
25
|
end
|
13
26
|
|
27
|
+
# Processes a refund for a specific sale.
|
28
|
+
#
|
29
|
+
# This method sends a request to refund a previously made sale. The sale is identified by its unique ID.
|
30
|
+
#
|
31
|
+
# @param sale_id [String] The unique identifier of the sale to refund.
|
32
|
+
# @param custom_token [String, nil] An optional custom token to use for the request.
|
33
|
+
# @return [OpenStruct] A structure indicating the result of the refund operation if the request is successful.
|
14
34
|
def refund(sale_id, custom_token = nil)
|
15
|
-
post("/vendas/#{sale_id}/estornar",
|
35
|
+
post("/vendas/#{sale_id}/estornar", {}, custom_token)
|
16
36
|
end
|
17
37
|
end
|
18
38
|
end
|
@@ -1,16 +1,39 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Zspay
|
4
|
+
# The Transfer class manages transfer-related actions within the Zspay platform.
|
5
|
+
# It provides methods to create, schedule, and remove transfers, extending from Zspay::Resource.
|
4
6
|
class Transfer < Zspay::Resource
|
5
7
|
class << self
|
8
|
+
# Creates a new transfer on the Zspay platform.
|
9
|
+
#
|
10
|
+
# This method sends a POST request to create a new transfer with the provided details.
|
11
|
+
#
|
12
|
+
# @param transfer [Hash] A hash containing the transfer details.
|
13
|
+
# @param custom_token [String, nil] An optional custom token to use for the request.
|
14
|
+
# @return [OpenStruct] A structure containing the newly created transfer's details if the request is successful.
|
6
15
|
def create(transfer, custom_token = nil)
|
7
|
-
post(
|
16
|
+
post("/transferencias", transfer, custom_token)
|
8
17
|
end
|
9
18
|
|
19
|
+
# Retrieves the details of a scheduled transfer.
|
20
|
+
#
|
21
|
+
# This method sends a GET request to obtain details about a transfer that has been scheduled.
|
22
|
+
#
|
23
|
+
# @param transfer_id [String] The unique identifier of the scheduled transfer.
|
24
|
+
# @param custom_token [String, nil] An optional custom token to use for the request.
|
25
|
+
# @return [OpenStruct] A structure containing the scheduled transfer's details if the request is successful.
|
10
26
|
def schedule_transfer(transfer_id, custom_token = nil)
|
11
27
|
get("/transferencias/agendadas/#{transfer_id}", custom_token)
|
12
28
|
end
|
13
29
|
|
30
|
+
# Cancels a scheduled transfer.
|
31
|
+
#
|
32
|
+
# This method sends a DELETE request to remove a previously scheduled transfer from the system.
|
33
|
+
#
|
34
|
+
# @param transfer_id [String] The unique identifier of the transfer to be removed.
|
35
|
+
# @param custom_token [String, nil] An optional custom token to use for the request.
|
36
|
+
# @return [OpenStruct] A structure indicating the result of the cancellation if the request is successful.
|
14
37
|
def remove(transfer_id, custom_token = nil)
|
15
38
|
delete("/transferencias/agendadas/#{transfer_id}", custom_token)
|
16
39
|
end
|
data/lib/zspay/resources.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
3
|
+
require "zspay/resources/bank_account"
|
4
|
+
require "zspay/resources/client"
|
5
|
+
require "zspay/resources/establishment"
|
6
|
+
require "zspay/resources/sale"
|
7
|
+
require "zspay/resources/transfer"
|
data/lib/zspay/version.rb
CHANGED
data/lib/zspay.rb
CHANGED
@@ -1,21 +1,42 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require 'active_support/hash_with_indifferent_access'
|
3
|
+
require "http"
|
4
|
+
require "logger"
|
5
|
+
require "active_support/hash_with_indifferent_access"
|
7
6
|
|
8
|
-
require
|
7
|
+
require "zspay/version"
|
9
8
|
|
10
|
-
require
|
11
|
-
require 'zspay/resources'
|
9
|
+
require "zspay/configuration"
|
12
10
|
|
11
|
+
require "zspay/resource"
|
12
|
+
require "zspay/resources"
|
13
|
+
|
14
|
+
# The Zspay module is the main namespace for the Zspay gem.
|
15
|
+
# It provides methods to configure and access the gem's settings.
|
16
|
+
#
|
17
|
+
# Examples:
|
18
|
+
# Zspay.configure do |config|
|
19
|
+
# config.token = 'your_api_token'
|
20
|
+
# end
|
13
21
|
module Zspay
|
14
22
|
class << self
|
23
|
+
# Returns the configuration object for Zspay. If the configuration
|
24
|
+
# has not yet been initialized, it will create a new instance of
|
25
|
+
# Configuration.
|
26
|
+
#
|
27
|
+
# @return [Zspay::Configuration] the current Zspay configuration
|
15
28
|
def configuration
|
16
29
|
@configuration ||= Configuration.new
|
17
30
|
end
|
18
31
|
|
32
|
+
# Yields the current Zspay configuration to a block.
|
33
|
+
# This method is typically used to set up the gem's settings.
|
34
|
+
#
|
35
|
+
# @yieldparam config [Zspay::Configuration] the current Zspay configuration
|
36
|
+
# @example
|
37
|
+
# Zspay.configure do |config|
|
38
|
+
# config.token = 'your_api_token'
|
39
|
+
# end
|
19
40
|
def configure
|
20
41
|
yield(configuration)
|
21
42
|
end
|
metadata
CHANGED
@@ -1,60 +1,47 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zspay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pedro Augusto Silva
|
8
8
|
- Edson Lima
|
9
9
|
- Nullbug
|
10
10
|
autorequire:
|
11
|
-
bindir:
|
11
|
+
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2024-03-24 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
16
|
+
name: activesupport
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
18
18
|
requirements:
|
19
19
|
- - ">="
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
21
|
+
version: 6.0.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
26
|
- - ">="
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
version:
|
29
|
-
- !ruby/object:Gem::Dependency
|
30
|
-
name: byebug
|
31
|
-
requirement: !ruby/object:Gem::Requirement
|
32
|
-
requirements:
|
33
|
-
- - ">="
|
34
|
-
- !ruby/object:Gem::Version
|
35
|
-
version: '0'
|
36
|
-
type: :development
|
37
|
-
prerelease: false
|
38
|
-
version_requirements: !ruby/object:Gem::Requirement
|
39
|
-
requirements:
|
40
|
-
- - ">="
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
version: '0'
|
28
|
+
version: 6.0.0
|
43
29
|
- !ruby/object:Gem::Dependency
|
44
|
-
name:
|
30
|
+
name: http
|
45
31
|
requirement: !ruby/object:Gem::Requirement
|
46
32
|
requirements:
|
47
33
|
- - ">="
|
48
34
|
- !ruby/object:Gem::Version
|
49
|
-
version:
|
50
|
-
type: :
|
35
|
+
version: 5.2.0
|
36
|
+
type: :runtime
|
51
37
|
prerelease: false
|
52
38
|
version_requirements: !ruby/object:Gem::Requirement
|
53
39
|
requirements:
|
54
40
|
- - ">="
|
55
41
|
- !ruby/object:Gem::Version
|
56
|
-
version:
|
57
|
-
description:
|
42
|
+
version: 5.2.0
|
43
|
+
description: A Ruby interface for integrating and managing payment and transfer functionalities
|
44
|
+
with the Zspay platform.
|
58
45
|
email:
|
59
46
|
- pedro@nullbug.dev
|
60
47
|
- edson@nullbug.dev
|
@@ -62,37 +49,42 @@ executables: []
|
|
62
49
|
extensions: []
|
63
50
|
extra_rdoc_files: []
|
64
51
|
files:
|
52
|
+
- ".rubocop.yml"
|
53
|
+
- ".yardopts"
|
54
|
+
- README.md
|
55
|
+
- Rakefile.rb
|
65
56
|
- lib/zspay.rb
|
66
57
|
- lib/zspay/configuration.rb
|
67
58
|
- lib/zspay/resource.rb
|
68
59
|
- lib/zspay/resources.rb
|
69
60
|
- lib/zspay/resources/bank_account.rb
|
70
61
|
- lib/zspay/resources/client.rb
|
71
|
-
- lib/zspay/resources/
|
62
|
+
- lib/zspay/resources/establishment.rb
|
72
63
|
- lib/zspay/resources/sale.rb
|
73
64
|
- lib/zspay/resources/transfer.rb
|
74
65
|
- lib/zspay/version.rb
|
75
|
-
homepage:
|
66
|
+
homepage: https://github.com/pedroaugustofsilva/zspay-ruby
|
76
67
|
licenses:
|
77
68
|
- MIT
|
78
|
-
metadata:
|
69
|
+
metadata:
|
70
|
+
rubygems_mfa_required: 'true'
|
79
71
|
post_install_message:
|
80
72
|
rdoc_options: []
|
81
73
|
require_paths:
|
82
74
|
- lib
|
83
75
|
required_ruby_version: !ruby/object:Gem::Requirement
|
84
76
|
requirements:
|
85
|
-
- - "
|
77
|
+
- - "~>"
|
86
78
|
- !ruby/object:Gem::Version
|
87
|
-
version:
|
79
|
+
version: '3.0'
|
88
80
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
81
|
requirements:
|
90
82
|
- - ">="
|
91
83
|
- !ruby/object:Gem::Version
|
92
84
|
version: '0'
|
93
85
|
requirements: []
|
94
|
-
rubygems_version: 3.
|
86
|
+
rubygems_version: 3.5.6
|
95
87
|
signing_key:
|
96
88
|
specification_version: 4
|
97
|
-
summary:
|
89
|
+
summary: Ruby interface for Zspay API.
|
98
90
|
test_files: []
|
@@ -1,35 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Zspay
|
4
|
-
class Establishments < Zspay::Resource
|
5
|
-
class << self
|
6
|
-
def index
|
7
|
-
get('/estabelecimentos/filhos')
|
8
|
-
end
|
9
|
-
|
10
|
-
def create(establishment)
|
11
|
-
post('/estabelecimentos', establishment, body: 'form')
|
12
|
-
end
|
13
|
-
|
14
|
-
def active(establishment_id)
|
15
|
-
post("/estabelecimentos/#{establishment_id}/habilitar")
|
16
|
-
end
|
17
|
-
|
18
|
-
def disable(establishment_id)
|
19
|
-
delete("/estabelecimentos/#{establishment_id}")
|
20
|
-
end
|
21
|
-
|
22
|
-
def token(establishment_id)
|
23
|
-
get("/estabelecimentos/#{establishment_id}/token")
|
24
|
-
end
|
25
|
-
|
26
|
-
def balance(establishment_id)
|
27
|
-
get("/estabelecimentos/#{establishment_id}/saldo")
|
28
|
-
end
|
29
|
-
|
30
|
-
def search_by_document(document)
|
31
|
-
get("/estabelecimentos/por_documento/#{document}")
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|