Class: XapoTools::MicroPayment

Inherits:
Object
  • Object
show all
Defined in:
lib/xapo_tools.rb

Overview

Xapo’s payment buttons snippet builder.

This class allows the construction of 2 kind of widgets, div and iframe. The result is a HTML snippet that could be embedded in a web page for doing micro payments though a payment button.

Params:

+service_url+ (str): The endpoint URL that returns the payment widget.
+app_id+ (str, optional): The id of the TPA for which the widget will be created.
+app_secret+ (str, optional): The TPA secret used to encrypt widget configuration.

Instance Method Summary collapse

Constructor Details

#initialize(service_url, app_id = nil, app_secret = nil) ⇒ MicroPayment

Returns a new instance of MicroPayment.



89
90
91
92
93
# File 'lib/xapo_tools.rb', line 89

def initialize(service_url, app_id=nil, app_secret=nil)
  @service_url = service_url
  @app_id = app_id
  @app_secret = app_secret
end

Instance Method Details

#build_div_widget(config, customization = XapoTools::micro_payment_customization) ⇒ Object

Build div HTML snippet in order to be embedded in apps.

Params:

+config+ (+Hash+): The button configuration options.
See @micro_payment_config.

Returns:

string: the div HTML snippet ot be embedded in a page.


148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/xapo_tools.rb', line 148

def build_div_widget(config, customization=XapoTools::micro_payment_customization)
  widget_url = build_url(config, customization)

  snippet = YAML::load(<<-END)
  |
      <div id="tipButtonDiv" class="tipButtonDiv"></div>
      <div id="tipButtonPopup" class="tipButtonPopup"></div>
      <script>
          $(document).ready(function() {{
              $("#tipButtonDiv").load("#{widget_url}");
          }});
      </script>
  END

  return snippet
end

#build_iframe_widget(config, customization = XapoTools::micro_payment_customization) ⇒ Object

Build an iframe HTML snippet in order to be embedded in apps.

Params:

+config+ (+Hash+): The button configuration options.
See @micro_payment_config.

Returns:

string: the iframe HTML snippet ot be embedded in a page.


126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/xapo_tools.rb', line 126

def build_iframe_widget(config, customization=XapoTools::micro_payment_customization)
  widget_url = build_url(config, customization)

  snippet = YAML::load(<<-END)
  |
      <iframe id="tipButtonFrame" scrolling="no" frameborder="0"
          style="border:none; overflow:hidden; height:22px;"
          allowTransparency="true" src="#{widget_url}">
      </iframe>
  END

  return snippet
end