📄 paypalwpp.php
字号:
$this->zcLog('before_process - DP-4', 'optionsAll: ' . print_r($optionsAll, true) . "\n" . 'optionsNVP: ' . print_r($optionsNVP, true) . "\n" . 'optionsShip' . print_r($optionsShip, true) . "\n" . 'Rest of data: ' . "\n" . number_format($order_amount, 2) . ' ' . $cc_expdate_month . ' ' . substr($cc_expdate_year, -2) . ' ' . $cc_first_name . ' ' . $cc_last_name . ' ' . $cc_type);
$response = $doPayPal->DoDirectPayment(number_format($order_amount, 2),
$cc_number,
$cc_checkcode,
$cc_expdate_month . substr($cc_expdate_year, -2),
$cc_first_name, $cc_last_name,
$cc_type,
$optionsAll, array_merge($optionsNVP, $optionsShip));
$this->zcLog('before_process - DP-5', 'resultset:' . "\n" . print_r($response, true));
// CHECK RESPONSE
$error = $this->_errorHandler($response, 'DoDirectPayment');
$this->feeamt = '';
$this->taxamt = '';
$this->pendingreason = '';
$this->reasoncode = '';
$this->numitems = sizeof($order->products);
$this->responsedata = $response;
if ($response['PNREF']) {
// PNREF only comes from payflow mode
$this->payment_type = MODULE_PAYMENT_PAYPALWPP_PF_TEXT_TYPE;
$this->transaction_id = $response['PNREF'];
$this->payment_status = (MODULE_PAYMENT_PAYPALWPP_TRANSACTION_MODE == 'Auth Only') ? 'Authorization' : 'Completed';
$this->avs = 'AVSADDR: ' . $response['AVSADDR'] . ', AVSZIP: ' . $response['AVSZIP'] . ', IAVS: ' . $response['IAVS'];
$this->cvv2 = $response['CVV2MATCH'];
$this->amt = $order_amount . ' ' . $my_currency;
$this->payment_time = date('Y-m-d h:i:s');
$this->responsedata['CURRENCYCODE'] = $my_currency;
$this->responsedata['EXCHANGERATE'] = $order->info['currency_value'];
$this->auth_code = $this->response['AUTHCODE'];
} else {
// here we're in NVP mode
$this->transaction_id = $response['TRANSACTIONID'];
$this->payment_type = MODULE_PAYMENT_PAYPALWPP_DP_TEXT_TYPE;
$this->payment_status = (MODULE_PAYMENT_PAYPALWPP_TRANSACTION_MODE == 'Auth Only') ? 'Authorization' : 'Completed';
$this->pendingreason = (MODULE_PAYMENT_PAYPALWPP_TRANSACTION_MODE == 'Auth Only') ? 'authorization' : '';
$this->avs = $response['AVSCODE'];
$this->cvv2 = $response['CVV2MATCH'];
$this->correlationid = $response['CORRELATIONID'];
$this->payment_time = urldecode($response['TIMESTAMP']);
$this->amt = urldecode($response['AMT'] . ' ' . $response['CURRENCYCODE']);
$this->auth_code = (isset($this->response['AUTHCODE'])) ? $this->response['AUTHCODE'] : $this->response['TOKEN'];
$this->transactiontype = 'cart';
}
}
}
/**
* When the order returns from the processor, this stores the results in order-status-history and logs data for subsequent use
*/
function after_process() {
global $insert_id, $db, $order;
// add a new OSH record for this order's PP details
$commentString = "Transaction ID: :transID: " .
(isset($this->responsedata['PPREF']) ? "\nPPRef: " . $this->responsedata['PPREF'] : "") .
(isset($this->responsedata['AUTHCODE'])? "\nAuthCode: " . $this->responsedata['AUTHCODE'] : "") .
"\nPayment Type: :pmtType: " .
"\nTimestamp: :pmtTime: " .
"\nPayment Status: :pmtStatus: " .
($this->avs != 'N/A' ? "\nAVS Code: ".$this->avs."\nCVV2 Code: ".$this->cvv2 : '') .
"\nAmount: :orderAmt: ";
$commentString = $db->bindVars($commentString, ':transID:', $this->transaction_id, 'noquotestring');
$commentString = $db->bindVars($commentString, ':pmtType:', $this->payment_type, 'noquotestring');
$commentString = $db->bindVars($commentString, ':pmtTime:', $this->payment_time, 'noquotestring');
$commentString = $db->bindVars($commentString, ':pmtStatus:', $this->payment_status, 'noquotestring');
$commentString = $db->bindVars($commentString, ':orderAmt:', $this->amt, 'noquotestring');
$sql_data_array= array(array('fieldName'=>'orders_id', 'value'=>$insert_id, 'type'=>'integer'),
array('fieldName'=>'orders_status_id', 'value'=>$order->info['order_status'], 'type'=>'integer'),
array('fieldName'=>'date_added', 'value'=>'now()', 'type'=>'noquotestring'),
array('fieldName'=>'customer_notified', 'value'=>0, 'type'=>'integer'),
array('fieldName'=>'comments', 'value'=>$commentString, 'type'=>'string'));
$db->perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
// store the PayPal order meta data -- used for later matching and back-end processing activities
$paypal_order = array('order_id' => $insert_id,
'txn_type' => $this->transactiontype,
'module_name' => $this->code,
'module_mode' => MODULE_PAYMENT_PAYPALWPP_MODULE_MODE,
'reason_code' => $this->reasoncode,
'payment_type' => $this->payment_type,
'payment_status' => $this->payment_status,
'pending_reason' => $this->pendingreason,
'invoice' => urldecode($_SESSION['paypal_ec_token'] . $this->responsedata['PPREF']),
'first_name' => $_SESSION['paypal_ec_payer_info']['payer_firstname'],
'last_name' => $_SESSION['paypal_ec_payer_info']['payer_lastname'],
'payer_business_name' => $_SESSION['paypal_ec_payer_info']['payer_business'],
'address_name' => $_SESSION['paypal_ec_payer_info']['ship_name'],
'address_street' => $_SESSION['paypal_ec_payer_info']['ship_street_1'],
'address_city' => $_SESSION['paypal_ec_payer_info']['ship_city'],
'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_PAYPALWPP_MODULE_MODE,0,7) == 'Payflow' ? MODULE_PAYMENT_PAYPALWPP_PFVENDOR : str_replace('_api1', '', MODULE_PAYMENT_PAYPALWPP_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/', 'paypalwpp.php', 'false'));
$error = array('title' => MODULE_PAYMENT_PAYPALWPP_ERROR_HEADING,
'error' => ((isset($_GET['error'])) ? stripslashes(urldecode($_GET['error'])) : MODULE_PAYMENT_PAYPALWPP_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_PAYPALWPP_STATUS'");
$this->_check = !$check_query->EOF;
}
return $this->_check;
}
/**
* Installs all the configuration keys for this module
*/
function install() {
global $db;
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('鍚
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -