worldpay_iadmin 1.0.0
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/CHANGELOG +3 -0
- data/MIT-LICENSE +22 -0
- data/README +69 -0
- data/lib/worldpay_iadmin.rb +152 -0
- data/test/worldpay_iadmin_test.rb +57 -0
- metadata +59 -0
data/CHANGELOG
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2010 Steven Cummings
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
data/README
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
== WorldPay iadmin Library
|
2
|
+
|
3
|
+
WorldPay offer an api to do some remote administration tasks relating to FuturePay. The iadmin
|
4
|
+
api is not available by default. You must contact WorldPay and ask them to activate it for you. A
|
5
|
+
new installation id and password will be provided access the api. The api allows you to cancel a
|
6
|
+
FuturePay agreement, change the start date, debit an agreement, or modify the amount. See the WorldPay
|
7
|
+
docs for a list of error responses you can expect.
|
8
|
+
|
9
|
+
WorldPay Docs: http://www.rbsworldpay.com/support/kb/bg/recurringpayments/rpfp8000.html
|
10
|
+
|
11
|
+
== Requirements
|
12
|
+
|
13
|
+
* Ruby 1.8.6 with openssl (Should work with previous versions. I've just not tested it)
|
14
|
+
* Valid WorldPay account
|
15
|
+
* Fakeweb gem for running tests
|
16
|
+
|
17
|
+
== Example Usage:
|
18
|
+
|
19
|
+
# Create a new WorldpayIadmin instance
|
20
|
+
@installation_id = "12345"
|
21
|
+
@password = "mypass"
|
22
|
+
@iadmin = WorldpayIadmin.new(@installation_id, @password)
|
23
|
+
|
24
|
+
@futurepay_id = "98765"
|
25
|
+
|
26
|
+
# Cancel a FuturePay agreement
|
27
|
+
if @iadmin.cancel_agreement(@futurepay_id)
|
28
|
+
puts "Agreement Cancelled"
|
29
|
+
else
|
30
|
+
puts "Agreement Cancellation Failed\n"
|
31
|
+
puts @iadmin.response
|
32
|
+
end
|
33
|
+
|
34
|
+
# Modify a start date
|
35
|
+
if @iadmin.modify_start_date(@futurepay_id, Time.now)
|
36
|
+
puts "Start Date Changed"
|
37
|
+
else
|
38
|
+
puts "Start Date Change Failed\n"
|
39
|
+
puts @iadmin.response
|
40
|
+
end
|
41
|
+
|
42
|
+
# Debit an agreement
|
43
|
+
if @iadmin.debit(@futurepay_id, 9.99)
|
44
|
+
puts "Debit Successful"
|
45
|
+
else
|
46
|
+
puts "Debit Failed\n"
|
47
|
+
puts @iadmin.response
|
48
|
+
end
|
49
|
+
|
50
|
+
# Change an amount
|
51
|
+
if @iadmin.change_amount(@futurepay_id, 9.99)
|
52
|
+
puts "Change Amount Successful"
|
53
|
+
else
|
54
|
+
puts "DChange Amount Failed\n"
|
55
|
+
puts @iadmin.response
|
56
|
+
end
|
57
|
+
|
58
|
+
== Test Mode:
|
59
|
+
|
60
|
+
@test_mode = true
|
61
|
+
@iadmin = WorldpayIadmin.new(@installation_id, @password, @test_mode)
|
62
|
+
|
63
|
+
or
|
64
|
+
|
65
|
+
@iadmin = WorldpayIadmin.new(@installation_id, @password)
|
66
|
+
@iadmin.test_mode = true
|
67
|
+
|
68
|
+
|
69
|
+
|
@@ -0,0 +1,152 @@
|
|
1
|
+
# = WorldPay iadmin Library
|
2
|
+
#
|
3
|
+
# WorldPay offer an api to do some remote administration tasks relating to FuturePay. The iadmin
|
4
|
+
# api is not available by default. You must contact WorldPay and ask them to activate it for you. A
|
5
|
+
# new installation id and password will be provided access the api. The api allows you to cancel a
|
6
|
+
# FuturePay agreement, change the start date, debit an agreement, or change the amount. See the WorldPay
|
7
|
+
# docs for a list of error responses you can expect.
|
8
|
+
#
|
9
|
+
# WorldPay API Docs: http://www.rbsworldpay.com/support/kb/bg/recurringpayments/rpfp8000.html
|
10
|
+
#
|
11
|
+
# == Requirements
|
12
|
+
#
|
13
|
+
# * Ruby 1.8.2 with openssl (Should work with previous versions. I've just not tested it)
|
14
|
+
# * Valid WorldPay account.
|
15
|
+
# * Fakeweb gem for running tests
|
16
|
+
#
|
17
|
+
# = Example Usage:
|
18
|
+
#
|
19
|
+
# # Create a new WorldpayIadmin instance
|
20
|
+
# @installation_id = "12345"
|
21
|
+
# @password = "mypass"
|
22
|
+
# @iadmin = WorldpayIadmin.new(@installation_id, @password)
|
23
|
+
#
|
24
|
+
# @futurepay_id = "98765"
|
25
|
+
#
|
26
|
+
# # Cancel a FuturePay agreement
|
27
|
+
# if @iadmin.cancel_agreement(@futurepay_id)
|
28
|
+
# puts "Agreement Cancelled"
|
29
|
+
# else
|
30
|
+
# puts "Agreement Cancellation Failed\n"
|
31
|
+
# puts @iadmin.response
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# # Modify a start date
|
35
|
+
# if @iadmin.modify_start_date(@futurepay_id, Time.now)
|
36
|
+
# puts "Start Date Changed"
|
37
|
+
# else
|
38
|
+
# puts "Start Date Change Failed\n"
|
39
|
+
# puts @iadmin.response
|
40
|
+
# end
|
41
|
+
#
|
42
|
+
# # Debit an agreement
|
43
|
+
# if @iadmin.debit(@futurepay_id, 9.99)
|
44
|
+
# puts "Debit Successful"
|
45
|
+
# else
|
46
|
+
# puts "Debit Failed\n"
|
47
|
+
# puts @iadmin.response
|
48
|
+
# end
|
49
|
+
#
|
50
|
+
# # Change an amount
|
51
|
+
# if @iadmin.change_amount(@futurepay_id, 9.99)
|
52
|
+
# puts "Change Amount Successful"
|
53
|
+
# else
|
54
|
+
# puts "DChange Amount Failed\n"
|
55
|
+
# puts @iadmin.response
|
56
|
+
# end
|
57
|
+
#
|
58
|
+
# = Test Mode:
|
59
|
+
#
|
60
|
+
# @test_mode = true
|
61
|
+
# @iadmin = WorldpayIadmin.new(@installation_id, @password, @test_mode)
|
62
|
+
#
|
63
|
+
# or
|
64
|
+
#
|
65
|
+
# @iadmin = WorldpayIadmin.new(@installation_id, @password)
|
66
|
+
# @iadmin.test_mode = true
|
67
|
+
|
68
|
+
class WorldpayIadmin
|
69
|
+
|
70
|
+
require 'net/http'
|
71
|
+
require 'net/https'
|
72
|
+
require 'uri'
|
73
|
+
|
74
|
+
# http://www.rbsworldpay.com/support/kb/bg/recurringpayments/rpfp8000.html
|
75
|
+
|
76
|
+
|
77
|
+
attr_accessor :worldpay_id, :password, :test_mode, :production_url, :test_url
|
78
|
+
|
79
|
+
def initialize(worldpay_id, password, test_mode=false)
|
80
|
+
@worldpay_id = worldpay_id
|
81
|
+
@password = password
|
82
|
+
@test_mode = test_mode
|
83
|
+
@production_url = "https://secure-test.wp3.rbsworldpay.com/wcc/iadmin"
|
84
|
+
@test_url = "https://secure.wp3.rbsworldpay.com/wcc/iadmin"
|
85
|
+
end
|
86
|
+
|
87
|
+
# Returns the url that the command will be sent to
|
88
|
+
def iadmin_url
|
89
|
+
@test_mode ? @test_url : @production_url
|
90
|
+
end
|
91
|
+
|
92
|
+
# Cancels an existing FuturePay agreement
|
93
|
+
def cancel_agreement(futurepay_id)
|
94
|
+
run_command({:futurePayId => futurepay_id, "op-cancelFP" => "" })
|
95
|
+
end
|
96
|
+
|
97
|
+
# Change or specify a FuturePay agreement's start date
|
98
|
+
def modify_start_date(futurepay_id, start_date)
|
99
|
+
run_command({:futurePayId => futurepay_id, :startDate => start_date.strftime("%Y-%m-%d"), "op-startDateRFP" => "" })
|
100
|
+
end
|
101
|
+
|
102
|
+
# Change the amount/price of subsequent debits for option 1 or 2 agreements, providing that there is at least
|
103
|
+
# 8 days before 00:00 GMT on the day the payment is due.
|
104
|
+
def change_amount(futurepay_id, amount)
|
105
|
+
run_command({:futurePayId => futurepay_id, :amount => amount, "op-adjustRFP" => "" })
|
106
|
+
end
|
107
|
+
|
108
|
+
# Debit from an agreement
|
109
|
+
def debit(futurepay_id, amount)
|
110
|
+
run_command({:futurePayId => futurepay_id, :amount => amount, "op-paymentLFP" => "" })
|
111
|
+
end
|
112
|
+
|
113
|
+
# Returns the raw response string received from WorldPay
|
114
|
+
def response
|
115
|
+
@response
|
116
|
+
end
|
117
|
+
|
118
|
+
protected
|
119
|
+
|
120
|
+
# Returns <code>true</code> if the passed response string indicated the action was sucessful
|
121
|
+
def check_response(response)
|
122
|
+
response =~ /^Y,/ ? true : false
|
123
|
+
end
|
124
|
+
|
125
|
+
# Returns <code>true</code> if able to connect to WorldPay the action was carried out
|
126
|
+
def run_command(command_params)
|
127
|
+
params = {:instId => @worldpay_id, :authPW => @password}
|
128
|
+
params.merge!(command_params)
|
129
|
+
params.merge!({ :testMode => "100" }) if @test_mode
|
130
|
+
|
131
|
+
url = URI.parse(iadmin_url)
|
132
|
+
|
133
|
+
req = Net::HTTP::Post.new(url.path)
|
134
|
+
req.set_form_data(params)
|
135
|
+
|
136
|
+
http = Net::HTTP.new(url.host, url.port)
|
137
|
+
http.use_ssl = true
|
138
|
+
|
139
|
+
response = http.request(req)
|
140
|
+
|
141
|
+
case response
|
142
|
+
when Net::HTTPSuccess, Net::HTTPRedirection
|
143
|
+
@response = response.body.strip
|
144
|
+
return check_response(@response)
|
145
|
+
else
|
146
|
+
@response = "Connection Error"
|
147
|
+
return false
|
148
|
+
end
|
149
|
+
|
150
|
+
end
|
151
|
+
|
152
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
2
|
+
require 'test/unit'
|
3
|
+
require 'worldpay_iadmin'
|
4
|
+
require 'net/http'
|
5
|
+
require 'net/https'
|
6
|
+
require 'uri'
|
7
|
+
require 'fakeweb'
|
8
|
+
|
9
|
+
class WorldpayIadminTest < Test::Unit::TestCase
|
10
|
+
|
11
|
+
def create_worldpay_iadmin(response)
|
12
|
+
@worldpay_iadmin = WorldpayIadmin.new("123434", "password")
|
13
|
+
FakeWeb.register_uri(:any, @worldpay_iadmin.iadmin_url, :body => response)
|
14
|
+
@worldpay_iadmin
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_initialize
|
18
|
+
@worldpay_iadmin = WorldpayIadmin.new("123434", "password", true)
|
19
|
+
|
20
|
+
assert_equal "123434", @worldpay_iadmin.worldpay_id
|
21
|
+
assert_equal "password", @worldpay_iadmin.password
|
22
|
+
assert_equal true, @worldpay_iadmin.test_mode
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_cancel_agreement
|
26
|
+
assert create_worldpay_iadmin("Y,Start date set OK").cancel_agreement("232323")
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_cancel_agreement_fail
|
30
|
+
assert !create_worldpay_iadmin("E,Problem cancelling agreement").cancel_agreement("232323")
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_modify_start_date
|
34
|
+
assert create_worldpay_iadmin("Y,Start date set OK").modify_start_date("232323", Time.now)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_modify_start_date_fail
|
38
|
+
assert !create_worldpay_iadmin("E,Agreement already has start date").modify_start_date("232323", Time.now)
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_change_amount
|
42
|
+
assert create_worldpay_iadmin("Y,Amount updated").change_amount("232323", 9.99)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_change_amount_fail
|
46
|
+
assert !create_worldpay_iadmin("E,Amount is fixed").change_amount("232323", 9.99)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_debit
|
50
|
+
assert create_worldpay_iadmin("Y,transId,A,rawAuthMessage,Payment successful").debit("232323", 9.99)
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_debit
|
54
|
+
assert !create_worldpay_iadmin("E,Agreement already finished").debit("232323", 9.99)
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: worldpay_iadmin
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Steven Cummings
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-01-15 00:00:00 +00:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: WorldPay iadmin provides a ruby interface to WorldPays remote administration interface.
|
17
|
+
email: steven@actiontab.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- README
|
26
|
+
- CHANGELOG
|
27
|
+
- MIT-LICENSE
|
28
|
+
- lib/worldpay_iadmin.rb
|
29
|
+
- test/worldpay_iadmin_test.rb
|
30
|
+
has_rdoc: true
|
31
|
+
homepage: http://stevencummings.name/
|
32
|
+
licenses: []
|
33
|
+
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options: []
|
36
|
+
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: "0"
|
50
|
+
version:
|
51
|
+
requirements: []
|
52
|
+
|
53
|
+
rubyforge_project:
|
54
|
+
rubygems_version: 1.3.5
|
55
|
+
signing_key:
|
56
|
+
specification_version: 3
|
57
|
+
summary: WorldPay Iadmin provides a ruby interface to WorldPays remote administration interface.
|
58
|
+
test_files: []
|
59
|
+
|