Last active
December 20, 2015 03:19
-
-
Save cgsmith/6062549 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# Prepare Data to send | |
$params = array( | |
'USER' => trim($this->config->get($classname . '_mid')), | |
'VENDOR' => trim($this->config->get($classname . '_vendor')), | |
'PARTNER' => trim($this->config->get($classname . '_partner')), | |
'PWD' => trim($this->config->get($classname . '_key')), | |
'CREATESECURETOKEN' => 'Y', | |
'TRXTYPE' => $this->config->get($classname . '_mode'), | |
'AMT' => $amount, | |
'CURRENCY' => $currency, | |
'COMPANYNAME' => trim($order_info['payment_company']), | |
'BILLTOFIRSTNAME' => trim($order_info['payment_firstname']), | |
'BILLTOLASTNAME' => trim($order_info['payment_lastname']), | |
'BILLTOSTREET' => trim($order_info['payment_address_1'] . ' ' . $order_info['payment_address_2']), | |
'BILLTOCITY' => trim($order_info['payment_city']), | |
'BILLTOSTATE' => trim($order_info['payment_zone_code']), | |
'BILLTOZIP' => trim($order_info['payment_postcode']), | |
'BILLTOCOUNTRY' => trim($order_info['payment_iso_code_2']), | |
'CUSTIP' => trim($order_info['ip']), | |
'CUSTOM' => ('ORDID-' . $order_info['order_id']), | |
'EMAIL' => $order_info['email'], | |
'PHONENUM' => $order_info['telephone'], | |
'INVNUM' => ('INV' . $order_info['order_id']), // Paypal apparently requires this to start with a letter so I strip it later | |
'RETURNURL' => ($store_url . $classname.'_accept.php'), | |
'ERRORURL' => ($store_url . $classname.'_declined.php'), | |
'CANCELURL' => ($store_url . $classname.'_cancel.php'), | |
'NOTIFYURL' => ($store_url . $classname.'_callback.php'), | |
); | |
##### ITEMIZED TOTALS. 1.5.0 or LATER ###### | |
if (!method_exists($this->document, 'addBreadcrumb') && $this->config->get($classname . '_itemized')) { //1.5.x | |
$itemAmt = 0; | |
$i = 0; | |
### Itemized Products | |
foreach ($this->cart->getProducts() as $product) { | |
$description = $product['name']; | |
if ($product['option']) { | |
$values = array(); | |
foreach ($product['option'] as $option) { | |
if (isset($option['option_value'])) { | |
$values[] = $option['name'].':'.$option['option_value']; | |
} elseif (isset($option['value'])) { | |
$values[] = $option['name'].':'.$option['value']; | |
} | |
} | |
if ($values) { | |
$description = implode(', ', $values); | |
} else { | |
$description = ''; | |
} | |
} | |
$params["L_NAME$i"] = html_entity_decode($product['name'], ENT_QUOTES, "ISO-8859-1"); | |
$params["L_SKU$i"] = $product['model']; | |
$params["L_DESC$i"] = (substr(html_entity_decode($description, ENT_QUOTES, "ISO-8859-1"), 0, 110) . '...'); | |
$params["L_QTY$i"] = $product['quantity']; | |
$params["L_COST$i"] = $this->currency->format(($product['price'] * $product['quantity']), $currency, FALSE, FALSE); | |
$itemAmt += $params["L_COST$i"]; | |
$i++; | |
} | |
### Itemized Totals | |
$dbtotals = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_total where order_id = '" . $this->session->data['order_id'] . "' ORDER BY sort_order ASC"); | |
foreach ($dbtotals->rows as $dbtotal) { | |
if ($dbtotal['code'] == 'sub_total' || $dbtotal['code'] == 'total') { continue; } | |
$params["L_NAME$i"] = html_entity_decode(str_replace(array('-','_'), ' ', ucwords($dbtotal['code'])), ENT_QUOTES, "ISO-8859-1"); | |
$params["L_SKU$i"] = isset($dbtotal['code']) ? $dbtotal['code'] : str_replace(' ', '-', strtolower($dbtotal['title'])); | |
$params["L_DESC$i"] = html_entity_decode($dbtotal['title'], ENT_QUOTES, "ISO-8859-1"); | |
$params["L_QTY$i"] = 1; | |
$params["L_COST$i"] = $this->currency->format(($dbtotal['value']), $currency, FALSE, FALSE); | |
$itemAmt += (float)$params["L_COST$i"]; | |
$i++; | |
} | |
$params['ITEMAMT'] = number_format($itemAmt, 2, '.', ''); // ensure that is has 2 decimal precision because paypal is sensitive | |
//$params['SHIPPINGAMT'] = number_format(($amount-$itemAmt), 2, '.', ''); // ensure that is has 2 decimal precision because paypal is sensitive | |
} | |
########################################## | |
if ($this->cart->hasShipping()) { | |
$params['SHIPTOFIRSTNAME'] = trim($order_info['shipping_firstname']); | |
$params['SHIPTOLASTNAME'] = trim($order_info['shipping_lastname']); | |
$params['SHIPTOSTREET'] = trim($order_info['shipping_address_1'] . ' ' . $order_info['shipping_address_2']); | |
$params['SHIPTOCITY'] = trim($order_info['shipping_city']); | |
$params['SHIPTOSTATE'] = trim($order_info['shipping_zone_code']); | |
$params['SHIPTOZIP'] = trim($order_info['shipping_postcode']); | |
$params['SHIPTOCOUNTRY'] = trim($order_info['shipping_iso_code_2']); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment