clearsaleID 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +6 -0
- data/.rspec +1 -0
- data/Gemfile +3 -0
- data/Guardfile +10 -0
- data/README.rdoc +112 -0
- data/Rakefile +6 -0
- data/clearsale.gemspec +33 -0
- data/lib/clearsale/analysis.rb +27 -0
- data/lib/clearsale/config.rb +24 -0
- data/lib/clearsale/connector.rb +61 -0
- data/lib/clearsale/logger_formatter_filter.rb +28 -0
- data/lib/clearsale/object.rb +27 -0
- data/lib/clearsale/order.rb +135 -0
- data/lib/clearsale/order_response.rb +50 -0
- data/lib/clearsale/version.rb +3 -0
- data/lib/clearsale.rb +11 -0
- data/spec/fixtures/clearsale.xml +10 -0
- data/spec/fixtures/filtered_clearsale.xml +10 -0
- data/spec/fixtures/vcr_cassettes/clearsale_get_order_status.yml +59 -0
- data/spec/fixtures/vcr_cassettes/clearsale_get_order_status_missing.yml +58 -0
- data/spec/fixtures/vcr_cassettes/clearsale_get_order_status_production.yml +60 -0
- data/spec/fixtures/vcr_cassettes/clearsale_send_orders.yml +76 -0
- data/spec/logger_formatter_spec.rb +56 -0
- data/spec/object_spec.rb +82 -0
- data/spec/order_response_spec.rb +35 -0
- data/spec/order_spec.rb +45 -0
- data/spec/requests/clearsale_spec.rb +70 -0
- data/spec/spec_helper.rb +23 -0
- data/spec/support/helpers.rb +81 -0
- metadata +281 -0
@@ -0,0 +1,58 @@
|
|
1
|
+
---
|
2
|
+
- !ruby/struct:VCR::HTTPInteraction
|
3
|
+
request: !ruby/struct:VCR::Request
|
4
|
+
method: :post
|
5
|
+
uri: http://homologacao.clearsale.com.br:80/Integracaov2/Service.asmx
|
6
|
+
body: <?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
7
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int="http://www.clearsale.com.br/integration"
|
8
|
+
xmlns:soap="http://www.w3.org/2003/05/soap-envelope"><soap:Body><int:GetOrderStatus><int:orderID>1234567890</int:orderID><int:entityCode>0E6F0C82-FC05-4AA7-86D4-EBBFC0FDC41A</int:entityCode></int:GetOrderStatus></soap:Body></soap:Envelope>
|
9
|
+
headers:
|
10
|
+
soapaction:
|
11
|
+
- '"http://www.clearsale.com.br/integration/GetOrderStatus"'
|
12
|
+
content-type:
|
13
|
+
- text/xml;charset=UTF-8
|
14
|
+
content-length:
|
15
|
+
- '551'
|
16
|
+
response: !ruby/struct:VCR::Response
|
17
|
+
status: !ruby/struct:VCR::ResponseStatus
|
18
|
+
code: 200
|
19
|
+
message: !binary |-
|
20
|
+
T0s=
|
21
|
+
headers:
|
22
|
+
!binary "ZGF0ZQ==":
|
23
|
+
- !binary |-
|
24
|
+
TW9uLCAwOSBBcHIgMjAxMiAxOToxMjoyNyBHTVQ=
|
25
|
+
!binary "c2VydmVy":
|
26
|
+
- !binary |-
|
27
|
+
TWljcm9zb2Z0LUlJUy82LjA=
|
28
|
+
!binary "eC1wb3dlcmVkLWJ5":
|
29
|
+
- !binary |-
|
30
|
+
QVNQLk5FVA==
|
31
|
+
!binary "eC1hc3BuZXQtdmVyc2lvbg==":
|
32
|
+
- !binary |-
|
33
|
+
Mi4wLjUwNzI3
|
34
|
+
!binary "Y2FjaGUtY29udHJvbA==":
|
35
|
+
- !binary |-
|
36
|
+
cHJpdmF0ZSwgbWF4LWFnZT0w
|
37
|
+
!binary "Y29udGVudC10eXBl":
|
38
|
+
- !binary |-
|
39
|
+
YXBwbGljYXRpb24vc29hcCt4bWw7IGNoYXJzZXQ9dXRmLTg=
|
40
|
+
!binary "Y29udGVudC1sZW5ndGg=":
|
41
|
+
- !binary |-
|
42
|
+
NTk5
|
43
|
+
body: !binary |-
|
44
|
+
PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48c29hcDpF
|
45
|
+
bnZlbG9wZSB4bWxuczpzb2FwPSJodHRwOi8vd3d3LnczLm9yZy8yMDAzLzA1
|
46
|
+
L3NvYXAtZW52ZWxvcGUiIHhtbG5zOnhzaT0iaHR0cDovL3d3dy53My5vcmcv
|
47
|
+
MjAwMS9YTUxTY2hlbWEtaW5zdGFuY2UiIHhtbG5zOnhzZD0iaHR0cDovL3d3
|
48
|
+
dy53My5vcmcvMjAwMS9YTUxTY2hlbWEiPjxzb2FwOkJvZHk+PEdldE9yZGVy
|
49
|
+
U3RhdHVzUmVzcG9uc2UgeG1sbnM9Imh0dHA6Ly93d3cuY2xlYXJzYWxlLmNv
|
50
|
+
bS5ici9pbnRlZ3JhdGlvbiI+PEdldE9yZGVyU3RhdHVzUmVzdWx0PiZsdDs/
|
51
|
+
eG1sIHZlcnNpb249IjEuMCIgZW5jb2Rpbmc9InV0Zi0xNiI/Jmd0Ow0KJmx0
|
52
|
+
O0NsZWFyU2FsZSZndDsNCiAgJmx0O09yZGVycyZndDsNCiAgICAmbHQ7T3Jk
|
53
|
+
ZXIgZDNwMTpuaWw9InRydWUiIHhtbG5zOmQzcDE9Imh0dHA6Ly93d3cudzMu
|
54
|
+
b3JnLzIwMDEvWE1MU2NoZW1hLWluc3RhbmNlIiAvJmd0Ow0KICAmbHQ7L09y
|
55
|
+
ZGVycyZndDsNCiZsdDsvQ2xlYXJTYWxlJmd0OzwvR2V0T3JkZXJTdGF0dXNS
|
56
|
+
ZXN1bHQ+PC9HZXRPcmRlclN0YXR1c1Jlc3BvbnNlPjwvc29hcDpCb2R5Pjwv
|
57
|
+
c29hcDpFbnZlbG9wZT4=
|
58
|
+
http_version: '1.1'
|
@@ -0,0 +1,60 @@
|
|
1
|
+
---
|
2
|
+
- !ruby/struct:VCR::HTTPInteraction
|
3
|
+
request: !ruby/struct:VCR::Request
|
4
|
+
method: :post
|
5
|
+
uri: https://www.clearsale.com.br/integracaov2/service.asmx
|
6
|
+
body: <?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
7
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int="http://www.clearsale.com.br/integration"
|
8
|
+
xmlns:soap="http://www.w3.org/2003/05/soap-envelope"><soap:Body><int:GetOrderStatus><int:orderID>TS1234</int:orderID><int:entityCode>0E6F0C82-FC05-4AA7-86D4-EBBFC0FDC41A</int:entityCode></int:GetOrderStatus></soap:Body></soap:Envelope>
|
9
|
+
headers:
|
10
|
+
soapaction:
|
11
|
+
- '"http://www.clearsale.com.br/integration/GetOrderStatus"'
|
12
|
+
content-type:
|
13
|
+
- text/xml;charset=UTF-8
|
14
|
+
content-length:
|
15
|
+
- '505'
|
16
|
+
response: !ruby/struct:VCR::Response
|
17
|
+
status: !ruby/struct:VCR::ResponseStatus
|
18
|
+
code: 200
|
19
|
+
message: !binary |-
|
20
|
+
T0s=
|
21
|
+
headers:
|
22
|
+
!binary "ZGF0ZQ==":
|
23
|
+
- !binary |-
|
24
|
+
V2VkLCAxMSBBcHIgMjAxMiAyMDozODowMCBHTVQ=
|
25
|
+
!binary "c2VydmVy":
|
26
|
+
- !binary |-
|
27
|
+
TWljcm9zb2Z0LUlJUy82LjA=
|
28
|
+
!binary "eC1wb3dlcmVkLWJ5":
|
29
|
+
- !binary |-
|
30
|
+
QVNQLk5FVA==
|
31
|
+
!binary "eC1hc3BuZXQtdmVyc2lvbg==":
|
32
|
+
- !binary |-
|
33
|
+
Mi4wLjUwNzI3
|
34
|
+
!binary "Y2FjaGUtY29udHJvbA==":
|
35
|
+
- !binary |-
|
36
|
+
cHJpdmF0ZSwgbWF4LWFnZT0w
|
37
|
+
!binary "Y29udGVudC10eXBl":
|
38
|
+
- !binary |-
|
39
|
+
YXBwbGljYXRpb24vc29hcCt4bWw7IGNoYXJzZXQ9dXRmLTg=
|
40
|
+
!binary "Y29udGVudC1sZW5ndGg=":
|
41
|
+
- !binary |-
|
42
|
+
NjYz
|
43
|
+
body: !binary |-
|
44
|
+
PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48c29hcDpF
|
45
|
+
bnZlbG9wZSB4bWxuczpzb2FwPSJodHRwOi8vd3d3LnczLm9yZy8yMDAzLzA1
|
46
|
+
L3NvYXAtZW52ZWxvcGUiIHhtbG5zOnhzaT0iaHR0cDovL3d3dy53My5vcmcv
|
47
|
+
MjAwMS9YTUxTY2hlbWEtaW5zdGFuY2UiIHhtbG5zOnhzZD0iaHR0cDovL3d3
|
48
|
+
dy53My5vcmcvMjAwMS9YTUxTY2hlbWEiPjxzb2FwOkJvZHk+PEdldE9yZGVy
|
49
|
+
U3RhdHVzUmVzcG9uc2UgeG1sbnM9Imh0dHA6Ly93d3cuY2xlYXJzYWxlLmNv
|
50
|
+
bS5ici9pbnRlZ3JhdGlvbiI+PEdldE9yZGVyU3RhdHVzUmVzdWx0PiZsdDs/
|
51
|
+
eG1sIHZlcnNpb249IjEuMCIgZW5jb2Rpbmc9InV0Zi0xNiI/Jmd0Ow0KJmx0
|
52
|
+
O0NsZWFyU2FsZSZndDsNCiAgJmx0O09yZGVycyZndDsNCiAgICAmbHQ7T3Jk
|
53
|
+
ZXImZ3Q7DQogICAgICAmbHQ7SUQmZ3Q7VFMxMjM0Jmx0Oy9JRCZndDsNCiAg
|
54
|
+
ICAgICZsdDtTdGF0dXMmZ3Q7QU1BJmx0Oy9TdGF0dXMmZ3Q7DQogICAgICAm
|
55
|
+
bHQ7U2NvcmUmZ3Q7MjEuMTEwMCZsdDsvU2NvcmUmZ3Q7DQogICAgJmx0Oy9P
|
56
|
+
cmRlciZndDsNCiAgJmx0Oy9PcmRlcnMmZ3Q7DQombHQ7L0NsZWFyU2FsZSZn
|
57
|
+
dDs8L0dldE9yZGVyU3RhdHVzUmVzdWx0PjwvR2V0T3JkZXJTdGF0dXNSZXNw
|
58
|
+
b25zZT48L3NvYXA6Qm9keT48L3NvYXA6RW52ZWxvcGU+
|
59
|
+
http_version: '1.1'
|
60
|
+
|
@@ -0,0 +1,76 @@
|
|
1
|
+
---
|
2
|
+
- !ruby/struct:VCR::HTTPInteraction
|
3
|
+
request: !ruby/struct:VCR::Request
|
4
|
+
method: :post
|
5
|
+
uri: http://homologacao.clearsale.com.br:80/Integracaov2/Service.asmx
|
6
|
+
body: <?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
7
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int="http://www.clearsale.com.br/integration"
|
8
|
+
xmlns:soap="http://www.w3.org/2003/05/soap-envelope"><soap:Body><int:SendOrders><int:xml><ClearSale><Orders><Order><ID>TS1234</ID><Date>2012-04-11T20:36:11</Date><Email>petergriffin@abc.com</Email><TotalItens>25.0</TotalItens><TotalOrder>20.0</TotalOrder><QtyInstallments>3</QtyInstallments><QtyItems>3</QtyItems><IP>127.0.0.1</IP><CollectionData><ID>8888</ID><Type>1</Type><LegalDocument1>24878346337</LegalDocument1><Name>Peter
|
9
|
+
Löwenbräu Griffin</Name><BirthDate>1972-04-11T20:36:11</BirthDate><Email>petergriffin@abc.com</Email><Genre>m</Genre><Address><Street>Bla
|
10
|
+
St</Street><Number>123</Number><Comp></Comp><County>Rhode
|
11
|
+
Island</County><City>Mayland</City><State>Maryland</State><ZipCode>00100-011</ZipCode></Address><Phones><Phone><Type>0</Type><DDD>11</DDD><Number>80011002</Number></Phone></Phones></CollectionData><ShippingData><ID>8888</ID><Type>1</Type><LegalDocument1>24878346337</LegalDocument1><Name>Peter
|
12
|
+
Löwenbräu Griffin</Name><BirthDate>1972-04-11T20:36:11</BirthDate><Email>petergriffin@abc.com</Email><Genre>m</Genre><Address><Street>Bla
|
13
|
+
St</Street><Number>123</Number><Comp></Comp><County>Rhode
|
14
|
+
Island</County><City>Mayland</City><State>Maryland</State><ZipCode>00100-011</ZipCode></Address><Phones><Phone><Type>0</Type><DDD>11</DDD><Number>80011002</Number></Phone></Phones></ShippingData><Payments><Payment><Date>2012-04-11T20:36:09</Date><Amount>20.0</Amount><PaymentTypeID>1</PaymentTypeID><QtyInstallments>3</QtyInstallments><CardNumber>2222</CardNumber><CardBin>1234432</CardBin><CardType>3</CardType><CardExpirationDate>05/2012</CardExpirationDate><Name>Peter
|
15
|
+
Löwenbräu Griffin</Name><LegalDocument>24878346337</LegalDocument><Address><Street>Bla
|
16
|
+
St</Street><Number>123</Number><Comp></Comp><County>Rhode
|
17
|
+
Island</County><City>Mayland</City><State>Maryland</State><ZipCode>00100-011</ZipCode></Address></Payment></Payments><Items><Item><ID>5555</ID><Name>Pogobol</Name><ItemValue>5.0</ItemValue><Qty>2</Qty><CategoryID>7777</CategoryID><CategoryName>Disney</CategoryName></Item><Item><ID>5555</ID><Name>Pogobol</Name><ItemValue>5.0</ItemValue><Qty>2</Qty><CategoryID>7777</CategoryID><CategoryName>Disney</CategoryName></Item></Items></Order></Orders></ClearSale></int:xml><int:entityCode>0E6F0C82-FC05-4AA7-86D4-EBBFC0FDC41A</int:entityCode></int:SendOrders></soap:Body></soap:Envelope>
|
18
|
+
headers:
|
19
|
+
soapaction:
|
20
|
+
- '"http://www.clearsale.com.br/integration/SendOrders"'
|
21
|
+
content-type:
|
22
|
+
- text/xml;charset=UTF-8
|
23
|
+
content-length:
|
24
|
+
- '3645'
|
25
|
+
response: !ruby/struct:VCR::Response
|
26
|
+
status: !ruby/struct:VCR::ResponseStatus
|
27
|
+
code: 200
|
28
|
+
message: !binary |-
|
29
|
+
T0s=
|
30
|
+
headers:
|
31
|
+
!binary "ZGF0ZQ==":
|
32
|
+
- !binary |-
|
33
|
+
V2VkLCAxMSBBcHIgMjAxMiAyMDozNjoxNSBHTVQ=
|
34
|
+
!binary "c2VydmVy":
|
35
|
+
- !binary |-
|
36
|
+
TWljcm9zb2Z0LUlJUy82LjA=
|
37
|
+
!binary "eC1wb3dlcmVkLWJ5":
|
38
|
+
- !binary |-
|
39
|
+
QVNQLk5FVA==
|
40
|
+
!binary "eC1hc3BuZXQtdmVyc2lvbg==":
|
41
|
+
- !binary |-
|
42
|
+
Mi4wLjUwNzI3
|
43
|
+
!binary "c2V0LWNvb2tpZQ==":
|
44
|
+
- !binary |-
|
45
|
+
QVNQLk5FVF9TZXNzaW9uSWQ9aXkyNG4wNTV1NXVrM3hpMDJtZ3Bwd25sOyBw
|
46
|
+
YXRoPS87IEh0dHBPbmx5
|
47
|
+
!binary "Y2FjaGUtY29udHJvbA==":
|
48
|
+
- !binary |-
|
49
|
+
cHJpdmF0ZSwgbWF4LWFnZT0w
|
50
|
+
!binary "Y29udGVudC10eXBl":
|
51
|
+
- !binary |-
|
52
|
+
YXBwbGljYXRpb24vc29hcCt4bWw7IGNoYXJzZXQ9dXRmLTg=
|
53
|
+
!binary "Y29udGVudC1sZW5ndGg=":
|
54
|
+
- !binary |-
|
55
|
+
ODE4
|
56
|
+
body: !binary |-
|
57
|
+
PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48c29hcDpF
|
58
|
+
bnZlbG9wZSB4bWxuczpzb2FwPSJodHRwOi8vd3d3LnczLm9yZy8yMDAzLzA1
|
59
|
+
L3NvYXAtZW52ZWxvcGUiIHhtbG5zOnhzaT0iaHR0cDovL3d3dy53My5vcmcv
|
60
|
+
MjAwMS9YTUxTY2hlbWEtaW5zdGFuY2UiIHhtbG5zOnhzZD0iaHR0cDovL3d3
|
61
|
+
dy53My5vcmcvMjAwMS9YTUxTY2hlbWEiPjxzb2FwOkJvZHk+PFNlbmRPcmRl
|
62
|
+
cnNSZXNwb25zZSB4bWxucz0iaHR0cDovL3d3dy5jbGVhcnNhbGUuY29tLmJy
|
63
|
+
L2ludGVncmF0aW9uIj48U2VuZE9yZGVyc1Jlc3VsdD4mbHQ7P3htbCB2ZXJz
|
64
|
+
aW9uPSIxLjAiIGVuY29kaW5nPSJ1dGYtMTYiPyZndDsNCiZsdDtQYWNrYWdl
|
65
|
+
U3RhdHVzJmd0Ow0KICAmbHQ7VHJhbnNhY3Rpb25JRCZndDtiMTg0NjQ0Zi1m
|
66
|
+
YmI1LTRjNWQtYTA0Zi1iZDE1NjRkZGYyYTgmbHQ7L1RyYW5zYWN0aW9uSUQm
|
67
|
+
Z3Q7DQogICZsdDtTdGF0dXNDb2RlJmd0OzAwJmx0Oy9TdGF0dXNDb2RlJmd0
|
68
|
+
Ow0KICAmbHQ7TWVzc2FnZSZndDtPSyZsdDsvTWVzc2FnZSZndDsNCiAgJmx0
|
69
|
+
O09yZGVycyZndDsNCiAgICAmbHQ7T3JkZXImZ3Q7DQogICAgICAmbHQ7SUQm
|
70
|
+
Z3Q7VFMxMjM0Jmx0Oy9JRCZndDsNCiAgICAgICZsdDtTdGF0dXMmZ3Q7QU1B
|
71
|
+
Jmx0Oy9TdGF0dXMmZ3Q7DQogICAgICAmbHQ7U2NvcmUmZ3Q7MjEuMTEwMCZs
|
72
|
+
dDsvU2NvcmUmZ3Q7DQogICAgJmx0Oy9PcmRlciZndDsNCiAgJmx0Oy9PcmRl
|
73
|
+
cnMmZ3Q7DQombHQ7L1BhY2thZ2VTdGF0dXMmZ3Q7PC9TZW5kT3JkZXJzUmVz
|
74
|
+
dWx0PjwvU2VuZE9yZGVyc1Jlc3BvbnNlPjwvc29hcDpCb2R5Pjwvc29hcDpF
|
75
|
+
bnZlbG9wZT4=
|
76
|
+
http_version: '1.1'
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'logger'
|
3
|
+
require 'tempfile'
|
4
|
+
|
5
|
+
describe Clearsale::LoggerFormatterFilter do
|
6
|
+
let(:tmp_file) { Tempfile.new('tagfilter') }
|
7
|
+
let(:logger) { Logger.new tmp_file }
|
8
|
+
|
9
|
+
let(:order_xml) { File.read('./spec/fixtures/clearsale.xml').chomp }
|
10
|
+
let(:filtered_order_xml) { File.read('./spec/fixtures/filtered_clearsale.xml').chomp }
|
11
|
+
|
12
|
+
after do
|
13
|
+
tmp_file.close
|
14
|
+
end
|
15
|
+
|
16
|
+
context "Initialize using tags and block" do
|
17
|
+
before do
|
18
|
+
logger.formatter = described_class.new(%w(CardNumber CardBin)) do |severity, datetime, progname, filtered_msg|
|
19
|
+
"#{severity} #{filtered_msg}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
it "filters the configured tag names using block" do
|
24
|
+
logger.info(order_xml)
|
25
|
+
tmp_file.rewind
|
26
|
+
tmp_file.read.should == "INFO #{filtered_order_xml}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "Initialize without block" do
|
31
|
+
before do
|
32
|
+
logger.formatter = described_class.new(%w(CardNumber CardBin))
|
33
|
+
end
|
34
|
+
|
35
|
+
it "filters the configured tag names" do
|
36
|
+
logger.info(order_xml)
|
37
|
+
tmp_file.rewind
|
38
|
+
tmp_file.read.end_with?(filtered_order_xml).should be_true
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context "Initialize without tags" do
|
43
|
+
before do
|
44
|
+
logger.formatter = described_class.new do |severity, datetime, progname, filtered_msg|
|
45
|
+
"#{severity} #{filtered_msg}"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
it "filters the configured tag names" do
|
50
|
+
logger.info(order_xml)
|
51
|
+
tmp_file.rewind
|
52
|
+
tmp_file.read.should == "INFO #{order_xml}"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
data/spec/object_spec.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Clearsale
|
4
|
+
describe Object do
|
5
|
+
describe "behavior it inherits from OpenStruct" do
|
6
|
+
it "can represent arbitrary data objects" do
|
7
|
+
ros = Object.new
|
8
|
+
ros.blah = "John Smith"
|
9
|
+
ros.blah.should == "John Smith"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "can be created from a hash" do
|
13
|
+
h = { :asdf => 'John Smith' }
|
14
|
+
ros = Object.new(h)
|
15
|
+
ros.asdf.should == "John Smith"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "can modify an existing key" do
|
19
|
+
h = { :blah => 'John Smith' }
|
20
|
+
ros = Object.new(h)
|
21
|
+
ros.blah = "George Washington"
|
22
|
+
ros.blah.should == "George Washington"
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "handling of arbitrary attributes" do
|
26
|
+
before(:each) do
|
27
|
+
@object = Object.new
|
28
|
+
@object.blah = "John Smith"
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#respond?" do
|
32
|
+
it { @object.should respond_to :blah }
|
33
|
+
it { @object.should respond_to :blah= }
|
34
|
+
it { @object.should_not respond_to :asdf }
|
35
|
+
it { @object.should_not respond_to :asdf= }
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "#methods" do
|
39
|
+
it { @object.methods.should include :blah }
|
40
|
+
it { @object.methods.should include :blah= }
|
41
|
+
it { @object.methods.should_not include :asdf }
|
42
|
+
it { @object.methods.should_not include :asdf= }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "recursive behavior" do
|
48
|
+
before(:each) do
|
49
|
+
h = { :blah => { :another => 'value'}, :list => [ { :foo => :bar } ] }
|
50
|
+
@object = Object.new(h)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "returns accessed hashes as Objects instead of hashes" do
|
54
|
+
@object.blah.another.should == 'value'
|
55
|
+
end
|
56
|
+
|
57
|
+
it "uses #key_as_a_hash to return key as a Hash" do
|
58
|
+
@object.blah_as_a_hash.should == { :another => 'value' }
|
59
|
+
end
|
60
|
+
|
61
|
+
it "return access hash as Object instead of hash even if it is inside a list" do
|
62
|
+
@object.list.first.foo.should == :bar
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "handling loops in the origin Hashes" do
|
66
|
+
before(:each) do
|
67
|
+
h1 = { :a => 'a'}
|
68
|
+
h2 = { :a => 'b', :h1 => h1 }
|
69
|
+
h1[:h2] = h2
|
70
|
+
@object = Object.new(h2)
|
71
|
+
end
|
72
|
+
|
73
|
+
it { @object.h1.a.should == 'a' }
|
74
|
+
it { @object.h1.h2.a.should == 'b' }
|
75
|
+
it { @object.h1.h2.h1.a.should == 'a' }
|
76
|
+
it { @object.h1.h2.h1.h2.a.should == 'b' }
|
77
|
+
it { @object.h1.should == @object.h1.h2.h1 }
|
78
|
+
it { @object.h1.should_not == @object.h1.h2 }
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Clearsale
|
4
|
+
describe OrderResponse do
|
5
|
+
describe "#approved?" do
|
6
|
+
let(:response) { {:orders=>{:order=>{:id=>"TS1234", :score=>"21.1100"}}} }
|
7
|
+
|
8
|
+
%w(APA APM).each do |status|
|
9
|
+
it "should return true if status return is: #{status}" do
|
10
|
+
response[:orders][:order][:status] = status
|
11
|
+
OrderResponse.new(response).should be_approved
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#rejected?" do
|
17
|
+
let(:response) { {:orders=>{:order=>{:id=>"TS1234", :score=>"21.1100"}}} }
|
18
|
+
|
19
|
+
%w(RPM SUS CAN).each do |status|
|
20
|
+
it "should return true if status return is: #{status}" do
|
21
|
+
response[:orders][:order][:status] = status
|
22
|
+
OrderResponse.new(response).should be_rejected
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#fraud?" do
|
28
|
+
let(:response) { {:orders=>{:order=>{:id=>"TS1234", :score=>"21.1100", :status => "FRD"}}} }
|
29
|
+
|
30
|
+
it "should return true if status return is FRD" do
|
31
|
+
OrderResponse.new(response).should be_fraud
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/spec/order_spec.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'timecop'
|
4
|
+
|
5
|
+
module Clearsale
|
6
|
+
describe Order do
|
7
|
+
before :each do
|
8
|
+
Timecop.freeze Time.parse('2012-07-01 11:13')
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:_order) { Object.new(order) }
|
12
|
+
let(:_payment) { Object.new(payment) }
|
13
|
+
let(:_user) { Object.new(user) }
|
14
|
+
|
15
|
+
describe ".to_xml" do
|
16
|
+
it "converts the order to xml successfully" do
|
17
|
+
described_class.to_xml(_order, _payment, _user).should eq '<ClearSale><Orders><Order><ID>1234</ID><Date>2012-07-01T11:13:00</Date><Email>petergriffin@abc.com</Email><TotalItens>20.0</TotalItens><TotalOrder>25.0</TotalOrder><QtyInstallments>3</QtyInstallments><QtyItems>3</QtyItems><IP>127.0.0.1</IP><CollectionData><ID>8888</ID><Type>1</Type><LegalDocument1>24878346337</LegalDocument1><Name>Peter Löwenbräu Griffin</Name><BirthDate>1972-07-01T11:13:00</BirthDate><Email>petergriffin@abc.com</Email><Genre>m</Genre><Address><Street>Billing Street</Street><Number>123</Number><Comp></Comp><County>Rhode Island</County><City>Mayland</City><State>Maryland</State><ZipCode>00100-011</ZipCode></Address><Phones><Phone><Type>0</Type><DDD>11</DDD><Number>80011002</Number></Phone></Phones></CollectionData><ShippingData><ID>8888</ID><Type>1</Type><LegalDocument1>24878346337</LegalDocument1><Name>Peter Löwenbräu Griffin</Name><BirthDate>1972-07-01T11:13:00</BirthDate><Email>petergriffin@abc.com</Email><Genre>m</Genre><Address><Street>Shipping Street</Street><Number>123</Number><Comp></Comp><County>Rhode Island</County><City>Mayland</City><State>Maryland</State><ZipCode>00100-011</ZipCode></Address><Phones><Phone><Type>0</Type><DDD>11</DDD><Number>80011002</Number></Phone></Phones></ShippingData><Payments><Payment><Date>2012-07-01T11:12:58</Date><Amount>50.0</Amount><PaymentTypeID>1</PaymentTypeID><QtyInstallments>3</QtyInstallments><CardNumber>1234432111112222</CardNumber><CardBin>123443</CardBin><CardType>3</CardType><CardExpirationDate>05/2012</CardExpirationDate><Name/><LegalDocument>24878346337</LegalDocument><Address><Street>Billing Street</Street><Number>123</Number><Comp></Comp><County>Rhode Island</County><City>Mayland</City><State>Maryland</State><ZipCode>00100-011</ZipCode></Address></Payment></Payments><Items><Item><ID>5555</ID><Name>Pogobol</Name><ItemValue>5.0</ItemValue><Qty>2</Qty><CategoryID>7777</CategoryID><CategoryName>Disney</CategoryName></Item><Item><ID>5555</ID><Name>Pogobol</Name><ItemValue>5.0</ItemValue><Qty>2</Qty><CategoryID>7777</CategoryID><CategoryName>Disney</CategoryName></Item></Items></Order></Orders></ClearSale>'
|
18
|
+
end
|
19
|
+
|
20
|
+
context "about credit card acquirer" do
|
21
|
+
it "should accept symbol" do
|
22
|
+
_payment.acquirer = :amex
|
23
|
+
described_class.to_xml(_order, _payment, _user).should include "<CardType>#{Clearsale::Order::CARD_TYPE_MAP[:amex]}</CardType>"
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should accept string" do
|
27
|
+
_payment.acquirer = 'amex'
|
28
|
+
described_class.to_xml(_order, _payment, _user).should include "<CardType>#{Clearsale::Order::CARD_TYPE_MAP[:amex]}</CardType>"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "when birthdate is empty" do
|
33
|
+
it "should not send birthdate" do
|
34
|
+
_user.birthdate = nil
|
35
|
+
described_class.to_xml(_order, _payment, _user).should_not include "<BirthDate>"
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should not send birthdate" do
|
39
|
+
_user.birthdate = nil
|
40
|
+
expect{ described_class.to_xml(_order, _payment, _user) }.to_not raise_error
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'clearsale'
|
4
|
+
require 'webmock/rspec'
|
5
|
+
|
6
|
+
describe 'Risk Analysis with ClearSale' do
|
7
|
+
let!(:vcs_params) { {:record => :none, :match_requests_on => [:method, :uri, :headers]} }
|
8
|
+
|
9
|
+
describe 'sending orders' do
|
10
|
+
it "returns the package response" do
|
11
|
+
VCR.use_cassette('clearsale_send_orders', vcs_params) do
|
12
|
+
response = Clearsale::Analysis.send_order(order, payment, user)
|
13
|
+
|
14
|
+
response.should be_manual_analysis
|
15
|
+
response.score.should be_within(0.01).of(21.11)
|
16
|
+
response.order_id.should eq(1234)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "updating order status" do
|
22
|
+
context "existing order" do
|
23
|
+
it "returns the package response" do
|
24
|
+
VCR.use_cassette('clearsale_get_order_status', vcs_params) do
|
25
|
+
response = Clearsale::Analysis.get_order_status('1234')
|
26
|
+
response.should be_manual_analysis
|
27
|
+
response.score.should be_within(0.01).of(21.11)
|
28
|
+
response.order_id.should eq(1234)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "missing order" do
|
34
|
+
it "returns the package response" do
|
35
|
+
VCR.use_cassette('clearsale_get_order_status_missing', vcs_params) do
|
36
|
+
order = double('Order', :id => 1234567890)
|
37
|
+
|
38
|
+
response = Clearsale::Analysis.get_order_status(order)
|
39
|
+
response.should be_inexistent_order
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "setting the environment" do
|
46
|
+
context "when CLEARSALE_ENV is production" do
|
47
|
+
it "should access production url" do
|
48
|
+
VCR.use_cassette('clearsale_get_order_status_production', vcs_params) do
|
49
|
+
Clearsale::Analysis.clear_connector
|
50
|
+
ENV["CLEARSALE_ENV"] = 'production'
|
51
|
+
Clearsale::Analysis.get_order_status('1234')
|
52
|
+
|
53
|
+
a_request(:post, "https://www.clearsale.com.br/integracaov2/service.asmx").should have_been_made
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "when CLEARSALE_ENV isn't production" do
|
59
|
+
it "should access production url" do
|
60
|
+
VCR.use_cassette('clearsale_get_order_status', vcs_params) do
|
61
|
+
Clearsale::Analysis.clear_connector
|
62
|
+
ENV["CLEARSALE_ENV"] = 'any'
|
63
|
+
Clearsale::Analysis.get_order_status('1234')
|
64
|
+
|
65
|
+
a_request(:post, "http://homologacao.clearsale.com.br/Integracaov2/Service.asmx").should have_been_made
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
Bundler.setup(:default)
|
4
|
+
require 'clearsale'
|
5
|
+
require 'vcr'
|
6
|
+
require 'savon'
|
7
|
+
|
8
|
+
HTTPI.log = false
|
9
|
+
|
10
|
+
Dir["./spec/support/**/*.rb"].each {|f| require f}
|
11
|
+
|
12
|
+
VCR.config do |c|
|
13
|
+
c.cassette_library_dir = File.expand_path('../../spec/fixtures/vcr_cassettes', __FILE__)
|
14
|
+
c.stub_with :webmock
|
15
|
+
c.default_cassette_options = { :record => :none }
|
16
|
+
c.allow_http_connections_when_no_cassette = false
|
17
|
+
end
|
18
|
+
|
19
|
+
RSpec.configure do |config|
|
20
|
+
config.mock_with :rspec
|
21
|
+
end
|
22
|
+
|
23
|
+
Clearsale::Config.log = false
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
def product
|
4
|
+
{
|
5
|
+
:id => 5555,
|
6
|
+
:name => 'Pogobol',
|
7
|
+
:category => { :id => 7777, :name => 'Disney' }
|
8
|
+
}
|
9
|
+
end
|
10
|
+
|
11
|
+
def item1
|
12
|
+
{
|
13
|
+
:product => product,
|
14
|
+
:price => 5.00,
|
15
|
+
:quantity => 2,
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
def billing_address
|
20
|
+
{
|
21
|
+
:street_name => 'Billing Street',
|
22
|
+
:number => '123',
|
23
|
+
:complement => '',
|
24
|
+
:neighborhood => 'Rhode Island',
|
25
|
+
:city => 'Mayland',
|
26
|
+
:state => 'Maryland',
|
27
|
+
:postal_code => '00100-011'
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
def shipping_address
|
32
|
+
{
|
33
|
+
:street_name => 'Shipping Street',
|
34
|
+
:number => '123',
|
35
|
+
:complement => '',
|
36
|
+
:neighborhood => 'Rhode Island',
|
37
|
+
:city => 'Mayland',
|
38
|
+
:state => 'Maryland',
|
39
|
+
:postal_code => '00100-011'
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
def user
|
44
|
+
{
|
45
|
+
:email => 'petergriffin@abc.com',
|
46
|
+
:id => 8888,
|
47
|
+
:cpf => '248.783.463-37',
|
48
|
+
:full_name => 'Peter Löwenbräu Griffin',
|
49
|
+
:birthdate => 40.years.ago,
|
50
|
+
:phone => '11 8001 1002',
|
51
|
+
:gender => 'm',
|
52
|
+
:last_sign_in_ip => '127.0.0.1',
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
def order
|
57
|
+
{
|
58
|
+
:id => 1234,
|
59
|
+
:paid_at => 2.seconds.ago,
|
60
|
+
:billing_address => billing_address,
|
61
|
+
:shipping_address => shipping_address,
|
62
|
+
:installments => 3,
|
63
|
+
:total_items => 20.00,
|
64
|
+
:total_order => 25.00,
|
65
|
+
:items_count => 3,
|
66
|
+
:created_at => Time.current,
|
67
|
+
:user => user,
|
68
|
+
:order_items => [item1, item1],
|
69
|
+
}
|
70
|
+
end
|
71
|
+
|
72
|
+
def payment
|
73
|
+
{
|
74
|
+
:card_holder => 'Petter L Griffin',
|
75
|
+
:card_number => '1234432111112222',
|
76
|
+
:card_expiration => '05/2012',
|
77
|
+
:card_security_code => '123',
|
78
|
+
:acquirer => 'visa',
|
79
|
+
:amount => 50.00,
|
80
|
+
}
|
81
|
+
end
|