Class: WorldpayIadmin

Inherits:
Object
  • Object
show all
Defined in:
lib/worldpay_iadmin.rb

Overview

WorldPay iadmin Library

WorldPay offer an api to do some remote administration tasks relating to FuturePay. The iadmin
api is not available by default. You must contact WorldPay and ask them to activate it for you. A
new installation id and password will be provided access the api. The api allows you to cancel a
FuturePay agreement, change the start date, debit an agreement, or change the amount. See the WorldPay
docs for a list of error responses you can expect.

WorldPay API Docs: http://www.rbsworldpay.com/support/kb/bg/recurringpayments/rpfp8000.html

Requirements

  • Ruby 1.8.2 with openssl (Should work with previous versions. I’ve just not tested it)

  • Valid WorldPay account.

  • Fakeweb gem for running tests

Example Usage:

# Create a new WorldpayIadmin instance
@installation_id = "12345"
@password = "mypass"
@iadmin = WorldpayIadmin.new(@installation_id, @password)

@futurepay_id = "98765"  

# Cancel a FuturePay agreement
if @iadmin.cancel_agreement(@futurepay_id)
  puts "Agreement Cancelled"
else
  puts "Agreement Cancellation Failed\n"
  puts @iadmin.response
end

# Modify a start date
if @iadmin.modify_start_date(@futurepay_id, Time.now)
  puts "Start Date Changed"
else
  puts "Start Date Change Failed\n"
  puts @iadmin.response
end

# Debit an agreement
if @iadmin.debit(@futurepay_id, 9.99)
  puts "Debit Successful"
else
  puts "Debit Failed\n"
  puts @iadmin.response
end

# Change an amount
if @iadmin.change_amount(@futurepay_id, 9.99)
  puts "Change Amount Successful"
else
  puts "DChange Amount Failed\n"
  puts @iadmin.response
end

Test Mode:

@test_mode = true 
@iadmin = WorldpayIadmin.new(@installation_id, @password, @test_mode)

or 

@iadmin = WorldpayIadmin.new(@installation_id, @password)
@iadmin.test_mode = true

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(worldpay_id, password, test_mode = false) ⇒ WorldpayIadmin

Returns a new instance of WorldpayIadmin.



76
77
78
79
80
81
82
# File 'lib/worldpay_iadmin.rb', line 76

def initialize(worldpay_id, password, test_mode=false)
  @worldpay_id = worldpay_id
  @password = password
  @test_mode = test_mode
  @production_url = "https://secure.wp3.rbsworldpay.com/wcc/iadmin"
  @test_url = "https://secure-test.wp3.rbsworldpay.com/wcc/iadmin"
end

Instance Attribute Details

#passwordObject

Returns the value of attribute password.



74
75
76
# File 'lib/worldpay_iadmin.rb', line 74

def password
  @password
end

#production_urlObject

Returns the value of attribute production_url.



74
75
76
# File 'lib/worldpay_iadmin.rb', line 74

def production_url
  @production_url
end

#test_modeObject

Returns the value of attribute test_mode.



74
75
76
# File 'lib/worldpay_iadmin.rb', line 74

def test_mode
  @test_mode
end

#test_urlObject

Returns the value of attribute test_url.



74
75
76
# File 'lib/worldpay_iadmin.rb', line 74

def test_url
  @test_url
end

#worldpay_idObject

Returns the value of attribute worldpay_id.



74
75
76
# File 'lib/worldpay_iadmin.rb', line 74

def worldpay_id
  @worldpay_id
end

Instance Method Details

#cancel_agreement(futurepay_id) ⇒ Object

Cancels an existing FuturePay agreement



90
91
92
# File 'lib/worldpay_iadmin.rb', line 90

def cancel_agreement(futurepay_id)
  run_command({:futurePayId => futurepay_id, "op-cancelFP" => "" })
end

#change_amount(futurepay_id, amount) ⇒ Object

Change the amount/price of subsequent debits for option 1 or 2 agreements, providing that there is at least 8 days before 00:00 GMT on the day the payment is due.



101
102
103
# File 'lib/worldpay_iadmin.rb', line 101

def change_amount(futurepay_id, amount)
  run_command({:futurePayId => futurepay_id, :amount => amount, "op-adjustRFP" => "" })
end

#debit(futurepay_id, amount) ⇒ Object

Debit from an agreement



106
107
108
# File 'lib/worldpay_iadmin.rb', line 106

def debit(futurepay_id, amount)
  run_command({:futurePayId => futurepay_id, :amount => amount, "op-paymentLFP" => "" })
end

#iadmin_urlObject

Returns the url that the command will be sent to



85
86
87
# File 'lib/worldpay_iadmin.rb', line 85

def iadmin_url
  @test_mode ? @test_url : @production_url
end

#modify_start_date(futurepay_id, start_date) ⇒ Object

Change or specify a FuturePay agreement’s start date



95
96
97
# File 'lib/worldpay_iadmin.rb', line 95

def modify_start_date(futurepay_id, start_date)
  run_command({:futurePayId => futurepay_id, :startDate => start_date.strftime("%Y-%m-%d"), "op-startDateRFP" => "" })
end

#responseObject

Returns the raw response string received from WorldPay



111
112
113
# File 'lib/worldpay_iadmin.rb', line 111

def response
  @response
end