Пример #1
0
 function FormatFedExShipRequest($pkg, $key)
 {
     global $ZONE001_DEFINES, $debug;
     $crlf = chr(13) . chr(10);
     if ($pkg->ship_method == 'GND' || $pkg->ship_method == 'GDR') {
         $carrier_code = 'FDXG';
         // Ground and Ground Home Delivery
     } else {
         $carrier_code = 'FDXE';
         // Express (all types)
     }
     $sBody = '<?xml version="1.0" encoding="UTF-8" ?>';
     $sBody .= $crlf . '<FDXShipRequest xmlns:api="http://www.fedex.com/fsmapi" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FDXShipRequest.xsd">';
     $sBody .= $crlf . '<RequestHeader>';
     $sBody .= $crlf . '<CustomerTransactionIdentifier>FedEx Ship Request</CustomerTransactionIdentifier>';
     $sBody .= $crlf . '<AccountNumber>' . MODULE_SHIPPING_FEDEX_ACCOUNT_NUMBER . '</AccountNumber>';
     $sBody .= $crlf . '<MeterNumber>' . MODULE_SHIPPING_FEDEX_RATE_LICENSE . '</MeterNumber>';
     $sBody .= $crlf . '<CarrierCode>' . $carrier_code . '</CarrierCode>';
     $sBody .= $crlf . '</RequestHeader>';
     $sBody .= $crlf . '<ShipDate>' . $pkg->terminal_date . '</ShipDate>';
     $sBody .= $crlf . '<ShipTime>' . date('H:i:s', time()) . '</ShipTime>';
     $sBody .= $crlf . '<DropoffType>' . $this->FedExPickupMap[$pkg->pickup_service] . '</DropoffType>';
     //Service
     // special case if residential checked and GND service (commercial) is selected, change to GDR home delivery
     $temp = array_flip($this->FedExRateCodes);
     $ship_method = $pkg->residential_address && $pkg->ship_method == 'GND' ? 'GDR' : $pkg->ship_method;
     $sBody .= $crlf . '<Service>' . $temp[$ship_method] . '</Service>';
     $sBody .= $crlf . '<Packaging>' . $this->PackageMap[$pkg->pkg_type] . '</Packaging>';
     // TBD convert weight to pounds if in KGs
     $sBody .= $crlf . '<WeightUnits>' . $pkg->pkg_weight_unit . '</WeightUnits>';
     // TBD total shipment weight or package weight
     $sBody .= $crlf . '<Weight>' . number_format($pkg->package[$key]['weight'], 1) . '</Weight>';
     $sBody .= $crlf . '<CurrencyCode>' . $pkg->insurance_currency . '</CurrencyCode>';
     $sBody .= $crlf . '<ListRate>1</ListRate>';
     if ($pkg->return_service) {
         $sBody .= $crlf . '<ReturnShipmentIndicator>PRINTRETURNLABEL</ReturnShipmentIndicator>';
     }
     // Origin
     $sBody .= $crlf . '<Origin>';
     $sBody .= $crlf . '<Contact>';
     $sBody .= $crlf . '<CompanyName>' . COMPANY_NAME . '</CompanyName>';
     $sBody .= $crlf . '<PhoneNumber>' . strip_alphanumeric(COMPANY_TELEPHONE1) . '</PhoneNumber>';
     if (COMPANY_FAX) {
         $sBody .= $crlf . '<FaxNumber>' . strip_alphanumeric(COMPANY_FAX) . '</FaxNumber>';
     }
     if (COMPANY_EMAIL) {
         $sBody .= $crlf . '<E-MailAddress>' . COMPANY_EMAIL . '</E-MailAddress>';
     }
     $sBody .= $crlf . '</Contact>';
     $sBody .= $crlf . '<Address>';
     $sBody .= $crlf . '<Line1>' . COMPANY_ADDRESS1 . '</Line1>';
     if (COMPANY_ADDRESS2) {
         $sBody .= $crlf . '<Line2>' . COMPANY_ADDRESS2 . '</Line2>';
     }
     $sBody .= $crlf . '<City>' . COMPANY_CITY_TOWN . '</City>';
     $country_code = gen_get_country_iso_2_from_3(COMPANY_COUNTRY);
     if ($country_code == 'US' || $country_code == 'CA') {
         $sBody .= $crlf . '<StateOrProvinceCode>' . COMPANY_ZONE . '</StateOrProvinceCode>';
     }
     if ($country_code == 'US' || $country_code == 'CA' || COMPANY_POSTAL_CODE != '') {
         $sBody .= $crlf . '<PostalCode>' . strip_alphanumeric(COMPANY_POSTAL_CODE) . '</PostalCode>';
     }
     $sBody .= $crlf . '<CountryCode>' . $country_code . '</CountryCode>';
     $sBody .= $crlf . '</Address>';
     $sBody .= $crlf . '</Origin>';
     // Destination
     $sBody .= $crlf . '<Destination>';
     $sBody .= $crlf . '<Contact>';
     if ($pkg->ship_contact) {
         $sBody .= $crlf . '<PersonName>' . remove_special_chars($pkg->ship_contact) . '</PersonName>';
     }
     $sBody .= $crlf . '<CompanyName>' . remove_special_chars($pkg->ship_primary_name) . '</CompanyName>';
     $sBody .= $crlf . '<PhoneNumber>' . strip_alphanumeric($pkg->ship_telephone1) . '</PhoneNumber>';
     if ($pkg->ship_email) {
         $sBody .= $crlf . '<E-MailAddress>' . $pkg->ship_email . '</E-MailAddress>';
     }
     $sBody .= $crlf . '</Contact>';
     $sBody .= $crlf . '<Address>';
     $sBody .= $crlf . '<Line1>' . remove_special_chars($pkg->ship_address1) . '</Line1>';
     if ($pkg->ship_address2) {
         $sBody .= $crlf . '<Line2>' . remove_special_chars($pkg->ship_address2) . '</Line2>';
     }
     $sBody .= $crlf . '<City>' . strtoupper($pkg->ship_city_town) . '</City>';
     if ($pkg->ship_country_code == 'US' || $pkg->ship_country_code == 'CA') {
         $sBody .= $crlf . '<StateOrProvinceCode>' . strtoupper($pkg->ship_state_province) . '</StateOrProvinceCode>';
     }
     if ($pkg->ship_country_code == 'US' || $pkg->ship_country_code == 'CA' || $pkg->ship_postal_code != '') {
         $sBody .= $crlf . '<PostalCode>' . strip_alphanumeric($pkg->ship_postal_code) . '</PostalCode>';
     }
     $sBody .= $crlf . '<CountryCode>' . $pkg->ship_country_code . '</CountryCode>';
     $sBody .= $crlf . '</Address>';
     $sBody .= $crlf . '</Destination>';
     // Payment
     $sBody .= $crlf . '<Payment>';
     $sBody .= $crlf . '<PayorType>' . $this->PaymentMap[$pkg->bill_charges] . '</PayorType>';
     if ($pkg->bill_charges == '1' || $pkg->bill_charges == '2') {
         $sBody .= $crlf . '<Payor>';
         $sBody .= $crlf . '<AccountNumber>' . $pkg->bill_acct . '</AccountNumber>';
         $sBody .= $crlf . '<CountryCode>' . $pkg->ship_country_code . '</CountryCode>';
         $sBody .= $crlf . '</Payor>';
     }
     $sBody .= $crlf . '</Payment>';
     // Reference info
     $sBody .= $crlf . '<ReferenceInfo>';
     //		$sBody .= $crlf . '<CustomerReference>' . $pkg->purchase_invoice_id . '</CustomerReference>';
     if ($pkg->so_po_ref_id) {
         $sBody .= $crlf . '<PONumber>' . $pkg->so_po_ref_id . '</PONumber>';
     }
     $sBody .= $crlf . '<InvoiceNumber>' . $pkg->purchase_invoice_id . '</InvoiceNumber>';
     $sBody .= $crlf . '</ReferenceInfo>';
     // Package
     // TBD what about MPS???
     if ($pkg->pkg_type == '02') {
         // customer supplied packaging
         $sBody .= $crlf . '<Dimensions>';
         $sBody .= $crlf . '<Length>' . $pkg->package[$key]['length'] . '</Length>';
         $sBody .= $crlf . '<Width>' . $pkg->package[$key]['width'] . '</Width>';
         $sBody .= $crlf . '<Height>' . $pkg->package[$key]['height'] . '</Height>';
         $sBody .= $crlf . '<Units>' . $pkg->pkg_dimension_unit . '</Units>';
         $sBody .= $crlf . '</Dimensions>';
     }
     $sBody .= $crlf . '<DeclaredValue>' . number_format($pkg->package[$key]['value'], 2) . '</DeclaredValue>';
     // Special Services
     $sBody .= $crlf . '<SpecialServices>';
     if ($pkg->cod) {
         $sBody .= $crlf . '<COD>';
         $sBody .= $crlf . '<CollectionAmount>' . $pkg->total_amount . '</CollectionAmount>';
         $sBody .= $crlf . '<CollectionType>' . $this->CODMap[$pkg->cod_payment_type] . '</CollectionType>';
         $sBody .= $crlf . '</COD>';
     }
     //		$sBody .= $crlf . '<HoldAtLocation>' . $pkg->hold_at_location . '</HoldAtLocation>'; // NOT USED AT THIS TIME
     //		$sBody .= $crlf . '<DangerousGoods>';
     //		$sBody .= $crlf . '<Accessibility>' . $pkg->accessibility . '</Accessibility>'; // NOT USED AT THIS TIME
     //		$sBody .= $crlf . '</DangerousGoods>';
     //		if ($pkg->dry_ice) $sBody .= $crlf . '<DryIce>1</DryIce>';
     //		$sBody .= $crlf . '<ResidentialPickup>' . $pkg->res_pickup . '</ResidentialPickup>'; // NOT USED AT THIS TIME
     if ($pkg->residential_address) {
         $sBody .= $crlf . '<ResidentialDelivery>1</ResidentialDelivery>';
     }
     //		$sBody .= $crlf . '<InsidePickup>' . $pkg->inside_pickup . '</InsidePickup>';
     //		$sBody .= $crlf . '<InsideDelivery>' . $pkg->inside_delivery . '</InsideDelivery>';
     //		if ($pkg->saturday_pickup) $sBody .= $crlf . '<SaturdayPickup>1</SaturdayPickup>';
     if ($pkg->saturday_delivery) {
         $sBody .= $crlf . '<SaturdayDelivery>1</SaturdayDelivery>';
     }
     if ($pkg->email_sndr_ship || $pkg->email_sndr_excp || $pkg->email_sndr_dlvr || $pkg->email_rcp_ship || $pkg->email_rcp_excp || $pkg->email_rcp_dlvr) {
         $sBody .= $crlf . '<EMailNotification>';
         if ($pkg->email_sndr_ship || $pkg->email_sndr_excp || $pkg->email_sndr_dlvr) {
             $sBody .= $crlf . '<Shipper>';
             if ($pkg->email_sndr_ship) {
                 $sBody .= $crlf . '<ShipAlert>' . $pkg->email_sndr_ship . '</ShipAlert>';
             }
             if ($pkg->email_sndr_dlvr) {
                 $sBody .= $crlf . '<DeliveryNotification>' . $pkg->email_sndr_dlvr . '</DeliveryNotification>';
             }
             if ($pkg->email_sndr_excp) {
                 $sBody .= $crlf . '<ExceptionNotification>' . $pkg->email_sndr_excp . '</ExceptionNotification>';
             }
             $sBody .= $crlf . '<Format>TEXT</Format>';
             $sBody .= $crlf . '<LanguageCode>en</LanguageCode>';
             $sBody .= $crlf . '</Shipper>';
         }
         if ($pkg->email_rcp_ship || $pkg->email_rcp_excp || $pkg->email_rcp_dlvr) {
             $sBody .= $crlf . '<Recipient>';
             if ($pkg->email_rcp_ship) {
                 $sBody .= $crlf . '<ShipAlert>' . $pkg->email_rcp_ship . '</ShipAlert>';
             }
             if ($pkg->email_rcp_dlvr) {
                 $sBody .= $crlf . '<DeliveryNotification>' . $pkg->email_rcp_dlvr . '</DeliveryNotification>';
             }
             if ($pkg->email_rcp_excp) {
                 $sBody .= $crlf . '<ExceptionNotification>' . $pkg->email_rcp_excp . '</ExceptionNotification>';
             }
             $sBody .= $crlf . '<Format>TEXT</Format>';
             $sBody .= $crlf . '<LanguageCode>en</LanguageCode>';
             $sBody .= $crlf . '</Recipient>';
         }
         $sBody .= $crlf . '</EMailNotification>';
     }
     if ($pkg->additional_handling) {
         $sBody .= $crlf . '<NonstandardContainer>1</NonstandardContainer>';
     }
     if ($pkg->delivery_confirmation) {
         $sBody .= $crlf . '<SignatureOption>' . $this->SignatureMap[$pkg->delivery_confirmation_type] . '</SignatureOption>';
     }
     $sBody .= $crlf . '</SpecialServices>';
     if (count($pkg->package) > 1) {
         $sBody .= $crlf . '<MultiPiece>';
         $sBody .= $crlf . '<PackageCount>' . count($pkg->package) . '</PackageCount>';
         $sBody .= $crlf . '<PackageSequenceNumber>' . ($key + 1) . '</PackageSequenceNumber>';
         //			$sBody .= $crlf . '<ShipmentWeight>' . count($pkg->package) . '</ShipmentWeight>';
         if ($key > 0) {
             // link to the master package
             $sBody .= $crlf . '<MasterTrackingNumber>' . $pkg->master_tracking . '</MasterTrackingNumber>';
             if ($carrier_code == 'FDXE') {
                 $sBody .= $crlf . '<MasterFormID>' . $pkg->form_id . '</MasterFormID>';
             }
         }
         $sBody .= $crlf . '</MultiPiece>';
     }
     $sBody .= $crlf . '<Label>';
     $sBody .= $crlf . '<Type>2DCOMMON</Type>';
     // For thermal labels
     if (MODULE_SHIPPING_FEDEX_PRINTER_TYPE == 'Thermal') {
         // valid values are PDF, PNG, ELTRON, ZEBRA, UNIMARK
         $sBody .= $crlf . '<ImageType>' . IMAGETYPE . '</ImageType>';
         $sBody .= $crlf . '<LabelStockOrientation>' . LABELSTOCKORIENTATION . '</LabelStockOrientation>';
         // (LEADING, TRAILING, NONE)
         $sBody .= $crlf . '<DocTabLocation>' . DOCTABLOCATION . '</DocTabLocation>';
         // only valid for thermal labels (TOP, BOTTOM)
         $sBody .= $crlf . '<DocTabContent>';
         $sBody .= $crlf . '<Type>' . DOCTABCONTENT . '</Type>';
         // (STANDARD, ZONE001, BARCODED, NONE)
         if (DOCTABCONTENT == 'ZONE001') {
             $sBody .= $crlf . '<Zone001>';
             foreach ($ZONE001_DEFINES as $zone => $settings) {
                 $sBody .= $crlf . '<HeaderValuePair>';
                 $sBody .= $crlf . '<ZoneNumber>' . $zone . '</ZoneNumber>';
                 $sBody .= $crlf . '<Header>' . $settings['Header'] . '</Header>';
                 if ($pkg->ship_method == 'GND' || $pkg->ship_method == 'GDR') {
                     $settings['Value'] = str_replace('/', '', $settings['Value']);
                 }
                 $sBody .= $crlf . '<Value>' . $settings['Value'] . '</Value>';
                 $sBody .= $crlf . '</HeaderValuePair>';
             }
             $sBody .= $crlf . '</Zone001>';
         }
         $sBody .= $crlf . '</DocTabContent>';
     } else {
         // default to pdf for laser labels
         $sBody .= $crlf . '<ImageType>' . 'PDF' . '</ImageType>';
     }
     $sBody .= $crlf . '</Label>';
     $sBody .= $crlf . '</FDXShipRequest>';
     $sBody .= $crlf;
     return $sBody;
 }
Пример #2
0
    /**
     * Store the CC info to the order and process any results that come back from the payment gateway
     *
     */
    function before_process()
    {
        global $order, $db, $currencies, $messageStack;
        // if the card number has the blanked out middle number fields, it has been processed, the message that
        // the charges were not processed were set in pre_confirmation_check, just return to continue without processing.
        if (strpos($_POST['paymentech_field_1'], '*') !== false) {
            return false;
        }
        $order->info['cc_expires'] = $_POST['paymentech_field_2'] . $_POST['paymentech_field_3'];
        $order->info['cc_owner'] = $_POST['paymentech_field_0'];
        $this->cc_card_owner = $_POST['paymentech_field_0'];
        $order->info['cc_cvv'] = $_POST['paymentech_field_4'];
        // Create a string that contains a listing of products ordered for the description field
        $description = $order->description;
        // Generate the XML file to be sent to Paymentech
        if (MODULE_PAYMENT_PAYMENTECH_TESTMODE == 'Test') {
            $MerchantID = MODULE_PAYMENT_PAYMENTECH_MERCHANT_ID_TEST;
        } else {
            switch (DEFAULT_CURRENCY) {
                case 'USD':
                    $MerchantID = MODULE_PAYMENT_PAYMENTECH_MERCHANT_ID_USD;
                    break;
                case 'CAD':
                    $MerchantID = MODULE_PAYMENT_PAYMENTECH_MERCHANT_ID_CAD;
                    break;
            }
        }
        $post_string = "\n\t\t<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\t\t<Request>\n\t\t\t<NewOrder>\n\t\t\t\t<IndustryType>EC</IndustryType>\n\t\t\t\t<MessageType>" . (MODULE_PAYMENT_PAYMENTECH_AUTHORIZATION_TYPE == 'Authorize' ? 'A' : 'AC') . "</MessageType>\n\t\t\t\t<BIN>" . MODULE_PAYMENT_PAYMENTECH_BIN . "</BIN>\n\t\t\t\t<MerchantID>" . $MerchantID . "</MerchantID>\n\t\t\t\t<TerminalID>" . MODULE_PAYMENT_PAYMENTECH_TERMINAL_ID . "</TerminalID>\n\t\t\t\t<AccountNum>" . $_POST['paymentech_field_1'] . "</AccountNum>\n\t\t\t\t<Exp>" . $order->info['cc_expires'] . "</Exp>\n\t\t\t\t<CurrencyCode>" . (DEFAULT_CURRENCY == 'USD' ? '840' : '124') . "</CurrencyCode>\n\t\t\t\t<CurrencyExponent>2</CurrencyExponent>\n\t\t\t\t<CardSecValInd>" . ($this->cc_cvv2 ? 1 : 9) . "</CardSecValInd>\n\t\t\t\t<CardSecVal>" . ($this->cc_cvv2 ? $this->cc_cvv2 : '') . "</CardSecVal>\n\t\t\t\t<AVSzip>" . preg_replace("/[^A-Za-z0-9]/", "", $order->bill_postal_code) . "</AVSzip>\n\t\t\t\t<AVSaddress1>" . substr($order->bill_address1, 0, 20) . "</AVSaddress1>" . ($order->bill_address2 ? '
				<AVSaddress2>' . $order->bill_address2 . '</AVSaddress2>' : '') . "\n\t\t\t\t<AVScity>" . $order->bill_city_town . "</AVScity>\n\t\t\t\t<AVSstate>" . $order->bill_state_province . "</AVSstate>\n\t\t\t\t<AVSphoneNum>" . $order->bill_telephone . "</AVSphoneNum>\n\t\t\t\t<AVSname>" . $this->cc_card_owner . "</AVSname>\n\t\t\t\t<AVScountryCode>" . gen_get_country_iso_2_from_3($order->bill_country_code) . "</AVScountryCode>\n\t\t\t\t<AVSDestzip>" . preg_replace("/[^A-Za-z0-9]/", "", $order->ship_postal_code) . "</AVSDestzip>\n\t\t\t\t<AVSDestaddress1>" . $order->ship_address1 . "</AVSDestaddress1>" . ($order->ship_address2 ? '
				<AVSDestaddress2>' . $order->ship_address2 . '</AVSDestaddress2>' : '') . "\n\t\t\t\t<AVSDestcity>" . $order->ship_city_town . "</AVSDestcity>\n\t\t\t\t<AVSDeststate>" . $order->ship_state_province . "</AVSDeststate>\n\t\t\t\t<AVSDestphoneNum>" . $order->ship_telephone . "</AVSDestphoneNum>\n\t\t\t\t<AVSDestname>" . $order->ship_primary_name . "</AVSDestname>\n\t\t\t\t<AVSDestcountryCode>" . gen_get_country_iso_2_from_3($order->ship_country_code) . "</AVSDestcountryCode>\n\t\t\t\t<OrderID>" . $order->purchase_invoice_id . "</OrderID>\n\t\t\t\t<Amount>" . $order->total_amount * pow(10, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']) . "</Amount>\n\t\t\t</NewOrder>\n\t\t</Request>\n\t";
        $header = "POST /AUTHORIZE HTTP/1.0\r\n";
        //HTTP/1.1 should work fine also
        $header .= "MIME-Version: 1.0\r\n";
        $header .= "Content-type: application/PTI41\r\n";
        $header .= "Content-length: " . strlen($post_string) . "\r\n";
        $header .= "Content-transfer-encoding: text\r\n";
        $header .= "Request-number: 1\r\n";
        $header .= "Document-type: Request\r\n";
        $header .= "Merchant-id: " . $MerchantID . "\r\n\r\n";
        //	$header .= "Connection: close \r\n\r\n";                        //Must have two CR/LF's here
        $header .= $post_string;
        // SEND DATA BY CURL SECTION
        // Post order info data to Paymentech gateway, make sure you have cURL support installed
        if (MODULE_PAYMENT_PAYMENTECH_TESTMODE == 'Test') {
            $url = MODULE_PAYMENT_PAYMENTECH_TEST_URL_PRIMARY;
        } else {
            $url = MODULE_PAYMENT_PAYMENTECH_PRODUCTION_URL_PRIMARY;
        }
        //echo 'transmit xml = '; echo htmlspecialchars($header); echo '<br><br>';
        $GetPost = 'POST';
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_TIMEOUT, 20);
        curl_setopt($ch, CURLOPT_HEADER, false);
        // You are providing a header manually so turn off auto header generation
        curl_setopt($ch, CURLOPT_VERBOSE, false);
        //*
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $header);
        // The following two options are necessary to properly set up SSL
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, true);
        //*/
        /*
        	curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
        	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        	if ($GetPost == 'POST') {
        	  curl_setopt($ch, CURLOPT_POST, 1);
        	  curl_setopt($ch, CURLOPT_POSTFIELDS, $header);
            }
        */
        if (CURL_PROXY_REQUIRED == 'True') {
            curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, true);
            curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
            curl_setopt($ch, CURLOPT_PROXY, CURL_PROXY_SERVER_DETAILS);
        }
        $authorize = curl_exec($ch);
        // Check for curl errors
        $curlerrornum = curl_errno($ch);
        $curlerror = curl_error($ch);
        curl_close($ch);
        if ($curlerrornum) {
            $messageStack->add('XML Read Error (cURL) #' . $curlerrornum . '. Description = ' . $curlerror, 'error');
            return true;
        }
        //echo 'response xml = ' . htmlspecialchars($authorize) . '<br><br>';
        // since the response is only one level deep, we can do a simple parse
        $authorize = trim($authorize);
        $authorize = substr($authorize, strpos($authorize, '<NewOrderResp>') + 14);
        // remove up to and including the container tag
        $authorize = substr($authorize, 0, strpos($authorize, '</NewOrderResp>'));
        // remove from end container tag on
        $results = array();
        $runaway_loop_counter = 0;
        while ($authorize) {
            $key = substr($authorize, strpos($authorize, '<') + 1, strpos($authorize, '>') - 1);
            $authorize = substr($authorize, strpos($authorize, '>') + 1);
            // remove start tag
            $value = substr($authorize, 0, strpos($authorize, '<'));
            // until start of end tag
            $authorize = substr($authorize, strpos($authorize, '>') + 1);
            // remove end tag
            $results[$key] = $value;
            if ($runaway_loop_counter++ > 1000) {
                break;
            }
        }
        //echo 'RespCode = ' . $results['RespCode'] . '<br>';
        //echo 'AVSRespCode = ' . $results['AVSRespCode'] . '<br>';
        //echo 'CVV2RespCode = ' . $results['CVV2RespCode'] . '<br>';
        //echo 'TxRefNum = ' . $results['TxRefNum'] . '<br><br>';
        if ($results['ProcStatus'] == 0) {
            //initial gateway test passed
            if ($results['ApprovalStatus'] == 1) {
                //Gateway returned approved
                $this->auth_code = $results['AuthCode'];
                $this->transaction_id = $results['TxRefNum'];
                $messageStack->add($results['StatusMsg'] . ' - Approval code: ' . $this->auth_code . ' --> CVV2 results: ' . $this->CVV2RespCode[$results['CVV2RespCode']], 'success');
                $messageStack->add('Address verification results: ' . $this->AVSRespCode[$results['AVSRespCode']], 'success');
                /* DELETE ME */
                return true;
                // force a fail to not post
                return false;
            } else {
                $messageStack->add(sprintf(MODULE_PAYMENT_PAYMENTECH_TEXT_DECLINED_MESSAGE, $results['StatusMsg']), 'error');
                return true;
            }
        }
        //gateway test failed
        $messageStack->add(MODULE_PAYMENT_PAYMENTECH_TEXT_GATEWAY_ERROR, 'error');
        return true;
    }
Пример #3
0
 function FormatUPSShipRequest($pkg, $key)
 {
     $crlf = chr(13) . chr(10);
     $sBody = '<?xml version="1.0"?>';
     $sBody .= $crlf . '<AccessRequest xml:lang="en-US">';
     $sBody .= $crlf . '<AccessLicenseNumber>' . MODULE_SHIPPING_UPS_ACCESS_KEY . '</AccessLicenseNumber>';
     $sBody .= $crlf . '<UserId>' . MODULE_SHIPPING_UPS_USER_ID . '</UserId>';
     $sBody .= $crlf . '<Password>' . MODULE_SHIPPING_UPS_PASSWORD . '</Password>';
     $sBody .= $crlf . '</AccessRequest>';
     $sBody .= $crlf . '<?xml version="1.0"?>';
     $sBody .= $crlf . '<ShipmentConfirmRequest>';
     $sBody .= $crlf . '<Request>';
     $sBody .= $crlf . '<TransactionReference>';
     $sBody .= $crlf . '<CustomerContext>Shipment Label Request</CustomerContext>';
     $sBody .= $crlf . '<XpciVersion>1.0001</XpciVersion>';
     $sBody .= $crlf . '</TransactionReference>';
     $sBody .= $crlf . '<RequestAction>' . 'ShipConfirm' . '</RequestAction>';
     // must be ShipConfirm for tool to work
     $sBody .= $crlf . '<RequestOption>' . 'validate' . '</RequestOption>';
     // 'validate' or 'nonvalidate' address
     $sBody .= $crlf . '</Request>';
     $sBody .= $crlf . '<Shipment>';
     $sBody .= $crlf . '<Shipper>';
     $sBody .= $crlf . '<Name>' . COMPANY_NAME . '</Name>';
     $sBody .= $crlf . '<ShipperNumber>' . MODULE_SHIPPING_UPS_SHIPPER_NUMBER . '</ShipperNumber>';
     if (COMPANY_TELEPHONE1) {
         $sBody .= $crlf . '<PhoneNumber>' . COMPANY_TELEPHONE1 . '</PhoneNumber>';
     }
     if (COMPANY_FAX) {
         $sBody .= $crlf . '<FaxNumber>' . COMPANY_FAX . '</FaxNumber>';
     }
     if (COMPANY_EMAIL) {
         $sBody .= $crlf . '<EMailAddress>' . COMPANY_EMAIL . '</EMailAddress>';
     }
     $sBody .= $crlf . '<Address>';
     if (COMPANY_ADDRESS1) {
         $sBody .= $crlf . '<AddressLine1>' . COMPANY_ADDRESS1 . '</AddressLine1>';
     }
     if (COMPANY_ADDRESS2) {
         $sBody .= $crlf . '<AddressLine2>' . COMPANY_ADDRESS2 . '</AddressLine2>';
     }
     //		if (COMPANY_ADDRESS3) $sBody .= $crlf . '<AddressLine3>' . COMPANY_ADDRESS3 . '</AddressLine3>'; // Not used in Current System
     if (COMPANY_CITY_TOWN) {
         $sBody .= $crlf . '<City>' . COMPANY_CITY_TOWN . '</City>';
     }
     if (COMPANY_ZONE) {
         $sBody .= $crlf . '<StateProvinceCode>' . COMPANY_ZONE . '</StateProvinceCode>';
     }
     if (COMPANY_POSTAL_CODE) {
         $sBody .= $crlf . '<PostalCode>' . COMPANY_POSTAL_CODE . '</PostalCode>';
     }
     $sBody .= $crlf . '<CountryCode>' . gen_get_country_iso_2_from_3(COMPANY_COUNTRY) . '</CountryCode>';
     $sBody .= $crlf . '</Address>';
     $sBody .= $crlf . '</Shipper>';
     $sBody .= $crlf . '<ShipTo>';
     $sBody .= $crlf . '<CompanyName>' . $pkg->ship_primary_name . '</CompanyName>';
     if ($pkg->ship_contact) {
         $sBody .= $crlf . '<AttentionName>' . $pkg->ship_contact . '</AttentionName>';
     }
     if ($pkg->ship_telephone1) {
         $sBody .= $crlf . '<PhoneNumber>' . $pkg->ship_telephone1 . '</PhoneNumber>';
     }
     if ($pkg->fax) {
         $sBody .= $crlf . '<FaxNumber>' . $pkg->fax . '</FaxNumber>';
     }
     if ($pkg->ship_email) {
         $sBody .= $crlf . '<EMailAddress>' . $pkg->ship_email . '</EMailAddress>';
     }
     $sBody .= $crlf . '<Address>';
     if ($pkg->ship_address1) {
         $sBody .= $crlf . '<AddressLine1>' . $pkg->ship_address1 . '</AddressLine1>';
     }
     if ($pkg->ship_address2) {
         $sBody .= $crlf . '<AddressLine2>' . $pkg->ship_address2 . '</AddressLine2>';
     }
     //		if ($pkg->ship_address3) $sBody .= $crlf . '<AddressLine3>' . $pkg->ship_address3 . '</AddressLine3>'; // Not used
     if ($pkg->ship_city_town) {
         $sBody .= $crlf . '<City>' . $pkg->ship_city_town . '</City>';
     }
     if ($pkg->ship_state_province) {
         $sBody .= $crlf . '<StateProvinceCode>' . strtoupper($pkg->ship_state_province) . '</StateProvinceCode>';
     }
     if ($pkg->ship_postal_code) {
         $sBody .= $crlf . '<PostalCode>' . $pkg->ship_postal_code . '</PostalCode>';
     }
     $sBody .= $crlf . '<CountryCode>' . $pkg->ship_country_code . '</CountryCode>';
     if ($pkg->residential_address) {
         $sBody .= $crlf . '<ResidentialAddress />';
     }
     $sBody .= $crlf . '</Address>';
     $sBody .= $crlf . '</ShipTo>';
     /* TBD assume ship from is the same as shipper
     		$sBody .= $crlf . '<ShipFrom>';
     		$sBody .= $crlf . '<CompanyName>' . COMPANY_NAME . '</CompanyName>';
     		if (COMPANY_TELEPHONE1) $sBody .= $crlf . '<PhoneNumber>' . COMPANY_TELEPHONE1 . '</PhoneNumber>';
     		if (COMPANY_FAX) $sBody .= $crlf . '<FaxNumber>' . COMPANY_FAX . '</FaxNumber>';
     		$sBody .= $crlf . '<Address>';
     		if (COMPANY_ADDRESS1) $sBody .= $crlf . '<AddressLine1>' . COMPANY_ADDRESS1 . '</AddressLine1>';
     		if (COMPANY_ADDRESS2) $sBody .= $crlf . '<AddressLine2>' . COMPANY_ADDRESS2 . '</AddressLine2>';
     //		if (COMPANY_ADDRESS3) $sBody .= $crlf . '<AddressLine3>' . TBD . '</AddressLine3>'; // Not used in Current System
     		if (COMPANY_CITY_TOWN) $sBody .= $crlf . '<City>' . COMPANY_CITY_TOWN . '</City>';
     		if (COMPANY_ZONE) $sBody .= $crlf . '<StateProvinceCode>' . COMPANY_ZONE . '</StateProvinceCode>';
     		if (COMPANY_POSTAL_CODE) $sBody .= $crlf . '<PostalCode>' . COMPANY_POSTAL_CODE . '</PostalCode>';
     		$sBody .= $crlf . '<CountryCode>' . gen_get_country_iso_2_from_3(COMPANY_COUNTRY) . '</CountryCode>';
     		$sBody .= $crlf . '</Address>';
     		$sBody .= $crlf . '</ShipFrom>';
     */
     /* TBD sold is only required for international
     		$sBody .= $crlf . '<SoldTo>';
     		$sBody .= $crlf . '<CompanyName>' . $pkg->ship_primary_name . '</CompanyName>';
     		if ($pkg->ship_contact) $sBody .= $crlf . '<AttentionName>' . $pkg->ship_contact . '</AttentionName>';
     		if ($pkg->ship_telephone1) $sBody .= $crlf . '<PhoneNumber>' . $pkg->ship_telephone1 . '</PhoneNumber>';
     		$sBody .= $crlf . '<Address>';
     		if ($pkg->ship_address1) $sBody .= $crlf . '<Address1>' . $pkg->ship_address1 . '</Address1>';
     		if ($pkg->ship_address2) $sBody .= $crlf . '<Address2>' . $pkg->ship_address2 . '</Address2>';
     //		if ($pkg->ship_to_address3) $sBody .= $crlf . '<Address3>' . $pkg->ship_to_address3 . '</Address3>'; // Not used
     		if ($pkg->ship_city_town) $sBody .= $crlf . '<City>' . $pkg->ship_city_town . '</City>';
     		if ($pkg->ship_state_province) $sBody .= $crlf . '<StateProvinceCode>' . $pkg->ship_state_province . '</StateProvinceCode>';
     		if ($pkg->ship_postal_code) $sBody .= $crlf . '<PostalCode>' . $pkg->ship_postal_code . '</PostalCode>';
     		$sBody .= $crlf . '<CountryCode>' . $pkg->ship_country_code . '</CountryCode>';
     		$sBody .= $crlf . '</Address>';
     		$sBody .= $crlf . '</SoldTo>';
     */
     $sBody .= $crlf . '<Service>';
     $temp = array_flip($this->UPSRateCodes);
     $sBody .= $crlf . '<Code>' . $temp[$pkg->ship_method] . '</Code>';
     $sBody .= $crlf . '</Service>';
     $sBody .= $crlf . '<PaymentInformation>';
     switch ($pkg->bill_charges) {
         default:
         case '0':
             // bill sender
             $sBody .= $crlf . '<Prepaid>';
             $sBody .= $crlf . '<BillShipper>';
             $sBody .= $crlf . '<AccountNumber>' . MODULE_SHIPPING_UPS_SHIPPER_NUMBER . '</AccountNumber>';
             // only bill account (no credit card)
             $sBody .= $crlf . '</BillShipper>';
             $sBody .= $crlf . '</Prepaid>';
             break;
         case '1':
             // bill recepient
             $sBody .= $crlf . '<FreightCollect>';
             $sBody .= $crlf . '<BillReceiver>';
             $sBody .= $crlf . '<AccountNumber>' . $pkg->bill_acct . '</AccountNumber>';
             // only bill accounts (no addresses)
             $sBody .= $crlf . '<Address>';
             $sBody .= $crlf . '<PostalCode>' . $pkg->ship_postal_code . '</PostalCode>';
             $sBody .= $crlf . '</Address>';
             $sBody .= $crlf . '</BillReceiver>';
             $sBody .= $crlf . '</FreightCollect>';
             break;
         case '2':
             // bill third party
             $sBody .= $crlf . '<BillThirdParty>';
             $sBody .= $crlf . '<BillThirdPartyShipper>';
             $sBody .= $crlf . '<AccountNumber>' . $pkg->bill_acct . '</AccountNumber>';
             // only bill accounts (no addresses)
             $sBody .= $crlf . '<ThirdParty>';
             $sBody .= $crlf . '<Address>';
             $sBody .= $crlf . '<PostalCode>' . $pkg->third_party_zip . '</PostalCode>';
             $sBody .= $crlf . '<CountryCode>' . $pkg->ship_country_code . '</CountryCode>';
             $sBody .= $crlf . '</Address>';
             $sBody .= $crlf . '</ThirdParty>';
             $sBody .= $crlf . '</BillThirdPartyShipper>';
             $sBody .= $crlf . '</BillThirdParty>';
             break;
         case '3':
             // COD - NOT allowed for UPS
             return false;
     }
     $sBody .= $crlf . '</PaymentInformation>';
     $sBody .= $crlf . '<RateInformation>';
     $sBody .= $crlf . '<NegotiatedRatesIndicator />';
     $sBody .= $crlf . '</RateInformation>';
     $sBody .= $crlf . '<ShipmentServiceOptions>';
     if ($pkg->saturday_delivery) {
         $sBody .= $crlf . '<SaturdayDelivery></SaturdayDelivery>';
     }
     if ($pkg->email_sndr_ship || $pkg->email_sndr_excp || $pkg->email_sndr_dlvr || $pkg->email_rcp_ship || $pkg->email_rcp_excp || $pkg->email_rcp_dlvr) {
         if ($pkg->email_sndr_ship || $pkg->email_sndr_excp || $pkg->email_sndr_dlvr) {
             if ($pkg->email_sndr_ship) {
                 $sBody .= $crlf . '<ShipmentNotification>';
                 $sBody .= $crlf . '<NotificationCode>6</NotificationCode>';
                 $sBody .= $crlf . '<EMailMessage>';
                 $sBody .= $crlf . '<EMailAddress>' . $pkg->sender_email_address . '</EMailAddress>';
                 $sBody .= $crlf . '<UndeliverableEMailAddress>' . COMPANY_EMAIL . '</UndeliverableEMailAddress>';
                 $sBody .= $crlf . '<SubjectCode>01</SubjectCode>';
                 $sBody .= $crlf . '</EMailMessage>';
                 $sBody .= $crlf . '</ShipmentNotification>';
             }
             if ($pkg->email_sndr_excp) {
                 $sBody .= $crlf . '<ShipmentNotification>';
                 $sBody .= $crlf . '<NotificationCode>7</NotificationCode>';
                 $sBody .= $crlf . '<EMailMessage>';
                 $sBody .= $crlf . '<EMailAddress>' . $pkg->sender_email_address . '</EMailAddress>';
                 $sBody .= $crlf . '<UndeliverableEMailAddress>' . COMPANY_EMAIL . '</UndeliverableEMailAddress>';
                 $sBody .= $crlf . '<SubjectCode>01</SubjectCode>';
                 $sBody .= $crlf . '</EMailMessage>';
                 $sBody .= $crlf . '</ShipmentNotification>';
             }
             if ($pkg->email_sndr_dlvr) {
                 $sBody .= $crlf . '<ShipmentNotification>';
                 $sBody .= $crlf . '<NotificationCode>8</NotificationCode>';
                 $sBody .= $crlf . '<EMailMessage>';
                 $sBody .= $crlf . '<EMailAddress>' . $pkg->sender_email_address . '</EMailAddress>';
                 $sBody .= $crlf . '<UndeliverableEMailAddress>' . COMPANY_EMAIL . '</UndeliverableEMailAddress>';
                 $sBody .= $crlf . '<SubjectCode>01</SubjectCode>';
                 $sBody .= $crlf . '</EMailMessage>';
                 $sBody .= $crlf . '</ShipmentNotification>';
             }
         }
         if ($pkg->email_rcp_ship || $pkg->email_rcp_excp || $pkg->email_rcp_dlvr) {
             if ($pkg->email_rcp_ship) {
                 $sBody .= $crlf . '<ShipmentNotification>';
                 $sBody .= $crlf . '<NotificationCode>6</NotificationCode>';
                 $sBody .= $crlf . '<EMailMessage>';
                 $sBody .= $crlf . '<EMailAddress>' . $pkg->ship_email . '</EMailAddress>';
                 $sBody .= $crlf . '<UndeliverableEMailAddress>' . COMPANY_EMAIL . '</UndeliverableEMailAddress>';
                 $sBody .= $crlf . '<SubjectCode>01</SubjectCode>';
                 $sBody .= $crlf . '</EMailMessage>';
                 $sBody .= $crlf . '</ShipmentNotification>';
             }
             if ($pkg->email_rcp_excp) {
                 $sBody .= $crlf . '<ShipmentNotification>';
                 $sBody .= $crlf . '<NotificationCode>7</NotificationCode>';
                 $sBody .= $crlf . '<EMailMessage>';
                 $sBody .= $crlf . '<EMailAddress>' . $pkg->ship_email . '</EMailAddress>';
                 $sBody .= $crlf . '<UndeliverableEMailAddress>' . COMPANY_EMAIL . '</UndeliverableEMailAddress>';
                 $sBody .= $crlf . '<SubjectCode>01</SubjectCode>';
                 $sBody .= $crlf . '</EMailMessage>';
                 $sBody .= $crlf . '</ShipmentNotification>';
             }
             if ($pkg->email_rcp_dlvr) {
                 $sBody .= $crlf . '<ShipmentNotification>';
                 $sBody .= $crlf . '<NotificationCode>8</NotificationCode>';
                 $sBody .= $crlf . '<EMailMessage>';
                 $sBody .= $crlf . '<EMailAddress>' . $pkg->ship_email . '</EMailAddress>';
                 $sBody .= $crlf . '<UndeliverableEMailAddress>' . COMPANY_EMAIL . '</UndeliverableEMailAddress>';
                 $sBody .= $crlf . '<SubjectCode>01</SubjectCode>';
                 $sBody .= $crlf . '</EMailMessage>';
                 $sBody .= $crlf . '</ShipmentNotification>';
             }
         }
     }
     $sBody .= $crlf . '</ShipmentServiceOptions>';
     foreach ($pkg->package as $pkgnum) {
         // Enter each package
         $sBody .= $crlf . '<Package>';
         $sBody .= $crlf . '<PackagingType><Code>' . $pkg->pkg_type . '</Code></PackagingType>';
         $sBody .= $crlf . '<Dimensions>';
         $sBody .= $crlf . '<UnitOfMeasurement><Code>' . $pkg->pkg_dimension_unit . '</Code></UnitOfMeasurement>';
         $sBody .= $crlf . '<Length>' . ceil($pkgnum['length']) . '</Length>';
         $sBody .= $crlf . '<Width>' . ceil($pkgnum['width']) . '</Width>';
         $sBody .= $crlf . '<Height>' . ceil($pkgnum['height']) . '</Height>';
         $sBody .= $crlf . '</Dimensions>';
         $sBody .= $crlf . '<PackageWeight>';
         $sBody .= $crlf . '<UnitOfMeasurement><Code>' . $pkg->pkg_weight_unit . '</Code></UnitOfMeasurement>';
         $sBody .= $crlf . '<Weight>' . $pkgnum['weight'] . '</Weight>';
         $sBody .= $crlf . '</PackageWeight>';
         $sBody .= $crlf . '<ReferenceNumber>';
         $sBody .= $crlf . '<Code>PO</Code>';
         // Purchase Order #
         $sBody .= $crlf . '<Value>' . $pkg->so_po_ref_id . '</Value>';
         $sBody .= $crlf . '</ReferenceNumber>';
         $sBody .= $crlf . '<ReferenceNumber>';
         $sBody .= $crlf . '<Code>IK</Code>';
         // Invoice #
         $sBody .= $crlf . '<Value>' . $pkg->purchase_invoice_id . '</Value>';
         $sBody .= $crlf . '</ReferenceNumber>';
         if ($pkg->additional_handling) {
             $sBody .= $crlf . '<AdditionalHandling></AdditionalHandling>';
         }
         $temp = '';
         if ($pkg->delivery_confirmation) {
             $temp .= $crlf . '<DeliveryConfirmation>';
             $temp .= $crlf . '<DCISType>' . $pkg->delivery_confirmation_type . '</DCISType>';
             $temp .= $crlf . '</DeliveryConfirmation>';
         }
         if ($pkg->insurance) {
             $temp .= $crlf . '<InsuredValue>';
             $temp .= $crlf . '<CurrencyCode>' . $pkg->insurance_currency . '</CurrencyCode>';
             $temp .= $crlf . '<MonetaryValue>' . $pkgnum['value'] . '</MonetaryValue>';
             $temp .= $crlf . '</InsuredValue>';
         }
         if ($pkg->cod) {
             $temp .= $crlf . '<COD>';
             $temp .= $crlf . '<CODCode>3</CODCode>';
             if ($pkg->cod_payment_type == 1 || $pkg->cod_payment_type == 2 || $pkg->cod_payment_type == 3) {
                 $payment_type = '9';
                 // check, money order, cashier's check
             } else {
                 $payment_type = '1';
                 // cash
             }
             $temp .= '<CODFundsCode>' . $payment_type . '</CODFundsCode>';
             $temp .= '<CODAmount>';
             $temp .= '<CurrencyCode>' . $pkg->cod_currency . '</CurrencyCode>';
             $temp .= '<MonetaryValue>' . $pkg->total_amount . '</MonetaryValue>';
             $temp .= '</CODAmount>';
             $temp .= '</COD>';
         }
         /* VerbalConfirmation */
         /* ShipperReleaseindicator */
         if ($temp) {
             $sBody .= $crlf . '<PackageServiceOptions>' . $crlf . $temp . $crlf . '</PackageServiceOptions>';
         }
         $sBody .= $crlf . '</Package>';
     }
     $sBody .= $crlf . '</Shipment>';
     $sBody .= $crlf . '<LabelSpecification>';
     $sBody .= $crlf . '<LabelPrintMethod><Code>' . (MODULE_SHIPPING_UPS_PRINTER_TYPE == 'GIF' ? 'GIF' : 'EPL') . '</Code></LabelPrintMethod>';
     // valid values are GIF, EPL, SPL
     $sBody .= $crlf . '<HTTPUserAgent>' . 'Mozilla/4.5' . '</HTTPUserAgent>';
     // Default Value
     if (MODULE_SHIPPING_UPS_PRINTER_TYPE != 'GIF') {
         $sBody .= $crlf . '<LabelStockSize>';
         $sBody .= $crlf . '<UnitOfMeasurement>IN</UnitOfMeasurement>';
         $sBody .= $crlf . '<Width>' . MODULE_SHIPPING_UPS_LABEL_SIZE . '</Width>';
         // valid values are 6 and 8
         $sBody .= $crlf . '<Height>4</Height>';
         // must be 4
         $sBody .= $crlf . '</LabelStockSize>';
         // valid values are 4x6 and 4x8
     }
     $sBody .= $crlf . '<LabelImageFormat><Code>' . (MODULE_SHIPPING_UPS_PRINTER_TYPE == 'GIF' ? 'GIF' : 'EPL2') . '</Code></LabelImageFormat>';
     $sBody .= $crlf . '</LabelSpecification>';
     $sBody .= $crlf . '</ShipmentConfirmRequest>';
     $sBody .= $crlf;
     return $sBody;
 }
/**************   page specific initialization  *************************/
$error = false;
$auto_print = false;
$label_data = NULL;
$sInfo = new shipment();
$action = isset($_GET['action']) ? $_GET['action'] : $_POST['todo'];
/***************   Act on the action request   *************************/
switch ($action) {
    case 'label':
        // overwrite the defaults with data from the form
        reset($_POST);
        while (list($key, $value) = each($_POST)) {
            $sInfo->{$key} = db_prepare_input($value);
        }
        // generate ISO2 codes for countries
        $sInfo->ship_country_code = gen_get_country_iso_2_from_3($sInfo->ship_country_code);
        $sInfo->ship_date = date('Y-m-d', strtotime($sInfo->ship_date));
        // read checkboxes
        $sInfo->residential_address = isset($_POST['residential_address']) ? '1' : '0';
        $sInfo->additional_handling = isset($_POST['additional_handling']) ? '1' : '0';
        $sInfo->delivery_confirmation = isset($_POST['delivery_confirmation']) ? '1' : '0';
        $sInfo->saturday_delivery = isset($_POST['saturday_delivery']) ? '1' : '0';
        $sInfo->cod = isset($_POST['cod']) ? '1' : '0';
        $sInfo->return_service = isset($_POST['return_service']) ? '1' : '0';
        $sInfo->email_rcp_ship = isset($_POST['email_rcp_ship']) ? '1' : '0';
        $sInfo->email_rcp_excp = isset($_POST['email_rcp_excp']) ? '1' : '0';
        $sInfo->email_rcp_dlvr = isset($_POST['email_rcp_dlvr']) ? '1' : '0';
        $sInfo->email_sndr_ship = isset($_POST['email_sndr_ship']) ? '1' : '0';
        $sInfo->email_sndr_excp = isset($_POST['email_sndr_excp']) ? '1' : '0';
        $sInfo->email_sndr_dlvr = isset($_POST['email_sndr_dlvr']) ? '1' : '0';
        // load package information
Пример #5
0
/***************   hook for custom actions  ***************************/
$custom_path = DIR_FS_WORKING . 'custom/pages/popup_shipping/extra_actions.php';
if (file_exists($custom_path)) {
    include $custom_path;
}
/***************   Act on the action request   *************************/
switch ($_REQUEST['action']) {
    case 'rates':
        // overwrite the defaults with data from the form
        reset($_POST);
        while (list($key, $value) = each($_POST)) {
            $pkg->{$key} = db_prepare_input($value);
        }
        // generate ISO2 codes for countries (needed by FedEx and others)
        $pkg->ship_from_country_iso2 = gen_get_country_iso_2_from_3($pkg->ship_country_code);
        $pkg->ship_to_country_iso2 = gen_get_country_iso_2_from_3($pkg->ship_to_country_code);
        // read checkboxes
        $pkg->residential_address = isset($_POST['residential_address']) ? '1' : '0';
        $pkg->additional_handling = isset($_POST['additional_handling']) ? '1' : '0';
        $pkg->insurance = isset($_POST['insurance']) ? '1' : '0';
        $pkg->split_large_shipments = isset($_POST['split_large_shipments']) ? '1' : '0';
        $pkg->delivery_confirmation = isset($_POST['delivery_confirmation']) ? '1' : '0';
        $pkg->handling_charge = isset($_POST['handling_charge']) ? '1' : '0';
        $pkg->cod = isset($_POST['cod']) ? '1' : '0';
        $pkg->saturday_pickup = isset($_POST['saturday_pickup']) ? '1' : '0';
        $pkg->saturday_delivery = isset($_POST['saturday_delivery']) ? '1' : '0';
        $pkg->hazardous_material = isset($_POST['hazardous_material']) ? '1' : '0';
        // read the modules installed
        $rates = array();
        foreach ($methods as $method) {
            if (isset($_POST['ship_method_' . $method])) {
Пример #6
0
 function FormatFedExShipRequest($pkg, $key)
 {
     global $ZONE001_DEFINES, $debug, $currencies;
     // process different for freight than express
     $is_freight = in_array($pkg->ship_method, array('GndFrt', 'EcoFrt')) && MODULE_SHIPPING_FEDEX_V7_LTL_ACCOUNT_NUMBER ? true : false;
     $request['WebAuthenticationDetail'] = array('UserCredential' => array('Key' => MODULE_SHIPPING_FEDEX_V7_AUTH_KEY, 'Password' => MODULE_SHIPPING_FEDEX_V7_AUTH_PWD));
     $request['ClientDetail'] = array('AccountNumber' => MODULE_SHIPPING_FEDEX_V7_ACCOUNT_NUMBER, 'MeterNumber' => MODULE_SHIPPING_FEDEX_V7_METER_NUMBER);
     $request['TransactionDetail'] = array('CustomerTransactionId' => '*** FedEx Shipping Request ***');
     $request['Version'] = array('ServiceId' => 'ship', 'Major' => MODULE_SHIPPING_FEDEX_SHIP_WSDL_VERSION, 'Intermediate' => '0', 'Minor' => '0');
     $temp = array_flip($this->FedExRateCodes);
     $ship_method = $pkg->residential_address && $pkg->ship_method == 'GND' ? 'GDR' : $pkg->ship_method;
     $request['RequestedShipment'] = array('ShipTimestamp' => date('c', strtotime($pkg->ship_date)), 'DropoffType' => $this->FedExPickupMap[$pkg->pickup_service], 'ServiceType' => $temp[$ship_method], 'PackagingType' => $this->PackageMap[$pkg->pkg_type]);
     $request['RequestedShipment']['Shipper'] = array('Contact' => array('PersonName' => AR_CONTACT_NAME, 'CompanyName' => COMPANY_NAME, 'PhoneNumber' => COMPANY_TELEPHONE1), 'Address' => array('StreetLines' => array('0' => COMPANY_ADDRESS1, '1' => COMPANY_ADDRESS2), 'City' => COMPANY_CITY_TOWN, 'StateOrProvinceCode' => COMPANY_ZONE, 'PostalCode' => COMPANY_POSTAL_CODE, 'CountryCode' => gen_get_country_iso_2_from_3(COMPANY_COUNTRY)));
     $request['RequestedShipment']['Recipient'] = array('Contact' => array('PersonName' => remove_special_chars($pkg->ship_contact), 'CompanyName' => remove_special_chars($pkg->ship_primary_name), 'PhoneNumber' => strip_alphanumeric($pkg->ship_telephone1)), 'Address' => array('StreetLines' => array('0' => remove_special_chars($pkg->ship_address1), '1' => remove_special_chars($pkg->ship_address2)), 'City' => strtoupper($pkg->ship_city_town), 'StateOrProvinceCode' => $pkg->ship_country_code == 'US' ? strtoupper($pkg->ship_state_province) : '', 'PostalCode' => strip_alphanumeric($pkg->ship_postal_code), 'CountryCode' => gen_get_country_iso_2_from_3($pkg->ship_country_code), 'Residential' => $pkg->residential_address ? '1' : '0'));
     // SmartPost
     if ($pkg->ship_method == '3Dam') {
         $request['RequestedShipment']['SmartPostDetail'] = array('Indicia' => $pkg->total_weight < 1 ? 'PRESORTED_STANDARD' : 'PARCEL_SELECT', 'HubId' => FEDEX_SMARTPOST_HUB_ID);
     }
     $request['RequestedShipment']['ShippingChargesPayment'] = array('PaymentType' => $this->PaymentMap[$pkg->bill_charges]);
     $pay_acct = MODULE_SHIPPING_FEDEX_V7_ACCOUNT_NUMBER;
     if ($pkg->bill_charges == '1' || $pkg->bill_charges == '2') {
         $pay_acct = $pkg->bill_acct;
     }
     $request['RequestedShipment']['ShippingChargesPayment']['Payor'] = array('AccountNumber' => $pay_acct, 'CountryCode' => 'US');
     if ($is_freight) {
         //			$request['ClientDetail']['AccountNumber'] = MODULE_SHIPPING_FEDEX_V7_LTL_ACCOUNT_NUMBER; // causes acct and meter not consistent error
         $request['RequestedShipment']['FreightShipmentDetail'] = array('FedExFreightAccountNumber' => MODULE_SHIPPING_FEDEX_V7_LTL_ACCOUNT_NUMBER, 'FedExFreightBillingContactAndAddress' => array('Contact' => array('PersonName' => AR_CONTACT_NAME, 'CompanyName' => COMPANY_NAME, 'PhoneNumber' => COMPANY_TELEPHONE1), 'Address' => array('StreetLines' => COMPANY_ADDRESS1, 'City' => COMPANY_CITY_TOWN, 'StateOrProvinceCode' => COMPANY_ZONE, 'PostalCode' => COMPANY_POSTAL_CODE, 'CountryCode' => gen_get_country_iso_2_from_3(COMPANY_COUNTRY))), 'PrintedReferences' => array('Type' => 'SHIPPER_ID_NUMBER', 'Value' => $pkg->purchase_invoice_id), 'Role' => 'SHIPPER', 'PaymentType' => 'PREPAID', 'CollectTermsType' => 'STANDARD', 'DeclaredValuePerUnit' => array('Amount' => $currencies->clean_value($pkg->package[$key]['value']), 'Currency' => 'USD'), 'TotalHandlingUnits' => $pkg->ltl_num_pieces, 'PalletWeight' => array('Units' => substr($pkg->pkg_weight_unit, 0, 2), 'Value' => number_format($pkg->package[$key]['weight'], 0, '.', '')), 'ShipmentDimensions' => array('Length' => $pkg->package[$key]['length'] < 32 ? 32 : $pkg->package[$key]['length'], 'Width' => $pkg->package[$key]['width'] < 32 ? 32 : $pkg->package[$key]['width'], 'Height' => $pkg->package[$key]['height'] < 16 ? 16 : $pkg->package[$key]['height'], 'Units' => $pkg->pkg_dimension_unit), 'LineItems' => array('FreightClass' => 'CLASS_' . $pkg->ltl_class, 'Packaging' => 'PALLET', 'Description' => $pkg->ltl_description, 'HandlingUnits' => $pkg->ltl_num_pieces, 'Pieces' => 1, 'BillOfLaddingNumber' => $pkg->purchase_invoice_id, 'PurchaseOrderNumber' => $pkg->purch_order_id, 'Weight' => array('Units' => substr($pkg->pkg_weight_unit, 0, 2), 'Value' => number_format($pkg->package[$key]['weight'], 0, '.', '')), 'Dimensions' => array('Length' => $pkg->package[$key]['length'] < 32 ? 32 : $pkg->package[$key]['length'], 'Width' => $pkg->package[$key]['width'] < 32 ? 32 : $pkg->package[$key]['width'], 'Height' => $pkg->package[$key]['height'] < 16 ? 16 : $pkg->package[$key]['height'], 'Units' => $pkg->pkg_dimension_unit)));
     } else {
         // provide small package/express freight details
         $pay_acct = $pkg->bill_charges == '1' || $pkg->bill_charges == '2' ? $pkg->bill_acct : MODULE_SHIPPING_FEDEX_V7_ACCOUNT_NUMBER;
         if ($pkg->cod) {
             $request['RequestedShipment']['SpecialServicesRequested'] = array('SpecialServiceTypes' => array('COD'), 'CodDetail' => array('CollectionType' => $this->CODMap[$pkg->cod_payment_type]));
         }
         if ($pkg->saturday_delivery) {
             $request['RequestedShipment']['SpecialServicesRequested']['SpecialServiceTypes'][] = 'SATURDAY_DELIVERY';
         }
         if ($key > 0) {
             // link to the master package
             $request['RequestedShipment']['MasterTrackingId'] = $pkg->master_tracking;
         }
         $request['RequestedShipment']['RequestedPackageLineItems'] = array('SequenceNumber' => $key + 1, 'InsuredValue' => array('Amount' => $currencies->clean_value($pkg->package[$key]['value']), 'Currency' => 'USD'), 'Weight' => array('Value' => number_format($pkg->package[$key]['weight'], 1, '.', ''), 'Units' => substr($pkg->pkg_weight_unit, 0, 2)), 'Dimensions' => array('Length' => $pkg->package[$key]['length'], 'Width' => $pkg->package[$key]['width'], 'Height' => $pkg->package[$key]['height'], 'Units' => $pkg->pkg_dimension_unit), 'CustomerReferences' => array('0' => array('CustomerReferenceType' => 'CUSTOMER_REFERENCE', 'Value' => $pkg->purchase_invoice_id . '-' . ($key + 1)), '1' => array('CustomerReferenceType' => 'INVOICE_NUMBER', 'Value' => $pkg->purchase_invoice_id), '2' => array('CustomerReferenceType' => 'P_O_NUMBER', 'Value' => $pkg->purch_order_id)));
         if ($pkg->cod) {
             $request['RequestedShipment']['RequestedPackageLineItems']['SpecialServicesRequested'] = array('CodCollectionAmount' => array('Amount' => $pkg->total_amount, 'Currency' => 'USD'), 'EMailNotificationDetail' => array('Shipper' => array('EMailAddress' => COMPANY_EMAIL, 'NotifyOnShipment' => $pkg->email_sndr_ship ? '1' : '0', 'NotifyOnException' => $pkg->email_sndr_dlvr ? '1' : '0', 'NotifyOnException' => $pkg->email_sndr_excp ? '1' : '0', 'Localization"' => substr($_SESSION['language'], 0, 2)), 'Recipient' => array('EMailAddress' => $pkg->ship_email, 'NotifyOnShipment' => $pkg->email_rcp_ship ? '1' : '0', 'NotifyOnException' => $pkg->email_rcp_dlvr ? '1' : '0', 'NotifyOnException' => $pkg->email_rcp_excp ? '1' : '0', 'Localization"' => substr($_SESSION['language'], 0, 2))));
         }
     }
     $request['RequestedShipment']['PackageCount'] = count($pkg->package);
     $request['RequestedShipment']['PackageDetail'] = 'INDIVIDUAL_PACKAGES';
     $request['RequestedShipment']['RateRequestTypes'] = 'LIST';
     // valid values ACCOUNT and LIST
     $request['RequestedShipment']['LabelSpecification']['LabelFormatType'] = 'COMMON2D';
     $request['RequestedShipment']['LabelSpecification']['CustomerSpecifiedDetail']['MaskedData'] = 'SHIPPER_ACCOUNT_NUMBER';
     // For thermal labels
     if (!$is_freight && MODULE_SHIPPING_FEDEX_V7_PRINTER_TYPE == 'Thermal') {
         $request['RequestedShipment']['LabelSpecification']['ImageType'] = 'EPL2';
         $request['RequestedShipment']['LabelSpecification']['LabelStockType'] = LABELORIENTATION_THERMAL;
         $request['RequestedShipment']['LabelSpecification']['LabelPrintingOrientation'] = 'TOP_EDGE_OF_TEXT_FIRST';
         if (DOCTABCONTENT == 'Zone001') {
             $request['RequestedShipment']['LabelSpecification']['CustomerSpecifiedDetail']['DocTabContent']['DocTabContentType'] = 'ZONE001';
             // define the zones and values
             $ZONE001_DEFINES = array('1' => array('Header' => TEXT_DATE, 'Literal' => date('Y-m-d', strtotime($pkg->ship_date))), '2' => array('Header' => 'Transit', 'Value' => 'REPLY/SHIPMENT/RoutingDetail/TransitTime'), '3' => array('Header' => 'PO Num', 'Literal' => $pkg->purch_order_id), '4' => array('Header' => 'Inv Num', 'Literal' => $pkg->purchase_invoice_id), '5' => array('Header' => TEXT_WEIGHT, 'Literal' => number_format($pkg->package[$key]['weight'], 1, '.', '')), '7' => array('Header' => 'DV', 'Literal' => number_format($pkg->package[$key]['value'], 2, '.', '')), '8' => array('Header' => 'Insured', 'Value' => 'REQUEST/PACKAGE/InsuredValue/Amount'), '9' => array('Header' => 'List', 'Value' => 'REPLY/SHIPMENT/RATES/PAYOR_LIST_PACKAGE/TotalNetCharge/Amount'), '12' => array('Header' => 'Net', 'Value' => 'REPLY/SHIPMENT/RATES/PAYOR_ACCOUNT_PACKAGE/TotalNetCharge/Amount'));
             foreach ($ZONE001_DEFINES as $zone => $settings) {
                 $request['RequestedShipment']['LabelSpecification']['CustomerSpecifiedDetail']['DocTabContent'][DOCTABCONTENT]['DocTabZoneSpecifications'][] = array('ZoneNumber' => $zone, 'Header' => $settings['Header'], 'DataField' => $settings['Value'], 'LiteralValue' => $settings['Literal']);
             }
         }
     } elseif ($is_freight) {
         $request['RequestedShipment']['LabelSpecification']['LabelFormatType'] = 'FEDEX_FREIGHT_STRAIGHT_BILL_OF_LADING';
         $request['RequestedShipment']['LabelSpecification']['ImageType'] = 'PDF';
         $request['RequestedShipment']['LabelSpecification']['LabelStockType'] = 'PAPER_LETTER';
         $request['RequestedShipment']['LabelSpecification']['LabelPrintingOrientation'] = 'TOP_EDGE_OF_TEXT_FIRST';
         $request['RequestedShipment']['ShippingDocumentSpecification'] = array('ShippingDocumentTypes' => array('FREIGHT_ADDRESS_LABEL'), 'FreightAddressLabelDetail' => array('Format' => array('ImageType' => MODULE_SHIPPING_FEDEX_V7_PRINTER_TYPE == 'Thermal' ? 'EPL2' : 'PDF', 'StockType' => MODULE_SHIPPING_FEDEX_V7_PRINTER_TYPE == 'Thermal' ? LABELORIENTATION_THERMAL : 'PAPER_4X6', 'ProvideInstuctions' => '0'), 'Copies' => '1'));
     } else {
         $request['RequestedShipment']['LabelSpecification']['ImageType'] = 'PDF';
         $request['RequestedShipment']['LabelSpecification']['LabelStockType'] = LABELORIENTATION_PDF;
     }
     return $request;
 }
Пример #7
0
 function before_process()
 {
     global $order, $db, $messageStack;
     // if the card number has the blanked out middle number fields, it has been processed, the message that
     // the charges were not processed were set in pre_confirmation_check, just return to continue without processing.
     if (strpos($this->field_1, '*') !== false) {
         return false;
     }
     $order->info['cc_expires'] = $this->field_2 . $this->field_3;
     $order->info['cc_owner'] = $this->field_0 . ' ' . $this->field_5;
     $this->cc_card_owner = $this->field_0 . ' ' . $this->field_5;
     $order->info['cc_cvv'] = $this->field_4;
     switch (substr($this->field_1, 0, 1)) {
         case '3':
             $card_type = 'Amex';
             break;
         case '4':
             $card_type = 'Visa';
             break;
         case '5':
             $card_type = 'MasterCard';
             break;
         case '6':
             $card_type = 'Discover';
             break;
     }
     // Set request-specific fields.
     $submit_data = array('PAYMENTACTION' => MODULE_PAYMENT_PAYPAL_NVP_AUTHORIZATION_TYPE, 'AMT' => $order->total_amount, 'SHIPPINGAMT' => $order->freight, 'TAXAMT' => $order->sales_tax ? $order->sales_tax : 0, 'DESC' => $order->description, 'INVNUM' => $order->purchase_invoice_id, 'CREDITCARDTYPE' => $card_type, 'ACCT' => preg_replace('/ /', '', $this->field_1), 'EXPDATE' => $this->field_2 . $this->field_3, 'CVV2' => $this->field_4 ? $this->field_4 : '', 'PAYERID' => $order->bill_short_name, 'FIRSTNAME' => $this->field_0, 'LASTNAME' => $this->field_5, 'STREET' => str_replace('&', '-', substr($order->bill_address1, 0, 20)), 'STREET2' => str_replace('&', '-', substr($order->bill_address2, 0, 20)), 'CITY' => $order->bill_city_town, 'STATE' => $order->bill_state_province, 'ZIP' => preg_replace("/[^A-Za-z0-9]/", "", $order->bill_postal_code), 'COUNTRYCODE' => gen_get_country_iso_2_from_3($order->bill_country_code), 'EMAIL' => $order->bill_email, 'PHONENUM' => $order->bill_telephone, 'CURRENCYCODE' => DEFAULT_CURRENCY, 'SHIPTONAME' => $order->ship_primary_name, 'SHIPTOSTREET' => $order->ship_address1, 'SHIPTOSTREET2' => $order->ship_address2, 'SHIPTOCITY' => $order->ship_city_town, 'SHIPTOSTATE' => $order->ship_state_province, 'SHIPTOZIP' => preg_replace("/[^A-Za-z0-9]/", "", $order->ship_postal_code), 'SHIPTOCOUNTRY' => $order->ship_country_code, 'SHIPTOPHONENUM' => $order->ship_telephone);
     // concatenate the submission data and put into $data variable
     $data = '';
     // initiate XML string
     while (list($key, $value) = each($submit_data)) {
         if ($value != '') {
             $data .= '&' . $key . '=' . urlencode($value);
         }
     }
     // FOR TEST PURPOSES
     //$messageStack->add('Test transaction complete!', 'success');
     //return false;
     // END FOR TEST
     // Execute the API operation; see the PPHttpPost function above.
     if (!($httpParsedResponseAr = $this->PPHttpPost('DoDirectPayment', $data))) {
         return true;
     }
     // failed cURL
     $this->transaction_id = $httpParsedResponseAr['TRANSACTIONID'];
     if ("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"])) {
         $messageStack->add(sprintf(MODULE_PAYMENT_PAYPAL_NVP_SUCCESSE_CODE, $httpParsedResponseAr['ACK'], $this->transaction_id, $this->cvv_codes[$httpParsedResponseAr['CVV2MATCH']]), 'success');
         $messageStack->add('Address verification results: ' . $this->avs_codes[$httpParsedResponseAr['AVSCODE']], 'success');
         //echo 'Success response:'; print_r($httpParsedResponseAr); echo '<br>';
         return false;
     }
     $messageStack->add(MODULE_PAYMENT_PAYPAL_NVP_DECLINE_CODE . $httpParsedResponseAr['L_ERRORCODE0'] . ': ' . urldecode($httpParsedResponseAr['L_LONGMESSAGE0']) . ' - ' . MODULE_PAYMENT_CC_TEXT_DECLINED_MESSAGE, 'error');
     //echo 'Failed response:'; print_r($httpParsedResponseAr); echo '<br>';
     return true;
 }