diff --git a/src/main/php/com-realexpayments-remote-sdk/domain/apm/APMRequest.php b/src/main/php/com-realexpayments-remote-sdk/domain/apm/APMRequest.php new file mode 100644 index 0000000..7934a62 --- /dev/null +++ b/src/main/php/com-realexpayments-remote-sdk/domain/apm/APMRequest.php @@ -0,0 +1,640 @@ + + * Class representing a APM request to be sent to Realex. + *

+ *

+ * Helper methods are provided (prefixed with 'add') for object creation. + *

+ *

+ * Example: + *

+ *

+ * $paymentmethoddetails = (new PaymentMethodDetails())
+ *    ->addReturnUrl("https://www.example.com/returnUrl")
+ *    ->addStatusUpdateUrl("https://www.example.com/statusUrl")
+ *    ->addDescriptor("Test Transaction")
+ *    ->addCountry("DE")
+ *    ->addAccountHoldername("James Mason");
+ *
+ * $request = (new APMRequest())
+ *    ->addAccount("yourAccount")
+ *    ->addMerchantId("yourMerchantId")
+ *    ->addType(APMType::PAYMENT_SET)
+ *    ->addPaymentMethod("sofort")
+ *  ->addAmount(100)
+ *    ->addCurrency("EUR")
+ *    ->addPaymentMethodDetails($paymentmethoddetails);
+ * 

+ * + * + * @author gnurub + * @package com\realexpayments\remote\sdk\domain\APM + * + */ +class APMRequest implements iRequest { + + /** + * @var string Format of timestamp is yyyyMMddhhmmss e.g. 20150131094559 for 31/01/2015 09:45:59. + * If the timestamp is more than a day (86400 seconds) away from the server time, then the request is rejected. + * + */ + private $timeStamp; + + /** + * @var string The APM type. + * + */ + private $type; + + /** + * @var string Represents Realex Payments assigned merchant id. + * + */ + private $merchantId; + + /** + * @var string Represents the Realex Payments subaccount to use. If this element is omitted, then the + * default account is used. + * + */ + private $account; + + /** + * @var string Represents the unique order id of this transaction. Must be unique across all of the sub-accounts. + * + */ + private $orderId; + + + /** + * @var string The payments reference for the transaction, returned in the payment-set response. + * + */ + private $paymentsReference; + + /** + * @var string Represents the unique order id of this transaction. Must be unique across all of the sub-accounts. + * + */ + private $paymentMethod; + + /** + * @var Amount {@link Amount} object containing the amount value and the currency type. + * + */ + private $amount; + + /** + * @var string Hash constructed from the time stamp, merchand ID, order ID, amount, currency, card number + * and secret values. + * + */ + private $hash; + + /** + * @var CommentCollection List of {@link Comment} objects to be passed in request. + * Optionally, up to two comments can be associated with any transaction. + * + */ + private $comments; + + /** + * @var PaymentMethodDetails Contains payment information to be used on Receipt-in transactions + */ + private $paymentMethodDetails; + + /** + * @var AutoSettle {@link AutoSettle} object containing the auto settle flag. + */ + private $autoSettle; + + /** + * APMRequest constructor. + */ + public function __construct() { + } + + public static function GetClassName() { + return __CLASS__; + } + + /** + * Getter for time stamp + * + * @return string + */ + public function getTimeStamp() { + return $this->timeStamp; + } + + /** + * Setter for time stamp + * + * @param string $timeStamp + */ + public function setTimeStamp( $timeStamp ) { + $this->timeStamp = $timeStamp; + } + + /** + * Getter for the ThreeDSecure type + * + * @return string + */ + public function getType() { + return $this->type; + } + + /** + * Setter for the ThreeDSecure type + * + * @param string $type + */ + public function setType( $type ) { + $this->type = $type; + } + + /** + * Getter for merchant Id + * + * @return string + */ + public function getMerchantId() { + return $this->merchantId; + } + + /** + * Setter for merchant Id + * + * @param string $merchantId + */ + public function setMerchantId( $merchantId ) { + $this->merchantId = $merchantId; + } + + /** + * Getter for account + * + * @return string + */ + public function getAccount() { + return $this->account; + } + + /** + * Setter for account + * + * @param string $account + */ + public function setAccount( $account ) { + $this->account = $account; + } + + /** + * Getter for order Id + * + * @return string + */ + public function getOrderId() { + return $this->orderId; + } + + /** + * Setter for order Id + * + * @param string $orderId + */ + public function setOrderId( $orderId ) { + $this->orderId = $orderId; + } + + /** + * Getter for payment method + * + * @return string + */ + public function getPaymentMethod() { + return $this->orderId; + } + + /** + * Setter for payment method + * + * @param string $paymentMethod + */ + public function setPaymentMethod( $paymentMethod ) { + $this->paymentMethod = $paymentMethod; + } + + /** + * @return string + */ + public function getPaymentsReference() + { + return $this->paymentsReference; + } + + /** + * @param string $paymentsReference + */ + public function setPaymentsReference($paymentsReference) + { + $this->paymentsReference = $paymentsReference; + } + + /** + * Getter for {@link Amount} + * + * @return Amount + */ + public function getAmount() { + return $this->amount; + } + + /** + * Setter for {@link Amount} + * + * @param Amount $amount + */ + public function setAmount( $amount ) { + $this->amount = $amount; + } + + /** + * Getter for {@link PaymentMethodDetails} + * + * @return PaymentMethodDetails + */ + public function getPaymentMethodDetails() { + return $this->paymentMethodDetails; + } + + /** + * Setter for {@link PaymentMethodDetails} + * + * @param PaymentMethodDetails $paymentMethod + */ + public function setPaymentMethodDetails( $paymentMethod ) { + $this->paymentMethodDetails = $paymentMethod; + } + + /** + * Getter for hash + * + * @return string + */ + public function getHash() { + return $this->hash; + } + + /** + * Setter for hash + * + * @param string $hash + */ + public function setHash( $hash ) { + $this->hash = $hash; + } + + /** + * Getter for comments + * + * @return CommentCollection + */ + public function getComments() { + return $this->comments; + } + + /** + * Setter for comments + * + * @param CommentCollection $comments + */ + public function setComments( $comments ) { + $this->comments = $comments; + } + + /** + * Getter for autoSettle + * + * @return AutoSettle + */ + public function getAutoSettle() { + return $this->autoSettle; + } + + /** + * Setter for autoSettle + * + * @param AutoSettle $autoSettle + */ + public function setAutoSettle( $autoSettle ) { + $this->autoSettle = $autoSettle; + } + + + /** + * Helper method for adding a timeStamp + * + * @param string $timeStamp + * + * @return APMRequest + */ + public function addTimeStamp( $timeStamp ) { + $this->timeStamp = $timeStamp; + + return $this; + } + + /** + * Helper method for adding a type + * + * @param string $type + * + * @return APMRequest + */ + public function addType( $type ) { + $this->type = $type; + + return $this; + } + + /** + * Helper method for adding a {@link APMType}. + * + * @param APMType $type + * + * @return APMRequest + */ + public function addTAPMType( APMType $type ) { + $this->type = $type->getType(); + + return $this; + } + + + /** + * Helper method for adding a merchantId + * + * @param string $merchantId + * + * @return APMRequest + */ + public function addMerchantId( $merchantId ) { + $this->merchantId = $merchantId; + + return $this; + } + + /** + * Helper method for adding a account + * + * @param string $account + * + * @return APMRequest + */ + public function addAccount( $account ) { + $this->account = $account; + + return $this; + } + + /** + * Helper method for adding a orderId + * + * @param string $orderId + * + * @return APMRequest + */ + public function addOrderId( $orderId ) { + $this->orderId = $orderId; + + return $this; + } + + /** + * Helper method for adding a payment method + * + * @param string $paymentMethod + * + * @return APMRequest + */ + public function addPaymentMethod( $paymentMethod ) { + $this->paymentMethod = $paymentMethod; + + return $this; + } + + /** + * @param string $pasRef + * @return APMRequest + */ + public function addPaymentsReference($pasRef) + { + $this->paymentsReference = $pasRef; + + return $this; + } + + /** + * Helper method for adding an amount. If an {@link Amount} has not been set, then one is created. + * + * @param int $amount + * + * @return APMRequest + */ + public function addAmount( $amount ) { + if ( is_null( $this->amount ) ) { + $this->amount = new Amount(); + $this->amount->addAmount( $amount ); + } else { + $this->amount->addAmount( $amount ); + } + + return $this; + } + + /** + * Helper method for adding a currency. If an {@link Amount} has not been set, then one is created. + * + * @param string $currency + * + * @return APMRequest + */ + public function addCurrency( $currency ) { + if ( is_null( $this->amount ) ) { + $this->amount = new Amount(); + $this->amount->addCurrency( $currency ); + } else { + $this->amount->addCurrency( $currency ); + } + + return $this; + } + + /** + * Helper method for adding a hash + * + * @param string $hash + * + * @return APMRequest + */ + public function addHash( $hash ) { + $this->hash = $hash; + + return $this; + } + + /** + * Helper method for adding a comment. NB Only 2 comments will be accepted by Realex. + * + * @param string $comment + * + * @return APMRequest + */ + public function addComment( $comment ) { + if ( is_null( $this->comments ) ) { + $this->comments = new CommentCollection(); + } + + //create new comments array list if null + if ( is_null( $this->comments ) ) { + $this->comments = new CommentCollection(); + } + + $size = $this->comments->getSize(); + $commentObject = new Comment(); + $this->comments->add( $commentObject->addComment( $comment )->addId( ++ $size ) ); + + return $this; + } + + /** + * Helper method for adding a paymentMethodDetails + * + * @param PaymentMethodDetails $paymentMethodDetails + * + * @return APMRequest + */ + public function addPaymentMethodDetails( $paymentMethodDetails ) { + $this->paymentMethodDetails = $paymentMethodDetails; + + return $this; + } + + /** + * Helper method for adding a autoSettle + * + * @param AutoSettle $autoSettle + * + * @return APMRequest + */ + public function addAutoSettle( $autoSettle ) { + $this->autoSettle = $autoSettle; + + return $this; + } + + + /** + * {@inheritDoc} + */ + public function toXml() { + return XmlUtils::toXml( $this, new MessageType( MessageType::APM ) ); + } + + /** + * {@inheritDoc} + */ + public function fromXml( $xml ) { + return XmlUtils::fromXml( $xml, new MessageType( MessageType::APM ) ); + } + + /** + * {@inheritDoc} + */ + public function generateDefaults( $secret ) { + + //generate timestamp if not set + if ( is_null( $this->timeStamp ) ) { + $this->timeStamp = GenerationUtils::generateTimestamp(); + } + + //generate order ID if not set + if ( is_null( $this->orderId ) ) { + $this->orderId = GenerationUtils::generateOrderId(); + } + + //generate hash + $this->hash( $secret ); + + return $this; + } + + /** + * {@inheritDoc} + */ + public function responseFromXml( $xml ) { + + $response = new APMResponse(); + + return $response->fromXml( $xml ); + } + + /** + * Creates the security hash from a number of fields and the shared secret. + * + * @param string $secret + * + * @return $this + */ + public function hash( $secret ) { + + //check for any null values and set them to empty string for hashing + $timeStamp = null == $this->timeStamp ? "" : $this->timeStamp; + $merchantId = null == $this->merchantId ? "" : $this->merchantId; + $orderId = null == $this->orderId ? "" : $this->orderId; + $paymentMethod = null == $this->paymentMethod ? "" : $this->paymentMethod; + $amount = ""; + $currency = ""; + + if ( $this->amount != null ) { + $amount = null == $this->amount->getAmount() ? "" : $this->amount->getAmount(); + $currency = null == $this->amount->getCurrency() ? "" : $this->amount->getCurrency(); + } + + //create String to hash + $toHash = $timeStamp + . "." + . $merchantId + . "." + . $orderId + . "." + . $amount + . "." + . $currency + . "." + . $paymentMethod; + + $this->hash = GenerationUtils::generateHash( $toHash, $secret ); + + return $this; + + } +} \ No newline at end of file diff --git a/src/main/php/com-realexpayments-remote-sdk/domain/apm/APMResponse.php b/src/main/php/com-realexpayments-remote-sdk/domain/apm/APMResponse.php new file mode 100644 index 0000000..2abf6ec --- /dev/null +++ b/src/main/php/com-realexpayments-remote-sdk/domain/apm/APMResponse.php @@ -0,0 +1,494 @@ + + * Class representing a APM response received from Realex. + *

+ * + * @author vicpada + * @package com\realexpayments\remote\sdk\domain\threeDSecure + */ +class APMResponse implements iResponse +{ + + /** + * @var string Time stamp in the format YYYYMMDDHHMMSS, which represents the time in the format year + * month date hour minute second. + * + */ + private $timeStamp; + + /** + * @var string Represents Realex Payments assigned merchant id. + * + */ + private $merchantId; + + /** + * @var string Represents the Realex Payments subaccount to use. If you omit this element then + * we will use your default account. + * + */ + private $account; + + /** + * @var string Represents the unique order id of this transaction. Must be unique across all of your accounts. + * + */ + private $orderId; + + /** + * @var string The result codes returned by the Realex Payments system. + * + */ + private $result; + + /** + * @var string Specifies the payment method. + * + */ + private $paymentMethod; + + /** + * @var PaymentMethodDetails Specifies the payment method. + * + */ + private $paymentMethodDetails; + + /** + * @var string The text of the response. + * + */ + private $message; + + /** + * @var string The Realex payments reference (pasref) for the transaction. Used when referencing + * this transaction in refund and void requests. + * + */ + private $paymentsReference; + + /** + * @var string The SHA-1 hash of certain elements of the response. The details of this are to be found + * in the realauth developer's guide. + * + */ + private $hash; + + /** + * APMResponse constructor. + */ + public function __construct() + { + } + + public static function GetClassName() + { + return __CLASS__; + } + + /** + * Getter for timeStamp + * + * @return string + */ + public function getTimeStamp() + { + return $this->timeStamp; + } + + /** + * Setter for timeStamp + * + * @param string $timeStamp + */ + public function setTimeStamp($timeStamp) + { + $this->timeStamp = $timeStamp; + } + + /** + * Getter for merchantId + * + * @return string + */ + public function getMerchantId() + { + return $this->merchantId; + } + + /** + * Setter for merchantId + * + * @param string $merchantId + */ + public function setMerchantId($merchantId) + { + $this->merchantId = $merchantId; + } + + /** + * Getter for account + * + * @return string + */ + public function getAccount() + { + return $this->account; + } + + /** + * Setter for account + * + * @param string $account + */ + public function setAccount($account) + { + $this->account = $account; + } + + /** + * Getter for orderId + * + * @return string + */ + public function getOrderId() + { + return $this->orderId; + } + + /** + * Setter for orderId + * + * @param string $orderId + */ + public function setOrderId($orderId) + { + $this->orderId = $orderId; + } + + /** + * Getter for result + * + * @return string + */ + public function getResult() + { + return $this->result; + } + + /** + * Setter for result + * + * @param string $result + */ + public function setResult($result) + { + $this->result = $result; + } + + /** + * @return string + */ + public function getPaymentMethod() + { + return $this->paymentMethod; + } + + /** + * @param string $paymentMethod + */ + public function setPaymentMethod($paymentMethod) + { + $this->paymentMethod = $paymentMethod; + } + + /** + * @return PaymentMethodDetails + */ + public function getPaymentMethodDetails() + { + return $this->paymentMethodDetails; + } + + /** + * @param PaymentMethodDetails $paymentMethodDetails + */ + public function setPaymentMethodDetails($paymentMethodDetails) + { + $this->paymentMethodDetails = $paymentMethodDetails; + } + + /** + * Getter for message + * + * @return string + */ + public function getMessage() + { + return $this->message; + } + + /** + * Setter for message + * + * @param string $message + */ + public function setMessage($message) + { + $this->message = $message; + } + + /** + * Getter for paymentsReference + * + * @return string + */ + public function getPaymentsReference() + { + return $this->paymentsReference; + } + + /** + * Setter for paymentsReference + * + * @param string $paymentsReference + */ + public function setPaymentsReference($paymentsReference) + { + $this->paymentsReference = $paymentsReference; + } + + /** + * Getter for hash + * + * @return string + */ + public function getHash() + { + return $this->hash; + } + + /** + * Setter for hash + * + * @param string $hash + */ + public function setHash($hash) + { + $this->hash = $hash; + } + + + /** + * Helper method for adding a timeStamp + * + * @param string $timeStamp + * + * @return APMResponse + */ + public function addTimeStamp($timeStamp) + { + $this->timeStamp = $timeStamp; + + return $this; + } + + /** + * Helper method for adding a merchantId + * + * @param string $merchantId + * + * @return APMResponse + */ + public function addMerchantId($merchantId) + { + $this->merchantId = $merchantId; + + return $this; + } + + /** + * @param string $paymentMethod + * @return APMResponse + */ + public function addPaymentMethod($paymentMethod) + { + $this->paymentMethod = $paymentMethod; + + return $this; + } + + /** + * @param PaymentMethodDetails $paymentMethodDetails + * @return APMResponse + */ + public function addPaymentMethodDetails($paymentMethodDetails) + { + $this->paymentMethodDetails = $paymentMethodDetails; + + return $this; + } + + /** + * Helper method for adding a account + * + * @param string $account + * + * @return APMResponse + */ + public function addAccount($account) + { + $this->account = $account; + + return $this; + } + + /** + * Helper method for adding a orderId + * + * @param string $orderId + * + * @return APMResponse + */ + public function addOrderId($orderId) + { + $this->orderId = $orderId; + + return $this; + } + + /** + * Helper method for adding a result + * + * @param string $result + * + * @return APMResponse + */ + public function addResult($result) + { + $this->result = $result; + + return $this; + } + + + /** + * Helper method for adding a message + * + * @param string $message + * + * @return APMResponse + */ + public function addMessage($message) + { + $this->message = $message; + + return $this; + } + + /** + * Helper method for adding a paymentsReference + * + * @param string $paymentsReference + * + * @return APMResponse + */ + public function addPaymentsReference($paymentsReference) + { + $this->paymentsReference = $paymentsReference; + + return $this; + } + + /** + * Helper method for adding a hash + * + * @param string $hash + * + * @return APMResponse + */ + public function addHash($hash) + { + $this->hash = $hash; + + return $this; + } + + + /** + * @{@inheritdoc} + */ + public function fromXML($resource) + { + return XmlUtils::fromXml($resource, new MessageType(MessageType::APM)); + } + + /** + * @{@inheritdoc} + */ + public function toXML() + { + return XmlUtils::toXml($this, new MessageType(MessageType::APM)); + } + + /** + * @{@inheritdoc} + */ + public function isHashValid($secret) + { + + $hashValid = false; + + //check for any null values and set them to empty $for hashing + $timeStamp = null == $this->timeStamp ? "" : $this->timeStamp; + $merchantId = null == $this->merchantId ? "" : $this->merchantId; + $orderId = null == $this->orderId ? "" : $this->orderId; + $result = null == $this->result ? "" : $this->result; + $message = null == $this->message ? "" : $this->message; + $paymentsReference = null == $this->paymentsReference ? "" : $this->paymentsReference; + $paymentMethod = null == $this->paymentMethod ? "" : $this->paymentMethod; + + //create $to hash + $toHash = $timeStamp + . "." + . $merchantId + . "." + . $orderId + . "." + . $result + . "." + . $message + . "." + . $paymentsReference + . "." + . $paymentMethod; + + //check if calculated hash matches returned value + $expectedHash = GenerationUtils::generateHash($toHash, $secret); + if ($expectedHash == $this->hash) { + $hashValid = true; + } + + return $hashValid; + } + + /** + * @{@inheritdoc} + */ + public function isSuccess() + { + return ResponseUtils::isSuccess($this); + } +} \ No newline at end of file diff --git a/src/main/php/com-realexpayments-remote-sdk/domain/apm/APMType.php b/src/main/php/com-realexpayments-remote-sdk/domain/apm/APMType.php new file mode 100644 index 0000000..d7ca8e3 --- /dev/null +++ b/src/main/php/com-realexpayments-remote-sdk/domain/apm/APMType.php @@ -0,0 +1,48 @@ +type = $type; + } + + /** + * Get the string value of the ThreeDSecure type + * + * @return string + */ + public function getType() { + return $this->type; + } + +} diff --git a/src/main/php/com-realexpayments-remote-sdk/domain/apm/BankAccount.php b/src/main/php/com-realexpayments-remote-sdk/domain/apm/BankAccount.php new file mode 100644 index 0000000..9a5e006 --- /dev/null +++ b/src/main/php/com-realexpayments-remote-sdk/domain/apm/BankAccount.php @@ -0,0 +1,100 @@ + + * Domain object representing PaymentMethodDetails information to be passed to Realex Alternative Payment Method + * for payment-set transactions. + * Payment data contains the CVN number for the stored card + *

+ *

+ *

+ * $bankAccount = ( new BankAccount() )
+ *    ->addIban("DE84837473949793743749")
+ *    ->addBic("GENODEF1GW1");
+ * 

+ * + * @author gnurub + */ +class BankAccount +{ + + /** + * @var string $iban The endpoint to which the customer should be redirected after a payment has been attempted or successfully completed on the payment scheme's site. + */ + private $iban; + private $bic; + + /** + * BankAccount constructor. + */ + public function __construct() + { + } + + /** + * @return string + */ + public function getIban() + { + return $this->iban; + } + + /** + * @param string $iban + */ + public function setIban($iban) + { + $this->iban = $iban; + } + + /** + * @param string $iban + * @return BankAccount + */ + public function addIban($iban) + { + $this->iban = $iban; + + return $this; + } + + /** + * @return string + */ + public function getBic() + { + return $this->bic; + } + + /** + * @param string $bic + */ + public function setBic($bic) + { + $this->bic = $bic; + } + + /** + * @param string $bic + * @return BankAccount + */ + public function addBic($bic) + { + $this->bic = $bic; + + return $this; + } + + public static function GetClassName() + { + return __CLASS__; + } + +} \ No newline at end of file diff --git a/src/main/php/com-realexpayments-remote-sdk/domain/apm/PaymentMethodDetails.php b/src/main/php/com-realexpayments-remote-sdk/domain/apm/PaymentMethodDetails.php new file mode 100644 index 0000000..c581ac8 --- /dev/null +++ b/src/main/php/com-realexpayments-remote-sdk/domain/apm/PaymentMethodDetails.php @@ -0,0 +1,285 @@ + + * Domain object representing PaymentMethodDetails information to be passed to Realex Alternative Payment Method + * for payment-set transactions. + * Payment data contains the CVN number for the stored card + *

+ *

+ *

+ * $paymentData = ( new PaymentData() )
+ *    ->addCvnNumber("123") ;
+ * 

+ * + * @author gnurub + */ +class PaymentMethodDetails +{ + + /** + * @var string $returnUrl The endpoint to which the customer should be redirected after a payment has been attempted or successfully completed on the payment scheme's site. + */ + private $returnUrl; + + /** + * @var string $redirectUrl URL to redirect the customer to - only available in PENDING asynchronous transactions. Sent there so merchant can redirect consumer to complete an interrupted payment. + */ + private $redirectUrl; + + /** + * @var string $paymentPurpose This parameter reflects what the customer will see on the proof of payment (for example, bank statement record and similar). Also known as the payment descriptor + */ + private $paymentPurpose; + + /** + * @var string $statusUpdateUrl The endpoint which will receive payment-status messages. This will include the result of the transaction or any updates to the transaction status. For certain asynchronous payment methods these notifications may come hours or days after the initial authorisation. + */ + private $statusUpdateUrl; + + /** + * @var string $descriptor Enables dynamic values to be sent for each transaction. + */ + private $descriptor; + + /** + * @var string $country 2 character country code, must adhere to ISO 3166-2. + */ + private $country; + + /** + * @var string $accountHoldername The name of the account holder + */ + private $accountHoldername; + + /** + * @var BankAccount $bankAccount The name of the account holder + */ + private $bankAccount; + + /** + * PaymentMethodDetails constructor. + */ + public function __construct() + { + } + + /** + * @return string + */ + public function getRedirectUrl() + { + return $this->redirectUrl; + } + + /** + * @param string $redirectUrl + */ + public function setRedirectUrl($redirectUrl) + { + $this->redirectUrl = $redirectUrl; + } + + /** + * @return string + */ + public function getPaymentPurpose() + { + return $this->paymentPurpose; + } + + /** + * @param string $paymentPurpose + */ + public function setPaymentPurpose($paymentPurpose) + { + $this->paymentPurpose = $paymentPurpose; + } + + /** + * @param string $paymentPurpose + * @return PaymentMethodDetails + */ + public function addPaymentPurpose($paymentPurpose) + { + $this->paymentPurpose = $paymentPurpose; + + return $this; + } + + /** + * @return BankAccount + */ + public function getBankAccount() + { + return $this->bankAccount; + } + + /** + * @param BankAccount $bankAccount + */ + public function setBankAccount($bankAccount) + { + $this->bankAccount = $bankAccount; + } + + /** + * @param BankAccount $bankAccount + * @return PaymentMethodDetails + */ + public function addBankAccount($bankAccount) + { + $this->bankAccount = $bankAccount; + + return $this; + } + + /** + * @return string + */ + public function getReturnUrl() + { + return $this->returnUrl; + } + + /** + * @param string $returnUrl + */ + public function setReturnUrl($returnUrl) + { + $this->returnUrl = $returnUrl; + } + + /** + * @param string $returnUrl + * @return PaymentMethodDetails + */ + public function addReturnUrl($returnUrl) + { + $this->setReturnUrl($returnUrl); + + return $this; + } + + /** + * @return string + */ + public function getStatusUpdateUrl() + { + return $this->statusUpdateUrl; + } + + /** + * @param string $statusUpdateUrl + */ + public function setStatusUpdateUrl($statusUpdateUrl) + { + $this->statusUpdateUrl = $statusUpdateUrl; + } + + /** + * @param string $statusUpdateUrl + * @return PaymentMethodDetails + */ + public function addStatusUpdateUrl($statusUpdateUrl) + { + $this->setStatusUpdateUrl($statusUpdateUrl); + + return $this; + } + + /** + * @return string + */ + public function getDescriptor() + { + return $this->descriptor; + } + + /** + * @param string $descriptor + */ + public function setDescriptor($descriptor) + { + $this->descriptor = $descriptor; + } + + /** + * @param string $descriptor + * @return PaymentMethodDetails + */ + public function addDescriptor($descriptor) + { + $this->setCountry($descriptor); + + return $this; + } + + /** + * @return string + */ + public function getCountry() + { + return $this->country; + } + + /** + * @param string $country + */ + public function setCountry($country) + { + $this->country = $country; + } + + + /** + * @param string $country + * @return PaymentMethodDetails + */ + public function addCountry($country) + { + $this->setCountry($country); + + return $this; + } + + /** + * @return string + */ + public function getAccountHoldername() + { + return $this->accountHoldername; + } + + /** + * @param string $accountHoldername + */ + public function setAccountHoldername($accountHoldername) + { + $this->accountHoldername = $accountHoldername; + } + + /** + * @param string $accountHoldername + * @return PaymentMethodDetails + */ + public function addAccountHoldername($accountHoldername) + { + $this->setAccountHoldername($accountHoldername); + + return $this; + } + + public static function GetClassName() + { + return __CLASS__; + } + +} \ No newline at end of file diff --git a/src/main/php/com-realexpayments-remote-sdk/domain/apm/normaliser/APMRequestNormalizer.php b/src/main/php/com-realexpayments-remote-sdk/domain/apm/normaliser/APMRequestNormalizer.php new file mode 100644 index 0000000..63dd934 --- /dev/null +++ b/src/main/php/com-realexpayments-remote-sdk/domain/apm/normaliser/APMRequestNormalizer.php @@ -0,0 +1,178 @@ +format = $format; + $this->context = $context; + + $request = new APMRequest(); + $array = new SafeArrayAccess($data); + + $request->addTimestamp($array['@timestamp']) + ->addType($array['@type']) + ->addMerchantId($array['merchantid']) + ->addAccount($array['account']) + ->addOrderId($array['orderid']) + ->addPaymentMethod($array['paymentmethod']) + ->addPaymentsReference($array['pasref']) + ->addHash($array['sha1hash']); + + + $request->addPaymentMethodDetails($this->denormalisePaymentMethodDetails($array)); + $request->setAutoSettle($this->denormaliseAutoSettle($array)); + + $request->setAmount($this->denormaliseAmount($array)); + $request->setComments($this->denormaliseComments($array)); + + return $request; + } + + private function denormaliseAmount(\ArrayAccess $array) + { + return $this->serializer->denormalize($array['amount'], Amount::GetClassName(), $this->format, $this->context); + } + + private function denormalisePaymentMethodDetails(\ArrayAccess $array) + { + return $this->serializer->denormalize($array['paymentmethoddetails'], PaymentMethodDetails::GetClassName(), $this->format, $this->context); + } + + private function denormaliseComments(\ArrayAccess $array) + { + $comments = $array['comments']; + + if (!isset($comments)) { + return null; + } + + $comments = new SafeArrayAccess($comments); + + $comments = $comments['comment']; + + if (!isset($comments) || !is_array($comments)) { + return null; + } + + $commentCollection = new CommentCollection(); + + foreach ($comments as $comment) { + $commentObject = new Comment(); + $commentObject->addId($comment["@id"]) + ->addComment($comment["#"]); + + $commentCollection->add($commentObject); + } + + return $commentCollection; + } + + private function denormaliseAutoSettle($array) + { + + return $this->serializer->denormalize($array['autosettle'], AutoSettle::GetClassName(), $this->format, $this->context); + } + + /** + * Checks whether the given class is supported for denormalization by this normalizer. + * + * @param mixed $data Data to denormalize from. + * @param string $type The class to which the data should be denormalized. + * @param string $format The format being deserialized from. + * + * @return bool + */ + public function supportsDenormalization($data, $type, $format = null) + { + if ($format == "xml" && $type == APMRequest::GetClassName()) { + return true; + } + + return false; + } + + /** + * Normalizes an object into a set of arrays/scalars. + * + * @param object $object object to normalize + * @param string $format format the normalization result will be encoded as + * @param array $context Context options for the normalizer + * + * @return array|string|bool|int|float|null + */ + public function normalize($object, $format = null, array $context = array()) + { + /** @var APMRequest $object */ + + $hasComments = true; + $comments = $object->getComments(); + if (is_null($comments) || $comments->getSize() == 0) { + $hasComments = false; + } else { + $comments = $comments->getComments(); + } + + + return array_filter(array( + '@timestamp' => $object->getTimestamp(), + '@type' => $object->getType(), + 'merchantid' => $object->getMerchantId(), + 'account' => $object->getAccount(), + 'orderid' => $object->getOrderId(), + 'amount' => $object->getAmount(), + 'sha1hash' => $object->getHash(), + 'comments' => $hasComments ? array('comment' => $comments) : array(), + 'pasref' => $object->getPaymentsReference(), + 'paymentmethod' => $object->getPaymentMethod(), + 'paymentmethoddetails' => $object->getPaymentMethodDetails(), + 'autosettle' => $object->getAutoSettle() + ), array(NormaliserHelper::GetClassName(), "filter_data")); + } + + /** + * Checks whether the given class is supported for normalization by this normalizer. + * + * @param mixed $data Data to normalize. + * @param string $format The format being (de-)serialized from or into. + * + * @return bool + */ + public function supportsNormalization($data, $format = null) + { + if ($format == "xml" && $data instanceof APMRequest) { + return true; + } + + return false; + } +} \ No newline at end of file diff --git a/src/main/php/com-realexpayments-remote-sdk/domain/apm/normaliser/APMResponseNormalizer.php b/src/main/php/com-realexpayments-remote-sdk/domain/apm/normaliser/APMResponseNormalizer.php new file mode 100644 index 0000000..de81744 --- /dev/null +++ b/src/main/php/com-realexpayments-remote-sdk/domain/apm/normaliser/APMResponseNormalizer.php @@ -0,0 +1,177 @@ +setTimeStamp($array['@timestamp']); + $response->setMerchantId($array['merchantid']); + $response->setAccount($array['account']); + $response->setOrderId($array['orderid']); + $response->setResult($array['result']); + $response->setMessage($array['message']); + $response->setPaymentsReference($array['pasref']); + $response->setPaymentMethod($array['paymentmethod']); + $response->setPaymentMethodDetails($this->denormalisePaymentMethodDetails($array)); + $response->setHash($array['sha1hash']); + + + return $response; + } + + private function denormalisePaymentMethodDetails($array) + { + $apmData = $array['paymentmethoddetails']; + + + if (!isset($apmData) || !is_array($apmData)) { + return null; + } + + $data = new SafeArrayAccess($apmData); + + $paymentMethodDetails = new PaymentMethodDetails(); + + + $paymentMethodDetails->addAccountHoldername($data['accountholdername']) + ->addCountry($data['country']) + ->addReturnUrl($data['redirecturl']) + ->addPaymentPurpose($data['paymentpurpose']); + + $apmBankAccountData = $apmData['bankaccount']; + if (!isset($apmBankAccountData) || !is_array($apmBankAccountData)) { + $bankAccount = new BankAccount(); + $bankAccount + ->addIban($apmBankAccountData["iban"]) + ->addBic($apmBankAccountData['bic']); + $paymentMethodDetails->addBankAccount($bankAccount); + } + + return $paymentMethodDetails; + } + + /** + * Checks whether the given class is supported for denormalization by this normalizer. + * + * @param mixed $data Data to denormalize from. + * @param string $type The class to which the data should be denormalized. + * @param string $format The format being deserialized from. + * + * @return bool + */ + public function supportsDenormalization($data, $type, $format = null) + { + if ($format == "xml" && $type == APMResponse::GetClassName()) { + return true; + } + + return false; + } + + /** + * Normalizes an object into a set of arrays/scalars. + * + * @param object $object object to normalize + * @param string $format format the normalization result will be encoded as + * @param array $context Context options for the normalizer + * + * @return array|string|bool|int|float|null + */ + public function normalize($object, $format = null, array $context = array()) + { + /** @var APMResponse $object */ + + return array_filter( + array( + '@timestamp' => $object->getTimestamp(), + 'merchantid' => $object->getMerchantId(), + 'account' => $object->getAccount(), + 'orderid' => $object->getOrderId(), + 'pasref' => $object->getPaymentsReference(), + 'paymentmethod' => $object->getPaymentMethod(), + 'result' => $object->getResult(), + 'message' => $object->getMessage(), + 'paymentmethoddetails' => $this->normalisePaymentMethodDetails($object), + 'sha1hash' => $object->getHash() + )); + } + + private function normalisePaymentMethodDetails(APMResponse $response) + { + $paymentMethodDetails = $response->getPaymentMethodDetails(); + if (is_null($paymentMethodDetails)) { + return array(); + } + + return array_filter(array( + 'bankaccount' => $this->normaliseBankAccount($response), + 'accountholdername' => $paymentMethodDetails->getAccountHoldername(), + 'country' => $paymentMethodDetails->getCountry(), + 'redirecturl' => $paymentMethodDetails->getRedirectUrl(), + 'paymentpurpose' => $paymentMethodDetails->getPaymentPurpose(), + ), array(NormaliserHelper::GetClassName(), "filter_data")); + } + + private function normaliseBankAccount(APMResponse $response) + { + $paymentMethodDetails = $response->getPaymentMethodDetails(); + if (is_null($paymentMethodDetails)) { + return array(); + } + + $bankAccount = $response->getPaymentMethodDetails()->getBankAccount(); + + if (is_null($bankAccount)) { + return array(); + } + + return array_filter(array( + 'iban' => $bankAccount->getIban(), + 'bic' => $bankAccount->getBic() + ), array(NormaliserHelper::GetClassName(), "filter_data")); + } + + /** + * Checks whether the given class is supported for normalization by this normalizer. + * + * @param mixed $data Data to normalize. + * @param string $format The format being (de-)serialized from or into. + * + * @return bool + */ + public function supportsNormalization($data, $format = null) + { + if ($format == "xml" && $data instanceof APMResponse) { + return true; + } + + return false; + } + + +} \ No newline at end of file diff --git a/src/main/php/com-realexpayments-remote-sdk/domain/apm/normaliser/PaymentMethodDetailsNormaliser.php b/src/main/php/com-realexpayments-remote-sdk/domain/apm/normaliser/PaymentMethodDetailsNormaliser.php new file mode 100644 index 0000000..05a95f8 --- /dev/null +++ b/src/main/php/com-realexpayments-remote-sdk/domain/apm/normaliser/PaymentMethodDetailsNormaliser.php @@ -0,0 +1,62 @@ + $object->getRedirectUrl(), + 'statusupdateurl' => $object->getStatusUpdateUrl(), + 'descriptor' => $object->getDescriptor(), + 'country' => $object->getCountry(), + 'accountholdername' => $object->getAccountHoldername(), + 'bankaccount' => $this->normaliseBankAccount($object->getBankAccount()), + ), array( NormaliserHelper::GetClassName(), "filter_data" ) ); + } + + private function normaliseBankAccount( BankAccount $bankAccount ) { + if ( is_null( $bankAccount ) ) { + return array(); + } + + return array_filter( array( + 'iban' => $bankAccount->getIban(), + 'bic' => $bankAccount->getBic(), + ), array( NormaliserHelper::GetClassName(), "filter_data" ) ); + } + + /** + * Checks whether the given class is supported for normalization by this normalizer. + * + * @param mixed $data Data to normalize. + * @param string $format The format being (de-)serialized from or into. + * + * @return bool + */ + public function supportsNormalization( $data, $format = null ) { + if ( $format == "xml" && $data instanceof PaymentMethodDetails ) { + return true; + } + + return false; + } +} \ No newline at end of file diff --git a/src/main/php/com-realexpayments-remote-sdk/utils/MessageType.php b/src/main/php/com-realexpayments-remote-sdk/utils/MessageType.php index acdd032..60c4da6 100644 --- a/src/main/php/com-realexpayments-remote-sdk/utils/MessageType.php +++ b/src/main/php/com-realexpayments-remote-sdk/utils/MessageType.php @@ -11,6 +11,7 @@ class MessageType extends EnumBase { const PAYMENT = "Payment"; const THREE_D_SECURE = "3DS"; + const APM = "APM"; /** * @var string The type diff --git a/src/main/php/com-realexpayments-remote-sdk/utils/XmlUtils.php b/src/main/php/com-realexpayments-remote-sdk/utils/XmlUtils.php index 5d9f678..b9eeac2 100644 --- a/src/main/php/com-realexpayments-remote-sdk/utils/XmlUtils.php +++ b/src/main/php/com-realexpayments-remote-sdk/utils/XmlUtils.php @@ -4,7 +4,11 @@ namespace com\realexpayments\remote\sdk\utils; +use com\realexpayments\remote\sdk\domain\APM\APMRequest; +use com\realexpayments\remote\sdk\domain\APM\APMResponse; +use com\realexpayments\remote\sdk\domain\APM\normaliser\APMRequestNormalizer; use com\realexpayments\remote\sdk\domain\iRequest; +use com\realexpayments\remote\sdk\domain\normaliser\normaliser\APMResponseNormalizer; use com\realexpayments\remote\sdk\domain\payment\normaliser\AddressNormaliser; use com\realexpayments\remote\sdk\domain\payment\normaliser\AmountNormalizer; use com\realexpayments\remote\sdk\domain\payment\normaliser\AutoSettleNormalizer; @@ -22,6 +26,7 @@ use com\realexpayments\remote\sdk\domain\payment\normaliser\PayerAddressNormalizer; use com\realexpayments\remote\sdk\domain\payment\normaliser\PayerNormalizer; use com\realexpayments\remote\sdk\domain\payment\normaliser\PaymentDataNormalizer; +use com\realexpayments\remote\sdk\domain\payment\normaliser\PaymentMethodDetailsNormaliser; use com\realexpayments\remote\sdk\domain\payment\normaliser\PaymentRequestNormalizer; use com\realexpayments\remote\sdk\domain\payment\normaliser\PaymentResponseNormalizer; use com\realexpayments\remote\sdk\domain\payment\normaliser\PhoneNumbersNormalizer; @@ -177,6 +182,8 @@ private static function InitialiseMarshaller() { ) ) ); $normalizers = array( + new APMRequestNormalizer(), + new APMResponseNormalizer(), new ThreeDSecureRequestNormalizer(), new ThreeDSecureResponseNormalizer(), new CommentsNormalizer(), @@ -195,6 +202,21 @@ private static function InitialiseMarshaller() { ); self::$marshallers[ MessageType::THREE_D_SECURE ] = new Serializer( $normalizers, $encoders ); + + $encoders = array( + new CustomStringXmlEncoder( 'response', array( + 'timestamp', + 'number' + ) ) + ); + + $normalizers = array( + new APMRequestNormalizer(), + new APMResponseNormalizer(), + new PaymentMethodDetailsNormaliser(), + //new ObjectNormalizer() + ); + self::$marshallers[ MessageType::APM ] = new Serializer( $normalizers, $encoders ); } private static function getRootName( $object ) { @@ -225,6 +247,15 @@ private static function getClassName( $xml, MessageType $messageType ) { return ThreeDSecureResponse::GetClassName(); } + case MessageType::APM: { + if ( self::IsRequest( $xml ) ) { + return APMRequest::GetClassName(); + + } + + return APMResponse::GetClassName(); + } + } }