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;
 }
 /**
  * Records the Protection Eligibility status to the Purchase Log on
  * DoExpressCheckout Call
  *
  * @return void
  */
 public function log_protection_status($response)
 {
     $params = $response->get_params();
     if (isset($params['PAYMENTINFO_0_PROTECTIONELIGIBILITY'])) {
         $elg = $params['PAYMENTINFO_0_PROTECTIONELIGIBILITY'];
     } else {
         $elg = false;
     }
     $paypal_log = wpsc_get_purchase_meta($this->purchase_log->get('id'), 'paypal_ec_details', true);
     $paypal_log['protection'] = $elg;
     wpsc_update_purchase_meta($this->purchase_log->get('id'), 'paypal_ec_details', $paypal_log);
 }
예제 #3
0
/**
 * Attach a purchase log to our customer profile
 *
 * @access private
 * @since  3.8.14
 */
function _wpsc_set_purchase_log_customer_id($wpsc_purchase_log)
{
    do_action('_wpsc_set_purchase_log_customer_id', $wpsc_purchase_log);
    // if there is a purchase log for this user we don't want to delete the
    // user id, even if the transaction isn't successful.  there may be useful
    // information in the customer profile related to the transaction
    wpsc_delete_customer_meta('temporary_profile');
    // connect the purchase to the visitor id
    wpsc_update_purchase_meta($wpsc_purchase_log->get('id'), 'visitor_id', wpsc_get_current_customer_id(), true);
    // connect the visitor to purchase
    wpsc_add_visitor_meta(wpsc_get_current_customer_id(), 'purchase_id', $wpsc_purchase_log->get('id'), false);
}
예제 #4
0
 /**
  * Records the Protection Eligibility status to the Purchase Log
  * after the purchase process
  *
  * @param PHP_Merchant_Paypal_Pro_Response $response
  * @return void
  */
 public function log_protection_status($response)
 {
     $params = $response->get_params();
     $elg = $params['PROTECTIONELIGIBILITY'];
     $paypal_log = wpsc_get_purchase_meta($this->purchase_log->get('id'), 'paypal_pro_details', true);
     $paypal_log['protection'] = $elg;
     wpsc_update_purchase_meta($this->purchase_log->get('id'), 'paypal_pro_details', $paypal_log);
 }
예제 #5
0
 /**
  * Save meta data for purchase log, if any was set via set().
  *
  * @since  4.0
  * @return void
  */
 private function save_meta_data()
 {
     do_action('wpsc_purchase_log_pre_save_meta', $this);
     $meta = $this->get_meta();
     foreach ($meta as $key => $value) {
         wpsc_update_purchase_meta($this->get('id'), $key, $value);
     }
     do_action('wpsc_purchase_log_save_meta', $this);
 }