Class: UpiLink::UriBuilder
- Inherits:
-
Object
- Object
- UpiLink::UriBuilder
- Defined in:
- lib/upi_link/uri_builder.rb
Instance Attribute Summary collapse
-
#am ⇒ Object
readonly
Returns the value of attribute am.
-
#cu ⇒ Object
readonly
Returns the value of attribute cu.
-
#mc ⇒ Object
readonly
Returns the value of attribute mc.
-
#pa ⇒ Object
readonly
Returns the value of attribute pa.
-
#pn ⇒ Object
readonly
Returns the value of attribute pn.
-
#tn ⇒ Object
readonly
Returns the value of attribute tn.
-
#tr ⇒ Object
readonly
Returns the value of attribute tr.
Instance Method Summary collapse
-
#initialize(pa:, pn:, am: nil, tn: nil, tr: nil, cu: "INR", mc: nil) ⇒ UriBuilder
constructor
A new instance of UriBuilder.
- #to_s ⇒ Object
Constructor Details
#initialize(pa:, pn:, am: nil, tn: nil, tr: nil, cu: "INR", mc: nil) ⇒ UriBuilder
Returns a new instance of UriBuilder.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/upi_link/uri_builder.rb', line 7 def initialize(pa:, pn:, am: nil, tn: nil, tr: nil, cu: "INR", mc: nil) VpaValidator.validate!(pa) raise ArgumentError, "pn (payee name) is required" if pn.nil? || pn.strip.empty? @pa = pa @pn = pn @am = format_amount(am) @tn = tn @tr = tr @cu = cu @mc = mc end |
Instance Attribute Details
#am ⇒ Object (readonly)
Returns the value of attribute am.
5 6 7 |
# File 'lib/upi_link/uri_builder.rb', line 5 def am @am end |
#cu ⇒ Object (readonly)
Returns the value of attribute cu.
5 6 7 |
# File 'lib/upi_link/uri_builder.rb', line 5 def cu @cu end |
#mc ⇒ Object (readonly)
Returns the value of attribute mc.
5 6 7 |
# File 'lib/upi_link/uri_builder.rb', line 5 def mc @mc end |
#pa ⇒ Object (readonly)
Returns the value of attribute pa.
5 6 7 |
# File 'lib/upi_link/uri_builder.rb', line 5 def pa @pa end |
#pn ⇒ Object (readonly)
Returns the value of attribute pn.
5 6 7 |
# File 'lib/upi_link/uri_builder.rb', line 5 def pn @pn end |
#tn ⇒ Object (readonly)
Returns the value of attribute tn.
5 6 7 |
# File 'lib/upi_link/uri_builder.rb', line 5 def tn @tn end |
#tr ⇒ Object (readonly)
Returns the value of attribute tr.
5 6 7 |
# File 'lib/upi_link/uri_builder.rb', line 5 def tr @tr end |
Instance Method Details
#to_s ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/upi_link/uri_builder.rb', line 20 def to_s params = { pa: pa, pn: pn, cu: cu } params[:am] = am if am params[:tn] = tn if tn && !tn.strip.empty? params[:tr] = tr if tr && !tr.strip.empty? params[:mc] = mc if mc && !mc.strip.empty? query = params.map { |k, v| "#{k}=#{URI.encode_www_form_component(v)}" }.join("&") "upi://pay?#{query}" end |