pagseguro-transparente 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5bded741d632c18a8084ba26f6c68d1558a45c63
4
- data.tar.gz: 8728cf5493e7558ca19f0fb73e87233f9f04029a
3
+ metadata.gz: c6d9a17bb3227f4fec059c6496f029db3a401056
4
+ data.tar.gz: b030e0427c75239ec9d9d779ab258f79ab0e7902
5
5
  SHA512:
6
- metadata.gz: e38f168f5797e5d2a94465154fddcaedd634581cb5c4e113d4c5a16213adcdfca35281365334d9b84e247ddb842abf665e843f065936279be9d0270786d4a48b
7
- data.tar.gz: 32b20d9c212f78bd666f627d01fe8858f4ed7129d47c30f8f13ac4a0bc4a3c1373e6e95fe699466203fd69824cd9443ee2328e6403148854040c795475b8adb1
6
+ metadata.gz: 1101539192b9077467a2f133c8f6234573bfcf471f3d7ff447c82f3904e13f1b87197204eaad12958b3d128ca4a1576a2c1a1af3398d3587321301a7499091c7
7
+ data.tar.gz: 64f1444db3180da20b647c1ff3e5a7377d3ebf33f477c9ae63a8db85b7aeaecc41fb7c21a66012dbe0e5f1411ddd740ea9531f7b9b615e733b5bd47700ed32ec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pagseguro-transparente (0.1.2)
4
+ pagseguro-transparente (0.2.0)
5
5
  activemodel
6
6
  httparty (~> 0.13)
7
7
  i18n (~> 0.6)
@@ -32,18 +32,18 @@ GEM
32
32
  safe_yaml (~> 1.0.0)
33
33
  diff-lcs (1.2.5)
34
34
  docile (1.1.3)
35
- httparty (0.13.1)
35
+ httparty (0.13.3)
36
36
  json (~> 1.8)
37
37
  multi_xml (>= 0.5.2)
38
38
  i18n (0.6.9)
39
39
  json (1.8.1)
40
40
  mime-types (2.2)
41
- mini_portile (0.6.0)
41
+ mini_portile (0.6.1)
42
42
  minitest (5.3.4)
43
43
  multi_json (1.10.0)
44
44
  multi_xml (0.5.5)
45
- nokogiri (1.6.2.1)
46
- mini_portile (= 0.6.0)
45
+ nokogiri (1.6.4.1)
46
+ mini_portile (~> 0.6.0)
47
47
  rake (10.3.2)
48
48
  rest-client (1.6.7)
49
49
  mime-types (>= 1.16)
data/lib/pagseguro.rb CHANGED
@@ -33,12 +33,18 @@ I18n.load_path += Dir[File.expand_path('../../config/locales/*.yml', __FILE__)]
33
33
 
34
34
  module PagSeguro
35
35
  class << self
36
- # Primary e-mail associated with this account.
36
+ # Primary e-mail associated with the primary account.
37
37
  attr_accessor :email
38
38
 
39
- # The API token associated with this account.
39
+ # The API token associated with primary account.
40
40
  attr_accessor :token
41
41
 
42
+ # Sencondary e-mail associated with secondary account.
43
+ attr_accessor :alt_email
44
+
45
+ # The API token associated with secondary account.
46
+ attr_accessor :alt_token
47
+
42
48
  # The PagSeguro environment.
43
49
  # Only +production+ for now.
44
50
  attr_accessor :environment
@@ -9,8 +9,8 @@ module PagSeguro
9
9
  @token = token
10
10
  end
11
11
 
12
- def transaction
13
- PagSeguro::Transaction.new get("/transactions/notifications/#{code}")
12
+ def transaction(account = nil)
13
+ PagSeguro::Transaction.new get("/transactions/notifications/#{code}", account)
14
14
  end
15
15
  end
16
16
  end
@@ -64,9 +64,9 @@ module PagSeguro
64
64
  end
65
65
 
66
66
  # Calls the PagSeguro web service and register this request for payment.
67
- def transaction
67
+ def transaction(account = nil)
68
68
  params = Serializer.new(self).to_params
69
- PagSeguro::Transaction.new post('/transactions', params).parsed_response
69
+ PagSeguro::Transaction.new post('/transactions', account, params).parsed_response
70
70
  end
71
71
 
72
72
  def initialize(options = {})
@@ -6,8 +6,8 @@ module PagSeguro
6
6
  @code = code
7
7
  end
8
8
 
9
- def transaction
10
- PagSeguro::Transaction.new get("/transactions/#{code}")
9
+ def transaction(account = nil)
10
+ PagSeguro::Transaction.new get("/transactions/#{code}", account)
11
11
  end
12
12
  end
13
13
  end
@@ -7,9 +7,8 @@ module PagSeguro
7
7
  @request = {}
8
8
  end
9
9
 
10
- def request
11
- @request = post("/transactions/refunds", transactionCode: @transaction_code)
12
-
10
+ def request(account = nil)
11
+ @request = post("/transactions/refunds", account, transactionCode: @transaction_code)
13
12
  @request.response.code == '200'
14
13
  end
15
14
 
@@ -7,31 +7,24 @@ module PagSeguro
7
7
 
8
8
  base_uri "https://ws.pagseguro.uol.com.br/v2/"
9
9
 
10
- def get(path)
11
- options = { query: {
12
- email: PagSeguro.email,
13
- token: PagSeguro.token
14
- }
15
- }
10
+ def get(path, account = "default")
11
+ options = { query: add_credencials(account) }
16
12
  self.class.get(path, options)
17
13
  end
18
14
 
19
- def post(path, params = {})
20
- options = add_credencials(params)
21
-
15
+ def post(path, account = "default", params = {})
16
+ options = { body: add_credencials(account) }
17
+ options[:body].merge!(params)
22
18
  self.class.post(path, options)
23
19
  end
24
20
 
25
21
  private
26
- def add_credencials(params)
27
- options = { body:
28
- {
29
- email: PagSeguro.email,
30
- token: PagSeguro.token
31
- }
32
- }
33
- options[:body].merge!(params)
34
- options
22
+ def add_credencials(account, params = nil)
23
+ if account == "alternative"
24
+ { email: PagSeguro.alt_email, token: PagSeguro.alt_token }
25
+ else
26
+ { email: PagSeguro.email, token: PagSeguro.token }
27
+ end
35
28
  end
36
29
  end
37
30
  end
@@ -1,7 +1,7 @@
1
1
  module PagSeguro
2
2
  class Session < Request
3
- def create
4
- Response.new post('/sessions').parsed_response
3
+ def create(account = nil)
4
+ Response.new post('/sessions', account).parsed_response
5
5
  end
6
6
  end
7
7
  end
@@ -1,3 +1,3 @@
1
1
  module PagSeguro
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -12,6 +12,8 @@ describe PagSeguro::Notification do
12
12
  before do
13
13
  PagSeguro.email = 'mail'
14
14
  PagSeguro.token = 'token'
15
+ PagSeguro.alt_email = 'alt_mail'
16
+ PagSeguro.alt_token = 'alt_token'
15
17
  end
16
18
 
17
19
  describe "#transaction" do
@@ -24,5 +26,15 @@ describe PagSeguro::Notification do
24
26
 
25
27
  it { should be_a_kind_of(PagSeguro::Transaction) }
26
28
  end
29
+
30
+ context "with secondary credencials" do
31
+ subject { notification.transaction("alternative") }
32
+ before do
33
+ stub_request(:get, "https://ws.pagseguro.uol.com.br/v2/transactions/notifications/766B9C-AD4B044B04DA-77742F5FA653-E1AB24?email=alt_mail&token=alt_token").
34
+ to_return(:status => 200, :body => "", :headers => {})
35
+ end
36
+
37
+ it { should be_a_kind_of(PagSeguro::Transaction) }
38
+ end
27
39
  end
28
40
  end
@@ -11,6 +11,8 @@ describe PagSeguro::Query do
11
11
  before do
12
12
  PagSeguro.email = 'mail'
13
13
  PagSeguro.token = 'token'
14
+ PagSeguro.alt_email = 'alt_mail'
15
+ PagSeguro.alt_token = 'alt_token'
14
16
  end
15
17
 
16
18
  describe "#transaction" do
@@ -22,4 +24,14 @@ describe PagSeguro::Query do
22
24
 
23
25
  it { should be_a_kind_of(PagSeguro::Transaction) }
24
26
  end
27
+
28
+ describe "with secondary credencials" do
29
+ subject { query.transaction("alternative") }
30
+ before do
31
+ stub_request(:get, "https://ws.pagseguro.uol.com.br/v2/transactions/64C4CB1E-5FF2-4092-BE17-CACE271D789E?email=alt_mail&token=alt_token").
32
+ to_return(:status => 200, :body => "", :headers => {})
33
+ end
34
+
35
+ it { should be_a_kind_of(PagSeguro::Transaction) }
36
+ end
25
37
  end
@@ -11,6 +11,8 @@ describe PagSeguro::Refund do
11
11
  before do
12
12
  PagSeguro.email = 'mail'
13
13
  PagSeguro.token = 'token'
14
+ PagSeguro.alt_email = 'alt_mail'
15
+ PagSeguro.alt_token = 'alt_token'
14
16
  end
15
17
 
16
18
  describe "#request" do
@@ -29,6 +31,18 @@ describe PagSeguro::Refund do
29
31
  it { expect(subject).to be_true }
30
32
  end
31
33
 
34
+ context "alternative successful refund" do
35
+ subject { refund.request('alternative') }
36
+
37
+ before do
38
+ stub_request(:post, "https://ws.pagseguro.uol.com.br/v2/transactions/refunds").
39
+ with(:body => "email=alt_mail&token=alt_token&transactionCode=766B9C-AD4B044B04DA-77742F5FA653-E1AB24").
40
+ to_return(:status => 200, :body => "<?xml version='1.0' encoding='ISO-8859-1' standalone='yes'?> <result>OK</result>", :headers => {'Content-Type' => 'application/xml;charset=ISO-8859-1'})
41
+ end
42
+
43
+ it { expect(subject).to be_true }
44
+ end
45
+
32
46
  context "unsuccessfull refund" do
33
47
  let(:single_error) { "<?xml version='1.0' encoding='ISO-8859-1' standalone='yes'?><errors><error><code>14006</code><message>insufficient balance to refund transaction.</message></error></errors>" }
34
48
  let(:multiple_errors) { "<?xml version='1.0' encoding='ISO-8859-1' standalone='yes'?><errors><error><code>14006</code><message>insufficient balance to refund transaction.</message></error><error><code>14007</code><message>invalid transaction status to refund.</message></error></errors>" }
@@ -22,5 +22,15 @@ describe PagSeguro::Session do
22
22
 
23
23
  it { should be_a_kind_of(PagSeguro::Session::Response) }
24
24
  end
25
+
26
+ context 'with alternative email and token' do
27
+ subject { session.create('alternative') }
28
+ before do
29
+ stub_request(:post, "https://ws.pagseguro.uol.com.br/v2/sessions").
30
+ with(body: "email=alt_mail&token=alt_token").to_return(status: 200)
31
+ end
32
+
33
+ it { should be_a_kind_of(PagSeguro::Session::Response) }
34
+ end
25
35
  end
26
36
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pagseguro-transparente
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cirdes Henrique
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-08-13 00:00:00.000000000 Z
12
+ date: 2014-11-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel