category OSS
package OSS_PaymentProcessor
copyright Copyright (c) 2007 - 2012, Open Source Solutions Limited, Dublin, Ireland
license New BSD License

 Methods

Realex Payment gateway processor

__construct(array $config, \OSS_Log $logger) 

Parameters

$config

array

An associated array of realex.* parameters from application.ini

$logger

\OSS_Log

An optional instance of an OSS_Log object if you want logging

Exceptions

\OSS_PaymentProcessor_Realex_Exception

Removes a "card" from Realex's systems.

cancelCard(\Entities\RealexCard $card) : \CreditcardTrasaction

Sends a 'card-cancel-card' request to Realex which remove credit card from Realex.

This also logs the transaction into the \Entities\RealexTransaction table, and returns that object which can be queried for the request and transaction state.

If $this->_fake_transactions is true then it skips the Realex request and returns with success after performing all normal database operations as if the request was sent.

see \global\$_fake_transactions

Parameters

$card

\Entities\RealexCard

Returns

\CreditcardTrasaction$rtrans

Created a unique Relaex credit card reference ID

createCardRef(\Entities\RealexCard $card) : string
Static

All cards added to the Realex store (linked to a payer) must be uniquely identifiable with a unique key. We use the integer primary key from the \Entities\RealexCard table.

These cards are added to payers in the Realex system.

see \global\OSS_PaymentProcessor_Realex::createCreditCardRef()

Parameters

$card

\Entities\RealexCard

The instance of the \Entities\RelaexCard object

Returns

stringThe unqiue card ID

Create a unique Realex order id.

createOrderId(\Entities\RealexTrasaction $rtrans) : string
Static

Every Realex transaction must have a unique order id. We use the integer primary key of the \Entities\RealexTransaction table (which records all Realex transactions) for this.

see \Entities\RealexTransaction

Parameters

$rtrans

\Entities\RealexTrasaction

An instance of a save()'d object

Exceptions

\OSS_PaymentProcessor_Realex_Exception

Returns

stringThe unique transaction ID

Creates a unique Realex payer reference ID

createPayerRef(\Entities\Customer $customer) : string
Static

All payers that we create must be identifiable by us with a unique ID. For this we use the integer primary key from the \Etnities\Customer object.

Later this ID can be used in RealEFT transactions for recurring payments, etc.

Parameters

$customer

\Entities\Customer

The instance of the payer's \Entities\Customer object

Returns

stringThe unique payer ID

Updates a "payer" in Realex's systems.

editPayer(\Entities\RealexPayer $payer) : boolean | int

Sends a 'edit-payer' request to Realex which updates payer data in Realex.

This also logs the transaction into the \Entities\ReaelxTransaction table, and returns that object which can be queried for the request and transaction state.

If $this->_fake_transactions is true then it skips the Realex request and returns with success after performing all normal database operations as if the request was sent.

see \global\$_fake_transactions

Parameters

$payer

\Entities\RealexPayer

Returns

booleanintthe result (true on success, otherwise integer on error)

Returns with the realEx code for credit card type.

getCardType($cardType) : string

Parameters

$cardType

Returns

string

Takes money from "payer" in Realex's systems.

getMoneyFromCustomer(\Entities\RealexPayer $payer, $amount, mixed $rtrans) : bool

It's wrapper function for receiptIn function. It takes three parameters. Payer from ho it will take money, the amount of money and arrow to transaction object which will be created in receiptIn function.

function will return true or false, depends on transaction status.

An example usage is:

    $rtrans = null;
    $payer = $this->getD2Em()->getRepostory( '\\Entities\\RealexPayer' )->find( $id );
    ...

    if( $this->getPaygate()->getMoneyFromCustomer( $payer, 100, $rtrans ) )
        // do something
    else
         $result = $rtrans->getResult(); //for other actions.
see \global\self::receiptIn()

Parameters

$payer

\Entities\RealexPayer

The payer to take money

$amount

$rtrans

mixed

&$rtrans Arrow to new \Entities\RealexTransaction

Exceptions

\OSS_PaymentProcessor_Exception

Returns

bool

Returns with a YYYYmmddhhmmss format timestamp used in Realex transactions.

getTimeStamp() : string
Static

Returns

stringYYYYmmddhhmmss formated timestamp

Gives money from "payer" in Realex's systems.

giveMoneyToCustomer(\Entities\RealexPayer $payer, $amount, mixed $rtrans) : bool

It's wrapper function for paymentOut function. It takes three parameters. Payer for ho it will give money, the amount of money and arrow to transaction object which will be created in receiptIn function.

function will return true or false, depends on transaction status.

An example usage is:

    $rtrans = null;
    $payer = $this->getD2Em()->getRepostory( '\\Entities\\RealexPayer' )->find( $id );
    ...

    if( $this->getPaygate()->getMoneyFromCustomer( $payer, 100, $rtrans ) )
        // do something
    else
         $result = $rtrans->getResult(); //for other actions.
see \global\self::paymentOut()

Parameters

$payer

\Entities\RealexPayer

The payer to give money

$amount

$rtrans

mixed

&$rtrans Arrow to new \Entities\RealexTransaction

Exceptions

\OSS_PaymentProcessor_Exception

Returns

bool

Creates a new "credit card" in Realex's systems.

newCard(\Entities\RealexCard $card) : \Entities\RealexTransaction

Sends a 'card-new' request to Realex which creates a new credit card at Realex which later can be used by RealEFT for recurring payments ('receipt-in').

This also logs the transaction into the \Entities\RealexTransaction table, and returns that object which can be queried for the request and transaction state.

If $this->_fake_transactions is true then it skips the Realex request and returns with success after performing all normal database operations as if the request was sent.

see \global\$_fake_transactions

Parameters

$card

\Entities\RealexCard

The credit card object to add to Realex

Exceptions

\OSS_PaymentProcessor_Exception

Returns

\Entities\RealexTransactionThe resultant \Entities\RealexTransaction object

Creates a new "payer" in Realex's systems.

newPayer(\Entities\Realex $payer) : \Entities\RealexTransaction

Sends a 'payer-new' request to Realex which creates a new payer at Realex which later can be used by RealEFT for recurring payments ('receipt-in').

This also logs the transaction into the \Entities\RealexTransaction table, and returns that object which can be queried for the request and transaction state.

If $this->_fake_transactions is true then it skips the Realex request and returns with success after performing all normal database operations as if the request was sent.

see \global\$_fake_transactions

Parameters

$payer

\Entities\Realex

The payer who will be associated as payer in Realex

Exceptions

\OSS_PaymentProcessor_Exception

Returns

\Entities\RealexTransactionThe resultant \Entities\RealexTransaction object

Creates a new "refund" in Realex's systems.

paymentOut(\Entities\RealexCard $card, int | float $amount) : \CreditcardTransaction

Sends a 'receipt-out' request to Realex which creates a new payment at Realex.

This also logs the transaction into the \Entities\RealexTransaction table, and returns that object which can be queried for the request and transaction state.

If $this->_fake_transactions is true then it skips the Realex request and returns with success after performing all normal database operations as if the request was sent.

see \global\$_fake_transactions

Parameters

$card

\Entities\RealexCard

$amount

intfloat

the amount to be withdrawn from the card, in the biggest unit of the currency, e.g. in euro or dollar and not in cent, then conversion is made inside the method

Exceptions

\OSS_PaymentProcessor_Exception

Returns

\CreditcardTransactionThe resultant CreditcardTransaction object

Creates a new "payment" in Realex's systems.

receiptIn(\Entities\RealexCard $card, int | float $amount) : \Entities\RealexTransaction

Sends a 'receipt-in' request to Realex which creates a new payment at Realex.

This also logs the transaction into the \Entities\RealexTransaction table, and returns that object which can be queried for the request and transaction state.

If $this->_fake_transactions is true then it skips the Realex request and returns with success after performing all normal database operations as if the request was sent.

see \global\$_fake_transactions

Parameters

$card

\Entities\RealexCard

$amount

intfloat

the amount to be withdrawn from the card, in the biggest unit of the currency, e.g. in euro or dollar and not in cent, then conversion is made inside the method

Exceptions

\OSS_PaymentProcessor_Exception

Returns

\Entities\RealexTransactionThe resultant \Entities\RealexTransaction object

Updates a "credit card" in Realex's systems.

updateCard(\Entities\RealexCard $card) : boolean | int

Sends a 'update-card' request to Realex which updates credit card data in Realex.

This also logs the transaction into the \Entities\RealexTransaction table, and returns that object which can be queried for the request and transaction state.

If $this->_fake_transactions is true then it skips the Realex request and returns with success after performing all normal database operations as if the request was sent.

see \global\$_fake_transactions

Parameters

$card

\Entities\RealexCard

Returns

booleaninttrue on success, otherwise an error code

Access method for the merchant ID

getD2EM() : string
see \global\$_merchant_id

Returns

stringThe merchant ID

Access method for the merchant ID

getMerchantId() : string
see \global\$_merchant_id

Returns

stringThe merchant ID

Access method for the merchant secret

getMerchantSecret() : string
see \global\$_merchant_secret

Returns

stringThe merchant secret

Access method for the refund password

getRefundPassword() : string
see \global\$_refund_password

Returns

stringThe refund password

Takes a Realex response and returns with its response code after additional checks

_checkResponse(string $resp) 

Outside of the possible checks that Realex performs, we need to allow for one more: an invalid hash of the received XML response indicated a bad transmission / man in the middle attack.

Parameters

$resp

string

The parsed Realex XML response as an array

Set fake CreditcardTransactions entries for a complete fake transaction

_completeFakeTransation(\Entities\RealexTransaction $rtrans) : \Entities\RealexTransaction

If $this->_fake_transactions is set to true, the system will not perform any Realex requests but fake the transactions in the database meaning we:

  • set is_fake to true
  • set state to STATE_COMPLETE
  • set pasref and authcode to

<

pre>FAKETRANS

Parameters

$rtrans

\Entities\RealexTransaction

The transaction object to create the fake entries in

Returns

\Entities\RealexTransactionThe modified (and save()'d) transaction object

Log a message if we have an instance of a logger

_log(string $msg, int $pri) 

Parameters

$msg

string

The log message

$pri

int

The priority of the message (defaults: OSS_Log::DEBUG)

Parse the XML response from Realex and update the transaction object

_parseResponse(string $xml, \Entities\RealexTransaction $rtrans) : \Entities\ReleaxTransaction

This function:

  • transforms the XML response to an array
  • validates the response hash
  • updates the authcode, pasref, state and response fields of the \Entities\RealexTransaction object

Parameters

$xml

string

The XML response from Realex for processing

$rtrans

\Entities\RealexTransaction

An instance of the \Entities\RealexTransaciton object

Exceptions

\OSS_PaymentProcessor_Realex_Receipt_Exception

Returns

\Entities\ReleaxTransactionThe updated $rtrans object for fluent interface

Sends an XML formatted request to Realex using cURL

_sendRequest(\Entities\RealexTransaction $rtrans, string $reqXML) : bool

This function does the heavy lifting for sending a request to Realex and parsing and processing the reponse. Specifically:

  • creates the cURL object (and throws an exception if it cannot)
  • sends the request to Realex

    If the request fails:

    • updates the $rtrans object as STATE_FAILED or STATE_TIMEOUT
    • returns false

    If the request succeeds:

    • parses and processes the response (@see _parseResponse())
    • returns true

Parameters

$rtrans

\Entities\RealexTransaction

The instance of \Entities\RealexTransaction to send to Realex

$reqXML

string

The XML request package to send to Realex

Exceptions

\OSS_PaymentProcessor_Realex_Exception

Returns

boolTrue if the API/CGI request succeeded (IT DOES NOT MEAN THE REALEX TRANSACTION SUCCEEDED!)

 Properties

 

Valid credit/debit card types

$CARD_TYPES : array
 

An array of error strings for the ERR_RESPONSE.

$ERR_TEXT : array

.. codes

 

An array of the optional application.ini parameters (defaults set with their definitions).

$OPTIONAL_PARAMS : array
 

An array of the mandatory application.ini parameters.

$REQUIRED_PARAMS : array
   

<p>The maximum number of seconds for the cURL operation</p>

$_cgi_timeout : int
 

The CGI Url

$_cgi_url : string
 

The Doctrine2 entity manager

$_d2em : \EntityManager
 

Fake transactions allows all operations to appear to succeed including updates to local database tables but it never contacts Realex and fakes all operations.

$_fake_transactions : bool
 

For security reasons, we clear the request data from the database after a sucessful Realex API/CGI call.

$_keep_request_data : bool

Some transactions require non-stored data (e.g. credit card number) to replay a failed transaction (such as createCreditCard()) which we will store and delete when we successfully replay the transaction. Setting this to true means we don't remove it.

WARNING: Set to true only for testing!

 

An instance of OSS_Log for logging.

$_logger : \OSS_Log
 

<p>Our assigned merchant ID</p>

$_merchant_id : string
 

<p>Our assigned shared secret</p>

$_merchant_secret : string
 

<p>Our assigned refund password</p>

$_refund_password : string
 

<p>The user agent to report to the CGI</p>

$_user_agent : string

 Constants

 

CARD_TYPE_LASER

CARD_TYPE_LASER 
 

CARD_TYPE_MASTERCARD

CARD_TYPE_MASTERCARD 
 

CARD_TYPE_VISA

CARD_TYPE_VISA 
 

An error code to indicate if the response hash is invalid

ERR_RESPONSE_INVALID_HASH : integer