📄 paypalwpp.php
字号:
return $process_button_string;
}
/**
* Prepare and submit the final authorization to PayPal via the appropriate means as configured
*/
function before_process() {
global $order, $doPayPal;
$options = array();
$optionsShip = array();
$optionsNVP = array();
$options = $this->getLineItemDetails();
//$this->zcLog('before_process - 1', 'Have line-item details:' . "\n" . print_r($options, true));
$doPayPal = $this->paypal_init();
if ($this->in_special_checkout() || $this->enableDirectPayment == false) {
$this->zcLog('before_process - EC-1', 'Beginning EC mode');
/****************************************
* Do EC checkout
****************************************/
// do not allow blank address to be sent to PayPal
if ($_SESSION['paypal_ec_payer_info']['ship_street_1'] != '' && $_SESSION['paypal_ec_payer_info']['ship_address_status'] != 'None') {
$options = array_merge($options,
array('SHIPTONAME' => $_SESSION['paypal_ec_payer_info']['ship_name'],
'SHIPTOSTREET' => $_SESSION['paypal_ec_payer_info']['ship_street_1'],
'SHIPTOSTREET2'=> $_SESSION['paypal_ec_payer_info']['ship_street_2'],
'SHIPTOCITY' => $_SESSION['paypal_ec_payer_info']['ship_city'],
'SHIPTOSTATE' => $_SESSION['paypal_ec_payer_info']['ship_state'],
'SHIPTOZIP' => $_SESSION['paypal_ec_payer_info']['ship_postal_code'],
'SHIPTOCOUNTRYCODE'=> $_SESSION['paypal_ec_payer_info']['ship_country_code'],
));
$this->zcLog('before_process - EC-2', 'address overrides added:' . "\n" . print_r($options, true));
}
$this->zcLog('before_process - EC-3', 'address info added:' . "\n" . print_r($options, true));
// If the customer has changed their shipping address,
// override the shipping address in PayPal with the shipping
// address that is selected in Zen Cart.
if ($order->delivery['street_address'] != $_SESSION['paypal_ec_payer_info']['ship_street_1'] && $_SESSION['paypal_ec_payer_info']['ship_street_1'] != '') {
$_GET['markflow'] = 2;
if (($address_arr = $this->getOverrideAddress()) !== false) {
// set the override var
$options['ADDROVERRIDE'] = 1;
// set the address info
$options['SHIPTONAME'] = $address_arr['entry_firstname'] . ' ' . $address_arr['entry_lastname'];
$options['SHIPTOSTREET'] = $address_arr['entry_street_address'];
if ($address_arr['entry_suburb'] != '') $options['SHIPTOSTREET2'] = $address_arr['entry_suburb'];
$options['SHIPTOCITY'] = $address_arr['entry_city'];
$options['SHIPTOZIP'] = $address_arr['entry_postcode'];
$options['SHIPTOSTATE'] = $address_arr['zone_code'];
$options['SHIPTOCOUNTRYCODE'] = $address_arr['countries_iso_code_2'];
}
}
// if these optional parameters are blank, remove them from transaction
if (isset($options['SHIPTOSTREET2']) && trim($options['SHIPTOSTREET2']) == '') unset($options['SHIPTOSTREET2']);
if (isset($options['SHIPTOPHONE']) && trim($options['SHIPTOPHONE']) == '') unset($options['SHIPTOPHONE']);
// if State is not supplied, repeat the city so that it's not blank, otherwise PayPal croaks
if ((!isset($options['SHIPTOSTATE']) || trim($options['SHIPTOSTATE']) == '') && $options['SHIPTOCITY'] != '') $options['SHIPTOSTATE'] = $options['SHIPTOCITY'];
$options['BUTTONSOURCE'] = $this->buttonSourceEC;
$options['CURRENCY'] = $this->selectCurrency($order->info['currency']);
$order_amount = $this->calc_order_amount($order->info['total'], $options['CURRENCY']);
// unused at present:
// $options['CUSTOM'] = '';
// $options['INVNUM'] = '';
// $options['DESC'] = '';
// debug output
$this->zcLog('before_process - EC-4', 'info being submitted:' . "\n" . $_SESSION['paypal_ec_token'] . ' ' . $_SESSION['paypal_ec_payer_id'] . ' ' . number_format($order_amount, 2) . "\n" . print_r($options, true));
$response = $doPayPal->DoExpressCheckoutPayment($_SESSION['paypal_ec_token'],
$_SESSION['paypal_ec_payer_id'],
number_format((isset($options['AMT']) ? $options['AMT'] : $order_amount), 2),
$options);
$this->zcLog('before_process - EC-5', 'resultset:' . "\n" . urldecode(print_r($response, true)));
// CHECK RESPONSE -- if error, actions are taken in the errorHandler
$error = $this->_errorHandler($response, 'DoExpressCheckoutPayment');
// SUCCESS
$this->payment_type = MODULE_PAYMENT_PAYPALWPP_EC_TEXT_TYPE;
$this->responsedata = $response;
if ($response['PAYMENTTYPE'] != '') $this->payment_type .= ' (' . urldecode($response['PAYMENTTYPE']) . ')';
$this->transaction_id = trim($response['PNREF'] . ' ' . $response['TRANSACTIONID']);
if (empty($response['PENDINGREASON']) ||
$response['PENDINGREASON'] == 'none' ||
$response['PENDINGREASON'] == 'completed' ||
$response['PAYMENTSTATUS'] == 'Completed') {
$this->payment_status = 'Completed';
if ($this->order_status > 0) $order->info['order_status'] = $this->order_status;
} else {
$this->payment_status = 'Pending (' . $response['PENDINGREASON'] . ')';
$order->info['order_status'] = $this->order_pending_status;
}
$this->avs = 'N/A';
$this->cvv2 = 'N/A';
$this->correlationid = $response['CORRELATIONID'];
$this->transactiontype = $response['TRANSACTIONTYPE'];
$this->payment_time = urldecode($response['ORDERTIME']);
$this->feeamt = urldecode($response['FEEAMT']);
$this->taxamt = urldecode($response['TAXAMT']);
$this->pendingreason = $response['PENDINGREASON'];
$this->reasoncode = $response['REASONCODE'];
// $this->numitems = $_SESSION['cart']->count_contents();
$this->numitems = sizeof($order->products);
$this->amt = urldecode($response['AMT'] . ' ' . $response['CURRENCYCODE']);
$this->auth_code = (isset($this->response['AUTHCODE'])) ? $this->response['AUTHCODE'] : $this->response['TOKEN'];
} else {
/****************************************
* Do DP checkout
****************************************/
$this->zcLog('before_process - DP-1', 'Beginning DP mode');
// Set state fields depending on what PayPal wants to see for that country
$this->setStateAndCountry($order->billing);
if (zen_not_null($order->delivery['street_address'])) {
$this->setStateAndCountry($order->delivery);
}
// Validate credit card data
include(DIR_WS_CLASSES . 'cc_validation.php');
$cc_validation = new cc_validation();
$response = $cc_validation->validate($_POST['ec_cc_number'], $_POST['ec_cc_expdate_month'], $_POST['ec_cc_expdate_year'],
$_POST['ec_cc_issuedate_month'], $_POST['ec_cc_issuedate_year']);
$error = '';
switch ($response) {
case -1:
$error = sprintf(TEXT_CCVAL_ERROR_UNKNOWN_CARD, substr($cc_validation->cc_number, 0, 4));
break;
case -2:
case -3:
case -4:
$error = TEXT_CCVAL_ERROR_INVALID_DATE;
break;
case false:
$error = TEXT_CCVAL_ERROR_INVALID_NUMBER;
break;
}
$this->zcLog('before_process - DP-2', 'CC validation results: ' . $error . '(' . $response . ')');
if ($response == false || $response < 1) {
$this->terminateEC($error, false, FILENAME_CHECKOUT_PAYMENT);
}
if (!in_array($cc_validation->cc_type, array('Visa', 'MasterCard', 'Switch', 'Solo', 'Discover', 'American Express', 'Maestro'))) {
$this->terminateEC(MODULE_PAYMENT_PAYPALWPP_TEXT_BAD_CARD, false, FILENAME_CHECKOUT_PAYMENT);
}
$this->zcLog('before_process - DP-3', 'CC info: ' . $cc_validation->cc_type . ' ' . substr($cc_validation->cc_number, 0, 4) . str_repeat('X', (strlen($cc_validation->cc_number) - 8)) . substr($cc_validation->cc_number, -4));
// if CC validation passed, continue using the validated data
$cc_type = $cc_validation->cc_type;
$cc_number = $cc_validation->cc_number;
$cc_first_name = $_POST['ec_payer_firstname'];
$cc_last_name = $_POST['ec_payer_lastname'];
$cc_checkcode = $_POST['ec_cc_checkcode'];
$cc_expdate_month = $cc_validation->cc_expiry_month;
$cc_expdate_year = $cc_validation->cc_expiry_year;
$cc_issuedate_month = $_POST['ec_cc_issuedate_month'];
$cc_issuedate_year = $_POST['ec_cc_issuedate_year'];
$cc_owner_ip = zen_get_ip_address();
// If they're still here, set some of the order object's variables.
$order->info['cc_type'] = $cc_type;
$order->info['cc_number'] = substr($cc_number, 0, 4) . str_repeat('X', (strlen($cc_number) - 8)) . substr($cc_number, -4);
$order->info['cc_owner'] = $cc_first_name . ' ' . $cc_last_name;
$order->info['cc_expires'] = $cc_expdate_month . substr($cc_expdate_year, -2);
$order->info['ip_address'] = $cc_owner_ip;
// Set currency
$my_currency = $this->selectCurrency($order->info['currency'], 'DP');
/*
// if CC is switch or solo, must be GBP
if (in_array($cc_type, array('Switch', 'Solo', 'Maestro'))) {
$my_currency = 'GBP';
}
*/
$order_amount = $this->calc_order_amount($order->info['total'], $my_currency);
// Initialize the paypal caller object.
$doPayPal = $this->paypal_init();
$optionsAll = array_merge($options,
array('STREET' => $order->billing['street_address'],
'ZIP' => $order->billing['postcode']));
$optionsNVP = array('CITY' => $order->billing['city'],
'STATE' => $order->billing['state'],
'COUNTRYCODE' => $order->billing['country']['iso_code_2'],
'EXPDATE' => $cc_expdate_month . $cc_expdate_year );
$optionsShip = array();
if (isset($order->delivery) && $order->delivery['street_address'] != '') {
$optionsShip= array('SHIPTONAME' => ($order->delivery['name'] == '' ? $order->delivery['firstname'] . ' ' . $order->delivery['lastname'] : $order->delivery['name']),
'SHIPTOSTREET' => $order->delivery['street_address'],
'SHIPTOSTREET2'=> $order->delivery['suburb'],
'SHIPTOCITY' => $order->delivery['city'],
'SHIPTOZIP' => $order->delivery['postcode'],
'SHIPTOSTATE' => $order->delivery['state'],
'SHIPTOCOUNTRYCODE'=> $order->delivery['country']['iso_code_2']);
}
// if these optional parameters are blank, remove them from transaction
if (isset($optionsShip['SHIPTOSTREET2']) && trim($optionsShip['SHIPTOSTREET2']) == '') unset($optionsShip['SHIPTOSTREET2']);
if (isset($optionsShip['SHIPTOPHONE']) && trim($optionsShip['SHIPTOPHONE']) == '') unset($optionsShip['SHIPTOPHONE']);
// if State is not supplied, repeat the city so that it's not blank, otherwise PayPal croaks
if (!isset($optionsShip['SHIPTOSTATE']) || trim($optionsShip['SHIPTOSTATE']) == '') $optionsShip['SHIPTOSTATE'] = $optionsShip['SHIPTOCITY'];
// Payment Transaction/Authorization Mode
$optionsNVP['PAYMENTACTION'] = (MODULE_PAYMENT_PAYPALWPP_TRANSACTION_MODE == 'Auth Only') ? 'Authorization' : 'Sale';
// if (in_array($cc_type, array('Switch', 'Solo'))) {
// $optionsNVP['PAYMENTACTION'] = 'Authorization';
// }
$optionsAll['BUTTONSOURCE'] = $this->buttonSourceDP;
$optionsAll['CURRENCY'] = $my_currency;
$optionsAll['IPADDRESS'] = $cc_owner_ip;
if ($cc_issuedate_month && $cc_issuedate_year) {
$optionsAll['CARDSTART'] = $cc_issuedate_month . substr($cc_issuedate_year, -2);
}
// unused at present:
// $options['CUSTOM'] = '';
// $options['INVNUM'] = '';
// $options['DESC'] = '';
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -