CREATE TABLE IF NOT EXISTS `phpwcms_shop_transactions` (
`transaction_id` int(10) unsigned NOT NULL auto_increment,
`receiver_email` varchar(60) collate latin1_bin default NULL,
`order_number` varchar(10) collate latin1_bin default NULL,
`payment_status` varchar(10) collate latin1_bin default NULL,
`pending_reason` varchar(10) collate latin1_bin default NULL,
`payment_date` varchar(20) collate latin1_bin default NULL,
`mc_gross` varchar(20) collate latin1_bin default NULL,
`mc_fee` varchar(20) collate latin1_bin default NULL,
`tax` varchar(20) collate latin1_bin default NULL,
`mc_currency` varchar(3) collate latin1_bin default NULL,
`txn_id` varchar(20) collate latin1_bin default NULL,
`txn_type` varchar(10) collate latin1_bin default NULL,
`first_name` varchar(30) collate latin1_bin default NULL,
`last_name` varchar(40) collate latin1_bin default NULL,
`address_street` varchar(50) collate latin1_bin default NULL,
`address_city` varchar(30) collate latin1_bin default NULL,
`address_state` varchar(30) collate latin1_bin default NULL,
`address_zip` varchar(20) collate latin1_bin default NULL,
`address_country` varchar(30) collate latin1_bin default NULL,
`address_status` varchar(10) collate latin1_bin default NULL,
`payer_email` varchar(60) collate latin1_bin default NULL,
`contact_phone` varchar(50) collate latin1_bin default NULL,
`payer_status` varchar(10) collate latin1_bin default NULL,
`payment_type` varchar(10) collate latin1_bin default NULL,
`notify_version` varchar(10) collate latin1_bin default NULL,
`verify_sign` varchar(10) collate latin1_bin default NULL,
`referrer_id` varchar(10) collate latin1_bin default NULL,
PRIMARY KEY (`transaction_id`)
) ENGINE=MyISAM AUTO_INCREMENT=14 ;
==== #2: Einspielen der notwendige Dateien ====
- front_order_process.inc.php \\
- paypal.class.php \\
hier herunterladen
{{:deutsch:module:shop:phpwcms_paypal.zip|}}
und auf den Server/ in include/inc_module/mod_shop_paypal/inc kopieren.
\\
==== #3: Modifizieren des bestehenden Orderprocess ====
Wenn im nachfolgenden des öftern von ggf. geredet wird bedeutet das, dass die Änderung nur vorzunehmen ist sollte die Funktion/ Abfrage/ Zeile noch nicht existieren. Es wurde seitens des Autors darauf verzichtet zu prüfen ob und ab wann die (teilweise) Paypal-Integrierung bereits von OG ins System implementiert wurde. \\
\\
=== 1. Template File ===
Falls nicht bereits vorhanden in der default.html (bzw. diejenige Templatedatei die verwendet wird) folgende Einstellungen \\
\\
Den Abschnitt:
<--- Config_Start --->
label_payby_prepay = "Cash with order"
label_payby_pod = "Cash on delivery"
label_payby_onbill = "On account"
mit folgendem erweitern:
label_payby_paypal = "PayPal"
\\
Im Abschnitt:
\\
Ausgabe der Zahlart in der eMail mit
[PAYBY_PAYPAL]You have paid via Paypal.[/PAYBY_PAYPAL]
erreichen.
\\
Nach
Order {ORDER} successfully sent
Hello {INV_FIRSTNAME} {INV_NAME},
Thanks for your order. You will receive a notification of your oder status at {EMAIL} once confirmation of your payment has been received...
Your order number is: {ORDER}. Please use this number in case you need to contact us by email.
Paypal class error message
{DEBUG_MSG1}
{DEBUG_MSG2}
{MESSAGE}
=== 2: edit.preferences.inc ===
suchen und ggf. danach (also wenn die neue tabelle aufgeht)
onchange="enableSubmit();" />
:
=== 3.1: frontend.render.php ===
$_tmpl['paypal_order_success'] = get_tmpl_section('PAYPAL_ORDER_DONE', $_tmpl['source']);
$_tmpl['paypal_order_debug'] = get_tmpl_section('PAYPAL_ORDER_DEBUG', $_tmpl['source']);
$_tmpl['paypal_order_canceled'] = get_tmpl_section('PAYPAL_ORDER_CANCELED', $_tmpl['source']);
und im Abschnitt
// merge config settings like translations and so on
$_tmpl['config'] = array_merge( array(
'label_payby_paypal' => "Paypal",
Direkt darunter unter
// get preferences
$_shopPref = array();
'shop_pref_email_paypal',
=== 3.2: frontend.render.php ===
Suche bei
elseif( isset($_POST['shop_order_submit']) && !isset($_SESSION['shopping_cart']['error']['step2']) )
} elseif( isset($_GET['shop_order_process']) ) {
//process order via paypal ipn
include($phpwcms['modules']['shop']['path'].'inc/front.order_process.inc.php');
=== 5. in front.order_submit.inc.php ===
Unter der stelle
// receive order db ID
$order_data = _dbInsert('phpwcms_shop_orders', $order_data);
// success inserting db record of order
$_SESSION['shopping_cart']['order_number'] = $order_num;
switch( $_SESSION['shopping_cart']['payby'] ){
case 'paypal':
headerRedirect(PHPWCMS_URL.$_tmpl['config']['cart_url']."&shop_order_process");
break;
default:
wobei sich ans default die
//send mail to customer anschließt.
ACHTUNG: switch nach der
// NO success routine mit
mit
} //endswitch
wieder schließen. \\
\\
=== 6. shop.func.php ===
Suche die Funktion
get_payment_options()
suchen und
$supported = array('paypal' => 0, 'prepay' => 0, 'pod' => 0, 'onbill' => 0);
überschreiben. \\
\\
Anschließend
function validateReferrer( $yoursite, //Your site url without 'http://' or subdomain
$domain_name //Type your domain with www. this time
)
{
$referer = $_SERVER['HTTP_REFERER'];
//Check if browser sends referrer url or not
if ($referer == "") { //If not, set referrer as your domain
$domain = $yoursite;
} else {
$domain = parse_url($referer); //If yes, parse referrer
}
if($domain['host'] == $yoursite || $domain['host'] == $domain_name) {
//Run your dowloading code here normally
} else {
//The referrer is not your site, we bail and redirect to home page
header("Location: http://".$domain_name."/index.php");
exit(); //Stop running the script
}
}
function reinitialize_session(&$_tmpl){
$_SESSION['shopping_cart']['order_number'] = ( isset($_POST['invoice']) ? clean_slweg($_POST['invoice']) : '' );
$_SESSION['shopping_cart']['step1'] = array(
'INV_FIRSTNAME' => isset($_POST['first_name']) ? clean_slweg($_POST['first_name']) : '',
'INV_NAME' => isset($_POST['last_name']) ? clean_slweg($_POST['last_name']) : '',
'INV_ADDRESS' => isset($_POST['address_street']) ? clean_slweg($_POST['address_street']) : '',
'INV_ZIP' => isset($_POST['address_zip']) ? clean_slweg($_POST['address_zip']) : '',
'INV_CITY' => isset($_POST['address_city']) ? clean_slweg($_POST['address_city']) : '',
'INV_REGION' => isset($_POST['address_state']) ? clean_slweg($_POST['address_state']) : '',
'INV_COUNTRY' => isset($_POST['address_country']) ? clean_slweg($_POST['address_country']) : '',
'EMAIL' => isset($_POST['payer_email']) ? clean_slweg($_POST['payer_email']) : '',
'PHONE' => isset($_POST['contact_phone']) ? clean_slweg($_POST['contact_phone']) : ''
);
}
function reinitialize_cart_products( $order_num ){
$cart_data = Array();
$cart_data[0] = "uninitialized";
$q_result = _dbQuery("SELECT * FROM ".DB_PREPEND."phpwcms_shop_orders WHERE order_number=".$order_num." LIMIT 1");
if(isset($q_result[0])){
$cart_data = unserialize($q_result[0]['order_data']);
}
return $cart_data;
}
function update_transactions_table(&$cart_data, &$P){
$temp = Array(
"txn_id",
"reason_code",
"receiver_email",
"mc_gross",
"protection_eligibility",
"address_status",
"payer_id",
"tax",
"address_street",
"payment_date",
"payment_status",
"charset",
"address_zip",
"mc_shipping",
"mc_handling",
"first_name",
"mc_fee",
"address_country_code",
"address_name",
"notify_version",
"custom",
"invoice",
"num_cart_items",
"payer_status",
"business",
"address_country",
"address_city",
"payer_email",
"contact_phone",
"verify_sign",
"payment_type",
"last_name",
"address_state",
"payment_fee",
"pending_reason",
"receiver_id",
"txn_type",
"mc_currency",
"residence_country",
"receipt_id",
"test_ipn",
"transaction_subject",
"payment_gross",
"merchant_return_link",
"form_charset"
);
$trans = Array();
foreach( $temp as $key ){
$trans[$key] = ( isset( $_POST[$key]) ? clean_slweg($_POST[$key]) : '');
}
for( $i=0; $i < $trans['num_cart_items']; $i++ ){
$trans['item_number'.($i+1)] = ( isset( $_POST['item_number' . ($i+1)]) ? clean_slweg($_POST['item_number'. ($i+1)]) : '');
$trans['mc_gross_'.($i+1)] = ( isset( $_POST['mc_gross_' . ($i+1)]) ? clean_slweg($_POST['mc_gross_' . ($i+1)]) : '');
$trans['quantity'.($i+1)] = ( isset( $_POST['quantity' . ($i+1)]) ? clean_slweg($_POST['quantity' . ($i+1)]) : '');
}
$validTransaction = true;
// test the txn_id; if txn_id is used and it's not a chargeback then it's invalid
$txn_id_is_used = _dbCount("Select * from".DB_PREPEND."phpwcms_shop_transactions where txn_id=".$trans['txn_id']);
if( $txn_id_is_used && !isset($trans['reason_code']) && !( empty($trans['txn_type']) && ($trans['reason_code'] === "chargeback")) ){
$validTransaction = false;
$lastError .= "Failed Anti-fraud test 1: txn_id is used: ".$txn_id_is_used." txn_type: ".$trans['txn_type']." trans_reason_code: ".$trans['reason_code']."\n";
}
// test receiver_email
if( $validTransaction && !( $trans['receiver_email'] === _getConfig( 'shop_pref_email_paypal', '_shopPref' ) ) ){
$validTransaction = false;
$lastError .= "Failed Anti-fraud test 2: unmatched email addresses for receiver_email: ".$trans['receiver_email']." vs "._getConfig( 'shop_pref_email_paypal', '_shopPref' )."\n";
}
// validate number of items
if( $validTransaction && ( count($cart_data['cart']) != $trans['num_cart_items'])){
$validTransaction = false;
$lastError .= "Failed Anti-fraud test 3: number of items mismatch: items in cart: ".count($cart_data['cart'])." vs items in post: ".$trans['num_cart_items']."\n";
}
// test to see that cart items match
if( $validTransaction ){
for( $i=0; $i < $trans['num_cart_items']; $i++ ){
if( $cart_data['cart'][$i]['shopprod_id'] != $trans['item_number'.($i+1)] ||
$cart_data['cart'][$i]['shopprod_price'] != $trans['mc_gross_'.($i+1)] ||
$cart_data['cart'][$i]['shopprod_quantity'] != $trans['quantity'.($i+1)] ){
$validTransaction = false;
$lastError .= "\n\nFailed Anti-fraud test 3: product mismatch: \n";
$lastError .= $cart_data['cart'][$i]['shopprod_id']." != ".$trans['item_number'.($i+1)].",\n";
$lastError .= $cart_data['cart'][$i]['shopprod_price']." != ".$trans['mc_gross_'.($i+1)].",\n";
$lastError .= $cart_data['cart'][$i]['shopprod_quantity']." != ".$trans['quantity'.($i+1)]."\n\n";
}
}
}
if( $validTransaction ){ // No fraud detected
$data = Array(
'receiver_email' => $trans['receiver_email'],
'order_number' => $trans['invoice'],
'payment_status' => $trans['payment_status'],
'pending_reason' => $trans['pending_reason'],
'payment_date' => $trans['payment_date'],
'mc_gross' => $trans['mc_gross'],
'mc_fee' => $trans['mc_fee'],
'tax' => $trans['tax'],
'mc_currency' => $trans['mc_currency'],
'txn_id' => $trans['txn_id'],
'txn_type' => $trans['txn_type'],
'first_name' => $trans['first_name'],
'last_name' => $trans['last_name'],
'address_street' => $trans['address_street'],
'address_city' => $trans['address_city'],
'address_state' => $trans['address_state'],
'address_zip' => $trans['address_zip'],
'address_country' => $trans['address_country'],
'address_status' => $trans['address_status'],
'payer_email' => $trans['payer_email'],
'contact_phone' => $trans['contact_phone'],
'payer_status' => $trans['payer_status'],
'payment_type' => $trans['payment_type'],
'notify_version' => $trans['notify_version'],
'verify_sign' => $trans['verify_sign'],
'referrer_id' => $trans['referrer_id']
);
_dbInsertOrUpdate( DB_PREPEND."phpwcms_shop_transactions", $data, "where `txn_id` = '".$trans['txn_id']."'", '');
}else{
$P->log_error($lastError );
}
return $validTransaction;
}
=== 7. processing.preferences.inc.php ===
Ersetzungen wie folgt. Nach
$plugin['data']['shop_pref_email_from'] = clean_slweg($_POST['pref_email_from']);
ggf. das einfügen
$plugin['data']['shop_pref_email_paypal'] = clean_slweg($_POST['pref_email_paypal']);
\\
nach
if(! is_valid_email($plugin['data']['shop_pref_email_from']) ) $plugin['data']['shop_pref_email_from'] = '';
ggf. das einfügen:
if(! is_valid_email($plugin['data']['shop_pref_email_paypal']) ) $plugin['data']['shop_pref_email_paypal'] = '';
\\
vor
'prepay' => empty($_POST['pref_payment_prepay']) ? 0 : 1,
ggf. das einfügen
'paypal' => empty($_POST['pref_payment_paypal']) ? 0 : 1,
\\
nach
_setConfig('shop_pref_email_from', $plugin['data']['shop_pref_email_from'], 'module_shop');
ggf. das einfügen
_setConfig('shop_pref_email_paypal', $plugin['data']['shop_pref_email_paypal'], 'module_shop');
\\
nach
'shop_pref_email_from' => '',
ggf. das einfügen
'shop_pref_email_paypal' => '',
\\
nach
'prepay'=> 1,
ggf. das einfügen
'paypal' => 1,
\\
\\
=== 8. Language-Files ===
Ggf. die language files unter /include/inc_module/mod_shop/lang mit paypal anreichern. \\
Das sollte eigentlich bei phpwcms > 2007 bereits vorhanden sein.
\\
Bspw. für deutsch nach
$BLM['shopprod_payment_method'] = 'Zahlungsmethoden';
das einfügen
$BLM['shopprod_payby_paypal'] = 'PayPal';
$BLM['shopprod_email_paypal'] = 'PayPal E-Mail';
\\
\\
\\
==== #4: Zusammenfassung ====
Jetzt müßte \\
a. die Zahlart PayPal Auswahl im Shop verfügbar sein
b. eine Weiterleitung zu PayPal geschehen (derzeit ist noch die Sandbox Testumgebung aktiv)
c. der Shop innerhalb seiner normalen Parameter funktionieren.
\\
Sollte eine der oben aufgeführten Punkte nicht zutreffen gibt es ein Problem. Kontrollier bitte noch einmal ganz genau die Punkt eins bis drei. Andernfalls: Happy PayPal'ing!!!
\\
\\