mundipagg 1.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bbf3d7205f733e00f3692647442de84ff6416f4a
4
+ data.tar.gz: 7d10653f59d31e4579d6d132082e5fb838e80d91
5
+ SHA512:
6
+ metadata.gz: a9dac6bc5d3b949c71aa863a46e59c582fa4adfddea857c4dc1bb3a9aa8a2b74e6346201644ac9497ea7becc71fe4aa4331db7752513e85f81c39d596f2d3cc5
7
+ data.tar.gz: afc809a2a9e9efa1a3cd226c72d550e031dad18d61d91c939830efa862add9c5ac69ab26ec78517aaa0ad8dc0827963177400b5e39e31adacb65e0a62d0a349c
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012-2013 MundiPagg Soluções em Pagamentos
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,59 @@
1
+ MundiPagg Ruby Client Library
2
+ ====================
3
+
4
+ [![Build Status](https://travis-ci.org/mundipagg/ruby-integration-api.png?branch=master)](https://travis-ci.org/mundipagg/ruby-integration-api)
5
+
6
+
7
+ Ruby API for integration with MundiPagg payment web services.
8
+
9
+ ## Dependencies
10
+ * [Savon 2.3.0](http://savonrb.com/version2/)
11
+ * [Nori 2.3.0](https://github.com/savonrb/nori)
12
+
13
+ Unit tests made with [Cucumber](https://github.com/cucumber/cucumber) and [RSpec](https://github.com/rspec/rspec)
14
+
15
+ ## Usage
16
+ Below a simple exemple of an order with one credit card transaction.
17
+
18
+
19
+ ````Ruby
20
+ require 'mundipagg'
21
+
22
+ #Create the client instance
23
+ client = MundiPaggClient.new :test #API test environment
24
+
25
+ #Create the order
26
+ order = CreateOrderRequest.new
27
+
28
+ #Fill order information
29
+ order.amountInCents = 1000 # R$ 10,00
30
+ order.amountInCentsToConsiderPaid = 1000
31
+ order.merchantKey = '00000000-0000-0000-0000-000000000000'
32
+ order.orderReference = 'Custom Order 42'
33
+ credit = CreditCardTransaction.new
34
+
35
+ #Credit card transaction information
36
+ credit.amountInCents = 1000; # R$ 10,00
37
+ credit.creditCardBrandEnum = CreditCardTransaction.BrandEnum[:Visa]
38
+ credit.creditCardOperationEnum = CreditCardTransaction.OperationEnum[:AuthAndCapture]
39
+ credit.creditCardNumber = '4111111111111111'
40
+ credit.holderName = 'Anthony Edward Stark'
41
+ credit.installmentCount = 1
42
+ credit.paymentMethodCode = 1 #Simulator
43
+ credit.securityCode = 123
44
+ credit.transactionReference = 'Custom Transaction Identifier'
45
+ credit.expirationMonth = 5
46
+ credit.expirationYear = 2020
47
+
48
+ #Add transaction to order
49
+ order.creditCardTransactionCollection << credit
50
+
51
+ response = client.CreateOrder(order)
52
+ ````
53
+
54
+ ## More information
55
+
56
+ [RubyDoc](http://rubydoc.info/github/mundipagg/mundipagg-ruby-api/)
57
+
58
+ ## LICENSE
59
+ See the LICENSE file.
@@ -0,0 +1,8 @@
1
+ require 'savon'
2
+ require 'mundipagg/gateway'
3
+ require 'mundipagg/CreateOrderRequest'
4
+ require 'mundipagg/BoletoTransaction'
5
+ require 'mundipagg/CreditCardTransaction'
6
+ require 'mundipagg/Buyer'
7
+ require 'mundipagg/QueryOrderRequest'
8
+ require 'mundipagg/ManageOrderRequest'
@@ -0,0 +1,31 @@
1
+ module Mundipagg
2
+ class BoletoTransaction
3
+
4
+ # @return [Long] Transaction amount in cents
5
+ attr_accessor :amountInCents
6
+
7
+ # @return [Integer] Bank code
8
+ attr_accessor :bankNumber
9
+
10
+ # @return [Integer] How many days after the creation the boleto will be valid.
11
+ # @param Default: 7
12
+ attr_accessor :daysToAddInBoletoExpirationDate
13
+
14
+ # @return [Integer] Number used to identify the boleto
15
+ attr_accessor :nossoNumero
16
+
17
+ # @return [Long] Text with payment instructions. Limit: 120 characters.
18
+ attr_accessor :instructions
19
+
20
+ # @return [Long] Custom transaction identifier.
21
+ attr_accessor :transactionReference
22
+
23
+ # Initialize class with default values
24
+ def initialize
25
+ @amountInCents = 0
26
+ @daysToAddInBoletoExpirationDate = 7
27
+ end
28
+
29
+
30
+ end
31
+ end
@@ -0,0 +1,82 @@
1
+ module Mundipagg
2
+ class Buyer
3
+
4
+ # @return [Guid] Buyer unique idenfitication. Generated by MundiPagg.
5
+ # param Default: 00000000-0000-0000-0000-000000000000 (Guid empty)
6
+ attr_accessor :buyerKey
7
+ # @return [String] Buyer custom idenfitication.
8
+ attr_accessor :buyerReference
9
+ # @return [String] Email address.
10
+ attr_accessor :email
11
+ # @return [String] Facebook ID.
12
+ attr_accessor :facebookId
13
+ # @return [String] Gender.
14
+ attr_accessor :genderEnum
15
+ # @return [String] Home phone.
16
+ attr_accessor :homePhone
17
+ # @return [String] IP Address.
18
+ attr_accessor :ipAddress
19
+ # @return [String] Mobile phone.
20
+ attr_accessor :mobilePhone
21
+ # @return [String] Work phone.
22
+ attr_accessor :workPhone
23
+ # @return [String] Buyer full name.
24
+ attr_accessor :name
25
+ # <i>Person</i> for individual people information and <i>Company</i> for enterprise information
26
+ # @return [String] Type.
27
+ # @param Default: Person
28
+ attr_accessor :personTypeEnum
29
+ # @return [String] Document number.
30
+ attr_accessor :taxDocumentNumber
31
+ #<i>CPF<i> for person document number or <i>CNPJ</i> for company document number.
32
+ # @return [String] Document type.
33
+ # @param Default: CPF
34
+ attr_accessor :taxDocumentTypeEnum
35
+ # @return [String] Twitter ID.
36
+ attr_accessor :twitterId
37
+ # @return [Array] Array of addresses.
38
+ # @see BuyerAddress
39
+ attr_accessor :addressCollection
40
+
41
+ # Gender
42
+ @@Gender = {
43
+ :Male => 'M',
44
+ :Female => 'F'
45
+ }
46
+
47
+ # Person Type
48
+ @@PersonType = {
49
+ :Person => 'Person',
50
+ :Company => 'Company'
51
+ }
52
+
53
+ # Document Type
54
+ @@DocumentType = {
55
+ :CPF => 'CPF',
56
+ :CNPJ => 'CNPJ'
57
+ }
58
+
59
+ # Initialize class with properties
60
+ def initialize
61
+ @addressCollection = Array.new
62
+ @buyerKey = '00000000-0000-0000-0000-000000000000'
63
+ @personTypeEnum = Buyer.PersonTypeEnum[:Person]
64
+ @taxDocumentTypeEnum = Buyer.DocumentTypeEnum[:CPF]
65
+ end
66
+
67
+ # Gender enum
68
+ def self.GenderEnum
69
+ @@Gender
70
+ end
71
+
72
+ # Person type enum
73
+ def self.PersonTypeEnum
74
+ @@PersonType
75
+ end
76
+
77
+ # Document type enum
78
+ def self.DocumentTypeEnum
79
+ @@DocumentType
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,69 @@
1
+ module Mundipagg
2
+ class BuyerAddress
3
+
4
+ # @return [String] Address Type.
5
+ # @see AddressTypeEnum
6
+ # @param Default: Residential
7
+ attr_accessor :addressTypeEnum
8
+ # @return [String] City.
9
+ attr_accessor :city
10
+ # @return [String] Address complement.
11
+ attr_accessor :complement
12
+ # @return [String] Address country.
13
+ # @param Default: Brazil
14
+ # @see CountryEnum
15
+ attr_accessor :countryEnum
16
+ # @return [String] District.
17
+ attr_accessor :district
18
+ # @return [String] Address number.
19
+ attr_accessor :number
20
+ # @return [String] Address state.
21
+ attr_accessor :state
22
+ # @return [String] Street.
23
+ attr_accessor :street
24
+ # @return [String] Zip Code.
25
+ attr_accessor :zipCode
26
+
27
+
28
+ #Address Type Enum
29
+ @@ADDRESS_TYPE={
30
+ :Billing => 'Billing',
31
+ :Shipping => 'Shipping',
32
+ :Work => 'Comercial',
33
+ :Home => 'Residential'
34
+ }
35
+
36
+
37
+ # Country Enum
38
+ @@COUNTRY = {
39
+ :Brazil => 'Brazil',
40
+ :UnitedStates => 'USA',
41
+ :Argentina => 'Argentina',
42
+ :Bolivia => 'Bolivia',
43
+ :Chile => 'Chile',
44
+ :Colombia => 'Colombia',
45
+ :Uruguay => 'Uruguay',
46
+ :Mexico => 'Mexico',
47
+ :Paraguay => 'Paraguay'
48
+ }
49
+
50
+ #Initialize class with properties
51
+ def initialize
52
+ @addressTypeEnum = BuyerAddress.AddressTypeEnum[:Home]
53
+ @countryEnum = BuyerAddress.CountryEnum[:Brazil]
54
+ end
55
+
56
+ #Address Type Enum
57
+ # @see @@ADDRESS_TYPE
58
+ def self.AddressTypeEnum
59
+ @@ADDRESS_TYPE
60
+ end
61
+
62
+ # Country Enum
63
+ # @see @@COUNTRY
64
+ def self.CountryEnum
65
+ @@COUNTRY
66
+ end
67
+
68
+ end
69
+ end
@@ -0,0 +1,62 @@
1
+ module Mundipagg
2
+ class CreateOrderRequest
3
+ # @return [Long] Order amount in cents
4
+ attr_accessor :amountInCents
5
+
6
+ # @return [Long] Amount (in cents) to consider the order is paid
7
+ attr_accessor :amountInCentsToConsiderPaid
8
+
9
+ # @return [String] Order amount currency.
10
+ # @param Default: BRL
11
+ # @see CurrencyIsoEnum
12
+ attr_accessor :currencyIsoEnum
13
+
14
+ # @return [Buyer] Buyer instance
15
+ # @see Buyer
16
+ attr_accessor :buyer
17
+
18
+ # @return [Guid] MundiPagg merchant identification
19
+ attr_accessor :merchantKey
20
+
21
+ # If merchant not send OrderReference, Mundipagg will generate and return in the response.
22
+ # @return [String] Custom order identification.
23
+ attr_accessor :orderReference
24
+
25
+ # @return [Array] Array with all credit card transactions
26
+ attr_accessor :creditCardTransactionCollection
27
+
28
+ # @return [Array] Array with all boleto transactions
29
+ attr_accessor :boletoTransactionCollection
30
+
31
+ # If not send, it will be generate automatically in the webservice and returned in response.
32
+ # Web service request identification, it is used for investigate problems with webservice requests.
33
+ # @return [Guid] Globally Unique Identifier.
34
+ # @param Optional
35
+ # @param Default: 00000000-0000-0000-0000-000000000000
36
+ attr_accessor :requestKey
37
+
38
+ # Currency Enum
39
+ # @returns [Hash<Symbol, String>]
40
+ @@CURRENCY_ISO ={
41
+ :BrazillianReal => 'BRL',
42
+ :AmericanDollar => 'USD'
43
+ }
44
+
45
+ # Initialize class and properties
46
+ def initialize
47
+ @creditCardTransactionCollection = Array.new;
48
+ @boletoTransactionCollection = Array.new;
49
+ @currencyIsoEnum = CreateOrderRequest.CurrencyIsoEnum[:BrazillianReal]
50
+ @requestKey = '00000000-0000-0000-0000-000000000000'
51
+
52
+ end
53
+
54
+ # Currency Enum
55
+ # @returns [Hash<Symbol, String>]
56
+ # @see @@CURRENCY_ISO
57
+ def self.CurrencyIsoEnum
58
+ @@CURRENCY_ISO
59
+ end
60
+
61
+ end
62
+ end
@@ -0,0 +1,78 @@
1
+ module Mundipagg
2
+ class CreditCardTransaction
3
+
4
+ # @return [Long] Transaction amount in cents
5
+ attr_accessor :amountInCents
6
+
7
+ # @return [String] Card brand. Use the static property <i>BrandEnum</i>.
8
+ # @see BrandEnum
9
+ attr_accessor :creditCardBrandEnum
10
+
11
+ # @return [String] Credit Card Number.
12
+ attr_accessor :creditCardNumber
13
+
14
+ # @return [String] Type of operation. Use the static property <i>OperationEnum</i>.
15
+ # @see OperationEnum
16
+ attr_accessor :creditCardOperationEnum
17
+
18
+ # @return [Integer] Credit card expiration month
19
+ attr_accessor :expirationMonth
20
+
21
+ # @return [Integer] Credit card expiration year
22
+ attr_accessor :expirationYear
23
+
24
+ # @return [Integer] Name in the credit card
25
+ attr_accessor :holderName
26
+
27
+ # @return [Integer] Transaction installments count.
28
+ attr_accessor :installmentCount
29
+
30
+ # @return [Integer] Card security code.
31
+ attr_accessor :securityCode
32
+
33
+ # @return [Integer] Code to select the payment method. Can be <i>Cielo<i>, <i>Redecard<i> and others.
34
+ attr_accessor :paymentMethodCode
35
+
36
+ # @return [String] Custom transaction identifier.
37
+ attr_accessor :transactionReference
38
+
39
+ # Fill this property when creating a recurrency transaction.
40
+ # @return [Recurrency] Transaction recurrency information.
41
+ attr_accessor :recurrency
42
+
43
+ # Allowed card brands
44
+ # @returns [Hash<Symbol, String>]
45
+ @@CARD_BRAND = {
46
+ :Visa => 'Visa',
47
+ :Mastercard => 'Mastercard',
48
+ :AmericanExpress => 'Amex',
49
+ :Hipercard => 'Hipercard',
50
+ :Diners => 'Diners',
51
+ :Elo => 'Elo',
52
+ :Aura => 'Aura',
53
+ :Discover => 'Discover'
54
+ }
55
+
56
+ # Types of operation.
57
+ # @returns [Hash<Symbol, String>]
58
+ @@OPERATION = {
59
+ :AuthOnly => 'AuthOnly',
60
+ :AuthAndCapture => 'AuthAndCapture',
61
+ :AuthAndCaptureWithDelay => 'AuthAndCaptureWithDelay'
62
+ }
63
+
64
+ # Allowed card brands
65
+ # @returns [Hash<Symbol, String>]
66
+ # @see @@CARD_BRAND
67
+ def self.BrandEnum
68
+ @@CARD_BRAND
69
+ end
70
+
71
+ # Allowed operations.
72
+ # @returns [Hash<Symbol, String>]
73
+ # @see @@OPERATION
74
+ def self.OperationEnum
75
+ @@OPERATION
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,52 @@
1
+ module Mundipagg
2
+ class ManageOrderRequest
3
+
4
+ # @return [Array] Credit card transaction collection
5
+ attr_accessor :transactionCollection
6
+
7
+ # @return [String] Operation enum
8
+ attr_accessor :manageOrderOperationEnum
9
+
10
+ # @return [Guid] MundiPagg merchant identification
11
+ attr_accessor :merchantKey
12
+
13
+ # @return [Guid] Unique order identification. Generated by MundiPagg.
14
+ attr_accessor :orderKey
15
+
16
+ # @return [String] Order identification.
17
+ attr_accessor :orderReference
18
+
19
+ # If not send, it will be generate automatically in the webservice and returned in response.
20
+ # Web service request identification, it is used for investigate problems with webservice requests.
21
+ # @return [Guid] Globally Unique Identifier.
22
+ # @param Optional
23
+ # @param Default: 00000000-0000-0000-0000-000000000000
24
+ attr_accessor :requestKey
25
+
26
+ # Initialize class and properties
27
+ def initialize
28
+ @transactionCollection = Array.new
29
+ @requestKey = '00000000-0000-0000-0000-000000000000'
30
+ end
31
+
32
+ # Operations allowed
33
+ @@Operation = {
34
+ :Capture => 'Capture',
35
+ :Void => 'Void'
36
+ }
37
+
38
+ # Hash collection with operations allowed
39
+ def self.OperationEnum
40
+ @@Operation
41
+ end
42
+ end
43
+
44
+ class ManageTransactionRequest
45
+ # @return [Long] Order amount in cents.
46
+ attr_accessor :amountInCents
47
+ # @return [Guid] Unique transacion identifier generated by MundiPagg.
48
+ attr_accessor :transactionKey
49
+ # @return [String] Custom transaction identifier.
50
+ attr_accessor :transactionReference
51
+ end
52
+ end
@@ -0,0 +1,27 @@
1
+ module Mundipagg
2
+ class QueryOrderRequest
3
+
4
+ # @return [Guid] MundiPagg merchant identification
5
+ attr_accessor :merchantKey
6
+
7
+ # @return [Guid] Unique order identification. Generated by MundiPagg.
8
+ attr_accessor :orderKey
9
+
10
+ # @return [Guid] Custom order identification.
11
+ attr_accessor :orderReference
12
+
13
+ # If not send, it will be generate automatically in the webservice and returned in response.
14
+ # Web service request identification, it is used for investigate problems with webservice requests.
15
+ # @return [Guid] Globally Unique Identifier.
16
+ # @param Optional
17
+ # @param Default: 00000000-0000-0000-0000-000000000000
18
+ attr_accessor :requestKey
19
+
20
+ # Initialize class and properties
21
+ def initialize()
22
+ @requestKey = '00000000-0000-0000-0000-000000000000'
23
+ end
24
+
25
+
26
+ end
27
+ end
@@ -0,0 +1,37 @@
1
+ module Mundipagg
2
+ # Class that hold recurrency transaction information
3
+ class Recurrency
4
+
5
+ # @return [Date] Date the first recurrency will be charged.
6
+ attr_accessor :dateToStartBilling
7
+
8
+ # @return [String] Indicating the recurrency frequency.
9
+ # @see FrequencyEnum
10
+ attr_accessor :frequencyEnum
11
+
12
+ # @return [Integer] Recurrency interval.
13
+ attr_accessor :interval
14
+
15
+ # @return [Boolean] Indicates whether the One webservice will run an OneDollarAuth
16
+ # to validate the credit card.
17
+ attr_accessor :oneDollarAuth
18
+
19
+ # @return [Integer] Number of recurrencies.
20
+ attr_accessor :recurrences
21
+
22
+ # Allowed recurrency frequency
23
+ @@FREQUENCY = {
24
+ :Monthly => 'Monthly',
25
+ :Yearly => 'Yearly',
26
+ :Daily => 'Daily'
27
+ }
28
+
29
+ # Initialize class and properties
30
+ def initialize
31
+ end
32
+
33
+ # Allowed recurrency frequency
34
+ def self.FrequencyEnum
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,309 @@
1
+ module Mundipagg
2
+ # Class that handles all webservice calls
3
+ class Gateway
4
+
5
+ # @return [Nori] Nori class who handle the conversion of base XML to a hash collection
6
+ # @see https://github.com/savonrb/nori
7
+ attr_reader :parser
8
+
9
+ # <i>:test</i> = Simulator enviroment, fake transaction approval;
10
+ # <i>:production</i> = Real transaction, needs real credit card.
11
+ # @return [Symbol] Webservice environment.
12
+ attr_accessor :environment
13
+
14
+ # @return [String] URL that points to the simulator WSDL
15
+ @@WEBSERVICE_TEST_URL = 'http://simulator.mundipaggone.com/One/MundiPaggService.svc?wsdl'
16
+
17
+ # @return [String] URL that points to the production WSDL
18
+ @@WEBSERVICE_PRODUCTION_URL = ''
19
+
20
+ # Initialize a class with an environment
21
+ #
22
+ # @param environment [Symbol] Sets the MundiPagg environment will be used by the client.
23
+ def initialize(environment=:test)
24
+ @parser = Nori.new(:convert_tags_to => lambda { |tag| tag })
25
+ @environment = environment
26
+ end
27
+
28
+ # This method makes requests to the webservice method ManageOrder.
29
+ #
30
+ # @param request [CreateOrderRequest] A ManagerOrderRequest instance containing information to capture or void a transaction or order.
31
+ # @return [Hash<Symbol, Object>] A hash collection containing the response data
32
+ def ManageOrder(request)
33
+
34
+ hash = @parser.parse('<tns:manageOrderRequest>
35
+ <mun:ManageCreditCardTransactionCollection>
36
+ </mun:ManageCreditCardTransactionCollection>
37
+ <mun:ManageOrderOperationEnum>?</mun:ManageOrderOperationEnum>
38
+ <mun:MerchantKey>?</mun:MerchantKey>
39
+ <mun:OrderKey>?</mun:OrderKey>
40
+ <mun:OrderReference>?</mun:OrderReference>
41
+ <mun:RequestKey>?</mun:RequestKey>
42
+ </tns:manageOrderRequest>')
43
+
44
+ xml_hash = hash['tns:manageOrderRequest'];
45
+
46
+ xml_hash['mun:ManageCreditCardTransactionCollection'] = {'mun:ManageCreditCardTransactionRequest'=>Array.new}
47
+
48
+ if request.transactionCollection.nil? == false and request.transactionCollection.count > 0
49
+
50
+ request.transactionCollection.each do |transaction|
51
+
52
+ xml_hash['mun:ManageCreditCardTransactionCollection']['mun:ManageCreditCardTransactionRequest'] << {
53
+ 'mun:AmountInCents' => transaction.amountInCents,
54
+ 'mun:TransactionKey' => transaction.transactionKey,
55
+ 'mun:TransactionReference' => transaction.transactionReference
56
+ }
57
+ end
58
+ end
59
+
60
+ xml_hash['mun:ManageOrderOperationEnum'] = request.manageOrderOperationEnum
61
+ xml_hash['mun:MerchantKey'] = request.merchantKey
62
+ xml_hash['mun:OrderKey'] = request.orderKey
63
+ xml_hash['mun:OrderReference'] = request.orderReference
64
+ xml_hash['mun:RequestKey'] = request.requestKey
65
+
66
+ response = SendToService(hash, :manage_order)
67
+
68
+ return response
69
+
70
+ end
71
+
72
+ # This method makes requests to the webservice method QueryOrder.
73
+ #
74
+ # @param request [QueryOrderRequest] A QueryOrderRequest instance containing information to request more information about an order or transaction.
75
+ # @return [Hash<Symbol, Object>]
76
+ def QueryOrder(request)
77
+
78
+ hash = @parser.parse('<tns:queryOrderRequest>
79
+ <mun:MerchantKey>?</mun:MerchantKey>
80
+ <mun:OrderKey>?</mun:OrderKey>
81
+ <mun:OrderReference>?</mun:OrderReference>
82
+ <mun:RequestKey>?</mun:RequestKey>
83
+ </tns:queryOrderRequest>')
84
+
85
+ xml_hash = hash['tns:queryOrderRequest'];
86
+
87
+ xml_hash['mun:MerchantKey'] = request.merchantKey
88
+ xml_hash['mun:OrderKey'] = request.orderKey
89
+ xml_hash['mun:OrderReference'] = request.orderReference
90
+ xml_hash['mun:RequestKey'] = request.requestKey
91
+
92
+ response = SendToService(hash, :query_order)
93
+
94
+ return response
95
+ end
96
+
97
+ # This method makes requests to the webservice method CreateOrder.
98
+ #
99
+ # @param request [CreateOrderRequest] A CreateOrderRequest instance containing information to create a order.
100
+ # @return [Hash<Symbol, Object>] A hash collection containing the response data
101
+ def CreateOrder(request)
102
+
103
+ hash = @parser.parse('
104
+ <tns:createOrderRequest>
105
+ <mun:AmountInCents>?</mun:AmountInCents>
106
+ <mun:AmountInCentsToConsiderPaid>?</mun:AmountInCentsToConsiderPaid>
107
+ <mun:CurrencyIsoEnum>?</mun:CurrencyIsoEnum>
108
+ <mun:MerchantKey>?</mun:MerchantKey>
109
+ <mun:OrderReference>?</mun:OrderReference>
110
+ <mun:RequestKey>?</mun:RequestKey>
111
+ <mun:Buyer>
112
+ </mun:Buyer>
113
+ <mun:CreditCardTransactionCollection>
114
+ </mun:CreditCardTransactionCollection>
115
+ <mun:BoletoTransactionCollection>
116
+ </mun:BoletoTransactionCollection>
117
+ </tns:createOrderRequest>')
118
+
119
+ xml_hash = hash['tns:createOrderRequest'];
120
+
121
+ xml_hash['mun:AmountInCents'] = request.amountInCents
122
+ xml_hash['mun:AmountInCentsToConsiderPaid'] = request.amountInCentsToConsiderPaid
123
+ xml_hash['mun:CurrencyIsoEnum'] = request.currencyIsoEnum
124
+ xml_hash['mun:MerchantKey'] = request.merchantKey
125
+ xml_hash['mun:OrderReference'] = request.orderReference
126
+ xml_hash['mun:RequestKey'] = request.requestKey
127
+
128
+ if request.buyer.nil? == false
129
+ xml_hash['mun:Buyer'] = CreateBuyer(request)
130
+ end
131
+
132
+ if not request.creditCardTransactionCollection.nil? and request.creditCardTransactionCollection.count > 0
133
+ #Create credit card transaction array and assing to the contract hash
134
+ creditCardTransactionCollection = CreateCreditCardTransaction(request)
135
+ xml_hash['mun:CreditCardTransactionCollection'] = creditCardTransactionCollection
136
+ else
137
+ xml_hash['mun:CreditCardTransactionCollection'] = nil
138
+ end
139
+
140
+ if request.boletoTransactionCollection.nil? == false and request.boletoTransactionCollection.count > 0
141
+ #Create boleto transaction array and assing to the contract hash
142
+ boletoTransactionCollection = CreateBoletoTransactionRequest(request);
143
+ xml_hash['mun:BoletoTransactionCollection'] = boletoTransactionCollection
144
+ end
145
+
146
+ response = SendToService(hash, :create_order)
147
+
148
+
149
+ return response
150
+
151
+ end
152
+
153
+
154
+ # This method create a hash collection with all buyer information.
155
+ # The hash collection is a part of the data send to the webservice.
156
+ #
157
+ # @param request [CreateOrderRequest]
158
+ # @return [Hash<Symbol, Object>] Hash collection with buyer information.
159
+ # @!visibility private
160
+ def CreateBuyer(request)
161
+
162
+ buyer = {
163
+ 'mun:BuyerKey' => request.buyer.buyerKey,
164
+ 'mun:BuyerReference' => request.buyer.buyerReference,
165
+ 'mun:Email' => request.buyer.email,
166
+ 'mun:GenderEnum' => request.buyer.genderEnum,
167
+ 'mun:FacebookId' => request.buyer.facebookId,
168
+ 'mun:GenderEnum' => request.buyer.genderEnum,
169
+ 'mun:HomePhone' => request.buyer.homePhone,
170
+ 'mun:IpAddress' => request.buyer.ipAddress,
171
+ 'mun:MobilePhone' => request.buyer.mobilePhone,
172
+ 'mun:Name' => request.buyer.name,
173
+ 'mun:PersonTypeEnum' => request.buyer.personTypeEnum,
174
+ 'mun:TaxDocumentNumber' => request.buyer.taxDocumentNumber,
175
+ 'mun:TaxDocumentNumberTypeEnum' => request.buyer.taxDocumentTypeEnum,
176
+ 'mun:TwitterId' => request.buyer.twitterId,
177
+ 'mun:WorkPhone' => request.buyer.workPhone,
178
+ 'mun:BuyerAddressCollection' => nil
179
+
180
+ }
181
+
182
+ if request.buyer.addressCollection.count > 0
183
+
184
+ buyer['mun:BuyerAddressCollection'] = {'mun:BuyerAddress'=>Array.new}
185
+
186
+ request.buyer.addressCollection.each do |address|
187
+
188
+ buyer['mun:BuyerAddressCollection']['mun:BuyerAddress'] << {
189
+ 'mun:AddressTypeEnum' => address.addressTypeEnum,
190
+ 'mun:City' => address.city,
191
+ 'mun:Complement' => address.complement,
192
+ 'mun:CountryEnum' => address.countryEnum,
193
+ 'mun:District' => address.district,
194
+ 'mun:Number' => address.number,
195
+ 'mun:State' => address.state,
196
+ 'mun:Street' => address.street,
197
+ 'mun:ZipCode' => address.zipCode
198
+ }
199
+
200
+ end
201
+ end
202
+
203
+ return buyer
204
+ end
205
+
206
+ # This method create a hash collection with all boleto transactions information.
207
+ # The hash collection is a part of the data send to the webservice.
208
+ #
209
+ # @param boletoRequest [Array<BoletoTransaction>] CreateOrderRequest instance
210
+ # @return [Hash<Symbol, Object>] Hash collection with one or more boleto transactions.
211
+ # @!visibility private
212
+ def CreateBoletoTransactionRequest(boletoRequest)
213
+
214
+ transactionCollection = {'mun:BoletoTransaction' => Array.new}
215
+
216
+ boletoRequest.boletoTransactionCollection.each do |boleto|
217
+
218
+ transactionCollection['mun:BoletoTransaction'] << {
219
+ 'mun:AmountInCents' => boleto.amountInCents,
220
+ 'mun:BankNumber' => boleto.bankNumber,
221
+ 'mun:DaysToAddInBoletoExpirationDate' => boleto.daysToAddInBoletoExpirationDate,
222
+ 'mun:Instructions' => boleto.instructions,
223
+ 'mun:NossoNumero' => boleto.nossoNumero,
224
+ 'mun:TransactionReference' => boleto.transactionReference,
225
+
226
+ }
227
+
228
+ end
229
+
230
+ return transactionCollection
231
+ end
232
+
233
+ # This method create a hash collection with all credit card transactions information.
234
+ # The hash collection is a part of the data send to the webservice.
235
+ #
236
+ # @param creditCardRequest [Array<CreditCardTransaction>] CreateOrderRequest instance
237
+ # @return [Hash<Symbol, Object>] Hash collection with one or more credit card transactions.
238
+ # @!visibility private
239
+ def CreateCreditCardTransaction(creditCardRequest)
240
+
241
+ transactionCollection = {'mun:CreditCardTransaction' => Array.new}
242
+
243
+ creditCardRequest.creditCardTransactionCollection.each do |transaction|
244
+
245
+ transaction_hash = {
246
+ 'mun:AmountInCents' => transaction.amountInCents,
247
+ 'mun:CreditCardBrandEnum' => transaction.creditCardBrandEnum.to_s,
248
+ 'mun:CreditCardNumber' => transaction.creditCardNumber,
249
+ 'mun:CreditCardOperationEnum' => transaction.creditCardOperationEnum.to_s,
250
+ 'mun:ExpMonth' => transaction.expirationMonth,
251
+ 'mun:ExpYear' => transaction.expirationYear,
252
+ 'mun:HolderName' => transaction.holderName,
253
+ 'mun:InstallmentCount' => transaction.installmentCount,
254
+ 'mun:PaymentMethodCode' => transaction.paymentMethodCode,
255
+ 'mun:SecurityCode' => transaction.securityCode,
256
+ 'mun:TransactionReference' => transaction.transactionReference
257
+ }
258
+
259
+ if transaction.recurrency.nil? == false
260
+
261
+ transaction_hash['mun:Recurrency'] = {
262
+ 'mun:DateToStartBilling' => transaction.recurrency.dateToStartBilling,
263
+ 'mun:FrequencyEnum' => transaction.recurrency.frequencyEnum,
264
+ 'mun:Interval' => transaction.recurrency.interval,
265
+ 'mun:OneDollarAuth' => transaction.recurrency.oneDollarAuth,
266
+ 'mun:Recurrences' => transaction.recurrency.recurrences
267
+ }
268
+ end
269
+
270
+ transactionCollection['mun:CreditCardTransaction'] << transaction_hash
271
+ end
272
+
273
+ return transactionCollection
274
+ end
275
+
276
+
277
+ # This method send the hash collectin created in this client and send it to the webservice.
278
+ #
279
+ # == Parameters:
280
+ # @param hash [Hash<Symbol, Object] Hash collection generated by Nori using the base SOAP XML.
281
+ # @param service_method [Symbol] A Symbol declaring the method that will be called. Can be <i>:create_order</i>, <i>:manage_order<i/> or <i>:query_order</i>.
282
+ # @return [Hash<Symbol, Object>] A hash collection with the service method response.
283
+ # @!visibility private
284
+ def SendToService(hash, service_method)
285
+
286
+ url = nil
287
+
288
+ if @environment == :production
289
+ url = @@WEBSERVICE_PRODUCTION_URL
290
+ else
291
+ url = @@WEBSERVICE_TEST_URL
292
+ end
293
+
294
+ client = Savon.client do
295
+ wsdl url
296
+ log_level :error
297
+ namespaces 'xmlns:mun' => 'http://schemas.datacontract.org/2004/07/MundiPagg.One.Service.DataContracts'
298
+ end
299
+
300
+ response = client.call(service_method) do
301
+ message hash
302
+ end
303
+
304
+ return response.to_hash
305
+ end
306
+
307
+ private :CreateBoletoTransactionRequest, :CreateCreditCardTransaction, :CreateBuyer, :SendToService
308
+ end
309
+ end
@@ -0,0 +1,9 @@
1
+ module Mundipagg
2
+ module Version
3
+ Major = 1
4
+ Minor = 1
5
+ Revision = 0
6
+
7
+ String = "#{Major}.#{Minor}.#{Revision}"
8
+ end
9
+ end
@@ -0,0 +1,16 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+ require "mundipagg/version"
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "mundipagg"
6
+ s.summary = "MundiPagg Ruby Client Library"
7
+ s.description = "Ruby library for integrating with the MundiPagg payment web services"
8
+ s.version = Mundipagg::Version::String
9
+ s.author = "MundiPagg"
10
+ s.email = "github@mundipagg.com"
11
+ s.homepage = "http://www.mundipagg.com/"
12
+ s.files = Dir.glob ["README.md", "LICENSE", "lib/**/*.{rb}", "tests/**/*", "*.gemspec"]
13
+ s.add_dependency "savon", "2.3.0"
14
+ s.required_ruby_version = '>= 1.9.2'
15
+
16
+ end
@@ -0,0 +1,9 @@
1
+ Feature: Boleto transaction
2
+ I want to create a order with one boleto transaction.
3
+
4
+ Scenario: Send a Boleto Transaction to One
5
+ Given I have purchase two products with a total cost of BRL 50.00
6
+ And I will pay using Boleto with 15 days to expire
7
+ And I will send to Mundipagg
8
+ Then The order amount in cents should be 5000
9
+ And The boleto status should be Generated
@@ -0,0 +1,16 @@
1
+ Feature: Credit Card Transaction
2
+ I want to create a order with one credit card transaction.
3
+
4
+ Scenario: Pay a order using credit card and installment
5
+ Given I have purchase three products with a total cost of BRL 250
6
+ And I will pay using a Visa credit card in 3 installments
7
+ And I will send to Mundipagg
8
+ Then the order amount in cents should be 25000
9
+ And the transaction status should be Captured
10
+
11
+ Scenario: Pay a order using credit card without installment
12
+ Given I have purchase three products with a total cost of BRL 100,29
13
+ And I will pay using a Visa credit card without installment
14
+ And I will send to Mundipagg
15
+ Then the order amount in cents should be 10029
16
+ And the transaction status should be Captured
@@ -0,0 +1,54 @@
1
+ # encoding: UTF-8
2
+ begin require 'rspec/expectations'; rescue LoadError; require 'spec/expectations'; end
3
+ $:.unshift(File.dirname(__FILE__) + '/../../../lib')
4
+ require 'bigdecimal'
5
+ require 'mundipagg'
6
+
7
+ Before do
8
+ @client = Mundipagg::Gateway.new :test
9
+ @order = Mundipagg::CreateOrderRequest.new
10
+ @boleto = Mundipagg::BoletoTransaction.new
11
+ @response = Hash.new
12
+ @order.merchantKey = '73611285-C8F7-45A4-8F50-579182627242'
13
+ end
14
+
15
+
16
+ Given(/^I have purchase two products with a total cost of (\w+) (\d+)\.(\d+)$/) do |currency,amount,cents|
17
+ amount = amount+'.'+cents
18
+ amount = BigDecimal.new(amount.gsub(',', '.'))
19
+ @order.amountInCents = (amount * 100).to_i
20
+ @order.amountInCentsToConsiderPaid = (amount * 100).to_i
21
+ @order.currencyIsoEnum = 'BRL'
22
+ end
23
+
24
+ Given(/^I will pay using (\w+) with (\d+) days to expire$/) do |type,daysToExpire|
25
+ if type.downcase == 'boleto'
26
+
27
+ @boleto.amountInCents = @order.amountInCents
28
+ @boleto.bankNumber = 1
29
+ @boleto.nossoNumero = 989790
30
+ @boleto.transactionReference = rand(389546232)
31
+ @boleto.daysToAddInBoletoExpirationDate = daysToExpire
32
+ @boleto.instructions = 'Não receber após o vencimento'
33
+
34
+ @order.boletoTransactionCollection << @boleto
35
+ @order.creditCardTransactionCollection = nil
36
+
37
+ end
38
+ end
39
+
40
+ Given(/^I send to Mundipagg$/) do
41
+ @response = @client.CreateOrder(@order)
42
+ end
43
+
44
+
45
+ Then(/^The order amount in cents should be (\d+)$/) do |amountInCents|
46
+ transaction = @response[:create_order_response][:create_order_result][:boleto_transaction_result_collection][:boleto_transaction_result]
47
+ transaction[:amount_in_cents].to_s.should == amountInCents
48
+ end
49
+
50
+ Then(/^The boleto status should be (\w+)$/) do |status|
51
+ transaction = @response[:create_order_response][:create_order_result][:boleto_transaction_result_collection][:boleto_transaction_result]
52
+ transaction[:boleto_transaction_status_enum].to_s == status
53
+ end
54
+
@@ -0,0 +1,76 @@
1
+ begin require 'rspec/expectations'; rescue LoadError; require 'spec/expectations'; end
2
+ $:.unshift(File.dirname(__FILE__) + '/../../../lib')
3
+ require 'bigdecimal'
4
+ require 'mundipagg'
5
+
6
+ #Scenario 1:
7
+ Before do
8
+ @client = Mundipagg::Gateway.new :test
9
+ @order = Mundipagg::CreateOrderRequest.new
10
+ @order.merchantKey = '73611285-C8F7-45A4-8F50-579182627242'
11
+ @transaction = Mundipagg::CreditCardTransaction.new
12
+ @order.creditCardTransactionCollection << @transaction
13
+ @response = Hash.new
14
+ end
15
+
16
+
17
+ Given(/^I have purchase three products with a total cost of (\w+) (\d+)$/) do |currency,amount|
18
+ amount = BigDecimal.new(amount.gsub(',', '.'))
19
+ @order.amountInCents = (amount * 100).to_i
20
+ @order.amountInCentsToConsiderPaid = (amount * 100).to_i
21
+ @order.currencyIsoEnum = 'BRL'
22
+ end
23
+
24
+ Given(/^I will pay using a (\w+) credit card in (\d+) installments$/) do |brand,installments|
25
+ @transaction.creditCardBrandEnum = brand
26
+ @transaction.installmentCount = installments
27
+ @transaction.paymentMethodCode = 1
28
+ @transaction.amountInCents = @order.amountInCents
29
+ @transaction.holderName = 'Ruby Unit Test'
30
+ @transaction.creditCardNumber = '41111111111111111'
31
+ @transaction.securityCode = '123'
32
+ @transaction.expirationMonth = 5
33
+ @transaction.expirationYear = 2018
34
+ @transaction.creditCardOperationEnum = Mundipagg::CreditCardTransaction.OperationEnum[:AuthAndCapture]
35
+ end
36
+
37
+ Given(/^I will send to Mundipagg$/) do
38
+ @response = @client.CreateOrder(@order)
39
+ end
40
+
41
+ Then(/^the order amount in cents should be (\d+)$/) do |amountInCents|
42
+ transaction = @response[:create_order_response][:create_order_result][:credit_card_transaction_result_collection][:credit_card_transaction_result]
43
+ transaction[:amount_in_cents].to_s.should == amountInCents
44
+ end
45
+
46
+ Then(/^the transaction status should be (\w+)$/) do |status|
47
+ transaction = @response[:create_order_response][:create_order_result][:credit_card_transaction_result_collection][:credit_card_transaction_result]
48
+ transaction[:credit_card_transaction_status_enum].to_s.downcase.should == status.downcase
49
+ end
50
+
51
+
52
+ #Scenario 2:
53
+
54
+ Given(/^I have purchase three products with a total cost of (\w+) (\d+),(\d+)$/) do |currency, amount, cents|
55
+ amount = amount+'.'+cents
56
+ amount = BigDecimal.new(amount.gsub(',', '.'))
57
+ @order.amountInCents = (amount * 100).to_i
58
+ @order.amountInCentsToConsiderPaid = (amount * 100).to_i
59
+ @order.currencyIsoEnum = currency
60
+
61
+ end
62
+
63
+ Given(/^I will pay using a (\w+) credit card without installment$/) do |brand|
64
+ @transaction.creditCardBrandEnum = brand
65
+ @transaction.installmentCount = 1
66
+ @transaction.paymentMethodCode = 1
67
+ @transaction.amountInCents = @order.amountInCents
68
+ @transaction.holderName = 'Ruby Unit Test'
69
+ @transaction.creditCardNumber = '41111111111111111'
70
+ @transaction.securityCode = '123'
71
+ @transaction.expirationMonth = 5
72
+ @transaction.expirationYear = 2018
73
+ @transaction.creditCardOperationEnum = Mundipagg::CreditCardTransaction.OperationEnum[:AuthAndCapture]
74
+
75
+ end
76
+
File without changes
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mundipagg
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
+ platform: ruby
6
+ authors:
7
+ - MundiPagg
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: savon
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 2.3.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 2.3.0
27
+ description: Ruby library for integrating with the MundiPagg payment web services
28
+ email: github@mundipagg.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - README.md
34
+ - LICENSE
35
+ - lib/mundipagg/BoletoTransaction.rb
36
+ - lib/mundipagg/Buyer.rb
37
+ - lib/mundipagg/BuyerAddress.rb
38
+ - lib/mundipagg/CreateOrderRequest.rb
39
+ - lib/mundipagg/CreditCardTransaction.rb
40
+ - lib/mundipagg/gateway.rb
41
+ - lib/mundipagg/ManageOrderRequest.rb
42
+ - lib/mundipagg/QueryOrderRequest.rb
43
+ - lib/mundipagg/Recurrency.rb
44
+ - lib/mundipagg/version.rb
45
+ - lib/mundipagg.rb
46
+ - tests/features/boleto.feature
47
+ - tests/features/credit_card.feature
48
+ - tests/features/step_definitions/boleto_steps.rb
49
+ - tests/features/step_definitions/credit_card_steps.rb
50
+ - tests/features/support/env.rb
51
+ - mundipagg.gemspec
52
+ homepage: http://www.mundipagg.com/
53
+ licenses: []
54
+ metadata: {}
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - '>='
62
+ - !ruby/object:Gem::Version
63
+ version: 1.9.2
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubyforge_project:
71
+ rubygems_version: 2.0.6
72
+ signing_key:
73
+ specification_version: 4
74
+ summary: MundiPagg Ruby Client Library
75
+ test_files: []
76
+ has_rdoc: