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.

Attributes:

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.



56
57
58
59
60
# File 'lib/xapo_tools.rb', line 56

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) ⇒ Object

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

Args:

config (MicroPaymentConfig): The button configuration options.
See @MicroPaymentConfig.

Returns:

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


115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/xapo_tools.rb', line 115

def build_div_widget(config)
  widget_url = build_url(config)

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

#build_iframe_widget(config) ⇒ Object

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

Args:

config (MicroPaymentConfig): The button configuration options.
See @MicroPaymentConfig.

Returns:

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


93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/xapo_tools.rb', line 93

def build_iframe_widget(config)
  widget_url = build_url(config)

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