presto_api 0.0.4 → 0.0.5
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/lib/presto_api/version.rb +1 -1
- data/lib/presto_api.rb +93 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31fe1a9517eb0077ce1eaa5a96dd7c98ccdb50eb
|
4
|
+
data.tar.gz: 68bd2862a4d157fc638eb7aeab60dd8bf0219d31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aed6204106e66a72529e8e00006cf7949eeec924152c0eb82982bbd454048c1d9914a4b6e86b730a62d229df21597d27b49e3a5593eb0df2bebb191fae8e37c3
|
7
|
+
data.tar.gz: 9362ada4ff9cfd99f4414445025789436a0fb6b66e0efaeffcc1680180f0333e6e50c36ea6f7e24191ec800ff390ee7f6cbe1ac86484f11612fff91af66de748
|
data/lib/presto_api/version.rb
CHANGED
data/lib/presto_api.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'mechanize'
|
3
|
+
require 'open-uri'
|
4
|
+
require 'json'
|
5
|
+
require 'base64'
|
3
6
|
|
4
7
|
module PrestoAPI
|
5
8
|
class Base
|
@@ -53,6 +56,13 @@ module PrestoAPI
|
|
53
56
|
:loyalty_discount
|
54
57
|
end
|
55
58
|
|
59
|
+
class CreditCard
|
60
|
+
attr_accessor :name,
|
61
|
+
:number,
|
62
|
+
:expiry_month,
|
63
|
+
:expiry_year
|
64
|
+
end
|
65
|
+
|
56
66
|
class Client
|
57
67
|
def user_with_username_password(username, password)
|
58
68
|
card_number = card_number_from_page(login_with_username_password(username, password))
|
@@ -74,6 +84,16 @@ module PrestoAPI
|
|
74
84
|
card_status_from_page(login_with_card_number(card_number))
|
75
85
|
end
|
76
86
|
|
87
|
+
def load_registered_card(username, password, email, amount, credit_card)
|
88
|
+
login_with_username_password(username, password)
|
89
|
+
load_card(amount, email, credit_card)
|
90
|
+
end
|
91
|
+
|
92
|
+
def load_unregistered_card(card_number, email, amount, credit_card)
|
93
|
+
login_with_card_number(card_number)
|
94
|
+
load_card(amount, email, credit_card)
|
95
|
+
end
|
96
|
+
|
77
97
|
private
|
78
98
|
|
79
99
|
def login_with_username_password(username, password)
|
@@ -181,6 +201,79 @@ module PrestoAPI
|
|
181
201
|
transaction_history
|
182
202
|
end
|
183
203
|
|
204
|
+
def load_card(amount, email, credit_card)
|
205
|
+
# Check that we want to load a dollar value onto the card
|
206
|
+
page = agent.get('https://www.prestocard.ca/en-US/Pages/TransactionalPages/ReloadEpurse.aspx')
|
207
|
+
form = page.forms.first
|
208
|
+
radio_button = form.radiobutton_with(:id => 'ctl00_SPWebPartManager1_LoadePurseWebPartWebpartControl_ctl00_wizardLoadEPurse_webpartPeriodPassWebPart_ctl00_wizardPeriodPassSelection_radioButtonListProducts_0')
|
209
|
+
radio_button.check
|
210
|
+
button = form.button_with(:name => "ctl00$SPWebPartManager1$LoadePurseWebPartWebpartControl$ctl00$wizardLoadEPurse$webpartPeriodPassWebPart$ctl00$wizardPeriodPassSelection$buttonNextinProductSelection")
|
211
|
+
page = agent.submit(form, button)
|
212
|
+
|
213
|
+
# Enter the amount to add to the card and our email address
|
214
|
+
form = page.forms.first
|
215
|
+
amount_field = form.field_with(:id => "ctl00_SPWebPartManager1_LoadePurseWebPartWebpartControl_ctl00_wizardLoadEPurse_textBoxamountToReload")
|
216
|
+
amount_field.value = amount
|
217
|
+
email_field = form.field_with(:id => "ctl00_SPWebPartManager1_LoadePurseWebPartWebpartControl_ctl00_wizardLoadEPurse_textBoxemailAddress")
|
218
|
+
email_field.value = email
|
219
|
+
button = form.button_with(:name => "ctl00$SPWebPartManager1$LoadePurseWebPartWebpartControl$ctl00$wizardLoadEPurse$buttonConfirmReload")
|
220
|
+
page = agent.submit(form, button)
|
221
|
+
|
222
|
+
# Confirm Amount
|
223
|
+
form = page.forms.first
|
224
|
+
button = form.button_with(:name => "ctl00$SPWebPartManager1$LoadePurseWebPartWebpartControl$ctl00$wizardLoadEPurse$buttonConfirmInVerification")
|
225
|
+
page = agent.submit(form, button)
|
226
|
+
|
227
|
+
# Intermediate Moneris Submit
|
228
|
+
storeId = page.body[/storeId = '[^\s]*'/,0][/'.*'/,0][1..-2]
|
229
|
+
hppKey = page.body[/hppKey = '[^\s]*'/,0][/'.*'/,0][1..-2]
|
230
|
+
totalCharge = page.body[/totalCharge = '[^\s]*'/,0][/'.*'/,0][1..-2]
|
231
|
+
orderId = page.body[/orderId = '[^\s]*'/,0][/'.*'/,0][1..-2]
|
232
|
+
language = page.body[/language = '[^\s]*'/,0][/'.*'/,0][1..-2]
|
233
|
+
|
234
|
+
form = page.forms.first
|
235
|
+
form.field_with(:id => "ps_store_id").value = storeId
|
236
|
+
form.field_with(:id => "hpp_key").value = hppKey
|
237
|
+
form.field_with(:id => "charge_total").value = totalCharge
|
238
|
+
form.field_with(:id => "order_id").value = orderId
|
239
|
+
form.field_with(:id => "lang").value = language
|
240
|
+
form.action = "https://www3.moneris.com/HPPDP/index.php"
|
241
|
+
page = form.submit
|
242
|
+
|
243
|
+
# Enter Payment Details
|
244
|
+
callCCPurchase = page.body[/function callCCPurchase\(\)[^}]*/,0]
|
245
|
+
|
246
|
+
hpp_id = callCCPurchase[/hpp_id=[^"]+/,0]
|
247
|
+
hpp_id["hpp_id="] = ""
|
248
|
+
hpp_ticket = callCCPurchase[/hpp_ticket=[^"]+/,0]
|
249
|
+
hpp_ticket["hpp_ticket="] = ""
|
250
|
+
pan = credit_card.number
|
251
|
+
pan_mm = credit_card.expiry_month
|
252
|
+
pan_yy = credit_card.expiry_year
|
253
|
+
cardholder = credit_card.name
|
254
|
+
|
255
|
+
post_data = "hpp_id=" + CGI::escape(hpp_id) +
|
256
|
+
"&hpp_ticket=" + CGI::escape(hpp_ticket) +
|
257
|
+
"&pan=" + CGI::escape(pan) +
|
258
|
+
"&pan_mm=" + CGI::escape(pan_mm) +
|
259
|
+
"&pan_yy=" + CGI::escape(pan_yy) +
|
260
|
+
"&cardholder=" + CGI::escape(cardholder) +
|
261
|
+
"&doTransaction=cc_purchase"
|
262
|
+
|
263
|
+
# Send Payment
|
264
|
+
headers = { 'Content-Type' => 'application/x-www-form-urlencoded', 'Connection' => 'close', 'Content-length' => post_data.length }
|
265
|
+
page = agent.post( 'https://www3.moneris.com/HPPDP/hprequest.php', post_data, headers)
|
266
|
+
|
267
|
+
# Confirm with Credit Card Provider
|
268
|
+
parsed = JSON.parse(page.body)
|
269
|
+
form_text_encoded = parsed['response']['data']['form']
|
270
|
+
form_text_decoded = Base64.decode64(form_text_encoded)
|
271
|
+
|
272
|
+
# Send the decoded HTML back to the client so the user can
|
273
|
+
# confirm with their credit card provider
|
274
|
+
form_text_decoded
|
275
|
+
end
|
276
|
+
|
184
277
|
def agent
|
185
278
|
@agent ||= Mechanize.new
|
186
279
|
end
|