/** * Adds product properties to analytics.track() when the order is completed successfully. * * @since 1.0.0 * @access public * * @uses func_get_args() Because our abstract class doesn't know how many parameters are passed to each hook * for each different platform, we use func_get_args(). * * @return array Filtered array of name and properties for analytics.track(). */ public function completed_order() { $args = func_get_args(); $track = $args[0]; if (did_action('wpsc_transaction_results_shutdown') && isset($_GET['sessionid'])) { $log = new WPSC_Purchase_Log($_GET['sessionid'], 'sessionid'); /* We like checking is_order_received(), as that's what the manual payment gateway uses. */ if ($log->is_transaction_completed() || $log->is_order_received()) { $gateway_data = $log->get_gateway_data(); $items = $log->get_cart_contents(); $products = array(); foreach ($items as $item) { $product = array('id' => $item->prodid, 'sku' => wpsc_product_sku($item->prodid), 'name' => $item->name, 'price' => $item->price, 'quantity' => $item->quantity, 'category' => implode(', ', wp_list_pluck(wpsc_get_product_terms($item->prodid, 'wpsc_product_category'), 'name'))); $products[] = $product; } $track = array('event' => __('Completed Order', 'segment'), 'properties' => array('id' => $log->get('id'), 'total' => $log->get('totalprice'), 'revenue' => $gateway_data['subtotal'], 'shipping' => $gateway_data['shipping'], 'tax' => $gateway_data['tax'], 'products' => $products)); } } return $track; }
function gateway_bitpay($seperator, $sessionid) { global $wpdb; global $wpsc_cart; try { // Protect your data! $mcrypt_ext = new \Bitpay\Crypto\McryptExtension(); $fingerprint = substr(sha1(sha1(__DIR__)), 0, 24); //Use token that is in_use and with facade = pos for generating invoices $is_a_token_paired = $wpdb->get_var("SELECT COUNT(*) FROM " . $wpdb->prefix . "bitpay_keys WHERE `in_use` = 'true' AND `facade` = 'pos' LIMIT 1"); if ($is_a_token_paired < 1) { debuglog('[Error] In Bitpay plugin, bitpay.merchant.php::gateway_bitpay(): No tokens are paired so no transactions can be done!'); var_dump("Error Processing Transaction. Please try again later. If the problem persists, please contact us at " . get_option('admin_email')); } $row = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "bitpay_keys WHERE `in_use` = 'true' AND `facade` = 'pos' LIMIT 1"); $token = unserialize(base64_decode($mcrypt_ext->decrypt($row[0]->token, $fingerprint, '00000000'))); $public_key = unserialize(base64_decode($mcrypt_ext->decrypt($row[0]->public_key, $fingerprint, '00000000'))); $private_key = unserialize(base64_decode($mcrypt_ext->decrypt($row[0]->private_key, $fingerprint, '00000000'))); $network = $row[0]->network === 'Livenet' ? new \Bitpay\Network\Livenet() : new \Bitpay\Network\Testnet(); $row_id = $row[0]->id; $adapter = new \Bitpay\Client\Adapter\CurlAdapter(); // This grabs the purchase log id from // the database that refers to the $sessionid $purchase_log = $wpdb->get_row("SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid`= " . $sessionid . " LIMIT 1", ARRAY_A); // This grabs the users info using the // $purchase_log from the previous SQL query $usersql = "SELECT `" . WPSC_TABLE_SUBMITED_FORM_DATA . "`.value," . "`" . WPSC_TABLE_CHECKOUT_FORMS . "`.`name`," . "`" . WPSC_TABLE_CHECKOUT_FORMS . "`.`unique_name` FROM " . "`" . WPSC_TABLE_CHECKOUT_FORMS . "` LEFT JOIN " . "`" . WPSC_TABLE_SUBMITED_FORM_DATA . "` ON " . "`" . WPSC_TABLE_CHECKOUT_FORMS . "`.id = " . "`" . WPSC_TABLE_SUBMITED_FORM_DATA . "`.`form_id` WHERE " . "`" . WPSC_TABLE_SUBMITED_FORM_DATA . "`.`log_id`='" . $purchase_log['id'] . "'"; $userinfo = $wpdb->get_results($usersql, ARRAY_A); // convert from awkward format $ui = array(); foreach ((array) $userinfo as $value) { if (strlen($value['value'])) { $ui[$value['unique_name']] = $value['value']; } } $userinfo = $ui; /** * Create Buyer object that will be used later. */ $buyer = new \Bitpay\Buyer(); // name if (true === isset($userinfo['billingfirstname'])) { $buyer->setFirstName($userinfo['billingfirstname']); } if (true === isset($userinfo['billinglastname'])) { $buyer->setLastName($userinfo['billinglastname']); } // address -- remove newlines if (true === isset($userinfo['billingaddress'])) { $newline = strpos($userinfo['billingaddress'], "\n"); $address2 = ''; if ($newline !== FALSE) { $address_line1 = substr($userinfo['billingaddress'], 0, $newline); $address_line2 = substr($userinfo['billingaddress'], $newline + 1); $address_line2 = preg_replace('/\\r\\n/', ' ', $address_line2, -1, $count); } else { $address_line1 = $userinfo['billingaddress']; } $buyer->setAddress(array($address_line1, $address_line2)); } // state if (true === isset($userinfo['billingstate'])) { // check if State is a number code used when Selecting country as US if (true === ctype_digit($userinfo['billingstate'])) { $buyer->setState(wpsc_get_state_by_id($userinfo['billingstate'], 'code')); } else { $buyer->setState($userinfo['billingstate']); } } // country if (true === isset($userinfo['billingcountry'])) { $buyer->setCountry($userinfo['billingcountry']); } // city if (true === isset($userinfo['billingcity'])) { $buyer->setCity($userinfo['billingcity']); } // postal code if (true === isset($userinfo['billingpostcode'])) { $buyer->setZip($userinfo['billingpostcode']); } // email if (true === isset($userinfo['billingemail'])) { $buyer->setEmail($userinfo['billingemail']); } // phone if (true === isset($userinfo['billingphone'])) { $buyer->setPhone($userinfo['billingphone']); } // more user info foreach (array('billingphone' => 'buyerPhone', 'billingemail' => 'buyerEmail', 'billingcity' => 'buyerCity', 'billingcountry' => 'buyerCountry', 'billingpostcode' => 'buyerZip') as $f => $t) { if ($userinfo[$f]) { $options[$t] = $userinfo[$f]; } } /** * Create an Item object that will be used later */ $item = new \Bitpay\Item(); // itemDesc, Sku, and Quantity if (count($wpsc_cart->cart_items) == 1) { $item_incart = $wpsc_cart->cart_items[0]; $item_id = $item_incart->product_id; $item_sku = wpsc_product_sku($item_id); $item_description = $item_incart->quantity > 1 ? $item_incart->quantity . ' x ' . $item_incart->product_name : $item_incart->product_name; } else { foreach ($wpsc_cart->cart_items as $item_incart) { $quantity += $item_incart->quantity; $item_id = $item_incart->product_id; $item_sku_individual = wpsc_product_sku($item_id); $item_sku .= $item_incart->quantity . ' x ' . $item_sku_individual . ' '; } $item_description = $quantity . ' items'; } // price $price = number_format($wpsc_cart->total_price, 2, '.', ''); $item->setDescription($item_description)->setCode($item_sku)->setPrice($price); // Create new BitPay invoice $invoice = new \Bitpay\Invoice(); // Add the item to the invoice $invoice->setItem($item); // Add the buyers info to invoice $invoice->setBuyer($buyer); // Configure the rest of the invoice $purchase_log = $wpdb->get_row("SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid`= " . $sessionid . " LIMIT 1", ARRAY_A); $invoice->setOrderId($purchase_log['id'])->setNotificationUrl(get_option('siteurl') . '/?bitpay_callback=true'); /** * BitPay offers services for many different currencies. You will need to * configure the currency in which you are selling products with. */ $currency = new \Bitpay\Currency(); $currencyId = get_option('currency_type'); $currency_code = $wpdb->get_var($wpdb->prepare("SELECT `code` FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `id` = %d LIMIT 1", $currencyId)); $currency->setCode($currency_code); // Set the invoice currency $invoice->setCurrency($currency); // Transaction Speed $invoice->setTransactionSpeed(get_option('bitpay_transaction_speed')); // Redirect URL $separator = get_option('permalink_structure') != '' ? '?' : '&'; if (true === is_null(get_option('bitpay_redirect'))) { update_option('bitpay_redirect', get_site_url()); } $redirect_url = get_option('bitpay_redirect'); $invoice->setRedirectUrl($redirect_url); // PosData $invoice->setPosData($sessionid); // Full Notifications $invoice->setFullNotifications(true); /** * Create the client that will be used * to send requests to BitPay's API */ $client = new \Bitpay\Client\Client(); $client->setAdapter($adapter); $client->setNetwork($network); $client->setPrivateKey($private_key); $client->setPublicKey($public_key); /** * You will need to set the token that was * returned when you paired your keys. */ $client->setToken($token); $transaction = true; // Send invoice try { $client->createInvoice($invoice); } catch (\Exception $e) { debuglog('[Error] In Bitpay plugin, bitpay.merchant.php::gateway_bitpay(): Call to createInvoice() failed with the message: ' . $e->getMessage()); var_dump("Error Processing Transaction. Please try again later. If the problem persists, please contact us at " . get_option('admin_email')); $transaction = false; } if (true === $transaction) { $sql = "UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET `notes`= 'The payment has not been received yet.' WHERE `sessionid`=" . $sessionid; $wpdb->query($sql); $wpsc_cart->empty_cart(); unset($_SESSION['WpscGatewayErrorMessage']); header('Location: ' . $invoice->getUrl()); } exit; } catch (\Exception $e) { debuglog('[Error] In Bitpay plugin, form_bitpay() function on line ' . $e->getLine() . ', with the error "' . $e->getMessage() . '" .'); throw $e; } }
<div class="detail_form_content"> <div class="form_outer"> <?php echo do_shortcode('[contact-form-7 id="236" title="detail product"]'); ?> </div> </div> </div> </div> <!-- form end --> <?php $url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; ?> <form> <input type="hidden" id="car" value="<?php echo wpsc_product_sku(wpsc_the_product_id()); ?> "/> <input type="hidden" id="pro_url" value="<?php echo $url; ?> "/> </form> <script> $(window).load(function() { document.getElementById('hidden_carid').value = document.getElementById('car').value document.getElementById('url').value = document.getElementById('pro_url').value $("#pro_form").css("display","none"); $(".hide").css("display","none"); });