Commit 3df22172 authored by David Weston's avatar David Weston

Tested as working (of sorts)

parent 72b4b00a
php-stpp php-stpp
-------- --------
Currently in development. Not properly tested at the moment, so do not expect it to work right now. This masterpiece is currently in development, however, it's doing things
properly as it should - including 3D Secure support, however awkward that
may be.
Licenced under MIT, I'll put in the *actual* licence file in here some time. I've tried to make this as versatile as possible, matching various different
\ No newline at end of file coding patterns, as well, as a developer I know annoying it can be to adjust to
someone else's patterns when you think your own is superior.
Note: Amounts do not match the scheme applied to Secure Trading's API, as I
think placing orders in pence for things that are usually in pounds is somewhat
counter intuitive. (GBP; stirling pounds as opposed to pence)
Note: There's no validation as of yet. I intend to add validation in whenever
I get the chance.
Example
-------
<?php
$stapi = new STAPI("127.0.0.1", 5000);
$stapi->setAlias("test_typefish0000");
$stapi->setOperationSiteReference("test_typefish0000")
->setOperationAccountTypeDescription("ECOM");
$billing = $this->stapi->getBilling();
$billing->setAmount(12.50)
->setCurrency("GBP")
->setPaymentType("VISA")
->setPaymentCardNumber("4111111111111111")
->setPaymentExpiryDate([ 10, 2016 ])
->setPaymentSecurityCode(123);
# set billing information
$billing->setNamePrefix("Mr")
->setFirstName("David")
->setLastName("Weston")
->setPremise("No 789")
->setStreet("Test Street")
->setTown("Corby")
->setCounty("Northamptonshire")
->setPostcode("TE45 6ST")
->setCountry("GB");
$response = $stapi->call("auth");
if($response->isSuccessful())
echo "Success!";
else
echo "Failure - ".$response->getErrorMessage();
Licence
-------
Copyright (C) 2013, David Weston <php-stpp@typefish.co.uk>
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.
\ No newline at end of file
...@@ -79,6 +79,16 @@ abstract class STPPAddressable extends STPPObject ...@@ -79,6 +79,16 @@ abstract class STPPAddressable extends STPPObject
} }
/**
* Set the country of this addressable object.
*/
public function setCountry($country)
{
$this->options["country"] = $country;
return $this;
}
/** /**
* Set the first name of the person referenced in this addressable object. * Set the first name of the person referenced in this addressable object.
*/ */
......
...@@ -50,7 +50,7 @@ class STPPMerchant extends STPPObject ...@@ -50,7 +50,7 @@ class STPPMerchant extends STPPObject
/** /**
* Set the terminating URL - for use in 3DSecure transactions. * Set the terminating URL - for use in 3DSecure transactions.
*/ */
public function set3DSecureTermUrl($url) public function setTermUrl($url)
{ {
$this->options["termurl"] = $url; $this->options["termurl"] = $url;
return $this; return $this;
......
...@@ -31,6 +31,9 @@ abstract class STPPObject ...@@ -31,6 +31,9 @@ abstract class STPPObject
foreach($this->options as $option => $value) foreach($this->options as $option => $value)
{ {
if($value === null)
continue;
$method = "compile".$option; $method = "compile".$option;
if(method_exists($this, $method)) if(method_exists($this, $method))
......
...@@ -62,4 +62,15 @@ class STPPOperation extends STPPObject ...@@ -62,4 +62,15 @@ class STPPOperation extends STPPObject
$this->options["pareq"] = $value; $this->options["pareq"] = $value;
return $this; return $this;
} }
/**
* Set the 3DSecure PaRes (payer authentication response) value.
* Based on values sent back from ST.
*/
public function set3DSecurePaRes($value)
{
$this->options["pares"] = $value;
return $this;
}
} }
\ No newline at end of file
...@@ -25,7 +25,7 @@ class STPPResponse ...@@ -25,7 +25,7 @@ class STPPResponse
/** /**
* Called when the response has been constructed. * Called when the response has been constructed.
*/ */
public function __construct($response) public function __construct($response = null, $request = null)
{ {
$this->feed = simplexml_load_string($response); $this->feed = simplexml_load_string($response);
return true; return true;
...@@ -53,6 +53,18 @@ class STPPResponse ...@@ -53,6 +53,18 @@ class STPPResponse
} }
/**
* Retrieves the error message.
*/
public function getErrorMessage()
{
if($this->isSuccessful())
return null;
return (array) $this->feed->response->error;
}
/** /**
* Retrieves the transaction reference that applies to this * Retrieves the transaction reference that applies to this
* transaction. * transaction.
......
...@@ -50,7 +50,8 @@ class STAPI ...@@ -50,7 +50,8 @@ class STAPI
*/ */
public function __construct($address = "127.0.0.1", $port = 5000) public function __construct($address = "127.0.0.1", $port = 5000)
{ {
# $this->connect($address, $port); if($address != null)
$this->connect($address, $port);
} }
...@@ -59,7 +60,7 @@ class STAPI ...@@ -59,7 +60,7 @@ class STAPI
*/ */
public function __destruct() public function __destruct()
{ {
# $this->disconnect(); $this->disconnect();
} }
...@@ -83,7 +84,10 @@ class STAPI ...@@ -83,7 +84,10 @@ class STAPI
*/ */
protected function disconnect() protected function disconnect()
{ {
return fclose($this->connection); if($this->connection)
return fclose($this->connection);
return true;
} }
...@@ -276,6 +280,8 @@ class STAPI ...@@ -276,6 +280,8 @@ class STAPI
* calling conventions. * calling conventions.
* *
* Otherwise, the correct value will be returned unmolested. * Otherwise, the correct value will be returned unmolested.
*
* @todo: Fix this so that stuff like setOperation3DSecure... works.
*/ */
public function __call($method, $arguments) public function __call($method, $arguments)
{ {
...@@ -311,22 +317,46 @@ class STAPI ...@@ -311,22 +317,46 @@ class STAPI
} }
/**
* Some __get abuse - if there is an object getter, call it and
* return its value.
*/
public function __get($property)
{
$caller = "get".ucfirst($property);
if(!method_exists($this, $caller))
return null;
return $this->$caller();
}
/** /**
* Used to push a request off to the SecureTrading endpoint. * Used to push a request off to the SecureTrading endpoint.
*/ */
public function call($type) public function call($type)
{ {
$request = $this->compile($type)->asXML(); $failure = new STPPResponse("<responseblock></responseblock>");
if(!fwrite($this->connection, $request, strlen($request))) if(!$this->connection)
return false; return $failure;
$request = $this->compile($type);
$outbound = $request->asXML()."\r\n";
if(!fwrite($this->connection, $outbound, strlen($outbound)))
return $failure;
$response = ""; $response = "";
while(($chunk = fread($this->connection, 4096)) !== false) while(($chunk = fread($this->connection, 4096)) != false)
$response .= $chunk; $response .= $chunk;
return new STPPResponse($response); if(!$response)
return $failure;
return new STPPResponse($response, $request);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment