stateless-systems-alertpay 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.txt +17 -0
- data/Rakefile +52 -0
- data/VERSION.yml +4 -0
- data/lib/alertpay.rb +2 -0
- data/lib/helpers.rb +51 -0
- data/lib/notification.rb +89 -0
- data/test/notification_test.rb +25 -0
- metadata +60 -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/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "alertpay"
|
8
|
+
gem.summary = %Q{Common interface to alertpay request params.}
|
9
|
+
gem.email = "enquiries@statelesssystems.com"
|
10
|
+
gem.homepage = "http://github.com/stateless-systems/alertpay"
|
11
|
+
gem.authors = ["Stateless Systems"]
|
12
|
+
end
|
13
|
+
rescue LoadError
|
14
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
15
|
+
end
|
16
|
+
|
17
|
+
require 'rake/testtask'
|
18
|
+
Rake::TestTask.new(:test) do |test|
|
19
|
+
test.libs << 'lib' << 'test'
|
20
|
+
test.pattern = 'test/**/*_test.rb'
|
21
|
+
test.verbose = true
|
22
|
+
end
|
23
|
+
|
24
|
+
begin
|
25
|
+
require 'rcov/rcovtask'
|
26
|
+
Rcov::RcovTask.new do |test|
|
27
|
+
test.libs << 'test'
|
28
|
+
test.pattern = 'test/**/*_test.rb'
|
29
|
+
test.verbose = true
|
30
|
+
end
|
31
|
+
rescue LoadError
|
32
|
+
task :rcov do
|
33
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
task :default => :test
|
38
|
+
|
39
|
+
require 'rake/rdoctask'
|
40
|
+
Rake::RDocTask.new do |rdoc|
|
41
|
+
if File.exist?('VERSION.yml')
|
42
|
+
config = YAML.load(File.read('VERSION.yml'))
|
43
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
44
|
+
else
|
45
|
+
version = ""
|
46
|
+
end
|
47
|
+
|
48
|
+
rdoc.rdoc_dir = 'rdoc'
|
49
|
+
rdoc.title = "alertpay #{version}"
|
50
|
+
rdoc.rdoc_files.include('README*')
|
51
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
52
|
+
end
|
data/VERSION.yml
ADDED
data/lib/alertpay.rb
ADDED
data/lib/helpers.rb
ADDED
@@ -0,0 +1,51 @@
|
|
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, currency, item_id, merchant, options = {})
|
12
|
+
params = {
|
13
|
+
:ap_amount => amount,
|
14
|
+
:ap_currency => (currency || :usd).to_s.upcase,
|
15
|
+
:ap_merchant => merchant,
|
16
|
+
:ap_itemcode => item_id,
|
17
|
+
:ap_quantity => 1
|
18
|
+
}
|
19
|
+
|
20
|
+
if options.include?(:subscription)
|
21
|
+
params[:ap_purchasetype] = :subscription
|
22
|
+
params[:ap_periodlength] = options[:subscription][:length]
|
23
|
+
params[:ap_timeunit] = case options[:subscription][:period]
|
24
|
+
when :monthly; 'Month'
|
25
|
+
when :yearly; 'Year'
|
26
|
+
when :weekly; 'Week'
|
27
|
+
when :daily; 'Day'
|
28
|
+
end
|
29
|
+
else
|
30
|
+
params[:ap_purchasetype] = :item
|
31
|
+
end
|
32
|
+
|
33
|
+
if options.include?(:custom)
|
34
|
+
options[:custom].each_index {|i| params["apc_#{i.to_i + 1}"] = options[:custom][i] }
|
35
|
+
end
|
36
|
+
|
37
|
+
params[:ap_quantity] = options[:quanity] if options.include?(:quanity)
|
38
|
+
params[:ap_itemname] = options[:item_name] if options.include?(:item_name)
|
39
|
+
params[:purchase_type] = options[:purchase_type] if options.include?(:purchase_type)
|
40
|
+
params[:ap_notifyurl] = options[:notify_url] if options.include?(:notify_url)
|
41
|
+
params[:ap_returnurl] = options[:return_url] if options.include?(:return_url)
|
42
|
+
params[:ap_cancelurl] = options[:cancel_url] if options.include?(:cancel_url)
|
43
|
+
|
44
|
+
returning button = [] do
|
45
|
+
params.each do |k, v|
|
46
|
+
button << tag(:input, :type => :hidden, :name => k.to_s, :value => v.to_s) unless v.nil?
|
47
|
+
end
|
48
|
+
end.join("\n")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/notification.rb
ADDED
@@ -0,0 +1,89 @@
|
|
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
|
+
# Was this a subscription payment?
|
36
|
+
def is_subscription_payment?
|
37
|
+
status == 'Subscription-Payment-Success'
|
38
|
+
end
|
39
|
+
|
40
|
+
# The shipping charges for this transaction.
|
41
|
+
def shipping
|
42
|
+
params['ap_shippingcharges'].to_f
|
43
|
+
end
|
44
|
+
|
45
|
+
# Amount of item purchased.
|
46
|
+
def amount
|
47
|
+
params['ap_amount'].to_f
|
48
|
+
end
|
49
|
+
|
50
|
+
# Currency that the payment was made in.
|
51
|
+
def currency
|
52
|
+
params['ap_currency']
|
53
|
+
end
|
54
|
+
|
55
|
+
# Status of the payment. E.g. 'Succes'
|
56
|
+
def status
|
57
|
+
params['ap_status']
|
58
|
+
end
|
59
|
+
|
60
|
+
# The reference number or transaction ID you can use to refer to this
|
61
|
+
# transaction.
|
62
|
+
def reference_number
|
63
|
+
params['ap_referencenumber']
|
64
|
+
end
|
65
|
+
|
66
|
+
# The email address associated with the merchant that recieved the monies.
|
67
|
+
def merchant
|
68
|
+
params['ap_merchant']
|
69
|
+
end
|
70
|
+
|
71
|
+
# The item code on the alertpay side
|
72
|
+
def item_code
|
73
|
+
params['ap_itemcode']
|
74
|
+
end
|
75
|
+
|
76
|
+
# An array containing the 6 custom elements
|
77
|
+
def custom
|
78
|
+
params.values_at('apc_1', 'apc_2', 'apc_3', 'apc_4', 'apc_5', 'apc_6')
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
def parse(post)
|
83
|
+
@raw = post
|
84
|
+
CGI.parse(post).each_pair do |k,v|
|
85
|
+
params[k] = v.to_s
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
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,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: stateless-systems-alertpay
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Stateless Systems
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-09-04 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: enquiries@statelesssystems.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.txt
|
24
|
+
files:
|
25
|
+
- README.txt
|
26
|
+
- Rakefile
|
27
|
+
- VERSION.yml
|
28
|
+
- lib/alertpay.rb
|
29
|
+
- lib/helpers.rb
|
30
|
+
- lib/notification.rb
|
31
|
+
- test/notification_test.rb
|
32
|
+
has_rdoc: false
|
33
|
+
homepage: http://github.com/stateless-systems/alertpay
|
34
|
+
licenses:
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options:
|
37
|
+
- --charset=UTF-8
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: "0"
|
45
|
+
version:
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: "0"
|
51
|
+
version:
|
52
|
+
requirements: []
|
53
|
+
|
54
|
+
rubyforge_project:
|
55
|
+
rubygems_version: 1.3.5
|
56
|
+
signing_key:
|
57
|
+
specification_version: 3
|
58
|
+
summary: Common interface to alertpay request params.
|
59
|
+
test_files:
|
60
|
+
- test/notification_test.rb
|