pag_seguro 0.5.4 → 0.5.5
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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7aff3540c942b98fb40649b198be4433f1180b46
|
4
|
+
data.tar.gz: 47906c183829ac71ce7187f0d250893e91f16aa4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36cadf61f5dabceb2d71d571053e8aea72eca02a4f29a4f2a481a53d329b46be6140c22a466f0076e0613fe0daf3ab2e94a02385198688689a22cb8030c8dccc
|
7
|
+
data.tar.gz: 6d950e06ad9ee88d5b6c8437a8c391f0ee5a9f72e559ccc3518a64a3570ffd6a7c709f27755f99c4d11d50cb021bd257002cf8ebfcb1f4ae34c34d79c4578a50
|
data/lib/pag_seguro/payment.rb
CHANGED
@@ -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
|
-
|
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
|
data/lib/pag_seguro/version.rb
CHANGED
@@ -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"
|