better-mundipagg 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Berksfile +3 -0
- data/Berksfile.lock +59 -0
- data/Gemfile.lock +35 -3
- data/Vagrantfile +40 -0
- data/lib/mundipagg/boleto.rb +30 -0
- data/lib/mundipagg/client.rb +30 -0
- data/lib/mundipagg/credit_card.rb +52 -0
- data/lib/mundipagg/error.rb +10 -0
- data/lib/mundipagg/gateway.rb +35 -0
- data/lib/mundipagg/key.rb +21 -0
- data/lib/mundipagg/message.rb +18 -0
- data/lib/mundipagg/refund.rb +28 -0
- data/lib/mundipagg/response.rb +27 -0
- data/lib/mundipagg/version.rb +1 -1
- data/lib/mundipagg.rb +10 -19
- data/mundipagg.gemspec +3 -0
- data/spec/fixtures/vcr_cassettes/Mundipagg_Client/_create_order/sends_a_create_order_command.yml +150 -0
- data/spec/fixtures/vcr_cassettes/Mundipagg_Client/_manage_order/sends_a_manager_order_command.yml +149 -0
- data/spec/fixtures/vcr_cassettes/Mundipagg_Gateway_Client/_create_order/sends_a_create_order_command.yml +150 -0
- data/spec/fixtures/vcr_cassettes/Mundipagg_Gateway_Client/_manage_order/sends_a_manager_order_command.yml +149 -0
- data/spec/lib/mundipagg/boleto_spec.rb +67 -0
- data/spec/lib/mundipagg/client_spec.rb +79 -0
- data/spec/lib/mundipagg/credit_card_spec.rb +117 -0
- data/spec/lib/mundipagg/gateway_spec.rb +82 -0
- data/spec/lib/mundipagg/{gateway/message_spec.rb → message_spec.rb} +1 -1
- data/spec/lib/mundipagg/refund_spec.rb +65 -0
- data/spec/lib/mundipagg/response_spec.rb +43 -0
- data/spec/spec_helper.rb +14 -3
- metadata +67 -12
- data/lib/mundipagg/buyer.rb +0 -4
- data/lib/mundipagg/gateway/client.rb +0 -28
- data/lib/mundipagg/gateway/key.rb +0 -23
- data/lib/mundipagg/gateway/message.rb +0 -20
- data/lib/mundipagg/order.rb +0 -26
- data/lib/mundipagg/transaction/boleto.rb +0 -23
- data/spec/lib/mundipagg/gateway/client_spec.rb +0 -23
- data/spec/lib/mundipagg/order_spec.rb +0 -54
- data/spec/lib/mundipagg/transaction/boleto_spec.rb +0 -18
@@ -0,0 +1,149 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://transaction.mundipaggone.com/MundiPaggService.svc?wsdl
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept-Encoding:
|
11
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
|
+
Accept:
|
13
|
+
- "*/*"
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Content-Type:
|
22
|
+
- text/xml; charset=UTF-8
|
23
|
+
Vary:
|
24
|
+
- Accept-Encoding
|
25
|
+
Server:
|
26
|
+
- Microsoft-IIS/8.0
|
27
|
+
X-Powered-By:
|
28
|
+
- ASP.NET
|
29
|
+
Date:
|
30
|
+
- Mon, 05 Jan 2015 19:19:01 GMT
|
31
|
+
Content-Length:
|
32
|
+
- '1437'
|
33
|
+
body:
|
34
|
+
encoding: UTF-8
|
35
|
+
string: <?xml version="1.0" encoding="utf-8"?><wsdl:definitions name="MundiPaggService"
|
36
|
+
targetNamespace="http://tempuri.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
|
37
|
+
xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
|
38
|
+
xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
|
39
|
+
xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract"
|
40
|
+
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
|
41
|
+
xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
42
|
+
xmlns:tns="http://tempuri.org/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
|
43
|
+
xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"><wsp:Policy
|
44
|
+
wsu:Id="basicHttp_policy"><wsp:ExactlyOne><wsp:All><sp:TransportBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy"><wsp:Policy><sp:TransportToken><wsp:Policy><sp:HttpsToken
|
45
|
+
RequireClientCertificate="false"/></wsp:Policy></sp:TransportToken><sp:AlgorithmSuite><wsp:Policy><sp:Basic256/></wsp:Policy></sp:AlgorithmSuite><sp:Layout><wsp:Policy><sp:Strict/></wsp:Policy></sp:Layout></wsp:Policy></sp:TransportBinding></wsp:All></wsp:ExactlyOne></wsp:Policy><wsdl:types><xsd:schema
|
46
|
+
targetNamespace="http://tempuri.org/Imports"><xsd:import schemaLocation="https://transaction.mundipaggone.com/MundiPaggService.svc?xsd=xsd0"
|
47
|
+
namespace="http://tempuri.org/"/><xsd:import schemaLocation="https://transaction.mundipaggone.com/MundiPaggService.svc?xsd=xsd1"
|
48
|
+
namespace="http://schemas.microsoft.com/2003/10/Serialization/"/><xsd:import
|
49
|
+
schemaLocation="https://transaction.mundipaggone.com/MundiPaggService.svc?xsd=xsd2"
|
50
|
+
namespace="http://schemas.datacontract.org/2004/07/MundiPagg.One.Service.DataContracts"/></xsd:schema></wsdl:types><wsdl:message
|
51
|
+
name="MundiPaggService_CreateOrder_InputMessage"><wsdl:part name="parameters"
|
52
|
+
element="tns:CreateOrder"/></wsdl:message><wsdl:message name="MundiPaggService_CreateOrder_OutputMessage"><wsdl:part
|
53
|
+
name="parameters" element="tns:CreateOrderResponse"/></wsdl:message><wsdl:message
|
54
|
+
name="MundiPaggService_ManageOrder_InputMessage"><wsdl:part name="parameters"
|
55
|
+
element="tns:ManageOrder"/></wsdl:message><wsdl:message name="MundiPaggService_ManageOrder_OutputMessage"><wsdl:part
|
56
|
+
name="parameters" element="tns:ManageOrderResponse"/></wsdl:message><wsdl:message
|
57
|
+
name="MundiPaggService_QueryOrder_InputMessage"><wsdl:part name="parameters"
|
58
|
+
element="tns:QueryOrder"/></wsdl:message><wsdl:message name="MundiPaggService_QueryOrder_OutputMessage"><wsdl:part
|
59
|
+
name="parameters" element="tns:QueryOrderResponse"/></wsdl:message><wsdl:message
|
60
|
+
name="MundiPaggService_GetInstantBuyData_InputMessage"><wsdl:part name="parameters"
|
61
|
+
element="tns:GetInstantBuyData"/></wsdl:message><wsdl:message name="MundiPaggService_GetInstantBuyData_OutputMessage"><wsdl:part
|
62
|
+
name="parameters" element="tns:GetInstantBuyDataResponse"/></wsdl:message><wsdl:message
|
63
|
+
name="MundiPaggService_RetryOrder_InputMessage"><wsdl:part name="parameters"
|
64
|
+
element="tns:RetryOrder"/></wsdl:message><wsdl:message name="MundiPaggService_RetryOrder_OutputMessage"><wsdl:part
|
65
|
+
name="parameters" element="tns:RetryOrderResponse"/></wsdl:message><wsdl:portType
|
66
|
+
name="MundiPaggService"><wsdl:operation name="CreateOrder"><wsdl:input wsaw:Action="http://tempuri.org/MundiPaggService/CreateOrder"
|
67
|
+
message="tns:MundiPaggService_CreateOrder_InputMessage"/><wsdl:output wsaw:Action="http://tempuri.org/MundiPaggService/CreateOrderResponse"
|
68
|
+
message="tns:MundiPaggService_CreateOrder_OutputMessage"/></wsdl:operation><wsdl:operation
|
69
|
+
name="ManageOrder"><wsdl:input wsaw:Action="http://tempuri.org/MundiPaggService/ManageOrder"
|
70
|
+
message="tns:MundiPaggService_ManageOrder_InputMessage"/><wsdl:output wsaw:Action="http://tempuri.org/MundiPaggService/ManageOrderResponse"
|
71
|
+
message="tns:MundiPaggService_ManageOrder_OutputMessage"/></wsdl:operation><wsdl:operation
|
72
|
+
name="QueryOrder"><wsdl:input wsaw:Action="http://tempuri.org/MundiPaggService/QueryOrder"
|
73
|
+
message="tns:MundiPaggService_QueryOrder_InputMessage"/><wsdl:output wsaw:Action="http://tempuri.org/MundiPaggService/QueryOrderResponse"
|
74
|
+
message="tns:MundiPaggService_QueryOrder_OutputMessage"/></wsdl:operation><wsdl:operation
|
75
|
+
name="GetInstantBuyData"><wsdl:input wsaw:Action="http://tempuri.org/MundiPaggService/GetInstantBuyData"
|
76
|
+
message="tns:MundiPaggService_GetInstantBuyData_InputMessage"/><wsdl:output
|
77
|
+
wsaw:Action="http://tempuri.org/MundiPaggService/GetInstantBuyDataResponse"
|
78
|
+
message="tns:MundiPaggService_GetInstantBuyData_OutputMessage"/></wsdl:operation><wsdl:operation
|
79
|
+
name="RetryOrder"><wsdl:input wsaw:Action="http://tempuri.org/MundiPaggService/RetryOrder"
|
80
|
+
message="tns:MundiPaggService_RetryOrder_InputMessage"/><wsdl:output wsaw:Action="http://tempuri.org/MundiPaggService/RetryOrderResponse"
|
81
|
+
message="tns:MundiPaggService_RetryOrder_OutputMessage"/></wsdl:operation></wsdl:portType><wsdl:binding
|
82
|
+
name="basicHttp" type="tns:MundiPaggService"><wsp:PolicyReference URI="#basicHttp_policy"/><soap:binding
|
83
|
+
transport="http://schemas.xmlsoap.org/soap/http"/><wsdl:operation name="CreateOrder"><soap:operation
|
84
|
+
soapAction="http://tempuri.org/MundiPaggService/CreateOrder" style="document"/><wsdl:input><soap:body
|
85
|
+
use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation
|
86
|
+
name="ManageOrder"><soap:operation soapAction="http://tempuri.org/MundiPaggService/ManageOrder"
|
87
|
+
style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body
|
88
|
+
use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="QueryOrder"><soap:operation
|
89
|
+
soapAction="http://tempuri.org/MundiPaggService/QueryOrder" style="document"/><wsdl:input><soap:body
|
90
|
+
use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation
|
91
|
+
name="GetInstantBuyData"><soap:operation soapAction="http://tempuri.org/MundiPaggService/GetInstantBuyData"
|
92
|
+
style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body
|
93
|
+
use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="RetryOrder"><soap:operation
|
94
|
+
soapAction="http://tempuri.org/MundiPaggService/RetryOrder" style="document"/><wsdl:input><soap:body
|
95
|
+
use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation></wsdl:binding><wsdl:service
|
96
|
+
name="MundiPaggService"><wsdl:port name="basicHttp" binding="tns:basicHttp"><soap:address
|
97
|
+
location="https://transaction.mundipaggone.com/MundiPaggService.svc"/></wsdl:port></wsdl:service></wsdl:definitions>
|
98
|
+
http_version:
|
99
|
+
recorded_at: Mon, 05 Jan 2015 19:19:01 GMT
|
100
|
+
- request:
|
101
|
+
method: post
|
102
|
+
uri: https://transaction.mundipaggone.com/MundiPaggService.svc
|
103
|
+
body:
|
104
|
+
encoding: UTF-8
|
105
|
+
string: <?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
106
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http://tempuri.org/"
|
107
|
+
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:mun="http://schemas.datacontract.org/2004/07/MundiPagg.One.Service.DataContracts"><env:Body><tns:ManageOrder><tns:manageOrderRequest><mun:ManageCreditCardTransactionCollection><mun:ManageCreditCardTransactionRequest><mun:AmountInCents>1</mun:AmountInCents><mun:TransactionKey>e4c764a4-8ea9-499b-9dd9-25fd4f0a7202</mun:TransactionKey></mun:ManageCreditCardTransactionRequest></mun:ManageCreditCardTransactionCollection><mun:ManageOrderOperationEnum>Void</mun:ManageOrderOperationEnum><mun:MerchantKey>MERCHANT-KEY</mun:MerchantKey><mun:OrderKey>0562f9ed-a578-4b4a-9e60-db9c9b25f625</mun:OrderKey></tns:manageOrderRequest></tns:ManageOrder></env:Body></env:Envelope>
|
108
|
+
headers:
|
109
|
+
Soapaction:
|
110
|
+
- '"http://tempuri.org/MundiPaggService/ManageOrder"'
|
111
|
+
Content-Type:
|
112
|
+
- text/xml;charset=UTF-8
|
113
|
+
Content-Length:
|
114
|
+
- '931'
|
115
|
+
Accept-Encoding:
|
116
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
117
|
+
Accept:
|
118
|
+
- "*/*"
|
119
|
+
User-Agent:
|
120
|
+
- Ruby
|
121
|
+
response:
|
122
|
+
status:
|
123
|
+
code: 200
|
124
|
+
message: OK
|
125
|
+
headers:
|
126
|
+
Content-Type:
|
127
|
+
- text/xml; charset=utf-8
|
128
|
+
Vary:
|
129
|
+
- Accept-Encoding
|
130
|
+
Server:
|
131
|
+
- Microsoft-IIS/8.0
|
132
|
+
X-Powered-By:
|
133
|
+
- ASP.NET
|
134
|
+
Date:
|
135
|
+
- Mon, 05 Jan 2015 19:19:04 GMT
|
136
|
+
Content-Length:
|
137
|
+
- '1017'
|
138
|
+
body:
|
139
|
+
encoding: UTF-8
|
140
|
+
string: <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><ManageOrderResponse
|
141
|
+
xmlns="http://tempuri.org/"><ManageOrderResult xmlns:a="http://schemas.datacontract.org/2004/07/MundiPagg.One.Service.DataContracts"
|
142
|
+
xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><a:ManageOrderOperationEnum>Void</a:ManageOrderOperationEnum><a:MundiPaggTimeInMilliseconds>159</a:MundiPaggTimeInMilliseconds><a:OrderKey>0562f9ed-a578-4b4a-9e60-db9c9b25f625</a:OrderKey><a:OrderReference
|
143
|
+
i:nil="true"/><a:OrderStatusEnum>Canceled</a:OrderStatusEnum><a:RequestKey>2b869c5c-c8a4-49a9-b883-23c995bb4b6d</a:RequestKey><a:Success>true</a:Success><a:Version>1.0</a:Version><a:CreditCardTransactionResultCollection><a:CreditCardTransactionResult><a:AcquirerMessage>Stone|APPR</a:AcquirerMessage><a:AcquirerReturnCode>0000</a:AcquirerReturnCode><a:AmountInCents>1</a:AmountInCents><a:AuthorizationCode>505548</a:AuthorizationCode><a:AuthorizedAmountInCents>1</a:AuthorizedAmountInCents><a:CapturedAmountInCents>1</a:CapturedAmountInCents><a:CreditCardNumber>555566****8884</a:CreditCardNumber><a:CreditCardOperationEnum>AuthAndCapture</a:CreditCardOperationEnum><a:CreditCardTransactionStatusEnum>Refunded</a:CreditCardTransactionStatusEnum><a:CustomStatus
|
144
|
+
i:nil="true"/><a:DueDate i:nil="true"/><a:ExternalTimeInMilliseconds>1637</a:ExternalTimeInMilliseconds><a:InstantBuyKey>95c705cc-1549-4cd0-a752-82a891412daa</a:InstantBuyKey><a:RefundedAmountInCents>1</a:RefundedAmountInCents><a:Success>true</a:Success><a:TransactionIdentifier>10550002425058</a:TransactionIdentifier><a:TransactionKey>e4c764a4-8ea9-499b-9dd9-25fd4f0a7202</a:TransactionKey><a:TransactionReference>3af76942-e27f-44ac-97fe-209067b18bda</a:TransactionReference><a:UniqueSequentialNumber>10550002425058</a:UniqueSequentialNumber><a:VoidedAmountInCents
|
145
|
+
i:nil="true"/><a:OriginalAcquirerReturnCollection i:nil="true"/></a:CreditCardTransactionResult></a:CreditCardTransactionResultCollection><a:BoletoTransactionResultCollection/><a:MundiPaggSuggestion
|
146
|
+
i:nil="true"/><a:ErrorReport i:nil="true"/></ManageOrderResult></ManageOrderResponse></s:Body></s:Envelope>
|
147
|
+
http_version:
|
148
|
+
recorded_at: Mon, 05 Jan 2015 19:19:04 GMT
|
149
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe Mundipagg::Boleto do
|
4
|
+
describe "#payload" do
|
5
|
+
let(:boleto) do
|
6
|
+
described_class.new bank_number: 347,
|
7
|
+
bank_code: 123456
|
8
|
+
end
|
9
|
+
|
10
|
+
it do
|
11
|
+
expect(boleto.payload(100)).to eq({
|
12
|
+
amount_in_cents: 100,
|
13
|
+
currency_iso_enum: "BRL",
|
14
|
+
boleto_transaction_collection: {
|
15
|
+
boleto_transaction: {
|
16
|
+
amount_in_cents: 100,
|
17
|
+
bank_number: 347,
|
18
|
+
days_to_add_in_boleto_expiration_date: 5,
|
19
|
+
nosso_numero: 123456
|
20
|
+
}
|
21
|
+
}
|
22
|
+
})
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
RSpec.describe Mundipagg::Boleto::Response do
|
28
|
+
let(:body) do
|
29
|
+
{
|
30
|
+
create_order_response: {
|
31
|
+
create_order_result: {
|
32
|
+
error_report: {
|
33
|
+
error_item_collection: {
|
34
|
+
error_item: {
|
35
|
+
description: "Out of Money",
|
36
|
+
error_code: "E666"
|
37
|
+
}
|
38
|
+
}
|
39
|
+
}
|
40
|
+
}
|
41
|
+
}
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
let(:response) { described_class.new body }
|
46
|
+
|
47
|
+
describe "#payload" do
|
48
|
+
it do
|
49
|
+
expect(response.payload).to eq({
|
50
|
+
error_report: {
|
51
|
+
error_item_collection: {
|
52
|
+
error_item: {
|
53
|
+
description: "Out of Money",
|
54
|
+
error_code: "E666"
|
55
|
+
}
|
56
|
+
}
|
57
|
+
}
|
58
|
+
})
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "#error" do
|
63
|
+
it { expect(response.error).to be_a(Mundipagg::Error) }
|
64
|
+
it { expect(response.error.code).to eq("E666") }
|
65
|
+
it { expect(response.error.message).to eq("Out of Money") }
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
RSpec.describe Mundipagg::Client do
|
2
|
+
describe "#adapter" do
|
3
|
+
subject { described_class.new.adapter }
|
4
|
+
|
5
|
+
it { expect(subject.globals[:wsdl]).to eq("https://transaction.mundipaggone.com/MundiPaggService.svc?wsdl") }
|
6
|
+
it { expect(subject.globals[:namespaces]).to eq("xmlns:mun" => "http://schemas.datacontract.org/2004/07/MundiPagg.One.Service.DataContracts") }
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "#call" do
|
10
|
+
let(:gateway) { described_class.new }
|
11
|
+
|
12
|
+
it "sends a message" do
|
13
|
+
expect(gateway.adapter).to receive(:call) do |operation, options|
|
14
|
+
expect(operation).to eq("create_order")
|
15
|
+
expect(options).to include(message: {
|
16
|
+
"tns:createOrderRequest" => { "mun:Test" => "works" }
|
17
|
+
})
|
18
|
+
end
|
19
|
+
|
20
|
+
gateway.call("create_order", "create_order_request", { test: "works" })
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#manage_order" do
|
25
|
+
let(:merchant_key) { "MERCHANT-KEY" }
|
26
|
+
let(:gateway) { described_class.new }
|
27
|
+
let(:message) {
|
28
|
+
{
|
29
|
+
manage_credit_card_transaction_collection: {
|
30
|
+
manage_credit_card_transaction_request: {
|
31
|
+
amount_in_cents: 1,
|
32
|
+
transaction_key: "e4c764a4-8ea9-499b-9dd9-25fd4f0a7202"
|
33
|
+
}
|
34
|
+
},
|
35
|
+
manage_order_operation_enum: "Void",
|
36
|
+
merchant_key: merchant_key,
|
37
|
+
order_key: "0562f9ed-a578-4b4a-9e60-db9c9b25f625"
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
let(:response) { gateway.manage_order(message) }
|
42
|
+
let(:result) { response.body[:manage_order_response][:manage_order_result] }
|
43
|
+
|
44
|
+
it "sends a manager order command", :vcr do
|
45
|
+
expect(result[:success]).to be_truthy
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#create_order" do
|
50
|
+
let(:merchant_key) { "MERCHANT-KEY" }
|
51
|
+
let(:gateway) { described_class.new }
|
52
|
+
let(:message) {
|
53
|
+
{
|
54
|
+
amount_in_cents: 1,
|
55
|
+
currency_iso_enum: "BRL",
|
56
|
+
merchant_key: merchant_key,
|
57
|
+
credit_card_transaction_collection: {
|
58
|
+
credit_card_transaction: {
|
59
|
+
amount_in_cents: 1,
|
60
|
+
credit_card_brand_enum: "Mastercard",
|
61
|
+
credit_card_number: "5555666677778884",
|
62
|
+
credit_card_operation_enum: "AuthAndCapture",
|
63
|
+
exp_month: 10, exp_year: 2019,
|
64
|
+
holder_name: "Bruno Azisaka Maciel",
|
65
|
+
installment_count: 1,
|
66
|
+
security_code: "123"
|
67
|
+
}
|
68
|
+
}
|
69
|
+
}
|
70
|
+
}
|
71
|
+
|
72
|
+
let(:response) { gateway.create_order(message) }
|
73
|
+
let(:result) { response.body[:create_order_response][:create_order_result] }
|
74
|
+
|
75
|
+
it "sends a create order command", :vcr do
|
76
|
+
expect(result[:success]).to be_truthy
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe Mundipagg::CreditCard do
|
4
|
+
|
5
|
+
describe "#brand_name" do
|
6
|
+
let(:credit_card) { described_class.new brand: brand }
|
7
|
+
subject { credit_card.brand_name }
|
8
|
+
|
9
|
+
context "when brand is master" do
|
10
|
+
let(:brand) { "master" }
|
11
|
+
it { is_expected.to eq "Mastercard" }
|
12
|
+
end
|
13
|
+
|
14
|
+
context "when brand is visa" do
|
15
|
+
let(:brand) { "visa" }
|
16
|
+
it { is_expected.to eq "Visa" }
|
17
|
+
end
|
18
|
+
|
19
|
+
context "when brand is nil" do
|
20
|
+
let(:brand) { nil }
|
21
|
+
it { is_expected.to eq "" }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#payload" do
|
26
|
+
let(:credit_card) do
|
27
|
+
described_class.new installment_count: 2,
|
28
|
+
number: "4012001037141112",
|
29
|
+
verification_value: "123",
|
30
|
+
year: 2020,
|
31
|
+
month: 10,
|
32
|
+
name: "Bruno Azisaka Maciel"
|
33
|
+
end
|
34
|
+
|
35
|
+
context "when under test" do
|
36
|
+
before do
|
37
|
+
allow(ActiveMerchant::Billing::Base).to receive(:test?).and_return(true)
|
38
|
+
end
|
39
|
+
|
40
|
+
it do
|
41
|
+
expect(credit_card.payload(100)).to eq({
|
42
|
+
amount_in_cents: 100,
|
43
|
+
credit_card_transaction_collection: {
|
44
|
+
credit_card_transaction: {
|
45
|
+
amount_in_cents: 100,
|
46
|
+
credit_card_brand_enum: "Visa",
|
47
|
+
credit_card_number: "4012001037141112",
|
48
|
+
credit_card_operation_enum: "AuthAndCapture",
|
49
|
+
exp_month: 10,
|
50
|
+
exp_year: 2020,
|
51
|
+
holder_name: "Bruno Azisaka Maciel",
|
52
|
+
installment_count: 2,
|
53
|
+
security_code: "123",
|
54
|
+
payment_method_code: 1
|
55
|
+
}
|
56
|
+
},
|
57
|
+
currency_iso_enum: "BRL"
|
58
|
+
})
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context "when not under test" do
|
63
|
+
before do
|
64
|
+
allow(ActiveMerchant::Billing::Base).to receive(:test?).and_return(false)
|
65
|
+
end
|
66
|
+
|
67
|
+
it do
|
68
|
+
expect(credit_card.payload(100)).to eq({
|
69
|
+
amount_in_cents: 100,
|
70
|
+
credit_card_transaction_collection: {
|
71
|
+
credit_card_transaction: {
|
72
|
+
amount_in_cents: 100,
|
73
|
+
credit_card_brand_enum: "Visa",
|
74
|
+
credit_card_number: "4012001037141112",
|
75
|
+
credit_card_operation_enum: "AuthAndCapture",
|
76
|
+
exp_month: 10,
|
77
|
+
exp_year: 2020,
|
78
|
+
holder_name: "Bruno Azisaka Maciel",
|
79
|
+
installment_count: 2,
|
80
|
+
security_code: "123",
|
81
|
+
}
|
82
|
+
},
|
83
|
+
currency_iso_enum: "BRL"
|
84
|
+
})
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
RSpec.describe Mundipagg::CreditCard::Response do
|
91
|
+
let(:body) do
|
92
|
+
{
|
93
|
+
create_order_response: {
|
94
|
+
create_order_result: {
|
95
|
+
acquirer_message: "Rede|Out of Money",
|
96
|
+
acquirer_return_code: "E666"
|
97
|
+
}
|
98
|
+
}
|
99
|
+
}
|
100
|
+
end
|
101
|
+
let(:response) { described_class.new body }
|
102
|
+
|
103
|
+
describe "#payload" do
|
104
|
+
it do
|
105
|
+
expect(response.payload).to eq({
|
106
|
+
acquirer_message: "Rede|Out of Money",
|
107
|
+
acquirer_return_code: "E666"
|
108
|
+
})
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe "#error" do
|
113
|
+
it { expect(response.error).to be_a(Mundipagg::Error) }
|
114
|
+
it { expect(response.error.code).to eq("E666") }
|
115
|
+
it { expect(response.error.message).to eq("Out of Money") }
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe Mundipagg::Gateway do
|
4
|
+
let(:gateway) { described_class.new merchant_key: "MERCHANT-KEY" }
|
5
|
+
let(:client) { double "client" }
|
6
|
+
|
7
|
+
before do
|
8
|
+
allow(Mundipagg::Client).to receive(:new).and_return(client)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#purchase" do
|
12
|
+
let(:boleto) { Mundipagg::Boleto.new bank_number: 123, bank_code: 987 }
|
13
|
+
let(:body) {
|
14
|
+
{
|
15
|
+
create_order_response: {
|
16
|
+
create_order_result: {
|
17
|
+
success: true
|
18
|
+
}
|
19
|
+
}
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
let(:gateway_response) { double "gateway_response", body: body }
|
24
|
+
|
25
|
+
it "sends a create order and returns the response" do
|
26
|
+
expect(client).to receive(:create_order).with({
|
27
|
+
amount_in_cents: 100,
|
28
|
+
currency_iso_enum: "BRL",
|
29
|
+
merchant_key: "MERCHANT-KEY",
|
30
|
+
boleto_transaction_collection: {
|
31
|
+
boleto_transaction: {
|
32
|
+
amount_in_cents: 100,
|
33
|
+
bank_number: 123,
|
34
|
+
days_to_add_in_boleto_expiration_date: 5,
|
35
|
+
nosso_numero: 987
|
36
|
+
}
|
37
|
+
}
|
38
|
+
}).and_return(gateway_response)
|
39
|
+
|
40
|
+
response = gateway.purchase(100, boleto)
|
41
|
+
expect(response).to be_a(Mundipagg::Boleto::Response)
|
42
|
+
expect(response).to be_success
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "#refund" do
|
47
|
+
let(:refund) do
|
48
|
+
Mundipagg::Refund.new transaction_key: "TRANSACTION-KEY",
|
49
|
+
order_key: "ORDER-KEY"
|
50
|
+
end
|
51
|
+
|
52
|
+
let(:body) do
|
53
|
+
{
|
54
|
+
manage_order_response: {
|
55
|
+
manage_order_result: {
|
56
|
+
success: true
|
57
|
+
}
|
58
|
+
}
|
59
|
+
}
|
60
|
+
end
|
61
|
+
|
62
|
+
let(:gateway_response) { double "gateway_response", body: body }
|
63
|
+
|
64
|
+
it "sends a manage order and returns the response" do
|
65
|
+
expect(client).to receive(:manage_order).with({
|
66
|
+
manage_credit_card_transaction_collection: {
|
67
|
+
manage_credit_card_transaction_request: {
|
68
|
+
amount_in_cents: 100,
|
69
|
+
transaction_key: "TRANSACTION-KEY"
|
70
|
+
}
|
71
|
+
},
|
72
|
+
manage_order_operation_enum: "Void",
|
73
|
+
merchant_key: "MERCHANT-KEY",
|
74
|
+
order_key: "ORDER-KEY"
|
75
|
+
}).and_return(gateway_response)
|
76
|
+
|
77
|
+
response = gateway.refund(100, refund)
|
78
|
+
expect(response).to be_a(Mundipagg::Refund::Response)
|
79
|
+
expect(response).to be_success
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe Mundipagg::Refund do
|
4
|
+
describe "#payload" do
|
5
|
+
let(:refund) do
|
6
|
+
described_class.new transaction_key: "TRANSACTION-KEY",
|
7
|
+
order_key: "ORDER-KEY"
|
8
|
+
end
|
9
|
+
|
10
|
+
it do
|
11
|
+
expect(refund.payload(100)).to eq({
|
12
|
+
manage_credit_card_transaction_collection: {
|
13
|
+
manage_credit_card_transaction_request: {
|
14
|
+
amount_in_cents: 100,
|
15
|
+
transaction_key: "TRANSACTION-KEY"
|
16
|
+
}
|
17
|
+
},
|
18
|
+
|
19
|
+
manage_order_operation_enum: "Void",
|
20
|
+
order_key: "ORDER-KEY"
|
21
|
+
})
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
RSpec.describe Mundipagg::Refund::Response do
|
27
|
+
let(:body) do
|
28
|
+
{
|
29
|
+
manage_order_response: {
|
30
|
+
manage_order_result: {
|
31
|
+
error_report: {
|
32
|
+
error_item_collection: {
|
33
|
+
error_item: {
|
34
|
+
description: "Out of Money",
|
35
|
+
error_code: "E666"
|
36
|
+
}
|
37
|
+
}
|
38
|
+
}
|
39
|
+
}
|
40
|
+
}
|
41
|
+
}
|
42
|
+
end
|
43
|
+
let(:response) { described_class.new body }
|
44
|
+
|
45
|
+
describe "#payload" do
|
46
|
+
it do
|
47
|
+
expect(response.payload).to eq({
|
48
|
+
error_report: {
|
49
|
+
error_item_collection: {
|
50
|
+
error_item: {
|
51
|
+
description: "Out of Money",
|
52
|
+
error_code: "E666"
|
53
|
+
}
|
54
|
+
}
|
55
|
+
}
|
56
|
+
})
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "#error" do
|
61
|
+
it { expect(response.error).to be_a(Mundipagg::Error) }
|
62
|
+
it { expect(response.error.code).to eq("E666") }
|
63
|
+
it { expect(response.error.message).to eq("Out of Money") }
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe Mundipagg::Response do
|
4
|
+
describe "#success?" do
|
5
|
+
context "when true" do
|
6
|
+
subject { described_class.new success: true }
|
7
|
+
it { expect(subject).to be_success }
|
8
|
+
end
|
9
|
+
|
10
|
+
context "when false" do
|
11
|
+
subject { described_class.new success: false }
|
12
|
+
it { expect(subject).to_not be_success }
|
13
|
+
end
|
14
|
+
|
15
|
+
context "when nil" do
|
16
|
+
it { expect(subject).to_not be_success }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#error_item" do
|
21
|
+
it { expect { subject.error_item }.to raise_error("Not yet implemented") }
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#error" do
|
25
|
+
context "when error_item is present" do
|
26
|
+
before do
|
27
|
+
allow(subject).to receive(:error_item).and_return({ description: "Error", error_code: 0 })
|
28
|
+
end
|
29
|
+
|
30
|
+
it { expect(subject.error).to be_a(Mundipagg::Error) }
|
31
|
+
it { expect(subject.error.message).to eq("Error") }
|
32
|
+
it { expect(subject.error.code).to eq(0) }
|
33
|
+
end
|
34
|
+
|
35
|
+
context "when error_item is not present" do
|
36
|
+
before do
|
37
|
+
allow(subject).to receive(:error_item).and_return(nil)
|
38
|
+
end
|
39
|
+
|
40
|
+
it { expect(subject.error).to be_nil }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,17 @@
|
|
1
|
+
require "simplecov"
|
2
|
+
SimpleCov.start do
|
3
|
+
add_filter "spec"
|
4
|
+
add_group "lib", "lib"
|
5
|
+
end
|
6
|
+
|
1
7
|
require "mundipagg"
|
2
|
-
require
|
3
|
-
|
8
|
+
require "vcr"
|
9
|
+
|
10
|
+
VCR.configure do |config|
|
11
|
+
config.cassette_library_dir = "spec/fixtures/vcr_cassettes"
|
12
|
+
config.hook_into :webmock
|
13
|
+
config.configure_rspec_metadata!
|
14
|
+
end
|
4
15
|
|
5
16
|
I18n.enforce_available_locales = true
|
6
17
|
|
@@ -21,7 +32,7 @@ RSpec.configure do |config|
|
|
21
32
|
config.warnings = true
|
22
33
|
|
23
34
|
if config.files_to_run.one?
|
24
|
-
config.default_formatter =
|
35
|
+
config.default_formatter = "doc"
|
25
36
|
end
|
26
37
|
|
27
38
|
config.order = :random
|