lib/webtopay_helper.rb in webtopay-1.2.1 vs lib/webtopay_helper.rb in webtopay-1.6.0
- old
+ new
@@ -1,19 +1,23 @@
module WebToPayHelper
- def macro_form(params, &block)
- fields = {:orderid => "1", :lang => 'LIT', :amount => 0, :currency => 'LTL',
- :accepturl => 'http://google.com', :cancelurl => 'http://yahoo.com', :callbackurl => 'http://yourdomain.com',
- :projectid => WebToPay.config.project_id,
- :sign_password => WebToPay.config.sign_password,
- :test => 0}
+ def webtopay_confirm_button(text, params_or_payment, button_options = {}, form_options = {})
+ fields = { :lang => 'LIT', :currency => 'LTL', :projectid => WebToPay.config.project_id, :test => 0 }
- fields.merge!(params)
+ if params_or_payment.is_a?(Hash)
+ fields = fields.merge(params_or_payment)
+ payment = WebToPay::Payment.new(fields, sign_password: WebToPay.config.sign_password)
+ else
+ payment = params_or_payment
+ fields.each_pair do |field, value|
+ payment.public_send("#{field}=", value) if payment.public_send(field).nil?
+ end
+ end
- request = WebToPay::Api.build_request(fields)
-
- concat "<form action=\"https://www.mokejimai.lt/pay/\" method=\"post\" style=\"padding:0px;margin:0px\">".html_safe
- request.each_pair {|k,v| concat hidden_field_tag(k, v) if !v.nil? }
- yield if block_given?
- concat "</form>".html_safe
+ content_tag(:form, {action: 'https://www.mokejimai.lt/pay/', method: :post}.merge(form_options)) do
+ html = ''
+ html << hidden_field_tag(:data, payment.data)
+ html << hidden_field_tag(:sign, payment.sign)
+ html << submit_tag(text, button_options)
+ html.html_safe
+ end
end
-end
-
+end
\ No newline at end of file