Subversion-Projekte lars-tiefland.php_share

Revision

Blame | Letzte Änderung | Log anzeigen | RSS feed

<?php

    /**
     * @package   php_share
     * @author    Lars Tiefland <tiefland@weban.de>
     * @copyright 2010 Webagentur Niewerth
     * @license   propietary http://www.weban.de
     * @version   $Rev: 761 $
     * @filesource
     * 
     */

    /**
     * 
     * @package   php_share
     * @author    Lars Tiefland <tiefland@weban.de>
     * @copyright 2010 Webagentur Niewerth
     */

    // SVN: $Id: sofortueberweisung.php 761 2011-10-12 14:04:34Z tiefland $

    require_once "creditcard.interface.php";

    class sofortueberweisung implements creditcard
    {
        protected $ini;

        function __construct()
        {
            if ( !is_array( $_SESSION["INI"] ) )
            {
                $this->ini = $GLOBALS["INI"];
            }
            else
            {
                $this->ini = $_SESSION["INI"];
            }
        }
        function getCreditcardStatus( $bestellId )
        {
            if ( isset( $this->ini["ueberweisung"]["zugang"] ) && $this->
                ini["ueberweisung"]["zugang"] )
            {
                define( "ZUGANG", $this->ini["ueberweisung"]["zugang"] );
                define( "SECRET", $this->ini["ueberweisung"]["secret"] );
                define( "PROJECT", $this->ini["ueberweisung"]["project"] );
                $reason_1 = $this->ini["ueberweisung"]["reason_1"];
                $reason_2 = $this->ini["ueberweisung"]["reason_2"] . $bestellId;
                $summe = getBasketSumme();
                if ( $_SESSION["brutto"] == true && $this->ini["netto_preise"] ==
                    1 )
                {
                    $summe = getBasketSummeBrutto();
                }
                $b_url = $this->ini["absoluteURL"];
                $b_url_s = ( $this->ini["ssl_buy"] ) ? str_replace( "http://",
                    "https://", $b_url ) : $b_url;
                $p_url = "https://www.sofortueberweisung.de/payment/start";
                $data = array( ZUGANG, PROJECT, '', '', '', '', $summe,
                    'EUR', $reason_1, $reason_2, $bestellId, '', '', '', '',
                    '', SECRET, );
                $data_implode = implode( '|', $data );
                $hash = $this->genCheckSum( $data_implode );
                $out = '
                    <form action="' . $p_url .
                    '" method="post" name="sofort" id="zahlung">
                        <input type="hidden" name="user_id" value="' .
                    ZUGANG . '">
                        <input type="hidden" name="project_id" value="' .
                    PROJECT . '">
                        <input type="hidden" name="amount" value="' . $summe .
                    '">
                        <input type="hidden" name="reason_1" value="' . $reason_1 .
                    '">
                        <input type="hidden" name="reason_2" value="' . $reason_2 .
                    '">
                        <input type="hidden" name="user_variable_0" value="' .
                    $bestellId . '">
                        <input type="hidden" name="currency_id" value="EUR"> 
                        <input type="hidden" name="hash" value="' . $hash .
                    '">
                        <input type="image" src="/images/webelemente/lockbox_150x65.png" />
                    </form>
                ';
                return $out;
            }
            return false;
        }

        function getCreditCardReturnStatus( $bestellId )
        {
            $table = ( $this->ini["dbConnect"]["order_db"] ) ? $this->ini["dbConnect"]["order_db"] .
                "." : "";
            $table .= "Bestellung";
            $query = "SELECT Bemerkung FROM $table WHERE id=$bestellId";
            $res = mysql_query( $query, $GLOBALS["order_dbh"] );
            $row = mysql_fetch_assoc( $res );
            $bemerkung = $row["Bemerkung"];

            switch ( $_GET["action"] )
            {
                case "cancel":
                    $res = false;
                    $status = "abgebrochen";
                    $bemerkung .=
                        "Die Zahlung auf sofortueberweisung.de wurde vom Kunden am " .
                        date( "d.m.Y" ) . " um " . date( "H:i" ) .
                        " Uhr abgebrochen!\n";
                    if ( USE_TRANSLATION2 === true )
                    {
                        $msg = $GLOBALS["langstrings"]["buy"]["sofort_canceled"];
                    } elseif ( $_SESSION["languageException"] )
                    {
                        $msg =
                            "You have canceled the payment. Click on the button to choose an other payment method.";
                    }
                    else
                    {
                        $msg =
                            "Sie haben die Zahlung abgebrochen. Klicken Sie auf den Button, um eine andere Zahlweise auszuwählen.";
                    }
                    break;
                case "accept":
                    $res = true;
                    $bemerkung .=
                        "Die Zahlung wurde von sofortueberweisung.de am " .
                        date( "d.m.Y" ) . " um " . date( "H:i" ) .
                        " Uhr genehmigt!\n";
                    if ( USE_TRANSLATION2 === true )
                    {
                        $msg = $GLOBALS["langstrings"]["buy"]["sofort_accepted"];
                    } elseif ( $_SESSION["languageException"] )
                    {
                        $msg =
                            "sofortueberweisung.de has confirmed your payment";
                    }
                    else
                    {
                        $msg =
                            "sofortüberweisung.de hat die erfolgreiche Bezahlung bestätigt!";
                    }
                    break;
                case "decline":
                    $status = "abgelehnt";
                    $_SESSION["zahlarten"]["ueberweisung"] = false;
                    $res = false;
                    $bemerkung .=
                        "Die Zahlung wurde von der sofortüberweisung.de am " .
                        date( "d.m.Y" ) . " um " . date( "H:i" ) .
                        " Uhr abgelehnt!\n";
                    break;
                case "except":
                    $status = "unklar";
                    $bemerkung .=
                        "Der Status der Zahlung wurde von sofortüberweisung.de am " .
                        date( "d.m.Y" ) . " um " . date( "H:i" ) .
                        " Uhr als unklar definiert!\n";
                    break;
            }
            $ret = array( "error" => !$res );
            $query = "
                UPDATE
                    $table
                SET
                    Bemerkung='$bemerkung'
                WHERE
                    id=$bestellId
            ";
            mysql_query( $query, $GLOBALS["order_dbh"] );
            if ( $ret["error"] )
            {
                $msg = $this->_getMsg( $ret, $status, $bestellId );
            }
            $ret["meld"] = $msg;
            return $ret;
        }
        function genCheckSum( $src )
        {
            switch ( $this->ini["ueberweisung"]["sha_algo"] )
            {
                case "sha512":
                default:
                    $data = hash( "sha512", $src );
                    break;
                case "sha256":
                    $data = hash( "sha256", $src );
                    break;
                case "sha1":
                    $data = sha1( $src );
                    break;
            }
            return $data;
        }
        private function _getMsg( $ret, $status, $bestellId )
        {
            if ( USE_TRANSLATION2 === true )
            {
                if ( $this->ini["change_order"] )
                {
                    $abschluss = $GLOBALS["langstrings"]["buy"]["click_button"];
                }
                else
                {
                    $abschluss = $GLOBALS["langstrings"]["buy"]["cancel_order"];
                }
            } elseif ( $_SESSION["languageException"] )
            {
                if ( $this->ini["change_order"] )
                {
                    $abschluss =
                        "Click on the button to choose an other payment method.";
                }
                else
                {
                    $abschluss = "Therefore we will now cancel your order.";
                }
            }
            else
            {
                if ( $this->ini["change_order"] )
                {
                    $abschluss =
                        "Klicken Sie auf den Button, um eine andere Zahlweise auszuwählen.";
                }
                else
                {
                    $abschluss =
                        "Deshalb werden wir nun Ihre Bestellung nun stornieren.";
                }
            }
            switch ( $status )
            {
                case "abgebrochen":
                    if ( USE_TRANSLATION2 === true )
                    {
                        $msg = $GLOBALS["langstrings"]["buy"]["order_canceled"];
                    } elseif ( $_SESSION["languageException"] )
                    {
                        $msg = "You have canceled the payment. ";
                    }
                    else
                    {
                        $msg = "Sie haben die Zahlung abgebrochen. ";
                    }
                    break;
                case "abgelehnt":
                    if ( USE_TRANSLATION2 === true )
                    {
                        $msg = $GLOBALS["langstrings"]["buy"]["sofort_declined"];
                    } elseif ( $_SESSION["languageException"] )
                    {
                        $msg =
                            "Unfortunately sofortuebwerweisung.de refused the payment. ";
                    }
                    else
                    {
                        $msg =
                            "Leider hat sofortüberweisung.de die Bezahlung verweigert. ";
                    }
                    break;
                case "unklar":
                    if ( USE_TRANSLATION2 === true )
                    {
                        $msg = $GLOBALS["langstrings"]["buy"]["sofort_excepted"];
                    } elseif ( $_SESSION["languageException"] )
                    {
                        "The status of the payment was defined as unclear by sofortueberweisung.de. ";
                    }
                    else
                    {
                        $msg =
                            "Der Status der zahlung wurde von sofortüberweisung.de als unklar definiert. ";
                    }
                    break;
            }
            $msg .= $abschluss;
            if ( $ret["error"] && $this->ini["change_order"] )
            {
                $msg .= '
                    <form method="post" action="/">
                        <input type="hidden" name="best_id" value="' . $bestellId .
                    '">
                        <input type="hidden" name="email" value="' . $_SESSION["SHOP"]["buy"]["Persdata"]["email"] .
                    '">
                        <input type="hidden" name="mode" value="change_order">
                        <input type="submit" value="Zahlart / Bestellung &auml;ndern">
                    </form>
                ';
            }
            return $msg;
        }
    }
?>