Index: branches/5.2.x/units/orders/orders_event_handler.php
===================================================================
diff -u -r14812 -r14813
--- branches/5.2.x/units/orders/orders_event_handler.php (.../orders_event_handler.php) (revision 14812)
+++ branches/5.2.x/units/orders/orders_event_handler.php (.../orders_event_handler.php) (revision 14813)
@@ -1,6 +1,6 @@
Application->isAdminUser) {
- return true;
+ return ;
}
else {
$event->setRedirectParams(Array('opener' => 's'), true);
@@ -675,7 +675,7 @@
else {
// strange: recalculate total amount on error
$object =& $event->getObject();
- /* @var $object kDBItem */
+ /* @var $object OrdersItem */
$object->SetDBField('TotalAmount', $object->getTotalAmount());
}
@@ -1428,10 +1428,10 @@
if ( $check_cc && ($field_values['PaymentType'] == $order->GetDBField('PaymentType')) ) {
// cc check required AND payment type was not changed during SUBMIT
if ( $this->Application->isAdminUser ) {
- $req_fields = Array ('PaymentCardType', 'PaymentAccount', 'PaymentNameOnCard', 'PaymentCCExpDate');
+ $req_fields = Array (/*'PaymentCardType',*/ 'PaymentAccount', /*'PaymentNameOnCard',*/ 'PaymentCCExpDate');
}
else {
- $req_fields = Array ('PaymentCardType', 'PaymentAccount', 'PaymentNameOnCard', 'PaymentCCExpDate', 'PaymentCVV2');
+ $req_fields = Array (/*'PaymentCardType',*/ 'PaymentAccount', /*'PaymentNameOnCard',*/ 'PaymentCCExpDate', 'PaymentCVV2');
}
$order->setRequired($req_fields);
@@ -2313,6 +2313,21 @@
$this->RecalculateProcessingFee($event);
$this->UpdateShippingTotal($event);
$this->RecalculateGift($event);
+
+ // guess fields from "One Step Checkout" form
+ if ( $object->GetDBField('PaymentAccount') ) {
+ $order_helper =& $this->Application->recallObject('OrderHelper');
+ /* @var $order_helper OrderHelper */
+
+ $object->SetDBField('PaymentCardType', $order_helper->getCreditCartType($object->GetDBField('PaymentAccount')));
+ }
+ else {
+ $object->SetDBField('PaymentCardType', '');
+ }
+
+ if ( !$object->GetDBField('PaymentNameOnCard') ) {
+ $object->SetDBField('PaymentNameOnCard', $object->GetDBField('BillingTo'));
+ }
}
/**
Index: branches/5.2.x/units/helpers/order_helper.php
===================================================================
diff -u -r14797 -r14813
--- branches/5.2.x/units/helpers/order_helper.php (.../order_helper.php) (revision 14797)
+++ branches/5.2.x/units/helpers/order_helper.php (.../order_helper.php) (revision 14813)
@@ -165,4 +165,34 @@
return $template;
}
+
+ /**
+ * Detects credit card type by it's number
+ *
+ * @param string $number
+ * @return int
+ * @access public
+ */
+ public function getCreditCartType($number)
+ {
+ // Get rid of any non-digits
+ $number = preg_replace('/[^\d]/', '', $number);
+
+ $mapping = Array (
+ '/^4.{15}$|^4.{12}$/' => 1, // Visa
+ '/^5[1-5].{14}$/' => 2, // MasterCard
+ '/^3[47].{13}$/' => 3, // American Express
+ '/^6011.{12}$/' => 4, // Discover
+ '/^30[0-5].{11}$|^3[68].{12}$/' => 5, // Diners Club
+ '/^3.{15}$|^2131|1800.{11}$/' => 6, // JBC
+ );
+
+ foreach ($mapping as $number_regex => $card_type) {
+ if ( preg_match($number_regex, $number) ) {
+ return $card_type;
+ }
+ }
+
+ return false;
+ }
}
Index: branches/5.2.x/units/orders/orders_tag_processor.php
===================================================================
diff -u -r14796 -r14813
--- branches/5.2.x/units/orders/orders_tag_processor.php (.../orders_tag_processor.php) (revision 14796)
+++ branches/5.2.x/units/orders/orders_tag_processor.php (.../orders_tag_processor.php) (revision 14813)
@@ -1,6 +1,6 @@
Application->registerClass( $gw_data['ClassName'], GW_CLASS_PATH.'/'.$gw_data['ClassFile'] );
$gateway_object =& $this->Application->recallObject( $gw_data['ClassName'] );
- $tpl = ''."\n";
+ $tpl = ''."\n";
$hidden_fields = $gateway_object->getHiddenFields($object->GetFieldValues(), $params, $gw_data['gw_params']);
$ret = '';
@@ -1112,6 +1112,8 @@
function NeedsPlaceButton($params)
{
$object =& $this->getObject($params);
+ /* @var $object OrdersItem */
+
$gw_data = $object->getGatewayData();
$this->Application->registerClass( $gw_data['ClassName'], GW_CLASS_PATH.'/'.$gw_data['ClassFile'] );
@@ -1647,4 +1649,27 @@
return $this->Application->HREF($order_helper->getContinueShoppingTemplate($template), '', $params);
}
+
+ /**
+ * Checks that billing address and shipping address are the same
+ *
+ * @param Array $params
+ * @return string
+ * @access protected
+ */
+ protected function AddressesTheSame($params)
+ {
+ $object =& $this->getObject($params);
+ /* @var $object kDBItem */
+
+ $address_fields = Array ('To', 'Company', 'Address1', 'Address2', 'City', 'Country', 'State', 'Zip');
+
+ foreach ($address_fields as $address_field) {
+ if ( $object->GetDBField('Shipping' . $address_field) != $object->GetDBField('Billing' . $address_field) ) {
+ return false;
+ }
+ }
+
+ return true;
+ }
}
\ No newline at end of file