I have been working on the module for a while and I have a few questions regarding the process_button method from paypal.php.
PHP Code:
function process_button() {
global $db, $order, $currencies, $currency;
$options = array();
$optionsCore = array();
$optionsPhone = array();
$optionsShip = array();
$optionsLineItems = array();
$optionsAggregate = array();
$optionsTrans = array();
$buttonArray = array();
$this->totalsum = $order->info['total'];
From the above I understand these arrays holds the different data, needed to be submitted, but in my case I need only to submit:
$optionsLineItems as it is the one controlling the ordered products list, my module needs only to submit:
<input type="hidden" name="ItemStore1" value="theoutletseason">
<input type="hidden" name="ItemDescription1" value="first item">
<input type="hidden" name="ItemSKU1" value="product number of first item">
<input type="hidden" name="ItemSize1" value="size of first item">
<input type="hidden" name="ItemColor1" value="color of first item">
<input type="hidden" name="ItemQuantity1" value="quantity of first item">
<input type="hidden" name="ItemPrice1" value="price of the first">
<input type="hidden" name="ItemImage1" value="COMPLETE path of their image" />
So I thought if I modify slightly the code of function ipn_getLineItemDetails() from the paypal_functions.php script, I will be able to get the data I need.
Correct me If I 'm wrong but I only need a list of the ordered products, not shipping, not tax, nothing like that.
So my question is can I get rid of many of these $optionsxxx arrays, and still achieve the same functionality?
PHP Code:
// save the session stuff permanently in case internationalcheckout loses the session
$_SESSION['ppipn_key_to_remove'] = session_id();
$db->Execute("delete from " . TABLE_INTERNATIONALCHECKOUT_SESSION . " where session_id = '" . zen_db_input($_SESSION['ppipn_key_to_remove']) . "'");
$sql = "insert into " . TABLE_INTERNATIONALCHECKOUT_SESSION . " (session_id, saved_session, expiry) values (
'" . zen_db_input($_SESSION['ppipn_key_to_remove']) . "',
'" . base64_encode(serialize($_SESSION)) . "',
'" . (time() + (1*60*60*24*2)) . "')";
Regarding the SESSION Above it is needed by Zen Cart to work or it's just a requirement of Paypal?
PHP Code:
$db->Execute($sql);
$my_currency = select_pp_currency();
$this->transaction_currency = $my_currency;
$this->transaction_amount = ($this->totalsum * $currencies->get_value($my_currency));
I keep the above
and comment out the below code snippet
PHP Code:
/* Can I eliminate this section ???
$telephone = preg_replace('/\D/', '', $order->customer['telephone']);
if ($telephone != '') {
$optionsPhone['H_PhoneNumber'] = $telephone;
if (in_array($order->customer['country']['iso_code_2'], array('US','CA'))) {
$optionsPhone['night_phone_a'] = substr($telephone,0,3);
$optionsPhone['night_phone_b'] = substr($telephone,3,3);
$optionsPhone['night_phone_c'] = substr($telephone,6,4);
$optionsPhone['day_phone_a'] = substr($telephone,0,3);
$optionsPhone['day_phone_b'] = substr($telephone,3,3);
$optionsPhone['day_phone_c'] = substr($telephone,6,4);
} else {
$optionsPhone['night_phone_b'] = $telephone;
$optionsPhone['day_phone_b'] = $telephone;
}
}
$optionsCore = array(
'charset' => CHARSET,
'lc' => $order->customer['country']['iso_code_2'],
'page_style' => MODULE_PAYMENT_INTERNATIONALCHECKOUT_PAGE_STYLE,
'custom' => zen_session_name() . '=' . zen_session_id(),
'business' => MODULE_PAYMENT_INTERNATIONALCHECKOUT_BUSINESS_ID,
'return' => zen_href_link(FILENAME_CHECKOUT_PROCESS, 'referer=internationalcheckout', 'SSL'),
'cancel_return' => zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'),
'shopping_url' => zen_href_link(FILENAME_SHOPPING_CART, '', 'SSL'),
'notify_url' => zen_href_link('ipn_main_handler.php', '', 'SSL',false,false,true),
'redirect_cmd' => '_xclick',
'rm' => 2,
'bn' => 'zencart',
'mrb' => 'R-6C7952342H795591R',
'pal' => '9E82WJBKKGPLQ',
);
$optionsCust = array(
'first_name' => replace_accents($order->customer['firstname']),
'last_name' => replace_accents($order->customer['lastname']),
'address1' => replace_accents($order->customer['street_address']),
'city' => replace_accents($order->customer['city']),
'state' => zen_get_zone_code($order->customer['country']['id'], $order->customer['zone_id'], $order->customer['zone_id']),
'zip' => $order->customer['postcode'],
'country' => $order->customer['country']['iso_code_2'],
'email' => $order->customer['email_address'],
);
if ($order->customer['suburb'] != '') $optionsCust['address2'] = $order->customer['suburb'];
if (MODULE_PAYMENT_INTERNATIONALCHECKOUT_ADDRESS_REQUIRED == 2) $optionsCust = array(
'address_name' => replace_accents($order->customer['firstname'] . ' ' . $order->customer['lastname']),
'address_street' => replace_accents($order->customer['street_address']),
'address_city' => replace_accents($order->customer['city']),
'address_state' => zen_get_zone_code($order->customer['country']['id'], $order->customer['zone_id'], $order->customer['zone_id']),
'address_zip' => $order->customer['postcode'],
'address_country' => $order->customer['country']['title'],
'address_country_code' => $order->customer['country']['iso_code_2'],
'payer_email' => $order->customer['email_address'],
);
$optionsShip = array(
//'address_override' => MODULE_PAYMENT_INTERNATIONALCHECKOUT_ADDRESS_OVERRIDE,
'no_shipping' => MODULE_PAYMENT_INTERNATIONALCHECKOUT_ADDRESS_REQUIRED,
);*/
I understand the code below loops through the ordered products and get the info
PHP Code:
if (MODULE_PAYMENT_INTERNATIONALCHECKOUT_DETAILED_CART == 'Yes') $optionsLineItems = ipn_getLineItemDetails();
if (sizeof($optionsLineItems) > 0) {
$optionsLineItems['cmd'] = '_cart';
// $optionsLineItems['num_cart_items'] = sizeof($order->products);
PHP Code:
/* Not needed as I don't have to pass shipping nor handling data
if (isset($optionsLineItems['shipping'])) {
$optionsLineItems['shipping_1'] = $optionsLineItems['shipping'];
unset($optionsLineItems['shipping']);
}
if (isset($optionsLineItems['handling'])) {
$optionsLineItems['handling_1'] = $optionsLineItems['handling'];
unset($optionsLineItems['handling']);
}*/
unset($optionsLineItems['subtotal']);
// if line-item details couldn't be kept due to calculation mismatches or discounts etc, default to aggregate mode
if (!isset($optionsLineItems['item_name_1'])) $optionsLineItems = array();
//if ($optionsLineItems['amount'] != $this->transaction_amount) $optionsLineItems = array();
/*ipn_debug_email('Line Item Details (if blank, this means there was a data mismatch, and thus bypassed): ' . "\n" . print_r($optionsLineItems, true));
}*/
// Aggregate is it an Auxiliary array? Redundant?
PHP Code:
$optionsAggregate = array(
'cmd' => '_ext-enter',
'item_name' => MODULE_PAYMENT_INTERNATIONALCHECKOUT_PURCHASE_DESCRIPTION_TITLE,
'item_number' => MODULE_PAYMENT_INTERNATIONALCHECKOUT_PURCHASE_DESCRIPTION_ITEMNUM,
//'num_cart_items' => sizeof($order->products),
'amount' => number_format($this->transaction_amount, $currencies->get_decimal_places($my_currency)),
'shipping' => '0.00',
);
if (MODULE_PAYMENT_INTERNATIONALCHECKOUT_TAX_OVERRIDE == 'true') $optionsAggregate['tax'] = '0.00';
if (MODULE_PAYMENT_INTERNATIONALCHECKOUT_TAX_OVERRIDE == 'true') $optionsAggregate['tax_cart'] = '0.00';
From here I think everything is needed, please note I only need to submit the detailed order and nothing else ...
PHP Code:
$optionsTrans = array(
'upload' => (int)(sizeof($order->products) > 0),
'currency_code' => $my_currency,
// 'internationalcheckout_order_id' => $internationalcheckout_order_id,
//'no_note' => '1',
//'invoice' => '',
);
// if line-item info is invalid, use aggregate:
if (sizeof($optionsLineItems) > 0) $optionsAggregate = $optionsLineItems;
// prepare submission
$options = array_merge($optionsCore, $optionsCust, $optionsPhone, $optionsShip, $optionsTrans, $optionsAggregate);
ipn_debug_email('Keys for submission: ' . print_r($options, true));
// build the button fields
foreach ($options as $name => $value) {
// remove quotation marks
$value = str_replace('"', '', $value);
// check for invalid chars
if (preg_match('/[^a-zA-Z_0-9]/', $name)) {
ipn_debug_email('datacheck - ABORTING - preg_match found invalid submission key: ' . $name . ' (' . $value . ')');
break;
}
// do we need special handling for & and = symbols?
//if (strpos($value, '&') !== false || strpos($value, '=') !== false) $value = urlencode($value);
$buttonArray[] = zen_draw_hidden_field($name, $value);
}
$process_button_string = implode("\n", $buttonArray) . "\n";
$_SESSION['internationalcheckout_transaction_info'] = array($this->transaction_amount, $this->transaction_currency);
return $process_button_string;
}
/**
* Store transaction info to the order and process any results that come back from the payment gateway
*/