Exemplo n.º 1
0
 function invokeGetReportList(MarketplaceWebService_Interface $service, $request)
 {
     try {
         $response = $service->getReportList($request);
         if ($response->isSetGetReportListResult()) {
             $getReportListResult = $response->getGetReportListResult();
             $reportInfoList = $getReportListResult->getReportInfoList();
             foreach ($reportInfoList as $reportInfo) {
                 if ($reportInfo->isSetReportType() && $reportInfo->getReportType() == '_GET_ORDERS_DATA_' && $reportInfo->isSetReportId()) {
                     return $reportInfo->getReportId();
                 }
             }
         } else {
             return false;
         }
     } catch (MarketplaceWebService_Exception $ex) {
         $message = 'MWS Report API : Caught Exception : ' . $ex->getMessage() . "\n";
         $message .= "Response Status Code: " . $ex->getStatusCode() . "\n";
         $message .= "Error Code: " . $ex->getErrorCode() . "\n";
         $message .= "Error Type: " . $ex->getErrorType() . "\n";
         $param['message'] = $message;
         $obj = new Pwapresta();
         $obj->generate_log($param);
     }
 }
Exemplo n.º 2
0
 function invokeGetReport(MarketplaceWebService_Interface $service, $request)
 {
     try {
         $response = $service->getReport($request);
         return stream_get_contents($request->getReport());
     } catch (MarketplaceWebService_Exception $ex) {
         $message = 'MWS Report API : Caught Exception : ' . $ex->getMessage() . "\n";
         $message .= "Response Status Code: " . $ex->getStatusCode() . "\n";
         $message .= "Error Code: " . $ex->getErrorCode() . "\n";
         $message .= "Error Type: " . $ex->getErrorType() . "\n";
         $param['message'] = $message;
         $obj = new Pwapresta();
         $obj->generate_log($param);
     }
 }
Exemplo n.º 3
0
 function invokeListOrders(MarketplaceWebServiceOrders_Interface $service, $request)
 {
     try {
         $response = $service->ListOrders($request);
         $dom = new DOMDocument();
         $dom->loadXML($response->toXML());
         $dom->preserveWhiteSpace = false;
         $dom->formatOutput = true;
         $xml = $dom->saveXML();
         $this->update_order($xml);
     } catch (MarketplaceWebServiceOrders_Exception $ex) {
         $message = 'MWS Order API : Caught Exception : ' . $ex->getMessage() . "\n";
         $message .= "Response Status Code: " . $ex->getStatusCode() . "\n";
         $message .= "Error Code: " . $ex->getErrorCode() . "\n";
         $message .= "Error Type: " . $ex->getErrorType() . "\n";
         $param['message'] = $message;
         $obj = new Pwapresta();
         $obj->generate_log($param);
     }
 }
Exemplo n.º 4
0
 function invokeManageReportSchedule(MarketplaceWebService_Interface $service, $request)
 {
     try {
         $response = $service->manageReportSchedule($request);
         echo "        ManageReportScheduleResponse\n";
         if ($response->isSetManageReportScheduleResult()) {
             echo "            ManageReportScheduleResult\n";
             $manageReportScheduleResult = $response->getManageReportScheduleResult();
             if ($manageReportScheduleResult->isSetCount()) {
                 echo "                Count\n";
                 echo "                    " . $manageReportScheduleResult->getCount() . "\n";
             }
             $reportScheduleList = $manageReportScheduleResult->getReportScheduleList();
             foreach ($reportScheduleList as $reportSchedule) {
                 echo "                ReportSchedule\n";
                 if ($reportSchedule->isSetReportType()) {
                     echo "                    ReportType\n";
                     echo "                        " . $reportSchedule->getReportType() . "\n";
                 }
                 if ($reportSchedule->isSetSchedule()) {
                     echo "                    Schedule\n";
                     echo "                        " . $reportSchedule->getSchedule() . "\n";
                 }
                 if ($reportSchedule->isSetScheduledDate()) {
                     echo "                    ScheduledDate\n";
                     echo "                        " . $reportSchedule->getScheduledDate()->format(DATE_FORMAT) . "\n";
                 }
             }
         }
     } catch (MarketplaceWebService_Exception $ex) {
         $message = 'MWS Report API : Caught Exception : ' . $ex->getMessage() . "\n";
         $message .= "Response Status Code: " . $ex->getStatusCode() . "\n";
         $message .= "Error Code: " . $ex->getErrorCode() . "\n";
         $message .= "Error Type: " . $ex->getErrorType() . "\n";
         $param['message'] = $message;
         $obj = new Pwapresta();
         $obj->generate_log($param);
         echo $message;
     }
 }
Exemplo n.º 5
0
 public function pwa_iopn($data)
 {
     include_once 'iopn/pwa-iopn.php';
     if (Configuration::get('PWAPRESTA_PWAPRESTA_ORDER_UPDATE_API') == 'IOPN') {
         if (!empty($data)) {
             $param['message'] = 'IOPN Notifications : IOPN function called with some POST data.';
             $obj = new Pwapresta();
             $obj->generate_log($param);
             $data1 = json_encode($data);
             $filename = '1_iopn_non';
             $myfile = fopen($filename, "w");
             fwrite($myfile, $data1);
             fclose($myfile);
             $iopn = new PWA_Iopn();
             $iopn->notifications($data);
         } else {
             $param['message'] = 'IOPN Notifications : IOPN function called without POST data.';
             $obj = new Pwapresta();
             $obj->generate_log($param);
         }
     }
     exit;
 }
Exemplo n.º 6
0
 public function notifications($param)
 {
     $prefix = _DB_PREFIX_;
     try {
         if (isset($param['UUID']) && $param['UUID'] != '') {
             $uuid = urldecode($param['UUID']);
         } else {
             $uuid = '';
         }
         if (isset($param['Timestamp']) && $param['Timestamp'] != '') {
             $timestamp = urldecode($param['Timestamp']);
         } else {
             $timestamp = '';
         }
         if (isset($param['Signature']) && $param['Signature'] != '') {
             $Signature = str_replace(' ', '+', urldecode($param['Signature']));
         } else {
             $Signature = '';
         }
         if (isset($param['AWSAccessKeyId']) && $param['AWSAccessKeyId'] != '') {
             $AWSAccessKeyId = urldecode($param['AWSAccessKeyId']);
         } else {
             $AWSAccessKeyId = '';
         }
         $NotificationType = urldecode($param['NotificationType']);
         $NotificationData = stripslashes(urldecode($param['NotificationData']));
         if ($uuid != '') {
             $sql = 'INSERT into `' . $prefix . 'pwa_iopn_records` (`uuid`,`timestamp`,`notification_type`) VALUES("' . $uuid . '" , "' . $timestamp . '" , "' . $NotificationType . '") ';
             Db::getInstance()->Execute($sql);
             $iopn_record_id = Db::getInstance()->Insert_ID();
         }
         // Verify that the notification request is valid by verifying the Signature
         $concatenate = $uuid . $timestamp;
         $secretKeyID = Configuration::get('PWAPRESTA_PWAPRESTA_SECRET_KEY');
         $calculator = new SignatureCalculator();
         $generatedSignature = $calculator->calculateRFC2104HMAC($concatenate, $secretKeyID);
         if ($Signature != '' && $Signature == $generatedSignature || $Signature == '') {
             // Verify the Timestamp
             //$this->time_difference($timestamp) > 15
             if (1) {
                 if ($NotificationType == 'NewOrderNotification') {
                     $new_order = new NewOrderNotification();
                     $new_order->update_order($NotificationData, $iopn_record_id);
                 }
                 if ($NotificationType == 'OrderReadyToShipNotification') {
                     if ($Signature == '') {
                         $xml = simplexml_load_string($NotificationData);
                         $AmazonOrderID = (string) $xml->ProcessedOrder->AmazonOrderID;
                         $obj = new Pwapresta();
                         if ($obj->pwa_order_exist($AmazonOrderID)) {
                             $confirm_order = new OrderReadyToShipNotification();
                             $confirm_order->update_order_status($NotificationData, $iopn_record_id);
                             header('HTTP/1.1 200 OK');
                         } else {
                             echo 'Sorry! it seems that this order is a fake order.';
                         }
                     } else {
                         $confirm_order = new OrderReadyToShipNotification();
                         $confirm_order->update_order_status($NotificationData, $iopn_record_id);
                         header('HTTP/1.1 200 OK');
                     }
                 }
                 if ($NotificationType == 'OrderCancelledNotification') {
                     $cancel_order = new OrderCancelledNotification();
                     $cancel_order->cancel_order($NotificationData, $iopn_record_id);
                     header('HTTP/1.1 200 OK');
                 }
             } else {
                 $param['message'] = 'IOPN Notifications : ' . $NotificationType . ' : IOPN function called and with wrong timestamp.';
                 $obj = new Pwapresta();
                 $obj->generate_log($param);
                 // Respond to the Request
                 header('HTTP/1.1 403 PERMISSION_DENIED');
             }
         } else {
             $param['message'] = 'IOPN Notifications : ' . $NotificationType . ' : IOPN function called and with wrong signature.';
             $obj = new Pwapresta();
             $obj->generate_log($param);
             // Respond to the Request
             header('HTTP/1.1 403 PERMISSION_DENIED');
         }
     } catch (Exception $e) {
         $param['message'] = 'IOPN Notifications : Caught exception : ' . $e->getMessage() . '.';
         $obj = new Pwapresta();
         $obj->generate_log($param);
     }
 }
Exemplo n.º 7
0
 function invokeSubmitFeed(MarketplaceWebService_Interface $service, $request)
 {
     try {
         $response = $service->submitFeed($request);
         if ($response->isSetSubmitFeedResult()) {
             $submitFeedResult = $response->getSubmitFeedResult();
             if ($submitFeedResult->isSetFeedSubmissionInfo()) {
                 $feedSubmissionInfo = $submitFeedResult->getFeedSubmissionInfo();
                 if ($feedSubmissionInfo->isSetFeedSubmissionId()) {
                     $feedSubmissionId = $feedSubmissionInfo->getFeedSubmissionId();
                     $param['message'] = 'Order Acknowledged : Feed Submission Id - ' . $feedSubmissionId;
                     $obj = new Pwapresta();
                     $obj->generate_log($param);
                 }
             }
         }
     } catch (MarketplaceWebService_Exception $ex) {
         $message = 'MWS Feed API : Caught Exception : ' . $ex->getMessage() . "\n";
         $message .= "Response Status Code: " . $ex->getStatusCode() . "\n";
         $message .= "Error Code: " . $ex->getErrorCode() . "\n";
         $message .= "Error Type: " . $ex->getErrorType() . "\n";
         $param['message'] = $message;
         $obj = new Pwapresta();
         $obj->generate_log($param);
     }
 }
Exemplo n.º 8
0
 function invokeGetReportRequestList(MarketplaceWebService_Interface $service, $request)
 {
     $prefix = _DB_PREFIX_;
     try {
         $response = $service->getReportRequestList($request);
         if ($response->isSetGetReportRequestListResult()) {
             $getReportRequestListResult = $response->getGetReportRequestListResult();
             $reportRequestInfoList = $getReportRequestListResult->getReportRequestInfoList();
             foreach ($reportRequestInfoList as $reportRequestInfo) {
                 if ($reportRequestInfo->isSetReportType() && $reportRequestInfo->getReportType() == '_GET_ORDERS_DATA_' && ($reportRequestInfo->isSetReportProcessingStatus() && $reportRequestInfo->getReportProcessingStatus() == '_DONE_')) {
                     if ($reportRequestInfo->isSetReportRequestId()) {
                         $ReportRequestId = $reportRequestInfo->getReportRequestId();
                     }
                     if ($reportRequestInfo->isSetGeneratedReportId()) {
                         $GeneratedReportId = $reportRequestInfo->getGeneratedReportId();
                         if ($GeneratedReportId == '' && $ReportRequestId != '') {
                             $GeneratedReportId = $this->get_report_list_api($ReportRequestId);
                             $data = $this->get_report_api($GeneratedReportId);
                         } else {
                             $data = $this->get_report_api($GeneratedReportId);
                         }
                         $xml = simplexml_load_string($data);
                         // Check and dump MWS Report API Response
                         if (Configuration::get('PWAPRESTA_PWAPRESTA_MWS_REPORT_DUMP') == '1') {
                             $dir = Configuration::get('PWAPRESTA_PWAPRESTA_MWS_REPORT_DUMP_URL');
                             if (!file_exists($dir) && !is_dir($dir)) {
                                 mkdir($dir, 0777);
                             }
                             $filename = $dir . $GeneratedReportId . '_mws_report';
                             $myfile = fopen($filename, "w");
                             fwrite($myfile, $data);
                             fclose($myfile);
                         }
                         foreach ($xml->Message as $orderdetail) {
                             $AmazonOrderID = (string) $orderdetail->OrderReport->AmazonOrderID;
                             $sql = 'select * from `' . $prefix . 'pwa_orders` where amazon_order_id = "' . $AmazonOrderID . '" ';
                             $results = Db::getInstance()->ExecuteS($sql);
                             if (empty($results)) {
                                 $tablename = $prefix . 'orders';
                                 $date = date('Y-m-d H:i:s');
                                 $sql = 'INSERT into `' . $tablename . '`  (`current_state` , `payment` , `module` , `date_add` ) VALUES( 99, "Pay with Amazon", "pwapresta", "' . $date . '" )';
                                 Db::getInstance()->Execute($sql);
                                 $order_id = Db::getInstance()->Insert_ID();
                                 $tablename = $prefix . 'pwa_orders';
                                 $sql = 'INSERT into `' . $tablename . '`  (`prestashop_order_id` , `amazon_order_id` ) VALUES( "' . $order_id . '", "' . $AmazonOrderID . '" )';
                                 Db::getInstance()->Execute($sql);
                                 $this->update_order_detail($order_id, $orderdetail);
                             } else {
                                 $order_id = $results[0]['prestashop_order_id'];
                                 $this->update_order_detail($order_id, $orderdetail);
                             }
                         }
                     }
                 }
             }
             $dateTime = new DateTime('now', new DateTimeZone('UTC'));
             $time = $dateTime->format(DATE_ISO8601);
             $sql = 'INSERT into `' . $prefix . 'mws_report_cron` (`created_before`) VALUES("' . $time . '") ';
             Db::getInstance()->Execute($sql);
         }
     } catch (MarketplaceWebService_Exception $ex) {
         $message = 'MWS Report API : Caught Exception : ' . $ex->getMessage() . "\n";
         $message .= "Response Status Code: " . $ex->getStatusCode() . "\n";
         $message .= "Error Code: " . $ex->getErrorCode() . "\n";
         $message .= "Error Type: " . $ex->getErrorType() . "\n";
         $param['message'] = $message;
         $obj = new Pwapresta();
         $obj->generate_log($param);
     }
 }