mundipagg 1.1.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -57,6 +57,51 @@ order.creditCardTransactionCollection << credit
57
57
  response = client.CreateOrder(order)
58
58
  ````
59
59
 
60
+ The response variable will contain a Hash like the one below.
61
+
62
+ ```Ruby
63
+ {:create_order_response=>
64
+ {:create_order_result=>
65
+ {:buyer_key=>"00000000-0000-0000-0000-000000000000",
66
+ :merchant_key=>"00000000-0000-0000-0000-000000000000",
67
+ :mundi_pagg_time_in_milliseconds=>"358",
68
+ :order_key=>"00000000-0000-0000-0000-000000000000",
69
+ :order_reference=>"Custom Order 42",
70
+ :order_status_enum=>"Paid",
71
+ :request_key=>"00000000-0000-0000-0000-000000000000",
72
+ :success=>true,
73
+ :version=>"1.0",
74
+ :credit_card_transaction_result_collection=>
75
+ {:credit_card_transaction_result=>
76
+ {:acquirer_message=>"Transação de simulação autorizada com sucesso",
77
+ :acquirer_return_code=>"0",
78
+ :amount_in_cents=>"1000",
79
+ :authorization_code=>"221672",
80
+ :authorized_amount_in_cents=>"1000",
81
+ :captured_amount_in_cents=>"1000",
82
+ :credit_card_number=>"411111****1111",
83
+ :credit_card_operation_enum=>"AuthAndCapture",
84
+ :credit_card_transaction_status_enum=>"Captured",
85
+ :custom_status=>nil,
86
+ :due_date=>nil,
87
+ :external_time_in_milliseconds=>"76",
88
+ :instant_buy_key=>"00000000-0000-0000-0000-000000000000",
89
+ :refunded_amount_in_cents=>nil,
90
+ :success=>true,
91
+ :transaction_identifier=>"774353",
92
+ :transaction_key=>"00000000-0000-0000-0000-000000000000",
93
+ :transaction_reference=>"Custom Transaction Identifier",
94
+ :unique_sequential_number=>"383884",
95
+ :voided_amount_in_cents=>nil,
96
+ :original_acquirer_return_collection=>nil}},
97
+ :boleto_transaction_result_collection=>nil,
98
+ :mundi_pagg_suggestion=>nil,
99
+ :error_report=>nil,
100
+ :"@xmlns:a"=>"http://schemas.datacontract.org/2004/07/MundiPagg.One.Service.DataContracts",
101
+ :"@xmlns:i"=>"http://www.w3.org/2001/XMLSchema-instance"},
102
+ :@xmlns=>"http://tempuri.org/"}}
103
+ ```
104
+
60
105
  ## More information
61
106
 
62
107
  [RubyDoc](http://rubydoc.info/github/mundipagg/mundipagg-ruby-api/)
@@ -2,6 +2,13 @@ module Mundipagg
2
2
  # Class that handles all webservice calls
3
3
  class Gateway
4
4
 
5
+ # Sets the soap request log level.
6
+ # Can be: { :debug, :info, :warn, :error }
7
+ # Use :debug only to inspect the Xml sent and received to the service.
8
+ # Default in test environment => :debug
9
+ # Default in production environment => :error
10
+ attr_accessor :log_level
11
+
5
12
  # @return [Nori] Nori class who handle the conversion of base XML to a hash collection
6
13
  # @see https://github.com/savonrb/nori
7
14
  attr_reader :parser
@@ -23,6 +30,14 @@ module Mundipagg
23
30
  def initialize(environment=:test)
24
31
  @parser = Nori.new(:convert_tags_to => lambda { |tag| tag })
25
32
  @environment = environment
33
+
34
+ if environment == :test
35
+ @log_level = :debug
36
+ else
37
+ @log_level = :error
38
+ end
39
+
40
+
26
41
  end
27
42
 
28
43
  # This method makes requests to the webservice method ManageOrder.
@@ -291,9 +306,17 @@ module Mundipagg
291
306
  url = @@WEBSERVICE_TEST_URL
292
307
  end
293
308
 
309
+ savon_levels = { :debug => 0, :info => 1, :warn => 2, :error => 3 }
310
+
311
+ if not savon_levels.include? @log_level
312
+ @log_level = :error
313
+ end
314
+
315
+ level = @log_level
316
+
294
317
  client = Savon.client do
295
318
  wsdl url
296
- log_level :error
319
+ log_level level
297
320
  namespaces 'xmlns:mun' => 'http://schemas.datacontract.org/2004/07/MundiPagg.One.Service.DataContracts'
298
321
  end
299
322
 
@@ -304,6 +327,6 @@ module Mundipagg
304
327
  return response.to_hash
305
328
  end
306
329
 
307
- private :CreateBoletoTransactionRequest, :CreateCreditCardTransaction, :CreateBuyer, :SendToService
330
+ private :CreateBoletoTransactionRequest, :CreateCreditCardTransaction, :CreateBuyer, :SendToService, :parser
308
331
  end
309
332
  end
@@ -0,0 +1,31 @@
1
+ require 'nori'
2
+
3
+ module Mundipagg
4
+ # Class who handles Mundipagg post notification XML
5
+ class PostNotification
6
+
7
+ # This method parse the Xml sent by Mundipagg when notify a change in a transaction.
8
+ #
9
+ # @param request [String] XML received in the Mundipagg POST request.
10
+ # @return [Hash<Symbol, String>] A hash collection containing the XML data parsed.
11
+ def self.ParseNotification(xml)
12
+
13
+ nori = Nori.new(:convert_tags_to => lambda { |tag| PostNotification.to_underscore(tag).to_sym })
14
+ xml_hash = nori.parse(xml)
15
+
16
+ return xml_hash
17
+ end
18
+
19
+ # Converts a string in Camel Case format to lower case with underscore.
20
+ #
21
+ # @param Example: 'StatusNotification' outputs 'status_notification'
22
+ # @returns [String] lower case string separated with underscore
23
+ def self.to_underscore(camel_case_string)
24
+ return camel_case_string.gsub(/::/, '/').
25
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
26
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
27
+ tr("-", "_").
28
+ downcase
29
+ end
30
+ end
31
+ end
@@ -1,8 +1,8 @@
1
1
  module Mundipagg
2
2
  module Version
3
3
  Major = 1
4
- Minor = 1
5
- Revision = 1
4
+ Minor = 2
5
+ Revision = 2
6
6
 
7
7
  String = "#{Major}.#{Minor}.#{Revision}"
8
8
  end
@@ -13,5 +13,6 @@ Gem::Specification.new do |s|
13
13
  s.add_dependency "savon", "2.3.0"
14
14
  s.required_ruby_version = '>= 1.9.2'
15
15
  s.license = "Apache 2.0"
16
+
16
17
 
17
18
  end
@@ -0,0 +1,9 @@
1
+ Feature: Post Notification
2
+ I want capture a transaction and receive a post notification telling my transaction has been captured.
3
+
4
+
5
+ Scenario: Receiving a POST notification
6
+ Given I have pre authorized a credit card transaction of BRL 100.00
7
+ And I captured the transaction
8
+ Then I will receive a POST notification telling my transaction has been Captured
9
+ And the amount captured should be BRL 100.00
@@ -1,8 +1,4 @@
1
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
2
 
7
3
  Before do
8
4
  @client = Mundipagg::Gateway.new :test
@@ -0,0 +1,89 @@
1
+ # encoding: UTF-8
2
+
3
+ Before do
4
+ @client = Mundipagg::Gateway.new :test
5
+ @client.log_level = :error
6
+
7
+ @order = Mundipagg::CreateOrderRequest.new
8
+ @manage_order = Mundipagg::ManageOrderRequest.new
9
+
10
+ @manage_order.merchantKey = '73611285-C8F7-45A4-8F50-579182627242'
11
+ @order.merchantKey = '73611285-C8F7-45A4-8F50-579182627242'
12
+
13
+ @transaction = Mundipagg::CreditCardTransaction.new
14
+ @order.creditCardTransactionCollection << @transaction
15
+
16
+ $world = self
17
+ end
18
+
19
+ Given(/^I have pre authorized a credit card transaction of (\w+) (\d+)\.(\d+)$/) do |currency, amount, cents|
20
+
21
+ amount_decimal = TestHelper.JoinAndConvertAmountAndCents(amount, cents)
22
+
23
+ @order.currencyIsoEnum = currency
24
+ @order.amountInCents = (amount_decimal * 100).to_i
25
+ @order.amountInCentsToConsiderPaid = (amount_decimal * 100).to_i
26
+
27
+ @transaction.amountInCents = @order.amountInCents;
28
+ @transaction.creditCardBrandEnum = Mundipagg::CreditCardTransaction.BrandEnum[:Visa]
29
+ @transaction.creditCardOperationEnum = Mundipagg::CreditCardTransaction.OperationEnum[:AuthOnly] #Pre-authorization
30
+ @transaction.creditCardNumber = '4111111111111111'
31
+ @transaction.holderName = 'Bruce Wayne'
32
+ @transaction.installmentCount = 1
33
+ @transaction.paymentMethodCode = 1
34
+ @transaction.securityCode = 123
35
+ @transaction.transactionReference = 'Custom Transaction Identifier'
36
+ @transaction.expirationMonth = 5
37
+ @transaction.expirationYear = 2020
38
+
39
+ response_hash = @client.CreateOrder(@order)
40
+ @response = response_hash[:create_order_response][:create_order_result]
41
+ @credit_card_result = @response[:credit_card_transaction_result_collection][:credit_card_transaction_result]
42
+
43
+ @response[:success].should == true
44
+ @response[:order_status_enum].should == 'Opened'
45
+ @credit_card_result[:amount_in_cents].to_i.should == @order.amountInCents
46
+ @credit_card_result[:credit_card_operation_enum].should == 'AuthOnly'
47
+ @credit_card_result[:credit_card_transaction_status_enum].should == 'AuthorizedPendingCapture'
48
+ end
49
+
50
+ Given(/^I captured the transaction$/) do
51
+ @manage_order.orderKey = @response[:order_key]
52
+
53
+ @manage_order.manageOrderOperationEnum = Mundipagg::ManageOrderRequest.OperationEnum[:Capture]
54
+
55
+ @manage_order.transactionCollection << Mundipagg::ManageTransactionRequest.new
56
+ @manage_order.transactionCollection[0].amountInCents = @credit_card_result[:amount_in_cents]
57
+ @manage_order.transactionCollection[0].transactionKey = @credit_card_result[:transaction_key]
58
+
59
+ response_hash = @client.ManageOrder(@manage_order)
60
+ @response_manage = response_hash[:manage_order_response][:manage_order_result]
61
+
62
+ @response_manage[:manage_order_operation_enum].should == 'Capture'
63
+ @response_manage[:order_status_enum].should == 'Paid'
64
+ @response_manage[:success].should == true
65
+ @response_manage[:credit_card_transaction_result_collection].should_not == nil
66
+ @response_manage[:credit_card_transaction_result_collection][:credit_card_transaction_result].should_not == nil
67
+
68
+ transaction_result_hash = @response_manage[:credit_card_transaction_result_collection][:credit_card_transaction_result]
69
+
70
+ transaction_result_hash[:amount_in_cents].to_i.should == @order.amountInCents
71
+ transaction_result_hash[:success].should == true
72
+
73
+
74
+ end
75
+
76
+ Then(/^I will receive a POST notification telling my transaction has been (\w+)$/) do |return_status|
77
+ xml = TestHelper.CreateFakePostNotification(@response, @response_manage)
78
+
79
+ @notification_hash = Mundipagg::PostNotification.ParseNotification(xml)
80
+
81
+ @notification_hash.should_not == nil
82
+ @notification_hash.count.should > 0
83
+ @notification_hash[:status_notification][:credit_card_transaction][:credit_card_transaction_status].downcase.should == return_status.downcase
84
+ end
85
+
86
+ Then(/^the amount captured should be (\w+) (\d+)\.(\d+)$/) do |currency, amount, cents|
87
+ amount_decimal = TestHelper.JoinAndConvertAmountAndCents(amount, cents)
88
+ @notification_hash[:status_notification][:credit_card_transaction][:captured_amount_in_cents].to_i.should == (amount_decimal.to_i) *100
89
+ end
@@ -0,0 +1,5 @@
1
+ begin require 'rspec/expectations'; rescue LoadError; require 'spec/expectations'; end
2
+ $:.unshift(File.dirname(__FILE__) + '/../../../lib')
3
+ require 'mundipagg'
4
+ require 'mundipagg/post_notification'
5
+ require_relative '../../test_helper.rb'
@@ -0,0 +1,69 @@
1
+ require 'nori'
2
+ require 'gyoku'
3
+ class TestHelper
4
+
5
+ def self.JoinAndConvertAmountAndCents(amount, cents)
6
+ amount_with_cents = amount.gsub(',', '.')
7
+ return BigDecimal.new(amount_with_cents)
8
+ end
9
+
10
+ def self.CreateFakePostNotification(create_order_result, manage_order_result)
11
+ xml = '<StatusNotification xmlns="http://schemas.datacontract.org/2004/07/MundiPagg.NotificationService.DataContract"
12
+ xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
13
+ <AmountInCents>?</AmountInCents>
14
+ <AmountPaidInCents>?</AmountPaidInCents>
15
+ <BoletoTransaction i:nil="true"/>
16
+ <CreditCardTransaction>
17
+ <Acquirer>Cielo</Acquirer>
18
+ <AmountInCents>?</AmountInCents>
19
+ <AuthorizedAmountInCents>?</AuthorizedAmountInCents>
20
+ <CapturedAmountInCents>?</CapturedAmountInCents>
21
+ <CreditCardBrand>?</CreditCardBrand>
22
+ <RefundedAmountInCents i:nil="true"/>
23
+ <StatusChangedDate>?</StatusChangedDate>
24
+ <TransactionIdentifier>?</TransactionIdentifier>
25
+ <TransactionKey>?</TransactionKey>
26
+ <TransactionReference>?</TransactionReference>
27
+ <UniqueSequentialNumber>?</UniqueSequentialNumber>
28
+ <VoidedAmountInCents i:nil="true"/>
29
+ <PreviousCreditCardTransactionStatus>?</PreviousCreditCardTransactionStatus>
30
+ <CreditCardTransactionStatus>?</CreditCardTransactionStatus>
31
+ </CreditCardTransaction>
32
+ <MerchantKey>?</MerchantKey>
33
+ <OrderKey>?</OrderKey>
34
+ <OrderReference>?</OrderReference>
35
+ <OrderStatus>?</OrderStatus>
36
+ </StatusNotification>'
37
+
38
+ parser = Nori.new(:convert_tags_to => lambda { |tag| tag })
39
+ hash = parser.parse(xml)
40
+
41
+ credit_card_result = create_order_result[:credit_card_transaction_result_collection][:credit_card_transaction_result]
42
+ manage_transaction_reuslt = manage_order_result[:credit_card_transaction_result_collection][:credit_card_transaction_result]
43
+
44
+ root = hash['StatusNotification']
45
+
46
+ root['AmountPaidInCents'] = 0
47
+ root['CreditCardTransaction'] = {
48
+ 'Acquirer' => 'Cielo',
49
+ 'AmountInCents' =>credit_card_result[:amount_in_cents],
50
+ 'AuthorizedAmountInCents'=> credit_card_result[:amount_in_cents],
51
+ 'CapturedAmountInCents' =>credit_card_result[:amount_in_cents],
52
+ 'CreditCardBrand' => 'Visa',
53
+ 'RefundedAmountInCents' => nil,
54
+ 'StatusChangedDate' => DateTime.now,
55
+ 'TransactionIdentifier' => Array.new(12){[*'0'..'9', *'A'..'Z'].sample}.join,
56
+ 'TransactionKey'=> credit_card_result[:transaction_key],
57
+ 'TransactionReference'=> credit_card_result[:transaction_reference],
58
+ 'UniqueSequentialNumber' => Array.new(6){[*'0'..'9'].sample}.join,
59
+ 'PreviousCreditCardTransactionStatus' => credit_card_result[:credit_card_transaction_status_enum],
60
+ 'CreditCardTransactionStatus' => manage_transaction_reuslt[:credit_card_transaction_status_enum]
61
+ }
62
+ root['MerchantKey'] = create_order_result[:merchant_key]
63
+ root['OrderKey'] = create_order_result[:order_key]
64
+ root['OrderReference'] = create_order_result[:order_reference]
65
+ root['OrderStatus'] = manage_transaction_reuslt[:order_status_enum]
66
+
67
+ return Gyoku.xml(hash)
68
+ end
69
+ end
metadata CHANGED
@@ -1,18 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mundipagg
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.2
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - MundiPagg
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-08-01 00:00:00.000000000 Z
12
+ date: 2013-08-04 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: savon
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
19
  - - '='
18
20
  - !ruby/object:Gem::Version
@@ -20,6 +22,7 @@ dependencies:
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
27
  - - '='
25
28
  - !ruby/object:Gem::Version
@@ -39,39 +42,43 @@ files:
39
42
  - lib/mundipagg/CreditCardTransaction.rb
40
43
  - lib/mundipagg/gateway.rb
41
44
  - lib/mundipagg/ManageOrderRequest.rb
45
+ - lib/mundipagg/post_notification.rb
42
46
  - lib/mundipagg/QueryOrderRequest.rb
43
47
  - lib/mundipagg/Recurrency.rb
44
48
  - lib/mundipagg/version.rb
45
49
  - lib/mundipagg.rb
46
50
  - tests/features/boleto.feature
47
51
  - tests/features/credit_card.feature
52
+ - tests/features/post_notification.feature
48
53
  - tests/features/step_definitions/boleto_steps.rb
49
54
  - tests/features/step_definitions/credit_card_steps.rb
55
+ - tests/features/step_definitions/post_notification.rb
50
56
  - tests/features/support/env.rb
57
+ - tests/test_helper.rb
51
58
  - mundipagg.gemspec
52
59
  homepage: http://www.mundipagg.com/
53
60
  licenses:
54
61
  - Apache 2.0
55
- metadata: {}
56
62
  post_install_message:
57
63
  rdoc_options: []
58
64
  require_paths:
59
65
  - lib
60
66
  required_ruby_version: !ruby/object:Gem::Requirement
67
+ none: false
61
68
  requirements:
62
- - - '>='
69
+ - - ! '>='
63
70
  - !ruby/object:Gem::Version
64
71
  version: 1.9.2
65
72
  required_rubygems_version: !ruby/object:Gem::Requirement
73
+ none: false
66
74
  requirements:
67
- - - '>='
75
+ - - ! '>='
68
76
  - !ruby/object:Gem::Version
69
77
  version: '0'
70
78
  requirements: []
71
79
  rubyforge_project:
72
- rubygems_version: 2.0.6
80
+ rubygems_version: 1.8.25
73
81
  signing_key:
74
- specification_version: 4
82
+ specification_version: 3
75
83
  summary: MundiPagg Ruby Client Library
76
84
  test_files: []
77
- has_rdoc:
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 6a3db6fbfdc7114d1167cef2b7ade09fc84a355f
4
- data.tar.gz: f3bce5c0e71cf35f6ed93a59d08001f98c887fd4
5
- SHA512:
6
- metadata.gz: dddba8fc2714191b1f0ccb0b5979a461a7da2c7d1a7f564a8451bc647545b5b8a59bf5fad55cdc93331a30294dff35553a152ec310aef6e449ddb34af2a9704e
7
- data.tar.gz: fe1b1ff134b21904540fb799c964861a07d9889455b863ad4d406a5452f74d4b9a5369468b4b0819410ff59ecb0f756ed51493651a4508e207102bc55dde47c0