pag_seguro 0.5.4 → 0.5.5

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: 3bbfb84a631ab24786de12bc5e7a16a107d09790
4
- data.tar.gz: a9c38a18d3194f2962e58d9813597c162aac5cc6
3
+ metadata.gz: 7aff3540c942b98fb40649b198be4433f1180b46
4
+ data.tar.gz: 47906c183829ac71ce7187f0d250893e91f16aa4
5
5
  SHA512:
6
- metadata.gz: bf1a7901bec996be24ca3b9f85adde8508a7cea7a5e0c05ba143c086a628be9cc110aa7976861a5251dab76107ad5eba3bf8ad6f890307ecc894615fe0b31e50
7
- data.tar.gz: 0438005dd35769dc354816e7be964d892e68b4e2c60d444ca2bfeea5a8c2c8b9f3088b7344cbfebbc16ecfed5dd707f696052edc9fbaaaa6b12b823d3bc27d8c
6
+ metadata.gz: 36cadf61f5dabceb2d71d571053e8aea72eca02a4f29a4f2a481a53d329b46be6140c22a466f0076e0613fe0daf3ab2e94a02385198688689a22cb8030c8dccc
7
+ data.tar.gz: 6d950e06ad9ee88d5b6c8437a8c391f0ee5a9f72e559ccc3518a64a3570ffd6a7c709f27755f99c4d11d50cb021bd257002cf8ebfcb1f4ae34c34d79c4578a50
@@ -3,9 +3,13 @@ module PagSeguro
3
3
  include ActiveModel::Validations
4
4
  extend PagSeguro::ConvertFieldToDigit
5
5
 
6
+ CHECKOUT_URL = "https://ws.pagseguro.uol.com.br/v2/checkout"
7
+
6
8
  attr_accessor :id, :email, :token, :items, :sender, :shipping,
7
9
  :extra_amount, :redirect_url, :max_uses, :max_age,
8
10
  :response, :pre_approval
11
+ alias :reference :id
12
+ alias :reference= :id=
9
13
 
10
14
  attr_reader_as_digit :extra_amount
11
15
 
@@ -17,7 +21,7 @@ module PagSeguro
17
21
  def initialize(email = nil, token = nil, options = {})
18
22
  @email = email unless email.nil?
19
23
  @token = token unless token.nil?
20
- @id = options[:id]
24
+ @id = options[:id] || options[:reference]
21
25
  @sender = options[:sender] || Sender.new
22
26
  @shipping = options[:shipping]
23
27
  @items = options[:items] || []
@@ -44,10 +48,6 @@ module PagSeguro
44
48
  pre_approval: @pre_approval
45
49
  end
46
50
 
47
- def checkout_url_with_params
48
- "https://ws.pagseguro.uol.com.br/v2/checkout?email=#{@email}&token=#{@token}"
49
- end
50
-
51
51
  def checkout_payment_url
52
52
  self.class.checkout_payment_url(code)
53
53
  end
@@ -92,7 +92,10 @@ module PagSeguro
92
92
  end
93
93
 
94
94
  def send_checkout
95
- RestClient.post(checkout_url_with_params, checkout_xml, content_type: "application/xml"){|resp, request, result| resp }
95
+ params = { email: @email, token: @token }
96
+ RestClient.post(CHECKOUT_URL, checkout_xml,
97
+ params: params,
98
+ content_type: "application/xml"){|resp, request, result| resp }
96
99
  end
97
100
 
98
101
  def parse_checkout_response
@@ -42,6 +42,7 @@ module PagSeguro
42
42
  def id
43
43
  @data.css("reference").first.content
44
44
  end
45
+ alias :reference :id
45
46
 
46
47
  def gross_amount
47
48
  @data.css("grossAmount").first.content
@@ -1,3 +1,3 @@
1
1
  module PagSeguro
2
- VERSION = "0.5.4"
2
+ VERSION = "0.5.5"
3
3
  end
@@ -20,6 +20,11 @@ describe PagSeguro::Payment do
20
20
  it { should respond_to :code }
21
21
  it { should respond_to :date }
22
22
 
23
+ describe "::CHECKOUT_URL" do
24
+ subject { PagSeguro::Payment::CHECKOUT_URL }
25
+ it { should == "https://ws.pagseguro.uol.com.br/v2/checkout" }
26
+ end
27
+
23
28
  describe '#date' do
24
29
  subject{ payment.send(:parse_date) }
25
30
  before{ payment.stub response: double(:response, body: '<checkout><date>2001-02-03T04:05:06+07:00</date></checkout>') }
@@ -87,16 +92,18 @@ describe PagSeguro::Payment do
87
92
  it { should be_valid }
88
93
  end
89
94
 
95
+ context 'using reference instead of id' do
96
+ subject { build :payment_with_item, id: nil, reference: "REF1234" }
97
+ its(:id){ should == "REF1234" }
98
+ its(:reference){ should == "REF1234" }
99
+ end
100
+
90
101
  context 'checking out' do
91
102
  let(:payment){ build(:payment) }
92
103
  it 'should generate a checkout url with an external code' do
93
104
  PagSeguro::Payment.checkout_payment_url('aabbcc').should == 'https://pagseguro.uol.com.br/v2/checkout/payment.html?code=aabbcc'
94
105
  end
95
106
 
96
- it 'should have a checkout_url_with_params' do
97
- payment.checkout_url_with_params.should == 'https://ws.pagseguro.uol.com.br/v2/checkout?email=myemail&token=mytoken'
98
- end
99
-
100
107
  it 'should generate a checkout url based on the received response' do
101
108
  payment.stub code: 'aabbcc'
102
109
  payment.checkout_payment_url.should == 'https://pagseguro.uol.com.br/v2/checkout/payment.html?code=aabbcc'
@@ -180,4 +187,19 @@ describe PagSeguro::Payment do
180
187
  payment.date
181
188
  end
182
189
  end
190
+
191
+ describe "#send_checkout" do
192
+ let(:payment){ PagSeguro::Payment.new "email@mail.com", "sometoken" }
193
+ it "should call pagseguro's webservice" do
194
+ checkout_xml = double(:checkout_xml)
195
+ payment.stub(checkout_xml: checkout_xml)
196
+ params = { email: "email@mail.com", token: "sometoken" }
197
+ RestClient.should_receive(:post).with(
198
+ PagSeguro::Payment::CHECKOUT_URL,
199
+ checkout_xml,
200
+ params: params,
201
+ content_type: "application/xml")
202
+ payment.send :send_checkout
203
+ end
204
+ end
183
205
  end
@@ -6,6 +6,10 @@ shared_examples_for "a transaction" do
6
6
  it "should have an id" do
7
7
  transaction.id.should == "REF1234"
8
8
  end
9
+
10
+ it "should have a reference" do
11
+ transaction.reference.should == "REF1234"
12
+ end
9
13
 
10
14
  it "should have a transaction id" do
11
15
  transaction.transaction_id.should == "9E884542-81B3-4419-9A75-BCC6FB495EF1"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pag_seguro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefano Diem Benatti