//Register Globals Workaround
foreach ($_GET as $key=>$val) {
GLOBAL $no_register_global;
securityCheck($key,$val);
if(!$no_register_global) ${$key}=$val;
}
foreach ($_POST as $key=>$val) {
GLOBAL $no_register_global;
securityCheck($key,$val);
if(!$no_register_global) ${$key}=$val;
}
//komplette URL (Pfad+Query-String) wird überprüft
securityCheck("",$_SERVER['REQUEST_URI']);
function securityCheck($key,$val)
{
//Arrays nicht prüfen und Variabele von Shop-Einstellungen für ConvesionTracking
if($val AND is_array($val) OR $key=="ga_conversion_global" OR $key=="ga_conversion_signup" OR $key=="ga_conversion_order" OR $key == "ref") return "";
if($key=="sid" AND strlen($val)>=38) fail2ban($key,$val,"301");
else if((substr($key,-3)=="_id" OR $key=="id") AND !is_int($val+1)) fail2ban($key,$val,"302");
else if(preg_match("/cmdshell|exec master|%TEMP%|cmd \/c|wait for delay|;select|select sleep|dnstun|waitfor delay/i",$val)) fail2ban($key,$val,"303");
else if(preg_match("/#temp#|cmd \/c|xampp|char\(|chr\(|bin\(|union all|all select|union select|null,null/i",$val)) fail2ban($key,$val,"304");
else if(preg_match("/boolean mode|concat\(|convert\(|case when|then 1 else|drop function|dbms_pipe/i",$val)) fail2ban($key,$val,"305");
else if(preg_match("/sleep\(|select upper|select var|@version|ping -n|select server|1=1/i",$val)) fail2ban($key,$val,"306");
else if(preg_match("/
";
if ( !$direkt_link ) return $html;
// Ab hier Link per HTML für Mail zb
$paypal_link = "https://www.paypal.com/cgi-bin/webscr?&cmd=_cart&upload=1&business=###mailadresse###¤cy_code=EUR&amount=###amount###&invoice=###ordernr###";
$paypal_link = preg_replace("/###mailadresse###/", trim($this->system->settings['paypal_mailadresse']), $paypal_link );
$paypal_link = preg_replace("/###amount###/", $brutto_preis_gesamt, $paypal_link );
$paypal_link = preg_replace("/###ordernr###/", $order_nr, $paypal_link );
// Items hinzufügen
$paypal_link .= "##items###";
$i=1;
$item_parameter="";
foreach ( $public_cart['items'] as $item ) {
$item_parameter .= '&item_name_'.$i.'='.urlencode($item[name]);
$item_parameter .= '&amount_'.$i.'='.$item['unit_amount']->value;
$item_parameter .= '&quantity_'.$i.'='.$item[quantity];
$i++;
}
$item_parameter .= '&shipping_1='.$lieferpreis;
if ( $gutschein ) {
$item_parameter .= '&discount_amount_1='.($gutschein['produkt_preis_brutto']*-1);
}
$paypal_link = preg_replace("/###items###/", $item_parameter, $paypal_link );
return $paypal_link;
/* ALS HTML Button funktioniert in Mail nicht
$html = '
';
*/
}
/**
* Prüft ob PayPal Express Transaction erfolgreich war und legt die Bestellung an
*
* @param string $orderId
*/
function getOrder($orderId)
{
$k_id=$this->k_id;
try {
// Verbindung zu PayPal
if ( $this->enableSandbox == true ) $environment = new PayPalCheckoutSdk\Core\SandboxEnvironment( $this->live->clientID, $this->live->clientSECRET );
else $environment = new PayPalCheckoutSdk\Core\ProductionEnvironment( $this->live->clientID, $this->live->clientSECRET );
$client = new PayPalCheckoutSdk\Core\PayPalHttpClient( $environment );
// Order ziehen
$response = $client->execute(new PayPalCheckoutSdk\Orders\OrdersGetRequest($orderId));
$details = json_decode($_POST['details']);
// Bestellung anlegen
if ( $response->result->status == "COMPLETED" && $response->statusCode == "200" )
{
$liefer_daten = $response->result->purchase_units[0]->shipping;
$kontaktgruppe_id = $this->system->settings['kontaktgruppe_guest_id'];
$company = "";
$anrede_id = 0; // Wird von PayPal nicht geliefert
$akagrad_id = 0; // Wird von PayPal nicht geliefert
// Name nur komplett geliefert:
$name = explode(" ", $liefer_daten->name->full_name, 2);
$vorname = $name[0];
$nachname = $name[1];
$strasse_hno = explode(" ", $liefer_daten->address->address_line_1, 2);
$strasse = $strasse_hno[0];
$hno = $strasse_hno[1];
$additional = $liefer_daten->address->address_line_2;
$plz = $liefer_daten->address->postal_code;
$stadt = $liefer_daten->address->admin_area_2;
$land_id = $this->system->db->setup_land->TakeData("id","k_id='$k_id' AND kuerzel='".$liefer_daten->address->country_code."'" );
$email = $details->email_address;
// Adresse des Customer aktualisieren
$address = array();
$kontakt_id = $this->system->session['userid'];
$address['id'] = $this->system->session['userid']; // $this->system->db->kontakt_adresse->TakeData("id","k_id='$k_id' AND kontakt_id=".$this->system->session['userid']);
$address['address_type'] = "main";
$address['data_from_paypal'] = true; // Hier keinen AdressCheck durchführen
$address['firma'] = $additional;
$address['vorname'] = $vorname;
$address['nachname'] = $nachname;
$address['kurzname'] = $vorname . " " . $nachname;
$address['strasse'] = $liefer_daten->address->address_line_1;
$address['hausnummer'] = $hno;
$address['plz'] = $plz;
$address['ort'] = $stadt;
$address['land_id'] = $land_id;
// Mailadresse nur aktualisieren wenn es ein Gast ist ohne mailadresse
$user_type = $this->system->db->kontakt_shop->TakeData("type","k_id='$k_id' AND id='$kontakt_id'");
$mailadresse_kontakt = $this->system->db->kontakte->TakeData("email","k_id='$k_id' AND id='$kontakt_id'");
if ( $user_type == "guest" && $mailadresse_kontakt=='' ) $address['email'] = $email;
if ( $kontakt_id>0 )
{
$this->system->customer->updateCustomerData( $address );
if ( $user_type == "guest" && $mailadresse_kontakt=='' ) $this->system->customer->updateCustomerShop($kontakt_id, "guest", $email, "", "", 0, 0, 0, 0);
}
$order_nr = $response->result->purchase_units[0]->invoice_id;
$checkout_id=$this->system->checkout->getCheckoutStatus();
$this->system->db->checkout_status->UpdateData("order_nr='$order_nr'","k_id='$k_id' AND id='$checkout_id'");
$this->system->db->kunde_shopping->UpdateData("paypal_express_order_id='$orderId'", "id='".$this->system->shopping['id']."' AND k_id='$k_id' AND status='1'");
// redirect auf "Jetzt kaufen" seite
echo json_encode( array( 'checkout'=> $this->system->shop_url ."/" . $this->system->actual_lang_code . "/checkout") );
}
} catch (PayPal\Exception\PayPalConnectionException $ex) {
$subject="emediashop Paypal Exception - ". $this->system->settings['name'];
$fehler="Fehler in PayPal GetOrder
Exception: ".$ex->getMessage()."
Kunde: ".$this->k_id."
Code: ".$ex->getCode()."
Data: ".$ex->getData()."
Backtrace:
" . $ex->getTraceAsString();
$this->system->email->sendErrorMail2Admin($subject,$fehler);
}
}
function captureOrder( $order_id, $checkout_id)
{
try {
// Verbindung zu PayPal
if ( $this->enableSandbox == true ) $environment = new PayPalCheckoutSdk\Core\SandboxEnvironment( $this->live->clientID, $this->live->clientSECRET );
else $environment = new PayPalCheckoutSdk\Core\ProductionEnvironment( $this->live->clientID, $this->live->clientSECRET );
$client = new PayPalCheckoutSdk\Core\PayPalHttpClient( $environment );
// Order Status
$order_response = $client->execute(new PayPalCheckoutSdk\Orders\OrdersGetRequest( $order_id ));
$paypal_invoice_id = $order_response->result->purchase_units[0]->invoice_id;
// PR 2937 War mal leer => In diesem Fall von der checkout status Tabelle ziehen
if ( $paypal_invoice_id=="" ) {
$paypal_invoice_id = $this->system->db->checkout_status->TakeData("order_nr", "k_id='$this->k_id' AND id='$checkout_id'");
}
$this->system->db->checkout_status->UpdateData("paypal_invoice_id='".$paypal_invoice_id."'", "k_id='$this->k_id' AND id='$checkout_id'");
$authorization_id = $order_response->result->purchase_units[0]->payments->authorizations[0]->id;
$capture_request = new PayPalCheckoutSdk\Payments\AuthorizationsCaptureRequest( $authorization_id );
$capture_request->body = "{}";
$capture_response = $client->execute( $capture_request );
$order_response = $client->execute(new PayPalCheckoutSdk\Orders\OrdersGetRequest( $order_id ));
$authorization_status = $order_response->result->purchase_units[0]->payments->authorizations[0]->status;
if ( $authorization_status == "CAPTURED" ) {
$this->data[ack] = "success";
}
return $order_response;
} catch (PayPal\Exception\PayPalConnectionException $ex) {
$subject="emediashop Paypal Exception - ". $this->system->settings['name'];
$fehler="Fehler in PayPal DoExpressCheckoutPayment
Exception: ".$ex->getMessage()."
Kunde: ".$this->k_id."
Code: ".$ex->getCode()."
Data: ".$ex->getData()."
Backtrace:
" . $ex->getTraceAsString();
$this->system->email->sendErrorMail2Admin($subject,$fehler);
}
}
}
?>