File tree Expand file tree Collapse file tree 7 files changed +56
-2
lines changed Expand file tree Collapse file tree 7 files changed +56
-2
lines changed Original file line number Diff line number Diff line change @@ -76,6 +76,13 @@ class CheckoutController < ApplicationController
76
76
}
77
77
end
78
78
79
+ # Caso você precise passar parâmetros para a api que ainda não foram
80
+ # mapeados na gem, você pode fazer de maneira dinâmica utilizando um
81
+ # simples hash.
82
+ payment.extra_params << { paramName: ' paramValue' }
83
+ payment.extra_params << { senderBirthDate: ' 07/05/1981' }
84
+ payment.extra_params << { extraAmount: ' -15.00' }
85
+
79
86
response = payment.register
80
87
81
88
# Caso o processo de checkout tenha dado errado, lança uma exceção.
Original file line number Diff line number Diff line change 1
- # -*- encoding : utf-8 -*-
1
+ # -*- encoding : utf-8 -*-
2
2
require_relative "boot"
3
3
4
4
payment = PagSeguro ::PaymentRequest . new
36
36
}
37
37
}
38
38
39
+ # Add extras params to request
40
+ # payment.extra_params << { paramName: 'paramValue' }
41
+ # payment.extra_params << { senderBirthDate: '07/05/1981' }
42
+ # payment.extra_params << { extraAmount: '-15.00' }
43
+
39
44
puts "=> REQUEST"
40
45
puts PagSeguro ::PaymentRequest ::Serializer . new ( payment ) . to_params
41
46
Original file line number Diff line number Diff line change @@ -57,6 +57,8 @@ class PaymentRequest
57
57
# The token that identifies the request. Defaults to PagSeguro.token
58
58
attr_accessor :token
59
59
60
+ # The extra parameters for payment request
61
+ attr_accessor :extra_params
60
62
61
63
# Products/items in this payment request.
62
64
def items
@@ -84,6 +86,7 @@ def register
84
86
85
87
private
86
88
def before_initialize
89
+ self . extra_params = [ ]
87
90
self . currency = "BRL"
88
91
self . email = PagSeguro . email
89
92
self . token = PagSeguro . token
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ def to_params
24
24
25
25
serialize_sender ( payment_request . sender )
26
26
serialize_shipping ( payment_request . shipping )
27
+ serialize_extra_params ( payment_request . extra_params )
27
28
28
29
params . delete_if { |key , value | value . nil? }
29
30
@@ -83,6 +84,14 @@ def serialize_address(address)
83
84
params [ :shippingAddressComplement ] = address . complement
84
85
end
85
86
87
+ def serialize_extra_params ( extra_params )
88
+ return unless extra_params
89
+
90
+ extra_params . each do |extra_param |
91
+ params [ extra_param . keys . first ] = extra_param . values . first
92
+ end
93
+ end
94
+
86
95
def to_amount ( amount )
87
96
"%.2f" % BigDecimal ( amount . to_s ) . round ( 2 ) . to_s ( "F" ) if amount
88
97
end
Original file line number Diff line number Diff line change 1
1
module PagSeguro
2
- VERSION = "2.0.6 "
2
+ VERSION = "2.0.7 "
3
3
end
Original file line number Diff line number Diff line change @@ -139,4 +139,18 @@ def build_item(index)
139
139
it_behaves_like "item serialization" , 1
140
140
it_behaves_like "item serialization" , 2
141
141
end
142
+
143
+ context "extra params serialization" do
144
+ before do
145
+ payment_request . stub ( {
146
+ extra_params : [
147
+ { extraParam : 'param_value' } ,
148
+ { newExtraParam : 'extra_param_value' }
149
+ ]
150
+ } )
151
+ end
152
+
153
+ it { expect ( params ) . to include ( extraParam : 'param_value' ) }
154
+ it { expect ( params ) . to include ( newExtraParam : 'extra_param_value' ) }
155
+ end
142
156
end
Original file line number Diff line number Diff line change 104
104
expect ( payment . register ) . to eql ( response )
105
105
end
106
106
end
107
+
108
+ describe "#extra_params" do
109
+ it "is empty before initialization" do
110
+ expect ( subject . extra_params ) . to eql ( [ ] )
111
+ end
112
+
113
+ it "allows extra parameter addition" do
114
+ subject . extra_params << { extraParam : 'value' }
115
+ subject . extra_params << { itemParam1 : 'value1' }
116
+
117
+ expect ( subject . extra_params ) . to eql ( [
118
+ { extraParam : 'value' } ,
119
+ { itemParam1 : 'value1' }
120
+ ] )
121
+ end
122
+ end
107
123
end
You can’t perform that action at this time.
0 commit comments