private function charge_credit_card()
 {
     // Common setup for API credentials
     $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
     $merchantAuthentication->setName($this->api_login_id);
     $merchantAuthentication->setTransactionKey($this->api_transaction_key);
     $refId = 'ref' . time();
     // Create the payment data for a credit card
     $creditCard = new AnetAPI\CreditCardType();
     $creditCard->setCardNumber($this->card_number);
     $creditCard->setExpirationDate($this->expiration_year . '-' . $this->expiration_month);
     $paymentOne = new AnetAPI\PaymentType();
     $paymentOne->setCreditCard($creditCard);
     // Order info
     $order = new AnetAPI\OrderType();
     $order->setInvoiceNumber($this->invoice_number);
     $order->setDescription(get_bloginfo('name'));
     $cart_contents = $this->purchase_log->get_cart_contents();
     $lineitems = array();
     // Line Item Info
     foreach ($cart_contents as $index => $item) {
         // this is for the product options support that can be used in place of variations
         if (defined('OPTION_BASE')) {
             $options = wpsc_get_cart_item_meta($item->id, OPTION_BASE, true);
             if (!empty($options)) {
                 $options_message = strip_tags($options->message());
             }
         }
         $custom_description = $item->name . ' ' . $options_message . ' ' . $item->custom_message;
         $lineitems[$index] = new AnetAPI\LineItemType();
         $lineitems[$index]->setItemId($item->prodid);
         $lineitems[$index]->setName(substr($item->name, 0, 31));
         $lineitems[$index]->setDescription(substr($custom_description, 0, 255));
         $lineitems[$index]->setQuantity($item->quantity);
         $lineitems[$index]->setUnitPrice($this->force_two_decimals($item->price));
         $lineitems[$index]->setTaxable(0.0 != floatval($item->tax_charged));
     }
     // Tax info
     $tax = new AnetAPI\ExtendedAmountType();
     $tax->setName("Sales Tax");
     $tax->setAmount($this->force_two_decimals($this->purchase_log->get('wpec_taxes_total')));
     $tax->setDescription("Sales Tax");
     // Customer info
     $customer = new AnetAPI\CustomerDataType();
     $wp_user = get_user_by('email', $this->checkout_data->get('billingemail'));
     if ($wp_user) {
         $customer->setId($wp_user->ID);
     }
     $customer->setEmail($this->checkout_data->get('billingemail'));
     // PO Number
     $ponumber = $this->checkout_data->get('billingponumber');
     //Ship To Info
     $shipto = new AnetAPI\NameAndAddressType();
     $shipto->setFirstName($this->checkout_data->get('shippingfirstname'));
     $shipto->setLastName($this->checkout_data->get('shippinglastname'));
     //		$shipto->setCompany( $this->checkout_data->get( 'shippingcompany') );
     $shipto->setAddress($this->checkout_data->get('shippingaddress'));
     $shipto->setCity($this->checkout_data->get('shippingcity'));
     $shipto->setState($this->checkout_data->get('shippingstate'));
     $shipto->setZip($this->checkout_data->get('shippingpostcode'));
     $shipto->setCountry($this->checkout_data->get('shippingcountry'));
     // Bill To
     $billto = new AnetAPI\CustomerAddressType();
     $billto->setFirstName($this->checkout_data->get('billingfirstname'));
     $billto->setLastName($this->checkout_data->get('billinglastname'));
     //		$billto->setCompany(  $this->checkout_data->get( 'billingcompany') );
     $billto->setAddress($this->checkout_data->get('billingaddress'));
     $billto->setCity($this->checkout_data->get('billingcity'));
     $billto->setState($this->checkout_data->get('billingstate'));
     $billto->setZip($this->checkout_data->get('billingpostcode'));
     $billto->setCountry($this->checkout_data->get('billingcountry'));
     $billto->setPhoneNumber($this->checkout_data->get('billingphone'));
     //create a transaction
     $transactionRequestType = new AnetAPI\TransactionRequestType();
     foreach ($lineitems as $lineitem) {
         $transactionRequestType->addToLineItems($lineitem);
     }
     $transactionRequestType->setTransactionType("authCaptureTransaction");
     $transactionRequestType->setAmount($this->force_two_decimals($this->purchase_log->get('totalprice')));
     $transactionRequestType->setTax($tax);
     $transactionRequestType->setPayment($paymentOne);
     $transactionRequestType->setOrder($order);
     if (!empty($ponumber)) {
         $transactionRequestType->setPoNumber($ponumber);
     }
     $transactionRequestType->setCustomer($customer);
     $transactionRequestType->setBillTo($billto);
     $transactionRequestType->setShipTo($shipto);
     if (!empty($_SERVER['REMOTE_ADDR'])) {
         $transactionRequestType->setCustomerIP($_SERVER['REMOTE_ADDR']);
     }
     $request = new AnetAPI\CreateTransactionRequest();
     $request->setMerchantAuthentication($merchantAuthentication);
     $request->setRefId($refId);
     $request->setTransactionRequest($transactionRequestType);
     $controller = new AnetController\CreateTransactionController($request);
     if ($this->sandbox_mode) {
         $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
     } else {
         $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::PRODUCTION);
     }
     $result = false;
     if ($response != null) {
         $tresponse = $response->getTransactionResponse();
         if ($tresponse != null) {
             // see http://developer.authorize.net/api/reference/ for definitions
             if ($tresponse->getResponseCode() == "1") {
                 // 1 = Approved
                 $this->set_purchaselog_status(WPSC_Purchase_Log::ACCEPTED_PAYMENT);
                 $result = true;
             } elseif ($tresponse->getResponseCode() == "2") {
                 // 2 = Declined
                 $this->set_purchaselog_status(WPSC_Purchase_Log::INCOMPLETE_SALE);
                 $result = true;
             } elseif ($tresponse->getResponseCode() == "3") {
                 // 3 = Error
                 $this->set_purchaselog_status(WPSC_Purchase_Log::INCOMPLETE_SALE);
                 $result = false;
             } elseif ($tresponse->getResponseCode() == "4") {
                 // 4 = Held for Review
                 $this->set_purchaselog_status(WPSC_Purchase_Log::INCOMPLETE_SALE);
                 $result = true;
             } else {
                 // Unknown transaction code
                 $this->set_purchaselog_status(WPSC_Purchase_Log::INCOMPLETE_SALE);
                 error_log(__CLASS__ . '::' . __FUNCTION__ . ' ' . "ERROR: Charge Credit Card ERROR : Unknown transaction response code");
             }
             wpsc_update_purchase_meta($this->invoice_number, 'pbci_auth_net_raw_response', $tresponse);
             $messages = wpsc_get_customer_meta('checkout_misc_error_messages');
             if (!is_array($messages)) {
                 $messages = array();
             }
             // get the transaction error messages
             $transaction_error_messages = $response->getMessages();
             if ($transaction_error_messages) {
                 $transaction_error_messages = $transaction_error_messages->getMessage();
             }
             if (!is_array($transaction_error_messages)) {
                 $transaction_error_messages = array($transaction_error_messages);
             }
             foreach ($transaction_error_messages as $error_message) {
                 $messages[] = $error_message->getText();
             }
             // get the transaction response error messages
             $transaction_errors = $tresponse->getErrors();
             foreach ($transaction_errors as $transaction_error) {
                 $messages[] = $transaction_error->getErrorText();
             }
             wpsc_update_customer_meta('checkout_misc_error_messages', $messages);
             $this->purchase_log->set('transactid', $tresponse->getTransId());
             $this->purchase_log->set('authcode', $tresponse->getAuthCode());
         } else {
             error_log(__CLASS__ . '::' . __FUNCTION__ . ' ' . "ERROR: Charge Credit Card ERROR :  Invalid response");
         }
     } else {
         error_log(__CLASS__ . '::' . __FUNCTION__ . ' ' . "ERROR: Charge Credit card Null response returned");
     }
     $this->purchase_log->save();
     return $result;
 }
예제 #2
0
function wpsc_purchaselog_details_SKU()
{
    global $purchlogitem;
    $meta_value = wpsc_get_cart_item_meta($purchlogitem->purchitem->id, 'sku', true);
    if ($meta_value != null) {
        return esc_attr($meta_value);
    } else {
        $meta_value = get_product_meta($purchlogitem->purchitem->prodid, 'sku', true);
        if ($meta_value != null) {
            return esc_attr($meta_value);
        } else {
            return __('N/A', 'wpsc');
        }
    }
}
예제 #3
0
/**
 * Get cart item meta
 * @access public
 *
 * @deprecated since 3.8.13
 */
function wpsc_get_cartmeta($cart_item_id, $meta_key)
{
    _wpsc_deprecated_function(__FUNCTION__, '3.8.13', 'wpsc_get_cart_item_meta');
    return wpsc_get_cart_item_meta($cart_item_id, $meta_key, true);
}
예제 #4
0
 /**
  * collate_cart method, collate cart data
  * @access public
  *
  */
 function collate_cart()
 {
     global $wpdb;
     $purchase_id =& $this->purchase_id;
     $original_cart_data = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid` = {$purchase_id}", ARRAY_A);
     foreach ($original_cart_data as $cart_row) {
         $is_downloadable = false;
         if ($wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_DOWNLOAD_STATUS . "` WHERE `cartid` = {$cart_row['id']}")) {
             $is_downloadable = true;
         }
         $is_recurring = (bool) get_post_meta($cart_row['prodid'], '_wpsc_is_recurring', true);
         if ($is_recurring == true) {
             $this->cart_data['is_subscription'] = true;
         }
         if (!($rebill_interval = get_post_meta($cart_row['prodid'], '_wpsc_rebill_interval', true))) {
             $rebill_interval = array();
         }
         $new_cart_item = array("cart_item_id" => $cart_row['id'], "product_id" => $cart_row['prodid'], "name" => $cart_row['name'], "price" => $cart_row['price'], "shipping" => $cart_row['pnp'], "tax" => $cart_row['tax_charged'], "quantity" => $cart_row['quantity'], "is_downloadable" => $is_downloadable, "is_capability" => (bool) wpsc_get_cart_item_meta($cart_row['id'], 'provided_capabilities', true), "is_recurring" => $is_recurring, "is_subscription" => $is_recurring, "recurring_data" => array("rebill_interval" => array('unit' => isset($rebill_interval['unit']) ? $rebill_interval['unit'] : null, 'length' => isset($rebill_interval['number']) ? $rebill_interval['number'] : null), "charge_to_expiry" => (bool) get_post_meta($cart_row['prodid'], '_wpsc_charge_to_expiry', true), "times_to_rebill" => get_post_meta($cart_row['prodid'], '_wpsc_rebill_number', true)));
         $this->cart_items[] = apply_filters('wpsc_merchant_collate_cart_item', $new_cart_item, $this);
     }
 }
예제 #5
0
파일: Main.php 프로젝트: TakenCdosG/chefs
 /**
  * Generate and store all the attendees information for a new order.
  *
  * @param int $id
  * @param string $status (unused)
  * @param string $old_status (unused)
  * @param $purchase_log
  */
 public function generate_tickets($id, $status, $old_status, $purchase_log)
 {
     if (empty($purchase_log)) {
         return;
     }
     // Do not generate tickets until payment has been accepted/job dispatched
     $complete = $purchase_log->is_accepted_payment() || $purchase_log->is_job_dispatched();
     apply_filters('wpectickets_order_is_complete', $complete, $purchase_log);
     if (!$complete) {
         return;
     }
     // Bail if we already generated the info for this order
     $done = wpsc_get_meta($id, $this->order_done, 'tribe_tickets');
     if (!empty($done)) {
         return;
     }
     $has_tickets = false;
     // Get the items purchased in this order
     $order_items = $purchase_log->get_cart_contents();
     // Bail if the order is empty
     if (empty($order_items)) {
         return;
     }
     // Iterate over each product
     foreach ((array) $order_items as $item) {
         $order_attendee_id = 0;
         $product_id = $item->prodid;
         // Get the event this tickets is for
         $event_id = get_post_meta($product_id, $this->event_key, true);
         $optout = (bool) wpsc_get_cart_item_meta($item->purchaseid, self::ATTENDEE_OPTOUT_KEY, true);
         if (!empty($event_id)) {
             $has_tickets = true;
             // Iterate over all the amount of tickets purchased (for this product)
             $quantity = intval($item->quantity);
             for ($i = 0; $i < $quantity; $i++) {
                 $attendee = array('post_status' => 'publish', 'post_title' => $id . ' | ' . $item->name . ' | ' . ($i + 1), 'post_type' => self::ATTENDEE_OBJECT, 'ping_status' => 'closed');
                 // Insert individual ticket purchased
                 $attendee_id = wp_insert_post($attendee);
                 update_post_meta($attendee_id, self::ATTENDEE_PRODUCT_KEY, $product_id);
                 update_post_meta($attendee_id, self::ATTENDEE_ORDER_KEY, $id);
                 update_post_meta($attendee_id, self::ATTENDEE_EVENT_KEY, $event_id);
                 update_post_meta($attendee_id, $this->security_code, $this->generate_security_code($id, $attendee_id));
                 update_post_meta($attendee_id, self::ATTENDEE_OPTOUT_KEY, $optout);
                 /**
                  * WPEC specific action fired when a WPEC-driven attendee ticket for an event is generated
                  *
                  * @param $attendee_id ID of attendee ticket
                  * @param $event_id ID of event
                  * @param $order_id WPEC order ID
                  * @param $product_id WPEC product ID
                  */
                 do_action('event_tickets_wpec_attendee_created', $attendee_id, $event_id, $product_id);
                 /**
                  * Action fired when an attendee ticket is generated
                  *
                  * @param $attendee_id ID of attendee ticket
                  * @param $purchase_log WPEC purchase log object
                  * @param $product_id Product ID attendee is "purchasing"
                  * @param $order_attendee_id Attendee # for order
                  * @param $event_id The Event which this ticket belongs
                  */
                 do_action('event_tickets_wpec_ticket_created', $attendee_id, $purchase_log, $product_id, $order_attendee_id, $event_id);
                 $this->record_attendee_user_id($attendee_id);
                 $order_attendee_id++;
             }
         }
     }
     if ($has_tickets) {
         wpsc_update_meta($id, $this->order_done, '1', 'tribe_tickets');
         // Send the email to the user
         do_action('wpectickets-send-tickets-email', $purchase_log);
     }
 }
function cph_wpsc_purchaselog_details_SKU()
{
    global $purchlogitem;
    $meta_value = wpsc_get_cart_item_meta($purchlogitem->purchitem->id, 'sku', true);
    if ($meta_value != null) {
        $sku = esc_attr($meta_value);
    } else {
        $meta_value = get_product_meta($purchlogitem->purchitem->prodid, 'sku', true);
        if ($meta_value != null) {
            $sku = esc_attr($meta_value);
        } else {
            $sku = $purchlogitem->purchitem->prodid;
        }
    }
    $sku = '<a href="' . get_permalink($purchlogitem->purchitem->prodid) . '">' . $sku . '</a>';
    return $sku;
}