Пример #1
0
 /**
  * constructor for a region object
  *
  * If null is passed for parameters an empty region is created
  *
  * @access public
  *
  * @since 3.8.14
  *
  * @param int|string|null       required    $country    The country identifier, can be the string ISO code,
  *                                                      or the numeric wpec country id
  *
  * @param int|string|null|array required    $region     The region identifier, can be the text region code,
  *                                                      or the numeric region id, if an array is passed a
  *                                                      new region will be created and saved in the permanent
  *                                                      data store
  */
 public function __construct($country, $region)
 {
     // if a country id or code is passed make sure we have a valid country_id
     $country_id = $country ? WPSC_Countries::get_country_id($country) : 0;
     // if we are creating a region use the country_id we just validated and get the region code
     if (is_array($region)) {
         $region['country_id'] = $country_id;
         $region_id_or_code = $this->_save_region_data($region);
     } else {
         $region_id_or_code = $region;
     }
     // if we have both a country country id and a region id/code we can construct this object
     if ($country && $region_id_or_code) {
         $region_id = WPSC_Countries::get_region_id($country_id, $region_id_or_code);
         if ($country_id && $region_id) {
             $wpsc_country = new WPSC_Country($country_id);
             $wpsc_region = $wpsc_country->get_region($region_id);
             if ($wpsc_region) {
                 $this->_code = $wpsc_region->_code;
                 $this->_id = $wpsc_region->_id;
                 $this->_country_id = $wpsc_region->_country_id;
                 $this->_name = $wpsc_region->_name;
                 $this->_tax = $wpsc_region->_tax;
             }
         }
     }
 }
Пример #2
0
 public function set_customer_details()
 {
     $_POST['wpsc_checkout_details'] = array();
     $_GET['amazon_reference_id'] = sanitize_text_field($_POST['amazon_reference_id']);
     try {
         if (!$this->reference_id) {
             throw new Exception(__('An Amazon payment method was not chosen.', 'wpsc'));
         }
         if (is_null($this->purchase_log)) {
             $log = _wpsc_get_current_controller()->get_purchase_log();
             wpsc_update_customer_meta('current_purchase_log_id', $log->get('id'));
             $this->set_purchase_log($log);
         }
         global $wpsc_cart;
         // Update order reference with amounts
         $response = $this->api_request(array('Action' => 'SetOrderReferenceDetails', 'AmazonOrderReferenceId' => $this->reference_id, 'OrderReferenceAttributes.OrderTotal.Amount' => $wpsc_cart->calculate_total_price(), 'OrderReferenceAttributes.OrderTotal.CurrencyCode' => strtoupper($this->get_currency_code()), 'OrderReferenceAttributes.SellerNote' => sprintf(__('Order %s from %s.', 'wpsc'), $this->purchase_log->get('id'), urlencode(remove_accents(wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES)))), 'OrderReferenceAttributes.SellerOrderAttributes.SellerOrderId' => $this->purchase_log->get('id'), 'OrderReferenceAttributes.SellerOrderAttributes.StoreName' => remove_accents(wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES)), 'OrderReferenceAttributes.PlatformId' => 'A2Z8DY3R4G08IM'));
         if (is_wp_error($response)) {
             throw new Exception($response->get_error_message());
         }
         if (isset($response['Error']['Message'])) {
             throw new Exception($response['Error']['Message']);
         }
         $response = $this->api_request(array('Action' => 'GetOrderReferenceDetails', 'AmazonOrderReferenceId' => $this->reference_id));
         if (is_wp_error($response)) {
             throw new Exception($response->get_error_message());
         }
         if (!isset($response['GetOrderReferenceDetailsResult']['OrderReferenceDetails']['Destination']['PhysicalDestination'])) {
             return;
         }
         $address = $response['GetOrderReferenceDetailsResult']['OrderReferenceDetails']['Destination']['PhysicalDestination'];
         remove_action('wpsc_checkout_get_fields', '__return_empty_array');
         add_filter('wpsc_validate_form', '__return_true');
         $form = WPSC_Checkout_Form::get();
         $fields = $form->get_fields();
         foreach ($fields as $field) {
             switch ($field->unique_name) {
                 case 'shippingstate':
                     $_POST['wpsc_checkout_details'][$field->id] = WPSC_Countries::get_region_id($address['CountryCode'], $address['StateOrRegion']);
                     break;
                 case 'shippingcountry':
                     $_POST['wpsc_checkout_details'][$field->id] = $address['CountryCode'];
                     break;
                 case 'shippingpostcode':
                     $_POST['wpsc_checkout_details'][$field->id] = $address['PostalCode'];
                     break;
                 case 'shippingcity':
                     $_POST['wpsc_checkout_details'][$field->id] = $address['City'];
                     break;
             }
         }
     } catch (Exception $e) {
         WPSC_Message_Collection::get_instance()->add($e->getMessage(), 'error', 'main', 'flash');
         return;
     }
 }