/**
 * prcessing functions, this is where the main logic of paypal express lives
 * @access public
 *
 * @since 3.8
 */
function paypal_processingfunctions()
{
    global $wpdb, $wpsc_cart;
    $sessionid = (string) wpsc_get_customer_meta('paypal_express_sessionid');
    if (isset($_REQUEST['act']) && 'error' == $_REQUEST['act']) {
        $resArray = wpsc_get_customer_meta('paypal_express_reshash');
        $paypal_express_message = '
		<center>
		<table width="700" align="left">
		<tr>
			<td colspan="2" class="header">' . __('The PayPal API has returned an error!', 'wpsc') . '</td>
		</tr>
		';
        //it will print if any URL errors
        if (wpsc_get_customer_meta('paypal_express_curl_error_msg')) {
            $errorMessage = wpsc_get_customer_meta('paypal_express_curl_error_msg');
            $response = wpsc_get_customer_meta('paypal_express_response');
            $paypal_express_message .= '
			<tr>
				<td>response:</td>
				<td>' . $response . '</td>
			</tr>

			<tr>
				<td>Error Message:</td>
				<td>' . $errorMessage . '</td>
			</tr>';
        } else {
            /* If there is no URL Errors, Construct the HTML page with
               Response Error parameters.   */
            $paypal_express_message .= "\n\t\t\t\t<tr>\n\t\t\t\t\t<td>Ack:</td>\n\t\t\t\t\t<td>" . $resArray['ACK'] . "</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td>Correlation ID:</td>\n\t\t\t\t\t<td>" . $resArray['CORRELATIONID'] . "</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td>Version:</td>\n\t\t\t\t\t<td>" . $resArray['VERSION'] . "</td>\n\t\t\t\t</tr>";
            $count = 0;
            while (isset($resArray["L_SHORTMESSAGE" . $count])) {
                $errorCode = $resArray["L_ERRORCODE" . $count];
                $shortMessage = $resArray["L_SHORTMESSAGE" . $count];
                $longMessage = $resArray["L_LONGMESSAGE" . $count];
                $count = $count + 1;
                $paypal_express_message .= "\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td>" . __('Error Number:', 'wpsc') . "</td>\n\t\t\t\t\t\t<td> {$errorCode} </td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td>" . __('Short Message:', 'wpsc') . "</td>\n\t\t\t\t\t\t<td> {$shortMessage} </td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td>" . __('Long Message:', 'wpsc') . "</td>\n\t\t\t\t\t\t<td> {$longMessage} </td>\n\t\t\t\t\t</tr>";
            }
            //end while
        }
        // end else
        $paypal_express_message .= "\n\t\t\t</center>\n\t\t\t\t</table>";
        wpsc_update_customer_meta('paypal_express_message', $paypal_express_message);
    } else {
        if (isset($_REQUEST['act']) && $_REQUEST['act'] == 'do') {
            /* Gather the information to make the final call to
               finalize the PayPal payment.  The variable nvpstr
               holds the name value pairs   */
            $token = urlencode($_REQUEST['token']);
            $paymentAmount = urlencode(wpsc_get_customer_meta('paypal_express_converted_amount'));
            $paymentType = urlencode(wpsc_get_customer_meta('paypal_express_payment_type'));
            $currCodeType = urlencode(wpsc_get_paypal_currency_code());
            $payerID = urlencode($_REQUEST['PayerID']);
            $serverName = urlencode($_SERVER['SERVER_NAME']);
            $BN = 'Instinct_e-commerce_wp-shopping-cart_NZ';
            $nvpstr = '&TOKEN=' . $token . '&PAYERID=' . $payerID . '&PAYMENTREQUEST_0_PAYMENTACTION=Sale&PAYMENTREQUEST_0_CURRENCYCODE=' . $currCodeType . '&IPADDRESS=' . $serverName . "&BUTTONSOURCE=" . $BN . "&PAYMENTREQUEST_0_INVNUM=" . urlencode($sessionid);
            // IPN data
            if (get_option('paypal_ipn') == 1) {
                $notify_url = add_query_arg('wpsc_action', 'gateway_notification', get_option('siteurl') . "/index.php");
                $notify_url = add_query_arg('gateway', 'wpsc_merchant_paypal_express', $notify_url);
                $notify_url = apply_filters('wpsc_paypal_express_notify_url', $notify_url);
                $nvpstr .= '&PAYMENTREQUEST_0_NOTIFYURL=' . urlencode($notify_url);
            }
            // Horrible code that I had to write to hot fix the issue with missing item detail in email receipts. arrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrgh!!!!! @#@$%@#%@##$#$
            $purchase_log = $wpdb->get_row($wpdb->prepare("SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid` = %s", $sessionid), ARRAY_A);
            $cart_data = $original_cart_data = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid` = {$purchase_log['id']}", ARRAY_A);
            $i = 0;
            $item_total = 0;
            $shipping_total = 0;
            foreach ($cart_data as $cart_item) {
                $converted_price = wpsc_paypal_express_convert($cart_item['price']);
                $nvpstr .= "&L_PAYMENTREQUEST_0_NAME{$i}=" . urlencode(apply_filters('the_title', $cart_item['name']));
                $nvpstr .= "&L_PAYMENTREQUEST_0_AMT{$i}=" . $converted_price;
                $nvpstr .= "&L_PAYMENTREQUEST_0_NUMBER{$i}=" . $i;
                $nvpstr .= "&L_PAYMENTREQUEST_0_QTY{$i}=" . $cart_item['quantity'];
                $item_total += $converted_price * $cart_item['quantity'];
                $shipping_total += wpsc_paypal_express_convert($cart_item['pnp']);
                $i++;
            }
            //if we have a discount then include a negative amount with that discount
            if ($purchase_log['discount_value'] && 0.0 != $purchase_log['discount_value']) {
                $discount_value = wpsc_paypal_express_convert($purchase_log['discount_value']);
                // if item total < discount amount, leave at least 0.01 unit in item total, then subtract
                // 0.01 from shipping as well
                if ($discount_value >= $item_total) {
                    $discount_value = $item_total - 0.01;
                    $shipping_total -= 0.01;
                }
                $nvpstr .= "&L_PAYMENTREQUEST_0_NAME{$i}=" . urlencode("Discount / Coupon");
                $nvpstr .= "&L_PAYMENTREQUEST_0_AMT{$i}=-" . urlencode($discount_value);
                $nvpstr .= "&L_PAYMENTREQUEST_0_NUMBER{$i}={$i}";
                $nvpstr .= "&L_PAYMENTREQUEST_0_QTY{$i}=1";
                $item_total -= $discount_value;
            }
            $item_total = wpsc_paypal_express_format($item_total);
            $shipping_total = wpsc_paypal_express_convert($purchase_log['base_shipping']) + $shipping_total;
            $nvpstr .= '&PAYMENTREQUEST_0_ITEMAMT=' . $item_total;
            $nvpstr .= '&PAYMENTREQUEST_0_SHIPPINGAMT=' . $shipping_total;
            $total = $item_total + $shipping_total;
            if (!wpsc_tax_isincluded()) {
                $tax = wpsc_paypal_express_convert($purchase_log['wpec_taxes_total']);
                $nvpstr .= '&PAYMENTREQUEST_0_TAXAMT=' . $tax;
                $total += $tax;
            }
            // adjust total amount in case we had to round up after converting currency
            if ($total != $paymentAmount) {
                $paymentAmount = $total;
            }
            $nvpstr .= "&PAYMENTREQUEST_0_AMT={$paymentAmount}";
            $resArray = paypal_hash_call("DoExpressCheckoutPayment", $nvpstr);
            /* Display the API response back to the browser.
               If the response from PayPal was a success, display the response parameters'
               If the response was an error, display the errors received using APIError.php. */
            $ack = strtoupper($resArray["ACK"]);
            wpsc_update_customer_meta('paypal_express_reshash', $resArray);
            if ($ack != "SUCCESS") {
                $location = get_option('transact_url') . "&act=error";
            } else {
                $transaction_id = $resArray['PAYMENTINFO_0_TRANSACTIONID'];
                switch ($resArray['PAYMENTINFO_0_PAYMENTSTATUS']) {
                    case 'Processed':
                        // I think this is mostly equivalent to Completed
                    // I think this is mostly equivalent to Completed
                    case 'Completed':
                        wpsc_update_purchase_log_status($sessionid, 3, 'sessionid');
                        transaction_results($sessionid, false);
                        break;
                    case 'Pending':
                        // need to wait for "Completed" before processing
                        wpsc_update_purchase_log_details($sessionid, array('processed' => 2, 'date' => time(), 'transactid' => $transaction_id), 'sessionid');
                        break;
                }
                $location = add_query_arg('sessionid', $sessionid, get_option('transact_url'));
                wpsc_delete_customer_meta('paypal_express_message');
                wp_redirect($location);
                exit;
            }
            wpsc_delete_customer_meta('nzshpcrt_serialized_cart');
            wpsc_delete_customer_meta('nzshpcart');
            $wpsc_cart->empty_cart();
        } else {
            if (isset($_REQUEST['paymentType']) || isset($_REQUEST['token'])) {
                $token = $_REQUEST['token'];
                if (!isset($token)) {
                    $paymentAmount = wpsc_get_customer_meta('paypal_express_converted_amount');
                    $currencyCodeType = wpsc_get_paypal_currency_code();
                    $paymentType = 'Sale';
                    if (get_option('permalink_structure') != '') {
                        $separator = "?";
                    } else {
                        $separator = "&";
                    }
                    $returnURL = urlencode(get_option('transact_url') . $separator . 'currencyCodeType=' . $currencyCodeType . '&paymentType=' . $paymentType . '&paymentAmount=' . $paymentAmount);
                    $cancelURL = urlencode(get_option('transact_url') . $separator . 'paymentType=$paymentType');
                    /* Construct the parameter string that describes the PayPal payment
                    			the varialbes were set in the web form, and the resulting string
                    			is stored in $nvpstr */
                    $nvpstr = "&PAYMENTREQUEST_0_AMT=" . $paymentAmount . "&PAYMENTREQUEST_0_PAYMENTACTION=" . $paymentType . "&ReturnUrl=" . $returnURL . "&CANCELURL=" . $cancelURL . "&PAYMENTREQUEST_0_CURRENCYCODE=" . $currencyCodeType;
                    /* Make the call to PayPal to set the Express Checkout token
                    			If the API call succeded, then redirect the buyer to PayPal
                    			to begin to authorize payment.  If an error occured, show the
                    			resulting errors
                    			*/
                    $resArray = paypal_hash_call("SetExpressCheckout", $nvpstr);
                    wpsc_update_customer_meta('paypal_express_reshash', $resArray);
                    $ack = strtoupper($resArray["ACK"]);
                    if ($ack == "SUCCESS") {
                        // Redirect to paypal.com here
                        $token = urldecode($resArray["TOKEN"]);
                        $payPalURL = $PAYPAL_URL . $token;
                        wp_redirect($payPalURL);
                    } else {
                        // Redirecting to APIError.php to display errors.
                        $location = get_option('transact_url') . "&act=error";
                        wp_redirect($location);
                    }
                    exit;
                } else {
                    /* At this point, the buyer has completed in authorizing payment
                    			at PayPal.  The script will now call PayPal with the details
                    			of the authorization, incuding any shipping information of the
                    			buyer.  Remember, the authorization is not a completed transaction
                    			at this state - the buyer still needs an additional step to finalize
                    			the transaction
                    			*/
                    $token = urlencode($_REQUEST['token']);
                    /* Build a second API request to PayPal, using the token as the
                    			ID to get the details on the payment authorization
                    			*/
                    $nvpstr = "&TOKEN=" . $token;
                    /* Make the API call and store the results in an array.  If the
                    			call was a success, show the authorization details, and provide
                    			an action to complete the payment.  If failed, show the error
                    			*/
                    $resArray = paypal_hash_call("GetExpressCheckoutDetails", $nvpstr);
                    wpsc_update_customer_meta('paypal_express_reshash', $resArray);
                    $ack = strtoupper($resArray["ACK"]);
                    if ($ack == "SUCCESS") {
                        /********************************************************
                        				GetExpressCheckoutDetails.php
                        
                        				This functionality is called after the buyer returns from
                        				PayPal and has authorized the payment.
                        
                        				Displays the payer details returned by the
                        				GetExpressCheckoutDetails response and calls
                        				DoExpressCheckoutPayment.php to complete the payment
                        				authorization.
                        
                        				Called by ReviewOrder.php.
                        
                        				Calls DoExpressCheckoutPayment.php and APIError.php.
                        
                        				********************************************************/
                        /* Collect the necessary information to complete the
                        			authorization for the PayPal payment
                        			*/
                        /* Display the API response back to the browser .
                        			If the response from PayPal was a success, display the response parameters
                        			*/
                        if (isset($_REQUEST['token']) && !isset($_REQUEST['PayerID'])) {
                            wpsc_update_customer_meta('paypal_express_message', _x('<h4>TRANSACTION CANCELED</h4>', 'paypal express cancel header', 'wpsc'));
                        } else {
                            wpsc_update_customer_meta('paypal_express_token', $_REQUEST['token']);
                            wpsc_update_customer_meta('paypal_express_payer_id', $_REQUEST['PayerID']);
                            $resArray = wpsc_get_customer_meta('paypal_express_reshash');
                            if (get_option('permalink_structure') != '') {
                                $separator = "?";
                            } else {
                                $separator = "&";
                            }
                            if (!isset($resArray['SHIPTOSTREET2'])) {
                                $resArray['SHIPTOSTREET2'] = '';
                            }
                            $output = "\n\t\t\t\t\t   <table width='400' class='paypal_express_form'>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td align='left' class='firstcol'><b>" . __('Order Total:', 'wpsc') . "</b></td>\n\t\t\t\t\t\t\t<td align='left'>" . wpsc_currency_display(wpsc_get_customer_meta('paypal_express_original_amount')) . "</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td align='left' colspan='2'><b>" . __('Shipping Address:', 'wpsc') . " </b></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td align='left' class='firstcol'>\n\t\t\t\t\t\t\t\t" . __('Street 1:', 'wpsc') . "</td>\n\t\t\t\t\t\t\t<td align='left'>" . $resArray['SHIPTOSTREET'] . "</td>\n\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td align='left' class='firstcol'>\n\t\t\t\t\t\t\t\t" . __('Street 2:', 'wpsc') . "</td>\n\t\t\t\t\t\t\t<td align='left'>" . $resArray['SHIPTOSTREET2'] . "\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td align='left' class='firstcol'>\n\t\t\t\t\t\t\t\t" . __('City:', 'wpsc') . "</td>\n\n\t\t\t\t\t\t\t<td align='left'>" . $resArray['SHIPTOCITY'] . "</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td align='left' class='firstcol'>\n\t\t\t\t\t\t\t\t" . __('State:', 'wpsc') . "</td>\n\t\t\t\t\t\t\t<td align='left'>" . $resArray['SHIPTOSTATE'] . "</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td align='left' class='firstcol'>\n\t\t\t\t\t\t\t\t" . __('Postal code:', 'wpsc') . "</td>\n\n\t\t\t\t\t\t\t<td align='left'>" . $resArray['SHIPTOZIP'] . "</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td align='left' class='firstcol'>\n\t\t\t\t\t\t\t\t" . __('Country:', 'wpsc') . "</td>\n\t\t\t\t\t\t\t<td align='left'>" . $resArray['SHIPTOCOUNTRYNAME'] . "</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td colspan='2'>";
                            $output .= "<form action=" . get_option('transact_url') . " method='post'>\n";
                            $output .= "\t<input type='hidden' name='totalAmount' value='" . wpsc_cart_total(false) . "' />\n";
                            $output .= "\t<input type='hidden' name='shippingStreet' value='" . $resArray['SHIPTOSTREET'] . "' />\n";
                            $output .= "\t<input type='hidden' name='shippingStreet2' value='" . $resArray['SHIPTOSTREET2'] . "' />\n";
                            $output .= "\t<input type='hidden' name='shippingCity' value='" . $resArray['SHIPTOCITY'] . "' />\n";
                            $output .= "\t<input type='hidden' name='shippingState' value='" . $resArray['SHIPTOSTATE'] . "' />\n";
                            $output .= "\t<input type='hidden' name='postalCode' value='" . $resArray['SHIPTOZIP'] . "' />\n";
                            $output .= "\t<input type='hidden' name='country' value='" . $resArray['SHIPTOCOUNTRYNAME'] . "' />\n";
                            $output .= "\t<input type='hidden' name='token' value='" . wpsc_get_customer_meta('paypal_express_token') . "' />\n";
                            $output .= "\t<input type='hidden' name='PayerID' value='" . wpsc_get_customer_meta('paypal_express_payer_id') . "' />\n";
                            $output .= "\t<input type='hidden' name='act' value='do' />\n";
                            $output .= "\t<p>  <input name='usePayPal' type='submit' value='" . __('Confirm Payment', 'wpsc') . "' /></p>\n";
                            $output .= "</form>";
                            $output .= " </td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t</table>\n\t\t\t\t\t</center>\n\t\t\t\t\t";
                            wpsc_update_customer_meta('paypal_express_message', $output);
                        }
                    }
                }
            }
        }
    }
}
Пример #2
0
function nzshpcrt_chronopay_callback()
{
    global $wpdb;
    // needs to execute on page start
    // look at page 36
    if (isset($_GET['chronopay_callback']) && $_GET['chronopay_callback'] == 'true' && $_POST['cs2'] == 'chronopay') {
        // This is a call from chronopay.  validate that it is from a chronopay server in the and process.
        // validate cs3 variable to see if it makes sense for security
        $salt = get_option('chronopay_salt');
        $gen_hash = md5($salt . md5($_POST['cs1'] . $salt));
        if ($gen_hash == $_POST['cs3']) {
            // Added in to fake a TX number for testing.  ChronoPay dev accounts do not return a trans_id.
            //if($_POST['transaction_id'] == '')
            //	$_POST['transaction_id'] = 'testid123123';
            // process response.
            $sessionid = trim(stripslashes($_POST['cs1']));
            $transaction_id = trim(stripslashes($_POST['transaction_id']));
            $verification_data['trans_id'] = trim(stripslashes($_POST['transaction_id']));
            $verification_data['trans_type'] = trim(stripslashes($_POST['transaction_type']));
            switch ($verification_data['trans_type']) {
                case 'onetime':
                    // All successful processing statuses.
                // All successful processing statuses.
                case 'initial':
                case 'rebill':
                    $data = array('processed' => 2, 'transactid' => $transact_id, 'date' => time());
                    wpsc_update_purchase_log_details($sessionid, $data, 'sessionid');
                    transaction_results($sessionid, false, $transaction_id);
                    break;
                case 'decline':
                    // if it fails, delete it
                    $log_id = $wpdb->get_var($wpdb->prepare("SELECT `id` FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid`=%s LIMIT 1", $sessionid));
                    $delete_log_form_sql = $wpdb->prepare("SELECT * FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid`=%d", $log_id);
                    $cart_content = $wpdb->get_results($delete_log_form_sql, ARRAY_A);
                    foreach ((array) $cart_content as $cart_item) {
                        $cart_item_variations = $wpdb->query($wpdb->prepare("DELETE FROM `" . WPSC_TABLE_CART_ITEM_VARIATIONS . "` WHERE `cart_id` = %d", $cart_item['id']), ARRAY_A);
                    }
                    $wpdb->query($wpdb->prepare("DELETE FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid`=%d", $log_id));
                    $wpdb->query($wpdb->prepare("DELETE FROM `" . WPSC_TABLE_SUBMITTED_FORM_DATA . "` WHERE `log_id` IN ( %d )", $log_id));
                    $wpdb->query($wpdb->prepare("DELETE FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `id`=%d LIMIT 1", $log_id));
                    break;
                case 'Pending':
                    // need to wait for "Completed" before processing
                    $wpdb->update(WPSC_TABLE_PURCHASE_LOGS, array('transactid' => $transaction_id, 'date' => time()), array('sessionid' => $sessionid), array('%d', '%s'));
                    break;
                default:
                    // if nothing, do nothing, safest course of action here.
                    break;
            }
        } else {
            // Security Hash failed!!.. notify someone..
            $message = "This message has been sent because a call to your ChronoPay function was made by a server that did not have the correct security key.  This could mean someone is trying to hack your payment site.  The details of the call are below.\n\r\n\r";
            $message .= "OUR_POST:\n\r" . print_r($header . $req, true) . "\n\r\n\r";
            $message .= "THEIR_POST:\n\r" . print_r($_POST, true) . "\n\r\n\r";
            $message .= "GET:\n\r" . print_r($_GET, true) . "\n\r\n\r";
            $message .= "SERVER:\n\r" . print_r($_SERVER, true) . "\n\r\n\r";
            mail(get_option('purch_log_email'), "ChronoPay Security Key Failed!", $message);
        }
    }
}
	/**
	* submit to gateway
	*/
	public function submit() {
		global $wpdb;

		// check for missing or invalid values
		$errors = $this->validateData();

		// if there were errors, fail the transaction so that user can fix things up
		if ($errors) {
			$this->set_purchase_processed_by_purchid(1);	// failed
			//~ $this->go_to_transaction_results($this->cart_data['session_id']);
			return;
		}

		// get purchase logs
		if ($this->purchase_id > 0) {
			$purchase_logs = new WPSC_Purchase_Log($this->purchase_id);
		}
		elseif (!empty($this->session_id)) {
			$purchase_logs = new WPSC_Purchase_Log($this->session_id, 'sessionid');

			$this->purchase_id = $purchase_logs->get('id');
		}
		else {
			$this->set_error_message('No cart ID and no active session!');
			return;
		}

		// process the payment
		$isLiveSite = !get_option('eway_test');
		$useStored = get_option('wpsc_merchant_eway_stored');

		if ($useStored) {
			$eway = new EwayPaymentsStoredPayment(get_option('ewayCustomerID_id'), $isLiveSite);
		}
		else {
			$eway = new EwayPaymentsPayment(get_option('ewayCustomerID_id'), $isLiveSite);
		}

		$eway->invoiceDescription		= get_bloginfo('name');
		$eway->invoiceReference			= $this->purchase_id;								// customer invoice reference
		$eway->transactionNumber		= $this->purchase_id;								// transaction reference
		$eway->cardHoldersName			= $this->collected_gateway_data['card_name'];
		$eway->cardNumber				= $this->collected_gateway_data['card_number'];
		$eway->cardExpiryMonth			= $this->collected_gateway_data['expiry_month'];
		$eway->cardExpiryYear			= $this->collected_gateway_data['expiry_year'];
		$eway->cardVerificationNumber	= $this->collected_gateway_data['c_v_n'];
		$eway->firstName				= $this->collected_gateway_data['first_name'];
		$eway->lastName					= $this->collected_gateway_data['last_name'];
		$eway->emailAddress				= $this->collected_gateway_data['email'];
		$eway->postcode					= $this->collected_gateway_data['post_code'];

		// for Beagle (free) security
		if (get_option('wpsc_merchant_eway_beagle')) {
			$eway->customerCountryCode	= $this->collected_gateway_data['country'];
		}

		// convert wp-e-commerce country code into country name
		$country = $this->collected_gateway_data['country'] ? wpsc_get_country($this->collected_gateway_data['country']) : '';

		// aggregate street, city, state, country into a single string
		$parts = array (
			$this->collected_gateway_data['address'],
			$this->collected_gateway_data['city'],
			$this->collected_gateway_data['state'],
			$country,
		);
		$eway->address					= implode(', ', array_filter($parts, 'strlen'));

		// use cardholder name for last name if no customer name entered
		if (empty($eway->firstName) && empty($eway->lastName)) {
			$eway->lastName				= $eway->cardHoldersName;
		}

		// allow plugins/themes to modify invoice description and reference, and set option fields
		$eway->invoiceDescription		= apply_filters('wpsc_merchant_eway_invoice_desc', $eway->invoiceDescription, $this->purchase_id);
		$eway->invoiceReference			= apply_filters('wpsc_merchant_eway_invoice_ref', $eway->invoiceReference, $this->purchase_id);
		$eway->option1					= apply_filters('wpsc_merchant_eway_option1', '', $this->purchase_id);
		$eway->option2					= apply_filters('wpsc_merchant_eway_option2', '', $this->purchase_id);
		$eway->option3					= apply_filters('wpsc_merchant_eway_option3', '', $this->purchase_id);

		// if live, pass through amount exactly, but if using test site, round up to whole dollars or eWAY will fail
		$total = $purchase_logs->get('totalprice');
		$eway->amount					= $isLiveSite ? $total : ceil($total);

		try {
			$response = $eway->processPayment();

			if ($response->status) {
				// transaction was successful, so record transaction number and continue
				if ($useStored) {
					$status = 2; // WPSC_Purchase_Log::ORDER_RECEIVED
				}
				else {
					$status = 3; // WPSC_Purchase_Log::ACCEPTED_PAYMENT
				}
				$log_details = array(
					'processed'			=> $status,
					'transactid'		=> $response->transactionNumber,
					'authcode'			=> $response->authCode,
				);

				if (!empty($response->beagleScore)) {
					$log_details['notes'] = 'Beagle score: ' . $response->beagleScore;
				}

				wpsc_update_purchase_log_details($this->purchase_id, $log_details);

				$this->go_to_transaction_results($this->cart_data['session_id']);
			}
			else {
				// transaction was unsuccessful, so record transaction number and the error
				$status = 6; // WPSC_Purchase_Log::PAYMENT_DECLINED
				$this->set_error_message(nl2br(esc_html($response->error)));

				$log_details = array(
					'processed'			=> $status,
					'notes'				=> $response->error,
				);
				wpsc_update_purchase_log_details($this->purchase_id, $log_details);

				return;
			}
		}
		catch (EwayPaymentsException $e) {
			// an exception occured, so record the error
			$status = 1; // WPSC_Purchase_Log::INCOMPLETE_SALE
			$this->set_error_message(nl2br(esc_html($e->getMessage())));
			$this->set_purchase_processed_by_purchid($status);
			return;
		}

	 	exit();
	}
Пример #4
0
 /**
  * set_transaction_details, maybe extended in merchant files
  */
 function set_transaction_details($transaction_id, $status = 1)
 {
     wpsc_update_purchase_log_details($this->purchase_id, array('processed' => $status, 'transactid' => $transaction_id));
 }
function gourlwpecommerce_gourlcallback($user_id, $order_id, $payment_details, $box_status)
{
    global $wpdb, $wpsc_merchant;
    if (!in_array($box_status, array("cryptobox_newrecord", "cryptobox_updated"))) {
        return false;
    }
    if (strpos($order_id, "order") === 0) {
        $order_id = intval(substr($order_id, 5));
    } else {
        return false;
    }
    if (!$user_id || $payment_details["status"] != "payment_received") {
        return false;
    }
    $sql = 'SELECT * FROM `' . WPSC_TABLE_PURCHASE_LOGS . '` WHERE id = ' . $order_id . ' LIMIT 1';
    $arr = $wpdb->get_row($sql, ARRAY_A);
    if (!$arr) {
        return false;
    }
    // Initialize
    $statuses = array(2 => 'Order Received', 3 => 'Accepted Payment', 4 => 'Job Dispatched', 5 => 'Closed Order');
    $ostatus = get_option(GOURLWPSC . 'ostatus');
    if (!in_array($ostatus, array_keys($statuses))) {
        $ostatus = 3;
    }
    // Accepted Payment
    $ostatus2 = get_option(GOURLWPSC . 'ostatus2');
    if (!in_array($ostatus2, array_keys($statuses))) {
        $ostatus2 = 3;
    }
    // Accepted Payment
    $coinName = ucfirst($payment_details["coinname"]);
    $amount = $payment_details["amount"] . " " . $payment_details["coinlabel"] . "&#160; ( \$" . $payment_details["amountusd"] . " )";
    $payID = $payment_details["paymentID"];
    $trID = $payment_details["tx"];
    $status = $payment_details["is_confirmed"] ? $ostatus2 : $ostatus;
    $confirmed = $payment_details["is_confirmed"] ? __('Yes', GOURLWPSC) : __('No', GOURLWPSC);
    // New Payment Received
    if ($box_status == "cryptobox_newrecord") {
        wpsc_gourl_gateway::add_order_note($order_id, sprintf(__('<b>%s</b> payment received<br>%s<br>Payment <a href="%s">id %s</a>. Awaiting network confirmation...' . ($arr["processed"] != $status ? '<br>Order status changed to: %s' : ''), GOURLWPSC), $coinName, $amount, GOURL_ADMIN . GOURL . "payments&s=payment_" . $payID, $payID, $statuses[$status]));
    }
    // Existing Payment confirmed (6+ confirmations)
    if ($payment_details["is_confirmed"]) {
        wpsc_gourl_gateway::add_order_note($order_id, sprintf(__('%s Payment id <a href="%s">%s</a> Confirmed' . ($arr["processed"] != $status ? '<br>Order status changed to: %s' : ''), GOURLWPSC), $coinName, GOURL_ADMIN . GOURL . "payments&s=payment_" . $payID, $payID, $statuses[$status]));
    }
    // Update Order Status
    wpsc_update_purchase_log_status($order_id, $status);
    wpsc_update_purchase_log_details($order_id, array('transactid' => $trID));
    // WP eCommerce not use new updated order status, therefore need to refresh page manually
    if (in_array($status, array(3, 4, 5)) && !in_array($arr["processed"], array(3, 4, 5)) && !stripos($_SERVER["REQUEST_URI"], "cryptobox.callback.php")) {
        header('Location: ' . $_SERVER["REQUEST_URI"]);
        echo "<script>window.location.href = '" . $_SERVER["REQUEST_URI"] . "';</script>";
        die;
    }
    return true;
}