private function set_purchase_log_for_callbacks($sessionid = false)
 {
     if ($sessionid === false) {
         $sessionid = $_REQUEST['sessionid'];
     }
     $purchase_log = new WPSC_Purchase_Log($sessionid, 'sessionid');
     if (!$purchase_log->exists()) {
         return;
     }
     $this->set_purchase_log($purchase_log);
 }
 /**
  * Creates a new Purchase Log entry and set it to the current object
  *
  * @return null
  */
 protected function set_purchase_log_for_callbacks($sessionid = false)
 {
     // Define the sessionid if it's not passed
     if ($sessionid === false) {
         $sessionid = $_REQUEST['sessionid'];
     }
     // Create a new Purchase Log entry
     $purchase_log = new WPSC_Purchase_Log($sessionid, 'sessionid');
     if (!$purchase_log->exists()) {
         return null;
     }
     // Set the Purchase Log for the gateway object
     $this->set_purchase_log($purchase_log);
 }
 private function import_ipn_data()
 {
     global $wpdb;
     $purchase_log = new WPSC_Purchase_Log($this->cart_data['session_id'], 'sessionid');
     if (!$purchase_log->exists()) {
         return;
     }
     // get all active form fields and organize them based on id and unique_name, because we're only
     // importing fields relevant to checkout fields that have unique name
     $form_fields_sql = "SELECT id, unique_name FROM " . WPSC_TABLE_CHECKOUT_FORMS . " WHERE active='1'";
     $form_fields_results = $wpdb->get_results($form_fields_sql);
     $form_fields = array();
     foreach ($form_fields_results as $row) {
         if (!empty($row->unique_name)) {
             $form_fields[$row->id] = $row->unique_name;
         }
     }
     $purchase_log_id = $purchase_log->get('id');
     // this defines how ipn response data will be parsed into checkout field values
     $field_mapping = array('firstname' => 'first_name', 'lastname' => 'last_name', 'country' => 'address_country_code', 'email' => 'payer_email', 'city' => 'address_city', 'address' => 'address_street', 'phone' => 'contact_phone');
     $inserts = array();
     // billing & shipping will get the same values
     foreach (array('billing', 'shipping') as $type) {
         // if the corresponding checkout field is "active", prepare the data array that will
         // get passed into $wpdb->insert()
         foreach ($field_mapping as $key => $value) {
             $unique_name = $type . $key;
             $id = array_search($unique_name, $form_fields);
             if ($id === false || !isset($this->paypal_ipn_values[$value])) {
                 continue;
             }
             $inserts[] = array('log_id' => $purchase_log_id, 'form_id' => $id, 'value' => $this->paypal_ipn_values[$value]);
         }
     }
     // loop through the prepared data array and insert them
     foreach ($inserts as $insert) {
         $wpdb->insert(WPSC_TABLE_SUBMITED_FORM_DATA, $insert, array('%d', '%d', '%s'));
     }
 }
Ejemplo n.º 4
0
 public function is_valid_ipn_response()
 {
     $valid = true;
     // Validate Currency
     if ($this->paypal_ipn_values['mc_currency'] !== $this->get_paypal_currency_code()) {
         $valid = false;
     }
     $purchase_log = new WPSC_Purchase_Log($this->cart_data['session_id'], 'sessionid');
     if (!$purchase_log->exists()) {
         $valid = false;
     }
     // Validate amount
     // It is worth noting, there are edge cases here that may need to be addressed via filter.
     // @link https://github.com/wp-e-commerce/WP-e-Commerce/issues/1232.
     if ($this->paypal_ipn_values['mc_gross'] != $this->convert($purchase_log->get('totalprice'))) {
         $valid = false;
     }
     return apply_filters('wpsc_paypal_standard_is_valid_ipn_response', $valid, $this);
 }
function _wpsc_oklink_return()
{
    if (!isset($_REQUEST['wpsc_oklink_return'])) {
        return;
    }
    // oklink order param interferes with wordpress
    unset($_REQUEST['order']);
    unset($_GET['order']);
    if (!isset($_REQUEST['sessionid'])) {
        return;
    }
    global $sessionid;
    $purchase_log = new WPSC_Purchase_Log($_REQUEST['sessionid'], 'sessionid');
    if (!$purchase_log->exists() || $purchase_log->is_transaction_completed()) {
        return;
    }
    $status = 1;
    if (isset($_REQUEST['cancelled'])) {
        # Unsetting sessionid to show error
        do_action('wpsc_payment_failed');
        $sessionid = false;
        unset($_REQUEST['sessionid']);
        unset($_GET['sessionid']);
    } else {
        $status = WPSC_Purchase_Log::ORDER_RECEIVED;
        $purchase_log->set('processed', $status);
        $purchase_log->save();
        wpsc_empty_cart();
    }
}