From 62c1f702efa3f81c1ee00fd80bce8381a6f55629 Mon Sep 17 00:00:00 2001 From: = <=> Date: Wed, 6 Jun 2012 10:33:10 -0400 Subject: [PATCH 01/20] Add ApiOrder --- lib/pagseguro/api_order.rb | 81 +++++++++++++++++++++++++++++++++++ lib/pagseguro/api_payment.rb | 82 ++++++++++++++++++++++++++++++++++++ 2 files changed, 163 insertions(+) create mode 100644 lib/pagseguro/api_order.rb create mode 100644 lib/pagseguro/api_payment.rb diff --git a/lib/pagseguro/api_order.rb b/lib/pagseguro/api_order.rb new file mode 100644 index 0000000..30a282d --- /dev/null +++ b/lib/pagseguro/api_order.rb @@ -0,0 +1,81 @@ +module PagSeguro + class ApiOrder + # Map all billing attributes that will be added as form inputs. + BILLING_MAPPING = { + :name => "senderName", + :email => "senderEmail", + :phone_area_code => "senderAreaCode", + :phone_number => "senderPhone", + :address_zipcode => "shippingAddressPostalCode", + :address_street => "shippingAddressStreet", + :address_number => "shippingAddressNumber", + :address_complement => "shippingAddressComplement", + :address_neighbourhood => "shippingAddressDistrict", + :address_city => "shippingAddressCity", + :address_state => "shippingAddressState", + :address_country => "shippingAddressCountry", + :reference => "reference" + } + + # The list of products added to the order + attr_accessor :products + + # The billing info that will be sent to PagSeguro. + attr_accessor :billing + + # Define the shipping type. + # Can be EN (PAC) or SD (Sedex) + attr_accessor :shipping_type + + def initialize(order_id = nil) + reset! + self.id = order_id + self.billing = {} + end + + # Set the order identifier. Should be a unique + # value to identify this order on your own application + def id=(identifier) + @id = identifier + end + + # Get the order identifier + def id + @id + end + + # Remove all products from this order + def reset! + @products = [] + end + + # Add a new product to the PagSeguro order + # The allowed values are: + # - weight (Optional. If float, will be multiplied by 1000g) + # - quantity (Optional. Defaults to 1) + # - price (Required. If float, will be multiplied by 100 cents) + # - description (Required. Identifies the product) + # - id (Required. Should match the product on your database) + def <<(options) + options = { + :weight => nil, + :quantity => 1 + }.merge(options) + + # convert weight to grammes + options[:weight] = convert_unit(options[:weight], 1000) + + products.push(options) + end + + def add(options) + self << options + end + + private + def convert_unit(number, unit) + number = (BigDecimal("#{number}") * unit).to_i unless number.nil? || number.kind_of?(Integer) + number + end + end +end \ No newline at end of file diff --git a/lib/pagseguro/api_payment.rb b/lib/pagseguro/api_payment.rb new file mode 100644 index 0000000..521ea4d --- /dev/null +++ b/lib/pagseguro/api_payment.rb @@ -0,0 +1,82 @@ +# encoding: utf-8 +module PagSeguro + class ApiPayment + API_URL = "https://ws.pagseguro.uol.com.br/v2/checkout/" + + # Normalize the specified hash converting all data to UTF-8. + # + def normalize(hash) + each_value(hash) do |value| + Utils.to_utf8(value) + end + end + + # Denormalize the specified hash converting all data to ISO-8859-1. + # + def denormalize(hash) + each_value(hash) do |value| + Utils.to_iso8859(value) + end + end + + private + def each_value(hash, &blk) # :nodoc: + hash.each do |key, value| + if value.kind_of?(Hash) + hash[key] = each_value(value, &blk) + else + hash[key] = blk.call value + end + end + + hash + end + + # Send the ApiOrder information and get redirect url + # + def get_payment_code(api_order) + # include the params to validate our request + debugger + request_params = { + :encoding => "UTF-8", + :email => PagSeguro.config["email"], + :token => PagSeguro.config["authenticity_token"], + :currency => "BRL", + :reference => api_order.id + } + # <%= hidden_field_tag "tipo", "CP" %> + + api_order.products.each_with_index do |product, i| + i += 1 + request_params.merge({ + "itemQuantity#{i}".to_sym => product[:quantity], + "itemId{i}".to_sym => product[:id], + "itemDescription#{i}".to_sym => product[:description], + "itemAmount{i}".to_sym => product[:price] + }) + request_params.merge({ + "itemWeight#{i}".to_sym => product[:weight].to_i + }) if product[:weight] + end + + api_order.billing.each do |name, value| + request_params.merge({ + PagSeguro::ApiOrder::BILLING_MAPPING[name.to_sym].to_sym => value + }) + end + + # do the request + uri = URI.parse(API_URL) + http = Net::HTTP.new(uri.host, uri.port) + http.use_ssl = true + http.verify_mode = OpenSSL::SSL::VERIFY_PEER + http.ca_file = File.dirname(__FILE__) + "/cacert.pem" + + request = Net::HTTP::Post.new(uri.path) + request.form_data = denormalize(request_params) + response = http.start {|r| r.request request } + debugger + (response.body =~ /VERIFICADO/) != nil + end + end +end From c05cd9ef4f82e0b0175aa1cd7932db446359874b Mon Sep 17 00:00:00 2001 From: = <=> Date: Wed, 6 Jun 2012 10:39:25 -0400 Subject: [PATCH 02/20] Add ApiOrder --- lib/pagseguro.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/pagseguro.rb b/lib/pagseguro.rb index 20a0368..e47870e 100644 --- a/lib/pagseguro.rb +++ b/lib/pagseguro.rb @@ -10,6 +10,8 @@ require "pagseguro/railtie" require "pagseguro/notification" require "pagseguro/order" +require "pagseguro/api_order" +require "pagseguro/api_payment" require "pagseguro/action_controller" require "pagseguro/helper" require "pagseguro/utils" From 65a9be708e922753b6c734788ad518b56c603aa5 Mon Sep 17 00:00:00 2001 From: = <=> Date: Wed, 6 Jun 2012 10:44:23 -0400 Subject: [PATCH 03/20] Add ApiOrder --- lib/pagseguro/api_payment.rb | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/pagseguro/api_payment.rb b/lib/pagseguro/api_payment.rb index 521ea4d..c0642fb 100644 --- a/lib/pagseguro/api_payment.rb +++ b/lib/pagseguro/api_payment.rb @@ -19,19 +19,6 @@ def denormalize(hash) end end - private - def each_value(hash, &blk) # :nodoc: - hash.each do |key, value| - if value.kind_of?(Hash) - hash[key] = each_value(value, &blk) - else - hash[key] = blk.call value - end - end - - hash - end - # Send the ApiOrder information and get redirect url # def get_payment_code(api_order) @@ -78,5 +65,18 @@ def get_payment_code(api_order) debugger (response.body =~ /VERIFICADO/) != nil end + + private + def each_value(hash, &blk) # :nodoc: + hash.each do |key, value| + if value.kind_of?(Hash) + hash[key] = each_value(value, &blk) + else + hash[key] = blk.call value + end + end + + hash + end end end From 26bb11b4adcb9448a3d96081c92a67128e9494e2 Mon Sep 17 00:00:00 2001 From: = <=> Date: Wed, 6 Jun 2012 10:55:52 -0400 Subject: [PATCH 04/20] Add ApiOrder --- lib/pagseguro/api_payment.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/pagseguro/api_payment.rb b/lib/pagseguro/api_payment.rb index c0642fb..6ff4444 100644 --- a/lib/pagseguro/api_payment.rb +++ b/lib/pagseguro/api_payment.rb @@ -1,8 +1,10 @@ # encoding: utf-8 module PagSeguro class ApiPayment + extend self + API_URL = "https://ws.pagseguro.uol.com.br/v2/checkout/" - + # Normalize the specified hash converting all data to UTF-8. # def normalize(hash) @@ -35,19 +37,19 @@ def get_payment_code(api_order) api_order.products.each_with_index do |product, i| i += 1 - request_params.merge({ + request_params.merge!({ "itemQuantity#{i}".to_sym => product[:quantity], "itemId{i}".to_sym => product[:id], "itemDescription#{i}".to_sym => product[:description], "itemAmount{i}".to_sym => product[:price] }) - request_params.merge({ + request_params.merge!({ "itemWeight#{i}".to_sym => product[:weight].to_i }) if product[:weight] end api_order.billing.each do |name, value| - request_params.merge({ + request_params.merge!({ PagSeguro::ApiOrder::BILLING_MAPPING[name.to_sym].to_sym => value }) end From 9133be78aae78d0a92518506568173c92bf91b4d Mon Sep 17 00:00:00 2001 From: = <=> Date: Wed, 6 Jun 2012 10:58:59 -0400 Subject: [PATCH 05/20] Add ApiOrder --- lib/pagseguro/api_payment.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pagseguro/api_payment.rb b/lib/pagseguro/api_payment.rb index 6ff4444..b9bdbe7 100644 --- a/lib/pagseguro/api_payment.rb +++ b/lib/pagseguro/api_payment.rb @@ -1,6 +1,6 @@ # encoding: utf-8 module PagSeguro - class ApiPayment + module ApiPayment extend self API_URL = "https://ws.pagseguro.uol.com.br/v2/checkout/" From 76fae64c0516ac50705155ade8c27d7132c64964 Mon Sep 17 00:00:00 2001 From: = <=> Date: Wed, 6 Jun 2012 11:02:58 -0400 Subject: [PATCH 06/20] Add ApiOrder --- lib/pagseguro/api_payment.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pagseguro/api_payment.rb b/lib/pagseguro/api_payment.rb index b9bdbe7..c37aaf6 100644 --- a/lib/pagseguro/api_payment.rb +++ b/lib/pagseguro/api_payment.rb @@ -39,9 +39,9 @@ def get_payment_code(api_order) i += 1 request_params.merge!({ "itemQuantity#{i}".to_sym => product[:quantity], - "itemId{i}".to_sym => product[:id], + "itemId#{i}".to_sym => product[:id], "itemDescription#{i}".to_sym => product[:description], - "itemAmount{i}".to_sym => product[:price] + "itemAmount#{i}".to_sym => product[:price] }) request_params.merge!({ "itemWeight#{i}".to_sym => product[:weight].to_i From f3873b18e63612345a2c9141f0624fba511a077c Mon Sep 17 00:00:00 2001 From: = <=> Date: Wed, 6 Jun 2012 11:19:24 -0400 Subject: [PATCH 07/20] Add ApiOrder --- lib/pagseguro/api_payment.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/pagseguro/api_payment.rb b/lib/pagseguro/api_payment.rb index c37aaf6..9079a47 100644 --- a/lib/pagseguro/api_payment.rb +++ b/lib/pagseguro/api_payment.rb @@ -25,7 +25,6 @@ def denormalize(hash) # def get_payment_code(api_order) # include the params to validate our request - debugger request_params = { :encoding => "UTF-8", :email => PagSeguro.config["email"], @@ -64,8 +63,7 @@ def get_payment_code(api_order) request = Net::HTTP::Post.new(uri.path) request.form_data = denormalize(request_params) response = http.start {|r| r.request request } - debugger - (response.body =~ /VERIFICADO/) != nil + response end private From e362a28af857f56d1553f8640cb3edcd3756a622 Mon Sep 17 00:00:00 2001 From: = <=> Date: Wed, 6 Jun 2012 11:46:58 -0400 Subject: [PATCH 08/20] Add ApiOrder --- lib/pagseguro/api_order.rb | 23 +++++++++++++++++++---- lib/pagseguro/api_payment.rb | 15 ++++++++++++--- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/lib/pagseguro/api_order.rb b/lib/pagseguro/api_order.rb index 30a282d..41c01c7 100644 --- a/lib/pagseguro/api_order.rb +++ b/lib/pagseguro/api_order.rb @@ -14,7 +14,6 @@ class ApiOrder :address_city => "shippingAddressCity", :address_state => "shippingAddressState", :address_country => "shippingAddressCountry", - :reference => "reference" } # The list of products added to the order @@ -23,10 +22,24 @@ class ApiOrder # The billing info that will be sent to PagSeguro. attr_accessor :billing - # Define the shipping type. - # Can be EN (PAC) or SD (Sedex) + # Optional: define the shipping type. Can be 1 (PAC) or 2 (Sedex) attr_accessor :shipping_type + + # Optional: extra amount on the purchase (negative for discount + attr_accessor :extra_amount + # Optional: specific redirect URL + attr_accessor :redirect_url + + # Optional: order id in your system + attr_accessor :reference + + # Optional: maximum number of uses of generated code, integer greater than 0 + attr_accessor :max_uses + + # Optional: maximum age of generated code in seconds, integer greater than 30 + attr_accessor :max_age + def initialize(order_id = nil) reset! self.id = order_id @@ -53,9 +66,11 @@ def reset! # The allowed values are: # - weight (Optional. If float, will be multiplied by 1000g) # - quantity (Optional. Defaults to 1) - # - price (Required. If float, will be multiplied by 100 cents) + # - price (Required, can be float) # - description (Required. Identifies the product) # - id (Required. Should match the product on your database) + # - shipping_cost(Optional. Will be used if provided instead + # of calculated by Correio) def <<(options) options = { :weight => nil, diff --git a/lib/pagseguro/api_payment.rb b/lib/pagseguro/api_payment.rb index 9079a47..ee495f4 100644 --- a/lib/pagseguro/api_payment.rb +++ b/lib/pagseguro/api_payment.rb @@ -23,14 +23,13 @@ def denormalize(hash) # Send the ApiOrder information and get redirect url # - def get_payment_code(api_order) + def get_payment_response(api_order) # include the params to validate our request request_params = { :encoding => "UTF-8", :email => PagSeguro.config["email"], :token => PagSeguro.config["authenticity_token"], - :currency => "BRL", - :reference => api_order.id + :currency => "BRL" } # <%= hidden_field_tag "tipo", "CP" %> @@ -53,6 +52,14 @@ def get_payment_code(api_order) }) end + # add optional values if available + request_params.merge!({:reference => api_order.id}) if api_order.id + request_params.merge!({:shippingType => api_order.shipping_type}) if api_order.shipping_type + request_params.merge!({:extraAmount => api_order.extra_amount}) if api_order.extra_amount + request_params.merge!({:redirectURL => api_order.redirect_url}) if api_order.redirect_url + request_params.merge!({:maxUses => api_order.max_uses}) if api_order.max_uses + request_params.merge!({:maxAge => api_order.max_age}) if api_order.max_age + # do the request uri = URI.parse(API_URL) http = Net::HTTP.new(uri.host, uri.port) @@ -63,6 +70,8 @@ def get_payment_code(api_order) request = Net::HTTP::Post.new(uri.path) request.form_data = denormalize(request_params) response = http.start {|r| r.request request } + + #return the request response end From 93f86fb68f709a89979fd14639761c38041962a6 Mon Sep 17 00:00:00 2001 From: = <=> Date: Wed, 6 Jun 2012 12:14:30 -0400 Subject: [PATCH 09/20] Add ApiOrder --- lib/pagseguro/api_payment.rb | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/lib/pagseguro/api_payment.rb b/lib/pagseguro/api_payment.rb index ee495f4..2014b0d 100644 --- a/lib/pagseguro/api_payment.rb +++ b/lib/pagseguro/api_payment.rb @@ -1,10 +1,18 @@ # encoding: utf-8 module PagSeguro - module ApiPayment - extend self + class ApiPayment API_URL = "https://ws.pagseguro.uol.com.br/v2/checkout/" + # the pure response from the HTTP request + attr_accessor :response + + # The pure response from the HTTP request to check for errors + attr_accessor :payment + + # The redirect_url if successful + attr_accessor :redirect_url + # Normalize the specified hash converting all data to UTF-8. # def normalize(hash) @@ -22,8 +30,11 @@ def denormalize(hash) end # Send the ApiOrder information and get redirect url - # - def get_payment_response(api_order) + def initialize(api_order) + reset! + self.id = order_id + self.billing = {} + # include the params to validate our request request_params = { :encoding => "UTF-8", @@ -31,7 +42,6 @@ def get_payment_response(api_order) :token => PagSeguro.config["authenticity_token"], :currency => "BRL" } - # <%= hidden_field_tag "tipo", "CP" %> api_order.products.each_with_index do |product, i| i += 1 @@ -71,10 +81,17 @@ def get_payment_response(api_order) request.form_data = denormalize(request_params) response = http.start {|r| r.request request } - #return the request - response + # saves the response + @response = response + + # saves the payment in hash format + @payment = Hash.from_xml(payment_response(api_order).body) + + # saves the redirect_url + code = @payment.try(:[], :checkout).try(:[], :code) + @redirect_url = code ? "https://pagseguro.uol.com.br/v2/checkout/payment.html?code=#{code}" : nil end - + private def each_value(hash, &blk) # :nodoc: hash.each do |key, value| From 3d459544e97e565424bb79fb323ab685e7af45e3 Mon Sep 17 00:00:00 2001 From: = <=> Date: Wed, 6 Jun 2012 12:20:56 -0400 Subject: [PATCH 10/20] Add ApiOrder --- lib/pagseguro/api_payment.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/pagseguro/api_payment.rb b/lib/pagseguro/api_payment.rb index 2014b0d..3f46c71 100644 --- a/lib/pagseguro/api_payment.rb +++ b/lib/pagseguro/api_payment.rb @@ -7,12 +7,15 @@ class ApiPayment # the pure response from the HTTP request attr_accessor :response - # The pure response from the HTTP request to check for errors + # The complete response hash attr_accessor :payment + # Errors hash if any + attr_accessor :errors + # The redirect_url if successful attr_accessor :redirect_url - + # Normalize the specified hash converting all data to UTF-8. # def normalize(hash) @@ -31,10 +34,6 @@ def denormalize(hash) # Send the ApiOrder information and get redirect url def initialize(api_order) - reset! - self.id = order_id - self.billing = {} - # include the params to validate our request request_params = { :encoding => "UTF-8", @@ -87,6 +86,9 @@ def initialize(api_order) # saves the payment in hash format @payment = Hash.from_xml(payment_response(api_order).body) + # get errors if any + @errors = @payment.try(:[], :errors) + # saves the redirect_url code = @payment.try(:[], :checkout).try(:[], :code) @redirect_url = code ? "https://pagseguro.uol.com.br/v2/checkout/payment.html?code=#{code}" : nil From 119312b69ad6ed19b9bb7b196adeb33d590db1ff Mon Sep 17 00:00:00 2001 From: = <=> Date: Wed, 6 Jun 2012 12:22:37 -0400 Subject: [PATCH 11/20] Add ApiOrder --- lib/pagseguro/api_payment.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pagseguro/api_payment.rb b/lib/pagseguro/api_payment.rb index 3f46c71..112854a 100644 --- a/lib/pagseguro/api_payment.rb +++ b/lib/pagseguro/api_payment.rb @@ -84,7 +84,7 @@ def initialize(api_order) @response = response # saves the payment in hash format - @payment = Hash.from_xml(payment_response(api_order).body) + @payment = Hash.from_xml(@response.body) # get errors if any @errors = @payment.try(:[], :errors) From 30cdb9f8e34361de3fb6ebf6452d675005bf65ab Mon Sep 17 00:00:00 2001 From: = <=> Date: Wed, 6 Jun 2012 12:25:19 -0400 Subject: [PATCH 12/20] Add ApiOrder --- lib/pagseguro/api_payment.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pagseguro/api_payment.rb b/lib/pagseguro/api_payment.rb index 112854a..7b903cc 100644 --- a/lib/pagseguro/api_payment.rb +++ b/lib/pagseguro/api_payment.rb @@ -87,10 +87,10 @@ def initialize(api_order) @payment = Hash.from_xml(@response.body) # get errors if any - @errors = @payment.try(:[], :errors) + @errors = @payment.try(:[], 'errors') # saves the redirect_url - code = @payment.try(:[], :checkout).try(:[], :code) + code = @payment.try(:[], 'checkout').try(:[], 'code') @redirect_url = code ? "https://pagseguro.uol.com.br/v2/checkout/payment.html?code=#{code}" : nil end From a44bbc2c012ce4d55d29bf6bc98623825d1fe813 Mon Sep 17 00:00:00 2001 From: = <=> Date: Wed, 6 Jun 2012 17:39:42 -0400 Subject: [PATCH 13/20] Add helper --- lib/pagseguro/api_payment.rb | 9 ++++++--- lib/pagseguro/utils.rb | 4 ++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/pagseguro/api_payment.rb b/lib/pagseguro/api_payment.rb index 7b903cc..4327548 100644 --- a/lib/pagseguro/api_payment.rb +++ b/lib/pagseguro/api_payment.rb @@ -13,8 +13,11 @@ class ApiPayment # Errors hash if any attr_accessor :errors + # Errors hash if any + attr_accessor :errors + # The redirect_url if successful - attr_accessor :redirect_url + attr_accessor :code # Normalize the specified hash converting all data to UTF-8. # @@ -90,8 +93,8 @@ def initialize(api_order) @errors = @payment.try(:[], 'errors') # saves the redirect_url - code = @payment.try(:[], 'checkout').try(:[], 'code') - @redirect_url = code ? "https://pagseguro.uol.com.br/v2/checkout/payment.html?code=#{code}" : nil + @code = @payment.try(:[], 'checkout').try(:[], 'code') + @redirect_url = @code ? "https://pagseguro.uol.com.br/v2/checkout/payment.html?code=#{@code}" : nil end private diff --git a/lib/pagseguro/utils.rb b/lib/pagseguro/utils.rb index 6070cb9..1258509 100644 --- a/lib/pagseguro/utils.rb +++ b/lib/pagseguro/utils.rb @@ -9,5 +9,9 @@ def to_utf8(string) def to_iso8859(string) string.to_s.unpack("U*").pack("C*") end + + def to_payment_url(string) + string ? "https://pagseguro.uol.com.br/v2/checkout/payment.html?code=#{string}" : nil + end end end From 4dc52c6cd18a224471e8b16df59378b2880309d2 Mon Sep 17 00:00:00 2001 From: = <=> Date: Sat, 9 Jun 2012 16:16:34 -0400 Subject: [PATCH 14/20] Adjust accessors --- lib/pagseguro/api_payment.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/pagseguro/api_payment.rb b/lib/pagseguro/api_payment.rb index 4327548..d000ee3 100644 --- a/lib/pagseguro/api_payment.rb +++ b/lib/pagseguro/api_payment.rb @@ -13,11 +13,11 @@ class ApiPayment # Errors hash if any attr_accessor :errors - # Errors hash if any - attr_accessor :errors + # Payment code attributed by PagSeguro + attr_accessor :code # The redirect_url if successful - attr_accessor :code + attr_accessor :redirect_url # Normalize the specified hash converting all data to UTF-8. # From 977a9f0a903d86d609fca9212b8c7975b77830db Mon Sep 17 00:00:00 2001 From: = <=> Date: Sat, 9 Jun 2012 18:39:51 -0400 Subject: [PATCH 15/20] Adjust output for less than 10 cents --- lib/pagseguro/order.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pagseguro/order.rb b/lib/pagseguro/order.rb index d71efb2..b9311d1 100644 --- a/lib/pagseguro/order.rb +++ b/lib/pagseguro/order.rb @@ -72,7 +72,7 @@ def <<(options) options[:fees] = convert_unit(options[:fees], 100) # convert price to cents - options[:price] = convert_unit(options[:price], 100) + options[:price] = "%03d" % convert_unit(options[:price], 100) # convert weight to grammes options[:weight] = convert_unit(options[:weight], 1000) From f5d064bdf1d2d2a8e4a341283e97169131548d36 Mon Sep 17 00:00:00 2001 From: = <=> Date: Sat, 9 Jun 2012 18:47:03 -0400 Subject: [PATCH 16/20] Adjust output for less than 10 cents --- lib/pagseguro/order.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pagseguro/order.rb b/lib/pagseguro/order.rb index b9311d1..6e75404 100644 --- a/lib/pagseguro/order.rb +++ b/lib/pagseguro/order.rb @@ -72,7 +72,7 @@ def <<(options) options[:fees] = convert_unit(options[:fees], 100) # convert price to cents - options[:price] = "%03d" % convert_unit(options[:price], 100) + options[:price] = convert_unit(options[:price], 100) # convert weight to grammes options[:weight] = convert_unit(options[:weight], 1000) @@ -87,7 +87,7 @@ def add(options) private def convert_unit(number, unit) number = (BigDecimal("#{number}") * unit).to_i unless number.nil? || number.kind_of?(Integer) - number + "%03d" % number end end end From 6cbc039d923c06d023ea67f3ec72b3e6285a3951 Mon Sep 17 00:00:00 2001 From: = <=> Date: Sat, 9 Jun 2012 18:49:55 -0400 Subject: [PATCH 17/20] Adjust output for less than 10 cents --- lib/pagseguro/order.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pagseguro/order.rb b/lib/pagseguro/order.rb index 6e75404..ce57ac7 100644 --- a/lib/pagseguro/order.rb +++ b/lib/pagseguro/order.rb @@ -87,7 +87,7 @@ def add(options) private def convert_unit(number, unit) number = (BigDecimal("#{number}") * unit).to_i unless number.nil? || number.kind_of?(Integer) - "%03d" % number + "%03d" % number.to_i end end end From 7bd94c298570e602a4afa33603432a0220f8e788 Mon Sep 17 00:00:00 2001 From: = <=> Date: Thu, 28 Jun 2012 03:11:04 -0300 Subject: [PATCH 18/20] Add extra amount to order --- lib/pagseguro/order.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/pagseguro/order.rb b/lib/pagseguro/order.rb index ce57ac7..50a1191 100644 --- a/lib/pagseguro/order.rb +++ b/lib/pagseguro/order.rb @@ -13,7 +13,8 @@ class Order :address_country => "cliente_pais", :phone_area_code => "cliente_ddd", :phone_number => "cliente_tel", - :email => "cliente_email" + :email => "cliente_email", + :extra_amount => "extra_amount" } # The list of products added to the order From adae26129d7528334bf3a36d39eea1bcfb899041 Mon Sep 17 00:00:00 2001 From: = <=> Date: Thu, 28 Jun 2012 03:14:45 -0300 Subject: [PATCH 19/20] Extra amount adjustment --- lib/pagseguro/order.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/pagseguro/order.rb b/lib/pagseguro/order.rb index 50a1191..90fade9 100644 --- a/lib/pagseguro/order.rb +++ b/lib/pagseguro/order.rb @@ -13,10 +13,12 @@ class Order :address_country => "cliente_pais", :phone_area_code => "cliente_ddd", :phone_number => "cliente_tel", - :email => "cliente_email", - :extra_amount => "extra_amount" + :email => "cliente_email" } + # The list of products added to the order + attr_accessor :extra_amount + # The list of products added to the order attr_accessor :products From 76bd1c503fd688b6859e7d79426acd986e6c63f7 Mon Sep 17 00:00:00 2001 From: = <=> Date: Thu, 28 Jun 2012 03:19:56 -0300 Subject: [PATCH 20/20] Extra amount adjustment --- lib/pagseguro/order.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pagseguro/order.rb b/lib/pagseguro/order.rb index 90fade9..dc80d6e 100644 --- a/lib/pagseguro/order.rb +++ b/lib/pagseguro/order.rb @@ -16,7 +16,7 @@ class Order :email => "cliente_email" } - # The list of products added to the order + # Optional: extra amount on the purchase (negative for discount attr_accessor :extra_amount # The list of products added to the order