pagseguro_next 1.0.1 → 1.0.2

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: eb0d9520494b52e758dc24754adce5056e7bd3838bebf18aade8e9e12be07c21
4
- data.tar.gz: b01d9f1954b4a03b0881e409b0f4b342f44498008c513e204df2fbb34cf7db90
3
+ metadata.gz: 412744374e66de13dd65e06ecaabb4e6b57787d53765f7d5d4c8a23225915d0e
4
+ data.tar.gz: e099b9a32083df965fc77c80a10bcb163a0b020f719a6725bd1e5a2acbbc44ba
5
5
  SHA512:
6
- metadata.gz: 2dbe1603b742149203287734b6838455a1dde4be580c19a6668350d2acb6411918f14c1b376755414d62b3cae7ffac0761135ab0e1dec23045c7715e9859a64a
7
- data.tar.gz: fddf07dd339714cdea4f280ae46c1a936edf7c26b704da2ed56a99965aacd4a775b6f7f6e59a9d6819dc5202451daf4882c18d994813038ef86c0023948b7690
6
+ metadata.gz: afe9ed2caf22a1e5e38cbea8c0c09e0c1ed857a1c1791b0d1b54c55a67159db23b5fa24f6c823e90194d2c9eb8c17e79c7d44ece0a21f5f178c94e0dbc2b774c
7
+ data.tar.gz: d8cf7e96bd8ddf49fc1fc0fbdde22550bfc70230934f999d3fcd5badcef146b0da5f46a24a387c82388b26d1022a2aad1ff4fa1e931534b0a896c96651f730e2
data/lib/pagseguro.rb CHANGED
@@ -19,9 +19,14 @@ module PagSeguro
19
19
  autoload :Transactions, "pagseguro/transactions"
20
20
  autoload :Mash, "pagseguro/mash"
21
21
 
22
+ ACCEPTS = {
23
+ json: "application/vnd.pagseguro.com.br.v3+xml;charset=ISO-8859-1",
24
+ xml: "application/vnd.pagseguro.com.br.v3+json;charset=ISO-8859-1"
25
+ }
26
+
22
27
  FORMATS = {
23
- json: "application/vnd.pagseguro.com.br.v3+json;charset=ISO-8859-1",
24
- xml: "application/xml;charset=ISO-8859-1"
28
+ json: "application/json",
29
+ xml: "application/xml"
25
30
  }
26
31
 
27
32
  mattr_accessor :token
@@ -26,7 +26,7 @@ module PagSeguro
26
26
  item do
27
27
  id params[:id]
28
28
  description { cdata(params[:description]) }
29
- amount format("%.2f", params[:amount].to_f)
29
+ amount format("%.2f", params[:amount])
30
30
  quantity 1
31
31
  end
32
32
  end
@@ -19,7 +19,7 @@ module PagSeguro
19
19
  conn.response :raise_error
20
20
  conn.adapter :net_http
21
21
  conn.params = auth_params
22
- conn.headers[:accept] = FORMATS[:json]
22
+ conn.headers[:accept] = ACCEPTS[:json]
23
23
  end
24
24
  end
25
25
 
@@ -5,10 +5,8 @@ module PagSeguro
5
5
  include Restful
6
6
 
7
7
  def create(params)
8
- params[:amount_per_payment] = to_money params[:amount_per_payment]
9
- params = parameterize params
10
-
11
- post("/pre-approvals/request", preApproval: params)
8
+ xml = build_request(params).to_xml
9
+ post_xml("/pre-approvals/request", xml)
12
10
  end
13
11
 
14
12
  def update(code, params)
@@ -22,5 +20,20 @@ module PagSeguro
22
20
  def to_money(value)
23
21
  format "%.2f", value.to_f
24
22
  end
23
+
24
+ def build_request(params)
25
+ builder do
26
+ preApprovalRequest do
27
+ reference params[:reference]
28
+ preApproval do
29
+ charge params[:charge]
30
+ name { cdata(params[:name]) }
31
+ details { cdata(params[:details]) }
32
+ period params[:period]
33
+ amountPerPayment format("%.2f", params[:amount_per_payment])
34
+ end
35
+ end
36
+ end
37
+ end
25
38
  end
26
39
  end
@@ -13,12 +13,12 @@ module PagSeguro
13
13
  end
14
14
 
15
15
  protected
16
- def get(path, options = nil, &block)
17
- connection.get(path, options, &block).body
16
+ def get(path, options = nil, headers = nil)
17
+ connection.get(path, options, headers).body
18
18
  end
19
19
 
20
- def post(path, options = nil, &block)
21
- connection.post(path, options, &block).body
20
+ def post(path, options = nil, headers = nil)
21
+ connection.post(path, options, headers).body
22
22
  end
23
23
 
24
24
  def put(path, options = {})
@@ -33,30 +33,24 @@ module PagSeguro
33
33
  connection.delete(path, options).body
34
34
  end
35
35
 
36
+ def xml_headers
37
+ { accept: ACCEPTS[:xml], content_type: FORMATS[:xml] }
38
+ end
39
+
36
40
  def get_xml(path, options = nil)
37
- get(path, options) do |conn|
38
- conn.headers[:content_type] = FORMATS[:xml]
39
- conn.headers[:accept] = FORMATS[:xml]
40
- end
41
+ get(path, options, xml_headers)
41
42
  end
42
43
 
43
44
  def post_xml(path, options = nil)
44
- post(path) do |conn|
45
- conn.headers[:content_type] = FORMATS[:xml]
46
- conn.headers[:accept] = FORMATS[:xml]
47
- end
45
+ post(path, options, xml_headers)
48
46
  end
49
47
 
50
48
  def parameterize(hash)
51
- hash.as_json.deep_transform_keys! do |key|
52
- key.to_s.camelize(:lower)
53
- end
49
+ hash.as_json.deep_transform_keys! { |key| key.to_s.camelize(:lower) }
54
50
  end
55
51
 
56
52
  def builder(&block)
57
- Nokogiri::XML::Builder.new do |xml|
58
- xml.instance_eval(&block)
59
- end
53
+ Nokogiri::XML::Builder.new { |xml| xml.instance_eval(&block) }
60
54
  end
61
55
  end
62
56
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PagSeguro
4
- VERSION = "1.0.1"
4
+ VERSION = "1.0.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pagseguro_next
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rainer Borene
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-07 00:00:00.000000000 Z
11
+ date: 2020-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday