Skip to content

Commit

Permalink
added all debit methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanmartin committed May 13, 2012
1 parent 45f2e26 commit 3cf11fc
Show file tree
Hide file tree
Showing 6 changed files with 246 additions and 14 deletions.
8 changes: 3 additions & 5 deletions Gemfile
@@ -1,10 +1,8 @@
source "http://rubygems.org"
# Add dependencies required to use your gem here.
# Example:
# gem "activesupport", ">= 2.3.5"

# Add dependencies to develop your gem here.
# Include everything needed to run rake, tests, features, etc.
gem 'addressable'
gem 'yajl-ruby'

group :development do
gem "shoulda", ">= 0"
gem "rdoc", "~> 3.12"
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
@@ -1,6 +1,7 @@
GEM
remote: http://rubygems.org/
specs:
addressable (2.2.8)
git (1.2.5)
jeweler (1.8.3)
bundler (~> 1.0)
Expand All @@ -17,13 +18,16 @@ GEM
shoulda-matchers (~> 1.0.0)
shoulda-context (1.0.0)
shoulda-matchers (1.0.0)
yajl-ruby (1.1.0)

PLATFORMS
ruby

DEPENDENCIES
addressable
bundler (~> 1.1.0)
jeweler (~> 1.8.3)
rcov
rdoc (~> 3.12)
shoulda
yajl-ruby
26 changes: 24 additions & 2 deletions lib/micropayment.rb
@@ -1,11 +1,33 @@
require "addressable/uri"
require "net/https"
require "cgi"

module Micropayment

BASE_URL = 'https://webservices.micropayment.de/public/'

autoload :Config, 'services/config'
autoload :API, 'services/api'
autoload :Debit, 'services/debit'

def self.setup
Micropayment::Config.setup
yield Micropayment::Config
Micropayment::Config.complete = true
Micropayment::Config
end

def self.assert_valid_keys(opts, *valid_keys)
valid_keys.flatten!
opts.each_key do |k|
raise(ArgumentError, "Unknown key: #{k}") unless valid_keys.include?(k)
end
end

def self.assert_keys_exists(opts, *keys)
keys.flatten!
opt_keys = opts.keys
keys.each do |k|
raise(ArgumentError, "Mandatory key missing: #{k}") unless opt_keys.include?(k)
end
end

end
17 changes: 13 additions & 4 deletions lib/services/api.rb
Expand Up @@ -2,10 +2,19 @@ module Micropayment

class API

def self.call(url, method, data)
puts "called: #{url}"
puts "method: #{method}"
puts "data: #{data.inspect}"
def self.ensure_config!
raise "Micropayment.setup has not been called yet. See github.com/GeneralScripting/micropayment" unless Config.complete
end

def self.call(url, method, data={})
ensure_config!
data[:action] = method
data[:accessKey] = Config.api_key
data[:testMode] ||= Config.sandbox||0 if Config.sandbox
data.delete_if {|k,v| v.nil? }
uri = Addressable::URI.parse(url)
uri.query_values = data
puts uri.inspect
end

end
Expand Down
12 changes: 11 additions & 1 deletion lib/services/config.rb
Expand Up @@ -2,7 +2,17 @@ module Micropayment

class Config


BASE_URL = 'https://webservices.micropayment.de/public/'

VALID_OPTION_KEYS = [ :complete, :api_key, :sandbox ]

class << self
attr_accessor *VALID_OPTION_KEYS
end

def self.setup
#Micropayment::Config.url = BASE_URL
end

end

Expand Down
193 changes: 191 additions & 2 deletions lib/services/debit.rb
Expand Up @@ -3,23 +3,212 @@
module Micropayment
class Debit

URL = BASE_URL + "debit/v1.4/nvp/"
URL = Config::BASE_URL + "debit/v1.4/nvp/"

class << self

def execute(method, data={})
API.call(URL, method, data)
end

# löscht alle Kunden und Transaktionen in der Testumgebung
def assert_valid_keys(*opts)
Micropayment.assert_valid_keys *opts
end

def assert_keys_exists(*opts)
Micropayment.assert_keys_exists *opts
end


# "löscht alle Kunden und Transaktionen in der Testumgebung"
def reset_test
execute(:resetTest, :testMode => 1)
end

# "legt neuen Kunden an"
def customerCreate
execute(:customerCreate)
end

# "ordnet weitere freie Parameter dem Kunden zu, oder ändert sie"
def customerSet(customer_id, free_params=nil)
execute(:customerSet, { :customerId => customer_id })
end

# "ermittelt alle freien Parameter des Kunden"
def customerGet(customer_id)
execute(:customerGet, :customerId => customer_id)
end

# "ermittelt alle Kunden"
def customerList(options={})
assert_valid_keys(options, :from, :count)
execute(:customerList, options)
end

# "erzeugt oder ändert Bankverbindung eines Kunden"
def bankaccountSet(options={})
assert_valid_keys(options, :customerId, :bankVode, :accountNumber, :accountHolder, :country)
assert_keys_exists(options, :customerId, :bankVode, :accountNumber, :accountHolder)
execute(:bankaccountSet, options)
end

# "ermittelt die Bankverbindung des Kunden"
def bankaccountGet(options={})
assert_valid_keys(options, :customerId)
assert_keys_exists(options, :customerId)
execute(:bankaccountGet, options)
end

# "prüft Bankleitzahl und ermittelt Banknamen"
def bankCheck(options={})
assert_valid_keys(options, :country, :bankCode)
assert_keys_exists(options, :bankCode)
execute(:bankCheck, options)
end

# "prüft Bankverbindung und ermittelt Banknamen"
def bankaccountCheck(options={})
assert_valid_keys(options, :country, :bankCode, :accountNumber)
assert_keys_exists(options, :bankCode, :accountNumber)
execute(:bankaccountCheck, options)
end

# "Sperrt Bankverbindung oder gibt sie frei"
def bankaccountBar(options={})
assert_valid_keys(options, :country, :bankCode, :accountNumber, :barStatus)
assert_keys_exists(options, :bankCode, :accountNumber, :barStatus)
execute(:bankaccountBar, options)
end

# "erzeugt oder ändert Adressdaten eines Kunden"
def addressSet(options={})
assert_valid_keys(options, :customerId, :firstName, :surName, :street, :zip, :city, :country)
assert_keys_exists(options, :customerId, :firstName, :surName, :street, :zip, :city)
execute(:addressSet, options)
end

# "ermittelt die Adresse des Kunden"
def addressGet(options={})
assert_valid_keys(options, :customerId)
assert_keys_exists(options, :customerId)
execute(:addressGet, options)
end

# "erzeugt oder ändert Kontaktdaten eines Kunden"
def contactDataSet(options={})
assert_valid_keys(options, :customerId, :email, :phone, :mobile)
assert_keys_exists(options, :customerId)
execute(:contactDataSet, options)
end

# "ermittelt die Kontaktdaten des Kunden"
def contactDataGet(options={})
assert_valid_keys(options, :customerId)
assert_keys_exists(options, :customerId)
execute(:contactDataGet, options)
end

# "erzeugt einen neuen Bezahlvorgang"
# => "löst die Benachrichtigung sessionStatus mit dem Status "INIT" bzw. "REINIT" aus"
def sessionCreate(options={})
assert_valid_keys(options, :customerId, :sessionId, :project, :projectCampaign, :account, :webmasterCampaign, :amount, :currency, :title, :payText, :ip, :freeParams)
assert_keys_exists(options, :customerId, :project)
execute(:sessionCreate, options)
end

# "ordnet weitere freie Parameter der Session zu, oder ändert sie"
def sessionSet(options={})
assert_valid_keys(options, :sessionId, :freeParams)
assert_keys_exists(options, :sessionId)
execute(:sessionSet, options)
end

# "ermittelt Daten eines Bezahlvorgangs"
def sessionGet(options={})
assert_valid_keys(options, :sessionId)
assert_keys_exists(options, :sessionId)
execute(:sessionGet, options)
end

# "bestätigt den Lastschrifteinzug eines Vorgangs"
# => "löst die Benachrichtigung sessionStatus mit dem Status "APPROVED" aus"
def sessionApprove(options={})
assert_valid_keys(options, :sessionId)
assert_keys_exists(options, :sessionId)
execute(:sessionApprove, options)
end

# "übermittelt alle Bezahlvorgänge eines Kunden"
def sessionList(options={})
assert_valid_keys(options, :customerId)
assert_keys_exists(options, :customerId)
execute(:sessionList, options)
end

# "simuliert die Abbuchung für alle bestätigten Vorgänge"
# => "erzeugt für jede bestätigte Session eine neue Transaktion mit dem Typ 'BOOKING' und löst die Benachrichtigung transactionCreate aus"
# => "löst die Benachrichtigung sessionStatus mit dem Status 'CHARGED' aus"
def sessionChargeTest(options={})
execute(:sessionChargeTest, :testMode => 1)
end

# "simuliert Stornierung eines einzelnen Vorgangs"
# => "erzeugt eine neue Transaktion mit dem Typ "REVERSAL" und löst die Benachrichtigung transactionCreate aus"
# => "löst die Benachrichtigung sessionStatus mit dem Status "REVERSED" aus"
def sessionReverseTest(options={})
assert_valid_keys(options, :sessionId)
assert_keys_exists(options, :sessionId)
execute(:sessionReverseTest, options.merge(:testMode => 1))
end

# "simuliert die komplette Nachzahlung eines stornierten Vorgangs"
# => "erzeugt eine neue Transaktion mit dem Typ "BACKPAY" und löst die Benachrichtigung transactionCreate aus"
# => "löst die Benachrichtigung sessionStatus mit dem Status "RECHARGED" aus, wenn der gesamte offene Betrag beglichen wurde"
def sessionRechargeTest(options={})
assert_valid_keys(options, :sessionId, :amount)
assert_keys_exists(options, :sessionId)
execute(:sessionRechargeTest, options.merge(:testMode => 1))
end

# "Veranlasst eine (Teil-)Gutschrift und überweist sie zurück"
# => "erzeugt eine neue Transaktion mit dem Typ "REFUND" und löst die Benachrichtigung transactionCreate aus"
def sessionRefund(options={})
assert_valid_keys(options, :sessionId, :bankCode, :accountNumber, :accountHolder, :amount, :payText)
assert_keys_exists(options, :sessionId)
execute(:sessionRefund, options)
end

# "simuliert Stornierung der letzten Gutschrift,"
# => "erzeugt eine neue Transaktion mit dem Typ "REFUNDREVERSAL" und löst die Benachrichtigung transactionCreate aus"
def sessionRefundReverseTest(options={})
assert_valid_keys(options, :sessionId)
assert_keys_exists(options, :sessionId)
execute(:sessionRefundReverseTest, options.merge(:testMode => 1))
end

# "erstellt eine Transaktion vom Typ "EXTERNAL""
# => "löst die Benachrichtigung transactionCreate aus"
def transactionCreate(options={})
assert_valid_keys(options, :sessionId, :date, :amount, :description)
assert_keys_exists(options, :sessionId, :amount)
execute(:transactionCreate, options)
end

# "ermittelt alle Transaktionen für einen Bezahlvorgang"
def transactionList(options={})
assert_valid_keys(options, :sessionId)
assert_keys_exists(options, :sessionId)
execute(:transactionList, options)
end

# "ermittelt Daten einer Transaktion"
def transactionGet(options={})
assert_valid_keys(options, :transactionId)
assert_keys_exists(options, :transactionId)
execute(:transactionGet, options)
end

end

end
Expand Down

0 comments on commit 3cf11fc

Please sign in to comment.