public function getData() { switch ($this->status_uid) { case 'people_signup_200' || 'people_verifyaddress_200': // successful submit, return messaging and optionally an asset link $show_final_message = true; if ($this->status_uid == 'people_signup_200' && !$this->options['do_not_verify']) { // if this is a first submit and we're verifying the email, first check to see if it's been verified already $verification_request = new CASHRequest(array('cash_request_type' => 'people', 'cash_action' => 'checkverification', 'address' => $this->original_response['payload']['address'], 'list_id' => $this->options['email_list_id'])); if (!$verification_request->response['payload']) { // not verified, so do not show the final message, and instead give a "you must verify" jam $show_final_message = false; $this->setTemplate('mustverify'); } } if ($show_final_message) { $all_friends = array($this->original_request['friend1'], $this->original_request['friend2'], $this->original_request['friend3']); if (!empty($this->original_request['main_name'])) { $from_name = $this->original_request['main_name']; } else { $from_name = $this->original_request['address']; } if (!empty($this->options['email_html_message'])) { $html_message = str_replace('</body>', '<br /><br /><br /><small>This e-card was sent from <a href="' . CASHSystem::getCurrentURL() . '">' . CASHSystem::getCurrentURL() . '</a></small></body>', $this->options['email_html_message']); } else { $html_message = false; } foreach ($all_friends as $friend) { if (filter_var($friend, FILTER_VALIDATE_EMAIL)) { CASHSystem::sendEmail(trim($this->options['email_subject']) . ' ' . $from_name, CASHSystem::getDefaultEmail(), $friend, $this->options['email_message'] . "\n\n\nThis e-card was sent from " . CASHSystem::getCurrentURL(), '', $html_message); } } if ($this->options['asset_id'] != 0) { // first we "unlock" the asset, telling the platform it's okay to generate a link for non-private assets $unlock_request = new CASHRequest(array('cash_request_type' => 'asset', 'cash_action' => 'unlock', 'id' => $this->options['asset_id'])); // next we make the link $asset_request = new CASHRequest(array('cash_request_type' => 'asset', 'cash_action' => 'getasset', 'id' => $this->options['asset_id'])); $this->element_data['asset_title'] = $asset_request->response['payload']['title']; $this->element_data['asset_description'] = $asset_request->response['payload']['description']; } $this->setTemplate('success'); } break; case 'people_signup_400': // error, likely in the email format. error message + default form $this->element_data['error_message'] = $this->options['message_invalid_email']; break; } return $this->element_data; }
/** * Records the basic access data to the elements analytics table * * @return boolean */ protected function recordAnalytics($id, $access_method, $access_action = 'getmarkup', $access_data = '') { $ip_and_proxy = CASHSystem::getRemoteIP(); $already_recorded = false; // first check and see if we've recorded this session and circumstance yet // only do this for empty lock_method_table queries so we don't repeat // unnecessary rows and overwhelm the table if ($access_action == 'getmarkup') { $already_recorded = $this->db->getData('elements_analytics', 'id', array("element_id" => array("condition" => "=", "value" => $id), "access_method" => array("condition" => "=", "value" => $access_method), "access_location" => array("condition" => "=", "value" => CASHSystem::getCurrentURL()), "cash_session_id" => array("condition" => "=", "value" => $this->getCASHSessionID()), "client_ip" => array("condition" => "=", "value" => $ip_and_proxy['ip']), "client_proxy" => array("condition" => "=", "value" => $ip_and_proxy['proxy']))); } if (!$already_recorded) { $result = $this->db->setData('elements_analytics', array('element_id' => $id, 'access_method' => $access_method, 'access_location' => CASHSystem::getCurrentURL(), 'access_action' => $access_action, 'access_data' => $access_data, 'access_time' => time(), 'client_ip' => $ip_and_proxy['ip'], 'client_proxy' => $ip_and_proxy['proxy'], 'cash_session_id' => $this->getCASHSessionID())); return $result; } else { return true; } }
protected function startJSSession() { $r = new CASHRequest(); $session_details = $r->startSession(); if ($session_details['newsession']) { $endpoint = explode('/', CASHSystem::getCurrentURL(), 4); unset($endpoint[3]); $endpoint = join('/', $endpoint); if (!$session_details['expiration']) { $session_details['expiration'] = time() + 10800; } return json_encode(array('endpoint' => $endpoint, 'expiration' => $session_details['expiration'], 'id' => $session_details['id'])); } else { return ''; } }
protected function sendOrderReceipt($id = false, $order_details = false, $finalize_url = false) { if (!$id && !$order_details) { return false; } if (!$order_details) { $order_details = $this->getOrder($id, true); } $order_totals = $this->getOrderTotals($order_details['order_contents']); try { $personalized_message = ''; if ($order_details['element_id']) { $element_request = new CASHRequest(array('cash_request_type' => 'element', 'cash_action' => 'getelement', 'id' => $order_details['element_id'])); if ($element_request->response['payload']) { if (isset($element_request->response['payload']['options']['message_email'])) { if ($element_request->response['payload']['options']['message_email']) { $personalized_message = $element_request->response['payload']['options']['message_email'] . "\n\n"; } } } } if ($order_details['digital']) { $addcode_request = new CASHRequest(array('cash_request_type' => 'element', 'cash_action' => 'addlockcode', 'element_id' => $order_details['element_id'])); if (!$finalize_url) { $finalize_url = CASHSystem::getCurrentURL(); } return CASHSystem::sendEmail('Thank you for your order', $order_details['user_id'], $order_details['customer_details']['email_address'], $personalized_message . "Your order is complete. Here are some details:\n\n**Order #" . $order_details['id'] . "** \n" . $order_totals['description'] . " \n Total: " . CASHSystem::getCurrencySymbol($order_details['currency']) . number_format($order_details['gross_price'], 2) . "\n\n" . "\n\n" . '[View your receipt and any downloads](' . $finalize_url . '?cash_request_type=element&cash_action=redeemcode&code=' . $addcode_request->response['payload'] . '&element_id=' . $order_details['element_id'] . '&email=' . urlencode($order_details['customer_details']['email_address']) . '&order_id=' . $order_details['id'] . ')', 'Thank you.'); } else { return CASHSystem::sendEmail('Thank you for your order', $order_details['user_id'], $order_details['customer_details']['email_address'], $personalized_message . "Your order is complete. Here are some details:\n\n**Order #" . $order_details['id'] . "** \n" . $order_totals['description'] . " \n Total: " . CASHSystem::getCurrencySymbol($order_details['currency']) . number_format($order_details['gross_price'], 2) . "\n\n", 'Thank you.'); } } catch (Exception $e) { // TODO: handle the case where an email can't be sent. maybe display the download // code on-screen? that plus storing it with the order is probably enough return false; } }
protected function finalizeRedirectedPayment($order_id, $creation_date, $direct_post_details = false, $session_id = false) { $order_details = $this->getOrder($order_id); $transaction_details = $this->getTransaction($order_details['transaction_id']); $connection_type = $this->getConnectionType($transaction_details['connection_id']); $r = new CASHRequest(); $r->startSession(false, $session_id); $finalize_url = $r->sessionGet('payment_finalize_url'); if ($finalize_url) { $r->sessionClear('payment_finalize_url'); } switch ($connection_type) { case 'com.paypal': if (isset($_GET['token'])) { if (isset($_GET['PayerID'])) { $pp = new PaypalSeed($order_details['user_id'], $transaction_details['connection_id'], $_GET['token']); $initial_details = $pp->getExpressCheckout(); if ($initial_details['ACK'] == 'Success') { $order_totals = $this->getOrderTotals($order_details['order_contents']); if ($initial_details['AMT'] >= $order_totals['price']) { $final_details = $pp->doExpressCheckout(); if ($final_details) { // look for a user to match the email. if not present, make one $user_request = new CASHRequest(array('cash_request_type' => 'people', 'cash_action' => 'getuseridforaddress', 'address' => $initial_details['EMAIL'])); $user_id = $user_request->response['payload']; if (!$user_id) { $user_request = new CASHRequest(array('cash_request_type' => 'system', 'cash_action' => 'addlogin', 'address' => $initial_details['EMAIL'], 'password' => time(), 'is_admin' => 0, 'display_name' => $initial_details['FIRSTNAME'] . ' ' . $initial_details['LASTNAME'], 'first_name' => $initial_details['FIRSTNAME'], 'last_name' => $initial_details['LASTNAME'], 'address_country' => $initial_details['COUNTRYCODE'])); $user_id = $user_request->response['payload']; } // deal with physical quantities if ($order_details['physical'] == 1) { $order_items = json_decode($order_details['order_contents'], true); if (is_array($order_items)) { foreach ($order_items as $i) { if ($i['available_units'] > 0 && $i['physical_fulfillment'] == 1) { $item = $this->getItem($i['id']); if ($i['variant']) { $variant_id = 0; $variant_qty = 0; if ($item['variants']) { foreach ($item['variants']['quantities'] as $q) { if ($q['key'] == $i['variant']) { $variant_id = $q['id']; $variant_qty = $q['value']; break; } } if ($variant_id) { $this->editItemVariant($variant_id, max($variant_qty - $i['qty'], 0), $i['id']); } } } else { $available_units = $this->editItem($i['id'], false, false, false, false, false, max($item['available_units'] - $i['qty'], 0)); } } } } } // record all the details if ($order_details['digital'] == 1 && $order_details['physical'] == 0) { // if the order is 100% digital just mark it as fulfilled $is_fulfilled = 1; } else { // there's something physical. sorry dude. gotta deal with it still. $is_fulfilled = 0; } $this->editOrder($order_id, $is_fulfilled, 0, false, $initial_details['COUNTRYCODE'], $user_id); $this->editTransaction($order_details['transaction_id'], strtotime($final_details['TIMESTAMP']), $final_details['CORRELATIONID'], json_encode($initial_details), json_encode($final_details), 1, $final_details['PAYMENTINFO_0_AMT'], $final_details['PAYMENTINFO_0_FEEAMT'], 'complete'); // empty the cart at this point $this->emptyCart($session_id); // TODO: add code to order metadata // bit of a hack, hard-wiring the email bits: try { $personalized_message = ''; if ($order_details['element_id']) { $element_request = new CASHRequest(array('cash_request_type' => 'element', 'cash_action' => 'getelement', 'id' => $order_details['element_id'])); if ($element_request->response['payload']) { if (isset($element_request->response['payload']['options']['message_email'])) { if ($element_request->response['payload']['options']['message_email']) { $personalized_message = $element_request->response['payload']['options']['message_email'] . "\n\n"; } } } } if ($order_details['digital']) { $addcode_request = new CASHRequest(array('cash_request_type' => 'element', 'cash_action' => 'addlockcode', 'element_id' => $order_details['element_id'])); if (!$finalize_url) { $finalize_url = CASHSystem::getCurrentURL(); } CASHSystem::sendEmail('Thank you for your order', $order_details['user_id'], $initial_details['EMAIL'], $personalized_message . "Your order is complete. Here are some details:\n\n**Order #" . $order_details['id'] . "** \n" . $initial_details['PAYMENTREQUEST_0_DESC'] . " \n Total: " . CASHSystem::getCurrencySymbol($order_details['currency']) . number_format($final_details['PAYMENTINFO_0_AMT'], 2) . "\n\n" . "\n\n" . '[View your receipt and any downloads](' . $finalize_url . '?cash_request_type=element&cash_action=redeemcode&code=' . $addcode_request->response['payload'] . '&element_id=' . $order_details['element_id'] . '&email=' . urlencode($initial_details['EMAIL']) . '&order_id=' . $order_details['id'] . ')', 'Thank you.'); } else { CASHSystem::sendEmail('Thank you for your order', $order_details['user_id'], $initial_details['EMAIL'], $personalized_message . "Your order is complete. Here are some details:\n\n**Order #" . $order_details['id'] . "** \n" . $initial_details['PAYMENTREQUEST_0_DESC'] . " \n Total: " . CASHSystem::getCurrencySymbol($order_details['currency']) . number_format($final_details['PAYMENTINFO_0_AMT'], 2) . "\n\n", 'Thank you.'); } } catch (Exception $e) { // TODO: handle the case where an email can't be sent. maybe display the download // code on-screen? that plus storing it with the order is probably enough } return $order_details['id']; } else { // make sure this isn't an accidentally refreshed page if ($initial_details['CHECKOUTSTATUS'] != 'PaymentActionCompleted') { $initial_details['ERROR_MESSAGE'] = $pp->getErrorMessage(); // there was an error processing the transaction $this->editOrder($order_id, 0, 1); $this->editTransaction($order_details['transaction_id'], strtotime($initial_details['TIMESTAMP']), $initial_details['CORRELATIONID'], false, json_encode($initial_details), 0, false, false, 'error processing payment'); return false; } else { // this is a successful transaction with the user hitting refresh // as long as it's within 30 minutes of the original return true, otherwise // call it false and allow the page to expire if (time() - strtotime($initial_details['TIMESTAMP']) < 180) { return true; } else { return false; } } } } else { // insufficient funds — user changed amount? $this->editOrder($order_id, 0, 1); $this->editTransaction($order_details['transaction_id'], strtotime($initial_details['TIMESTAMP']), $initial_details['CORRELATIONID'], false, json_encode($initial_details), 0, false, false, 'incorrect amount'); return false; } } else { // order reporting failure $this->editOrder($order_id, 0, 1); $this->editTransaction($order_details['transaction_id'], strtotime($initial_details['TIMESTAMP']), $initial_details['CORRELATIONID'], false, json_encode($initial_details), 0, false, false, 'payment failed'); return false; } } else { // user canceled transaction $this->editOrder($order_id, 0, 1); $this->editTransaction($order_details['transaction_id'], time(), false, false, false, 0, false, false, 'canceled'); return false; } } break; default: return false; } }
public static function getBrowserIdStatus($assertion, $return_details = false) { if (!$assertion) { return false; } else { $post_data = array('assertion' => $assertion, 'audience' => CASHSystem::getCurrentURL(true)); $status = json_decode(CASHSystem::getURLContents('https://browserid.org/verify', $post_data, true), true); if ($return_details || !$status) { return $status; } else { if ($status['status'] == 'okay') { return $status['email']; } else { return false; } } } }
/** * Adds a user to a list. If no user exists for the email address passed, a * new user will be created then added to the list. * * @param {string} $address - the email address in question * @param {int} $list_id - the id of the list * @param {bool} $verified - 0 for unverified, 1 to skip verification and mark ok * @param {string} $initial_comment - a comment passed with the list signup * @param {string} $additional_data - any extra data (JSON, etc) a dev might pass with signup for later use * @param {string} $name - if the user doesn't exist in the system this will be used as their display name * @return bool */ protected function addAddress($address, $list_id, $do_not_verify = false, $initial_comment = '', $additional_data = '', $name = 'Anonymous', $force_verification_url = false, $request_from_service = false, $service_opt_in = true, $extra_querystring = '', $first_name = '', $last_name = '', $additional_data = '') { if (filter_var($address, FILTER_VALIDATE_EMAIL)) { // first check to see if the email is already on the list $take_action = false; $user_id = $this->getUserIDForAddress($address); if ($user_id) { $user_info = $this->getAddressListInfo($address, $list_id); if (!$user_info) { $take_action = 'addandemail'; } else { if (!$user_info['verified']) { $take_action = 'onlyemail'; } } } else { $take_action = 'addandemail'; } if ($take_action) { $initial_comment = strip_tags($initial_comment); $name = strip_tags($name); //$user_id = $this->getUserIDForAddress($address); if (!$user_id) { if ($name = 'Anonymous' && (!empty($first_name) || !empty($last_name))) { $name = trim($first_name . ' ' . $last_name); } $addlogin_request = new CASHRequest(array('cash_request_type' => 'system', 'cash_action' => 'addlogin', 'address' => $address, 'password' => md5(rand(23456, 9876541)), 'display_name' => $name, 'first_name' => $first_name, 'last_name' => $last_name)); if ($addlogin_request->response['status_code'] == 200) { $user_id = $addlogin_request->response['payload']; } else { return false; } } if ($user_id) { if ($take_action != 'onlyemail') { $result = $this->db->setData('list_members', array('user_id' => $user_id, 'list_id' => $list_id, 'initial_comment' => $initial_comment, 'additional_data' => $additional_data, 'verified' => 0, 'active' => 1)); } else { $result = true; } if ($result && !$request_from_service) { if ($do_not_verify) { $api_connection = $this->getConnectionAPI($list_id); if ($api_connection) { // connection found, api instantiated switch ($api_connection['connection_type']) { case 'com.mailchimp': $mc = $api_connection['api']; // mailchimp found. subscribe user and request opt-in // error_log(json_encode($mc)); $rc = $mc->listSubscribe($address, array('double_optin' => $service_opt_in)); // error_log(json_encode($rc)); break; } } } else { $list_details = $this->getList($list_id); $verification_code = $this->setAddressVerification($address, $list_id); $verification_url = $force_verification_url; if (!$verification_url) { $verification_url = CASHSystem::getCurrentURL(); } $verification_url .= '?cash_request_type=people&cash_action=verifyaddress&address=' . urlencode($address) . '&list_id=' . $list_id . '&verification_code=' . $verification_code . $extra_querystring; CASHSystem::sendEmail('Complete sign-up for: ' . $list_details['name'], $list_details['user_id'], $address, 'You requested to join the ' . $list_details['name'] . ' list. If this message has been sent in error ignore it.' . 'To complete your sign-up: ' . "\n\n [Verify your email address](" . $verification_url . ") \n\nNote to iOS users: you can only download on your computers, then sync to your device. Downloads will not work if on your iPhone or iPad.", 'Please confirm your membership'); } } return $result; } } else { // address already present, do nothing but return true return true; } } return false; }
public function getMarkup() { // define $markup to store all screen output $markup = ''; // the default form and basic elements: $default_markup = '<p class="cash_element_intro">' . $this->options->message_instructions . '</p>'; if (!empty($this->options->image_url)) { $default_markup .= '<img src="' . $this->options->image_url . '" alt="E-Card" class="cash_image_ecard" />'; } $default_markup .= '<form id="cash_' . self::type . '_form_' . $this->element_id . '" class="cash_form ' . self::type . '" method="post" action="">' . '<div class="cash_main_name_container"><label for="address">Your Name: (The \'from\' for the card)</label>' . '<input type="text" name="main_name" value="" class="cash_input cash_input_address cash_main_name" /></div>' . '<div class="cash_main_address_container"><label for="address">Your Email:</label>' . '<input type="email" name="address" value="" class="cash_input cash_input_address cash_main_address" /></div>' . '<div class="cash_friends">' . '<label for="address">Email Addresses For Up To 3 Friends:</label>' . '<input type="email" name="friend1" value="" class="cash_input cash_input_address cash_friend_address1" />' . '<input type="email" name="friend2" value="" class="cash_input cash_input_address cash_friend_address2" />' . '<input type="email" name="friend3" value="" class="cash_input cash_input_address cash_friend_address3" />' . '</div>' . '<input type="hidden" name="cash_request_type" value="people" />' . '<input type="hidden" name="cash_action" value="signup" />' . '<input type="hidden" name="list_id" value="' . $this->options->email_list_id . '" class="cash_input cash_input_list_id" />' . '<input type="hidden" name="element_id" value="' . $this->element_id . '" class="cash_input cash_input_element_id" />' . '<input type="hidden" name="comment" value="" class="cash_input cash_input_comment" />' . '<input type="submit" value="send the cards" class="button" /><br />' . '</form>'; switch ($this->status_uid) { case 'people_signup_200' || 'people_verifyaddress_200': // successful submit, return messaging and optionally an asset link $markup = '<div class="cash_success ' . self::type . '">'; $show_final_message = true; if ($this->status_uid == 'people_signup_200' && !$this->options->do_not_verify) { // if this is a first submit and we're verifying the email, first check to see if it's been verified already $verification_request = new CASHRequest(array('cash_request_type' => 'people', 'cash_action' => 'checkverification', 'address' => $this->original_response['payload']['address'], 'list_id' => $this->options->email_list_id)); if (!$verification_request->response['payload']) { // not verified, so do not show the final message, and instead give a "you must verify" jam $show_final_message = false; $markup .= 'You must verify your email address to continue. An email has been sent. Click the link provided and you will be brought back here.<br /><br />(If you do not see the message, check your SPAM folder.)'; } } if ($show_final_message) { $all_friends = array($this->original_request['friend1'], $this->original_request['friend2'], $this->original_request['friend3']); if (!empty($this->original_request['main_name'])) { $from_name = $this->original_request['main_name']; } else { $from_name = $this->original_request['address']; } if (!empty($this->options->email_html_message)) { $html_message = str_replace('</body>', '<br /><br /><br /><small>This e-card was sent from <a href="' . CASHSystem::getCurrentURL() . '">' . CASHSystem::getCurrentURL() . '</a></small></body>', $this->options->email_html_message); } else { $html_message = false; } foreach ($all_friends as $friend) { if (filter_var($friend, FILTER_VALIDATE_EMAIL)) { CASHSystem::sendEmail(trim($this->options->email_subject) . ' ' . $from_name, CASHSystem::getDefaultEmail(), $friend, $this->options->email_message . "\n\n\nThis e-card was sent from " . CASHSystem::getCurrentURL(), '', $html_message); } } $markup .= $this->options->message_success; if ($this->options->asset_id != 0) { // first we "unlock" the asset, telling the platform it's okay to generate a link for non-private assets $unlock_request = new CASHRequest(array('cash_request_type' => 'asset', 'cash_action' => 'unlock', 'id' => $this->options->asset_id)); // next we make the link $asset_request = new CASHRequest(array('cash_request_type' => 'asset', 'cash_action' => 'getasset', 'id' => $this->options->asset_id)); $asset_title = $asset_request->response['payload']['title']; $asset_description = $asset_request->response['payload']['description']; $markup .= '<br /><br />' . '<a href="?cash_request_type=asset&cash_action=claim&id=' . $this->options->asset_id . '&element_id=' . $this->element_id . '" class="download">' . $asset_title . '</a>' . '<div class="description">' . $asset_description . '</div>'; } } if (!empty($this->options->image_url)) { $markup .= '<img src="' . $this->options->image_url . '" alt="E-Card" class="cash_image_ecard" />'; } $markup .= '</div>'; break; case 'people_signup_400': // error, likely in the email format. error message + default form $markup = '<div class="cash_error ' . self::type . '">' . $this->options->message_invalid_email . '</div>' . $default_markup; break; default: // default form $markup = $default_markup; } return $markup; }
/** * Adds a user to a list. If no user exists for the email address passed, a * new user will be created then added to the list. * * @param {string} $address - the email address in question * @param {int} $list_id - the id of the list * @param {bool} $verified - 0 for unverified, 1 to skip verification and mark ok * @param {string} $initial_comment - a comment passed with the list signup * @param {string} $additional_data - any extra data (JSON, etc) a dev might pass with signup for later use * @param {string} $name - if the user doesn't exist in the system this will be used as their display name * @return bool */ protected function addAddress($address, $list_id, $do_not_verify = false, $initial_comment = '', $additional_data = '', $name = 'Anonymous', $force_verification_url = false, $request_from_service = false, $service_opt_in = true) { if (filter_var($address, FILTER_VALIDATE_EMAIL)) { // first check to see if the email is already on the list $user_id = $this->getUserIDForAddress($address); if (!$this->getAddressListInfo($address, $list_id)) { $initial_comment = strip_tags($initial_comment); $name = strip_tags($name); $user_id = $this->getUserIDForAddress($address); if (!$user_id) { $addlogin_request = new CASHRequest(array('cash_request_type' => 'system', 'cash_action' => 'addlogin', 'address' => $address, 'password' => rand(23456, 9876541), 'display_name' => $name)); if ($addlogin_request->response['status_code'] == 200) { $user_id = $addlogin_request->response['payload']; } else { return false; } } if ($user_id) { $result = $this->db->setData('list_members', array('user_id' => $user_id, 'list_id' => $list_id, 'initial_comment' => $initial_comment, 'verified' => 0, 'active' => 1)); if ($result && !$request_from_service) { if ($do_not_verify) { $api_connection = $this->getConnectionAPI($list_id); if ($api_connection) { // connection found, api instantiated switch ($api_connection['connection_type']) { case 'com.mailchimp': $mc = $api_connection['api']; // mailchimp found. subscribe user and request opt-in // error_log(json_encode($mc)); $rc = $mc->listSubscribe($address, null, null, $service_opt_in); // error_log(json_encode($rc)); break; } } } else { $list_details = $this->getList($list_id); $verification_code = $this->setAddressVerification($address, $list_id); $verification_url = $force_verification_url; if (!$verification_url) { $verification_url = CASHSystem::getCurrentURL(); } $verification_url .= '?cash_request_type=people&cash_action=verifyaddress&address=' . urlencode($address) . '&list_id=' . $list_id . '&verification_code=' . $verification_code; CASHSystem::sendEmail('Complete sign-up for: ' . $list_details['name'], CASHSystem::getDefaultEmail(), $address, 'You requested to join the ' . $list_details['name'] . ' email list. If this message has been sent in error ignore it.' . 'To complete your sign-up simply visit: ' . "\n\n" . $verification_url, 'Please confirm your membership'); } } return $result; } } else { // address already present, do nothing but return true return true; } } return false; }
/** * Records the basic access data to the elements analytics table * * @return boolean */ protected function recordAnalytics($id, $access_method, $access_action = 'getmarkup', $location = false, $access_data = '') { // check settings first as they're already loaded in the environment $record_type = CASHSystem::getSystemSettings('analytics'); if ($record_type == 'off') { return true; } if (!$location) { $location = CASHSystem::getCurrentURL(); } // only count one asset + situation per session $recorded_elements = $this->sessionGet('recorded_elements'); if (is_array($recorded_elements)) { if (in_array($id . $access_method . $location, $recorded_elements)) { // already recorded for this session. just return true. return true; } else { // didn't find a record of this asset. record it and move forward $recorded_elements[] = $id . $access_method . $location; $this->sessionSet('recorded_elements', $recorded_elements); } } else { $this->sessionSet('recorded_elements', array($id . $access_method . $location)); } // first the big record if needed if ($record_type == 'full' || !$record_type) { $ip_and_proxy = CASHSystem::getRemoteIP(); $result = $this->db->setData('elements_analytics', array('element_id' => $id, 'access_method' => $access_method, 'access_location' => $location, 'access_action' => $access_action, 'access_data' => json_encode($access_data), 'access_time' => time(), 'client_ip' => $ip_and_proxy['ip'], 'client_proxy' => $ip_and_proxy['proxy'], 'cash_session_id' => $this->getSessionID())); } // basic logging happens for full or basic if ($record_type == 'full' || $record_type == 'basic') { $condition = array("element_id" => array("condition" => "=", "value" => $id)); $current_result = $this->db->getData('elements_analytics_basic', '*', $condition); $short_geo = false; if (is_array($access_data)) { if (isset($access_data['geo'])) { $short_geo = $access_data['geo']['city'] . ', ' . $access_data['geo']['region'] . ' / ' . $access_data['geo']['countrycode']; } } if (is_array($current_result)) { $new_total = $current_result[0]['total'] + 1; $data = json_decode($current_result[0]['data'], true); if (isset($data['locations'][$location])) { $data['locations'][$location] = $data['locations'][$location] + 1; } else { $data['locations'][$location] = 1; } if (isset($data['methods'][$access_method])) { $data['methods'][$access_method] = $data['methods'][$access_method] + 1; } else { $data['methods'][$access_method] = 1; } if (isset($data['geo'][$short_geo])) { $data['geo'][$short_geo] = $data['geo'][$short_geo] + 1; } else { $data['geo'][$short_geo] = 1; } } else { $new_total = 1; $data = array('locations' => array($location => 1), 'methods' => array($access_method => 1), 'geo' => array($short_geo => 1)); $condition = false; } $result = $this->db->setData('elements_analytics_basic', array('element_id' => $id, 'data' => json_encode($data), 'total' => $new_total), $condition); } return $result; }
protected function finalizeRedirectedPayment($order_id, $creation_date, $direct_post_details = false) { $order_details = $this->getOrder($order_id); $transaction_details = $this->getTransaction($order_details['transaction_id']); $connection_type = $this->getConnectionType($transaction_details['connection_id']); switch ($connection_type) { case 'com.paypal': if (isset($_GET['token'])) { if (isset($_GET['PayerID'])) { $pp = new PaypalSeed($order_details['user_id'], $transaction_details['connection_id'], $_GET['token']); $initial_details = $pp->getExpressCheckout(); if ($initial_details['ACK'] == 'Success') { $order_totals = $this->getOrderTotals($order_details['order_contents']); if ($initial_details['AMT'] >= $order_totals['price']) { $final_details = $pp->doExpressCheckout(); if ($final_details) { // look for a user to match the email. if not present, make one $user_request = new CASHRequest(array('cash_request_type' => 'people', 'cash_action' => 'getuseridforaddress', 'address' => $initial_details['EMAIL'])); $user_id = $user_request->response['payload']; if (!$user_id) { $user_request = new CASHRequest(array('cash_request_type' => 'system', 'cash_action' => 'addlogin', 'address' => $initial_details['EMAIL'], 'password' => time(), 'is_admin' => 0, 'display_name' => $initial_details['FIRSTNAME'] . ' ' . $initial_details['LASTNAME'], 'first_name' => $initial_details['FIRSTNAME'], 'last_name' => $initial_details['LASTNAME'], 'address_country' => $initial_details['COUNTRYCODE'])); $user_id = $user_request->response['payload']; } // record the details to the order/transaction where appropriate $this->editOrder($order_id, 1, 0, false, $initial_details['COUNTRYCODE'], $user_id); $this->editTransaction($order_details['transaction_id'], $service_timestamp = strtotime($final_details['TIMESTAMP']), $service_transaction_id = $final_details['CORRELATIONID'], $data_sent = json_encode($initial_details), $data_returned = json_encode($final_details), $successful = 1, $gross_price = $final_details['PAYMENTINFO_0_AMT'], $service_fee = $final_details['PAYMENTINFO_0_FEEAMT'], $status = 'complete'); $addcode_request = new CASHRequest(array('cash_request_type' => 'element', 'cash_action' => 'addlockcode', 'element_id' => $order_details['element_id'])); // bit of a hack, hard-wiring the email bits: CASHSystem::sendEmail('Your download is ready', CASHSystem::getDefaultEmail(), $initial_details['EMAIL'], 'Your download of "' . $initial_details['L_PAYMENTREQUEST_0_NAME0'] . '" is ready and can be found at: ' . CASHSystem::getCurrentURL() . '?cash_request_type=element&cash_action=redeemcode&code=' . $addcode_request->response['payload'] . '&element_id=' . $order_details['element_id'] . '&email=' . urlencode($initial_details['EMAIL']), 'Thank you'); return true; } else { // make sure this isn't an accidentally refreshed page if ($initial_details['CHECKOUTSTATUS'] != 'PaymentActionCompleted') { $initial_details['ERROR_MESSAGE'] = $pp->getErrorMessage(); // there was an error processing the transaction $this->editOrder($order_id, 0, 1); $this->editTransaction($order_details['transaction_id'], $service_timestamp = strtotime($initial_details['TIMESTAMP']), $service_transaction_id = $initial_details['CORRELATIONID'], $data_sent = false, $data_returned = json_encode($initial_details), $successful = 0, $gross_price = false, $service_fee = false, $status = 'error processing payment'); return false; } else { // this is a successful transaction with the user hitting refresh // as long as it's within 30 minutes of the original return true, otherwise // call it false and allow the page to expire if (time() - strtotime($initial_details['TIMESTAMP']) < 180) { return true; } else { return false; } } } } else { // insufficient funds — user changed amount? $this->editOrder($order_id, 0, 1); $this->editTransaction($order_details['transaction_id'], $service_timestamp = strtotime($initial_details['TIMESTAMP']), $service_transaction_id = $initial_details['CORRELATIONID'], $data_sent = false, $data_returned = json_encode($initial_details), $successful = 0, $gross_price = false, $service_fee = false, $status = 'incorrect amount'); return false; } } else { // order reporting failure $this->editOrder($order_id, 0, 1); $this->editTransaction($order_details['transaction_id'], $service_timestamp = strtotime($initial_details['TIMESTAMP']), $service_transaction_id = $initial_details['CORRELATIONID'], $data_sent = false, $data_returned = json_encode($initial_details), $successful = 0, $gross_price = false, $service_fee = false, $status = 'payment failed'); return false; } } else { // user canceled transaction $this->editOrder($order_id, 0, 1); $this->editTransaction($order_details['transaction_id'], $service_timestamp = time(), $service_transaction_id = false, $data_sent = false, $data_returned = false, $successful = 0, $gross_price = false, $service_fee = false, $status = 'canceled'); return false; } } break; default: return false; } }
AdminHelper::formFailure('Error. Something just didn\'t work right.', '/settings/connections/'); } } else { $finalize = false; if (isset($request_parameters[2])) { if ($request_parameters[2] == 'finalize') { $finalize = true; } } $seed_name = $settings_types_data[$settings_type]['seed']; if (!$finalize) { $return_url = rtrim(CASHSystem::getCurrentURL(), '/') . '/finalize'; // PHP <= 5.2 >>>> $cash_admin->page_data['state_markup'] = call_user_func($seed_name . '::getRedirectMarkup', $return_url); $cash_admin->page_data['state_markup'] = $seed_name::getRedirectMarkup($return_url); } else { $connections_base_uri = rtrim(str_replace($request_parameters, '', CASHSystem::getCurrentURL()), '/'); $_REQUEST['connections_base_uri'] = $connections_base_uri; // PHP <= 5.2 >>>> $cash_admin->page_data['state_markup'] = call_user_func($seed_name . '::handleRedirectReturn', $_REQUEST); $cash_admin->page_data['state_markup'] = $seed_name::handleRedirectReturn($_REQUEST); } } } break; case 'edit': $connection_id = $request_parameters[1]; $settings_name = $request_parameters[2]; $settings_type = $request_parameters[3]; $settings_details = $page_data_object->getConnectionSettings($connection_id); if (!isset($_POST['dosettingsedit'])) { if ($settings_details) { $cash_admin->page_data['state_markup'] = '<h4>Edit ' . $settings_name . '</h4><p>' . $settings_types_data[$settings_type]['description'] . '</p>' . '<form method="post" action="">' . '<input type="hidden" name="dosettingsedit" value="makeitso" />' . '<input type="hidden" name="connection_id" value="' . $connection_id . '" />' . '<input type="hidden" name="settings_type" value="' . $settings_type . '" />' . '<label for="settings_name">Connection name</label>' . '<input type="text" id="settings_name" name="settings_name" value="' . $settings_name . '" /><br />';