payu-ruby 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +27 -3
- data/lib/payu/payment_form.rb +37 -0
- data/lib/payu/version.rb +1 -1
- data/lib/payu.rb +4 -3
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 94b40d4686b64845659c12c92c956abb4d5d68e864ffe77875c2cc695e9a87d6
|
|
4
|
+
data.tar.gz: 96af6c931aa710aac02c0bd4b0a16e60638db52bd1e58e535c77ed039df2e675
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d4f0fbbb6051bde54a99567d09e47c5749392854e6d9f8c1ae4645b85a8de14bc47a332a04eda68b06c4346413ba96ceab8da90bf4176f981191919f2cfcc2b8
|
|
7
|
+
data.tar.gz: 5f237b35f525398bc77a74200e45172ae549cfed9cf589fedbc7fbc43adc42f3ff6ac31754e5a452a4608225f5690dcac2e277a81a4d22b572881ab39e1b660b
|
data/README.md
CHANGED
|
@@ -57,9 +57,33 @@ refund.status(result.mihpayid)
|
|
|
57
57
|
reported status is informational only; always follow up with
|
|
58
58
|
`verify_payment` before treating a transaction as successful.
|
|
59
59
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
## Auto-submit checkout page (web + mobile)
|
|
61
|
+
|
|
62
|
+
`form.to_html` renders a complete, self-contained HTML page that
|
|
63
|
+
auto-submits to PayU on load — a hidden form with one input per field,
|
|
64
|
+
`onload="document.forms[0].submit()"`, and a `<noscript>` fallback button.
|
|
65
|
+
Values are HTML-escaped.
|
|
66
|
+
|
|
67
|
+
Expose one route that renders it:
|
|
68
|
+
|
|
69
|
+
```ruby
|
|
70
|
+
# GET /checkout/:id/pay
|
|
71
|
+
def pay
|
|
72
|
+
form = client.build_payment(...)
|
|
73
|
+
render html: form.to_html.html_safe, content_type: "text/html"
|
|
74
|
+
end
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
That single public URL (e.g. `https://app.example.com/checkout/123/pay`) is
|
|
78
|
+
all any client needs — no client-side form building required either way:
|
|
79
|
+
|
|
80
|
+
- **Web** — redirect the browser to it, or link to it.
|
|
81
|
+
- **Mobile** — point a WebView at the same URL; the page auto-submits to
|
|
82
|
+
PayU itself, so the app never needs to construct the POST or handle
|
|
83
|
+
`fields` directly.
|
|
84
|
+
|
|
85
|
+
`form.to_h` (`{ payment_url:, fields: }`) is also available if you'd rather
|
|
86
|
+
hand the raw data to your own frontend code instead of using `to_html`.
|
|
63
87
|
|
|
64
88
|
## Error handling
|
|
65
89
|
|
data/lib/payu/payment_form.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require "cgi"
|
|
2
|
+
|
|
1
3
|
module Payu
|
|
2
4
|
# Return value of Client#build_payment. No network call is made to
|
|
3
5
|
# produce this — it's just the signed field set and the URL to post it to.
|
|
@@ -8,5 +10,40 @@ module Payu
|
|
|
8
10
|
@payment_url = payment_url
|
|
9
11
|
@fields = fields
|
|
10
12
|
end
|
|
13
|
+
|
|
14
|
+
# Shape expected by the bundled payu-checkout.js: new PayuCheckout(data).open()
|
|
15
|
+
def to_h = { payment_url: @payment_url, fields: @fields }
|
|
16
|
+
|
|
17
|
+
# A complete, self-contained HTML page that auto-submits to PayU on
|
|
18
|
+
# load. Render this from a single GET route (e.g. GET /checkout/:id/pay)
|
|
19
|
+
# and that URL is all a client needs: redirect a browser to it, or point
|
|
20
|
+
# a mobile WebView at it — no client-side form building required either
|
|
21
|
+
# way. Values are HTML-escaped; a <noscript> button covers JS-disabled
|
|
22
|
+
# browsers.
|
|
23
|
+
def to_html
|
|
24
|
+
inputs = @fields.map { |name, value| hidden_input(name, value) }.join("\n ")
|
|
25
|
+
|
|
26
|
+
<<~HTML
|
|
27
|
+
<!DOCTYPE html>
|
|
28
|
+
<html>
|
|
29
|
+
<head>
|
|
30
|
+
<meta charset="utf-8">
|
|
31
|
+
<title>Redirecting to PayU…</title>
|
|
32
|
+
</head>
|
|
33
|
+
<body onload="document.forms[0].submit()">
|
|
34
|
+
<form method="POST" action="#{CGI.escapeHTML(@payment_url)}">
|
|
35
|
+
#{inputs}
|
|
36
|
+
<noscript><button type="submit">Continue to payment</button></noscript>
|
|
37
|
+
</form>
|
|
38
|
+
</body>
|
|
39
|
+
</html>
|
|
40
|
+
HTML
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
private
|
|
44
|
+
|
|
45
|
+
def hidden_input(name, value)
|
|
46
|
+
%(<input type="hidden" name="#{CGI.escapeHTML(name.to_s)}" value="#{CGI.escapeHTML(value.to_s)}">)
|
|
47
|
+
end
|
|
11
48
|
end
|
|
12
49
|
end
|
data/lib/payu/version.rb
CHANGED
data/lib/payu.rb
CHANGED
|
@@ -32,6 +32,7 @@ require "payu/refund"
|
|
|
32
32
|
# )
|
|
33
33
|
# form.payment_url # => URL to POST form.fields to (form submit or WebView)
|
|
34
34
|
# form.fields # => Hash of all form fields including :hash
|
|
35
|
+
# form.to_html # => self-contained auto-submitting checkout page
|
|
35
36
|
#
|
|
36
37
|
# # 2. Verify an inbound callback/redirect's hash (never trust it for final state)
|
|
37
38
|
# callback = client.verify_callback(params)
|
|
@@ -43,8 +44,8 @@ require "payu/refund"
|
|
|
43
44
|
# result.mihpayid
|
|
44
45
|
# result.raw # full parsed JSON, for audit logging
|
|
45
46
|
#
|
|
46
|
-
#
|
|
47
|
-
#
|
|
48
|
-
#
|
|
47
|
+
# form.to_html renders a complete auto-submitting checkout page — expose it
|
|
48
|
+
# from one GET route and that URL is all any client needs: redirect a
|
|
49
|
+
# browser to it, or point a mobile WebView at it. See README for details.
|
|
49
50
|
module Payu
|
|
50
51
|
end
|