ruby-saferpay
= ELC-Tecnologies[http://www.elctech.com], http://www.elctech.com

== DESCRIPTION:

Saferpay (http://www.saferpay.com) is a european e-commerce payment services provider, present mostly in Switzerland, Germany and Austria but expanding elsewhere as well.
This gem provides a ruby interface to the "Saferpay Card Authorization Interface" (SCAI) part of the API. The code also contain a "payinit" method that is part of the "Virtual Terminal" (VT) approach to ecommerce payments.

The SCAI interface is used when the merchant wishes to keep the acquirer on her/his own website for the whole duration of the transaction (client payment details transits through *both* the merchant site and the saferpay database ) whereas VT implies a redirect to the saferpay site.

== FEATURES/PROBLEMS:

* supports both common credit cards and direct debit cards ("Lastschrift")
* support for VT style payments is incomplete


== SYNOPSIS:

Init (info from saferpay test account; they're the same for all test accounts):
@pan = "9451123100000004" # Saferpay test PAN
@accountid = "99867-94913159" # Saferpay test ACCOUNTID
@exp = "1107" # This will change for other test accounts I guess... Might just be three months ahead of Time.now
@sfp = Saferpay.new( @accountid, @pan, @exp )

Reserve:
<tt>@sfp.reserve(30000, "USD")</tt>

Amounts are divided by 100. We're talking cents here, not dollars...

Capture last transaction:
<tt>@sfp.capture</tt>

Capture with a transacaton ID "4hj34hj4hh34h4j3hj4h334":
<tt>@sfp.capture("4hj34hj4hh34h4j3hj4h334")</tt>

== REQUIREMENTS:

Saferpay:
* A saferpay account
* openssl-0.9.7: saferpay docs says "d" version, but "m" seem to work; 0.9.8 does _not_ work. MacPorts package: "openssl97"

* A working saferpay installation
As of today (august '07), the linux distribution have issues and compilation has not been straightforward (I have used the libidpapp lib from the binary distribution and compiled the saferpay executable from the source distribution, using
make -f saferpay.mk
The libs from the binary distribution require lbstdc++5 (not standard on most modern linux distros).

YMMV.

The Mac binary distribution is for OS X 10.2, so that's pretty useless today; the Mac source distribution is not compiling (and is outdated).

Use the linux source distribution with modified makefiles as follows:

Makefile:
PREFIX = /usr
SSLVERSION = openssl-0.9.7b
SSLEAYDIR = ../$(SSLVERSION)


all:

make -f idpapp.mk
cp ./out/libidpapp.dylib $(PREFIX)/lib

make -f saferpay.mk
cp idpapi.h ./out
cp idperrc.h ./out
cp ./out/settings.template ./out/settings.xml

install:
cp ./out/libidpapp.s* $(PREFIX)/lib

clean:
make -f idpapp.mk clean
make -f saferpay.mk clean

xs: all
perl -e 'system("cd perl/MessageObject\nperl Makefile.PL\nmake");'
perl -e 'system("cd perl/MessageFactory\nperl Makefile.PL\nmake");'
perl -e 'system("cd perl/ConfigurationSetup\nperl Makefile.PL\nmake");'

testxs:
perl -e 'system("cd perl/ConfigurationSetup\nmake test");'
perl -e 'system("cd perl/MessageFactory\nmake test");'

installxs:
perl -e 'system("cd perl/ConfigurationSetup\nmake install");'
perl -e 'system("cd perl/MessageFactory\nmake install");'
perl -e 'system("cd perl/MessageObject\nmake install");'

cleanxs:
perl -e 'system("cd perl/ConfigurationSetup\nmake clean");'
perl -e 'system("cd perl/MessageFactory\nmake clean");'
perl -e 'system("cd perl/MessageObject\nmake clean");'

testmk:
echo "SSLVERSION: $(SSLVERSION)"
echo "SSLEAYDIR: $(SSLEAYDIR)"


saferpay.mk:
####### Compiler, tools and options
CC = gcc
CXX = g++

#CFLAGS = -pipe -fPIC -O2
CFLAGS = -pipe -fPIC -O2 -DUNIX -DHAVE_UNISTD_H -DHAVE_STDLIB_H
CXXFLAGS= -pipe -fPIC -O2
INCPATH =

LINK = g++
LFLAGS = -fPIC -ldl
LIBS = -lidpapp
MOC = $(QTDIR)/bin/moc

TAR = tar -cf
GZIP = gzip -9f

####### Files

HEADERS = idpapi.h \
idperrc.h
SOURCES = saferpay.c
OBJECTS = saferpay.o
SRCMOC =
OBJMOC =
DIST =
TARGET = ./out/saferpay

####### Implicit rules

.SUFFIXES: .cpp .cxx .cc .C .c

.cpp.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<

.cxx.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<

.cc.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<

.C.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<

.c.o:
$(CC) -c $(CFLAGS) $(INCPATH) -o $@ $<

####### Build rules

all: $(TARGET)

$(TARGET): $(OBJECTS) $(OBJMOC)
$(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJMOC) $(LIBS)

moc: $(SRCMOC)

tmake: saferpay.mk

# no more tmake


dist:
$(TAR) saferpay.tar saferpay.pro $(SOURCES) $(HEADERS) $(DIST)
$(GZIP) saferpay.tar

clean:
-rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(TARGET)
-rm -f *~ core

####### Compile

saferpay.o: saferpay.c \
idpapi.h \
idperrc.h

Ruby:
* Log4r is needed for logging (will log to GEMDIR/lib/log if user can write there)
* Hpricot is needed for XML parse (overkill?)

== INSTALL:
* saferpay tools (see docs and comments above)
* a working saferpay installation (run <tt>saferpay --help</tt> for more info and look at the Saferpay docs)
* <tt>sudo gem install ruby-saferpay</tt>
* test:
cd GEM_INSTALLATION_DIR
rake


The gem expects the saferpay installtion to be found in <tt>/opt/saferpay/</tt>. For the time being hack the source to change this:
BASEDIR = '/opt/saferpay/'
EXECUTABLE = 'saferpay'
CONFIG = BASEDIR


== LICENSE:

(The MIT License)

Copyright (c) 2007 ELC Tecnologies

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.