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: 759 $
     * @filesource
     * 
     */

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

    // SVN: $Id: paypal.php 759 2011-10-12 14:02:14Z tiefland $

    require_once "creditcard.interface.php";

    class paypal implements creditcard
    {
        protected $ini;

        function __construct()
        {
            if ( !is_array( $_SESSION["INI"] ) )
            {
                $this->ini = $GLOBALS["INI"];
            }
            else
            {
                $this->ini = $_SESSION["INI"];
            }
        }
        function getCreditcardStatus( $bestellId )
        {
            $summe = getBasketSumme();
            if ( $_SESSION["brutto"] == true && $this->ini["netto_preise"] ==
                1 )
            {
                $summe = getBasketSummeBrutto();
            }
            $prot = "http";
            if ( $this->ini["ssl_buy"] == 1 )
            {
                $prot = "https";
            }
            if ( isset( $this->ini["paypal"]["aktiv"] ) && $this->ini["paypal"]["email"] )
            {
                $email = $this->ini["paypal"]["email"];
                $out = '
                    <form action="https://www.paypal.com/cgi-bin/webscr" method="post" name="paypal" target="_top" id="zahlung">Wenn Sie nicht automatisch weitergeleitet werden, dr&uuml;cken Sie bitte auf den PayPal-Button.<br>
                        <br>
                        <input type="hidden" name="cmd" value="_xclick">
                        <input type="hidden" name="business" value="' . $email .
                    '">
                        <input type="hidden" name="currency_code" value="EUR">
                        <input type="hidden" name="cancel_return" value="' .
                    $prot . '://' . $_SERVER["SERVER_NAME"] .
                    '/paypal_cancel_' . $bestellId . '.html">
                        <input type="hidden" name="return" value="' . $prot .
                    '://' . $_SERVER["SERVER_NAME"] . '/paypal_accept_' . $bestellId .
                    '.html">
                        <input type="hidden" name="amount" value="' . $summe .
                    '">
                        <input type="hidden" name="item_name" value="Ihre Bestellung bei ' .
                    $_SERVER["SERVER_NAME"] . ' (BestNr.: ' . $bestellId .
                    ')">
                        <input type="hidden" name="custom" value="' . $bestellId .
                    '" />
                        <br>
                        <input style="cursor: pointer;" type="image" name="submit" value="Jetzt mit PayPal bezahlen!" src="/images/webelemente/versand_paypal.jpg" alt="Jetzt mit PayPal bezahlen!">
                    </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;
                    $bemerkung .=
                        "Die Zahlung per Paypal wurde vom Kunden am " . date( "d.m.Y" ) .
                        " um " . date( "H:i" ) . " Uhr abgebrochen!\n";
                    $status = "abgebrochen";
                    break;
                case "accept":
                    $res = true;
                    $bemerkung .= "Die Zahlung wurde von Paypal am " . date( "d.m.Y" ) .
                        " um " . date( "H:i" ) . " Uhr genehmigt!\n";
                    $res = true;
                    if ( USE_TRANSLATION2 === true )
                    {
                        $msg = $GLOBALS["langstrings"]["buy"]["paypal_accepted"];
                    } elseif ( $_SESSION["languageException"] )
                    {
                        $msg = "Paypal confirmed the successful payment";
                    }
                    else
                    {
                        $msg =
                            "Paypal hat die erfolgreiche Bezahlung best&auml;tigt!";
                    }
                    break;
            }
            $query = "
                UPDATE
                    $table
                SET
                    Bemerkung='$bemerkung'
                WHERE
                    id=$bestellId
            ";
            mysql_query( $query, $GLOBALS["order_dbh"] );
            $ret = array( "error" => !$res );
            if ( $ret["error"] )
            {
                $msg = $this->_getMsg( $ret, $status, $bestellId );
            }
            $ret["meld"] = $msg;
            return $ret;
        }
        function genCheckSum( $src )
        {
            switch ( $this->ini["kreditkarte"]["sha_algo"] )
            {
                case "sha512":
                    $data = hash( "sha512", $src );
                    break;
                case "sha256":
                    $data = hash( "sha256", $src );
                    break;
                case "sha1":
                default:
                    $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;
            }
            $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;
        }
    }
?>