Class: Payu::PaymentForm
- Inherits:
-
Object
- Object
- Payu::PaymentForm
- Defined in:
- lib/payu/payment_form.rb
Overview
Return value of Client#build_payment. No network call is made to produce this — it's just the signed field set and the URL to post it to.
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#payment_url ⇒ Object
readonly
Returns the value of attribute payment_url.
Instance Method Summary collapse
-
#initialize(payment_url:, fields:) ⇒ PaymentForm
constructor
A new instance of PaymentForm.
-
#to_h ⇒ Object
Shape expected by the bundled payu-checkout.js: new PayuCheckout(data).open().
-
#to_html ⇒ Object
A complete, self-contained HTML page that auto-submits to PayU on load.
Constructor Details
#initialize(payment_url:, fields:) ⇒ PaymentForm
Returns a new instance of PaymentForm.
9 10 11 12 |
# File 'lib/payu/payment_form.rb', line 9 def initialize(payment_url:, fields:) @payment_url = payment_url @fields = fields end |
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
7 8 9 |
# File 'lib/payu/payment_form.rb', line 7 def fields @fields end |
#payment_url ⇒ Object (readonly)
Returns the value of attribute payment_url.
7 8 9 |
# File 'lib/payu/payment_form.rb', line 7 def payment_url @payment_url end |
Instance Method Details
#to_h ⇒ Object
Shape expected by the bundled payu-checkout.js: new PayuCheckout(data).open()
15 |
# File 'lib/payu/payment_form.rb', line 15 def to_h = { payment_url: @payment_url, fields: @fields } |
#to_html ⇒ Object
A complete, self-contained HTML page that auto-submits to PayU on load. Render this from a single GET route (e.g. GET /checkout/:id/pay) and that URL is all a client needs: redirect a browser to it, or point a mobile WebView at it — no client-side form building required either way. Values are HTML-escaped; a
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/payu/payment_form.rb', line 23 def to_html inputs = @fields.map { |name, value| hidden_input(name, value) }.join("\n ") <<~HTML <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Redirecting to PayU…</title> </head> <body onload="document.forms[0].submit()"> <form method="POST" action="#{CGI.escapeHTML(@payment_url)}"> #{inputs} <noscript><button type="submit">Continue to payment</button></noscript> </form> </body> </html> HTML end |