public function update_order_detail($order_id, $data)
 {
     global $wpdb, $woocommerce, $pwa;
     $non_received = $wpdb->get_results("select * from {$wpdb->postmeta} where meta_key = '_non_received' and post_id = {$order_id} ");
     if (empty($non_received)) {
         $pwacheckkout = new Pwacheckout();
         if ($pwacheckkout->get_option('iopn_dump') == 'yes') {
             $dir = $pwacheckkout->get_option('iopn_dump_url');
             if (!file_exists($dir) && !is_dir($dir)) {
                 mkdir($dir, 0777);
             }
             $filename = $dir . $order_id . '_iopn_non';
             $myfile = fopen($filename, "w");
             fwrite($myfile, $data);
             fclose($myfile);
         }
         add_post_meta($order_id, '_non_received', '1');
         if (UPDATE_ODER_FROM == 'xmlcart') {
             $this->update_cart_by_xml($order_id, $data);
         } else {
             $this->update_cart_by_woocart($order_id, $data);
         }
     }
     $order = new WC_Order($order_id);
     $order->update_status('cancelled');
     // Acknowledge the order in seller central using MWS FEED API
     $pwa->pwa_cancel_feed($order_id);
     header('HTTP/1.1 200 OK');
     exit;
 }
예제 #2
0
 public function update_order_detail($order_id, $data)
 {
     global $wpdb, $woocommerce;
     $non_received = $wpdb->get_results("select * from {$wpdb->postmeta} where meta_key = '_non_received' and post_id = {$order_id} ");
     if (empty($non_received)) {
         // Check and generate IOPN dump file
         $pwacheckkout = new Pwacheckout();
         if ($pwacheckkout->get_option('iopn_dump') == 'yes') {
             $dir = $pwacheckkout->get_option('iopn_dump_url');
             if (!file_exists($dir) && !is_dir($dir)) {
                 mkdir($dir, 0777);
             }
             $filename = $dir . $order_id . '_iopn_non';
             $myfile = fopen($filename, "w");
             fwrite($myfile, $data);
             fclose($myfile);
         }
         add_post_meta($order_id, '_non_received', '1');
         if (UPDATE_ODER_FROM == 'xmlcart') {
             $this->update_cart_by_xml($order_id, $data);
         } else {
             $this->update_cart_by_woocart($order_id, $data);
         }
         // Respond to the Request
         header('HTTP/1.1 200 OK');
         exit;
     } else {
         // Respond to the Request
         header('HTTP/1.1 503 SERVICE_UNAVAILABLE');
         exit;
     }
 }
예제 #3
0
 public function update_order($data)
 {
     global $wpdb, $woocommerce;
     $xml = simplexml_load_string($data);
     // Check and dump MWS Report API Response
     $pwacheckkout = new Pwacheckout();
     if ($pwacheckkout->get_option('mws_order_dump') == 'yes') {
         $dir = $pwacheckkout->get_option('mws_order_dump_url');
         if (!file_exists($dir) && !is_dir($dir)) {
             mkdir($dir, 0777);
         }
         $filename = $dir . time() . '_mws_order';
         $myfile = fopen($filename, "w");
         fwrite($myfile, $data);
         fclose($myfile);
     }
     $LastUpdatedBefore = $xml->ListOrdersResult->LastUpdatedBefore;
     $wpdb->insert($wpdb->prefix . 'pwa_mws_order_cron', array('created_before' => $LastUpdatedBefore));
     foreach ($xml->ListOrdersResult->Orders->Order as $order) {
         $AmazonOrderId = (string) $order->AmazonOrderId;
         $OrderStatus = (string) $order->OrderStatus;
         $order_postmeta = $wpdb->get_results("select post_id from {$wpdb->postmeta} where meta_key = '_pwa_order_id' and meta_value = '{$AmazonOrderId}' ");
         if (!empty($order_postmeta)) {
             if ($OrderStatus == 'Canceled') {
                 $order_id = $order_postmeta[0]->post_id;
                 $order = new WC_Order($order_id);
                 $order->update_status('cancelled');
             }
         }
     }
 }
예제 #4
0
 public function notifications($param)
 {
     global $wpdb, $prefix;
     $prefix = $wpdb->prefix . 'pwa_';
     try {
         $uuid = urldecode($param['UUID']);
         $timestamp = urldecode($param['Timestamp']);
         $Signature = str_replace(' ', '+', urldecode($param['Signature']));
         $AWSAccessKeyId = urldecode($param['AWSAccessKeyId']);
         $NotificationType = urldecode($param['NotificationType']);
         $NotificationData = stripslashes(urldecode($param['NotificationData']));
         $wpdb->insert($prefix . 'iopn_records', array('uuid' => $uuid, 'timestamp' => $timestamp, 'notification_type' => $NotificationType));
         $iopn_record_id = $wpdb->insert_id;
         // Verify that the notification request is valid by verifying the Signature
         $concatenate = $uuid . $timestamp;
         $pwacheckkout = new Pwacheckout();
         $secretKeyID = $pwacheckkout->get_option('secret_key');
         $calculator = new SignatureCalculator();
         $generatedSignature = $calculator->calculateRFC2104HMAC($concatenate, $secretKeyID);
         if ($Signature == $generatedSignature) {
             // 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') {
                     $confirm_order = new OrderReadyToShipNotification();
                     $confirm_order->update_order_status($NotificationData, $iopn_record_id);
                 }
                 if ($NotificationType == 'OrderCancelledNotification') {
                     $cancel_order = new OrderCancelledNotification();
                     $cancel_order->cancel_order($NotificationData, $iopn_record_id);
                 }
             } else {
                 $param['message'] = 'IOPN Notifications : ' . $NotificationType . ' : IOPN function called and with wrong timestamp.';
                 $this->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.';
             $this->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() . '.';
         $this->generate_log($param);
     }
 }
예제 #5
0
 public function pay_with_amazon_button()
 {
     $pwacheckkout = new Pwacheckout();
     if ($pwacheckkout->get_option('enabled') == 'yes') {
         $merchantID = $pwacheckkout->get_option('merchant_id');
         $accessKeyID = $pwacheckkout->get_option('access_key');
         $secretKeyID = $pwacheckkout->get_option('secret_key');
         $pwa_btn_color = $pwacheckkout->get_option('pwa_btn_color');
         $pwa_btn_bkgd = $pwacheckkout->get_option('pwa_btn_bkgd');
         $pwa_btn_size = $pwacheckkout->get_option('pwa_btn_size');
         if (!defined('PWA_BTN_COLOR')) {
             define('PWA_BTN_COLOR', $pwa_btn_color);
         }
         if (!defined('PWA_BTN_BKGD')) {
             define('PWA_BTN_BKGD', $pwa_btn_bkgd);
         }
         if (!defined('PWA_BTN_SIZE')) {
             define('PWA_BTN_SIZE', $pwa_btn_size);
         }
         $cartFactory = new XMLCartFactory();
         $calculator = new SignatureCalculator();
         $cart = $cartFactory->getSignatureInput($merchantID, $accessKeyID);
         $signature = $calculator->calculateRFC2104HMAC($cart, $secretKeyID);
         $cartHtml = $cartFactory->getCartHTML($merchantID, $accessKeyID, $signature);
         echo $cartHtml;
     }
 }
예제 #6
0
 public static function get_instance()
 {
     NULL === self::$instance and self::$instance = new self();
     return self::$instance;
 }
예제 #7
0
 function invokeGetReportRequestList(MarketplaceWebService_Interface $service, $request)
 {
     global $wpdb, $woocommerce;
     try {
         $response = $service->getReportRequestList($request);
         if ($response->isSetGetReportRequestListResult()) {
             $getReportRequestListResult = $response->getGetReportRequestListResult();
             $reportRequestInfoList = $getReportRequestListResult->getReportRequestInfoList();
             print_r($reportRequestInfoList);
             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
                         $pwacheckkout = new Pwacheckout();
                         if ($pwacheckkout->get_option('mws_report_dump') == 'yes') {
                             $dir = $pwacheckkout->get_option('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;
                             $order_postmeta = $wpdb->get_results("select post_id from {$wpdb->postmeta} where meta_key = '_pwa_order_id' and meta_value = '{$AmazonOrderID}' ");
                             if (empty($order_postmeta)) {
                                 $order = wc_create_order();
                                 add_post_meta($order->id, '_pwa_order_id', $AmazonOrderID);
                                 $this->update_order_detail($order->id, $orderdetail);
                             } else {
                                 $order_id = $order_postmeta[0]->post_id;
                                 $this->update_order_detail($order_id, $orderdetail);
                             }
                         }
                     }
                 }
             }
             $dateTime = new DateTime('now', new DateTimeZone('UTC'));
             $time = $dateTime->format(DATE_ISO8601);
             $wpdb->insert($wpdb->prefix . 'pwa_mws_report_cron', array('created_before' => $time));
         }
     } 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;
         $this->generate_log($param);
     }
 }
예제 #8
0
파일: pwa.php 프로젝트: booklein/wpbookle
 public function add_button_before_checkout()
 {
     $pwacheckkout = new Pwacheckout();
     if ($pwacheckkout->get_option('show_pwa_button') == 'yes') {
         if (is_user_logged_in()) {
             $cba = new PWA_Cba();
             $cba->pay_with_amazon_button();
         }
     } else {
         //echo "user not logged in";
         $cba = new PWA_Cba();
         $cba->pay_with_amazon_button();
     }
 }