Skip to content

Commit

Permalink
Merge pull request #3 from realexpayments-developers/master
Browse files Browse the repository at this point in the history
Mobile Payments Auth functionality
  • Loading branch information
RealexITSO committed Feb 22, 2016
2 parents c6bdca9 + 447f5c0 commit 22c4576
Show file tree
Hide file tree
Showing 20 changed files with 446 additions and 132 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
.idea/
vendor/
.vagrant/
composer.phar
Vagrantfile
vm-config/
phpunit.phar
composer.lock
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Change Log
All notable changes to the SDK will be documented in this file.


## [1.1]
- Added mobile payment type (auth-mobile) and relevant fields (mobile, token) to payment request.

## [1.0.1]
- Minor Fixes

## [1.0]
- Initial Release
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ $response = $client->send( $request );
// do something with the response
echo $response->toXML();
$resultCode = $response->getResult();
$message = $response->getMessage();
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use com\realexpayments\remote\sdk\utils\XmlUtils;



/**
* Class PaymentRequest
*
Expand All @@ -26,47 +25,60 @@
* </p>
* <p><code><pre>
* $card = (new Card())
* ->addType(CardType::VISA)
* ->addNumber("4242424242424242")
* ->addExpiryDate("0525")
* ->addType(CardType::VISA)
* ->addNumber("4242424242424242")
* ->addExpiryDate("0525")
* ->addCvn("123")
* ->addCvnPresenceIndicator(PresenceIndicator::CVN_PRESENT);
* ->addCardHolderName("Joe Bloggs");
*
* $request = (new PaymentRequest())
* ->addMerchantId("yourMerchantId")
* ->addAccount("yourAccount")
* ->addType(PaymentType::AUTH)
* ->addAmount(10001)
* ->addCurrency("EUR")
* ->addCard($card)
* ->addAutoSettle((new AutoSettle())->addFlag(AutoSettleFlag::TRUE));
* ->addMerchantId("yourMerchantId")
* ->addAccount("yourAccount")
* ->addType(PaymentType::AUTH)
* ->addAmount(10001)
* ->addCurrency("EUR")
* ->addCard($card)
* ->addAutoSettle((new AutoSettle())->addFlag(AutoSettleFlag::TRUE));
* </pre></code></p>
*
* <p>
* Example AUTH with Address Verification:
* <p>
* <p><code><pre>
* $card = (new Card())
* ->addType(CardType::VISA)
* ->addNumber("4242424242424242")
* ->addExpiryDate("0525")
* ->addType(CardType::VISA)
* ->addNumber("4242424242424242")
* ->addExpiryDate("0525")
* ->addCvn("123")
* ->addCvnPresenceIndicator(PresenceIndicator::CVN_PRESENT)
* ->addCardHolderName("Joe Bloggs");
*
* $request = (new PaymentRequest())
* ->addMerchantId("yourMerchantId")
* ->addAccount("yourAccount")
* ->addType(PaymentType::AUTH)
* ->addAmount(10001)
* ->addCurrency("EUR")
* ->addCard($card)
* ->addAutoSettle((new AutoSettle())->addFlag(AutoSettleFlag::TRUE));
* ->addMerchantId("yourMerchantId")
* ->addAccount("yourAccount")
* ->addType(PaymentType::AUTH)
* ->addAmount(10001)
* ->addCurrency("EUR")
* ->addCard($card)
* ->addAutoSettle((new AutoSettle())->addFlag(AutoSettleFlag::TRUE));
* ->addAddressVerificationServiceDetails("382 The Road", "WB1 A42", "GB");
* </pre></code></p>
*
* <p>
* Example AUTH MOBILE
* <p>
* <p><code><pre>
* $request = (new PaymentRequest())
* ->addMerchantId("yourMerchantId")
* ->addAccount("yourAccount")
* ->addType(PaymentType::AUTH_MOBILE)
* ->addAutoSettle((new AutoSettle())->addFlag(AutoSettleFlag::TRUE));
* ->addMobile("apple-pay")
* ->addToken("{auth mobile payment token}");
* </pre></code></p>
*
*
* @author vicpada
* @package com\realexpayments\remote\sdk\domain\payment
*/
Expand Down Expand Up @@ -180,7 +192,7 @@ class PaymentRequest implements iRequest {
private $refundHash;

/**
* @var string wellTODO - info on this
* @var string Fraud filter flag
*
*/
private $fraudFilter;
Expand All @@ -205,6 +217,19 @@ class PaymentRequest implements iRequest {
*/
private $mpi;

/**
* @var string The mobile auth payment type e.g. apple-pay.
*
*/
private $mobile;

/**
* @var string The mobile auth payment token to be sent in place of payment data.
*
*/
private $token;


/**
* Constructor for Payment Request
*/
Expand Down Expand Up @@ -543,6 +568,42 @@ public function setMpi( $mpi ) {
$this->mpi = $mpi;
}

/**
* Getter for mobile
*
* @return string
*/
public function getMobile() {
return $this->mobile;
}

/**
* Setter for mobile
*
* @param string $mobile
*/
public function setMobile( $mobile ) {
$this->mobile = $mobile;
}

/**
* Getter for token
*
* @return string
*/
public function getToken() {
return $this->token;
}

/**
* Setter for token
*
* @param string $token
*/
public function setToken( $token ) {
$this->token = $token;
}


/**
* Helper method for adding TSS info
Expand Down Expand Up @@ -821,6 +882,32 @@ public function addMpi( Mpi $mpi ) {
return $this;
}

/**
* Helper method for adding a mobile
*
* @param string $mobile
*
* @return PaymentRequest
*/
public function addMobile( $mobile ) {
$this->mobile = $mobile;

return $this;
}

/**
* Helper method for adding a token
*
* @param string $token
*
* @return PaymentRequest
*/
public function addToken( $token ) {
$this->token = $token;

return $this;
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -884,6 +971,7 @@ public function hash( $secret ) {
$orderId = null == $this->orderId ? "" : $this->orderId;
$amount = "";
$currency = "";
$token = null == $this->token ? "" : $this->token;

if ( $this->amount != null ) {
$amount = null == $this->amount->getAmount() ? "" : $this->amount->getAmount();
Expand All @@ -897,17 +985,27 @@ public function hash( $secret ) {
}

//create String to hash
$toHash = $timeStamp
. "."
. $merchantId
. "."
. $orderId
. "."
. $amount
. "."
. $currency
. "."
. $cardNumber;
if ( $this->type == PaymentType::AUTH_MOBILE ) {
$toHash = $timeStamp
. "."
. $merchantId
. "."
. $orderId
. "..."
. $token;
} else {
$toHash = $timeStamp
. "."
. $merchantId
. "."
. $orderId
. "."
. $amount
. "."
. $currency
. "."
. $cardNumber;
}

$this->hash = GenerationUtils::generateHash( $toHash, $secret );

Expand Down Expand Up @@ -951,4 +1049,6 @@ public function addAddressVerificationServiceDetails( $addressLine, $postcode, $

return $this;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class PaymentType extends EnumBase {

const __default = self::AUTH;
const AUTH = "auth";
const AUTH_MOBILE = "auth-mobile";

/**
* @var string The payment type String value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,11 @@ private function parseXmlValue( \DOMNode $node ) {

foreach ( $value as $key => $val ) {
if ( is_array( $val ) && 1 === count( $val ) ) {
$value[ $key ] = current( $val );
$val = current( $val );
if ( is_string( $val ) ) {
$val = trim( $val );
}
$value[ $key ] = $val;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,38 @@ public function denormalize( $data, $class, $format = null, array $context = arr
->addAccount( $array['account'] )
->addChannel( $array['channel'] )
->addOrderId( $array['orderid'] )
->addCard( $this->denormaliseCard( $array ) )
->addAutoSettle( $this->denormaliseAutoSettle( $array ) )
->addHash( $array['sha1hash'] )
->addPaymentsReference( $array['pasref'] )
->addAuthCode( $array['authcode'] )
->addRefundHash( $array['refundhash'] )
->addFraudFilter( $array['fraudfilter'] )
->addRecurring( $this->denormaliseRecurring( $array ) )
->addTssInfo( $this->denormaliseTssInfo( $array ) )
->addMpi( $this->denormaliseMpi( $array ) );
->addMobile( $array['mobile'] )
->addToken( $array['token'] );

$autoSettle = $this->denormaliseAutoSettle( $array );
if ( $autoSettle != null ) {
$request->addAutoSettle( $autoSettle );
}

$card = $this->denormaliseCard( $array );
if ( $card != null ) {
$request->addCard( $card );
}

$recurring = $this->denormaliseRecurring( $array );
if ( $recurring != null ) {
$request->addRecurring( $recurring );
}

$tssInfo = $this->denormaliseTssInfo( $array );
if ( $tssInfo != null ) {
$request->addTssInfo( $tssInfo );
}

$mpi = $this->denormaliseMpi( $array );
if ( $mpi != null ) {
$request->addMpi( $mpi );
}

$request->setAmount( $this->denormaliseAmount( $array ) );
$request->setComments( $this->denormaliseComments( $array ) );
Expand Down Expand Up @@ -299,6 +321,8 @@ public function normalize( $object, $format = null, array $context = array() ) {
'recurring' => $this->normaliseRecurring( $object ),
'tssinfo' => $this->normaliseTssInfo( $object ),
'mpi' => $this->normaliseMpi( $object ),
'mobile' => $object->getMobile(),
'token' => $object->getToken(),
) );
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/php/com-realexpayments-remote-sdk/http/HttpUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class HttpUtils {
*
* @return HttpClient httpclient
*/
public static function getDefaultClient( HttpConfiguration $httpConfiguration ) {
public static function getDefaultClient( HttpConfiguration $httpConfiguration ) {

self::getLogger();

Expand Down Expand Up @@ -123,7 +123,7 @@ public static function sendMessage( $xml, HttpClient $httpClient, HttpConfigurat

} catch ( Exception $e ) {

self::$logger->error( "Exception communicating with Realex.", $e->getMessage() );
self::$logger->error( "Exception communicating with Realex." . $e->getMessage() );
throw new RealexException( "Exception communicating with Realex", $e );
}
}
Expand Down
Loading

0 comments on commit 22c4576

Please sign in to comment.