public function create_shipment( $order, $shipment ) { //get authoriztion key $this->get_auth(); //get user address info $address = $this->account_info->Address; //check if shipment is domestic or international $domestic = in_array( $order->shipping_country, $this->domestic ); //load packages $packages = $shipment['_packages']; //set costs to zero $shipment['_shipping_costs'] = 0; //load senders as //$address = $this->get_sender_address(); //loop through packages foreach( $packages as $key => $package ) { //verify a label has been generated if( ! isset( $package->ShippingLabel ) ) { //create unique transaction ID $integratorTxID = substr( md5( rand( 0, 1000000 ) ), 0, 64 ); //set params for API call $params = array( 'Authenticator' => $this->authenticator, 'IntegratorTxID' => $integratorTxID, 'Rate' => $package->Rate, 'From' => $address, 'To' => $this->get_shipping_address( $order ), ); //check for memo and set params if needed if( isset( $POST['memo'] ) ) { $params['memo'] = sanitize_text_field( $_POST['memo'] ); $params['printMemo'] = true; } //international shipment if( ! $domestic ) { //load and set customs form params if( isset( $shipment['_customs'] ) ) { $params['Customs'] = $shipment['_customs']; } else { slp_ajax_functions::get_customs_form( $order, $shipment ); } } //receive create indicium response $response = $this->stamps->CreateIndicium( $params ); //handle errors if( is_soap_fault( $response ) ) { //save transaction id for later use $package->IntegratorTxID = $integratorTxID; //document errors $package->Errors = array( 'type' => 'processing', 'code' => $response->faultcode, 'error' => $response->faultstring ); //send to error handler $this->error_handler( $order, $shipment, __FUNCTION__, __LINE__, $response ); //get new authenticator $this->get_auth(); $authenticator = $this->authenticator; //process next package if any continue; } //update shipping costs $shipment['_shipping_costs'] += (float)$response->Rate->Amount; //check if package is trackable if( $this->is_trackable( $order ) ) { //set package tracking number $package->id = isset( $response->TrackingNumber ) ? $response->TrackingNumber : 'Not Trackable'; //set initial tracking info $shipment['_tracking_info'] = array( 'status' => 'CONFIRMED', 'timestamp' => current_time( 'm/d/Y h:m a', 'timestamp' ) ); } $package->ShippingCost = (float)$response->Rate->Amount; $package->ShippingLabel = $response->URL; $package->StampsTxID = $response->StampsTxID; $txIDs[] = $response->StampsTxID; $this->authenticator = $response->Authenticator; } } $shipment['_shipment_status'] = 'CONFIRMED'; $shipment['_shipping_date'] = $response->Rate->ShipDate; if( $this->settings['scanform'] ) { $shipment = $this->get_scanform( $shipment ); } slp_ajax_functions::confirm_shipment( $order, $shipment, true ); }
/** * * * * */ public function create_shipment( $order, $shipment ) { //Create XML for Shipment Accept Request $request = $this->xml_header(); $request .= "<ShipmentAcceptRequest> <Request> <TransactionReference> <CustomerContext>ship_accept</CustomerContext> <XpciVersion>1.0</XpciVersion> </TransactionReference> <RequestAction>ShipAccept</RequestAction> <RequestOption>1</RequestOption> </Request> <ShipmentDigest>" . $shipment['_shipment_digest'] . "</ShipmentDigest> </ShipmentAcceptRequest>"; $request = str_replace( array( "\n", "\r" ), '', $request ); //Send XML to UPS for processing and recieve XML Response $response = $this->xml_request( $request, $this->endpoints['production'] . 'ShipAccept' ); unset( $shipment['_shipment_digest'] ); $shipment['_shipping_cost'] = (string)$response->ShipmentResults->ShipmentCharges->TotalCharges->MonetaryValue; $shipment['_shipping_date'] = time() < strtotime( $this->settings['readytime'] ) ? date( 'm/d/Y' ) : date( 'm/d/Y', strtotime( '+1 day' ) ); $shipment['_shipment_status'] = 'CONFIRMED'; $rates = $response->ShipmentResults->PackageResults; $packages = $shipment['_packages']; $count = 0; foreach( $rates as $rate ) { $package = $packages[$count]; $package->id = (string)$rate->TrackingNumber; $package->ShippingLabel = 'data:image/gif;base64,' . (string)$rate->LabelImage->GraphicImage; ++$count; } slp_ajax_functions::confirm_shipment( $order, $shipment, true ); }