paghiper 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4d52f289b7853e883c04bf6a96910668e0ecab3189bc43d3689f17d734c3d618
4
- data.tar.gz: a4c9118ffc5be577653c19f7b6830dd49c2c10f4c3bbb117e23f9186bb4e492d
3
+ metadata.gz: da31a11dc2e22c997d659b2b42382d96336780f4f60baf100a3d41674106e98d
4
+ data.tar.gz: fcfeabd0edbfeaa7fa1c29c3c87d99ccb802e76d75841fa897d69019e3291df5
5
5
  SHA512:
6
- metadata.gz: af9549a633aae1f136a6caf4492572ac3839ed56a69ecb6341be9872beb6eaffa0d3b9ef9693679a609ee07cb904aed0129743be5c0610acf3300d774f383ff3
7
- data.tar.gz: 21cf3746cd8671101e0eab34619378f0f98870321e8048eb9982bf9cd93ef8c6830fca649326fa6e908696d68ba18c8bb90197cac311b921b7ce5d617b111bfc
6
+ metadata.gz: 2059c9c598ecaf786e322ca4f2741598e583e86d971a9828bb13c7cf0134ffb8c8858044dcb67457bd2ef092a535195c5b37b8823ae2f5f864e181caefc6bc74
7
+ data.tar.gz: 92e0279075df87c91876d2e9e6aae08acba21a47c0f7faf314d61908e76f784128b2ef8ca286c3de1eb47ed94db1bee913ea4e2d7a6f3b9c3ffe894aca005f35
data/README.md CHANGED
@@ -36,6 +36,7 @@ Configure your client settings
36
36
  ```ruby
37
37
  Paghiper.configure do |config|
38
38
  config.api_key = 'apk_99999999-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
39
+ config.token = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
39
40
  config.http_debug = true
40
41
  end
41
42
  ```
@@ -48,7 +49,15 @@ end
48
49
  Paghiper::Transaction.create(transaction_data)
49
50
  ```
50
51
 
51
- Check [API documentations](https://dev.paghiper.com/reference#gerar-boleto) of PAGHIPER required data to generate boletos.
52
+ Check the [API documentation](https://dev.paghiper.com/reference#gerar-boleto) for more information regarding this endpoint.
53
+
54
+ ### Responding to boletos webhook (Automatic status notification)
55
+
56
+ ```ruby
57
+ Paghiper::Transaction.notification(notification_data)
58
+ ```
59
+
60
+ Check the [API documentation](https://dev.paghiper.com/reference#qq) for the detailed notification flow.
52
61
 
53
62
  ## Development
54
63
 
@@ -16,7 +16,7 @@ module Paghiper
16
16
  end
17
17
 
18
18
  class Configuration
19
- attr_accessor :api_key, :http_debug
19
+ attr_accessor :api_key, :token, :http_debug
20
20
 
21
21
  def initialize
22
22
  @http_debug = false
@@ -2,6 +2,7 @@ require 'httparty'
2
2
 
3
3
  module Paghiper
4
4
  class MissingApiKeyError < StandardError; end
5
+ class MissingTokenError < StandardError; end
5
6
 
6
7
  class Client
7
8
  include HTTParty
@@ -11,20 +12,34 @@ module Paghiper
11
12
  debug_output $stdout if Paghiper.configuration && Paghiper.configuration.http_debug
12
13
 
13
14
  class << self
14
- def create_transaction(transaction)
15
- peform_action!(:post, '/transaction/create', body: prepare_body(transaction))
15
+ def create_transaction(data)
16
+ peform_action!(:post, '/transaction/create', body: prepare_body(data))
17
+ end
18
+
19
+ def transaction_notification(data)
20
+ raise(MissingTokenError, 'Informe o token para realizar essa operação') if missing_configuration_parameter?(:token)
21
+
22
+ peform_action!(:post, '/transaction/notification', body: data.merge(token: Paghiper.configuration.token).to_json)
16
23
  end
17
24
 
18
25
  private
19
26
 
27
+ def missing_configuration_parameter?(parameter)
28
+ return Paghiper.configuration.nil? || Paghiper.configuration.send(parameter).nil? || Paghiper.configuration.send(parameter).empty?
29
+ end
30
+
20
31
  def prepare_body(data)
21
32
  data.merge(apiKey: Paghiper.configuration.api_key).to_json
22
33
  end
23
34
 
24
35
  def peform_action!(action_name, url, options = {})
25
- raise(MissingTokenError, 'Informe a api key para realizar a autenticação') if Paghiper.configuration.api_key.nil? || Paghiper.configuration.api_key.empty?
36
+ raise(MissingApiKeyError, 'Informe a api key para realizar a autenticação') if missing_configuration_parameter?(:api_key)
37
+
38
+ parse_response(send(action_name, url, options))
39
+ end
26
40
 
27
- send(action_name, url, options)
41
+ def parse_response(response)
42
+ JSON.parse(response.body).with_indifferent_access
28
43
  end
29
44
  end
30
45
  end
@@ -3,9 +3,14 @@ module Paghiper
3
3
  class << self
4
4
  def create(transaction)
5
5
  response = Paghiper::Client.create_transaction(transaction)
6
- hash = JSON.parse(response.body).with_indifferent_access
7
6
 
8
- return hash['create_request']
7
+ return response['create_request']
8
+ end
9
+
10
+ def notification(notification)
11
+ response = Paghiper::Client.transaction_notification(notification)
12
+
13
+ return response['status_request']
9
14
  end
10
15
  end
11
16
  end
@@ -1,3 +1,3 @@
1
1
  module Paghiper
2
- VERSION = '0.1.1'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
@@ -1,4 +1,5 @@
1
1
  Paghiper.configure do |config|
2
2
  config.api_key = 'SUA API KEY'
3
+ config.token = 'SEU TOKEN'
3
4
  config.http_debug = true
4
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paghiper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Coyô Software
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-09-18 00:00:00.000000000 Z
11
+ date: 2018-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler