alertpay 0.1
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.
- data/README.txt +17 -0
- data/lib/alertpay.rb +2 -0
- data/lib/helpers.rb +50 -0
- data/lib/notification.rb +84 -0
- data/test/notification_test.rb +25 -0
- metadata +50 -0
data/README.txt
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= alertpay
|
2
|
+
|
3
|
+
This library simply converts a HTTP/S request into an object.
|
4
|
+
|
5
|
+
== Resources
|
6
|
+
|
7
|
+
Install
|
8
|
+
|
9
|
+
* gem install alertpay
|
10
|
+
|
11
|
+
Rubyforge project
|
12
|
+
|
13
|
+
* http://rubyforge.org/projects/alertpay
|
14
|
+
|
15
|
+
RDocs
|
16
|
+
|
17
|
+
* http://alertpay.rubyforge.org
|
data/lib/alertpay.rb
ADDED
data/lib/helpers.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
module Alertpay
|
2
|
+
module Helpers
|
3
|
+
def alertpay_form_tag(url = 'https://www.alertpay.com/PayProcess.aspx', options = {}, &block)
|
4
|
+
if block_given?
|
5
|
+
form_tag(url, options, &block)
|
6
|
+
else
|
7
|
+
form_tag(url, options)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def alertpay_setup(amount, item_id, merchant, options = {})
|
12
|
+
params = {
|
13
|
+
:ap_amount => amount,
|
14
|
+
:ap_merchant => merchant,
|
15
|
+
:ap_itemcode => item_id,
|
16
|
+
:ap_quantity => 1
|
17
|
+
}
|
18
|
+
|
19
|
+
if options.include?(:subscription)
|
20
|
+
params[:ap_purchasetype] = :subscription
|
21
|
+
params[:ap_periodlength] = options[:subscription][:length]
|
22
|
+
params[:ap_timeunit] = case options[:subscription][:period]
|
23
|
+
when :monthly; 'Month'
|
24
|
+
when :yearly; 'Year'
|
25
|
+
when :weekly; 'Week'
|
26
|
+
when :daily; 'Day'
|
27
|
+
end
|
28
|
+
else
|
29
|
+
params[:ap_purchasetype] = :item
|
30
|
+
end
|
31
|
+
|
32
|
+
if options.include?(:custom)
|
33
|
+
options[:custom].each_index {|i| params["apc_#{i.to_i + 1}"] = options[:custom][i] }
|
34
|
+
end
|
35
|
+
|
36
|
+
params[:ap_quantity] = options[:quanity] if options.include?(:quanity)
|
37
|
+
params[:ap_itemname] = options[:item_name] if options.include?(:item_name)
|
38
|
+
params[:purchase_type] = options[:purchase_type] if options.include?(:purchase_type)
|
39
|
+
params[:ap_notifyurl] = options[:notify_url] if options.include?(:notify_url)
|
40
|
+
params[:ap_returnurl] = options[:return_url] if options.include?(:return_url)
|
41
|
+
params[:ap_cancelurl] = options[:cancel_url] if options.include?(:cancel_url)
|
42
|
+
|
43
|
+
returning button = [] do
|
44
|
+
params.each do |k, v|
|
45
|
+
button << tag(:input, :type => :hidden, :name => k.to_s, :value => v.to_s) unless v.nil?
|
46
|
+
end
|
47
|
+
end.join("\n")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/notification.rb
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
|
3
|
+
module Alertpay
|
4
|
+
class Notification
|
5
|
+
attr_accessor :params
|
6
|
+
attr_accessor :raw
|
7
|
+
|
8
|
+
def initialize(post)
|
9
|
+
@params = {}
|
10
|
+
parse(post)
|
11
|
+
end
|
12
|
+
|
13
|
+
# The type of purchase. E.g. 'item' or 'subscription'.
|
14
|
+
def purchase_type
|
15
|
+
params['ap_purchasetype']
|
16
|
+
end
|
17
|
+
|
18
|
+
# Security code sent through from alertpay. You are to compare this with a
|
19
|
+
# hard coded value that you get from your alertpay profile, which only you
|
20
|
+
# should know.
|
21
|
+
def security_code
|
22
|
+
params['ap_securitycode']
|
23
|
+
end
|
24
|
+
|
25
|
+
# Name of the item that was purchased.
|
26
|
+
def item_name
|
27
|
+
params['ap_itemname']
|
28
|
+
end
|
29
|
+
|
30
|
+
# Was the payment successful?
|
31
|
+
def successful?
|
32
|
+
status == 'Success'
|
33
|
+
end
|
34
|
+
|
35
|
+
# The shipping charges for this transaction.
|
36
|
+
def shipping
|
37
|
+
params['ap_shippingcharges'].to_f
|
38
|
+
end
|
39
|
+
|
40
|
+
# Amount of item purchased.
|
41
|
+
def amount
|
42
|
+
params['ap_amount'].to_f
|
43
|
+
end
|
44
|
+
|
45
|
+
# Currency that the payment was made in.
|
46
|
+
def currency
|
47
|
+
params['ap_currency']
|
48
|
+
end
|
49
|
+
|
50
|
+
# Status of the payment. E.g. 'Succes'
|
51
|
+
def status
|
52
|
+
params['ap_status']
|
53
|
+
end
|
54
|
+
|
55
|
+
# The reference number or transaction ID you can use to refer to this
|
56
|
+
# transaction.
|
57
|
+
def reference_number
|
58
|
+
params['ap_referencenumber']
|
59
|
+
end
|
60
|
+
|
61
|
+
# The email address associated with the merchant that recieved the monies.
|
62
|
+
def merchant
|
63
|
+
params['ap_merchant']
|
64
|
+
end
|
65
|
+
|
66
|
+
# The item code on the alertpay side
|
67
|
+
def item_code
|
68
|
+
params['ap_itemcode']
|
69
|
+
end
|
70
|
+
|
71
|
+
# An array containing the 6 custom elements
|
72
|
+
def custom
|
73
|
+
params.values_at('apc_1', 'apc_2', 'apc_3', 'apc_4', 'apc_5', 'apc_6')
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
def parse(post)
|
78
|
+
@raw = post
|
79
|
+
CGI.parse(post).each_pair do |k,v|
|
80
|
+
params[k] = v.to_s
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'alertpay'
|
5
|
+
|
6
|
+
class NotificationTest < Test::Unit::TestCase
|
7
|
+
def test_parse
|
8
|
+
alertpay = Alertpay::Notification.new raw_post
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_successful
|
12
|
+
alertpay = Alertpay::Notification.new raw_post
|
13
|
+
assert alertpay.successful?
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_custom
|
17
|
+
alertpay = Alertpay::Notification.new raw_post
|
18
|
+
assert_equal 'Danial Pearce', alertpay.custom[2]
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
def raw_post
|
23
|
+
'ap_merchant=alertpay@tigris.id.au&ap_securitycode=NOT_SECURE&ap_custfirstname=Danial&ap_custlastname=Pearce&ap_custaddress=1 There St&ap_custcity=Melbourne&ap_custstate=VIC&ap_custcountry=AUS&ap_custzip=3000&ap_custemailaddress=alertpay@tigris.id.au&ap_purchasetype=subscription&ap_referencenumber=TEST TRANSACTION&ap_itemname=Jigglets&ap_description=&ap_itemcode=&ap_quantity=1&ap_amount=28&ap_shippingcharges=0&ap_additionalcharges=0&ap_taxamount=0&ap_discountamount=0&ap_totalamount=28&ap_currency=USD&ap_subscriptionreferencenumber=REFERENCE&ap_timeunit=Month&ap_periodlength=1&ap_periodcount=-1&ap_nextrundate=&apc_1=1&apc_2=alertpay@tigris.id.au&apc_3=Danial Pearce&apc_4=&apc_5=&apc_6=&ap_test=1&ap_status=Success'
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.4
|
3
|
+
specification_version: 1
|
4
|
+
name: alertpay
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: "0.1"
|
7
|
+
date: 2008-05-08 00:00:00 +10:00
|
8
|
+
summary: Common interface to alertpay request params.
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: danial@statelesssystems.com
|
12
|
+
homepage: http://statelesssystems.com
|
13
|
+
rubyforge_project:
|
14
|
+
description: Common interface to alertpay request params.
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Danial Pearce
|
31
|
+
files:
|
32
|
+
- lib/alertpay.rb
|
33
|
+
- lib/helpers.rb
|
34
|
+
- lib/notification.rb
|
35
|
+
- test/notification_test.rb
|
36
|
+
- README.txt
|
37
|
+
test_files:
|
38
|
+
- test/notification_test.rb
|
39
|
+
rdoc_options: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- README.txt
|
43
|
+
executables: []
|
44
|
+
|
45
|
+
extensions: []
|
46
|
+
|
47
|
+
requirements: []
|
48
|
+
|
49
|
+
dependencies: []
|
50
|
+
|