📄 paypaldp.php
字号:
'address_state' => $_SESSION['paypal_ec_payer_info']['ship_state'],
'address_zip' => $_SESSION['paypal_ec_payer_info']['ship_postal_code'],
'address_country' => $_SESSION['paypal_ec_payer_info']['ship_country'],
'address_status' => $_SESSION['paypal_ec_payer_info']['ship_address_status'],
'payer_email' => $_SESSION['paypal_ec_payer_info']['payer_email'],
'payer_id' => $_SESSION['paypal_ec_payer_id'],
'payer_status' => $_SESSION['paypal_ec_payer_info']['payer_status'],
'payment_date' => trim(preg_replace('/[^0-9-:]/', ' ', $this->payment_time)),
'business' => '',
'receiver_email' => (substr(MODULE_PAYMENT_PAYPALDP_MODULE_MODE,0,7) == 'Payflow' ? MODULE_PAYMENT_PAYPALDP_PFVENDOR : str_replace('_api1', '', MODULE_PAYMENT_PAYPALDP_APIUSERNAME)),
'receiver_id' => '',
'txn_id' => $this->transaction_id,
'parent_txn_id' => '',
'num_cart_items' => (float)$this->numitems,
'mc_gross' => (float)$this->amt,
'mc_fee' => (float)urldecode($this->feeamt),
'mc_currency' => $this->responsedata['CURRENCYCODE'],
'settle_amount' => (float)urldecode($this->responsedata['SETTLEAMT']),
'settle_currency' => $this->responsedata['CURRENCYCODE'],
'exchange_rate' => (urldecode($this->responsedata['EXCHANGERATE']) > 0 ? urldecode($this->responsedata['EXCHANGERATE']) : 1.0),
'notify_version' => '0',
'verify_sign' =>'',
'date_added' => 'now()',
'memo' => '{Record generated by payment module}'
);
zen_db_perform(TABLE_PAYPAL, $paypal_order);
// Unregister the paypal session variables, making it necessary to start again for another purchase
unset($_SESSION['paypal_ec_temp']);
unset($_SESSION['paypal_ec_token']);
unset($_SESSION['paypal_ec_payer_id']);
unset($_SESSION['paypal_ec_payer_info']);
unset($_SESSION['paypal_ec_final']);
unset($_SESSION['paypal_ec_markflow']);
}
/**
* Build admin-page components
*
* @param int $zf_order_id
* @return string
*/
function admin_notification($zf_order_id) {
global $db;
$module = $this->code;
$output = '';
$response = $this->_GetTransactionDetails($zf_order_id);
//$response = $this->_TransactionSearch('2006-12-01T00:00:00Z', $zf_order_id);
$sql = "SELECT * from " . TABLE_PAYPAL . " WHERE order_id = :orderID
AND parent_txn_id = '' AND order_id > 0
ORDER BY paypal_ipn_id DESC LIMIT 1";
$sql = $db->bindVars($sql, ':orderID', $zf_order_id, 'integer');
$ipn = $db->Execute($sql);
if ($ipn->RecordCount() == 0) $ipn->fields = array();
if (file_exists(DIR_FS_CATALOG . DIR_WS_MODULES . 'payment/paypal/paypalwpp_admin_notification.php')) require(DIR_FS_CATALOG . DIR_WS_MODULES . 'payment/paypal/paypalwpp_admin_notification.php');
return $output;
}
/**
* Used to read details of an existing transaction. FOR FUTURE USE.
*/
function _GetTransactionDetails($oID) {
global $db, $messageStack, $doPayPal;
$doPayPal = $this->paypal_init();
// look up history on this order from PayPal table
$sql = "select * from " . TABLE_PAYPAL . " where order_id = :orderID AND parent_txn_id = '' ";
$sql = $db->bindVars($sql, ':orderID', $oID, 'integer');
$zc_ppHist = $db->Execute($sql);
if ($zc_ppHist->RecordCount() == 0) return false;
$txnID = $zc_ppHist->fields['txn_id'];
/**
* Read data from PayPal
*/
$response = $doPayPal->GetTransactionDetails($txnID);
$error = $this->_errorHandler($response, 'GetTransactionDetails', 10007);
if ($error === false) {
return false;
} else {
return $response;
}
}
/**
* Used to read details of existing transactions. FOR FUTURE USE.
*/
function _TransactionSearch($startDate = '', $oID = '', $criteria = '') {
global $db, $messageStack, $doPayPal;
$doPayPal = $this->paypal_init();
// look up history on this order from PayPal table
$sql = "select * from " . TABLE_PAYPAL . " where order_id = :orderID AND parent_txn_id = '' ";
$sql = $db->bindVars($sql, ':orderID', $oID, 'integer');
$zc_ppHist = $db->Execute($sql);
if ($zc_ppHist->RecordCount() == 0) return false;
$txnID = $zc_ppHist->fields['txn_id'];
$startDate = $zc_ppHist->fields['payment_date'];
$timeval = time();
if ($startDate == '') $startDate = date('Y-m-d', $timeval) . 'T' . date('h:i:s', $timeval) . 'Z';
/**
* Read data from PayPal
*/
$response = $doPayPal->TransactionSearch($startDate, $txnID, $email, $criteria);
$error = $this->_errorHandler($response, 'TransactionSearch');
if ($error === false) {
return false;
} else {
return $response;
}
}
/**
* Display appropriate error message when needed
*/
function get_error() {
include_once(zen_get_file_directory(DIR_FS_CATALOG . DIR_WS_LANGUAGES . $_SESSION['language'] . '/modules/payment/', 'paypaldp.php', 'false'));
$error = array('title' => MODULE_PAYMENT_PAYPALDP_ERROR_HEADING,
'error' => ((isset($_GET['error'])) ? stripslashes(urldecode($_GET['error'])) : MODULE_PAYMENT_PAYPALDP_TEXT_CARD_ERROR));
return $error;
}
/**
* Evaluate installation status of this module. Returns true if the status key is found.
*/
function check() {
global $db;
if (!isset($this->_check)) {
$check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_PAYPALDP_STATUS'");
$this->_check = !$check_query->EOF;
}
return $this->_check;
}
/**
* Installs all the configuration keys for this module
*/
function install() {
global $db, $messageStack;
// cannot install DP if EC not already enabled:
if (!defined('MODULE_PAYMENT_PAYPALWPP_STATUS') || MODULE_PAYMENT_PAYPALWPP_STATUS != 'True') {
$messageStack->add_session('<strong>Sorry, you must install and configure PayPal Express Checkout first.</strong> Website Payments Pro requires that you offer Express Checkout to your customers.<br /><a href="' . zen_href_link('modules.php?set=payment&module=paypalwpp', '', 'NONSSL') . '">Click here to set up Express Checkout.</a>' , 'error');
zen_redirect(zen_href_link(FILENAME_MODULES, 'set=payment&module=paypaldp', 'NONSSL'));
return 'failed';
}
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable this Payment Module', 'MODULE_PAYMENT_PAYPALDP_STATUS', 'True', 'Do you want to enable this payment module?', '6', '25', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Live or Sandbox', 'MODULE_PAYMENT_PAYPALDP_SERVER', 'live', '<strong>Live: </strong> Used to process Live transactions<br><strong>Sandbox: </strong>For developers and testing', '6', '25', 'zen_cfg_select_option(array(\'live\', \'sandbox\'), ', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort order of display.', 'MODULE_PAYMENT_PAYPALDP_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '25', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Payment Zone', 'MODULE_PAYMENT_PAYPALDP_ZONE', '0', 'If a zone is selected, only enable this payment method for that zone.', '6', '25', 'zen_get_zone_class_title', 'zen_cfg_pull_down_zone_classes(', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, use_function, date_added) values ('Set Order Status', 'MODULE_PAYMENT_PAYPALDP_ORDER_STATUS_ID', '2', 'Set the status of orders paid with this payment module to this value. <br /><strong>Recommended: Processing[2]</strong>', '6', '25', 'zen_cfg_pull_down_order_statuses(', 'zen_get_order_status_name', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, use_function, date_added) values ('Set Unpaid Order Status', 'MODULE_PAYMENT_PAYPALDP_ORDER_PENDING_STATUS_ID', '1', 'Set the status of unpaid orders made with this payment module to this value. <br /><strong>Recommended: Pending[1]</strong>', '6', '25', 'zen_cfg_pull_down_order_statuses(', 'zen_get_order_status_name', now())");
// $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, use_function, date_added) values ('Set Refund Order Status', 'MODULE_PAYMENT_PAYPALDP_REFUNDED_STATUS_ID', '1', 'Set the status of refunded orders to this value. <br /><strong>Recommended: Pending[1]</strong>', '6', '25', 'zen_cfg_pull_down_order_statuses(', 'zen_get_order_status_name', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Payment Action', 'MODULE_PAYMENT_PAYPALDP_TRANSACTION_MODE', 'Final Sale', 'How do you want to obtain payment?<br /><strong>Default: Final Sale</strong>', '6', '25', 'zen_cfg_select_option(array(\'Auth Only\', \'Final Sale\'), ', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Transaction Currency', 'MODULE_PAYMENT_PAYPALDP_CURRENCY', 'Selected Currency', 'Which currency should the order be sent to PayPal as? <br />NOTE: if an unsupported currency is sent to PayPal, it will be auto-converted to USD (or GBP if using UK account)<br /><strong>Default: Selected Currency</strong>', '6', '25', 'zen_cfg_select_option(array(\'Selected Currency\', \'Only USD\', \'Only AUD\', \'Only CAD\', \'Only EUR\', \'Only GBP\', \'Only CHF\', \'Only CZK\', \'Only DKK\', \'Only HKD\', \'Only HUF\', \'Only JPY\', \'Only NOK\', \'Only NZD\', \'Only PLN\', \'Only SEK\', \'Only SGD\', \'Only THB\'), ', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('PAYFLOW: User', 'MODULE_PAYMENT_PAYPALDP_PFUSER', '', 'If you set up one or more additional users on the account, this value is the ID of the user authorized to process transactions. Otherwise it should be the same value as VENDOR. This value is case-sensitive.', '6', '25', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('PAYFLOW: Partner', 'MODULE_PAYMENT_PAYPALDP_PFPARTNER', 'ZenCart', 'Your Payflow Partner linked to your Payflow account. This value is case-sensitive.<br />Typical values: <strong>PayPal</strong> or <strong>ZenCart</strong>', '6', '25', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('PAYFLOW: Vendor', 'MODULE_PAYMENT_PAYPALDP_PFVENDOR', '', 'Your merchant login ID that you created when you registered for the Payflow Pro account. This value is case-sensitive.', '6', '25', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added, set_function, use_function) values ('PAYFLOW: Password', 'MODULE_PAYMENT_PAYPALDP_PFPASSWORD', '', 'The 6- to 32-character password that you defined while registering for the account. This value is case-sensitive.', '6', '25', now(), 'zen_cfg_password_input(', 'zen_cfg_password_display')");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('PayPal Mode', 'MODULE_PAYMENT_PAYPALDP_MODULE_MODE', 'PayPal', 'Which PayPal API system should be used for processing? <br /><u>Choices:</u><br /><font color=green>For choice #1, you need to supply <strong>API Settings</strong> in the Express Checkout module.</font><br /><strong>1. PayPal</strong> = Website Payments Pro with a US PayPal account<br />or<br /><font color=green>for choices 2 & 3 you need to supply <strong>PAYFLOW settings</strong>, (and have a Payflow account)</font><br /><strong>2. Payflow-UK</strong> = Website Payments Pro UK Payflow Edition<br /><strong>3. Payflow-US</strong> = Payflow Pro Gateway only<!--<br /><strong>4. PayflowUS+EC</strong> = Payflow Pro with Express Checkout-->', '6', '25', 'zen_cfg_select_option(array(\'PayPal\', \'Payflow-UK\', \'Payflow-US\'), ', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Debug Mode', 'MODULE_PAYMENT_PAYPALDP_DEBUGGING', 'Off', 'Would you like to enable debug mode? A complete detailed log of failed transactions will be emailed to the store owner.', '6', '25', 'zen_cfg_select_option(array(\'Off\', \'Alerts Only\', \'Log File\', \'Log and Email\'), ', now())");
$this->notify('NOTIFY_PAYMENT_PAYPALDP_INSTALLED');
}
function keys() {
$keys_list = array('MODULE_PAYMENT_PAYPALDP_STATUS', 'MODULE_PAYMENT_PAYPALDP_SORT_ORDER', 'MODULE_PAYMENT_PAYPALDP_ZONE', 'MODULE_PAYMENT_PAYPALDP_ORDER_STATUS_ID', 'MODULE_PAYMENT_PAYPALDP_ORDER_PENDING_STATUS_ID', /*'MODULE_PAYMENT_PAYPALDP_REFUNDED_STATUS_ID', */'MODULE_PAYMENT_PAYPALDP_TRANSACTION_MODE', 'MODULE_PAYMENT_PAYPALDP_CURRENCY', 'MODULE_PAYMENT_PAYPALDP_MODULE_MODE', 'MODULE_PAYMENT_PAYPALDP_SERVER', 'MODULE_PAYMENT_PAYPALDP_DEBUGGING');
if (IS_ADMIN_FLAG === true && ((isset($_GET['debug']) && $_GET['debug']=='on') || PAYPAL_DEV_MODE == 'true') || strstr(MODULE_PAYMENT_PAYPALDP_MODULE_MODE, 'Payflow')) {
// $keys_list[]='MODULE_PAYMENT_PAYPALDP_MODULE_MODE';
}
return $keys_list;
}
/**
* De-install this module
*/
function remove() {
global $db;
$db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key LIKE 'MODULE\_PAYMENT\_PAYPALDP\_%'");
$this->notify('NOTIFY_PAYMENT_PAYPALDP_UNINSTALLED');
}
/**
* Check settings and conditions to determine whether we are in an Express Checkout phase or not
*/
function in_special_checkout() {
if ((defined('MODULE_PAYMENT_PAYPALDP_STATUS') && MODULE_PAYMENT_PAYPALDP_STATUS == 'True') &&
!empty($_SESSION['paypal_ec_token']) &&
!empty($_SESSION['paypal_ec_payer_id']) &&
!empty($_SESSION['paypal_ec_payer_info'])) {
return true;
}
}
/**
* Determine whether the shipping-edit button should be displayed or not
*/
function alterShippingEditButton() {
return false;
if ($this->in_special_checkout() && empty($_SESSION['paypal_ec_markflow'])) {
return zen_href_link('ipn_main_handler.php', 'type=ec&clearSess=1', 'SSL', true,true, true);
}
}
/**
* Debug Logging support
*/
function zcLog($stage, $message) {
static $tokenHash;
if ($tokenHash == '') $tokenHash = '_' . zen_create_random_value(4);
if (MODULE_PAYMENT_PAYPALDP_DEBUGGING == 'Log and Email' || MODULE_PAYMENT_PAYPALDP_DEBUGGING == 'Log File') {
$token = (isset($_SESSION['paypal_ec_token'])) ? $_SESSION['paypal_ec_token'] : preg_replace('/[^0-9.A-Z\-]/', '', $_GET['token']);
$token = ($token == '') ? date('m-d-Y-h-i') : $token; // or time()
$token .= $tokenHash;
$file = $this->_logDir . '/' . $this->code . '_Paypal_Action_' . $token . '.log';
if (defined('PAYPAL_DEV_MODE') && PAYPAL_DEV_MODE == 'true') $file = $this->_logDir . '/' . $this->code . '_Paypal_Debug_' . $token . '.log';
$fp = @fopen($file, 'a');
@fwrite($fp, date('M-d-Y h:i:s') . "\n" . $stage . "\n" . $message . "\n=================================\n\n");
@fclose($fp);
}
$this->_doDebug($stage, $message, false);
}
/**
* Debug Emailing support
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -