xapo_sdk 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +8 -181
- data/lib/xapo_api.rb +14 -8
- data/lib/xapo_sdk/version.rb +1 -1
- data/lib/xapo_tools.rb +66 -32
- data/test/test_xapo_api.rb +11 -2
- data/test/test_xapo_tools.rb +73 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 871f7523590b9e02591a7893f9f332cfb9e9162a
|
4
|
+
data.tar.gz: a38c8e8dac78651273131220e4561e8a3cea2e17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 109aad64ffc30cc73240cc13af47643899188e37976c08dab9f19c549c7fabdf5e335a1235cc9a5d9262c2101249eaed9ea0cd8aee5b9bc12636cd8549b1ce77
|
7
|
+
data.tar.gz: c1569ea70db9e650a08f73aa14fcfc7eb84d179c7c5cc4997d4b3781bf5f61b794e53012c73a85dcc301dabc977987ce5a6c0e0c1c8e9877f2ea1f0ea3ee4c3d
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,26 +1,22 @@
|
|
1
1
|
# README
|
2
2
|
|
3
|
-
>This is the Ruby version of the Xapo's Widget Tools. These tools allow you (Third Party Application, TPA) to easily embed tools like Payments Buttons, Donation Buttons and other kind of widgets
|
3
|
+
>This is the Ruby version of the Xapo's SDK & Widget Tools. These tools allow you (Third Party Application, TPA) to easily develop your bitcoins applications to manage *Accounts, Wallets, Transactions*, etc., or embed tools like *Payments Buttons, Donation Buttons* and other kind of widgets into your web application using your language of choice. In this way, tedious details like encryption and HTML snippet generation are handled for you in a simple and transparent way.
|
4
|
+
|
5
|
+
For more information please visit: http://developers.xapo.com
|
4
6
|
|
5
7
|
---
|
6
8
|
|
9
|
+
[![Gem Version](https://badge.fury.io/rb/xapo_sdk.svg)](http://badge.fury.io/rb/xapo_sdk)
|
10
|
+
[![Build Status](https://travis-ci.org/xapo/ruby-sdk.svg?branch=master)](https://travis-ci.org/xapo/ruby-sdk)
|
11
|
+
|
7
12
|
[Changelog](CHANGELOG.md)
|
8
13
|
|
14
|
+
## Table of Contents
|
9
15
|
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
10
16
|
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
11
|
-
## Table of Contents
|
12
17
|
|
13
18
|
- [Build](#build)
|
14
19
|
- [Installation](#installation)
|
15
|
-
- [API](#api)
|
16
|
-
- [Credit](#credit)
|
17
|
-
- [Parameters](#parameters)
|
18
|
-
- [Result](#result)
|
19
|
-
- [Usage Example](#usage-example)
|
20
|
-
- [Micro Payment Widgets](#micro-payment-widgets)
|
21
|
-
- [IFrame Widget](#iframe-widget)
|
22
|
-
- [Div Widget](#div-widget)
|
23
|
-
- [Widgets Gallery](#widgets-gallery)
|
24
20
|
- [Contributing](#contributing)
|
25
21
|
- [TODO](#todo)
|
26
22
|
|
@@ -56,175 +52,6 @@ Or install it yourself as:
|
|
56
52
|
|
57
53
|
$ gem install xapo_sdk
|
58
54
|
|
59
|
-
## API
|
60
|
-
|
61
|
-
The of the API allows third party application to interact with Xapo wallets and resources in a simple and intuitive way.
|
62
|
-
|
63
|
-
|
64
|
-
Development Environment:
|
65
|
-
|
66
|
-
> http://dev.xapo.com/api/v1
|
67
|
-
|
68
|
-
### Credit
|
69
|
-
|
70
|
-
The Credit API allows any Third Party Application (TPA) to load Bitcoins into any Xapo Wallet using a secure App_ID + App_Shared_Key authentication method.
|
71
|
-
|
72
|
-
#### Parameters
|
73
|
-
|
74
|
-
- **To:** ``(string, mandatory)`` any email, BTC address or mobile number.
|
75
|
-
- **Currency:** ``(Currency, mandatory)`` any of ``Currency.BTC`` or ``Currency.SAT`` .
|
76
|
-
- **Amount:** ``(numeric, mandatory)`` amount to be credited.
|
77
|
-
- **Comments:** ``(string, optional)`` note or message to attach to the transaction.
|
78
|
-
- **Subject:** ``(string, optional)`` if specified, will be used as email subject (when crediting an email address) or SMS text (when crediting a mobile #).
|
79
|
-
- **Timestamp:** ``(int, mandatory)`` UTC Unix Timestamp. The request will be rejected if using a timestamp not equal or greater than the last used by previous request.
|
80
|
-
- **Resquest Id:** ``(string, mandatory)`` any ID that uniquely identifies this request. Cannot be repeated with any new request.
|
81
|
-
|
82
|
-
#### Result
|
83
|
-
|
84
|
-
The result is a dictionary containing:
|
85
|
-
|
86
|
-
| Key | Type | Description |
|
87
|
-
|---------| ------- | ----------- |
|
88
|
-
| success | boolean | Indicates whether the request was successfully processed or not |
|
89
|
-
| code | string | A response |
|
90
|
-
| message | string | Description of the result |
|
91
|
-
|
92
|
-
Error codes:
|
93
|
-
|
94
|
-
| Code | Message |
|
95
|
-
| --------------- | ------- |
|
96
|
-
Success | Wallet successfully credited |
|
97
|
-
InvalidRequest | Either the App token or Hash are invalid |
|
98
|
-
ExpiredRequest | The request timestamp and/or unique_request_id have expired |
|
99
|
-
InvalidWallet | Wallet not linked with this APP |
|
100
|
-
InvalidEmail | The destination email is invalid |
|
101
|
-
InvalidBTCAddress | The destination BTC address is invalid |
|
102
|
-
InvalidCellphone | The destination mobile number is invalid |
|
103
|
-
InvalidCurrency | The currency is invalid |
|
104
|
-
InvalidAmount | The amount to deposit is invalid |
|
105
|
-
MinimumAmount | The amount to deposit must be at least XXX |
|
106
|
-
InsufficientFunds | The wallet you are withdrawing from does not have enough available balance to fulfill the Deposit |
|
107
|
-
|
108
|
-
|
109
|
-
#### Usage Example
|
110
|
-
|
111
|
-
```ruby
|
112
|
-
|
113
|
-
require "xapo_api"
|
114
|
-
require "securerandom"
|
115
|
-
|
116
|
-
...
|
117
|
-
|
118
|
-
# config the api
|
119
|
-
api = Xapo::API.new(SERVICE_URL, APP_ID, APP_SECRET)
|
120
|
-
|
121
|
-
...
|
122
|
-
|
123
|
-
# call cerdit service
|
124
|
-
res = api.credit('sample@xapo.com', 0.5, SecureRandom.hex,
|
125
|
-
currency: Xapo::Currency::BTC,
|
126
|
-
comments: "Sample deposit")
|
127
|
-
|
128
|
-
puts(res)
|
129
|
-
```
|
130
|
-
|
131
|
-
|
132
|
-
## Micro Payment Widgets
|
133
|
-
Micro payment widgets allow to dynamically get a HTML snippet pre-configured and insert into your web page. Micro payment widgets provides 4 kind of pre-configured actions __Pay, Donate, Tip__ and __Deposit__. The widgets allow the following configurations:
|
134
|
-
|
135
|
-
- **Amount BIT:** `[optional]` sets a fixed amount for the intended payment.
|
136
|
-
- **Sender's Id:** `[optional]` any identifier used in the TPA context to identify the sender.
|
137
|
-
- **Sender's email:** `[optional]` used to pre-load the widget with the user's email.
|
138
|
-
- **Sender's cellphone:** `[optional]` used to pre-load the widget with the user's cellphone.
|
139
|
-
- **Receiver's Id:** `[mandatory]` any receiver's user unique identifier in the TPA context.
|
140
|
-
- **Receiver's email:** `[mandatory]` the email of the user receiving the payment. It allows XAPO to contact the receiver to claim her payment.
|
141
|
-
- **Pay Object's Id:** `[mandatory]` any unique identifier in the context of the TPA distinguishing the object of the payment.
|
142
|
-
- **Pay type:** `[optional]` any of Donate | Pay | Tip | Deposit.
|
143
|
-
|
144
|
-
Be aware that micro payments could be optionally configured with your own application id and secret (`app_id`/`app_secret`). Configuring the micro payment with your application credentials allows you to charge a transaction fee for example.
|
145
|
-
|
146
|
-
### IFrame Widget
|
147
|
-
```ruby
|
148
|
-
require 'xapo_tools'
|
149
|
-
|
150
|
-
...
|
151
|
-
|
152
|
-
micro_payment = XapoTools::MicroPayment.new(
|
153
|
-
XAPO_URL,
|
154
|
-
APP_ID, # optional
|
155
|
-
APP_SECRET # optional
|
156
|
-
)
|
157
|
-
config = XapoTools.micro_payment_config
|
158
|
-
|
159
|
-
config[:sender_user_email] = "sender@xapo.com"
|
160
|
-
config[:sender_user_cellphone] = "+5491112341234"
|
161
|
-
config[:receiver_user_id] = "r0210"
|
162
|
-
config[:receiver_user_email] = "fernando.taboada@xapo.com"
|
163
|
-
config[:pay_object_id] = "to0210"
|
164
|
-
config[:amount_BIT] = 0.01
|
165
|
-
config[:pay_type] = PayType::DONATE
|
166
|
-
|
167
|
-
# Get IFRAME snippet
|
168
|
-
String iframe = microPayment.buildIframeWidget(request);
|
169
|
-
```
|
170
|
-
|
171
|
-
With this you get the following snippet:
|
172
|
-
|
173
|
-
```html
|
174
|
-
<iframe id='tipButtonFrame' scrolling='no' frameborder='0' style='border:none; overflow:hidden; height:22px;' allowTransparency='true' src='http://dev.xapo.com:8089/pay_button/show?customization=%7B%22button_text%22%3A%22Tip%22%7D&app_id=b91014cc28c94841&button_request=C%2F6OaxS0rh3jMhH90kRYyp3y%2BU5ADcCgMLCyz2P5ssFG%2FJoGf55ccvicyRMuIXpU5xhDeHGffpZAvVeMCpJhGFyIPwLFh%2FVdnjnDUjYgJCQeB4mCpGsEW5SC6wNvg69ksgeAtr108Wc5miA8H4JG99EWTTlC7WtIGg5rFKkbjrop15fSJfhv5cTs02jSC5f2BaLlh1mKh5hSPW3HGcWcl%2BdyZj%2F9m1lPB4gKfky2%2FnT0tYjbEFo5aU6WtowWrf2xE8OYejyI0poEFkClBkv2eDkp4Gel4tGb%2Bkwszcyb18ztK89RlBwhe8sX4HeM2KJM8ZaWuDOGH2VW4kbThMCZEw%3D%3D'></iframe>
|
175
|
-
```
|
176
|
-
|
177
|
-
See the example results in the [widgets gallery](#widgets-gallery).
|
178
|
-
|
179
|
-
### Div Widget
|
180
|
-
```ruby
|
181
|
-
require 'xapo_tools'
|
182
|
-
|
183
|
-
...
|
184
|
-
|
185
|
-
micro_payment = XapoTools::MicroPayment.new(
|
186
|
-
XAPO_URL,
|
187
|
-
APP_ID, # optional
|
188
|
-
APP_SECRET # optional
|
189
|
-
)
|
190
|
-
config = XapoTools.micro_payment_config
|
191
|
-
|
192
|
-
config[:sender_user_email] = "sender@xapo.com"
|
193
|
-
config[:sender_user_cellphone] = "+5491112341234"
|
194
|
-
config[:receiver_user_id] = "r0210"
|
195
|
-
config[:receiver_user_email] = "fernando.taboada@xapo.com"
|
196
|
-
config[:pay_object_id] = "to0210"
|
197
|
-
config[:amount_BIT] = 0.01
|
198
|
-
config[:pay_type] = PayType::TIP
|
199
|
-
|
200
|
-
# PayType::TIP | PayType::PAY | PayType::DEPOSIT | PayType::DONATE
|
201
|
-
config[:pay_type] = PayType::DONATE
|
202
|
-
|
203
|
-
# Get DIV snippet
|
204
|
-
xapo_tools.build_div_widget(config)
|
205
|
-
```
|
206
|
-
|
207
|
-
With this you get the following snippet:
|
208
|
-
|
209
|
-
```html
|
210
|
-
<div id='tipButtonDiv' class='tipButtonDiv'></div>
|
211
|
-
<div id='tipButtonPopup' class='tipButtonPopup'></div>
|
212
|
-
<script>
|
213
|
-
$(document).ready(function() {$('#tipButtonDiv').load('http://dev.xapo.com:8089/pay_button/show?customization=%7B%22button_text%22%3A%22Donate%22%7D&app_id=b91014cc28c94841&button_request=C%2F6OaxS0rh3jMhH90kRYyp3y%2BU5ADcCgMLCyz2P5ssFG%2FJoGf55ccvicyRMuIXpU5xhDeHGffpZAvVeMCpJhGFyIPwLFh%2FVdnjnDUjYgJCQeB4mCpGsEW5SC6wNvg69ksgeAtr108Wc5miA8H4JG99EWTTlC7WtIGg5rFKkbjrop15fSJfhv5cTs02jSC5f2BaLlh1mKh5hSPW3HGcWcl%2BdyZj%2F9m1lPB4gKfky2%2FnT0tYjbEFo5aU6WtowWrf2xE8OYejyI0poEFkClBkv2eDkp4Gel4tGb%2Bkwszcyb18ztK89RlBwhe8sX4HeM2KJMHVfAM8NQXQu8oiIyCAl0vg%3D%3D');});
|
214
|
-
</script>
|
215
|
-
```
|
216
|
-
|
217
|
-
See the example results in the [widgets gallery](#widgets-gallery).
|
218
|
-
|
219
|
-
### Widgets Gallery
|
220
|
-
|
221
|
-
![payment button](http://developers.xapo.com/images/payment_widget/donate_button.png)
|
222
|
-
|
223
|
-
![payment phone](http://developers.xapo.com/images/payment_widget/mpayment1.png)
|
224
|
-
|
225
|
-
![payment email](http://developers.xapo.com/images/payment_widget/mpayment2.png)
|
226
|
-
|
227
|
-
![payment pin](http://developers.xapo.com/images/payment_widget/mpayment3.png)
|
228
55
|
|
229
56
|
## Contributing
|
230
57
|
|
@@ -237,7 +64,7 @@ See the example results in the [widgets gallery](#widgets-gallery).
|
|
237
64
|
## TODO
|
238
65
|
- ~~Fix style (https://github.com/bbatsov/ruby-style-guide#naming)~~
|
239
66
|
- ~~Add unit testing~~
|
240
|
-
- Document, document
|
67
|
+
- Document, ~~document~~, ~~document~~
|
241
68
|
- ~~Review naming and organization (with respect to Java & Python?)~~
|
242
69
|
- ~~Review `gem` build infraestructure~~
|
243
70
|
- ...
|
data/lib/xapo_api.rb
CHANGED
@@ -5,14 +5,6 @@ require "json"
|
|
5
5
|
require "uri"
|
6
6
|
require "net/http"
|
7
7
|
|
8
|
-
# Xapo's API.
|
9
|
-
#
|
10
|
-
# This class allows the interaction with bitcoins APIs provided with Xapo.
|
11
|
-
#
|
12
|
-
# Attributes:
|
13
|
-
# service_url (str): The endpoint URL that returns the payment widget.
|
14
|
-
# app_id (str, optional): The id of the TPA for which the widget will be created.
|
15
|
-
# app_secret (str, optional): The TPA secret used to encrypt widget configuration.
|
16
8
|
module Xapo
|
17
9
|
|
18
10
|
module_function
|
@@ -22,6 +14,14 @@ module Xapo
|
|
22
14
|
SAT = "SAT"
|
23
15
|
end
|
24
16
|
|
17
|
+
# Xapo's API.
|
18
|
+
#
|
19
|
+
# This class allows the interaction with bitcoins APIs provided with Xapo.
|
20
|
+
#
|
21
|
+
# Params:
|
22
|
+
# +service_url+ (str): The endpoint URL that returns the payment widget.
|
23
|
+
# +app_id+ (str): The id of the TPA doing the credit.
|
24
|
+
# +app_secret+ (str): The TPA secret used to encrypt payload.
|
25
25
|
class API
|
26
26
|
def initialize(service_url, app_id, app_secret)
|
27
27
|
@service_url = service_url
|
@@ -30,6 +30,12 @@ module Xapo
|
|
30
30
|
@credit_resource = '/credit/'
|
31
31
|
end
|
32
32
|
|
33
|
+
# Transfer a given amount from the main wallet of the TPA to a given sub account.
|
34
|
+
#
|
35
|
+
# Params:
|
36
|
+
# +to+ (str): the destination of the credit.
|
37
|
+
# +amount+ (decimal): the amount to be credited.
|
38
|
+
# +currency+ (Xapo::Currency): the currency of the operation (SAT|BTC).
|
33
39
|
def credit(to, amount, request_id, currency: Xapo::Currency::BTC,
|
34
40
|
comments: "", subject: "")
|
35
41
|
timestamp = XapoUtils.timestamp
|
data/lib/xapo_sdk/version.rb
CHANGED
data/lib/xapo_tools.rb
CHANGED
@@ -15,19 +15,27 @@ module XapoTools
|
|
15
15
|
# payments buttons configuration but also serves for documenting. A
|
16
16
|
# hash with the intended fields would give the same results.
|
17
17
|
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
18
|
+
# Params:
|
19
|
+
# +sender_user_id+ (str): The id of the user sending the payment.
|
20
|
+
# +sender_user_email+ (str, optional): The email of the user sending
|
21
|
+
# the payment.
|
22
|
+
# +sender_user_cellphone+ (str, optional): The celphone number of the user
|
23
|
+
# sending the payment.
|
24
|
+
# +receiver_user_id+ (str): The id of the user receiving the payment.
|
25
|
+
# +receiver_user_email+ (str): The email of the user receiving the payment.
|
26
|
+
# +pay_object_id+ (str): A payment identifier in the TPA context.
|
27
|
+
# +amount_BIT+ (float, optional): The amount of bitcoins to be payed by the
|
28
|
+
# widget. If not specified here, it must be entered on payment basis.
|
29
|
+
# +pay_type+ (str): The string representing the type of operation
|
30
|
+
# ("Tip", "Pay", "Deposit" or "Donate").
|
31
|
+
# +reference_code+ (str, optional): A custom tag to be tracked by the TPA. It's
|
32
|
+
# sent back to the TPA in the specified callback (see customization).
|
33
|
+
# +end_mpayment_uri+ (str, optional): The callback URL to notify a successful
|
34
|
+
# micro payment. The callback will be called with parameters
|
35
|
+
# "reference_code" and "request_UID".
|
36
|
+
# +redirect_uri+ (str, optional): redirect URL after a successful OAuth flow.
|
37
|
+
# The URL must accept a "code" parameter if access is granted or
|
38
|
+
# "error" and "error_description" in case of denial.
|
31
39
|
def micro_payment_config
|
32
40
|
return Hash[
|
33
41
|
:sender_user_id => "",
|
@@ -38,7 +46,32 @@ module XapoTools
|
|
38
46
|
:pay_object_id => "",
|
39
47
|
:amount_BIT => 0,
|
40
48
|
:timestamp => XapoUtils.timestamp,
|
41
|
-
:pay_type => ""
|
49
|
+
:pay_type => "",
|
50
|
+
:reference_code => "",
|
51
|
+
:end_mpayment_uri => "",
|
52
|
+
:redirect_uri => "",
|
53
|
+
]
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
# Micro payment button customization options.
|
58
|
+
#
|
59
|
+
# This function is intended to be a helper for creating empty micro
|
60
|
+
# payments buttons customization but also serves for documenting. A
|
61
|
+
# hash with the intended fields would give the same results.
|
62
|
+
#
|
63
|
+
# Params:
|
64
|
+
# +login_cellphone_header_title+ (str, optional): Text to appear in the login
|
65
|
+
# screen. Default: "Support content creators by sending them bits.
|
66
|
+
# New users receive 50 bits to get started!"
|
67
|
+
# +predefined_pay_values+ (str, optional): A string of comma separated
|
68
|
+
# amount values, e.g. "1,5,10".
|
69
|
+
# +button_css+ (str, optional): optional CSS button customization ("red" | "grey").
|
70
|
+
def micro_payment_customization
|
71
|
+
return Hash[
|
72
|
+
:login_cellphone_header_title => "",
|
73
|
+
:predefined_pay_values => "",
|
74
|
+
:button_css => ""
|
42
75
|
]
|
43
76
|
end
|
44
77
|
|
@@ -48,10 +81,10 @@ module XapoTools
|
|
48
81
|
# *iframe*. The result is a HTML snippet that could be embedded in a
|
49
82
|
# web page for doing micro payments though a payment button.
|
50
83
|
#
|
51
|
-
#
|
52
|
-
#
|
53
|
-
#
|
54
|
-
#
|
84
|
+
# Params:
|
85
|
+
# +service_url+ (str): The endpoint URL that returns the payment widget.
|
86
|
+
# +app_id+ (str, optional): The id of the TPA for which the widget will be created.
|
87
|
+
# +app_secret+ (str, optional): The TPA secret used to encrypt widget configuration.
|
55
88
|
class MicroPayment
|
56
89
|
def initialize(service_url, app_id=nil, app_secret=nil)
|
57
90
|
@service_url = service_url
|
@@ -59,13 +92,13 @@ module XapoTools
|
|
59
92
|
@app_secret = app_secret
|
60
93
|
end
|
61
94
|
|
62
|
-
def build_url(config)
|
63
|
-
json_config = JSON.generate(config)
|
95
|
+
def build_url(config, customization)
|
96
|
+
json_config = JSON.generate(config, customization)
|
64
97
|
|
65
98
|
if @app_secret == nil || @app_id == nil
|
66
99
|
query_str = URI.encode_www_form(
|
67
100
|
:payload => json_config,
|
68
|
-
:customization => JSON.generate(
|
101
|
+
:customization => JSON.generate(customization)
|
69
102
|
)
|
70
103
|
else
|
71
104
|
encrypted_config = XapoUtils.encrypt(json_config, @app_secret)
|
@@ -73,7 +106,7 @@ module XapoTools
|
|
73
106
|
query_str = URI.encode_www_form(
|
74
107
|
:app_id => @app_id,
|
75
108
|
:button_request => encrypted_config,
|
76
|
-
:customization => JSON.generate(
|
109
|
+
:customization => JSON.generate(customization)
|
77
110
|
)
|
78
111
|
end
|
79
112
|
|
@@ -84,14 +117,14 @@ module XapoTools
|
|
84
117
|
|
85
118
|
# Build an iframe HTML snippet in order to be embedded in apps.
|
86
119
|
#
|
87
|
-
#
|
88
|
-
# config (
|
89
|
-
# See @
|
120
|
+
# Params:
|
121
|
+
# +config+ (+Hash+): The button configuration options.
|
122
|
+
# See @micro_payment_config.
|
90
123
|
#
|
91
124
|
# Returns:
|
92
125
|
# string: the iframe HTML snippet ot be embedded in a page.
|
93
|
-
def build_iframe_widget(config)
|
94
|
-
widget_url = build_url(config)
|
126
|
+
def build_iframe_widget(config, customization=XapoTools::micro_payment_customization)
|
127
|
+
widget_url = build_url(config, customization)
|
95
128
|
|
96
129
|
snippet = YAML::load(<<-END)
|
97
130
|
|
|
@@ -106,14 +139,14 @@ module XapoTools
|
|
106
139
|
|
107
140
|
# Build div HTML snippet in order to be embedded in apps.
|
108
141
|
#
|
109
|
-
#
|
110
|
-
# config (
|
111
|
-
# See @
|
142
|
+
# Params:
|
143
|
+
# +config+ (+Hash+): The button configuration options.
|
144
|
+
# See @micro_payment_config.
|
112
145
|
#
|
113
146
|
# Returns:
|
114
147
|
# string: the div HTML snippet ot be embedded in a page.
|
115
|
-
def build_div_widget(config)
|
116
|
-
widget_url = build_url(config)
|
148
|
+
def build_div_widget(config, customization=XapoTools::micro_payment_customization)
|
149
|
+
widget_url = build_url(config, customization)
|
117
150
|
|
118
151
|
snippet = YAML::load(<<-END)
|
119
152
|
|
|
@@ -138,4 +171,5 @@ module PayType
|
|
138
171
|
DONATE = "Donate"
|
139
172
|
PAY = "Pay"
|
140
173
|
DEPOSIT = "Deposit"
|
174
|
+
OAUTH = "Oauth"
|
141
175
|
end
|
data/test/test_xapo_api.rb
CHANGED
@@ -6,12 +6,15 @@ class TestXapoAPI < Minitest::Test
|
|
6
6
|
def setup
|
7
7
|
@api = Xapo::API.new(
|
8
8
|
"http://dev.xapo.com/api/v1",
|
9
|
-
"
|
10
|
-
"
|
9
|
+
"your app id",
|
10
|
+
"your app secret"
|
11
11
|
)
|
12
12
|
end
|
13
13
|
|
14
14
|
def test_credit()
|
15
|
+
# TODO: remove skip
|
16
|
+
skip("Set app id and secret and remove this line")
|
17
|
+
|
15
18
|
res = @api.credit('sample@xapo.com', 1, SecureRandom.hex,
|
16
19
|
currency: Xapo::Currency::SAT,
|
17
20
|
comments: "Sample deposit")
|
@@ -22,6 +25,9 @@ class TestXapoAPI < Minitest::Test
|
|
22
25
|
end
|
23
26
|
|
24
27
|
def test_credit_bad_ammount()
|
28
|
+
# TODO: remove skip
|
29
|
+
skip("Set app id and secret and remove this line")
|
30
|
+
|
25
31
|
res = @api.credit('sample@xapo.com', -0.5, SecureRandom.hex)
|
26
32
|
|
27
33
|
puts("test_credit -> ", res)
|
@@ -31,6 +37,9 @@ class TestXapoAPI < Minitest::Test
|
|
31
37
|
end
|
32
38
|
|
33
39
|
def test_credit_missing_to()
|
40
|
+
# TODO: remove skip
|
41
|
+
skip("Set app id and secret and remove this line")
|
42
|
+
|
34
43
|
res = @api.credit('', -0.5, SecureRandom.hex)
|
35
44
|
|
36
45
|
puts("test_credit -> ", res)
|
data/test/test_xapo_tools.rb
CHANGED
@@ -22,8 +22,15 @@ class TestXapoTools < Minitest::Test
|
|
22
22
|
config[:pay_object_id] = "to0210"
|
23
23
|
config[:amount_BIT] = 0.01
|
24
24
|
config[:pay_type] = PayType::DONATE
|
25
|
+
config[:reference_code] = "test"
|
25
26
|
|
26
|
-
|
27
|
+
customization = XapoTools.micro_payment_customization
|
28
|
+
customization[:predefined_pay_values] = "1,5,10"
|
29
|
+
customization[:end_mpayment_uri] = "http://localhost:9000"
|
30
|
+
customization[:redirect_uri] = "http://localhost:9000"
|
31
|
+
customization[:button_css] = "grey"
|
32
|
+
|
33
|
+
actual = @xapo_tools.build_iframe_widget(config, customization)
|
27
34
|
puts("test_build_iframe_widget -> ", actual)
|
28
35
|
|
29
36
|
assert_match(/<iframe(.*)button_request(.*)>(.*)<\/iframe>\n/m, actual)
|
@@ -38,13 +45,37 @@ class TestXapoTools < Minitest::Test
|
|
38
45
|
config[:pay_object_id] = "to0210"
|
39
46
|
config[:amount_BIT] = 0.01
|
40
47
|
config[:pay_type] = PayType::DONATE
|
48
|
+
config[:reference_code] = "test"
|
49
|
+
|
50
|
+
customization = XapoTools.micro_payment_customization
|
51
|
+
customization[:predefined_pay_values] = "1,5,10"
|
52
|
+
customization[:end_mpayment_uri] = "http://localhost:9000"
|
53
|
+
customization[:redirect_uri] = "http://localhost:9000"
|
54
|
+
customization[:button_css] = "red"
|
41
55
|
|
42
|
-
actual = @xapo_tools_notpa.build_iframe_widget(config)
|
56
|
+
actual = @xapo_tools_notpa.build_iframe_widget(config, customization)
|
43
57
|
puts("test_build_iframe_widget_notpa -> ", actual)
|
44
58
|
|
45
59
|
assert_match(/<iframe(.*)payload(.*)>(.*)<\/iframe>\n/m, actual)
|
46
60
|
end
|
47
61
|
|
62
|
+
def test_build_iframe_widget_np_cust()
|
63
|
+
config = XapoTools.micro_payment_config
|
64
|
+
config[:sender_user_email] = "sender@xapo.com"
|
65
|
+
config[:sender_user_cellphone] = "+5491112341234"
|
66
|
+
config[:receiver_user_id] = "r0210"
|
67
|
+
config[:receiver_user_email] = "fernando.taboada@xapo.com"
|
68
|
+
config[:pay_object_id] = "to0210"
|
69
|
+
config[:amount_BIT] = 0.01
|
70
|
+
config[:pay_type] = PayType::DONATE
|
71
|
+
config[:reference_code] = "test"
|
72
|
+
|
73
|
+
actual = @xapo_tools.build_iframe_widget(config)
|
74
|
+
puts("test_build_iframe_widget -> ", actual)
|
75
|
+
|
76
|
+
assert_match(/<iframe(.*)button_request(.*)>(.*)<\/iframe>\n/m, actual)
|
77
|
+
end
|
78
|
+
|
48
79
|
def test_build_div_widget()
|
49
80
|
config = XapoTools.micro_payment_config
|
50
81
|
config[:sender_user_email] = "sender@xapo.com"
|
@@ -54,13 +85,21 @@ class TestXapoTools < Minitest::Test
|
|
54
85
|
config[:pay_object_id] = "to0210"
|
55
86
|
config[:amount_BIT] = 0.01
|
56
87
|
config[:pay_type] = PayType::TIP
|
88
|
+
config[:reference_code] = "test"
|
89
|
+
|
90
|
+
customization = XapoTools.micro_payment_customization
|
91
|
+
customization[:predefined_pay_values] = "1,5,10"
|
92
|
+
customization[:end_mpayment_uri] = "http://localhost:9000"
|
93
|
+
customization[:redirect_uri] = "http://localhost:9000"
|
94
|
+
customization[:button_css] = "grey"
|
95
|
+
|
57
96
|
regex = /
|
58
97
|
<div\sid="tipButtonDiv"\sclass="tipButtonDiv"><\/div>\n
|
59
98
|
<div\sid="tipButtonPopup"\sclass="tipButtonPopup"><\/div>\n
|
60
99
|
<script>(.*)button_request(.*)<\/script>\n
|
61
100
|
/mx
|
62
101
|
|
63
|
-
actual = @xapo_tools.build_div_widget(config)
|
102
|
+
actual = @xapo_tools.build_div_widget(config, customization)
|
64
103
|
puts("test_build_div_widget -> ", actual)
|
65
104
|
|
66
105
|
assert_match(regex, actual)
|
@@ -75,6 +114,37 @@ class TestXapoTools < Minitest::Test
|
|
75
114
|
config[:pay_object_id] = "to0210"
|
76
115
|
config[:amount_BIT] = 0.01
|
77
116
|
config[:pay_type] = PayType::TIP
|
117
|
+
config[:reference_code] = "test"
|
118
|
+
|
119
|
+
customization = XapoTools.micro_payment_customization
|
120
|
+
customization[:predefined_pay_values] = "1,5,10"
|
121
|
+
customization[:end_mpayment_uri] = "http://localhost:9000"
|
122
|
+
customization[:redirect_uri] = "http://localhost:9000"
|
123
|
+
customization[:button_css] = "red"
|
124
|
+
|
125
|
+
regex = /
|
126
|
+
<div\sid="tipButtonDiv"\sclass="tipButtonDiv"><\/div>\n
|
127
|
+
<div\sid="tipButtonPopup"\sclass="tipButtonPopup"><\/div>\n
|
128
|
+
<script>(.*)payload(.*)<\/script>\n
|
129
|
+
/mx
|
130
|
+
|
131
|
+
actual = @xapo_tools_notpa.build_div_widget(config, customization)
|
132
|
+
puts("test_build_div_widget_notpa -> ", actual)
|
133
|
+
|
134
|
+
assert_match(regex, actual)
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_build_div_widget_cust()
|
138
|
+
config = XapoTools.micro_payment_config
|
139
|
+
config[:sender_user_email] = "sender@xapo.com"
|
140
|
+
config[:sender_user_cellphone] = "+5491112341234"
|
141
|
+
config[:receiver_user_id] = "r0210"
|
142
|
+
config[:receiver_user_email] = "fernando.taboada@xapo.com"
|
143
|
+
config[:pay_object_id] = "to0210"
|
144
|
+
config[:amount_BIT] = 0.01
|
145
|
+
config[:pay_type] = PayType::TIP
|
146
|
+
config[:reference_code] = "test"
|
147
|
+
|
78
148
|
regex = /
|
79
149
|
<div\sid="tipButtonDiv"\sclass="tipButtonDiv"><\/div>\n
|
80
150
|
<div\sid="tipButtonPopup"\sclass="tipButtonPopup"><\/div>\n
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xapo_sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Federico Repond
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|