Plugin Directory

Changeset 803175


Ignore:
Timestamp:
11/12/2013 04:08:53 PM (12 years ago)
Author:
datenwerk
Message:

2013-11-12: Update to current mPAY24 specification
Update mPAY24 API to current version

Location:
woocommerce-mpay24-gateway/trunk
Files:
74 added
10 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • woocommerce-mpay24-gateway/trunk/MPay24/MPay24Api.php

    r696575 r803175  
    11<?php
     2/**
     3 * The MPay24Api class provides the communication functioanallity. It hold's all the sensitive data (merchant ID, SOAP password, etc) and
     4 * build the SOAP request, sent to mPAY24
     5 *
     6 * @author              mPAY24 GmbH <[email protected]>
     7 * @version             $Id: MPay24Api.php 5522 2013-06-24 13:08:35Z anna $
     8 * @filesource          MPay24Api.php
     9 * @license             http://ec.europa.eu/idabc/eupl.html EUPL, Version 1.1
     10 */
     11class MPay24Api {
     12  /**
     13   * TRUE, when you want to use the test system, and FALSE otherwise
     14   * @var               bool
     15   */
     16  private $test                   = false;
     17  /**
     18   * 'test', when you want to use the test system, and 'www' otherwise
     19   * @var               string
     20   */
     21  private $flexLINKSystem         = "test";
     22  /**
     23   * The link where the requests should be sent to
     24   *
     25   * DEFAULT : https://test.mpay24.com/app/bin/etpproxy_v14 (TEST SYSTEM)
     26   * @var               string
     27   */
     28  private $etp_url                = "https://test.mpay24.com/app/bin/etpproxy_v15";
     29  /**
     30   * The merchant ID (supported from mPAY24). 5-digit number. Begin with 9
     31   * for test system, begin with 7 for the live system.
     32   * @var               int
     33   */
     34  private $merchantid             = "9xxxx";
     35  /**
     36   * SPID (supported from mPAY24).
     37   * @var               string
     38   */
     39  private $spid                   = "";
     40  /**
     41   * The SOAP password (supproted from mPAY24)
     42   * @var               string
     43   */
     44  private $soappass               = "";
     45  /**
     46   * The flexLINK password (supproted from mPAY24)
     47   * @var               string
     48   */
     49  private $pass                   = "";
     50  /**
     51   * The fix (envelope) part of the soap xml, which is to be sent to mPAY24
     52   * @var               string
     53   */
     54  private $soap_xml               = "";
     55  /**
     56   * The host name, in case you are using proxy
     57   * @var               string
     58   */
     59  private $proxy_host             = "";
     60  /**
     61   * 4-digit port number, in case you are using proxy
     62   * @var               int
     63   */
     64  private $proxy_port             = "";
     65  /**
     66   * The whole soap-xml (envelope and body), which is to be sent to mPAY24 as request
     67   * @var               string
     68   */
     69  private $request                = "";
     70  /**
     71   * The response from mPAY24
     72   * @var               string
     73   */
     74  private $response                = "";
     75  /**
     76   * TRUE if log files are to be written, by default - FALSE
     77   * @var               bool
     78   */
     79  private $debug                  = true;
     80
     81  /**
     82   * Set the basic (mandatory) settings for the requests
     83   * @param             int                 $merchantID                   5-digit account number, supported by mPAY24
     84   *
     85   *                                                                      TEST accounts - starting with 9
     86   *
     87   *                                                                      LIVE account - starting with 7
     88   * @param             string              $soapPassword                 The webservice's password, supported by mPAY24
     89   * @param             bool                $test                         TRUE - when you want to use the TEST system
     90   *
     91   *                                                                      FALSE - when you want to use the LIVE system
     92   * @param             string              $proxyHost                    The host name in case you are behind a proxy server ("" when not)
     93   * @param             int                 $proxyPort                    4-digit port number in case you are behind a proxy server ("" when not)
     94   */
     95  public function configure($merchantID, $soapPassword, $test, $proxyHost, $proxyPort) {
    296    /**
    3      * @author              [email protected]
    4      * @version             $Id: MPay24Api.php 5294 2013-01-17 11:54:45Z anna $
    5      * @filesource          MPay24Api.php
    6      * @license             http://ec.europa.eu/idabc/eupl.html EUPL, Version 1.1
     97     * An error message, that will be displayed to the user in case you are using the LIVE system
     98     * @const           LIVE_ERROR_MSG
    799     */
    8    
    9     class MPay24Api {
    10 
    11         /**
    12          * @var         BOOLEAN                            TRUE, when you want to use the test system, and FALSE otherwise
    13          */
    14         private $test             = false;
    15         /**
    16          * @var         STRING                            The link where the requests should be sent to
    17          *
    18          *                                                 DEFAULT : https://test.mpay24.com/app/bin/etpproxy_v14 (TEST SYSTEM)
    19          */
    20         private $etp_url         = "https://test.mpay24.com/app/bin/etpproxy_v15";
    21         /**
    22          * @var         INTEGER                            The merchant ID (supported from mPAY24). 5-digit number. Begin with 9
    23          *                                                 for test system, begin with 7 for the live system.
    24          */
    25         private $merchantid         = "9xxxx";
    26         /**
    27          * @var         STRING                            The SOAP password (supproted from mPAY24)
    28          */
    29         private $soappass         = "";
    30         /**
    31          * @var         STRING                            The fix (envelope) part of the soap xml, which is to be sent to mPAY24
    32          */
    33         private $soap_xml        = "";
    34         /**
    35          * @var         STRING                            The host name, in case you are using proxy
    36          */
    37         private $proxy_host        = "";
    38         /**
    39          * @var         INTEGER                            4-digit port number, in case you are using proxy
    40          */
    41         private $proxy_port        = "";
    42         /**
    43          * @var         STRING                            The whole soap-xml (envelope and body), which is to be sent to mPAY24 as request
    44          */
    45         private $request        = "";
    46         /**
    47          * @var         STRING                            The response from mPAY24
    48          */
    49         private $response         = "";
    50         /**
    51          * @var         BOOLEAN                            TRUE if log files are to be written, by default - FALSE
    52          */
    53         private $debug         = true;
    54        
    55        
    56         /**
    57          * @abstract                                    Set the basic (mandatory) settings for the requests
    58          * @param         INTEGER                            5-digit account number, supported by mPAY24
    59          *
    60          *                                                 TEST accounts - starting with 9
    61          *
    62          *                                                 LIVE account - starting with 7
    63          * @param         STRING                            The webservice's password, supported by mPAY24
    64          * @param         BOOLEAN                            TRUE - when you want to use the TEST system
    65          *
    66          *                                                 FALSE - when you want to use the LIVE system               
    67          * @param         STRING                            The host name in case you are behind a proxy server ("" when not)
    68          * @param         INTEGER                            4-digit port number in case you are behind a proxy server ("" when not)
    69          */
    70         public function configure($merchantID, $soapPassword, $test, $proxyHost, $proxyPort) {
    71             define('LIVE_ERROR_MSG', "We are sorry, an error occured - please contact the merchant!");
    72            
    73             if ( !defined('__DIR__') ) define('__DIR__', dirname(__FILE__));
    74            
    75             $this->setMerchantID($merchantID);
    76             $this->setSoapPassword($soapPassword);
    77             $this->setSystem($test);
    78            
    79             if($proxyHost != "" && $proxyPort != "")
    80                 $this->setProxySettings($proxyHost, $proxyPort);
     100    define('LIVE_ERROR_MSG', "We are sorry, an error occured - please contact the merchant!");
     101
     102    /**
     103     * The current directory, where the script is runnig from
     104     * @const           __DIR__
     105     */
     106    if ( !defined('__DIR__') ) define('__DIR__', dirname(__FILE__));
     107
     108    $this->setMerchantID($merchantID);
     109    $this->setSoapPassword($soapPassword);
     110    $this->setSystem($test);
     111
     112    if($proxyHost != "" && $proxyPort != "")
     113      $this->setProxySettings($proxyHost, $proxyPort);
     114  }
     115
     116  /**
     117   * Set the basic (mandatory) settings for the requests
     118   * @param             string              $spid                         The SPID of your account, supported by mPAY24
     119   * @param             string              $password                     The flexLINK password, supported by mPAY24
     120   * @param             bool                $test                         TRUE - when you want to use the TEST system
     121   *
     122   *                                                                      FALSE - when you want to use the LIVE system
     123   */
     124  public function configureFlexLINK($spid, $password, $test) {
     125    /**
     126     * An error message, that will be displayed to the user in case you are using the LIVE system
     127     * @const           LIVE_ERROR_MSG
     128     */
     129    define('LIVE_ERROR_MSG', "We are sorry, an error occured - please contact the merchant!");
     130
     131    /**
     132     * The current directory, where the script is runnig from
     133     * @const           __DIR__
     134     */
     135    if ( !defined('__DIR__') ) define('__DIR__', dirname(__FILE__));
     136
     137    $this->setSPID($spid);
     138    $this->setPassword($password);
     139    $this->setFlexLINKSystem($test);
     140  }
     141
     142  /**
     143   * Get the merchant ID, which was set by the function configure($merchantID, $soapPassword, $test, $proxyHost, $proxyPort)
     144   * @return            string
     145   */
     146  public function getMerchantID() {
     147    return substr($this->merchantid, 1);
     148  }
     149
     150  /**
     151   * Get the SPID, which was set by the function configureFlexLINK($spid, $password, $test)
     152   * @return            string
     153   */
     154  public function getSPID() {
     155    return $this->spid;
     156  }
     157
     158  /**
     159   * Get the system, which should be used for flexLINK (test -> 'test' or live -> 'www')
     160   * @return            string
     161   */
     162  public function getFlexLINKSystem() {
     163    return $this->flexLINKSystem;
     164  }
     165
     166  /**
     167   * Get the url, where requests are going to be posted
     168   * @return            string
     169   */
     170  public function getEtpURL() {
     171    return $this->etp_url;
     172  }
     173
     174  /**
     175   * Get the request, which was sent to mPAY24 (in XML form)
     176   * @return            string
     177   */
     178  public function getRequest() {
     179    return $this->request;
     180  }
     181
     182  /**
     183   * Get the response from mPAY24 (in XML form)
     184   * @return            string
     185   */
     186  public function getResponse() {
     187    return $this->response;
     188  }
     189
     190  /**
     191   * Check whether a proxy is used
     192   * @return            bool
     193   */
     194  public function proxyUsed() {
     195    if($this->proxy_host != '' && $this->proxy_port != '')
     196      return true;
     197    else
     198      return false;
     199  }
     200
     201  /**
     202   * Set debug modus (FALSE by default)
     203   * @param             bool                $debug                        TRUE if is turned on, otherwise FALSE
     204   */
     205  public function setDebug($debug) {
     206    $this->debug = $debug;
     207  }
     208
     209  /**
     210   * Check whether the debug modus is turned on or off
     211   * @return            bool
     212   */
     213  public function getDebug() {
     214    return $this->debug;
     215  }
     216
     217  /**
     218   * In case the test system is used, show die with the real error message, otherwise, show the difined constant error LIVE_ERROR_MSG
     219   * @param             string              $msg                          The message, which is shown to the user
     220   */
     221  public function dieWithMsg($msg) {
     222    if($this->test)
     223      die($msg);
     224    else
     225      die(LIVE_ERROR_MSG);
     226  }
     227
     228  /**
     229   * In case the test system is used, show print the real error message, otherwise, show the difined constant error LIVE_ERROR_MSG
     230   * @param             string              $msg                          The message, which is shown to the user
     231   */
     232  public function printMsg($msg) {
     233    if($this->test)
     234      print($msg);
     235    else
     236      print(LIVE_ERROR_MSG);
     237  }
     238
     239  /**
     240   * Die with an error message, which show the path in case of read/write permission errors
     241   */
     242  public function permissionError() {
     243    $errors = error_get_last();
     244    $message = $errors['message'];
     245    $path = substr($message, strpos($message, 'fopen(')+6, strpos($message, ')')-(strpos($message, 'fopen(')+6));
     246    $this->dieWithMsg("Can't open file '$path'! Please set the needed read/write rights!");
     247  }
     248
     249  /**
     250   * Get all the payment methods, that are available for the merchant by mPAY24
     251   * @return            ListPaymentMethodsResponse
     252   */
     253  public function ListPaymentMethods() {
     254    $xml = $this->buildEnvelope();
     255    $body = $xml->getElementsByTagNameNS('http://schemas.xmlsoap.org/soap/envelope/', 'Body')->item(0);
     256
     257    $operation = $xml->createElementNS('https://www.mpay24.com/soap/etp/1.5/ETP.wsdl', 'etp:ListPaymentMethods');
     258    $operation = $body->appendChild($operation);
     259
     260    $xmlMerchantID = $xml->createElement('merchantID', substr($this->merchantid, 1));
     261    $xmlMerchantID = $operation->appendChild($xmlMerchantID);
     262
     263    $this->request  = $xml->saveXML();
     264
     265    $this->send();
     266
     267    $result = new ListPaymentMethodsResponse($this->response);
     268
     269    return $result;
     270  }
     271
     272  /**
     273   * Start a secure payment through the mPAY24 payment window -
     274   * the sensible data (credit card numbers, bank account numbers etc)
     275   * is (will be) not saved in the shop
     276   * @param             ORDER               $mdxi                         The mdxi xml, which contains the shopping cart
     277   * @return            PaymentResponse
     278   */
     279  public function SelectPayment($mdxi) {
     280    $xml = $this->buildEnvelope();
     281    $body = $xml->getElementsByTagNameNS('http://schemas.xmlsoap.org/soap/envelope/', 'Body')->item(0);
     282
     283    $operation = $xml->createElementNS('https://www.mpay24.com/soap/etp/1.5/ETP.wsdl', 'etp:SelectPayment');
     284    $operation = $body->appendChild($operation);
     285
     286    $merchantID = $xml->createElement('merchantID', substr($this->merchantid, 1));
     287    $merchantID = $operation->appendChild($merchantID);
     288
     289    $xmlMDXI = $xml->createElement('mdxi', htmlspecialchars($mdxi));
     290    $xmlMDXI = $operation->appendChild($xmlMDXI);
     291
     292    $getDataURL = $xml->createElement('getDataURL', "dummy_getDataURL");
     293    $getDataURL = $operation->appendChild($getDataURL);
     294
     295    $tid = $xml->createElement('tid', 'tid');
     296    $tid = $operation->appendChild($tid);
     297
     298    $this->request  = $xml->saveXML();
     299
     300    $this->send();
     301
     302    $result = new PaymentResponse($this->response);
     303
     304    return $result;
     305  }
     306
     307  /**
     308   * Start a secure payment using a PROFILE (mPAY24 proSAFE), supported by mPAY24 -
     309   * a customer profile (you have already created) will be used for the payment.
     310   * The payment window will not be called, the payment source (for example credit card),
     311   * which was used from the customer by the last payment will be used for the transaction.
     312   * @param             ORDER               $requestString                The order xml, which contains the shopping cart
     313   * @return            SelectPaymentResponse
     314   */
     315  public function ProfilePayment($requestString) {
     316    $xml = $this->buildEnvelope();
     317    $body = $xml->getElementsByTagNameNS('http://schemas.xmlsoap.org/soap/envelope/', 'Body')->item(0);
     318
     319    $operation = $xml->createElementNS('https://www.mpay24.com/soap/etp/1.5/ETP.wsdl', 'etp:AcceptPayment');
     320    $operation = $body->appendChild($operation);
     321
     322    $requestXML = new DOMDocument("1.0", "UTF-8");
     323    $requestXML->formatOutput = true;
     324    $requestXML->loadXML($requestString);
     325
     326    $requestNode = $requestXML->getElementsByTagName("AcceptPayment")->item(0);
     327
     328    foreach($requestNode->childNodes as $child) {
     329      $child = $xml->importNode($child, true);
     330      $operation->appendChild($child);
     331    }
     332
     333    $this->request  = $xml->saveXML();
     334
     335    $this->send();
     336
     337    $result = new PaymentResponse($this->response);
     338
     339    return $result;
     340  }
     341
     342  /**
     343   * Start a secure payment using a PayPal Express Checkout, supported by mPAY24 -
     344    * the customer doesn't need to be logged in in the shop or to give any data
     345    * (addresses or payment information), but will be redirected to the PayPal site,
     346    * and all the information from PayPal will be taken for the payment.
     347    * @param            ORDER               $requestString                The order xml, which contains the shopping cart
     348    * @return           PaymentResponse
     349    */
     350  public function ExpressCheckoutPayment($requestString) {
     351    $xml = $this->buildEnvelope();
     352    $body = $xml->getElementsByTagNameNS('http://schemas.xmlsoap.org/soap/envelope/', 'Body')->item(0);
     353
     354    $operation = $xml->createElement('etp:AcceptPayment');
     355    $operation = $body->appendChild($operation);
     356
     357    $requestXML = new DOMDocument("1.0", "UTF-8");
     358    $requestXML->formatOutput = true;
     359    $requestXML->loadXML($requestString);
     360
     361    $requestNode = $requestXML->getElementsByTagName("AcceptPayment")->item(0);
     362
     363    foreach($requestNode->childNodes as $child) {
     364      $child = $xml->importNode($child, true);
     365      $operation->appendChild($child);
     366
     367      if($child->nodeName == 'payment')
     368        $child->setAttributeNS('http://www.w3.org/2001/XMLSchema-instance' ,'xsi:type', 'etp:PaymentPAYPAL');
     369    }
     370
     371    $this->request  = $xml->saveXML();
     372
     373    $this->send();
     374
     375    $result = new PaymentResponse($this->response);
     376
     377    return $result;
     378  }
     379
     380  /**
     381   * Initialize a manual callback to mPAY24 in order to check the information provided by PayPal
     382   * @param             string              $requestString                The callback request to mPAY24
     383   * @return            PaymentResponse
     384   */
     385  public function CallbackPaypal($requestString) {
     386    $xml = $this->buildEnvelope();
     387    $body = $xml->getElementsByTagNameNS('http://schemas.xmlsoap.org/soap/envelope/', 'Body')->item(0);
     388
     389    $operation = $xml->createElement('etp:ManualCallback');
     390    $operation = $body->appendChild($operation);
     391
     392    $requestXML = new DOMDocument("1.0", "UTF-8");
     393    $requestXML->formatOutput = true;
     394    $requestXML->loadXML($requestString);
     395
     396    $requestNode = $requestXML->getElementsByTagName("AcceptPayment")->item(0);
     397
     398    foreach($requestNode->childNodes as $child) {
     399      $child = $xml->importNode($child, true);
     400      $operation->appendChild($child);
     401
     402      if($child->nodeName == 'paymentCallback')
     403        $child->setAttributeNS('http://www.w3.org/2001/XMLSchema-instance' ,'xsi:type', 'etp:CallbackPAYPAL');
     404    }
     405
     406    $this->request  = $xml->saveXML();
     407
     408    $this->send();
     409
     410    $result = new PaymentResponse($this->response);
     411
     412    return $result;
     413  }
     414
     415  /**
     416   * Clear a transaction with an amount
     417   * @param             int                 $mPAYTid                      The mPAY24 transaction ID
     418   * @param             int                 $amount                       The amount to be cleared multiplay by 100
     419   * @param             string              $currency                     3-digit ISO currency code: EUR, USD, etc
     420   * @return            ManagePaymentResponse
     421   */
     422  public function ManualClear($mPAYTid, $amount, $currency) {
     423    $xml = $this->buildEnvelope();
     424    $body = $xml->getElementsByTagNameNS('http://schemas.xmlsoap.org/soap/envelope/', 'Body')->item(0);
     425
     426    $operation = $xml->createElementNS('https://www.mpay24.com/soap/etp/1.5/ETP.wsdl', 'etp:ManualClear');
     427    $operation = $body->appendChild($operation);
     428
     429    $merchantID = $xml->createElement('merchantID', substr($this->merchantid, 1));
     430    $merchantID = $operation->appendChild($merchantID);
     431
     432    $clearingDetails = $xml->createElement('clearingDetails');
     433    $clearingDetails = $operation->appendChild($clearingDetails);
     434
     435    $xmlMPayTid = $xml->createElement('mpayTID', $mPAYTid);
     436    $xmlMPayTid = $clearingDetails->appendChild($xmlMPayTid);
     437
     438    $price = $xml->createElement('amount', $amount);
     439    $price = $clearingDetails->appendChild($price);
     440
     441    $this->request  = $xml->saveXML();
     442
     443    $this->send();
     444
     445    $result = new ManagePaymentResponse($this->response);
     446
     447    return $result;
     448  }
     449
     450  /**
     451   * Credit a transaction with an amount
     452   * @param             int                 $mPAYTid                      The mPAY24 transaction ID
     453   * @param             int                 $amount                       The amount to be credited multiplay by 100
     454   * @param             string              $currency                     3-digit ISO currency code: EUR, USD, etc
     455   * @param             string              $customer                     The name of the customer, who has paid
     456   * @return            ManagePaymentResponse
     457   */
     458  public function ManualCredit($mPAYTid, $amount, $currency, $customer) {
     459    $xml = $this->buildEnvelope();
     460    $body = $xml->getElementsByTagNameNS('http://schemas.xmlsoap.org/soap/envelope/', 'Body')->item(0);
     461
     462    $operation = $xml->createElementNS('https://www.mpay24.com/soap/etp/1.5/ETP.wsdl', 'etp:ManualCredit');
     463    $operation = $body->appendChild($operation);
     464
     465    $merchantID = $xml->createElement('merchantID', substr($this->merchantid, 1));
     466    $merchantID = $operation->appendChild($merchantID);
     467
     468    $xmlMPayTid = $xml->createElement('mpayTID', $mPAYTid);
     469    $xmlMPayTid = $operation->appendChild($xmlMPayTid);
     470
     471    $price = $xml->createElement('amount', $amount);
     472    $price = $operation->appendChild($price);
     473
     474    $this->request  = $xml->saveXML();
     475
     476    $this->send();
     477
     478    $result = new ManagePaymentResponse($this->response);
     479
     480    return $result;
     481  }
     482
     483  /**
     484   * Cancel a transaction
     485   * @param             int                 $mPAYTid                      The mPAY24 transaction ID for the transaction you want to cancel
     486   * @return            ManagePaymentResponse
     487   */
     488  public function ManualReverse($mPAYTid) {
     489    $xml = $this->buildEnvelope();
     490    $body = $xml->getElementsByTagNameNS('http://schemas.xmlsoap.org/soap/envelope/', 'Body')->item(0);
     491
     492    $operation = $xml->createElementNS('https://www.mpay24.com/soap/etp/1.5/ETP.wsdl', 'etp:ManualReverse');
     493    $operation = $body->appendChild($operation);
     494
     495    $merchantID = $xml->createElement('merchantID', substr($this->merchantid, 1));
     496    $merchantID = $operation->appendChild($merchantID);
     497
     498    $xmlMPayTid = $xml->createElement('mpayTID', $mPAYTid);
     499    $xmlMPayTid = $operation->appendChild($xmlMPayTid);
     500
     501    $this->request  = $xml->saveXML();
     502
     503    $this->send();
     504
     505    $result = new ManagePaymentResponse($this->response);
     506
     507    return $result;
     508  }
     509
     510  /**
     511   * Get all the information for a transaction, supported by mPAY24
     512   * @param             int                 $mPAYTid                      The mPAY24 transaction ID
     513   * @param             string              $tid                          The transaction ID from your shop
     514   * @return            TransactionStatusResponse
     515   */
     516  public function TransactionStatus($mPAYTid=null, $tid=null) {
     517    $xml = $this->buildEnvelope();
     518    $body = $xml->getElementsByTagNameNS('http://schemas.xmlsoap.org/soap/envelope/', 'Body')->item(0);
     519
     520    $operation = $xml->createElementNS('https://www.mpay24.com/soap/etp/1.5/ETP.wsdl', 'etp:TransactionStatus');
     521    $operation = $body->appendChild($operation);
     522
     523    $merchantID = $xml->createElement('merchantID', substr($this->merchantid, 1));
     524    $merchantID = $operation->appendChild($merchantID);
     525
     526    if($mPAYTid) {
     527      $xmlMPayTid = $xml->createElement('mpayTID', $mPAYTid);
     528      $xmlMPayTid = $operation->appendChild($xmlMPayTid);
     529    } else {
     530      $xmlTid = $xml->createElement('tid', $tid);
     531      $xmlTid = $operation->appendChild($xmlTid);
     532    }
     533
     534    $this->request  = $xml->saveXML();
     535
     536    $this->send();
     537
     538    $result = new TransactionStatusResponse($this->response);
     539
     540    return $result;
     541  }
     542
     543  /**
     544   * Encoded the parameters (AES256-CBC) for the pay link and retunr them
     545   * @param             array               $params                       The parameters, which are going to be posted to mPAY24
     546   * @return            string
     547   */
     548  public function flexLINK($params) {
     549    $paramsString = "";
     550
     551    foreach($params as $key => $value)
     552      $paramsString .= "$key=$value&";
     553
     554    $encryptedParams = $this->ssl_encrypt($this->pass, $paramsString);
     555
     556    return $encryptedParams;
     557  }
     558
     559  /**
     560   * Set the merchant ID (without 'u')
     561   * @param             string              $merchantID                   The merchant ID
     562   */
     563  private function setMerchantID($merchantID=null) {
     564    if($merchantID==null)
     565      $this->merchantid = 'u' . MERCHANT_ID;
     566    else
     567      $this->merchantid = 'u' . $merchantID;
     568  }
     569
     570  /**
     571   * Set the SPID
     572   * @param             string              $spid                         The SPID of your account, supported by mPAY24
     573   */
     574  private function setSPID($spid) {
     575    $this->spid = $spid;
     576  }
     577
     578  /**
     579   * Set the Web-Services/SOAP password
     580   * @param             string              $pass                         The SOAP password, provided by mPAY24
     581   */
     582  private function setSoapPassword($pass=null) {
     583    if(defined("SOAP_PASSWORD"))
     584      $this->soappass = SOAP_PASSWORD;
     585    else
     586      $this->soappass = $pass;
     587  }
     588
     589  /**
     590   * Set the flexLINK password
     591   * @param             string              $pass                         The flexLINK password, provided by mPAY24
     592   */
     593  private function setPassword($pass) {
     594    $this->pass = $pass;
     595  }
     596
     597  /**
     598   * Set whether the tets system (true) or the live system (false) will be used for the SOAP requests
     599   * Set the POST url
     600   *
     601   * ("https://test.mpay24.com/app/bin/etpproxy_v14" or
     602   *
     603   * "https://www.mpay24.com/app/bin/etpproxy_v14")
     604   * @param             bool                $test                         TRUE for TEST system and FALSE for LIVE system.
     605   *
     606   */
     607  private function setSystem($test=null) {
     608    if($test) {
     609      $this->test = true;
     610      $this->etp_url = "https://test.mpay24.com/app/bin/etpproxy_v15";
     611  } else {
     612    $this->test = false;
     613    $this->etp_url = "https://www.mpay24.com/app/bin/etpproxy_v15";
     614  }
     615}
     616
     617  /**
     618   * Set whether the tets system (true) or the live system (false) will be used for the flexLINK requests
     619   * @param             bool                $test                         TRUE for TEST system and FALSE for LIVE system.
     620   */
     621  private function setFlexLINKSystem($test=null) {
     622    if($test)
     623      $this->flexLINKSystem = "test";
     624    else
     625      $this->flexLINKSystem = "www";
     626  }
     627
     628  /**
     629   * Set the used proxy host and proxy port in case proxy is used
     630   * @param             string              $proxy_host                   Proxy host
     631   * @param             string              $proxy_port                   Proxy port
     632   */
     633  private function setProxySettings($proxy_host="", $proxy_port="") {
     634    if($proxy_host != "" && $proxy_port != "") {
     635      $this->proxy_host = $proxy_host;
     636      $this->proxy_port = $proxy_port;
     637    }
     638  }
     639
     640  /**
     641   * Create a DOMDocument and prepare it for SOAP request:
     642   * set Envelope, NameSpaces, create empty Body
     643   * @return            DOMDocument
     644   */
     645  private function buildEnvelope() {
     646    $this->soap_xml = new DOMDocument("1.0", "UTF-8");
     647    $this->soap_xml->formatOutput = true;
     648
     649    $envelope = $this->soap_xml->createElementNS('http://schemas.xmlsoap.org/soap/envelope/', 'soapenv:Envelope');
     650    $envelope->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xsd', 'http://www.w3.org/2001/XMLSchema');
     651    $envelope->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:etp', 'https://www.mpay24.com/soap/etp/1.5/ETP.wsdl');
     652    $envelope->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
     653    $envelope = $this->soap_xml->appendChild($envelope);
     654
     655    $body = $this->soap_xml->createElementNS('http://schemas.xmlsoap.org/soap/envelope/', 'soapenv:Body');
     656    $body = $envelope->appendChild($body);
     657
     658    return $this->soap_xml;
     659  }
     660
     661  /**
     662   * Create a curl request and send the cretaed SOAP XML
     663   */
     664  private function send() {
     665    $userAgent = 'mPAY24 PHP API $Rev: 5522 $ ($Date:: 2013-06-24 #$)';
     666
     667    $ch = curl_init($this->etp_url);
     668    curl_setopt($ch, CURLOPT_HEADER, 0);
     669    curl_setopt($ch, CURLOPT_POST, 1);
     670    curl_setopt($ch,CURLOPT_USERPWD,"$this->merchantid:$this->soappass");
     671    curl_setopt($ch,CURLOPT_USERAGENT,$userAgent);
     672    curl_setopt($ch, CURLOPT_POSTFIELDS, $this->request);
     673    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     674
     675    if($this->debug) {
     676      $fh = fopen(__DIR__."/curllog.log", 'a+') or $this->permissionError();
     677
     678      curl_setopt($ch, CURLOPT_VERBOSE, 1);
     679      curl_setopt($ch, CURLOPT_STDERR, $fh);
     680    }
     681
     682    try {
     683      curl_setopt($ch, CURLOPT_CAINFO, __DIR__.'/cacert.pem');
     684
     685      if($this->proxy_host !== '' && $this->proxy_port !== '')
     686        curl_setopt($ch, CURLOPT_PROXY, $this->proxy_host.':'.$this->proxy_port);
     687
     688      $this->response = curl_exec($ch);
     689      curl_close($ch);
     690
     691      if($this->debug)
     692        fclose($fh);
     693    } catch (Exception $e) {
     694      if($this->test)
     695        $dieMSG = "Your request couldn't be sent because of the following error:" . "\n" .
     696        curl_error($ch) . "\n" .
     697        $e->getMessage() .
     698        ' in '.$e->getFile().', line: '.
     699        $e->getLine().'.';
     700      else
     701        $dieMSG = LIVE_ERROR_MSG;
     702
     703      echo $dieMSG;
     704    }
     705  }
     706
     707  /**
     708   * Encode data (AES256-CBC) using a password
     709   * @param             string              $pass                         The password, used for the encoding
     710   * @param             string              $data                         The data, that should be encoded
     711   * @return            string
     712   */
     713  private function ssl_encrypt($pass, $data) {
     714    // Set a random salt
     715    $salt = substr(md5(mt_rand(), true), 8);
     716
     717    $block = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
     718    $pad = $block - (strlen($data) % $block);
     719
     720    $data = $data . str_repeat(chr($pad), $pad);
     721
     722    // Setup encryption parameters
     723    $td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, "", MCRYPT_MODE_CBC, "");
     724
     725    $key_len =  mcrypt_enc_get_key_size($td);
     726    $iv_len =  mcrypt_enc_get_iv_size($td);
     727
     728    $total_len = $key_len + $iv_len;
     729    $salted = '';
     730    $dx = '';
     731
     732    // Salt the key and iv
     733    while (strlen($salted) < $total_len) {
     734      $dx = md5($dx.$pass.$salt, true);
     735      $salted .= $dx;
     736    }
     737
     738    $key = substr($salted,0,$key_len);
     739    $iv = substr($salted,$key_len,$iv_len);
     740
     741    mcrypt_generic_init($td, $key, $iv);
     742    $encrypted_data = mcrypt_generic($td, $data);
     743    mcrypt_generic_deinit($td);
     744    mcrypt_module_close($td);
     745
     746    return chunk_split(base64_encode('Salted__' . $salt . $encrypted_data),32,"\r\n");
     747  }
     748}
     749
     750/**
     751 * The GeneralResponse class contains the status of a response and return code, which was delivered by mPAY24 as an answer of your request
     752 *
     753 * @author              mPAY24 GmbH <[email protected]>
     754 * @version             $Id: MPay24Api.php 5522 2013-06-24 13:08:35Z anna $
     755 * @filesource          MPay24Api.php
     756 * @license             http://ec.europa.eu/idabc/eupl.html EUPL, Version 1.1
     757 */
     758class GeneralResponse {
     759  /**
     760   * The status of the request, which was sent to mPAY24
     761   * @var               string
     762   */
     763  var $status;
     764  /**
     765   * The return code from the request, which was sent to mPAY24
     766   * @var               string
     767   */
     768  var $returnCode;
     769
     770  /**
     771   * Sets the basic values from the response from mPAY24: status and return code
     772   * @param             string              $response                     The SOAP response from mPAY24 (in XML form)
     773   */
     774  function GeneralResponse($response) {
     775    if($response != '') {
     776      $responseAsDOM = new DOMDocument();
     777      $responseAsDOM->loadXML($response);
     778
     779      if(!empty($responseAsDOM) && is_object($responseAsDOM))
     780        if(!$responseAsDOM || $responseAsDOM->getElementsByTagName('status')->length == 0 || $responseAsDOM->getElementsByTagName('returnCode')->length == 0){
     781          $this->status             = "ERROR";
     782          $this->returnCode        = urldecode($response);
     783        } else {
     784          $this->status             = $responseAsDOM->getElementsByTagName('status')->item(0)->nodeValue;
     785          $this->returnCode         = $responseAsDOM->getElementsByTagName('returnCode')->item(0)->nodeValue;
    81786        }
    82        
    83         /**
    84          * @return        STRING                            5-digit merchant ID                               
    85          */
    86         public function getMerchantID() {
    87             return substr($this->merchantid, 1);           
     787    } else {
     788      $this->status             = "ERROR";
     789      $this->returnCode         = "The response is empty! Probably your request to mPAY24 was not sent! Please see your server log for more information!";
     790    }
     791  }
     792
     793  /**
     794   * Get the status of the request, which was sent to mPAY24
     795   * @return            string
     796   */
     797  public function getStatus() {
     798    return $this->status;
     799  }
     800
     801  /**
     802   * Get the return code from the request, which was sent to mPAY24
     803   * @return            string
     804   */
     805  public function getReturnCode() {
     806    return $this->returnCode;
     807  }
     808
     809  /**
     810   * Set the status in the response, which was delivered by mPAY24
     811   * @param             string               $status                      Status
     812   */
     813  public function setStatus($status) {
     814    $this->status = $status;
     815  }
     816
     817  /**
     818   * Set the return code in the response, which was delivered by mPAY24
     819   * @param             string               $returnCode                  Return code
     820   */
     821  public function setReturnCode($returnCode) {
     822    return $this->returnCode = $returnCode;
     823  }
     824}
     825
     826/**
     827 * The PaymentResponse class contains a generalResponse object and the location(URL), which will be used for the payment session
     828 *
     829 * @author              mPAY24 GmbH <[email protected]>
     830 * @version             $Id: MPay24Api.php 5522 2013-06-24 13:08:35Z anna $
     831 * @filesource          MPay24Api.php
     832 * @license             http://ec.europa.eu/idabc/eupl.html EUPL, Version 1.1
     833 */
     834class PaymentResponse extends GeneralResponse {
     835  /**
     836   * An object, that represents the basic values from the response from mPAY24: status and return code
     837   * @var               string
     838   */
     839  var $generalResponse;
     840  /**
     841   * An URL (of the mPAY24 payment fenster), where the customer would be redirected to, in case of successfull request
     842   * @var               string
     843   */
     844  var $location;
     845
     846  /**
     847   * Sets the values for a payment from the response from mPAY24: mPAY transaction ID, error number and location (URL)
     848   * @param             string              $response                     The SOAP response from mPAY24 (in XML form)
     849   */
     850  function PaymentResponse($response) {
     851    $this->generalResponse = new GeneralResponse($response);
     852
     853    if($response != '') {
     854      $responseAsDOM = new DOMDocument();
     855      $responseAsDOM->loadXML($response);
     856
     857      if(!empty($responseAsDOM) && is_object($responseAsDOM) && $responseAsDOM->getElementsByTagName('location')->length != 0)
     858        $this->location            = $responseAsDOM->getElementsByTagName('location')->item(0)->nodeValue;
     859    } else {
     860      $this->generalResponse->setStatus("ERROR");
     861      $this->generalResponse->setReturnCode("The response is empty! Probably your request to mPAY24 was not sent! Please see your server log for more information!");
     862    }
     863  }
     864
     865  /**
     866   * Get the location (URL), returned from mPAY24
     867   * @return            string
     868   */
     869  public function getLocation(){
     870    return $this->location;
     871  }
     872
     873  /**
     874   * Get the object, that contains the basic values from the response from mPAY24: status and return code
     875   * @return            string
     876   */
     877  public function getGeneralResponse(){
     878    return $this->generalResponse;
     879  }
     880}
     881
     882/**
     883 * The ManagePaymentResponse class contains a generalResponse object and the mPAYTID and/or tid of the transaction which was managed
     884 *
     885 * @author              mPAY24 GmbH <[email protected]>
     886 * @version             $Id: MPay24Api.php 5522 2013-06-24 13:08:35Z anna $
     887 * @filesource          MPay24Api.php
     888 * @license             http://ec.europa.eu/idabc/eupl.html EUPL, Version 1.1
     889 */
     890class ManagePaymentResponse extends GeneralResponse {
     891  /**
     892   * An object, that represents the basic values from the response from mPAY24: status and return code
     893   * @var               string
     894   */
     895  var $generalResponse;
     896  /**
     897   * The mPAY transaction ID
     898   * @var               string
     899   */
     900  var $mpayTID;
     901  /**
     902   * The transaction ID of the shop
     903   * @var               string
     904   */
     905  var $tid;
     906
     907  /**
     908   * Sets the values for a payment from the response from mPAY24: mPAY transaction IDand transaction ID from the shop
     909   * @param             string              $response                     The SOAP response from mPAY24 (in XML form)
     910   */
     911  function ManagePaymentResponse($response) {
     912    $this->generalResponse = new GeneralResponse($response);
     913
     914    if($response != '') {
     915      $responseAsDOM = new DOMDocument();
     916      $responseAsDOM->loadXML($response);
     917
     918      if($responseAsDOM && $responseAsDOM->getElementsByTagName('mpayTID')->length != 0 && $responseAsDOM->getElementsByTagName('tid')->length != 0) {
     919        $this->mpayTID         = $responseAsDOM->getElementsByTagName('mpayTID')->item(0)->nodeValue;
     920        $this->tid             = $responseAsDOM->getElementsByTagName('tid')->item(0)->nodeValue;
     921      }
     922    } else {
     923      $this->generalResponse->setStatus("ERROR");
     924      $this->generalResponse->setReturnCode("The response is empty! Probably your request to mPAY24 was not sent! Please see your server log for more information!");
     925    }
     926  }
     927
     928  /**
     929   * Get the mPAY transaction ID, returned from mPAY24
     930   * @return            string
     931   */
     932  public function getMpayTID() {
     933    return $this->mpayTID;
     934  }
     935
     936  /**
     937   * Get the transaction ID of the shop, returned from mPAY24
     938   * @return            string
     939   */
     940  public function getTid() {
     941    return $this->tid;
     942  }
     943
     944  /**
     945   * Get the object, that contains the basic values from the response from mPAY24: status and return code
     946   * @return            string
     947   */
     948  public function getGeneralResponse() {
     949    return $this->generalResponse;
     950  }
     951}
     952
     953/**
     954 * The ListPaymentMethodsResponse class contains a generalResponse object and all the needed informarion for the active payment mothods (payment methods count, payment types, brands and descriptions)
     955 *
     956 * @author              mPAY24 GmbH <[email protected]>
     957 * @version             $Id: MPay24Api.php 5522 2013-06-24 13:08:35Z anna $
     958 * @filesource          MPay24Api.php
     959 * @license             http://ec.europa.eu/idabc/eupl.html EUPL, Version 1.1
     960 */
     961class ListPaymentMethodsResponse extends GeneralResponse {
     962  /**
     963   * An object, that represents the basic values from the response from mPAY24: status and return code
     964   * @var               string
     965   */
     966  var $generalResponse;
     967  /**
     968   * The count of the payment methods, which are activated by mPAY24
     969   * @var               int
     970   */
     971  var $all                        = 0;
     972  /**
     973   * A list with the payment types, activated by mPAY24
     974   * @var               array
     975   */
     976  var $pTypes                      = array();
     977  /**
     978   * A list with the brands, activated by mPAY24
     979   * @var               array
     980   */
     981  var $brands                      = array();
     982  /**
     983   * A list with the descriptions of the payment methods, activated by mPAY24
     984   * @var               array
     985   */
     986  var $descriptions                = array();
     987
     988  /**
     989   * Sets the values for a payment from the response from mPAY24: count, payment types, brands and descriptions
     990   * @param             string              $response                     The SOAP response from mPAY24 (in XML form)
     991   */
     992  function ListPaymentMethodsResponse($response) {
     993    $this->generalResponse = new GeneralResponse($response);
     994
     995    if($response != '') {
     996      $responseAsDOM = new DOMDocument();
     997      $responseAsDOM->loadXML($response);
     998
     999      if($responseAsDOM && $responseAsDOM->getElementsByTagName('all')->length != 0) {
     1000        $this->all             = $responseAsDOM->getElementsByTagName('all')->item(0)->nodeValue;
     1001
     1002        for($i = 0; $i < $this->all; $i++) {
     1003          $this->pTypes[$i] = $responseAsDOM->getElementsByTagName('pType')->item($i)->nodeValue;
     1004          $this->brands[$i] = $responseAsDOM->getElementsByTagName('brand')->item($i)->nodeValue;
     1005          $this->descriptions[$i] = $responseAsDOM->getElementsByTagName('description')->item($i)->nodeValue;
    881006        }
    89        
    90         /**
    91          * @return        STRING                            The URL where the requests are sending to                               
    92          */
    93         public function getEtpURL() {
    94             return $this->etp_url;           
     1007      }
     1008    } else {
     1009      $this->generalResponse->setStatus("ERROR");
     1010      $this->generalResponse->setReturnCode("The response is empty! Probably your request to mPAY24 was not sent! Please see your server log for more information!");
     1011    }
     1012  }
     1013
     1014  /**
     1015   * Get the count of the payment methods, returned from mPAY24
     1016   * @return            int
     1017   */
     1018  public function getAll() {
     1019    return $this->all;
     1020  }
     1021
     1022  /**
     1023   * Get the payment types, returned from mPAY24
     1024   * @return            array
     1025   */
     1026  public function getPTypes() {
     1027    return $this->pTypes;
     1028  }
     1029
     1030  /**
     1031   * Get the brands, returned from mPAY24
     1032   * @return            array
     1033   */
     1034  public function getBrands() {
     1035    return $this->brands;
     1036  }
     1037
     1038  /**
     1039   * Get the descriptions, returned from mPAY24
     1040   * @return            array
     1041   */
     1042  public function getDescriptions() {
     1043    return $this->descriptions;
     1044  }
     1045
     1046  /**
     1047   * Get payment type, returned from mPAY24
     1048   * @param             int                 $i                            The index of a payment type
     1049   * @return            string
     1050   */
     1051  public function getPType($i) {
     1052    return $this->pTypes[$i];
     1053  }
     1054
     1055  /**
     1056   * Get brand, returned from mPAY24
     1057   * @param             int                 $i                            The index of a brand
     1058   * @return            string
     1059   */
     1060  public function getBrand($i) {
     1061    return $this->brands[$i];
     1062  }
     1063
     1064  /**
     1065   * Get description, returned from mPAY24
     1066   * @param             int                 $i                            The index of a description
     1067   * @return            string
     1068   */
     1069  public function getDescription($i) {
     1070    return $this->descriptions[$i];
     1071  }
     1072
     1073  /**
     1074   * Get the object, that contains the basic values from the response from mPAY24: status and return code
     1075   * @return            string
     1076   */
     1077  public function getGeneralResponse() {
     1078    return $this->generalResponse;
     1079  }
     1080}
     1081
     1082/**
     1083 * The TransactionStatusResponse class contains a generalResponse object and all the parameters, returned with the confirmation from mPAY24
     1084 *
     1085 * @author              mPAY24 GmbH <[email protected]>
     1086 * @version             $Id: MPay24Api.php 5522 2013-06-24 13:08:35Z anna $
     1087 * @filesource          MPay24Api.php
     1088 * @license             http://ec.europa.eu/idabc/eupl.html EUPL, Version 1.1
     1089 */
     1090class TransactionStatusResponse extends GeneralResponse {
     1091  /**
     1092   * An object, that represents the basic values from the response from mPAY24: status and return code
     1093   * @var               string
     1094   */
     1095  var $generalResponse;
     1096  /**
     1097   * A list with all the parameters for a transaction
     1098   * @var               array
     1099   */
     1100  var $params                     = array();
     1101  /**
     1102   * The count of all the paramerters for a transaction
     1103   * @var               int
     1104   */
     1105  var $paramCount                 = 0;
     1106
     1107  /**
     1108   * Sets the values for a transaction from the response from mPAY24: STATUS, PRICE, CURRENCY, LANGUAGE, etc
     1109   * @param             string              $response                     The SOAP response from mPAY24 (in XML form)
     1110   */
     1111  function TransactionStatusResponse($response) {
     1112    $this->generalResponse = new GeneralResponse($response);
     1113
     1114    if($response != '') {
     1115      $responseAsDOM = new DOMDocument();
     1116      $responseAsDOM->loadXML($response);
     1117
     1118      if($responseAsDOM && $responseAsDOM->getElementsByTagName('name')->length != 0) {
     1119        $this->paramCount = $responseAsDOM->getElementsByTagName('name')->length;
     1120        $this->params['STATUS'] = $this->generalResponse->getStatus();
     1121
     1122        for($i = 0; $i < $this->paramCount; $i++){
     1123          if($responseAsDOM->getElementsByTagName("name")->item($i)->nodeValue == "STATUS")
     1124            $this->params["TSTATUS"] = $responseAsDOM->getElementsByTagName("value")->item($i)->nodeValue;
     1125          else
     1126            $this->params[$responseAsDOM->getElementsByTagName('name')->item($i)->nodeValue]
     1127                                          = $responseAsDOM->getElementsByTagName('value')->item($i)->nodeValue;
    951128        }
    96        
    97         /**
    98          * @return        STRING                            The request, which was sent to mPAY24 (in XML form)
    99          */
    100         public function getRequest() {
    101             return $this->request;
    102         }
    103 
    104         /**
    105          * @return        STRING                            The response from mPAY24 (in XML form)
    106          */
    107         public function getResponse() {
    108             return $this->response;
    109         }
    110        
    111         /**
    112          * @return        BOOLEAN                            Whether a proxy is used
    113          */
    114         public function proxyUsed() {
    115             if($this->proxy_host != '' && $this->proxy_port != '')
    116                 return true;
    117             else
    118                 return false;
    119         }
    120        
    121         /**
    122          * @abstract                                    Set debug modus (FALSE by default)
    123          * @param         BOOLEAN                       TRUE if is turned on, otherwise FALSE
    124          */
    125         public function setDebug($debug) {
    126             $this->debug = $debug;     
    127         }
    128        
    129         /**
    130          * @return        BOOLEAN                            Whether the debug modus is turned on or off
    131          */
    132         public function getDebug() {
    133             return $this->debug;
    134         }
    135        
    136         public function dieWithMsg($msg) {
    137             if($this->test)
    138                 die($msg);
    139             else
    140                 die(LIVE_ERROR_MSG);
    141         }
    142        
    143         public function printMsg($msg) {
    144             if($this->test)
    145                 print($msg);
    146             else
    147                 print(LIVE_ERROR_MSG);
    148         }
    149        
    150         public function permissionError() {
    151             $errors = error_get_last();
    152             $message = $errors['message'];
    153             $path = substr($message, strpos($message, 'fopen(')+6, strpos($message, ')')-(strpos($message, 'fopen(')+6));
    154             $this->dieWithMsg("Can't open file '$path'! Please set the needed read/write rights!");
    155         }
    156        
    157         /**
    158          * @abstract                                    Get all the payment methods, that are available for the merchant by mPAY24
    159          * @uses        ListPaymentMethodsResponse
    160          * @return        ListPaymentMethodsResponse
    161          */
    162         public function ListPaymentMethods() {
    163             $xml = $this->buildEnvelope();
    164             $body = $xml->getElementsByTagNameNS('http://schemas.xmlsoap.org/soap/envelope/', 'Body')->item(0);
    165              
    166             $operation = $xml->createElementNS('https://www.mpay24.com/soap/etp/1.5/ETP.wsdl', 'etp:ListPaymentMethods');
    167             $operation = $body->appendChild($operation);
    168            
    169             $xmlMerchantID = $xml->createElement('merchantID', substr($this->merchantid, 1));
    170             $xmlMerchantID = $operation->appendChild($xmlMerchantID);
    171            
    172             $this->request  = $xml->saveXML();
    173            
    174             $this->send();
    175            
    176             $result = new ListPaymentMethodsResponse($this->response);
    177 
    178             return $result;
    179         }
    180        
    181         /**
    182          * @abstract                                    Start a secure payment through the mPAY24 payment window -
    183          *                                                 the sensible data (credit card numbers, bank account numbers etc)
    184          *                                                 is (will be) not saved in the shop
    185          * @uses        PaymentResponse
    186          * @param         ORDER                             The mdxi xml, which contains the shopping cart
    187          * @return        PaymentResponse
    188          */
    189         public function SelectPayment($mdxi) {
    190             $xml = $this->buildEnvelope();
    191             $body = $xml->getElementsByTagNameNS('http://schemas.xmlsoap.org/soap/envelope/', 'Body')->item(0);
    192              
    193             $operation = $xml->createElementNS('https://www.mpay24.com/soap/etp/1.5/ETP.wsdl', 'etp:SelectPayment');
    194             $operation = $body->appendChild($operation);
    195            
    196             $merchantID = $xml->createElement('merchantID', substr($this->merchantid, 1));
    197             $merchantID = $operation->appendChild($merchantID);
    198        
    199             $xmlMDXI = $xml->createElement('mdxi', htmlspecialchars($mdxi));
    200             $xmlMDXI = $operation->appendChild($xmlMDXI);   
    201 
    202             $getDataURL = $xml->createElement('getDataURL', "dummy_getDataURL");
    203             $getDataURL = $operation->appendChild($getDataURL);   
    204            
    205             $tid = $xml->createElement('tid', 'tid');
    206             $tid = $operation->appendChild($tid);
    207 
    208             $this->request  = $xml->saveXML();
    209            
    210             $this->send();
    211            
    212             $result = new PaymentResponse($this->response);
    213                        
    214             return $result;
    215         }
    216        
    217         /**
    218          * @abstract                                    Start a secure payment using a PROFILE (mPAY24 proSAFE), supported by mPAY24 -
    219          *                                                 a customer profile (you have already created) will be used for the payment.
    220          *                                                 The payment window will not be called, the payment source (for example credit card),
    221          *                                                 which was used from the customer by the last payment will be used for the transaction. 
    222          * @uses        PaymentResponse
    223          * @param         ORDER                            The order xml, which contains the shopping cart
    224          * @return        SelectPaymentResponse
    225          */
    226         public function ProfilePayment($requestString) {
    227             $xml = $this->buildEnvelope();
    228             $body = $xml->getElementsByTagNameNS('http://schemas.xmlsoap.org/soap/envelope/', 'Body')->item(0);
    229 
    230             $operation = $xml->createElementNS('https://www.mpay24.com/soap/etp/1.5/ETP.wsdl', 'etp:AcceptPayment');
    231             $operation = $body->appendChild($operation);
    232            
    233             $requestXML = new DOMDocument("1.0", "UTF-8");
    234             $requestXML->formatOutput = true;
    235             $requestXML->loadXML($requestString);
    236 
    237             $requestNode = $requestXML->getElementsByTagName("AcceptPayment")->item(0);
    238            
    239             foreach($requestNode->childNodes as $child) {
    240                 $child = $xml->importNode($child, true);
    241                 $operation->appendChild($child);
    242             }
    243 
    244             $this->request  = $xml->saveXML();
    245            
    246             $this->send();
    247            
    248             $result = new PaymentResponse($this->response);
    249 
    250             return $result;
    251         }
    252        
    253         /**
    254          * @abstract                                    Start a secure payment using a PayPal Express Checkout, supported by mPAY24 -
    255          *                                                 the customer doesn't need to be logged in in the shop or to give any data
    256          *                                                 (addresses or payment information), but will be redirected to the PayPal site,
    257          *                                                 and all the information from PayPal will be taken for the payment.
    258          * @uses        PaymentResponse
    259          * @param         ORDER                            The order xml, which contains the shopping cart
    260          * @return        PaymentResponse
    261          */
    262         public function ExpressCheckoutPayment($requestString) {
    263             $xml = $this->buildEnvelope();
    264             $body = $xml->getElementsByTagNameNS('http://schemas.xmlsoap.org/soap/envelope/', 'Body')->item(0);
    265              
    266             $operation = $xml->createElement('etp:AcceptPayment');
    267             $operation = $body->appendChild($operation);
    268            
    269             $requestXML = new DOMDocument("1.0", "UTF-8");
    270             $requestXML->formatOutput = true;
    271             $requestXML->loadXML($requestString);
    272 
    273             $requestNode = $requestXML->getElementsByTagName("AcceptPayment")->item(0);
    274            
    275             foreach($requestNode->childNodes as $child) {
    276                 $child = $xml->importNode($child, true);
    277                 $operation->appendChild($child);
    278                 if($child->nodeName == 'payment') {
    279                     $child->setAttributeNS('http://www.w3.org/2001/XMLSchema-instance' ,'xsi:type', 'etp:PaymentPAYPAL');
    280                 }
    281             }
    282            
    283             $this->request  = $xml->saveXML();
    284            
    285             $this->send();
    286            
    287             $result = new PaymentResponse($this->response);
    288 
    289             return $result;
    290         }
    291        
    292         /**
    293          * @uses        PaymentResponse                           
    294          * @param         STRING                            5-digit account number, supported by mPAY24
    295          * @param         STRING                            The transaction ID, supported from mPAY24
    296          * @param         INTEGER                            The positive shipping costs for the transaction multiply by 100
    297          * @param         INTEGER                            The positive amount to be reserved/billed multiply by 100
    298          * @param        STRING                            In case of "true", the transaction will be canceled, in case of "false" the amount will be reserved
    299          * @return        PaymentResponse
    300          */
    301         public function CallbackPaypal($requestString) {
    302             $xml = $this->buildEnvelope();
    303             $body = $xml->getElementsByTagNameNS('http://schemas.xmlsoap.org/soap/envelope/', 'Body')->item(0);
    304              
    305             $operation = $xml->createElement('etp:ManualCallback');
    306             $operation = $body->appendChild($operation);
    307            
    308             $requestXML = new DOMDocument("1.0", "UTF-8");
    309             $requestXML->formatOutput = true;
    310             $requestXML->loadXML($requestString);
    311            
    312             $requestNode = $requestXML->getElementsByTagName("AcceptPayment")->item(0);
    313            
    314             foreach($requestNode->childNodes as $child) {
    315                 $child = $xml->importNode($child, true);
    316                 $operation->appendChild($child);
    317                 if($child->nodeName == 'paymentCallback') {
    318                     $child->setAttributeNS('http://www.w3.org/2001/XMLSchema-instance' ,'xsi:type', 'etp:CallbackPAYPAL');
    319                 }
    320             }
    321            
    322             $this->request  = $xml->saveXML();
    323            
    324             $this->send();
    325            
    326             $result = new PaymentResponse($this->response);
    327 
    328             return $result;
    329            
    330         }
    331        
    332         /**
    333          * @abstract                                    Clear a transaction with an amount
    334          * @uses        ManagePaymentResponse
    335          * @param         INTEGER                         The mPAY24 transaction ID
    336          * @param         INTEGER                            The amount to be cleared multiplay by 100
    337          * @param         STRING                            3-digit ISO currency code: EUR, USD, etc
    338          * @return        ManagePaymentResponse           
    339          */
    340         public function ManualClear($mPAYTid, $amount, $currency) {
    341             $xml = $this->buildEnvelope();
    342             $body = $xml->getElementsByTagNameNS('http://schemas.xmlsoap.org/soap/envelope/', 'Body')->item(0);
    343              
    344             $operation = $xml->createElementNS('https://www.mpay24.com/soap/etp/1.5/ETP.wsdl', 'etp:ManualClear');
    345             $operation = $body->appendChild($operation);
    346            
    347             $merchantID = $xml->createElement('merchantID', substr($this->merchantid, 1));
    348             $merchantID = $operation->appendChild($merchantID);
    349        
    350             $clearingDetails = $xml->createElement('clearingDetails');
    351             $clearingDetails = $operation->appendChild($clearingDetails);
    352            
    353             $xmlMPayTid = $xml->createElement('mpayTID', $mPAYTid);
    354             $xmlMPayTid = $clearingDetails->appendChild($xmlMPayTid);
    355            
    356             $price = $xml->createElement('amount', $amount);
    357             $price = $clearingDetails->appendChild($price);
    358            
    359             $this->request  = $xml->saveXML();
    360            
    361             $this->send();
    362 
    363             $result = new ManagePaymentResponse($this->response);
    364 
    365             return $result;
    366         }
    367        
    368         /**
    369          * @abstract                                    Credit a transaction with an amount
    370          * @uses        ManagePaymentResponse
    371          * @param         INTEGER                         The mPAY24 transaction ID
    372          * @param         INTEGER                            The amount to be credited multiplay by 100
    373          * @param         STRING                            3-digit ISO currency code: EUR, USD, etc
    374          * @param         STRING                            The name of the customer, who has paid
    375          * @return        ManagePaymentResponse           
    376          */
    377         public function ManualCredit($mPAYTid, $amount, $currency, $customer) {
    378             $xml = $this->buildEnvelope();
    379             $body = $xml->getElementsByTagNameNS('http://schemas.xmlsoap.org/soap/envelope/', 'Body')->item(0);
    380              
    381             $operation = $xml->createElementNS('https://www.mpay24.com/soap/etp/1.5/ETP.wsdl', 'etp:ManualCredit');
    382             $operation = $body->appendChild($operation);
    383            
    384             $merchantID = $xml->createElement('merchantID', substr($this->merchantid, 1));
    385             $merchantID = $operation->appendChild($merchantID);   
    386            
    387             $xmlMPayTid = $xml->createElement('mpayTID', $mPAYTid);
    388             $xmlMPayTid = $operation->appendChild($xmlMPayTid);   
    389            
    390             $price = $xml->createElement('amount', $amount);
    391             $price = $operation->appendChild($price);
    392            
    393             $this->request  = $xml->saveXML();
    394            
    395             $this->send();
    396 
    397             $result = new ManagePaymentResponse($this->response);
    398 
    399             return $result;
    400         }
    401        
    402         /**
    403          * @abstract                                    Cancel a transaction
    404          * @uses        ManagePaymentResponse
    405          * @param         INTEGER                         The mPAY24 transaction ID for the transaction you want to cancel
    406          * @return        ManagePaymentResponse           
    407          */
    408         public function ManualReverse($mPAYTid) {
    409             $xml = $this->buildEnvelope();
    410             $body = $xml->getElementsByTagNameNS('http://schemas.xmlsoap.org/soap/envelope/', 'Body')->item(0);
    411              
    412             $operation = $xml->createElementNS('https://www.mpay24.com/soap/etp/1.5/ETP.wsdl', 'etp:ManualReverse');
    413             $operation = $body->appendChild($operation);
    414            
    415             $merchantID = $xml->createElement('merchantID', substr($this->merchantid, 1));
    416             $merchantID = $operation->appendChild($merchantID);   
    417            
    418             $xmlMPayTid = $xml->createElement('mpayTID', $mPAYTid);
    419             $xmlMPayTid = $operation->appendChild($xmlMPayTid);       
    420            
    421             $this->request  = $xml->saveXML();
    422            
    423             $this->send();
    424            
    425             $result = new ManagePaymentResponse($this->response);
    426 
    427             return $result;
    428         }
    429        
    430         /**
    431          * @abstract                                    Get all the information for a transaction, supported by mPAY24
    432          * @uses        TransactionStatusResponse
    433          * @param         INTEGER                         The mPAY24 transaction ID
    434          * @param         STRING                            The transaction ID from your shop
    435          * @return        TransactionStatusResponse
    436          */
    437         public function TransactionStatus($mPAYTid=null, $tid=null) {
    438             $xml = $this->buildEnvelope();
    439             $body = $xml->getElementsByTagNameNS('http://schemas.xmlsoap.org/soap/envelope/', 'Body')->item(0);
    440              
    441             $operation = $xml->createElementNS('https://www.mpay24.com/soap/etp/1.5/ETP.wsdl', 'etp:TransactionStatus');
    442             $operation = $body->appendChild($operation);
    443            
    444             $merchantID = $xml->createElement('merchantID', substr($this->merchantid, 1));
    445             $merchantID = $operation->appendChild($merchantID);
    446        
    447             if($mPAYTid) {                   
    448                 $xmlMPayTid = $xml->createElement('mpayTID', $mPAYTid);
    449                 $xmlMPayTid = $operation->appendChild($xmlMPayTid);
    450             } else {
    451                 $xmlTid = $xml->createElement('tid', $tid);
    452                 $xmlTid = $operation->appendChild($xmlTid);
    453             }
    454            
    455             $this->request  = $xml->saveXML();
    456            
    457             $this->send();
    458 
    459             $result = new TransactionStatusResponse($this->response);
    460 
    461             return $result;
    462         }
    463    
    464         /**
    465          * @param         STRING: (without 'u')
    466          */
    467         private function setMerchantID($merchantID=null) {
    468             if($merchantID==null)
    469                $this->merchantid = 'u' . MERCHANT_ID;
    470             else
    471                 $this->merchantid = 'u' . $merchantID;
    472         }
    473        
    474         /**
    475          * @param         STRING
    476          */
    477         private function setSoapPassword($pass=null) {
    478             if(defined("SOAP_PASSWORD"))
    479                 $this->soappass = SOAP_PASSWORD;
    480             else
    481                 $this->soappass = $pass;
    482         }   
    483 
    484         /**
    485          * @abstract                                    Set if the system is test (true) or not (false)
    486          *
    487          *                                                 Set the POST url
    488          *                                                 ("https://test.mpay24.com/app/bin/etpproxy_v14" or
    489          *                                                 "https://www.mpay24.com/app/bin/etpproxy_v14")
    490          * @param         BOOLEAN
    491          *                     
    492          */
    493         private function setSystem($test=null) {
    494             if($test) {
    495                $this->test = true;
    496                $this->etp_url = "https://test.mpay24.com/app/bin/etpproxy_v15";
    497             } else {
    498                 $this->test = false;
    499                 $this->etp_url = "https://www.mpay24.com/app/bin/etpproxy_v15";
    500             }
    501         }
    502        
    503         /**
    504          * @abstract                                    Set the used proxy host and proxy port in case proxy is used
    505          * @param        STRING
    506          * @param        STRING
    507          */
    508         private function setProxySettings($proxy_host="", $proxy_port="") {
    509             if($proxy_host != "" && $proxy_port != "") {
    510                $this->proxy_host = $proxy_host;
    511                $this->proxy_port = $proxy_port;
    512             }
    513         }
    514        
    515         /**
    516          * @abstract                                    Create a DOMDocument and prepare it for SOAP request:
    517          *
    518          *                                                 set Envelope, NameSpaces, create empty Body
    519          * @return        DOMDocument
    520          */
    521         private function buildEnvelope() {
    522             $this->soap_xml = new DOMDocument("1.0", "UTF-8");
    523             $this->soap_xml->formatOutput = true;
    524            
    525             $envelope = $this->soap_xml->createElementNS('http://schemas.xmlsoap.org/soap/envelope/', 'soapenv:Envelope');
    526             $envelope->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xsd', 'http://www.w3.org/2001/XMLSchema');
    527             $envelope->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:etp', 'https://www.mpay24.com/soap/etp/1.5/ETP.wsdl');
    528             $envelope->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
    529             $envelope = $this->soap_xml->appendChild($envelope);
    530            
    531             $body = $this->soap_xml->createElementNS('http://schemas.xmlsoap.org/soap/envelope/', 'soapenv:Body');
    532             $body = $envelope->appendChild($body);
    533 
    534             return $this->soap_xml;
    535         }
    536 
    537         /**
    538           * @uses        buildXMLRequest()
    539           * @abstract                                    Create a curl request and send the cretaed SOAP XML
    540           */
    541         private function send() {
    542             $userAgent = 'mPAY24 PHP API $Rev: 5294 $ ($Date:: 2013-01-17 #$)';
    543    
    544             $ch = curl_init($this->etp_url);
    545             curl_setopt($ch, CURLOPT_HEADER, 0);
    546             curl_setopt($ch, CURLOPT_POST, 1);
    547             curl_setopt($ch,CURLOPT_USERPWD,"$this->merchantid:$this->soappass");
    548             curl_setopt($ch,CURLOPT_USERAGENT,$userAgent);
    549             curl_setopt($ch, CURLOPT_POSTFIELDS, $this->request);
    550             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    551 
    552             if($this->debug) {
    553               $fh = fopen(__DIR__."/curllog.log", 'a+') or $this->permissionError();
    554                    
    555               curl_setopt($ch, CURLOPT_VERBOSE, 1);
    556               curl_setopt($ch, CURLOPT_STDERR, $fh);
    557             }
    558            
    559             try {
    560                 curl_setopt($ch, CURLOPT_CAINFO, __DIR__.'/cacert.pem');
    561                
    562                 if($this->proxy_host !== '' && $this->proxy_port !== '')
    563                     curl_setopt($ch, CURLOPT_PROXY, $this->proxy_host.':'.$this->proxy_port);
    564                    
    565                 $this->response = curl_exec($ch);
    566                 curl_close($ch); 
    567                 if($this->debug)
    568                     fclose($fh);
    569             } catch (Exception $e) {
    570                 if($this->test)
    571                    $dieMSG = "Your request couldn't be sent because of the following error:" . "\n" .
    572                              curl_error($ch) . "\n" .
    573                              $e->getMessage() .
    574                              ' in '.$e->getFile().', line: '.
    575                             $e->getLine().'.';
    576                 else
    577                     $dieMSG = LIVE_ERROR_MSG;
    578                
    579                 echo $dieMSG;
    580             }
    581          }
    582     }
    583    
    584    
    585    
    586     class GeneralResponse {
    587        
    588         /**
    589          * @var         STRING                            The status of the request, which was sent to mPAY24
    590          */
    591         var $status;
    592         /**
    593          *
    594          * @var         STRING                            The return code from the request, which was sent to mPAY24
    595          */
    596         var $returnCode;
    597        
    598         /**
    599          * @abstract                                    Sets the basic values from the response from mPAY24: status and return code
    600          * @param         STRING                            The SOAP response from mPAY24 (in XML form)
    601          */
    602         function GeneralResponse($response) {
    603             if($response != '') {
    604                         $responseAsDOM = new DOMDocument();
    605               $responseAsDOM->loadXML($response);
    606                
    607               if(!empty($responseAsDOM) && is_object($responseAsDOM))
    608                 if(!$responseAsDOM || $responseAsDOM->getElementsByTagName('status')->length == 0 || $responseAsDOM->getElementsByTagName('returnCode')->length == 0){
    609                     $this->status             = "ERROR";
    610                     $this->returnCode        = urldecode($response);
    611                 } else {
    612                     $this->status             = $responseAsDOM->getElementsByTagName('status')->item(0)->nodeValue;
    613                     $this->returnCode         = $responseAsDOM->getElementsByTagName('returnCode')->item(0)->nodeValue;
    614                 }   
    615             } else {
    616                 $this->status             = "ERROR";
    617               $this->returnCode         = "The response is empty! Probably your request to mPAY24 was not sent! Please see your server log for more information!";
    618             }       
    619         }
    620        
    621         /**
    622          * @return        STRING                            The status of the request, which was sent to mPAY24
    623          */
    624         public function getStatus() {
    625             return $this->status;
    626         }
    627        
    628         /**
    629          * @return        STRING                            The return code from the request, which was sent to mPAY24
    630          */
    631         public function getReturnCode() {
    632             return $this->returnCode;
    633         }
    634 
    635         public function setStatus($status) {
    636             $this->status = $status;
    637         }
    638 
    639         public function setReturnCode($returnCode) {
    640             return $this->returnCode = $returnCode;
    641         }
    642        
    643     }
    644    
    645     class PaymentResponse extends GeneralResponse {
    646        
    647         /**
    648          * @var         GeneralResponse                    An object, that represents the basic values from the response from mPAY24:
    649          *                                                 status and return code
    650          */
    651         var $generalResponse;
    652 
    653         /**
    654          * @var         STRING                            An URL (of the mPAY24 payment fenster), where the customer would be redirected to,
    655          *                                                 in case of successfull request
    656          */
    657         var $location;
    658        
    659        
    660         /**
    661          * @abstract                                    Sets the values for a payment from the response from mPAY24:
    662          *                                                 mPAY transaction ID, error number and location (URL)
    663          * @param         STRING                            The SOAP response from mPAY24 (in XML form)
    664          */
    665         function PaymentResponse($response) {
    666             $this->generalResponse = new GeneralResponse($response);
    667             if($response != '') {   
    668                             $responseAsDOM = new DOMDocument();
    669                 $responseAsDOM->loadXML($response);
    670                
    671                 if(!empty($responseAsDOM) && is_object($responseAsDOM) && $responseAsDOM->getElementsByTagName('location')->length != 0)       
    672                     $this->location            = $responseAsDOM->getElementsByTagName('location')->item(0)->nodeValue;
    673              } else {
    674                 $this->generalResponse->setStatus("ERROR");
    675                 $this->generalResponse->setReturnCode("The response is empty! Probably your request to mPAY24 was not sent! Please see your server log for more information!");
    676             }   
    677         }
    678        
    679         /**
    680          * @return        STRING                            The location (URL), returned from mPAY24
    681          */
    682         public function getLocation(){
    683             return $this->location;
    684         }
    685        
    686         /**
    687          * @return        GeneralResponse                    The object, that contains the basic values from the response from mPAY24:
    688          *                                                 status and return code
    689          */
    690         public function getGeneralResponse(){
    691             return $this->generalResponse;
    692         }
    693     }
    694    
    695     class ManagePaymentResponse extends GeneralResponse {
    696        
    697         /**
    698          * @var         GeneralResponse                    An object, that represents the basic values from the response from mPAY24:
    699          *                                                 status and return code
    700          */
    701         var $generalResponse;
    702         /**
    703          * @var         STRING                            The mPAY transaction ID
    704          */
    705         var $mpayTID;
    706         /**
    707          * @var         STRING                            The transaction ID of the shop
    708          */
    709         var $tid;
    710        
    711         /**
    712          * @abstract                                    Sets the values for a payment from the response from mPAY24:
    713          *                                                 mPAY transaction IDand transaction ID from the shop
    714          * @param         STRING                            The SOAP response from mPAY24 (in XML form)
    715          */
    716         function ManagePaymentResponse($response) {
    717             $this->generalResponse = new GeneralResponse($response);
    718            
    719             if($response != '') {
    720                 $responseAsDOM = new DOMDocument();
    721                 $responseAsDOM->loadXML($response);
    722                
    723                 if($responseAsDOM && $responseAsDOM->getElementsByTagName('mpayTID')->length != 0 && $responseAsDOM->getElementsByTagName('tid')->length != 0) {       
    724                     $this->mpayTID         = $responseAsDOM->getElementsByTagName('mpayTID')->item(0)->nodeValue;
    725                     $this->tid             = $responseAsDOM->getElementsByTagName('tid')->item(0)->nodeValue;
    726                 }
    727             } else {
    728                 $this->generalResponse->setStatus("ERROR");
    729                 $this->generalResponse->setReturnCode("The response is empty! Probably your request to mPAY24 was not sent! Please see your server log for more information!");
    730             }   
    731         }
    732        
    733         /**
    734          * @return        STRING                            The mPAY transaction ID, returned from mPAY24
    735          */
    736         public function getMpayTID() {
    737             return $this->mpayTID;
    738         }
    739        
    740         /**
    741          * @return        STRING                            The transaction ID of the shop, returned from mPAY24
    742          */
    743         public function getTid() {
    744             return $this->tid;
    745         }
    746        
    747         /**
    748          * @return        GeneralResponse                    The object, that contains the basic values from the response from mPAY24:
    749          *                                                 status and return code
    750          */
    751         public function getGeneralResponse() {
    752             return $this->generalResponse;
    753         }
    754     }
    755    
    756     class ListPaymentMethodsResponse extends GeneralResponse {
    757        
    758         /**
    759          * @var         GeneralResponse                    An object, that represents the basic values from the response from mPAY24:
    760          *                                                 status and return code
    761          */
    762         var $generalResponse;
    763         /**
    764          * @var         INTEGER                            The count of the payment methods, which are activated by mPAY24
    765          */
    766         var $all                        = 0;
    767         /**
    768          * @var         ARRAY                            A list with the payment types, activated by mPAY24
    769          */
    770         var $pTypes                    = array();
    771         /**
    772          * @var         ARRAY                            A list with the brands, activated by mPAY24
    773          */
    774         var $brands                    = array();
    775         /**
    776          * @var         ARRAY                            A list with the descriptions of the payment methods, activated by mPAY24
    777          */
    778         var $descriptions            = array();
    779        
    780         /**
    781          * @abstract                                    Sets the values for a payment from the response from mPAY24:
    782          *                                                 count, payment types, brands and descriptions
    783          * @param         STRING                            The SOAP response from mPAY24 (in XML form)
    784          */
    785         function ListPaymentMethodsResponse($response) {
    786             $this->generalResponse = new GeneralResponse($response);
    787            
    788             if($response != '') {
    789                 $responseAsDOM = new DOMDocument();
    790                 $responseAsDOM->loadXML($response);
    791                
    792                 if($responseAsDOM && $responseAsDOM->getElementsByTagName('all')->length != 0) {       
    793                     $this->all             = $responseAsDOM->getElementsByTagName('all')->item(0)->nodeValue;
    794                        
    795                     for($i = 0; $i < $this->all; $i++) {
    796                         $this->pTypes[$i] = $responseAsDOM->getElementsByTagName('pType')->item($i)->nodeValue;
    797                         $this->brands[$i] = $responseAsDOM->getElementsByTagName('brand')->item($i)->nodeValue;
    798                         $this->descriptions[$i] = $responseAsDOM->getElementsByTagName('description')->item($i)->nodeValue;
    799                     }
    800                 }
    801             } else {
    802                 $this->generalResponse->setStatus("ERROR");
    803                 $this->generalResponse->setReturnCode("The response is empty! Probably your request to mPAY24 was not sent! Please see your server log for more information!");
    804             }   
    805         }
    806        
    807         /**
    808          * @return        INTEGER                            The count of the payment methods, returned from mPAY24
    809          */
    810         public function getAll() {
    811             return $this->all;
    812         }
    813        
    814         /**
    815          * @return        ARRAY                            The payment types, returned from mPAY24
    816          */
    817         public function getPTypes() {
    818             return $this->pTypes;
    819         }
    820        
    821         /**
    822          * @return        ARRAY                            The brands, returned from mPAY24
    823          */
    824         public function getBrands() {
    825             return $this->brands;
    826         }
    827        
    828         /**
    829          * @return        ARRAY                            The descriptions, returned from mPAY24
    830          */
    831         public function getDescriptions() {
    832             return $this->descriptions;
    833         }
    834        
    835         /**
    836          * @param        INTEGER                            The index of a payment type
    837          * @return        STRING                            A payment type, returned from mPAY24
    838          */
    839         public function getPType($i) {
    840             return $this->pTypes[$i];
    841         }
    842        
    843         /**
    844          * @param        INTEGER                            The index of a brand
    845          * @return        STRING                            A brand, returned from mPAY24
    846          */
    847         public function getBrand($i) {
    848             return $this->brands[$i];
    849         }
    850        
    851         /**
    852          * @param        INTEGER                            The index of a description
    853          * @return        STRING                            A description, returned from mPAY24
    854          */
    855         public function getDescription($i) {
    856             return $this->descriptions[$i];
    857         }
    858        
    859         /**
    860          * @return        GeneralResponse                    The object, that contains the basic values from the response from mPAY24:
    861          *                                                 status and return code
    862          */
    863         public function getGeneralResponse() {
    864             return $this->generalResponse;
    865         }
    866     }
    867    
    868     class TransactionStatusResponse extends GeneralResponse {
    869        
    870         /**
    871          * @var         GeneralResponse                    An object, that represents the basic values from the response from mPAY24:
    872          *                                                 status and return code
    873          */
    874         var $generalResponse;
    875         /**
    876          * @var         ARRAY                            A list with all the parameters for a transaction
    877          */
    878         var $params                    = array();
    879         /**
    880          * @var         INTEGER                            The count of all the paramerters for a transaction
    881          */
    882         var $paramCount                = 0;
    883        
    884         /**
    885          * @abstract                                    Sets the values for a transaction from the response from mPAY24:
    886          *                                                 STATUS, PRICE, CURRENCY, LANGUAGE, etc
    887          * @param         STRING                            The SOAP response from mPAY24 (in XML form)
    888          */
    889         function TransactionStatusResponse($response) {
    890             $this->generalResponse = new GeneralResponse($response);
    891             if($response != '') {
    892                 $responseAsDOM = new DOMDocument();
    893                 $responseAsDOM->loadXML($response);
    894                
    895                 if($responseAsDOM && $responseAsDOM->getElementsByTagName('name')->length != 0) {       
    896                     $this->paramCount = $responseAsDOM->getElementsByTagName('name')->length;
    897                     $this->params['STATUS'] = $this->generalResponse->getStatus();
    898                    
    899                     for($i = 0; $i < $this->paramCount; $i++){
    900                         if($responseAsDOM->getElementsByTagName("name")->item($i)->nodeValue == "STATUS")
    901                             $this->params["TSTATUS"] = $responseAsDOM->getElementsByTagName("value")->item($i)->nodeValue;
    902                         else
    903                             $this->params[$responseAsDOM->getElementsByTagName('name')->item($i)->nodeValue]
    904                                             = $responseAsDOM->getElementsByTagName('value')->item($i)->nodeValue;                   
    905                     }
    906                 }
    907             } else {
    908                 $this->generalResponse->setStatus("ERROR");
    909                 $this->generalResponse->setReturnCode("The response is empty! Probably your request to mPAY24 was not sent! Please see your server log for more information!");
    910             }   
    911         }
    912        
    913         /**
    914          * @return        INTEGER                            The count of all the paramerters for a transaction
    915          */
    916         public function getParamCount() {
    917             return $this->paramCount;
    918         }
    919        
    920         /**
    921          * @return        ARRAY                            The parameters for a transaction, returned from mPAY24
    922          */
    923         public function getParams() {
    924             return $this->params;
    925         }
    926        
    927         /**
    928          * @param        STRING                            The name of a parameter (for example: STATUS, PRICE, CURRENCY, etc)
    929          * @return        STRING                            A description, returned from mPAY24
    930          */
    931         public function getParam($i) {
    932             if(isset($this->params[$i]))
    933                 return $this->params[$i];
    934             else
    935                 return false;
    936         }
    937        
    938         /**
    939          * @param        STRING                            The name of a parameter (for example: STATUS, PRICE, CURRENCY, etc)
    940          * @param        STRING                            The value of the parameter
    941          */
    942         public function setParam($name, $value) {
    943             $this->params[$name] = $value;
    944         }
    945        
    946         /**
    947          * @return        GeneralResponse                    The object, that contains the basic values from the response from mPAY24:
    948          *                                                 status and return code
    949          */
    950         public function getGeneralResponse() {
    951             return $this->generalResponse;
    952         }
    953     }
     1129      }
     1130    } else {
     1131      $this->generalResponse->setStatus("ERROR");
     1132      $this->generalResponse->setReturnCode("The response is empty! Probably your request to mPAY24 was not sent! Please see your server log for more information!");
     1133    }
     1134  }
     1135
     1136  /**
     1137   * Get the count of all the paramerters for a transaction
     1138   * @return            int
     1139   */
     1140  public function getParamCount() {
     1141    return $this->paramCount;
     1142  }
     1143
     1144  /**
     1145   * Get the parameters for a transaction, returned from mPAY24
     1146   * @return            array
     1147   */
     1148  public function getParams() {
     1149    return $this->params;
     1150  }
     1151
     1152  /**
     1153   * Get the parameter's value, returned from mPAY24
     1154   * @param             string              $i                            The name of a parameter (for example: STATUS, PRICE, CURRENCY, etc)
     1155   * @return            array
     1156   */
     1157  public function getParam($i) {
     1158    if(isset($this->params[$i]))
     1159      return $this->params[$i];
     1160    else
     1161      return false;
     1162  }
     1163
     1164  /**
     1165   * Set a value for a parameter
     1166   * @param             string              $name                         The name of a parameter (for example: STATUS, PRICE, CURRENCY, etc)
     1167   * @param             string              $value                        The value of the parameter
     1168   */
     1169  public function setParam($name, $value) {
     1170    $this->params[$name] = $value;
     1171  }
     1172
     1173  /**
     1174   * Get the object, that contains the basic values from the response from mPAY24: status and return code
     1175   * @return            string
     1176   */
     1177  public function getGeneralResponse() {
     1178    return $this->generalResponse;
     1179  }
     1180}
    9541181?>
  • woocommerce-mpay24-gateway/trunk/MPay24/MPay24Shop.php

    r636654 r803175  
    11<?php
    2     /**
    3      * @author            [email protected]
    4      * @version             $Id: MPay24Shop.php 5217 2012-10-16 05:27:43Z anna $
    5      * @filesource        MPay24Shop.php
    6      * @license             http://ec.europa.eu/idabc/eupl.html EUPL, Version 1.1
    7      */
    8 
    9     include_once("MPay24Api.php");
    10     include_once("orderXML.php");
    11    
    12     abstract class MPay24Shop extends Transaction {
    13 
    14         /**
    15          * @var         MPAY24API                        The mPAY24API Object, with you are going to work
    16          */
    17         var $mPay24Api = null;
    18        
    19         /**
    20          * @abstract                                    The constructor, which sets all the initial values
    21          *                                                 to be able making transactions
    22          * @param         INTEGER                            5-digit account number, supported by mPAY24
    23          *
    24          *                                                 TEST accounts - starting with 9
    25          *
    26          *                                                 LIVE account - starting with 7
    27          * @param         STRING                            The webservice's password, supported by mPAY24
    28          * @param         BOOLEAN                            TRUE - when you want to use the TEST system
    29          *
    30          *                                                 FALSE - when you want to use the LIVE system               
    31          * @param         STRING                            The host name in case you are behind a proxy server ("" when not)
    32          * @param         INTEGER                            4-digit port number in case you are behind a proxy server ("" when not)
    33          */
    34         function MPay24Shop($merchantID, $soapPassword, $test, $proxyHost=null, $proxyPort=null, $debug=false) {
    35             if(!is_bool($test))
    36                 die("The test parameter '$test' you have given is wrong, it must be boolean value 'true' or 'false'!");
    37            
    38             if(!is_bool($debug))
    39                 die("The debug parameter '$debug' you have given is wrong, it must be boolean value 'true' or 'false'!");
    40            
    41             $this->mPay24Api = new MPay24Api();
    42            
    43             if($proxyHost == null) {
    44                 $pHost = "";
    45                 $pPort = "";
    46             } else {
    47                 $pHost = $proxyHost;
    48                 $pPort = $proxyPort;
    49             }
    50                
    51             $this->mPay24Api->configure($merchantID, $soapPassword, $test, $pHost, $pPort);
    52             $this->mPay24Api->setDebug($debug);
    53                
    54             if (version_compare(phpversion(), '5.0.0', '<')===true || !in_array('curl', get_loaded_extensions()) || !in_array('dom', get_loaded_extensions())) {
    55                 $this->mPay24Api->printMsg("ERROR: You don't meet the needed requirements for this example shop.<br>");
    56             if(version_compare(phpversion(), '5.0.0', '<')===true)
    57                 $this->mPay24Api->printMsg("You need PHP version 5.0.0 or newer!<br>");
    58             if(!in_array('curl', get_loaded_extensions()))
    59                 $this->mPay24Api->printMsg("You need cURL extension!<br>");
    60             if(!in_array('dom', get_loaded_extensions()))
    61                 $this->mPay24Api->printMsg("You need DOM extension!<br>");
    62             $this->mPay24Api->dieWithMsg("Please load the required extensions!");
    63           }           
    64            
    65           if(strlen($merchantID) != 5 || (substr($merchantID, 0, 1) != "7" && substr($merchantID, 0, 1) != "9"))
    66                 $this->mPay24Api->dieWithMsg("The merchant ID '$merchantID' you have given is wrong, it must be 5-digit number and starts with 7 or 9!");       
    67 
    68           if($proxyPort != null && (!is_numeric($proxyPort) || strlen($proxyPort) != 4))
    69                 $this->mPay24Api->dieWithMsg("The proxy port '$proxyPort' you have given must be numeric!");
    70                
    71           if(($proxyHost == null && $proxyHost != $proxyPort) || ($proxyPort == null && $proxyHost != $proxyPort))
    72                 $this->mPay24Api->dieWithMsg("You must setup both variables 'proxyHost' and 'proxyPort'!");           
    73         }
    74 
    75        
    76        
    77         /**
    78          * @abstract                                    Create a transaction and save this (in a data base or file system (for example XML))
    79          * @uses        Transaction
    80          * @return         Transaction                        The created transaction
    81          */
    82         abstract function createTransaction();
    83        
    84        
    85        
    86         /**
    87          * @abstract                                    Actualize the transaction, which has a transaction ID = $tid with the values from $args in your shop
    88          * @param        STRING                            The transaction ID you want to update with the confirmation
    89          * @param        ARRAY                            Arrguments with them the transaction is to be updated
    90          * @param        BOOLEAN                            TRUE if the shipping address is confirmed, FALSE - otherwise (in case of PayPal Express Checkout)
    91          * @return         Transaction                        The updated    transaction
    92          */
    93         abstract function updateTransaction($tid, $args, $shippingConfirmed);
    94        
    95        
    96        
    97         /**
    98          * @abstract                                    Give the transaction object back, for a transaction which has a transaction ID = $tid
    99          * @param        STRING                            The transaction ID of the transaction you want get
    100          * @return         Transaction       
    101          */
    102         abstract function getTransaction($tid);
    103 
    104        
    105        
    106         /**
    107          * @abstract                                    Using the ORDER object from order.php, create a MDXI-XML, which is needed
    108          *                                                 for a transaction to be started
    109          * @uses        ORDER
    110          * @param        Transaction                        The transaction you want to make a MDXI XML file for
    111          * @return        ORDER                            The MDXI, needed for a transaction to be started
    112          */
    113         abstract function createMDXI($transaction);
    114        
    115         /**
    116          * @abstract                                    Using the ORDER object from order.php, create a order-xml, which is needed
    117          *                                                 for a transaction with profiles to be started
    118          * @uses        ORDER
    119          * @param        Transaction                        The transaction you want to make an order transaction XML file for
    120          * @return        XML                                The ORDER, needed for a transaction to be started
    121          */
    122         abstract function createProfileOrder($tid);
    123        
    124         /**
    125          * @abstract                                    Using the ORDER object from order.php, create a order-xml, which is needed
    126          *                                                 for a transaction with PayPal Express Checkout to be started
    127          * @uses        ORDER
    128          * @param        Transaction                        The transaction you want to make an order transaction XML file for
    129          * @return        XML                                The ORDER, needed for a transaction to be started
    130          */
    131         abstract function createExpressCheckoutOrder($tid);
    132        
    133         /**
    134          * @abstract                                    Using the ORDER object from order.php, create a order-xml, which is needed
    135          *                                                 for a transaction with PayPal Express Checkout to be finished
    136          * @uses        ORDER
    137          * @param        Transaction                        The transaction you want to make an order transaction XML file for
    138          * @return        XML                                The ORDER, needed for a transaction to be started
    139          */
    140         abstract function createFinishExpressCheckoutOrder($tid, $shippingCosts, $amount, $cancel);
    141        
    142         /**
    143          * @abstract                                    Write a log into a file, file system, data base                           
    144          * @param         STRING                            The operation, which is to log: GetPaymentMethods, Pay, PayWithProfile,
    145          *                                                 Confirmation, UpdateTransactionStatus, ClearAmount, CreditAmount, CancelTransaction, etc.
    146          * @param         STRING                            The information, which is to log: request, response, etc.
    147          */
    148         abstract function write_log($operation, $info_to_log);
    149        
    150         /**
    151          * @abstract                                    This is an optional function, but it's strongly recomended that you implement it.
    152          *                                                 It should build a hash from the transaction ID of your shop, the amount of the transaction,
    153          *                                                 the currency and the timeStamp of the transaction. The mPAY24 confirmation interface will be called
    154          *                                                 with this hash (parameter name 'token'), so you would be able to check whether the confirmation is
    155          *                                                 really coming from mPAY24 or not. The hash should be then saved in the transaction object, so that
    156          *                                                 every transaction has an unique secret token.
    157          * @param        STRING                            The transaction ID you want to make a secret key for
    158          * @param        STRING                            The amount, reserved for this transaction
    159          * @param        CURRENCY                        The currency for the transaction
    160          * @param        DATE                            The timeStamp at the moment the transaction is created
    161          * @return        HASHED_STRING                    The secret key for the transaction
    162          */
    163         abstract function createSecret($tid, $amount, $currency, $timeStamp);
    164        
    165         /**
    166          * @param         STRING                            The transaction ID you want to get the secret key for
    167          * @return        HASHED_STRING                    The hash for the transaction
    168          */
    169        
    170         abstract function getSecret($tid);
    171        
    172         /**
    173          * @return         ARRAY                            A list which includes all the payment methods (activated by mPAY24)
    174          *                                                 for your mechant ID
    175          */
    176         function getPaymentMethods() {
    177             if(!$this->mPay24Api)
    178                 die("You are not allowed to define a constructor in the child class of MPay24Shop!");
    179                
    180             $paymentMethods = $this->mPay24Api->ListPaymentMethods();
    181             if($this->mPay24Api->getDebug()) {
    182                 $this->write_log("GetPaymentMethods",
    183                                 "REQUEST to " . $this->mPay24Api->getEtpURL() . " - ".str_replace("><", ">\n<", $this->mPay24Api->getRequest())."\n");
    184                 $this->write_log("GetPaymentMethods",
    185                                 "RESPONSE - ".str_replace("><", ">\n<", $this->mPay24Api->getResponse())."\n");
    186             }
    187             return $paymentMethods;
    188         }
    189        
    190         /**
    191          * @abstract                                    Start a payment
    192          * @return         PaymentResponse                    Including redirection URL
    193          */
    194         function pay() {
    195             if(!$this->mPay24Api)
    196                 die("You are not allowed to define a constructor in the child class of MPay24Shop!");
    197            
    198             $transaction = $this->createTransaction();
    199            
    200             $this->checkTransaction($transaction);
    201            
    202             libxml_use_internal_errors(true);
    203            
    204             $mdxi = $this->createMDXI($transaction);
    205 
    206             if(!$mdxi || !$mdxi instanceof ORDER)
    207                 $this->mPay24Api->dieWithMsg("To be able to use the MPay24Api you must create an ORDER object (order.php) and fulfill it with a MDXI!");
    208            
    209             $mdxiXML = $mdxi->toXML();
    210            
    211             if(!$this->mPay24Api->proxyUsed())
    212                 if(!$mdxi->validate()) {
    213                     $errors = "";
    214                     foreach(libxml_get_errors() as $error)
    215                         $errors.= trim($error->message) . "<br>";
    216                    
    217                     $this->mPay24Api->dieWithMsg("The schema you have created is not valid!". "<br><br>".$errors.
    218                         "<textarea cols='100' rows='30'>$mdxiXML</textarea>"
    219                     );
    220                 }
    221            
    222             $mdxiXML = $mdxi->toXML();
    223            
    224             $payResult = $this->mPay24Api->SelectPayment($mdxiXML);
    225            
    226             if($this->mPay24Api->getDebug()) {
    227                 $this->write_log("Pay",
    228                                 "REQUEST to " . $this->mPay24Api->getEtpURL() . " - ".str_replace("><", ">\n<", $this->mPay24Api->getRequest())."\n");
    229                 $this->write_log("Pay",
    230                                 "RESPONSE - ".str_replace("><", ">\n<", $this->mPay24Api->getResponse())."\n");
    231             }
    232            
    233             return $payResult;
    234         }
    235        
    236         /**
    237          * @abstract                                    Start a payment with customer profile
    238          * @return         PaymentResponse   
    239          */
    240         function payWithProfile() {
    241             if(!$this->mPay24Api)
    242                 die("You are not allowed to define a constructor in the child class of MPay24Shop!");
    243                
    244             $transaction = $this->createTransaction();
    245            
    246             $this->checkTransaction($transaction);
    247                
    248             $order = $this->createProfileOrder($transaction);
    249            
    250             if(!$order || !$order instanceof ORDER)
    251                 $this->mPay24Api->dieWithMsg("To be able to use the MPay24Api you must create an ORDER object (order.php)!");
    252                            
    253             $payWithProfileResult = $this->mPay24Api->ProfilePayment($order->toXML());
    254            
    255             if($this->mPay24Api->getDebug()) {
    256                 $this->write_log("PayWithProfile",
    257                                 "REQUEST to " . $this->mPay24Api->getEtpURL() . " - ".str_replace("><", ">\n<", $this->mPay24Api->getRequest())."\n");
    258                 $this->write_log("PayWithProfile",
    259                                 "RESPONSE - ".str_replace("><", ">\n<", $this->mPay24Api->getResponse())."\n");
    260             }
    261            
    262             return $payWithProfileResult;
    263         }
    264 
    265         /**
    266          * @abstract                                    Start a payment with PayPal Express Checkout
    267          * @return         PaymentResponse                    Including redirection URL
    268          */
    269         function payWithExpressCheckout() {
    270             if(!$this->mPay24Api)
    271                 die("You are not allowed to define a constructor in the child class of MPay24Shop!");
    272                
    273             $transaction = $this->createTransaction();
    274            
    275             $this->checkTransaction($transaction);
    276            
    277             $order = $this->createExpressCheckoutOrder($transaction);
    278            
    279             if(!$order || !$order instanceof ORDER)
    280                 $this->mPay24Api->dieWithMsg("To be able to use the MPay24Api you must create an ORDER object (order.php)!");           
    281            
    282             $payWithExpressCheckoutResult = $this->mPay24Api->ExpressCheckoutPayment($order->toXML());
    283            
    284             if($this->mPay24Api->getDebug()) {
    285                 $this->write_log("PayWithExpressCheckout",
    286                                 "REQUEST to " . $this->mPay24Api->getEtpURL() . " - ".str_replace("><", ">\n<", $this->mPay24Api->getRequest())."\n");
    287                 $this->write_log("PayWithExpressCheckout",
    288                                 "RESPONSE - ".str_replace("><", ">\n<", $this->mPay24Api->getResponse())."\n");
    289             }
    290            
    291             return $payWithExpressCheckoutResult;
    292         }
    293        
    294         /**
    295          * @abstract                                    Finish the payment, started with PayPal Express Checkout - reserve, bill or cancel it:
    296          *
    297          *                                                 Whether are you going to reserve or bill a payment is setted at the beginning of the payment.
    298          *
    299          *                                                 With the 'cancel' parameter you are able also to cancel the transaction                                               
    300          * @param         STRING                            The transaction ID in the shop
    301          * @param         INTEGER                            The shippingcosts for the transaction multiply by 100
    302          * @param         INTEGER                            The amount you want to reserve/bill multiply by 100
    303          * @param         STRING                            ALLOWED: "true" or "false" - in case of 'true' the transaction will be canceled, otherwise
    304          *                                                 reserved/billed
    305          * @return         PaymentResponse                    Including mPAY24 transaction ID
    306          */
    307         function finishExpressCheckoutPayment($tid, $shippingCosts, $amount, $cancel) {
    308             if(!$this->mPay24Api)
    309                 die("You are not allowed to define a constructor in the child class of MPay24Shop!");
    310                
    311             if($cancel !== "true" && $cancel !== "false")
    312                 $this->mPay24Api->dieWithMsg("The allowed values for the parameter 'cancel' by finishing a PayPal (Express Checkout) payment are 'true' or 'false'!");
    313                
    314             $transaction = $this->getTransaction($tid);
    315            
    316             $this->checkTransaction($transaction);
    317            
    318             $mPAYTid = $transaction->MPAYTID;
    319            
    320             if(!$mPAYTid)
    321                 $this->mPay24Api->dieWithMsg("The transaction '$tid' you want to finish with the mPAYTid '$mPAYTid' does not exist in the mPAY24 data base!");
    322            
    323             if(!$amount || !is_numeric($amount))
    324                 $this->mPay24Api->dieWithMsg("The amount '$amount' you are trying to pay by PayPal is not valid!");
    325                
    326             if(!$shippingCosts || !is_numeric($shippingCosts))
    327                 $this->mPay24Api->dieWithMsg("The shipping costs '$shippingCosts' you are trying to set are not valid!");
    328            
    329             $order = $this->createFinishExpressCheckoutOrder($transaction, $shippingCosts, $amount, $cancel);
    330            
    331             if(!$order || !$order instanceof ORDER)
    332                 $this->mPay24Api->dieWithMsg("To be able to use the MPay24Api you must create an ORDER object (order.php)!");
    333 
    334             $finishExpressCheckoutResult = $this->mPay24Api->CallbackPaypal($order->toXML());
    335            
    336             if($this->mPay24Api->getDebug()) {
    337                 $this->write_log("FinishExpressCheckoutResult",
    338                                 "REQUEST to " . $this->mPay24Api->getEtpURL() . " - ".str_replace("><", ">\n<", $this->mPay24Api->getRequest())."\n");
    339                 $this->write_log("FinishExpressCheckoutResult",
    340                                 "RESPONSE - ".str_replace("><", ">\n<", $this->mPay24Api->getResponse())."\n");
    341             }
    342            
    343             return $finishExpressCheckoutResult;
    344         }
    345        
    346         /**
    347          * @param         STRING                            The transaction ID, for the transaction you want to confirm
    348          * @param         ARRAY                            The arguments you want to set for this transaction
    349          */
    350         function confirm($tid, $args) {
    351             $to_log = '';
    352             $shippingConfirmed = "";
    353            
    354             foreach($args as $name => $value)
    355                 $to_log.= $name . " = " . $value . "\n";
    356 
    357             if($this->mPay24Api->getDebug())
    358                 $this->write_log("Confirmation for transaction '" . $tid . "'\n", utf8_encode($to_log)."\n");               
    359 
    360             $transactionStatus = $this->updateTransactionStatus($tid);
    361            
    362             $newArgs = $transactionStatus->getParams();
    363            
    364             foreach($newArgs as $name => $value)
    365                 $to_log.= $name . " = " . $value . "\n";
    366 
    367             if($this->mPay24Api->getDebug())
    368                 $this->write_log("Status for transaction " . $tid . ":", utf8_encode($to_log)."\n");   
    369            
    370             if($transactionStatus->getParam("SHIPPING_ADDR")) {
    371                     $order = new DOMDocument();
    372                 $order->loadXML($transactionStatus->getParam("SHIPPING_ADDR"));
    373             }
    374            
    375             if(isset($order)) {
    376                 $shipping = $order->getElementsByTagName("Shipping")->item(0);
    377                 $shippingConfirmed = $shipping->getAttribute("confirmed");
    378             }
    379 
    380             if($this->getSecret($tid) == $args['token']) {
    381                 if($shippingConfirmed == "false") {
    382                     $newArgs["SHIPP_NAME"] = $order->getElementsByTagName("Shipping")->item(0)->getElementsByTagName("Name")->item(0)->nodeValue;
    383                     $newArgs["SHIPP_STREET"] = $order->getElementsByTagName("Shipping")->item(0)->getElementsByTagName("Street")->item(0)->nodeValue;
    384                     if($order->getElementsByTagName("Shipping")->item(0)->hasAttribute("Street2"))
    385                         $newArgs["SHIPP_STREET2"] = $order->getElementsByTagName("Shipping")->item(0)->getElementsByTagName("Street2")->item(0)->nodeValue;
    386                     $newArgs["SHIPP_ZIP"] = $order->getElementsByTagName("Shipping")->item(0)->getElementsByTagName("Zip")->item(0)->nodeValue;
    387                     $newArgs["SHIPP_CITY"] = $order->getElementsByTagName("Shipping")->item(0)->getElementsByTagName("City")->item(0)->nodeValue;
    388                     $newArgs["SHIPP_COUNTRY"] = $order->getElementsByTagName("Shipping")->item(0)->getElementsByTagName("Country")->item(0)->getAttribute("code");
    389                     $this->updateTransaction($tid, $newArgs, false);
    390                 } else
    391                     $this->updateTransaction($tid, $newArgs, true);
    392             }
    393         }
    394        
    395        
    396        
    397         /**
    398          * @param         STRING                           The transaction ID (in your shop), for the transaction you are asking for
    399          * @return        ARRAY                            An array with all the data (by mPAY24) for this transaction (STATUS, CURRENCY, PRICE, APPR_CODE, etc).
    400          *                                                                                               Possible values for the STATUS attribute:
    401          *                             
    402          *                                                 RESERVED - in case the authorization was successful but not cleared yet
    403          *             
    404          *                                                 BILLED - in case the authorization was successful and amount was cleared
    405          *
    406          *                                                 CREDITED - in case amount was credited
    407          *
    408          *                                                 REVERSED - in case the transaction was canceled
    409          *
    410          *                                                 SUSPENDED - in case the transaction is not fully compleated yet
    411          *
    412          *                                                 NOT FOUND - in case there is not such a transaction in the mPAY24 database
    413          *
    414          *                                                 ERROR - in case the transaction was not successful
    415          */
    416         function updateTransactionStatus($tid) {
    417             if(!$this->mPay24Api)
    418                 die("You are not allowed to define a constructor in the child class of MPay24Shop!");
    419                
    420             $transaction = $this->getTransaction($tid);
    421            
    422             $this->checkTransaction($transaction);
    423                        
    424             if(!$transaction->MPAYTID || !is_numeric($transaction->MPAYTID)) {
    425                 $tidTransactionStatusResult = $this->mPay24Api->TransactionStatus(null, $tid);
    426                
    427                 if($this->mPay24Api->getDebug()) {
    428                     $this->write_log("TidTransactionStatus",
    429                                 "REQUEST to " . $this->mPay24Api->getEtpURL() . " - ".str_replace("><", ">\n<", $this->mPay24Api->getRequest())."\n");
    430                     $this->write_log("TidTransactionStatus",
    431                                 "RESPONSE - ".str_replace("><", ">\n<", $this->mPay24Api->getResponse())."\n");
    432                 }
    433                
    434                 if($tidTransactionStatusResult->getParam("SHIPPING_ADDR")) {
    435                     $order = new DOMDocument();
    436                     $order->loadXML($tidTransactionStatusResult->getParam("SHIPPING_ADDR"));
    437                 }
    438 
    439                 if(isset($order)) {
    440                     $shipping = $order->getElementsByTagName("Shipping")->item(0);
    441                     $shippingConfirmed = $shipping->getAttribute("confirmed");
    442                                        
    443                     if($shippingConfirmed == "false") {
    444                         $tidTransactionStatusResult->setParam("shippingConfirmed", false);
    445                         $tidTransactionStatusResult->setParam("SHIPP_NAME", $order->getElementsByTagName("Shipping")->item(0)
     2include_once("MPay24Api.php");
     3include_once("orderXML.php");
     4
     5/**
     6 * The abstract MPay24Shop class provides abstract functions, which are used from the other functions in order to make a payment or a request to mPAY24
     7 *
     8 * @author              mPAY24 GmbH <[email protected]>
     9 * @version             $Id: MPay24Shop.php 5522 2013-06-24 13:08:35Z anna $
     10 * @filesource          MPay24Shop.php
     11 * @license             http://ec.europa.eu/idabc/eupl.html EUPL, Version 1.1
     12 */
     13abstract class MPay24Shop extends Transaction {
     14  /**
     15   * The mPAY24API Object, with you are going to work
     16   * @var               $mPay24Api
     17   */
     18  var $mPay24Api = null;
     19
     20  /**
     21   * The constructor, which sets all the initial values, in order to be able making transactions
     22   * @param             int                 $merchantID                   5-digit account number, supported by mPAY24:
     23   *                                                                      TEST accounts - starting with 9
     24   *                                                                      LIVE account - starting with 7
     25   * @param             string              $soapPassword                 The webservice's password, supported by mPAY24
     26   * @param             bool                $test                         TRUE - when you want to use the TEST system,
     27   *                                                                      FALSE - when you want to use the LIVE system
     28   * @param             string              $proxyHost                    The host name in case you are behind a proxy server ("" when not)
     29   * @param             int                 $proxyPort                    4-digit port number in case you are behind a proxy server ("" when not)
     30   * @param             bool                $debug                        TRUE - when you want to write log files,
     31   *                                                                      FALSE - when you don't want write log files
     32   */
     33  function MPay24Shop($merchantID, $soapPassword, $test, $proxyHost=null, $proxyPort=null, $debug=false) {
     34    if(!is_bool($test))
     35      die("The test parameter '$test' you have given is wrong, it must be boolean value 'true' or 'false'!");
     36
     37    if(!is_bool($debug))
     38      die("The debug parameter '$debug' you have given is wrong, it must be boolean value 'true' or 'false'!");
     39
     40    $this->mPay24Api = new MPay24Api();
     41
     42    if($proxyHost == null) {
     43      $pHost = "";
     44      $pPort = "";
     45    } else {
     46      $pHost = $proxyHost;
     47      $pPort = $proxyPort;
     48    }
     49
     50    $this->mPay24Api->configure($merchantID, $soapPassword, $test, $pHost, $pPort);
     51    $this->mPay24Api->setDebug($debug);
     52
     53    if (version_compare(phpversion(), '5.0.0', '<')===true || !in_array('curl', get_loaded_extensions()) || !in_array('dom', get_loaded_extensions())) {
     54      $this->mPay24Api->printMsg("ERROR: You don't meet the needed requirements for this example shop.<br>");
     55
     56      if(version_compare(phpversion(), '5.0.0', '<')===true)
     57        $this->mPay24Api->printMsg("You need PHP version 5.0.0 or newer!<br>");
     58      if(!in_array('curl', get_loaded_extensions()))
     59        $this->mPay24Api->printMsg("You need cURL extension!<br>");
     60      if(!in_array('dom', get_loaded_extensions()))
     61        $this->mPay24Api->printMsg("You need DOM extension!<br>");
     62
     63      $this->mPay24Api->dieWithMsg("Please load the required extensions!");
     64    }
     65
     66    if(strlen($merchantID) != 5 || (substr($merchantID, 0, 1) != "7" && substr($merchantID, 0, 1) != "9"))
     67      $this->mPay24Api->dieWithMsg("The merchant ID '$merchantID' you have given is wrong, it must be 5-digit number and starts with 7 or 9!");
     68
     69    if($proxyPort != null && (!is_numeric($proxyPort) || strlen($proxyPort) != 4))
     70      $this->mPay24Api->dieWithMsg("The proxy port '$proxyPort' you have given must be numeric!");
     71
     72    if(($proxyHost == null && $proxyHost != $proxyPort) || ($proxyPort == null && $proxyHost != $proxyPort))
     73      $this->mPay24Api->dieWithMsg("You must setup both variables 'proxyHost' and 'proxyPort'!");
     74  }
     75
     76  /**
     77   * Create a transaction and save/return this (in a data base or file system (for example XML))
     78   * @return            Transaction
     79   */
     80  abstract function createTransaction();
     81
     82  /**
     83   * Actualize the transaction, which has a transaction ID = $tid with the values from $args in your shop and return it
     84   * @param             string              $tid                          The transaction ID you want to update with the confirmation
     85   * @param             array               $args                         Arrguments with them the transaction is to be updated
     86   * @param             bool                $shippingConfirmed            TRUE if the shipping address is confirmed, FALSE - otherwise (in case of PayPal Express Checkout)
     87   */
     88  abstract function updateTransaction($tid, $args, $shippingConfirmed);
     89
     90  /**
     91   * Give the transaction object back, for a transaction which has a transaction ID = $tid
     92   * @param             string              $tid                          The transaction ID of the transaction you want get
     93   * @return            Transaction
     94   */
     95  abstract function getTransaction($tid);
     96
     97  /**
     98   * Using the ORDER object from order.php, create a MDXI-XML, which is needed for a transaction to be started
     99   * @param             Transaction         $transaction                  The transaction you want to make a MDXI XML file for
     100   * @return            ORDER
     101   */
     102  abstract function createMDXI($transaction);
     103
     104  /**
     105   * Using the ORDER object from order.php, create a order-xml, which is needed for a transaction with profiles to be started
     106   * @param             string              $tid                          The transaction ID of the transaction you want to make an order transaction XML file for
     107   * @return            XML
     108   */
     109  abstract function createProfileOrder($tid);
     110
     111  /**
     112   * Using the ORDER object from order.php, create a order-xml, which is needed for a transaction with PayPal Express Checkout to be started
     113   * @param             string              $tid                          The transaction ID of the transaction you want to make an order transaction XML file for
     114   * @return            XML
     115   */
     116  abstract function createExpressCheckoutOrder($tid);
     117
     118  /**
     119   * Using the ORDER object from order.php, create a order-xml, which is needed for a transaction with PayPal Express Checkout to be finished
     120   * @param             string              $tid                          The transaction ID of the transaction you want to make an order transaction XML file for
     121   * @param             string              $shippingCosts                The shipping costs amount for the transaction, provided by PayPal, after changing the shipping address
     122   * @param             string              $amount                       The new amount for the transaction, provided by PayPal, after changing the shipping address
     123   * @param             bool                $cancel                       TRUE if the a cancelation is wanted after renewing the amounts and FALSE otherwise
     124   * @return            XML
     125   */
     126  abstract function createFinishExpressCheckoutOrder($tid, $shippingCosts, $amount, $cancel);
     127
     128  /**
     129   * Write a log into a file, file system, data base
     130   * @param             string              $operation                    The operation, which is to log: GetPaymentMethods, Pay, PayWithProfile, Confirmation, UpdateTransactionStatus, ClearAmount, CreditAmount, CancelTransaction, etc.
     131   * @param             string              $info_to_log                  The information, which is to log: request, response, etc.
     132   */
     133  abstract function write_log($operation, $info_to_log);
     134
     135  /**
     136   * This is an optional function, but it's strongly recomended that you implement it - see details.
     137   * It should build a hash from the transaction ID of your shop, the amount of the transaction,
     138   * the currency and the timeStamp of the transaction. The mPAY24 confirmation interface will be called
     139   * with this hash (parameter name 'token'), so you would be able to check whether the confirmation is
     140   * really coming from mPAY24 or not. The hash should be then saved in the transaction object, so that
     141   * every transaction has an unique secret token.
     142   * @param             string              $tid                          The transaction ID you want to make a secret key for
     143   * @param             string              $amount                       The amount, reserved for this transaction
     144   * @param             string              $currency                     The timeStamp at the moment the transaction is created
     145   * @param             string              $timeStamp                    The timeStamp at the moment the transaction is created
     146   * @return            string
     147   */
     148  abstract function createSecret($tid, $amount, $currency, $timeStamp);
     149
     150  /**
     151   * Get the secret (hashed) token for a transaction
     152   * @param             string              $tid                          The transaction ID you want to get the secret key for
     153   * @return            string
     154   */
     155  abstract function getSecret($tid);
     156
     157  /**
     158   * Get a list which includes all the payment methods (activated by mPAY24) for your mechant ID
     159   * @return            ListPaymentMethodsResponse
     160   */
     161  function getPaymentMethods() {
     162    if(!$this->mPay24Api)
     163      die("You are not allowed to define a constructor in the child class of MPay24Shop!");
     164
     165    $paymentMethods = $this->mPay24Api->ListPaymentMethods();
     166
     167    if($this->mPay24Api->getDebug()) {
     168      $this->write_log("GetPaymentMethods",
     169                    "REQUEST to " . $this->mPay24Api->getEtpURL() . " - ".str_replace("><", ">\n<", $this->mPay24Api->getRequest())."\n");
     170      $this->write_log("GetPaymentMethods",
     171                    "RESPONSE - ".str_replace("><", ">\n<", $this->mPay24Api->getResponse())."\n");
     172    }
     173
     174    return $paymentMethods;
     175  }
     176
     177  /**
     178   * Return a redirect URL to start a payment
     179   * @return            PaymentResponse
     180   */
     181  function pay() {
     182    if(!$this->mPay24Api)
     183      die("You are not allowed to define a constructor in the child class of MPay24Shop!");
     184
     185    $transaction = $this->createTransaction();
     186
     187    $this->checkTransaction($transaction);
     188
     189    libxml_use_internal_errors(true);
     190
     191    $mdxi = $this->createMDXI($transaction);
     192
     193    if(!$mdxi || !$mdxi instanceof ORDER)
     194      $this->mPay24Api->dieWithMsg("To be able to use the MPay24Api you must create an ORDER object (order.php) and fulfill it with a MDXI!");
     195
     196    $mdxiXML = $mdxi->toXML();
     197
     198    if(!$this->mPay24Api->proxyUsed())
     199      if(!$mdxi->validate()) {
     200        $errors = "";
     201
     202        foreach(libxml_get_errors() as $error)
     203          $errors.= trim($error->message) . "<br>";
     204
     205        $this->mPay24Api->dieWithMsg("The schema you have created is not valid!". "<br><br>".$errors.
     206                                      "<textarea cols='100' rows='30'>$mdxiXML</textarea>");
     207      }
     208
     209    $mdxiXML = $mdxi->toXML();
     210
     211    $payResult = $this->mPay24Api->SelectPayment($mdxiXML);
     212
     213    if($this->mPay24Api->getDebug()) {
     214      $this->write_log("Pay",
     215                    "REQUEST to " . $this->mPay24Api->getEtpURL() . " - ".str_replace("><", ">\n<", $this->mPay24Api->getRequest())."\n");
     216      $this->write_log("Pay",
     217                    "RESPONSE - ".str_replace("><", ">\n<", $this->mPay24Api->getResponse())."\n");
     218    }
     219
     220    return $payResult;
     221  }
     222
     223  /**
     224   * Start a payment with customer profile
     225   * @return            PaymentResponse
     226   */
     227  function payWithProfile() {
     228    if(!$this->mPay24Api)
     229      die("You are not allowed to define a constructor in the child class of MPay24Shop!");
     230
     231    $transaction = $this->createTransaction();
     232
     233    $this->checkTransaction($transaction);
     234
     235    $order = $this->createProfileOrder($transaction);
     236
     237    if(!$order || !$order instanceof ORDER)
     238      $this->mPay24Api->dieWithMsg("To be able to use the MPay24Api you must create an ORDER object (order.php)!");
     239
     240    $payWithProfileResult = $this->mPay24Api->ProfilePayment($order->toXML());
     241
     242    if($this->mPay24Api->getDebug()) {
     243      $this->write_log("PayWithProfile",
     244                    "REQUEST to " . $this->mPay24Api->getEtpURL() . " - ".str_replace("><", ">\n<", $this->mPay24Api->getRequest())."\n");
     245      $this->write_log("PayWithProfile",
     246                    "RESPONSE - ".str_replace("><", ">\n<", $this->mPay24Api->getResponse())."\n");
     247    }
     248
     249    return $payWithProfileResult;
     250  }
     251
     252  /**
     253   * Start a payment with PayPal Express Checkout
     254   * @return            PaymentResponse
     255   */
     256  function payWithExpressCheckout() {
     257    if(!$this->mPay24Api)
     258      die("You are not allowed to define a constructor in the child class of MPay24Shop!");
     259
     260    $transaction = $this->createTransaction();
     261
     262    $this->checkTransaction($transaction);
     263
     264    $order = $this->createExpressCheckoutOrder($transaction);
     265
     266    if(!$order || !$order instanceof ORDER)
     267      $this->mPay24Api->dieWithMsg("To be able to use the MPay24Api you must create an ORDER object (order.php)!");
     268
     269    $payWithExpressCheckoutResult = $this->mPay24Api->ExpressCheckoutPayment($order->toXML());
     270
     271    if($this->mPay24Api->getDebug()) {
     272      $this->write_log("PayWithExpressCheckout",
     273                    "REQUEST to " . $this->mPay24Api->getEtpURL() . " - ".str_replace("><", ">\n<", $this->mPay24Api->getRequest())."\n");
     274      $this->write_log("PayWithExpressCheckout",
     275                    "RESPONSE - ".str_replace("><", ">\n<", $this->mPay24Api->getResponse())."\n");
     276    }
     277
     278    return $payWithExpressCheckoutResult;
     279  }
     280
     281  /**
     282   * Finish the payment, started with PayPal Express Checkout - reserve, bill or cancel it: Whether are you going to reserve or bill a payment is setted at the beginning of the payment. With the 'cancel' parameter you are able also to cancel the transaction
     283   * @param             string              $tid                          The transaction ID in the shop
     284   * @param             int                 $shippingCosts                The shippingcosts for the transaction multiply by 100
     285   * @param             int                 $amount                       The amount you want to reserve/bill multiply by 100
     286   * @param             string              $cancel                       ALLOWED: "true" or "false" - in case of 'true' the transaction will be canceled, otherwise reserved/billed
     287   * @return            PaymentResponse
     288   */
     289  function finishExpressCheckoutPayment($tid, $shippingCosts, $amount, $cancel) {
     290    if(!$this->mPay24Api)
     291      die("You are not allowed to define a constructor in the child class of MPay24Shop!");
     292
     293    if($cancel !== "true" && $cancel !== "false")
     294      $this->mPay24Api->dieWithMsg("The allowed values for the parameter 'cancel' by finishing a PayPal (Express Checkout) payment are 'true' or 'false'!");
     295
     296    $transaction = $this->getTransaction($tid);
     297
     298    $this->checkTransaction($transaction);
     299
     300    $mPAYTid = $transaction->MPAYTID;
     301
     302    if(!$mPAYTid)
     303      $this->mPay24Api->dieWithMsg("The transaction '$tid' you want to finish with the mPAYTid '$mPAYTid' does not exist in the mPAY24 data base!");
     304
     305    if(!$amount || !is_numeric($amount))
     306      $this->mPay24Api->dieWithMsg("The amount '$amount' you are trying to pay by PayPal is not valid!");
     307
     308    if(!$shippingCosts || !is_numeric($shippingCosts))
     309      $this->mPay24Api->dieWithMsg("The shipping costs '$shippingCosts' you are trying to set are not valid!");
     310
     311    $order = $this->createFinishExpressCheckoutOrder($transaction, $shippingCosts, $amount, $cancel);
     312
     313    if(!$order || !$order instanceof ORDER)
     314      $this->mPay24Api->dieWithMsg("To be able to use the MPay24Api you must create an ORDER object (order.php)!");
     315
     316    $finishExpressCheckoutResult = $this->mPay24Api->CallbackPaypal($order->toXML());
     317
     318    if($this->mPay24Api->getDebug()) {
     319      $this->write_log("FinishExpressCheckoutResult",
     320                    "REQUEST to " . $this->mPay24Api->getEtpURL() . " - ".str_replace("><", ">\n<", $this->mPay24Api->getRequest())."\n");
     321      $this->write_log("FinishExpressCheckoutResult",
     322                    "RESPONSE - ".str_replace("><", ">\n<", $this->mPay24Api->getResponse())."\n");
     323    }
     324
     325    return $finishExpressCheckoutResult;
     326  }
     327
     328  /**
     329   * Proceed the confirmation call
     330   * @param             string              $tid                          The transaction ID in the shop
     331   * @param             array               $args                         A list with the arguments, provided with the confirmation
     332   */
     333  function confirm($tid, $args) {
     334    $to_log = '';
     335    $shippingConfirmed = "";
     336
     337    foreach($args as $name => $value)
     338      $to_log.= $name . " = " . $value . "\n";
     339
     340    if($this->mPay24Api->getDebug())
     341      $this->write_log("Confirmation for transaction '" . $tid . "'\n", utf8_encode($to_log)."\n");
     342
     343    $transactionStatus = $this->updateTransactionStatus($tid);
     344
     345    $newArgs = $transactionStatus->getParams();
     346
     347    foreach($newArgs as $name => $value)
     348      $to_log.= $name . " = " . $value . "\n";
     349
     350    if($this->mPay24Api->getDebug())
     351      $this->write_log("Status for transaction " . $tid . ":", utf8_encode($to_log)."\n");
     352
     353    if($transactionStatus->getParam("SHIPPING_ADDR")) {
     354      $order = new DOMDocument();
     355      $order->loadXML($transactionStatus->getParam("SHIPPING_ADDR"));
     356    }
     357
     358    if(isset($order)) {
     359      $shipping = $order->getElementsByTagName("Shipping")->item(0);
     360      $shippingConfirmed = $shipping->getAttribute("confirmed");
     361    }
     362
     363    if($this->getSecret($tid) == $args['token']) {
     364      if($shippingConfirmed == "false") {
     365        $newArgs["SHIPP_NAME"] = $order->getElementsByTagName("Shipping")->item(0)->getElementsByTagName("Name")->item(0)->nodeValue;
     366        $newArgs["SHIPP_STREET"] = $order->getElementsByTagName("Shipping")->item(0)->getElementsByTagName("Street")->item(0)->nodeValue;
     367
     368        if($order->getElementsByTagName("Shipping")->item(0)->hasAttribute("Street2"))
     369          $newArgs["SHIPP_STREET2"] = $order->getElementsByTagName("Shipping")->item(0)->getElementsByTagName("Street2")->item(0)->nodeValue;
     370
     371        $newArgs["SHIPP_ZIP"] = $order->getElementsByTagName("Shipping")->item(0)->getElementsByTagName("Zip")->item(0)->nodeValue;
     372        $newArgs["SHIPP_CITY"] = $order->getElementsByTagName("Shipping")->item(0)->getElementsByTagName("City")->item(0)->nodeValue;
     373        $newArgs["SHIPP_COUNTRY"] = $order->getElementsByTagName("Shipping")->item(0)->getElementsByTagName("Country")->item(0)->getAttribute("code");
     374        $this->updateTransaction($tid, $newArgs, false);
     375      } else
     376        $this->updateTransaction($tid, $newArgs, true);
     377    }
     378  }
     379
     380  /**
     381   * Get the transaction's current information - see details
     382   *
     383   * An array with all the data (by mPAY24) for this transaction (STATUS, CURRENCY, PRICE, APPR_CODE, etc) will be returned.
     384   * Possible values for the STATUS attribute:
     385   *
     386   * * RESERVED - in case the authorization was successful but not cleared yet
     387   * * BILLED - in case the authorization was successful and amount was cleared
     388   * * CREDITED - in case amount was credited
     389   * * REVERSED - in case the transaction was canceled
     390   * * SUSPENDED - in case the transaction is not fully compleated yet
     391   * * NOT FOUND - in case there is not such a transaction in the mPAY24 database
     392   * * ERROR - in case the transaction was not successful
     393   * @param             string              $tid                          The transaction ID (in your shop), for the transaction you are asking for
     394   * @return            array
     395   */
     396  function updateTransactionStatus($tid) {
     397    if(!$this->mPay24Api)
     398      die("You are not allowed to define a constructor in the child class of MPay24Shop!");
     399
     400    $transaction = $this->getTransaction($tid);
     401
     402    $this->checkTransaction($transaction);
     403
     404    if(!$transaction->MPAYTID || !is_numeric($transaction->MPAYTID)) {
     405      $tidTransactionStatusResult = $this->mPay24Api->TransactionStatus(null, $tid);
     406
     407      if($this->mPay24Api->getDebug()) {
     408        $this->write_log("TidTransactionStatus",
     409                    "REQUEST to " . $this->mPay24Api->getEtpURL() . " - ".str_replace("><", ">\n<", $this->mPay24Api->getRequest())."\n");
     410        $this->write_log("TidTransactionStatus",
     411                    "RESPONSE - ".str_replace("><", ">\n<", $this->mPay24Api->getResponse())."\n");
     412      }
     413
     414      if($tidTransactionStatusResult->getParam("SHIPPING_ADDR")) {
     415        $order = new DOMDocument();
     416        $order->loadXML($tidTransactionStatusResult->getParam("SHIPPING_ADDR"));
     417      }
     418
     419      if(isset($order)) {
     420        $shipping = $order->getElementsByTagName("Shipping")->item(0);
     421        $shippingConfirmed = $shipping->getAttribute("confirmed");
     422
     423        if($shippingConfirmed == "false") {
     424          $tidTransactionStatusResult->setParam("shippingConfirmed", false);
     425          $tidTransactionStatusResult->setParam("SHIPP_NAME", $order->getElementsByTagName("Shipping")->item(0)
    446426                                                                                    ->getElementsByTagName("Name")->item(0)->nodeValue);
    447                         $tidTransactionStatusResult->setParam("SHIPP_STREET", $order->getElementsByTagName("Shipping")->item(0)
    448                                                                                         ->getElementsByTagName("Street")->item(0)->nodeValue);
    449                         if($tidTransactionStatusResult->getParam("SHIPP_STREET2"))
    450                             $tidTransactionStatusResult->setParam("SHIPP_STREET2", $order->getElementsByTagName("Shipping")->item(0)
    451                                                                                         ->getElementsByTagName("Street2")->item(0)->nodeValue);
    452                         $tidTransactionStatusResult->setParam("SHIPP_ZIP", $order->getElementsByTagName("Shipping")->item(0)
     427          $tidTransactionStatusResult->setParam("SHIPP_STREET", $order->getElementsByTagName("Shipping")->item(0)
     428                                                                                    ->getElementsByTagName("Street")->item(0)->nodeValue);
     429          if($tidTransactionStatusResult->getParam("SHIPP_STREET2"))
     430            $tidTransactionStatusResult->setParam("SHIPP_STREET2", $order->getElementsByTagName("Shipping")->item(0)
     431                                                                                    ->getElementsByTagName("Street2")->item(0)->nodeValue);
     432            $tidTransactionStatusResult->setParam("SHIPP_ZIP", $order->getElementsByTagName("Shipping")->item(0)
    453433                                                                                    ->getElementsByTagName("Zip")->item(0)->nodeValue);
    454                         $tidTransactionStatusResult->setParam("SHIPP_CITY", $order->getElementsByTagName("Shipping")->item(0)
     434            $tidTransactionStatusResult->setParam("SHIPP_CITY", $order->getElementsByTagName("Shipping")->item(0)
    455435                                                                                    ->getElementsByTagName("City")->item(0)->nodeValue);
    456                         $tidTransactionStatusResult->setParam("SHIPP_COUNTRY", $order->getElementsByTagName("Shipping")->item(0)
     436            $tidTransactionStatusResult->setParam("SHIPP_COUNTRY", $order->getElementsByTagName("Shipping")->item(0)
    457437                                                                                    ->getElementsByTagName("Country")->item(0)->getAttribute("code"));
    458                     } else
    459                         $tidTransactionStatusResult->setParam("shippingConfirmed", true);
    460                 } else
    461                     $tidTransactionStatusResult->setParam("shippingConfirmed", true);
    462                 return $tidTransactionStatusResult;
    463             } else{
    464                 $mPAYTidTransactionStatusResult = $this->mPay24Api->TransactionStatus($transaction->MPAYTID, null);
    465                
    466                 if($this->mPay24Api->getDebug()) {
    467                     $this->write_log("mPAYTidTransactionStatus",
    468                                 "REQUEST to " . $this->mPay24Api->getEtpURL() . " - ".str_replace("><", ">\n<", $this->mPay24Api->getRequest())."\n");
    469                     $this->write_log("mPAYTidTransactionStatus",
    470                                 "RESPONSE - ".str_replace("><", ">\n<", $this->mPay24Api->getResponse())."\n");
    471                 }
    472                
    473                 if($mPAYTidTransactionStatusResult->getParam("SHIPPING_ADDR")) {
    474                         $order = new DOMDocument();
    475                     $order->loadXML($mPAYTidTransactionStatusResult->getParam("SHIPPING_ADDR"));
    476                 }
    477                
    478                 if(isset($order)) {                   
    479                     $shipping = $order->getElementsByTagName("Shipping")->item(0);
    480                     $shippingConfirmed = $shipping->getAttribute("confirmed");
    481                                        
    482                     if($shippingConfirmed == "false") {
    483                         $mPAYTidTransactionStatusResult->setParam("shippingConfirmed", false);
    484                         $mPAYTidTransactionStatusResult->setParam("SHIPP_NAME", $order->getElementsByTagName("Shipping")->item(0)
     438        } else
     439            $tidTransactionStatusResult->setParam("shippingConfirmed", true);
     440      } else
     441        $tidTransactionStatusResult->setParam("shippingConfirmed", true);
     442
     443      return $tidTransactionStatusResult;
     444    } else{
     445      $mPAYTidTransactionStatusResult = $this->mPay24Api->TransactionStatus($transaction->MPAYTID, null);
     446
     447      if($this->mPay24Api->getDebug()) {
     448        $this->write_log("mPAYTidTransactionStatus",
     449                      "REQUEST to " . $this->mPay24Api->getEtpURL() . " - ".str_replace("><", ">\n<", $this->mPay24Api->getRequest())."\n");
     450        $this->write_log("mPAYTidTransactionStatus",
     451                      "RESPONSE - ".str_replace("><", ">\n<", $this->mPay24Api->getResponse())."\n");
     452      }
     453
     454      if($mPAYTidTransactionStatusResult->getParam("SHIPPING_ADDR")) {
     455        $order = new DOMDocument();
     456        $order->loadXML($mPAYTidTransactionStatusResult->getParam("SHIPPING_ADDR"));
     457      }
     458
     459      if(isset($order)) {
     460        $shipping = $order->getElementsByTagName("Shipping")->item(0);
     461        $shippingConfirmed = $shipping->getAttribute("confirmed");
     462
     463        if($shippingConfirmed == "false") {
     464          $mPAYTidTransactionStatusResult->setParam("shippingConfirmed", false);
     465          $mPAYTidTransactionStatusResult->setParam("SHIPP_NAME", $order->getElementsByTagName("Shipping")->item(0)
    485466                                                                                    ->getElementsByTagName("Name")->item(0)->nodeValue);
    486                         $mPAYTidTransactionStatusResult->setParam("SHIPP_STREET", $order->getElementsByTagName("Shipping")->item(0)
    487                                                                                         ->getElementsByTagName("Street")->item(0)->nodeValue);
    488                         $mPAYTidTransactionStatusResult->setParam("SHIPP_STREET2", $order->getElementsByTagName("Shipping")->item(0)
    489                                                                                         ->getElementsByTagName("Street2")->item(0)->nodeValue);
    490                         $mPAYTidTransactionStatusResult->setParam("SHIPP_ZIP", $order->getElementsByTagName("Shipping")->item(0)
     467          $mPAYTidTransactionStatusResult->setParam("SHIPP_STREET", $order->getElementsByTagName("Shipping")->item(0)
     468                                                                                    ->getElementsByTagName("Street")->item(0)->nodeValue);
     469          $mPAYTidTransactionStatusResult->setParam("SHIPP_STREET2", $order->getElementsByTagName("Shipping")->item(0)
     470                                                                                    ->getElementsByTagName("Street2")->item(0)->nodeValue);
     471          $mPAYTidTransactionStatusResult->setParam("SHIPP_ZIP", $order->getElementsByTagName("Shipping")->item(0)
    491472                                                                                    ->getElementsByTagName("Zip")->item(0)->nodeValue);
    492                         $mPAYTidTransactionStatusResult->setParam("SHIPP_CITY", $order->getElementsByTagName("Shipping")->item(0)
     473          $mPAYTidTransactionStatusResult->setParam("SHIPP_CITY", $order->getElementsByTagName("Shipping")->item(0)
    493474                                                                                    ->getElementsByTagName("City")->item(0)->nodeValue);
    494                         $mPAYTidTransactionStatusResult->setParam("SHIPP_COUNTRY", $order->getElementsByTagName("Shipping")->item(0)
     475          $mPAYTidTransactionStatusResult->setParam("SHIPP_COUNTRY", $order->getElementsByTagName("Shipping")->item(0)
    495476                                                                                    ->getElementsByTagName("Country")->item(0)->getAttribute("code"));
    496                     } else
    497                         $mPAYTidTransactionStatusResult->setParam("shippingConfirmed", true);
    498                 } else
    499                     $mPAYTidTransactionStatusResult->setParam("shippingConfirmed", true);
    500                 return $mPAYTidTransactionStatusResult;
    501             }
    502 
    503         }
    504        
    505         /**
    506          * @param         STRING                            The transaction ID, for the transaction you want to clear
    507          * @param         INTEGER                         The amount you want to clear multiply by 100
    508          */
    509         function clearAmount($tid, $amount) {
    510             if(!$this->mPay24Api)
    511                 die("You are not allowed to define a constructor in the child class of MPay24Shop!");
    512                
    513             $transaction = $this->getTransaction($tid);
    514            
    515             $this->checkTransaction($transaction);
    516            
    517             $mPAYTid = $transaction->MPAYTID;
    518             $currency = $transaction->CURRENCY;
    519            
    520             if(!$mPAYTid)
    521                 $this->mPay24Api->dieWithMsg("The transaction '$tid' you want to clear with the mPAYTid '$mPAYTid' does not exist in the mPAY24 data base!");
    522            
    523             if(!$amount || !is_numeric($amount))
    524                 $this->mPay24Api->dieWithMsg("The amount '$amount' you are trying to clear is not valid!");
    525                
    526             if(!$currency || strlen($currency) != 3)
    527                 $this->mPay24Api->dieWithMsg("The currency code '$currency' for the amount you are trying to clear is not valid (3-digit ISO-Currency-Code)!");
    528            
    529             $clearAmountResult = $this->mPay24Api->ManualClear($mPAYTid, $amount, $currency);
    530            
    531             if($this->mPay24Api->getDebug()) {
    532                 $this->write_log("ClearAmount",
    533                                 "REQUEST to " . $this->mPay24Api->getEtpURL() . " - ".str_replace("><", ">\n<", $this->mPay24Api->getRequest())."\n");
    534                 $this->write_log("ClearAmount",
    535                                 "RESPONSE - ".str_replace("><", ">\n<", $this->mPay24Api->getResponse())."\n");
    536             }
    537            
    538             return $clearAmountResult;
    539         }
    540        
    541        
    542        
    543         /**
    544          * @param         STRING                            The transaction ID, for the transaction you want to credit
    545          * @param         INTEGER                         The amount you want to credit multiply by 100
    546          */
    547         function creditAmount($tid, $amount) {
    548             if(!$this->mPay24Api)
    549                 die("You are not allowed to define a constructor in the child class of MPay24Shop!");
    550                
    551             $transaction = $this->getTransaction($tid);
    552            
    553             $this->checkTransaction($transaction);
    554            
    555             $mPAYTid = $transaction->MPAYTID;
    556             $currency = $transaction->CURRENCY;
    557             $customer = $transaction->CUSTOMER;
    558            
    559             if(!$mPAYTid)
    560                 $this->mPay24Api->dieWithMsg("The transaction '$tid' you want to credit with the mPAYTid '$mPAYTid' does not exist in the mPAY24 data base!");
    561            
    562             if(!$amount || !is_numeric($amount))
    563                 $this->mPay24Api->dieWithMsg("The amount '$amount' you are trying to credit is not valid!");
    564                
    565             if(!$currency || strlen($currency) != 3)
    566                 $this->mPay24Api->dieWithMsg("The currency code '$currency' for the amount you are trying to credit is not valid (3-digit ISO-Currency-Code)!");
    567            
    568             $creditAmountResult = $this->mPay24Api->ManualCredit($mPAYTid, $amount, $currency, $customer);
    569            
    570             if($this->mPay24Api->getDebug()) {
    571                 $this->write_log("CreditAmount",
    572                                 "REQUEST to " . $this->mPay24Api->getEtpURL() . " - ".str_replace("><", ">\n<", $this->mPay24Api->getRequest())."\n");
    573                 $this->write_log("CreditAmount",
    574                                 "RESPONSE - ".str_replace("><", ">\n<", $this->mPay24Api->getResponse())."\n");
    575             }
    576            
    577             return $creditAmountResult;
    578         }
    579        
    580        
    581        
    582         /**
    583          * @param         STRING                            The transaction ID, for the transaction you want to cancel
    584          */
    585         function cancelTransaction($tid) {
    586             if(!$this->mPay24Api)
    587                 die("You are not allowed to define a constructor in the child class of MPay24Shop!");
    588                
    589             $transaction = $this->getTransaction($tid);
    590            
    591             $this->checkTransaction($transaction);
    592            
    593             $mPAYTid = $transaction->MPAYTID;
    594            
    595             if(!$mPAYTid)
    596                 $this->mPay24Api->dieWithMsgie("The transaction '$tid' you want to cancel with the mPAYTid '$mPAYTid' does not exist in the mPAY24 data base!");
    597            
    598             $cancelTransactionResult = $this->mPay24Api->ManualReverse($mPAYTid);
    599            
    600             if($this->mPay24Api->getDebug()) {
    601                 $this->write_log("CancelTransaction",
    602                                 "REQUEST to " . $this->mPay24Api->getEtpURL() . " - ".str_replace("><", ">\n<", $this->mPay24Api->getRequest())."\n");
    603                 $this->write_log("CancelTransaction",
    604                                 "RESPONSE - ".str_replace("><", ">\n<", $this->mPay24Api->getResponse())."\n");
    605             }
    606            
    607             return $cancelTransactionResult;
    608         }
    609        
    610         /**
    611          * @abstract                                    Check if the a transaction is created, whether the object is from type Transaction
    612          *                                                 and whether the mandatory settings (TID and PRICE) of a transaction are setted
    613          * @param         Transaction                     The transaction, which is to be checked
    614          */
    615         private function checkTransaction($transaction) {
    616             if(!$transaction || !$transaction instanceof Transaction)
    617                 $this->mPay24Api->dieWithMsg("To be able to use the MPay24Api you must create a Transaction object, which contains at least TID and PRICE!");
    618             else if(!$transaction->TID)
    619                 $this->mPay24Api->dieWithMsg("The Transaction must contain TID!");
    620             else if(!$transaction->PRICE)
    621                 $this->mPay24Api->dieWithMsg("The Transaction must contain PRICE!");
    622         }
    623     }
    624    
    625     define("TRANSACTION_PROPERTIES", "SECRET,TID,STATUS,MPAYTID,APPR_CODE,P_TYPE,
    626                                     BRAND,PRICE,CURRENCY,OPERATION,LANGUAGE,
    627                                     USER_FIELD,ORDERDESC,CUSTOMER,CUSTOMER_EMAIL,
    628                                     CUSTOMER_ID,PROFILE_STATUS,FILTER_STATUS,TSTATUS");
    629 
    630     class Transaction {
    631        
    632         /**
    633          * @abstract    PARAMETER                        VALUE(s), description
    634          *
    635          *                 STRING                             STATUS : OK, ERROR
    636          *
    637          *                 STRING                             OPERATION = CONFIRMATION
    638          *
    639          *                 STRING                             TID : length <= 32
    640          *
    641          *                 STRING                             TRANSACTION_STATUS : RESERVED, BILLED, REVERSED, CREDITED, ERROR
    642          *
    643          *                 INTEGER                         PRICE : length = 11 (e. g. "10" = "0,10")
    644          *
    645          *                 STRING                             CURRENCY : length = 3 (ISO currency code, e. g. "EUR")
    646          *
    647          *                 STRING                             P_TYPE : CC, ELV, EPS, GIROPAY, MAESTRO, MIA, PB, PSC, QUICK
    648          *
    649          *                 STRING                             BRAND : AMEX, DINERS, JCB, MASTERCARD, VISA, ATOS, HOBEX-AT, HOBEX-DE,
    650          *                                                 HOBEX-NL, ARZ, BA, ERSTE, HYPO, RZB, ONE, T-MOBILE
    651          *
    652          *                 INTEGER                         MPAYTID : length = 11
    653          *
    654          *                 STRING                             USER_FIELD
    655          *
    656          *                 STRING                             ORDERDESC
    657          *
    658          *                 STRING                             CUSTOMER
    659          *
    660          *                 STRING                             CUSTOMER_EMAIL
    661          *
    662          *                 STRING                             LANGUAGE : length = 2
    663          *
    664          *                 STRING                             CUSTOMER_ID : length = 11
    665          *
    666          *                 STRING                             PROFILE_STATUS : IGNORED, USED, ERROR, CREATED, UPDATED, DELETED 
    667          *
    668          *                 STRING                             FILTER_STATUS
    669          *
    670          *              STRING                             APPR_CODE
    671          */
    672         var $allowedProperties  = array();
    673         /**
    674          *
    675          * @var            INTEGER                            The ID of a transaction
    676          */
    677         var $properties            = array();
    678        
    679         /**
    680          * @abstract                                    Create a transaction object and set the allowed properties from the TRANSACTION_PROPERTIES
    681          * @uses        CONSTANT                        TRANSACTION_PROPERTIES
    682          * @param         INTEGER                             The ID of a transaction
    683          */
    684         function Transaction($tid) {
    685             $this->allowedProperties =  explode(",", preg_replace('/\s*/m', '', TRANSACTION_PROPERTIES));
    686             $this->TID = $tid;
    687         }
    688        
    689         public function __get($property) {
    690             if(!in_array($property, $this->allowedProperties))
    691                 die("The transaction's property " . $property . ", you want to get is not defined!");
    692             if(isset($this->properties[$property]))
    693                 return $this->properties[$property];
    694             else
    695                 return false;
    696         }
    697        
    698         public function __set($property, $value) {
    699             if(!in_array($property, $this->allowedProperties))
    700                 die("The transaction's property " . $property . ", you want to set is not defined!");
    701             $this->properties[$property] = $value;
    702         }
    703        
    704         /**
    705          * @param         ARRAY                            All the allowed properties for this transaction
    706          */
    707         protected function setProperties($args) {
    708             $this->properties = $args;
    709         }
    710        
    711         /**
    712          * @return        ARRAY                            All the allowed properties for this transaction
    713          */
    714         protected function getProperties() {
    715             return $this->properties;
    716         }
    717     }
     477        } else
     478          $mPAYTidTransactionStatusResult->setParam("shippingConfirmed", true);
     479      } else
     480        $mPAYTidTransactionStatusResult->setParam("shippingConfirmed", true);
     481
     482      return $mPAYTidTransactionStatusResult;
     483    }
     484  }
     485
     486  /**
     487   * Clear an amount of an authorized transaction
     488   * @param             string              $tid                          The transaction ID, for the transaction you want to clear
     489   * @param             int                 $amount                       The amount you want to clear multiply by 100
     490   */
     491  function clearAmount($tid, $amount) {
     492    if(!$this->mPay24Api)
     493      die("You are not allowed to define a constructor in the child class of MPay24Shop!");
     494
     495    $transaction = $this->getTransaction($tid);
     496
     497    $this->checkTransaction($transaction);
     498
     499    $mPAYTid = $transaction->MPAYTID;
     500    $currency = $transaction->CURRENCY;
     501
     502    if(!$mPAYTid)
     503      $this->mPay24Api->dieWithMsg("The transaction '$tid' you want to clear with the mPAYTid '$mPAYTid' does not exist in the mPAY24 data base!");
     504
     505    if(!$amount || !is_numeric($amount))
     506      $this->mPay24Api->dieWithMsg("The amount '$amount' you are trying to clear is not valid!");
     507
     508    if(!$currency || strlen($currency) != 3)
     509      $this->mPay24Api->dieWithMsg("The currency code '$currency' for the amount you are trying to clear is not valid (3-digit ISO-Currency-Code)!");
     510
     511    $clearAmountResult = $this->mPay24Api->ManualClear($mPAYTid, $amount, $currency);
     512
     513    if($this->mPay24Api->getDebug()) {
     514      $this->write_log("ClearAmount",
     515                    "REQUEST to " . $this->mPay24Api->getEtpURL() . " - ".str_replace("><", ">\n<", $this->mPay24Api->getRequest())."\n");
     516      $this->write_log("ClearAmount",
     517                    "RESPONSE - ".str_replace("><", ">\n<", $this->mPay24Api->getResponse())."\n");
     518    }
     519
     520    return $clearAmountResult;
     521  }
     522
     523  /**
     524   * Credit an amount of a billed transaction
     525   * @param             string              $tid                          The transaction ID, for the transaction you want to credit
     526   * @param             int                 $amount                       The amount you want to credit multiply by 100
     527   */
     528  function creditAmount($tid, $amount) {
     529    if(!$this->mPay24Api)
     530      die("You are not allowed to define a constructor in the child class of MPay24Shop!");
     531
     532    $transaction = $this->getTransaction($tid);
     533
     534    $this->checkTransaction($transaction);
     535
     536    $mPAYTid = $transaction->MPAYTID;
     537    $currency = $transaction->CURRENCY;
     538    $customer = $transaction->CUSTOMER;
     539
     540    if(!$mPAYTid)
     541      $this->mPay24Api->dieWithMsg("The transaction '$tid' you want to credit with the mPAYTid '$mPAYTid' does not exist in the mPAY24 data base!");
     542
     543    if(!$amount || !is_numeric($amount))
     544      $this->mPay24Api->dieWithMsg("The amount '$amount' you are trying to credit is not valid!");
     545
     546    if(!$currency || strlen($currency) != 3)
     547      $this->mPay24Api->dieWithMsg("The currency code '$currency' for the amount you are trying to credit is not valid (3-digit ISO-Currency-Code)!");
     548
     549    $creditAmountResult = $this->mPay24Api->ManualCredit($mPAYTid, $amount, $currency, $customer);
     550
     551    if($this->mPay24Api->getDebug()) {
     552      $this->write_log("CreditAmount",
     553                    "REQUEST to " . $this->mPay24Api->getEtpURL() . " - ".str_replace("><", ">\n<", $this->mPay24Api->getRequest())."\n");
     554      $this->write_log("CreditAmount",
     555                    "RESPONSE - ".str_replace("><", ">\n<", $this->mPay24Api->getResponse())."\n");
     556    }
     557
     558    return $creditAmountResult;
     559  }
     560
     561  /**
     562   * Cancel a authorized transaction
     563   * @param             string              $tid                          The transaction ID, for the transaction you want to cancel
     564   */
     565  function cancelTransaction($tid) {
     566    if(!$this->mPay24Api)
     567      die("You are not allowed to define a constructor in the child class of MPay24Shop!");
     568
     569    $transaction = $this->getTransaction($tid);
     570
     571    $this->checkTransaction($transaction);
     572
     573    $mPAYTid = $transaction->MPAYTID;
     574
     575    if(!$mPAYTid)
     576      $this->mPay24Api->dieWithMsgie("The transaction '$tid' you want to cancel with the mPAYTid '$mPAYTid' does not exist in the mPAY24 data base!");
     577
     578    $cancelTransactionResult = $this->mPay24Api->ManualReverse($mPAYTid);
     579
     580    if($this->mPay24Api->getDebug()) {
     581      $this->write_log("CancelTransaction",
     582                    "REQUEST to " . $this->mPay24Api->getEtpURL() . " - ".str_replace("><", ">\n<", $this->mPay24Api->getRequest())."\n");
     583      $this->write_log("CancelTransaction",
     584                    "RESPONSE - ".str_replace("><", ">\n<", $this->mPay24Api->getResponse())."\n");
     585    }
     586
     587    return $cancelTransactionResult;
     588  }
     589
     590  /**
     591   * Check if the a transaction is created, whether the object is from type Transaction and whether the mandatory settings (TID and PRICE) of a transaction are setted
     592   * @param             Transaction         $tid                          The transaction, which should be checked
     593   */
     594  private function checkTransaction($transaction) {
     595    if(!$transaction || !$transaction instanceof Transaction)
     596      $this->mPay24Api->dieWithMsg("To be able to use the MPay24Api you must create a Transaction object, which contains at least TID and PRICE!");
     597    else if(!$transaction->TID)
     598      $this->mPay24Api->dieWithMsg("The Transaction must contain TID!");
     599    else if(!$transaction->PRICE)
     600      $this->mPay24Api->dieWithMsg("The Transaction must contain PRICE!");
     601  }
     602}
     603
     604/**
     605 * The properties, which are allowed for a transaction
     606 * @const               TRANSACTION_PROPERTIES
     607 */
     608define("TRANSACTION_PROPERTIES", "SECRET,TID,STATUS,MPAYTID,APPR_CODE,P_TYPE,
     609                                  BRAND,PRICE,CURRENCY,OPERATION,LANGUAGE,
     610                                  USER_FIELD,ORDERDESC,CUSTOMER,CUSTOMER_EMAIL,
     611                                  CUSTOMER_ID,PROFILE_STATUS,FILTER_STATUS,TSTATUS");
     612
     613/**
     614 * The Transaction class allows you to set and get different trnasaction's properties - see details
     615 *
     616 * TYPE:                PARAMETER -         VALUE(s), description
     617 *
     618 * * STRING:            STATUS -             OK, ERROR
     619 * * STRING:            OPERATION -          CONFIRMATION
     620 * * STRING:            TID -                length <= 32
     621 * * STRING:            TRANSACTION_STATUS - RESERVED, BILLED, REVERSED, CREDITED, ERROR
     622 * * INT:               PRICE -              length = 11 (e. g. "10" = "0,10")
     623 * * STRING:            CURRENCY -           length = 3 (ISO currency code, e. g. "EUR")
     624 * * STRING:            P_TYPE -             CC, ELV, EPS, GIROPAY, MAESTRO, PB, PSC, QUICK, etc
     625 * * STRING:            BRAND -              AMEX, DINERS, JCB, MASTERCARD, VISA, ATOS, HOBEX-AT, HOBEX-DE, etc
     626 * * INT:               MPAYTID -            length = 11
     627 * * STRING:            USER_FIELD
     628 * * STRING:            ORDERDESC
     629 * * STRING:            CUSTOMER
     630 * * STRING:            CUSTOMER_EMAIL
     631 * * STRING:            LANGUAGE -           length = 2
     632 * * STRING:            CUSTOMER_ID -        length = 11
     633 * * STRING:            PROFILE_STATUS -     IGNORED, USED, ERROR, CREATED, UPDATED, DELETED
     634 * * STRING:            FILTER_STATUS
     635 * * STRING:            APPR_CODE
     636 * @author              mPAY24 GmbH <[email protected]>
     637 * @version             $Id: MPay24Shop.php 5522 2013-06-24 13:08:35Z anna $
     638 * @filesource          MPay24Shop.php
     639 * @license             http://ec.europa.eu/idabc/eupl.html EUPL, Version 1.1
     640 */
     641class Transaction {
     642  /**
     643   * An array, which contains the allowed properties for an transaction
     644   * @var               $allowedProperties
     645   */
     646  var $allowedProperties  = array();
     647  /**
     648   * An array, which contains the set properties for this transaction object
     649   * @var               $allowedProperties
     650   */
     651  var $properties            = array();
     652
     653  /**
     654   * Create a transaction object and set the allowed properties from the TRANSACTION_PROPERTIES
     655   * @param             string              $tid                          The ID of a transaction
     656   */
     657  function Transaction($tid) {
     658    $this->allowedProperties =  explode(",", preg_replace('/\s*/m', '', TRANSACTION_PROPERTIES));
     659    $this->TID = $tid;
     660  }
     661
     662  /**
     663   * Get the property of the Transaction object
     664   * @param             string              $property                     The name of the property, which is searched
     665   * @return            string|bool
     666   */
     667  public function __get($property) {
     668    if(!in_array($property, $this->allowedProperties))
     669      die("The transaction's property " . $property . ", you want to get is not defined!");
     670
     671    if(isset($this->properties[$property]))
     672      return $this->properties[$property];
     673    else
     674      return false;
     675  }
     676
     677  /**
     678   * Set the property of the Transaction object
     679   * @param             string              $property                     The name of the property you want to set, see TRANSACTION_PROPERTIES
     680   * @param             mixed               $value                        The value of the property you want to set
     681   */
     682  public function __set($property, $value) {
     683    if(!in_array($property, $this->allowedProperties))
     684      die("The transaction's property " . $property . ", you want to set is not defined!");
     685    $this->properties[$property] = $value;
     686  }
     687
     688  /**
     689   * Set all the allowed properties for this transaction
     690   * @param             array               $args                         An array with the allowed properties
     691   */
     692  protected function setProperties($args) {
     693    $this->properties = $args;
     694  }
     695
     696  /**
     697   * Get all the allowed properties for this transaction
     698   * @return            array
     699   */
     700  protected function getProperties() {
     701    return $this->properties;
     702  }
     703}
     704
     705/**
     706 * The abstract MPay24flexLINK class provides abstract functions, which are used from the other functions in order to create a flexLINK
     707 *
     708 * @author              mPAY24 GmbH <[email protected]>
     709 * @version             $Id: MPay24Shop.php 5522 2013-06-24 13:08:35Z anna $
     710 * @filesource          MPay24Shop.php
     711 * @license             http://ec.europa.eu/idabc/eupl.html EUPL, Version 1.1
     712 */
     713abstract class MPay24flexLINK {
     714  /**
     715   * The mPAY24API Object, you are going to work with
     716   * @var               $mPay24Api
     717   */
     718  var $mPay24Api = null;
     719
     720  /**
     721   * The constructor, which sets all the initial values to be able making flexLINK transactions. In order to be able use this functionality, you should contact mPAY24 first.
     722   * @param             string              $spid                         SPID, supported by mPAY24
     723   * @param             string              $password                     The flexLINK password, supported by mPAY24
     724   * @param             bool                $test                         TRUE - when you want to use the TEST system
     725   *
     726   *                                                                      FALSE - when you want to use the LIVE system
     727   * @param             bool                $debug                        TRUE - when you want to write log files
     728   *
     729   */
     730  function MPay24flexLINK($spid, $password, $test, $debug=false) {
     731    if(!is_bool($test))
     732      die("The test parameter '$test' you have given is wrong, it must be boolean value 'true' or 'false'!");
     733
     734    if(!is_bool($debug))
     735      die("The debug parameter '$debug' you have given is wrong, it must be boolean value 'true' or 'false'!");
     736
     737    $this->mPay24Api = new MPay24Api();
     738
     739    $this->mPay24Api->configureFlexLINK($spid, $password, $test);
     740    $this->mPay24Api->setDebug($debug);
     741
     742    if (version_compare(phpversion(), '5.0.0', '<')===true || !in_array('mcrypt', get_loaded_extensions())) {
     743      $this->mPay24Api->printMsg("ERROR: You don't meet the needed requirements for this example shop.<br>");
     744
     745      if(version_compare(phpversion(), '5.0.0', '<')===true)
     746        $this->mPay24Api->printMsg("You need PHP version 5.0.0 or newer!<br>");
     747      if(!in_array('mcrypt', get_loaded_extensions()))
     748        $this->mPay24Api->printMsg("You need mcrypt extension!<br>");
     749       $this->mPay24Api->dieWithMsg("Please load the required extensions!");
     750    }
     751  }
     752
     753  /**
     754   * Encrypt the parameters you want to post to mPAY24 - see details
     755   * @param             string              $invoice_id                   The invoice ID of the transaction
     756   * @param             string              $amount                       The amount which should be invoiced in 12.34
     757   * @param             string              $currency                     length = 3 (ISO currency code, e. g. "EUR")
     758   * @param             string              $language                     length = 2 (ISO currency code, e. g. "DE")
     759   * @param             string              $user_field                   A place hollder for free chosen user information
     760   * @param             string              $description                  Description of the product, the invoice is for
     761   * @param             string              $mode                         BillingAddress Mode (ReadWrite or ReadOnly)
     762   * @param             string              $name                         Name of the customer
     763   * @param             string              $street                       Billing address street
     764   * @param             string              $street2                      Billing address street2
     765   * @param             string              $zip                          Billing address zip
     766   * @param             string              $city                         Billing address city
     767   * @param             string              $country                      Billing address country, length = 2 (ISO country code, e. g. "AT")
     768   * @param             string              $email                        Billing address e-mail
     769   * @param             string              $success                      Success-URL
     770   * @param             string              $error                        Error-URL
     771   * @param             string              $confirmation                 Confirmation-URL
     772   * @param             string              $invoice_idVar                Default = IID
     773   * @param             string              $amountVar                    Default = AMO
     774   * @param             string              $currencyVar                  Default = CUR
     775   * @param             string              $languageVar                  Default = LAN
     776   * @param             string              $user_fieldVar                Default = USR
     777   * @param             string              $descriptionVar               Default = DES
     778   * @param             string              $modeVar                      Default = MOD
     779   * @param             string              $nameVar                      Default = NAM
     780   * @param             string              $streetVar                    Default = ST1
     781   * @param             string              $street2Var                   Default = ST2
     782   * @param             string              $zipVar                       Default = ZIP
     783   * @param             string              $cityVar                      Default = CIT
     784   * @param             string              $countryVar                   Default = COU
     785   * @param             string              $emailVar                     Default = EML
     786   * @param             string              $successVar                   Default = SUC
     787   * @param             string              $errorVar                     Default = ERR
     788   * @param             string              $confirmationVar              Default = CON
     789   * @return            string
     790   */
     791  function getEncryptedParams(//parameter values
     792                              $invoice_id,
     793                              $amount,
     794                              $currency=NULL,
     795                              $language=NULL,
     796                              $user_field=NULL,
     797                              $description=NULL,
     798                              $mode=NULL,
     799                              $name=NULL,
     800                              $street=NULL,
     801                              $street2=NULL,
     802                              $zip=NULL,
     803                              $city=NULL,
     804                              $country=NULL,
     805                              $email=NULL,
     806                              $success=NULL,
     807                              $error=NULL,
     808                              $confirmation=NULL,
     809                              //parameters names
     810                              $invoice_idVar="IID",
     811                              $amountVar="AMO",
     812                              $currencyVar="CUR",
     813                              $languageVar="LAN",
     814                              $user_fieldVar="USR",
     815                              $descriptionVar="DES",
     816                              $modeVar="MOD",
     817                              $nameVar="NAM",
     818                              $streetVar="ST1",
     819                              $street2Var="ST2",
     820                              $zipVar="ZIP",
     821                              $cityVar="CIT",
     822                              $countryVar="COU",
     823                              $emailVar="EML",
     824                              $successVar="SUC",
     825                              $errorVar="ERR",
     826                              $confirmationVar="CON") {
     827    if(!$this->mPay24Api)
     828      die("You are not allowed to define a constructor in the child class of MPay24flexLINK!");
     829
     830    $params[$invoice_idVar] = $invoice_id;
     831    $params[$amountVar] = $amount;
     832
     833    if($currency == NULL)
     834      $currency = "EUR";
     835
     836    $params[$currencyVar] = $currency;
     837
     838    if($language == NULL)
     839      $language = "DE";
     840
     841    $params[$languageVar] = $language;
     842    $params[$user_fieldVar] = $user_field;
     843
     844    if($description == NULL)
     845      $description = "Rechnungsnummer:";
     846
     847    $params[$descriptionVar] = $description;
     848
     849    if($mode == NULL)
     850      $mode = "ReadWrite";
     851
     852    $params[$modeVar] = $mode;
     853
     854    $params[$nameVar] = $name;
     855    $params[$streetVar] = $street;
     856    $params[$street2Var] = $street2;
     857    $params[$zipVar] = $zip;
     858    $params[$cityVar] = $city;
     859
     860    if($country == NULL)
     861      $country = "AT";
     862
     863    $params[$countryVar] = $country;
     864
     865    $params[$emailVar] = $email;
     866    $params[$successVar] = $success;
     867    $params[$errorVar] = $error;
     868    $params[$confirmationVar] = $confirmation;
     869
     870    foreach($params as $key => $value)
     871      if($this->mPay24Api->getDebug())
     872        $this->write_flexLINK_log("flexLINK:\t\t\tParameters: $key = $value\n");
     873
     874    $parameters = $this->mPay24Api->flexLINK($params);
     875
     876    if($this->mPay24Api->getDebug())
     877      $this->write_flexLINK_log("flexLINK:\t\t\tEncrypted parameters: $parameters\n");
     878
     879    return $parameters;
     880  }
     881
     882  /**
     883   * Get the whole URL (flexLINK) to the mPAY24 pay page, used to pay an invoice
     884   * @param             string              $encryptedParams              The encrypted parameters, returned by the function getEncryptedParams
     885   * @return            stringAn URL to pay
     886   */
     887  public function getPayLink($encryptedParams) {
     888    if($this->mPay24Api->getDebug())
     889      $this->write_flexLINK_log("flexLINK:\t\t\tURL: https://".$this->mPay24Api->getFlexLINKSystem().".mpay24.com/app/bin/checkout/".$this->mPay24Api->getSPID()."/$encryptedParams\n");
     890
     891    return "https://".$this->mPay24Api->getFlexLINKSystem().".mpay24.com/app/bin/checkout/".$this->mPay24Api->getSPID()."/$encryptedParams";
     892  }
     893
     894  /**
     895   * Write a flexLINK log into a file, file system, data base
     896   * @param             string              $info_to_log                  The information, which is to log: request, response, etc.
     897   */
     898  abstract function write_flexLINK_log($info_to_log);
     899}
    718900?>
  • woocommerce-mpay24-gateway/trunk/MPay24/doc/errors.html

    r636654 r803175  
    1 <?xml version="1.0" encoding="iso-8859-1"?>
    2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    3 <!--
    4     /**
    5      * @author              [email protected]
    6      * @version             $Id: errors.html 5217 2012-10-16 05:27:43Z anna $
    7      * @filesource          errors.html
    8      * @license             http://ec.europa.eu/idabc/eupl.html EUPL, Version 1.1
    9      */
    10  -->
    11   <html xmlns="http://www.w3.org/1999/xhtml">
    12         <head>
    13             <!-- template designed by Marco Von Ballmoos -->
    14             <title>phpDocumentor Parser Errors and Warnings</title>
    15             <link rel="stylesheet" href="media/stylesheet.css" />
    16             <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'/>
    17         </head>
    18         <body>
    19                         <a href="#Post-parsing">Post-parsing</a><br>
    20 <a href="#MPay24Shop.php">MPay24Shop.php</a><br>
    21 <a href="#orderXML.php">orderXML.php</a><br>
    22 <a name="MPay24Api.php"></a>
    23 <h1>MPay24Api.php</h1>
    24 <h2>Warnings:</h2><br>
    25 <b>Warning on line 8</b> - no @package tag was used in a DocBlock for class MPay24Api<br>
    26 <b>Warning on line 554</b> - no @package tag was used in a DocBlock for class GeneralResponse<br>
    27 <b>Warning on line 597</b> - no @package tag was used in a DocBlock for class PaymentResponse<br>
    28 <b>Warning on line 678</b> - no @package tag was used in a DocBlock for class ManagePaymentResponse<br>
    29 <b>Warning on line 733</b> - no @package tag was used in a DocBlock for class ListPaymentMethodsResponse<br>
    30 <b>Warning on line 839</b> - no @package tag was used in a DocBlock for class TransactionStatusResponse<br>
    31 <b>Warning on line 916</b> - File "/var/www/api/MPay24Api.php" has no page-level DocBlock, use @package in the first DocBlock to create one<br>
    32 <a name="MPay24Shop.php"></a>
    33 <h1>MPay24Shop.php</h1>
    34 <h2>Warnings:</h2><br>
    35 <b>Warning on line 11</b> - no @package tag was used in a DocBlock for class MPay24Shop<br>
    36 <b>Warning on line 578</b> - no @package tag was used in a DocBlock for class Transaction<br>
    37 <b>Warning on line 664</b> - File "/var/www/api/MPay24Shop.php" has no page-level DocBlock, use @package in the first DocBlock to create one<br>
    38 <a name="orderXML.php"></a>
    39 <h1>orderXML.php</h1>
    40 <h2>Warnings:</h2><br>
    41 <b>Warning on line 11</b> - no @package tag was used in a DocBlock for file /var/www/api/orderXML.php<br>
    42 <b>Warning on line 14</b> - no @package tag was used in a DocBlock for class ORDER<br>
    43     <p class="notes" id="credit">
    44         Documentation generated on Tue, 31 May 2011 09:56:05 +0200 by <a href="http://www.phpdoc.org" target="_blank">phpDocumentor 1.4.3</a>
    45     </p>
    46     </body>
     1<!DOCTYPE html>
     2<html lang="en">
     3<head>
     4    <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
     5    <meta charset="utf-8"/>
     6    <title>     &raquo; Compilation errors
     7</title>
     8    <meta name="author" content=""/>
     9    <meta name="description" content=""/>
     10
     11    <!--[if lt IE 9]>
     12    <script src="http://html5shim.googlecode.com/svn/trunk/html5.js" type="text/javascript"></script>
     13    <![endif]-->
     14
     15    <link href="css/template.css" rel="stylesheet" media="all"/>
     16    <script src="js/jquery-1.7.1.min.js" type="text/javascript"></script>
     17    <script src="js/jquery-ui-1.8.2.custom.min.js" type="text/javascript"></script>
     18    <script src="js/jquery.mousewheel.min.js" type="text/javascript"></script>
     19    <script src="js/bootstrap.js" type="text/javascript"></script>
     20    <script src="js/template.js" type="text/javascript"></script>
     21    <script src="js/prettify/prettify.min.js" type="text/javascript"></script>
     22
     23    <link rel="shortcut icon" href="img/favicon.ico"/>
     24    <link rel="apple-touch-icon" href="img/apple-touch-icon.png"/>
     25    <link rel="apple-touch-icon" sizes="72x72" href="img/apple-touch-icon-72x72.png"/>
     26    <link rel="apple-touch-icon" sizes="114x114" href="img/apple-touch-icon-114x114.png"/>
     27</head>
     28<body>
     29
     30<div class="navbar navbar-fixed-top">
     31    <div class="navbar-inner">
     32        <div class="container">
     33            <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
     34                <span class="icon-bar"></span> <span class="icon-bar"></span>
     35                <span class="icon-bar"></span> </a>
     36            <a class="brand" href="index.html">API Documentation</a>
     37
     38            <div class="nav-collapse">
     39                <ul class="nav">
     40                    <li class="dropdown">
     41                        <a href="#api" class="dropdown-toggle" data-toggle="dropdown">
     42                            API Documentation <b class="caret"></b>
     43                        </a>
     44                        <ul class="dropdown-menu">
     45                                                                                </ul>
     46                    </li>
     47                    <li class="dropdown" id="charts-menu">
     48                        <a href="#charts" class="dropdown-toggle" data-toggle="dropdown">
     49                            Charts <b class="caret"></b>
     50                        </a>
     51                        <ul class="dropdown-menu">
     52                            <li>
     53                                <a href="graph_class.html">
     54                                    <i class="icon-list-alt"></i>&#160;Class hierarchy diagram
     55                                </a>
     56                            </li>
     57                        </ul>
     58                    </li>
     59                    <li class="dropdown" id="reports-menu">
     60                        <a href="#reports" class="dropdown-toggle" data-toggle="dropdown">
     61                            Reports <b class="caret"></b>
     62                        </a>
     63                        <ul class="dropdown-menu">
     64                            <li><a href="errors.html"><i class="icon-list-alt"></i>&#160;Errors</a></li>
     65                            <li><a href="markers.html"><i class="icon-list-alt"></i>&#160;Markers</a></li>
     66                            <li><a href="deprecated.html"><i class="icon-list-alt"></i>&#160;Deprecated</a></li>
     67                        </ul>
     68                    </li>
     69                </ul>
     70            </div>
     71        </div>
     72    </div>
     73    <div class="go_to_top">
     74        <a href="#___" style="color: inherit">Back to top&#160;&#160;<i class="icon-upload icon-white"></i></a>
     75    </div>
     76</div>
     77
     78<div id="___" class="container">
     79    <noscript>
     80        <div class="alert alert-warning">
     81            Javascript is disabled; several features are only available if Javascript is enabled.
     82        </div>
     83    </noscript>
     84
     85    <div class="row">
     86        <div class="span4">
     87
     88            <ul class="side-nav nav nav-list">
     89                <li class="nav-header">Filter type</li>
     90                <li>
     91                    <div class="btn-group type-filter" data-toggle="buttons-checkbox">
     92                        <button class="btn critical">Critical</button>
     93                        <button class="btn error">Error</button>
     94                        <button class="btn notice">Notice</button>
     95                    </div>
     96                </li>
     97                <li class="nav-header">Navigation</li>
     98                                                                                                                                                                                                                                                                                                                                                                                                                                                    </ul>
     99        </div>
     100
     101        <div class="span8">
     102            <ul class="breadcrumb">
     103                <li><a href=""><i class="icon-remove-sign"></i></a><span class="divider">\</span></li>
     104                <li>Compilation Errors</li>
     105            </ul>
     106
     107                            <div class="alert alert-info">No errors have been found in this project.</div>
     108           
     109                            <div class="package-contents">
     110                                    </div>
     111                            <div class="package-contents">
     112                                    </div>
     113                            <div class="package-contents">
     114                                    </div>
     115                            <div class="package-contents">
     116                                    </div>
     117                            <div class="package-contents">
     118                                    </div>
     119                            <div class="package-contents">
     120                                    </div>
     121                            <div class="package-contents">
     122                                    </div>
     123                    </div>
     124    </div>
     125</div>
     126
     127<footer class="span12">
     128    Template is built using <a href="http://twitter.github.com/bootstrap/">Twitter Bootstrap 2</a> and icons provided by
     129    <a href="http://glyphicons.com/">Glyphicons</a>.<br/>
     130    Documentation is powered by <a href="http://www.phpdoc.org/">phpDocumentor </a> and<br/>
     131    generated on Mon, 24 Jun 2013 15:13:05 +0200.<br/>
     132</footer>
     133</body>
    47134</html>
  • woocommerce-mpay24-gateway/trunk/MPay24/doc/how_to_confirm.html

    r636654 r803175  
    1 <!--
    2     /**
    3      * @author              [email protected]
    4      * @version             $Id: how_to_confirm.html 5217 2012-10-16 05:27:43Z anna $
    5      * @filesource          how_to_confirm.html
    6      * @license             http://ec.europa.eu/idabc/eupl.html EUPL, Version 1.1
    7      */
    8  -->
    9 <html>
     1<!DOCTYPE html>
     2<html lang="en">
    103<head>
    11     <title>mPAY24API Documentation</title>
    12             <link rel="stylesheet" href="media/stylesheet.css" />
    13             <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'/>
     4    <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
     5    <meta charset="utf-8"/>
     6    <title>API Documentation</title>
     7    <meta name="author" content=""/>
     8    <meta name="description" content=""/>
     9
     10    <!--[if lt IE 9]>
     11    <script src="http://html5shim.googlecode.com/svn/trunk/html5.js" type="text/javascript"></script>
     12    <![endif]-->
     13
     14    <link href="css/template.css" rel="stylesheet" media="all"/>
     15    <script src="js/jquery-1.7.1.min.js" type="text/javascript"></script>
     16    <script src="js/jquery-ui-1.8.2.custom.min.js" type="text/javascript"></script>
     17    <script src="js/jquery.mousewheel.min.js" type="text/javascript"></script>
     18    <script src="js/bootstrap.js" type="text/javascript"></script>
     19    <script src="js/template.js" type="text/javascript"></script>
     20    <script src="js/prettify/prettify.min.js" type="text/javascript"></script>
     21
     22    <link rel="shortcut icon" href="img/favicon.ico"/>
     23    <link rel="apple-touch-icon" href="img/apple-touch-icon.png"/>
    1424</head>
    1525<body>
    16 <div align="center"><h1>How to work with the confirmation</h1></div>
    17 <p>
    18     After you're already familiar with the requests to mPAY24 (see <a href="blank.html">hier</a>) it's time to show you
     26
     27<div class="navbar navbar-fixed-top">
     28    <div class="navbar-inner">
     29        <div class="container">
     30            <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
     31                <span class="icon-bar"></span> <span class="icon-bar"></span>
     32                <span class="icon-bar"></span> </a>
     33            <a class="brand" href="index.html">API Documentation</a>
     34        </div>
     35    </div>
     36    <div class="go_to_top">
     37        <a href="#___" style="color: inherit">Back to top&#160;&#160;<i class="icon-upload icon-white"></i></a>
     38    </div>
     39</div>
     40
     41<div id="___" class="container">
     42    <noscript>
     43        <div class="alert alert-warning">
     44            Javascript is disabled; several features are only available if Javascript is enabled.
     45        </div>
     46    </noscript>
     47   
     48    <div class="hero-unit">
     49                                    <div class="well">
     50    <img alt="mPAY24 Logo" src="img/payment-mpay24.png" style="padding-left: 20px;">
     51<div align="center"><h2>How to work with the confirmation</h2></div>
     52
     53    After you're already familiar with the requests to mPAY24 (see <a href="index.html">hier</a>) it's time to show you
    1954    how to interact with the mPAY24 confirmation interface. For details please read the "Specification of the mPAY24 interfaces".
    2055    <br>
    2156    In general there are 3 important things you should do:   
    22 </p>
    23 <h2>STEP 1</h2>
     57
     58<br><br>
     59<h3>STEP 1</h3>
    2460Create a new file - for example confirm.php - you should include the initial index.php, where the class MyShop was defined.
    2561The mPAY24 confirmation interface send (via GET) a list of parameters every time when a transaction has changed it's status - by initiating
    2662(RESERVED/BILLED/ERROR), by clearing (BILLED), by crediting (CREDITED), by canceling (CANCELED). The only thing you should do is to "save" these
    27 attributes into array and pass the array to the method <a href="mPAY24API/MPay24Shop.html#confirm" title="details" class="method-name">
     63attributes into array and pass the array to the method <a href="classes/MPay24Shop.html" title="details" class="method-name">
    2864confirm</a> together with the transaction ID for the transaction you want to update.
    2965<br><br>
    30 <textarea rows="10" cols="120">
     66<textarea class="span10" rows="11" cols="120">
    3167<?php
    3268  include("index.php");           
     
    4177</textarea>
    4278
    43 <h2>STEP 2</h2>
    44 The <a href="mPAY24API/MPay24Shop.html#confirm" title="details" class="method-name">confirm</a> method requires the implementation of the
    45 two abstract mehtods in our MyShop class - <a href="mPAY24API/MPay24Shop.html#updateTransaction" title="details" class="method-name">
    46 updateTransaction</a> and <a href="mPAY24API/MPay24Shop.html#getTransaction" title="details" class="method-name">getTransaction</a>.
     79<h3>STEP 2</h3>
     80The <a href="classes/MPay24Shop.html" title="details" class="method-name">confirm</a> method requires the implementation of the
     81two abstract mehtods in our MyShop class - <a href="classes/MPay24Shop.html" title="details" class="method-name">
     82updateTransaction</a> and <a href="classes/MPay24Shop.html" title="details" class="method-name">getTransaction</a>.
    4783<br><br>
    48 <textarea rows="16" cols="120">
     84<textarea class="span10" rows="17" cols="120">
    4985  function updateTransaction($tid, $args, $shippingConfirmed){
    5086    $fh = fopen("result.txt", 'w') or die("can't open file");
     
    65101</textarea>
    66102<br><br>
    67 With the <a href="mPAY24API/MPay24Shop.html#updateTransaction" title="details" class="method-name">updateTransaction</a> we create a regular
    68 text file and save the information from the mPAY24 confirmation in it. The <a href="mPAY24API/MPay24Shop.html#getTransaction" title="details" class="method-name">
     103With the <a href="classes/MPay24Shop.html" title="details" class="method-name">updateTransaction</a> we create a regular
     104text file and save the information from the mPAY24 confirmation in it. The <a href="classes/MPay24Shop.html" title="details" class="method-name">
    69105getTransaction</a> method just gives us back a transaction with the specific transaction ID.
    70106
    71 <h2>STEP 3</h2>
     107<h3>STEP 3</h3>
    72108The last thing we need to to do is to specify the needed URLs in our MDXI XML (see chapter 4.2.9 of the specification for details). Modify
    73 the <a href="mPAY24API/MPay24Shop.html#createMDXI" title="details" class="method-name">createMDXI</a> method by adding a success and a confirmation URLs:
     109the <a href="classes/MPay24Shop.html" title="details" class="method-name">createMDXI</a> method by adding a success and a confirmation URLs:
    74110<br><br>
    75 <textarea rows="13" cols="120">
     111<textarea class="span10" rows="14" cols="120">
    76112  function createMDXI($transaction){
    77113    $mdxi = new ORDER();
     
    92128was closed).
    93129<br><br>
    94 <textarea rows="8" cols="120">
     130<textarea class="span10" rows="9" cols="120">
    95131<?php
    96132  $file_handle = fopen("result.txt", "r");
     
    105141The success.php does nothing but only open the file created from the confirmation and prints out its content in your browser. You can also
    106142analogical define an error and cancel URLs.
     143
     144                    </div>               
     145        </div>
     146
     147</div>
    107148</body>
    108149</html>
  • woocommerce-mpay24-gateway/trunk/MPay24/doc/how_to_order.html

    r636654 r803175  
    1 <!--
    2     /**
    3      * @author              [email protected]
    4      * @version             $Id: how_to_order.html 5217 2012-10-16 05:27:43Z anna $
    5      * @filesource          how_to_order.html
    6      * @license             http://ec.europa.eu/idabc/eupl.html EUPL, Version 1.1
    7      */
    8  -->
    9 <html>
     1<!DOCTYPE html>
     2<html lang="en">
    103<head>
    11     <title>mPAY24API Documentation</title>
    12             <link rel="stylesheet" href="media/stylesheet.css" />
    13             <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'/>
     4    <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
     5    <meta charset="utf-8"/>
     6    <title>API Documentation</title>
     7    <meta name="author" content=""/>
     8    <meta name="description" content=""/>
     9
     10    <!--[if lt IE 9]>
     11    <script src="http://html5shim.googlecode.com/svn/trunk/html5.js" type="text/javascript"></script>
     12    <![endif]-->
     13
     14    <link href="css/template.css" rel="stylesheet" media="all"/>
     15    <script src="js/jquery-1.7.1.min.js" type="text/javascript"></script>
     16    <script src="js/jquery-ui-1.8.2.custom.min.js" type="text/javascript"></script>
     17    <script src="js/jquery.mousewheel.min.js" type="text/javascript"></script>
     18    <script src="js/bootstrap.js" type="text/javascript"></script>
     19    <script src="js/template.js" type="text/javascript"></script>
     20    <script src="js/prettify/prettify.min.js" type="text/javascript"></script>
     21
     22    <link rel="shortcut icon" href="img/favicon.ico"/>
     23    <link rel="apple-touch-icon" href="img/apple-touch-icon.png"/>
    1424</head>
    1525<body>
    16 <div align="center"><h1>How to work with ORDER objects</h1></div>
    17 <h2>Basics</h2>
    18 <p>
     26
     27<div class="navbar navbar-fixed-top">
     28    <div class="navbar-inner">
     29        <div class="container">
     30            <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
     31                <span class="icon-bar"></span> <span class="icon-bar"></span>
     32                <span class="icon-bar"></span> </a>
     33            <a class="brand" href="index.html">API Documentation</a>
     34        </div>
     35    </div>
     36    <div class="go_to_top">
     37        <a href="#___" style="color: inherit">Back to top&#160;&#160;<i class="icon-upload icon-white"></i></a>
     38    </div>
     39</div>
     40
     41<div id="___" class="container">
     42    <noscript>
     43        <div class="alert alert-warning">
     44            Javascript is disabled; several features are only available if Javascript is enabled.
     45        </div>
     46    </noscript>
     47   
     48    <div class="hero-unit">
     49                                    <div class="well">
     50    <img alt="mPAY24 Logo" src="img/payment-mpay24.png" style="padding-left: 20px;">
     51<div align="center"><h2>How to work with ORDER objects</h2></div>
     52<h3>Basics</h3>
    1953    In the mPAY24 context an ORDER is an object, represented by a XML, which contains all the usual information of a shopping cart.
    2054    <br />For example: price, currency, items, billing address, shipping address, descriptions for the rows of the shopping cart, etc.
     
    2256    <a href="https://www.mpay24.com/schemas/MDXI/v3.0/MDXI.xsd">MDXI schema</a>, which defines the order,
    2357    the type and the allowed count of all these elements. This is also specified in chapter 4.2.9 of the specification.
    24     <br />Accordingly to this schema and using the <a href="mPAY24API/ORDER.html">ORDER</a> class we support, you can create a MDXI-XML very easy.
    25 </p>
    26 
    27 <p>
    28     The first thing you should do is to instantiate an object from the <a href="mPAY24API/ORDER.html">ORDER</a> type.
    29     <br />
    30     <textarea rows=2 cols=75>
     58    <br />Accordingly to this schema and using the <a href="classes/ORDER.html">ORDER</a> class we support, you can create a MDXI-XML very easy.
     59
     60    The first thing you should do is to instantiate an object from the <a href="classes/ORDER.html">ORDER</a> type.
     61    <br />
     62    <textarea class="span6" rows=1 cols=75>
    3163$mdxi = new ORDER();
    3264    </textarea>
     
    3668    node is in the "Order" node you should only type the following:
    3769    <br />
    38     <textarea rows=2 cols=75>
     70    <textarea class="span6" rows=1 cols=75>
    3971$mdxi->Order->BillingAddr->EMail = "[email protected]";
    4072    </textarea>
     
    4476    You can also pass attributes for a node with only one set function call:
    4577    <br />
    46     <textarea rows=2 cols=75>
     78    <textarea class="span6" rows=1 cols=75>
    4779$mdxi->Order->BillingAddr->setMode("ReadOnly");
    4880    </textarea>
     
    5587    The index can only be a positive integer!
    5688    <br />
    57     <textarea rows=2 cols=75>
     89    <textarea class="span6" rows=1 cols=75>
    5890$mdxi->Order->PaymentTypes->Payment(3)->setType("PAYPAL");
    5991    </textarea>
    6092    <br />
    61 </p>
    62 
    63 <h2>Example</h2>
     93
     94<h3>Example</h3>
    6495<table>
    6596    <tr>
    66         <th>Input</th>
    67         <th>Output</th>
     97        <th><h3>Input</h3></th>
     98        <th><h3>Output</h3></th>
    6899    </tr>   
    69100    <tr>
    70101<td>
    71 <textarea rows=55 cols=75>
     102<textarea class="span6" rows=46 cols=75>
    72103$mdxi = new ORDER();
    73104$mdxi->Order->setLogoStyle(""); // is empty, so will be not set
     
    78109$mdxi->Order->TemplateSet = "WEB";
    79110$mdxi->Order->TemplateSet->setLanguage("DE");
    80 
    81 $mdxi->Order->PaymentTypes->setEnable("true");
    82 
    83 $mdxi->Order->PaymentTypes->Payment(1)->setType("CC");
    84 $mdxi->Order->PaymentTypes->Payment(1)->setBrand("VISA");
    85 
    86 $mdxi->Order->PaymentTypes->Payment(2)->setType("CC");
    87 $mdxi->Order->PaymentTypes->Payment(2)->setBrand("MASTERCARD");
    88 
    89 $mdxi->Order->PaymentTypes->Payment(3)->setType("MAESTRO");
    90111
    91112$mdxi->Order->ShoppingCart->Description = "Order Description";
     
    114135$mdxi->Order->Customer->setUseProfile("true");
    115136$mdxi->Order->Customer->setId("98765");
    116    
    117 $mdxi->Order->BillingAddr->setMode("ReadWrite");
     137$mdxi->Order->Customer = "Hans Mayer";
     138   
     139$mdxi->Order->BillingAddr->setMode("ReadOnly");
    118140$mdxi->Order->BillingAddr->Name = "Max Musterman";
    119141$mdxi->Order->BillingAddr->Street = "Teststreet 1";
     
    126148</td>
    127149<td>
    128 <textarea rows=55 cols=75>
     150<textarea class="span6" rows=46 cols=75>
    129151<?xml version="1.0" encoding="UTF-8"?>
    130152<Order>
     
    135157    <TemplateSet Language="DE">WEB</TemplateSet>
    136158 
    137     <PaymentTypes Enable="true">
    138        
    139        
    140         <Payment Type="CC" Brand="VISA"/>
    141        
    142        
    143         <Payment Type="CC" Brand="MASTERCARD"/>
    144        
    145        
    146         <Payment Type="MAESTRO"/>
    147     </PaymentTypes>
    148159    <ShoppingCart>
    149160        <Description>Order Description</Description>
     
    169180    <Price>30.35</Price>
    170181    <Currency>USD</Currency>
    171     <Customer UseProfile="true" Id="98765"/>
     182   
     183   
     184    <Customer UseProfile="true" Id="98765">Hans Mayer</Customer>
    172185 
    173     <BillingAddr Mode="ReadWrite">
     186    <BillingAddr Mode="ReadOnly">
    174187        <Name>Max Musterman</Name>
    175188        <Street>Teststreet 1</Street>
     
    185198</tr>
    186199</table>
     200
     201                    </div>               
     202        </div>
     203
     204</div>
    187205</body>
    188206</html>
  • woocommerce-mpay24-gateway/trunk/MPay24/doc/index.html

    r636654 r803175  
    1 <?xml version="1.0" encoding="iso-8859-1"?>
    2 <!DOCTYPE html
    3      PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//FR"
    4      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
    5      <!--
    6     /**
    7      * @author              [email protected]
    8      * @version             $Id: index.html 5217 2012-10-16 05:27:43Z anna $
    9      * @filesource          index.html
    10      * @license             http://ec.europa.eu/idabc/eupl.html EUPL, Version 1.1
    11      */
    12  -->
    13    <html xmlns="http://www.w3.org/1999/xhtml">
     1<!DOCTYPE html>
     2<html lang="en">
    143<head>
    15     <!-- Generated by phpDocumentor on Tue, 31 May 2011 09:11:57 +0200  -->
    16   <title>mPAY24API Documentation</title>
    17  
    18  
    19  
    20   <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'/>
     4    <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
     5    <meta charset="utf-8"/>
     6    <title>API Documentation</title>
     7    <meta name="author" content=""/>
     8    <meta name="description" content=""/>
     9
     10    <!--[if lt IE 9]>
     11    <script src="http://html5shim.googlecode.com/svn/trunk/html5.js" type="text/javascript"></script>
     12    <![endif]-->
     13
     14    <link href="css/template.css" rel="stylesheet" media="all"/>
     15    <script src="js/jquery-1.7.1.min.js" type="text/javascript"></script>
     16    <script src="js/jquery-ui-1.8.2.custom.min.js" type="text/javascript"></script>
     17    <script src="js/jquery.mousewheel.min.js" type="text/javascript"></script>
     18    <script src="js/bootstrap.js" type="text/javascript"></script>
     19    <script src="js/template.js" type="text/javascript"></script>
     20    <script src="js/prettify/prettify.min.js" type="text/javascript"></script>
     21
     22    <link rel="shortcut icon" href="img/mpay24-favicon.ico"/>
     23    <link rel="apple-touch-icon" href="img/mpay24-apple-touch-icon.png"/>
    2124</head>
    22 
    23 <FRAMESET rows='120,*'>
    24     <FRAME src='packages.html' name='left_top' frameborder="1" bordercolor="#999999">
    25     <FRAMESET cols='25%,*'>
    26         <FRAME src='li_mPAY24API.html' name='left_bottom' frameborder="1" bordercolor="#999999">
    27         <FRAME src='blank.html' name='right' frameborder="1" bordercolor="#999999">
    28     </FRAMESET>
    29     <NOFRAMES>
    30         <H2>Frame Alert</H2>
    31         <P>This document is designed to be viewed using the frames feature.
    32         If you see this message, you are using a non-frame-capable web client.</P>
    33     </NOFRAMES>
    34 </FRAMESET>
    35 </HTML>
     25<body>
     26
     27<div class="navbar navbar-fixed-top">
     28    <div class="navbar-inner">
     29        <div class="container">
     30            <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
     31                <span class="icon-bar"></span> <span class="icon-bar"></span>
     32                <span class="icon-bar"></span> </a>
     33            <a class="brand" href="index.html">API Documentation</a>
     34        </div>
     35    </div>
     36    <div class="go_to_top">
     37        <a href="#___" style="color: inherit">Back to top&#160;&#160;<i class="icon-upload icon-white"></i></a>
     38    </div>
     39</div>
     40
     41<div id="___" class="container">
     42    <noscript>
     43        <div class="alert alert-warning">
     44            Javascript is disabled; several features are only available if Javascript is enabled.
     45        </div>
     46    </noscript>
     47
     48            <div class="hero-unit">
     49            <img alt="mPAY24 Logo" src="img/payment-mpay24.png" style="padding-left: 20px;">
     50            <h1>mPAY24 PHP API</h1>
     51            <h2>Documentation</h2>
     52        </div>
     53
     54        <div class="hero-unit">
     55                                    <div class="well">
     56                        <ul class="nav nav-list">
     57                            <li class="nav-header">Packages</li>
     58                            <li><a href="packages/default.html">Global ()</a></li>
     59                            <li><a href="how_to_order.html">How to work with the ORDER object</a></li>
     60                            <li><a href="how_to_confirm.html">How to work with the confimration</a></li>
     61                                                    </ul>
     62            </div>
     63        </div>
     64       
     65        <div class="hero-unit">
     66                                    <div class="well">
     67                       <div align="center"><h2>Open the mPAY24 payment window in 5 steps!</h2></div>
     68<div align="justify">
     69<h3>LICENSE/DISCLAIMER</h3>
     70Copyright 2011 mPAY24 GmbH<br /><br />
     71
     72Licensed under the EUPL, Version 1.1 or - as soon they
     73will be approved by the European Commission - subsequent
     74versions of the EUPL (the "Licence");
     75You may not use this work except in compliance with the
     76Licence.<br />
     77You may obtain a copy of the Licence at:<br />
     78
     79http://ec.europa.eu/idabc/eupl.html<br /><br />
     80
     81Unless required by applicable law or agreed to in
     82writing, software distributed under the Licence is
     83distributed on an "AS IS" basis,
     84WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
     85express or implied.<br />
     86See the Licence for the specific language governing
     87permissions and limitations under the Licence.
     88
     89<h3>ABSTRACT</h3>
     90The target of this guide is to help you open the <a href="http://www.mpay24.com/">mPAY24</a> payment page in five simple steps, using the mPAY24 PHP API.<br /><br />
     91
     92*Please note, that you still need to implement the mPAY24 Confirmation-Interface as explained in chapter 4.2.6.1 of the "Specification of the mPAY24 Interfaces"
     93in order to have your system process the result of the payment transaction!* The mPAY24 PHP API will also help you with this, but in order to fully understand
     94how payment transactions work and therefore avoid some common pitfalls with the implementation, you are strongly encouraged to refer to the specification!
     95There is also a complete and ready to test "example shop" available at mPAY24.
     96
     97
     98<h3>Prerequisites</h3>
     99In order for the mPAY24 PHP API to work, your installation will have to meet the following prerequisites:<br /><br />
     100* <a href="http://www.php.net/">PHP >= 5</a><br />
     101* <a href="http://at2.php.net/manual/de/book.curl.php">cURL</a><br />
     102* <a href="http://at2.php.net/manual/de/book.dom.php">DOM</a><br />
     103* <a href="http://at2.php.net/manual/en/mcrypt">Mcrypt</a><br /><br />
     104
     105Please refer to <a href="http://www.php.net/">http://www.php.net/phpinfo</a> or consult your systems administrator in order to find out if your system fulfills the prerequisites.
     106
     107<h3>STEP 1</h3>
     108a. create a PHP file, preferably in a folder dedicated to testing the mPAY24 PHP API within the DocumentRoot, for example: ../DocumentRoot/mPAY24_PHP_API/index.php<br />
     109b. copy the files supplied by mPAY24 into this same directory.<br />
     110<textarea class="span10" rows="11" cols="155">
     111<html>                                                                                     
     112  <head>                                                                                   
     113   <title>Proceed with payment</title>                                                     
     114  </head>                                                                                   
     115  <body>                                                                                   
     116   <form method="post">                                                                     
     117    <input name="submit" type="submit" value="Proceed to the mPAY24 payment page"/>         
     118   </form>                                                                                 
     119  </body>                                                                                   
     120</html>
     121</textarea><br /><br />
     122c. ...and implement some functionality. First of, we need to include the file "MPay24Shop.php" in our script and initialize our own class.
     123Let's just use the name "MyShop" for the moment. MyShop extends the <a href='classes/MPay24Shop.html' target='right'>MPay24Shop</a> class
     124supplied from the MPay24Shop.php file. We'll leave this class empty for this step.
     125<br /><br />
     126<textarea class="span10" rows="10" cols="155">
     127<?php                                                                                     
     128include_once("MPay24Shop.php");                                                           
     129                                                                                           
     130class MyShop extends MPay24Shop {                                                       
     131                                                                                           
     132}                                                                                       
     133?>                                                                                         
     134<html>                                                                                     
     135  ...     
     136</textarea><br /><br />
     137
     138<h3>STEP 2</h3>
     139Out of the ten abstract methods within the <a href='classes/MPay24Shop.html' target='right'>MPay24Shop</a> class, you will have to implement
     140functionality into at least two of the methods to initialize the
     141mPAY24 payment page. We initialize also two variables, which are responisble for the the mandatory tags from the MDXI(see chapter 4.2.9 of the specification for details).
     142We start out by inserting all the functions into our class like this:<br /><br />
     143<textarea class="span10" rows="19" cols="155">
     144...                                                                                     
     145class MyShop extends MPay24Shop {
     146   
     147  var $tid = "My first order";
     148  var $price = 123.45;
     149                                                         
     150  function updateTransaction($tid, $args, $shippingConfirmed) {}                         
     151  function getTransaction($tid) {}                                                       
     152  function createProfileOrder($tid) {}                                                   
     153  function createExpressCheckoutOrder($tid) {}                                           
     154  function createFinishExpressCheckoutOrder($tid, $shippingCosts, $amount, $cancel) {}   
     155  function write_log($operation, $info_to_log) {}                                         
     156  function createSecret($tid, $amount, $currency, $timeStamp) {}                         
     157  function getSecret($tid) {}                                                             
     158  function createTransaction() {}                                                         
     159  function createMDXI($transaction) {}                                                   
     160}                                                                                       
     161   ...                 
     162</textarea>
     163<br /><br />
     164
     165<h3>STEP 3</h3>
     166a. to carry out a payment transaction, mPAY24 will need to know the amount to be paid, as well as a transaction identifier (see chapter 4.2.2 and
     167chapter 4.2.9 of the mPAY24 specification for details), which will come in handy especially later, when we begin to obtain the result of the payment.
     168You can refer to the "allowed properties for a transaction" for further reference.
     169Now, create a transaction by filling the createTransaction method with life:<br /><br />
     170<textarea class="span10" rows="7" cols="155">
     171  function createTransaction() {                                                         
     172    $transaction = new Transaction($this->tid);                                           
     173    $transaction->PRICE = $this->price;                                                   
     174                                                                                           
     175    return $transaction;                                                                   
     176  }               
     177</textarea>
     178<br /><br />
     179b. in order to initialize the mPAY24 payment page, you need to supply mPAY24 with a MDXI XML (see chapter 4.2.9 of the specification for details).
     180The MDXI XML contains all the information mPAY24 needs to authorize and/or bill, which is at least the TID specified by your system as well as the amount.
     181The <a href='classes/ORDER.html' target='right'>ORDER</a> object helps you create such a XML file. We create the MDXI by utilizing the - right,
     182you guessed it - <a href="classes/MPay24Shop.html" title="details" class="method-name">createMDXI</a> method.<br /><br />
     183<textarea class="span10" rows="9" cols="155">
     184  function createMDXI($transaction) {                                                     
     185    $mdxi = new ORDER();                                                                   
     186                                                                                           
     187    $mdxi->Order->Tid   = $transaction->TID;                                               
     188    $mdxi->Order->Price = $transaction->PRICE;                                             
     189                                                                                           
     190    return $mdxi;                                                                         
     191  }                                                                                       
     192</textarea>
     193<br /><br />Please read the specification as well as <a href='how_to_order.html' target='right'>"How to work with the ORDER object"</a> to utilize the MDXI XML to it's full power.
     194
     195<h3>STEP 4</h3>
     196We do not need to create a constructor for our MyShop class, as it is sufficient to use the
     197<a href="classes/MPay24Shop.html" title="details" class="method-name">parent constructor</a> of the MPay24Shop class.
     198The parent constructor expects 3 mandatory variables:<br />
     1991. the mPAY24 merchantID - please supply your test system merchantID, starting with the digit 9. <br />
     2002. your SOAP password supplied by mPAY24. Please note, that this is *not* the same password used for login at www.mpay24.com or test.mpay24.com!<br />
     2013. a boolean to define whether to use the productive- or test systems<br />
     202 * TRUE to use the mPAY24 test systems, what is exactly we like to do for now...<br />
     203 * FALSE to use the mPAY24 productive systems<br />
     2044. optional: in case you are behind a proxy, you can set it's IP address...<br />
     2055. ... and port.<br />
     2066. You can also set whether log files are going to be created or not with another boolean variable:<br />
     207 * TRUE to write log files<br />
     208 * FALSE is the default value - in this case no log files are written<br /><br />
     209
     210Insert the declaration before the end of the if(isset($_POST["submit"])) control structure. If you are not behind a proxy, just set the two variables to NULL.
     211If you are unsure whether or not you are behind a proxy, please contact your systems administrator or ISP.<br /><br />
     212<textarea class="span10" rows="4" cols="155">
     213if(isset($_POST["submit"])) {                                                             
     214  $myShop = new MyShop("merchantID", 'SOAPPassword', TRUE, "proxyHost", "proxyPort", TRUE);                                                               
     215</textarea><br /><br />
     216
     217<h3>STEP 5</h3>
     218Last but not least, we need to call the <a href="classes/MPay24Shop.html" title="details" class="method-name">pay()</a> method and parse it's PaymentResponse object. The PaymentResponse object contains a GeneralResponse object holding
     219the response from the mPAY24 systems. <br /><br />
     220<textarea class="span10" rows="12" cols="155">                                                                                           
     221  if(isset($_POST["submit"])) {
     222    $myShop = new MyShop("MerchantID", "Password", TRUE, null, null, TRUE);
     223    $result = $myShop->pay();
     224
     225    if($result->getGeneralResponse()->getStatus() == "OK")
     226      header('Location: ' . $result->getLocation());
     227    else
     228      echo "Return Code: " . $result->getGeneralResponse()->getReturnCode();
     229  }   
     230}                                                                                   
     231</textarea><br /><br />
     232
     233Navigate your browser to the file with your code and use the test details from chapter five of the mPAY24 specification to conduct
     234your first test transaction. Of course, you cannot finish the transaction as the Success-, Error- and
     235Confirmation-URLs still have to be implemented (see <a href='how_to_confirm.html' target='right'>"How to work with the confirmation"</a>).
     236Please read the FAQ within Appendix B of the specification and find our contact details within Appendix C in case you have any questions.<br /><br />
     237</div>
     238            </div>
     239        </div>
     240</div>
     241</body>
     242</html>
  • woocommerce-mpay24-gateway/trunk/MPay24/orderXML.php

    r636654 r803175  
    11<?php
    2     /**
    3      * @author              [email protected]
    4      * @version             $Id: orderXML.php 5217 2012-10-16 05:27:43Z anna $
    5      * @filesource          orderXML.php
    6      * @license             http://ec.europa.eu/idabc/eupl.html EUPL, Version 1.1
    7      */
    8 
    92/**
    10  * @abstract        STRING MDXI_SCHEMA = the specified from mPAY24 URL, where you can download the MDXI schema
     3 * The URL specified from mPAY24, where MDXI schema will be download from
     4 * @const               MDXI_SCHEMA
    115 */
    126define ("MDXI_SCHEMA","https://www.mpay24.com/schemas/MDXI/v3.0/MDXI.xsd");
    137
     8/**
     9 * The ORDER class provides the functioanallity to create a XML, which is validatable with the MDXI.xsd
     10 *
     11 * @author              mPAY24 GmbH <[email protected]>
     12 * @version             $Id: orderXML.php 5477 2013-06-18 13:00:17Z anna $
     13 * @filesource          orderXML.php
     14 * @license             http://ec.europa.eu/idabc/eupl.html EUPL, Version 1.1
     15 */
    1416class ORDER {
    15     private $doc;
    16     private $node;
    17 
    18     /**
    19      * @abstract                                        Create a DOMDocument or a ORDER-Object with root $doc
    20      * @param            DOMNode                         The root DOMNode of an XML tree
    21      * @param            DOMNode                         The child DOMNode
    22      */
    23     public function ORDER($doc=null,$node=null) {
    24         if ($doc)
    25             $this->doc = $doc;
     17  /**
     18   * The DOMDocument, which the MDXI XML will be build on
     19   * @var               DOMDocument
     20   */
     21  private $doc;
     22  /**
     23   * A DOMNode from the MDXI XML, or the whole MDXI XML, represented as DOMDocument
     24   * @var               DOMDocument|DOMNode
     25   */
     26  private $node;
     27
     28  /**
     29   * Create a DOMDocument or a ORDER-Object with root $doc
     30   * @param             DOMNode             $doc                          The root DOMNode of an XML tree
     31   * @param             DOMNode             $node                         The child DOMNode
     32   */
     33  public function ORDER($doc=null,$node=null) {
     34    if ($doc)
     35      $this->doc = $doc;
     36    else {
     37      $this->doc = new DOMDocument("1.0", "UTF-8");
     38      $this->doc->formatOutput = true;
     39    }
     40
     41    if ($node)
     42      $this->node = $node;
     43    else
     44      $this->node = $this->doc;
     45  }
     46
     47  /**
     48   * Generic call-Method instead of numerous setter methods
     49   * @param             string              $method                       The name of the method, which is called for the Item-Object
     50   * @param             array               $args                         The arguments with them the method is called - minOccurance = 0, maxOccurance = 2:
     51   *                                                                      The first argument must be a positive integer (will be used as a index)
     52   *                                                                      The second argument is optional and would be used as value for the DOMNode
     53   */
     54  public function __call($method, $args) {
     55    if(substr($method, 0, 3) == "set" && $args[0] != '') {
     56      $attributeName = substr($method, 3);
     57
     58      $value = $args[0];
     59
     60      if(preg_match('/[0-9]+,[0-9]+/', $value, $match))
     61        $value = str_replace(',', '.', $match[0]);
     62
     63      if(preg_match('/[0-9]+.[0-9]+/', $value, $match) && $value == $match[0] && $attributeName != 'shippingCosts' && (is_int(strpos($attributeName, 'price')) || is_int(strpos($attributeName, 'Price')) || is_int(strpos($attributeName, 'Tax')) || is_int(strpos($attributeName, 'cost')) || is_int(strpos($attributeName, 'Cost'))))
     64        $value = number_format(floatval($match[0]), 2, '.', '');
     65
     66        $this->node->setAttribute($attributeName, $value);
     67    } elseif($args[0] != '') {
     68      if(sizeof($args)>2)
     69        die("It is not allowed to set more than 2 arguments for the node '$method'!");
     70      if(!is_int($args[0]) || $args[0] < 1)
     71        die("The first argument for the node '$method' must be whole number, bigger than 0!");
     72
     73      $name = $method . '[' . $args[0] . ']';
     74
     75      $xpath = new DOMXPath($this->doc);
     76      $qry = $xpath->query($name,$this->node);
     77
     78      if ($qry->length > 0)
     79        return new ORDER($this->doc,$qry->item(0));
     80      else {
     81        if(array_key_exists(1, $args)) {
     82          $value = $args[1];
     83
     84          if(preg_match('/[0-9]+,[0-9]+/', $value, $match))
     85            $value = str_replace(',', '.', $match[0]);
     86
     87          if(preg_match('/[0-9]+.[0-9]+/', $value, $match) && $value == $match[0] && $name != 'shippingCosts' && (is_int(strpos($name, 'price')) || is_int(strpos($name, 'Price')) || is_int(strpos($name, 'Tax')) || is_int(strpos($name, 'cost')) || is_int(strpos($name, 'Cost'))))
     88            $value = number_format(floatval($match[0]), 2, '.', '');
     89
     90          $node = $this->doc->createElement($method, $value);
     91        } else
     92          $node = $this->doc->createElement($method);
     93
     94        $node = $this->node->appendChild($node);
     95
     96        return new ORDER($this->doc,$node);
     97      }
     98    }
     99  }
     100
     101  /**
     102   * Get the value of a ORDER-Variable
     103   * @param             string              $name                         The name of the method, which is called for the Item-Object
     104   * @return            ORDER
     105   */
     106  public function __get($name) {
     107    $xpath = new DOMXPath($this->doc);
     108    $qry = $xpath->query($name,$this->node);
     109
     110    if ($qry->length > 0)
     111      return new ORDER($this->doc,$qry->item(0));
     112    else {
     113      $node = $this->doc->createElement($name);
     114      $node = $this->node->appendChild($node);
     115      return new ORDER($this->doc,$node);
     116    }
     117  }
     118
     119  /**
     120   * Set the value of a ORDER-Variable
     121   * @param             string              $name                         The name of the Node you want to set
     122   * @param             mixed               $value                        The value of the Node you want to set
     123   */
     124  public function __set($name, $value) {
     125    $xpath = new DOMXPath($this->doc);
     126    $qry = $xpath->query($name,$this->node);
     127
     128    $value = str_replace('&', '&amp;', $value);
     129
     130    if(preg_match('/[0-9]+,[0-9]+/', $value, $match))
     131      $value = str_replace(',', '.', $match[0]);
     132
     133    if(preg_match('/[0-9]+.[0-9]+/', $value, $match) && $value == $match[0] && $name != 'shippingCosts' && (is_int(strpos($name, 'price')) || is_int(strpos($name, 'Price')) || is_int(strpos($name, 'Tax')) || is_int(strpos($name, 'cost')) || is_int(strpos($name, 'Cost'))))
     134      $value = number_format(floatval($match[0]), 2, '.', '');
     135
     136    if(strpos($value, "<") || strpos($value, ">"))
     137      $value = "<![CDATA[" . $this->xmlencode($value) . "]]>";
     138
     139    if ($qry->length > 0)
     140      $qry->item(0)->nodeValue = $value;
     141    else {
     142      $node = $this->doc->createElement($name,$value);
     143      $this->node = $this->node->appendChild($node);
     144    }
     145  }
     146
     147  /**
     148   * Create a XML-Object from the ORDER-Object and return it
     149   * @return            XML
     150   */
     151  public function toXML() {
     152    return $this->doc->saveXML();
     153  }
     154
     155  /**
     156   * Validate the ORDER with the schema, defined in the constant MDXI_SCHEMA and return TRUE if the validation was successful or FALSE
     157   * @return            bool
     158   */
     159  public function validate() {
     160    $mdxi = "/MDXI.xsd";
     161
     162    if($this->olderThanOneWeek(__DIR__ . $mdxi)) {
     163      set_time_limit(0);
     164      ini_set('display_errors',true);
     165
     166      $fp = fopen (__DIR__ . '/MDXInew.xsd', 'w');
     167      $ch = curl_init(MDXI_SCHEMA);
     168      curl_setopt($ch, CURLOPT_FILE, $fp);
     169      curl_setopt($ch, CURLOPT_HEADER, 0);
     170      curl_setopt($ch, CURLOPT_CAINFO, __DIR__.'/cacert.pem');
     171      $result = curl_exec($ch);
     172
     173      if(curl_getinfo($ch, CURLINFO_HTTP_CODE) === 200 && file_exists(__DIR__ . '/MDXInew.xsd')) {
     174        unlink(__DIR__ . $mdxi);
     175        fclose($fp);
     176        rename(__DIR__ . "/MDXInew.xsd", __DIR__ . $mdxi);
     177      } else
     178        fclose($fp);
     179
     180      curl_close($ch);
     181    }
     182
     183    return $this->doc->schemaValidate(__DIR__ . $mdxi);
     184  }
     185
     186  /**
     187   * Encode the XML-characters in a string
     188   * @param             string              $txt                          A string to be encoded
     189   * @return            string
     190   */
     191  private function xmlencode($txt) {
     192    $txt = str_replace('<', '&lt;', $txt);
     193    $txt = str_replace('>', '&gt;', $txt);
     194    $txt = str_replace('&amp;apos;', "'", $txt);
     195    $txt = str_replace('&amp;quot;', '"', $txt);
     196    return $txt;
     197  }
     198
     199  /**
     200   * Check whether the MDXI.xsd is older than one week
     201   * @param             string              $filename                     The path to the file (MDXI.xsd)
     202   * @return            bool
     203   */
     204  private function olderThanOneWeek($filename){
     205    $year = date ("Y", filemtime($filename));
     206    $month = date ("m", filemtime($filename));
     207    $day = date ("d", filemtime($filename));
     208
     209    $tyear = date ("Y");
     210    $tmonth = date ("m");
     211    $tday = date ("d");
     212
     213    if($tyear > $year)
     214      return true;
     215    else {
     216      if($tmonth > $month){
     217        if($tday > 7)
     218          return true;
    26219        else {
    27             $this->doc = new DOMDocument("1.0", "UTF-8");
    28             $this->doc->formatOutput = true;
     220          if($tday-7+30 < $day)
     221            return false;
     222          else
     223            return true;
    29224        }
    30        
    31         if ($node)
    32             $this->node = $node;
     225      } else {
     226        if($tday-7 > $day)
     227          return true;
    33228        else
    34             $this->node = $this->doc;
    35     }
    36 
    37     /**
    38      * @abstract                                        Generic call-Method instead of numerous setter methods
    39      * @param             STRING                             The name of the method, which is called for the Item-Object
    40      * @param             ARRAY                             The arguments with them the method is called - minOccurance = 0, maxOccurance = 2:
    41      *
    42      *                                                     The first argument must be a positive integer (will be used as a index)
    43      *
    44      *                                                     The second argument is optional and would be used as value for the DOMNode
    45      */
    46     public function __call($method, $args) {
    47         if(substr($method, 0, 3) == "set" && $args[0] != '') {
    48             $attributeName = substr($method, 3);
    49            
    50             $value = $args[0];
    51            
    52             if(preg_match('/[0-9]+,[0-9]+/', $value, $match))
    53                    $value = str_replace(',', '.', $match[0]);
    54 
    55             if(preg_match('/[0-9]+.[0-9]+/', $value, $match) && $value == $match[0] && $attributeName != 'shippingCosts' && (is_int(strpos($attributeName, 'price')) || is_int(strpos($attributeName, 'Price')) || is_int(strpos($attributeName, 'Tax')) || is_int(strpos($attributeName, 'cost')) || is_int(strpos($attributeName, 'Cost'))))
    56               $value = number_format(floatval($match[0]), 2, '.', '');
    57          
    58             $this->node->setAttribute($attributeName, $value);
    59         } elseif($args[0] != '') {
    60             if(sizeof($args)>2)
    61               die("It is not allowed to set more than 2 arguments for the node '$method'!");
    62             if(!is_int($args[0]) || $args[0] < 1)
    63               die("The first argument for the node '$method' must be whole number, bigger than 0!");
    64 
    65             $name = $method . '[' . $args[0] . ']';
    66 
    67             $xpath = new DOMXPath($this->doc);
    68             $qry = $xpath->query($name,$this->node);
    69 
    70             if ($qry->length > 0)
    71                 return new ORDER($this->doc,$qry->item(0));
    72             else {
    73                 if(array_key_exists(1, $args)) {
    74                   $value = $args[1];
    75                  
    76                   if(preg_match('/[0-9]+,[0-9]+/', $value, $match))
    77                    $value = str_replace(',', '.', $match[0]);
    78                  
    79                   if(preg_match('/[0-9]+.[0-9]+/', $value, $match) && $value == $match[0] && $name != 'shippingCosts' && (is_int(strpos($name, 'price')) || is_int(strpos($name, 'Price')) || is_int(strpos($name, 'Tax')) || is_int(strpos($name, 'cost')) || is_int(strpos($name, 'Cost'))))
    80                     $value = number_format(floatval($match[0]), 2, '.', '');
    81                  
    82                   $node = $this->doc->createElement($method, $value);
    83                 }
    84                 else
    85                   $node = $this->doc->createElement($method);
    86                
    87                 $node = $this->node->appendChild($node);
    88                 return new ORDER($this->doc,$node);
    89             }
    90         }
    91     }
    92 
    93     /**
    94      * @abstract                                        Get the value of a ORDER-Variable
    95      * @param             STRING                             The name of the Node you need
    96      * @return            ORDER                             The ORDER-Object of a DOMDocument tree
    97      */
    98     public function __get($name) {
    99         $xpath = new DOMXPath($this->doc);
    100         $qry = $xpath->query($name,$this->node);
    101 
    102         if ($qry->length > 0)
    103             return new ORDER($this->doc,$qry->item(0));
    104         else {
    105             $node = $this->doc->createElement($name);
    106             $node = $this->node->appendChild($node);
    107             return new ORDER($this->doc,$node);
    108         }
    109     }
    110 
    111     /**
    112      * @abstract                                        Set the value of a ORDER-Variable
    113      * @param             STRING                             The name of the Node you want to set
    114      * @param             ANY                                 The value of the Node you want to set
    115      */
    116     public function __set($name, $value) {
    117         $xpath = new DOMXPath($this->doc);
    118         $qry = $xpath->query($name,$this->node);
    119 
    120         $value = str_replace('&', '&amp;', $value);
    121        
    122         if(preg_match('/[0-9]+,[0-9]+/', $value, $match))
    123           $value = str_replace(',', '.', $match[0]);
    124        
    125         if(preg_match('/[0-9]+.[0-9]+/', $value, $match) && $value == $match[0] && $name != 'shippingCosts' && (is_int(strpos($name, 'price')) || is_int(strpos($name, 'Price')) || is_int(strpos($name, 'Tax')) || is_int(strpos($name, 'cost')) || is_int(strpos($name, 'Cost'))))
    126           $value = number_format(floatval($match[0]), 2, '.', '');
    127 
    128         if(strpos($value, "<") || strpos($value, ">"))
    129             $value = "<![CDATA[" . $this->xmlencode($value) . "]]>";
    130        
    131         if ($qry->length > 0)
    132             $qry->item(0)->nodeValue = $value;
    133         else {
    134             $node = $this->doc->createElement($name,$value);
    135             $this->node = $this->node->appendChild($node);
    136         }
    137     }
    138 
    139     /**
    140      * @abstract                                        Create a XML-Object from the ORDER-Object
    141      * @return            XML                             The created XML from the ORDER
    142      */
    143     public function toXML() {
    144         return $this->doc->saveXML();
    145     }
    146 
    147     /**
    148      * @abstract                                        Validate the ORDER with the schema, defined in the constant MDXI_SCHEMA
    149      * @uses            CONSTANT                         MDXI_SCHEMA
    150      * @return            BOOLEAN                         TRUE if the validation was successful or FALSE
    151      */
    152     public function validate() {
    153       $mdxi = "/MDXI.xsd";
    154      
    155       if($this->olderThanOneWeek(__DIR__ . $mdxi)){
    156         set_time_limit(0);
    157         ini_set('display_errors',true);
    158        
    159         $fp = fopen (__DIR__ . '/MDXInew.xsd', 'w');
    160         $ch = curl_init(MDXI_SCHEMA);
    161         curl_setopt($ch, CURLOPT_FILE, $fp);
    162         curl_setopt($ch, CURLOPT_HEADER, 0);
    163         curl_setopt($ch, CURLOPT_CAINFO, __DIR__.'/cacert.pem');
    164         $result = curl_exec($ch);
    165        
    166         if(curl_getinfo($ch, CURLINFO_HTTP_CODE) === 200 && file_exists(__DIR__ . '/MDXInew.xsd')) {
    167           unlink(__DIR__ . $mdxi);
    168           fclose($fp);
    169           rename(__DIR__ . "/MDXInew.xsd", __DIR__ . $mdxi);
    170         } else
    171           fclose($fp);
    172        
    173         curl_close($ch);
     229          return false;
    174230      }
    175 
    176       return $this->doc->schemaValidate(__DIR__ . $mdxi);
    177     }
    178    
    179     private function xmlencode($txt)
    180     {
    181         $txt = str_replace('<', '&lt;', $txt);
    182         $txt = str_replace('>', '&gt;', $txt);
    183         $txt = str_replace('&amp;apos;', "'", $txt);
    184         $txt = str_replace('&amp;quot;', '"', $txt);
    185         return $txt;
    186     }
    187    
    188     private function olderThanOneWeek($filename){
    189       $year = date ("Y", filemtime($filename));
    190       $month = date ("m", filemtime($filename));
    191       $day = date ("d", filemtime($filename));
    192      
    193       $tyear = date ("Y");
    194       $tmonth = date ("m");
    195       $tday = date ("d");
    196      
    197       if($tyear > $year)
    198         return true;
    199       else {
    200         if($tmonth > $month){
    201           if($tday > 7)
    202             return true;
    203           else {
    204             if($tday-7+30 < $day)
    205               return false;
    206             else
    207               return true;
    208           }
    209         } else {
    210           if($tday-7 > $day)
    211             return true;
    212           else {
    213             return false;
    214           }
    215         }
    216       }
    217     }
     231    }
     232  }
    218233}
    219234?>
  • woocommerce-mpay24-gateway/trunk/readme.txt

    r696575 r803175  
    55Tags: woocommerce, gateway, mpay24
    66Requires at least: 3.5
    7 Tested up to: 3.5.1
    8 Stable tag: 1.1
     7Tested up to: 3.7.1
     8Stable tag: 1.2
    99License: GNU General Public License v3.0
    1010License URI: http://www.gnu.org/licenses/gpl-3.0.html
     
    1616= Features =
    1717
    18 * Uses mPAY24 PHP files (version 2013-01-17), follows mPAY24 specification (version 2013-02-22)
     18* Uses mPAY24 PHP files (version 2013-06-24), follows mPAY24 specification (version 2013-10-08)
    1919* Using the mPAY24 payment page to integrate in website
    2020* Switching between DEV and PROD mPAY24 environment with SOAP logins
    2121* Supports all payment methods of mPAY24
    2222* Languages available for Wordpress Admin: EN, DE
    23 * Languages available for payment page: BG, CS, DE, EN, ES, FR, HU, NL (no real localisation)
     23* Languages available for payment page: BG, CS, DE, EN, ES, FR, HR, HU, IT, JA, NL, PL, PT, RO, RU, SK, SL, SR, TR, ZH
    2424* Supported currency in payment page: EUR
    2525* no mPAY24 proSafe Support
     
    6565== Changelog ==
    6666
     67= 1.2 =
     68
     69* 2013-11-12: Update to current mPAY24 specification
     70* Update mPAY24 API to current version
     71
    6772= 1.1 =
    6873
Note: See TracChangeset for help on using the changeset viewer.