Class: Moiper::Payment
- Inherits:
-
Object
- Object
- Moiper::Payment
- Defined in:
- lib/moiper/payment.rb
Instance Attribute Summary collapse
-
#accretion ⇒ Float
The amount to be increased from the final price.
-
#deduction ⇒ Float
The amount to be deducted from the final price.
-
#description ⇒ String
The description of the purchase.
-
#id ⇒ String
The unique ID you can set for this payment.
-
#notification_url ⇒ String
The URL where Moip will send notifications about your purchase updates.
-
#price ⇒ Float
The amount to be billed from the user.
-
#return_url ⇒ String
The URL where the user will be redirected after he finishes the payment process.
Instance Method Summary collapse
-
#checkout ⇒ Response
Send a new payment request to Moip.
-
#initialize(options = {}) ⇒ Payment
constructor
Create a new Moip Payment request.
-
#to_xml ⇒ String
Create the payment XML representation.
Constructor Details
#initialize(options = {}) ⇒ Payment
Create a new Moip Payment request
40 41 42 43 44 45 46 47 |
# File 'lib/moiper/payment.rb', line 40 def initialize( = {}) raise ArgumentError, "You must inform a description" if [:description].nil? || [:description].empty? raise ArgumentError, "You must inform a price" if [:price].nil? || [:price].to_f <= 0 .each do |attribute, value| send "#{attribute}=", value end end |
Instance Attribute Details
#accretion ⇒ Float
Returns the amount to be increased from the final price.
16 17 18 |
# File 'lib/moiper/payment.rb', line 16 def accretion @accretion end |
#deduction ⇒ Float
Returns the amount to be deducted from the final price.
19 20 21 |
# File 'lib/moiper/payment.rb', line 19 def deduction @deduction end |
#description ⇒ String
Returns the description of the purchase.
10 11 12 |
# File 'lib/moiper/payment.rb', line 10 def description @description end |
#id ⇒ String
Returns the unique ID you can set for this payment. This is usefull to keep track of which payment we will receive on the Moip’s notification process.
7 8 9 |
# File 'lib/moiper/payment.rb', line 7 def id @id end |
#notification_url ⇒ String
Returns the URL where Moip will send notifications about your purchase updates.
26 27 28 |
# File 'lib/moiper/payment.rb', line 26 def notification_url @notification_url end |
#price ⇒ Float
Returns the amount to be billed from the user.
13 14 15 |
# File 'lib/moiper/payment.rb', line 13 def price @price end |
#return_url ⇒ String
Returns the URL where the user will be redirected after he finishes the payment process.
23 24 25 |
# File 'lib/moiper/payment.rb', line 23 def return_url @return_url end |
Instance Method Details
#checkout ⇒ Response
Send a new payment request to Moip
75 76 77 78 |
# File 'lib/moiper/payment.rb', line 75 def checkout request = Request.new request.process(to_xml) end |
#to_xml ⇒ String
Create the payment XML representation
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/moiper/payment.rb', line 51 def to_xml builder = Nokogiri::XML::Builder.new(:encoding => "UTF-8") do |xml| xml.EnviarInstrucao { xml.InstrucaoUnica { xml.Razao description xml.IdProprio id if id xml.Valores { xml.Valor price, :moeda => "BRL" xml.Acrescimo accretion, :moeda => "BRL" if accretion xml.Deducao deduction, :moeda => "BRL" if deduction } xml.URLNotificacao notification_url if notification_url xml.URLRetorno return_url if return_url } } end builder.to_xml end |