/** * @method POST */ function form() { // parse request parse_str($this->request->data, $request); $siteId = $request['siteId']; $pageId = $request['pageId']; $site = Site::GetBySiteId($siteId); $page = Page::GetByPageId($pageId); // create a form (sent to webhooks) $wh_form = array('SiteId' => $siteId, 'PageId' => $pageId); if ($site != null && $page != null) { $subject = BRAND . ': Form Submission [' . $site['Name'] . ': ' . $page['Name'] . ']'; $content = '<h3>Site Information</h3>' . '<table>' . '<tr>' . '<td style="width: 125px; padding: 5px 25px 5px 0;">Site</td>' . '<td style="padding: 5px 0">' . $site['Name'] . '</td>' . '</tr>' . '<tr>' . '<td style="width: 125px; padding: 5px 25px 5px 0;">Page</td>' . '<td style="padding: 5px 0">' . $page['Name'] . '</td>' . '</tr>' . '</table>' . '<h3>Form Details</h3>' . '<table>'; foreach ($request as $key => $value) { if ($key != 'siteId' && $key != 'pageId') { // clean up title $title = urldecode($key); $title = preg_replace('/(?!^)[A-Z]{2,}(?=[A-Z][a-z])|[A-Z][a-z]|[0-9]{1,}/', ' $0', $key); $title = ucwords($title); // decode value $value = urldecode($value); $content .= '<tr>' . '<td style="width: 125px; padding: 5px 25px 5px 0;">' . $title . '</td>' . '<td style="padding: 5px 0">' . $value . '</td>' . '</tr>'; $wh_form[$key] = $value; } } $content .= '</table>'; // sends the email $to = $site['PrimaryEmail']; $from = $site['PrimaryEmail']; $fromName = $site['Name']; // send site email Utilities::SendSiteEmail($site, $to, $site['PrimaryEmail'], $site['Name'], $subject, $content); // send webhook Webhooks::FormSubmit($wh_form); // return a successful response (200) return new Tonic\Response(Tonic\Response::OK); } else { // unauthorized access return new Tonic\Response(Tonic\Response::UNAUTHORIZED); } }
/** * @method POST */ function post() { parse_str($this->request->data, $request); $siteId = $request['custom']; // get reference to site $site = Site::GetBySiteId($siteId); $use_sandbox = false; // set whether to use a sandbox if ($site['PayPalUseSandbox'] == '1') { $use_sandbox = true; } $listener = new IpnListener(); $listener->use_curl = false; $listener->use_sandbox = $use_sandbox; $listener->use_ssl = true; try { $verified = $listener->processIpn(); } catch (Exception $e) { // fatal error trying to process IPN. exit(0); } // IPN response was "VERIFIED" if ($verified) { $processor = 'PayPal'; if ($use_sandbox == true) { $processor .= ' (sandbox)'; } $processorTransactionId = $request['txn_id']; $processorStatus = $request['payment_status']; $email = $request['payer_email']; $payerId = $request['payer_id']; $name = $request['first_name'] . ' ' . $request['last_name']; $shipping = $request['mc_handling']; $fee = $request['mc_fee']; $tax = $request['tax']; $total = $request['mc_gross']; $currency = $request['mc_currency']; $num_items = 1000; if (isset($request['num_cart_items'])) { $num_items = $request['num_cart_items']; } $items = array(); // line-items (for receipt) $line_items = ''; // set static URL $staticUrl = $site['Domain']; if (FILES_ON_S3 == true) { $bucket = $site['Bucket']; $staticUrl = str_replace('{{bucket}}', $bucket, S3_URL); $staticUrl = str_replace('{{site}}', $site['FriendlyId'], $staticUrl); } // get items for ($x = 1; $x <= $num_items; $x++) { if (isset($request['item_number' . $x])) { $item_number = $request['item_number' . $x]; $item_name = $request['item_name' . $x]; $item_number = iconv("ISO-8859-1", "UTF-8", $item_number); $item_name = iconv("ISO-8859-1", "UTF-8", $item_name); $item_quantity = $request['quantity' . $x]; $item_total = $request['mc_gross_' . $x]; $item_price = floatval($item_total) / intval($item_quantity); $item = array('ProductId' => $item_number, 'Name' => $item_name, 'Quantity' => $item_quantity, 'Price' => $item_price, 'Total' => $item_total); // get product $product = Product::GetByProductId($item_number); // get download link $download_link = ''; // check if there is a downloaded file for the product if ($product['Download'] != '' && $product['Download'] != NULL) { $download_link = '<br><a href="' . API_URL . '/transaction/download/{{transactionId}}/' . $item_number . '">Download</a>'; } // setup currency for line items $item_total = $item_total . ' ' . $currency; $item_price = $item_price . ' ' . $currency; // add $ for total and price if ($currency == 'USD') { $item_total = '$' . $item_total; $item_price = '$' . $item_price; } $line_items .= '<tr style="border-bottom: 1px solid #f0f0f0;"><td>' . $item_name . '<br><small>' . $item_number . '</small>' . $download_link . '</td><td align="right">' . $item_price . '</td><td align="right">' . $item_quantity . '</td><td align="right">' . $item_total . '</td></tr>'; array_push($items, $item); } } $items_json = json_encode($items); $data_json = json_encode($_POST); // create receipt $receipt = $line_items; // add a transaction $transaction = Transaction::Add($site['SiteId'], $processor, $processorTransactionId, $processorStatus, $email, $payerId, $name, $shipping, $fee, $tax, $total, $currency, $items_json, $data_json, $receipt); // replace {{transactionId}} in line_items $line_items = str_replace('{{transactionId}}', $transaction['TransactionId'], $line_items); $site_logo = ''; if ($site['LogoUrl'] != '' && $site['LogoUrl'] != NULL) { $site_logo = '<img src="' . $staticUrl . '/files/' . $site['LogoUrl'] . '" style="max-height:50px">'; } // setup currency for line items $shipping = $shipping . ' ' . $currency; $tax = $tax . ' ' . $currency; $total = $total . ' ' . $currency; // add $ for total and price if ($currency == 'USD') { $shipping = '$' . $shipping; $tax = '$' . $tax; $total = '$' . $total; } // send email $replace = array('{{site}}' => $site['Name'], '{{site-logo}}' => $site_logo, '{{reply-to}}' => $site['PrimaryEmail'], '{{line-items}}' => $line_items, '{{shipping}}' => $shipping, '{{tax}}' => $tax, '{{total}}' => $total); $subject = '[' . $site['Name'] . '] Receipt for your purchase from ' . $site['Name'] . ' (Transaction: ' . strtoupper($transaction['TransactionId']) . ') (Triangulate)'; $file = SITES_LOCATION . '/' . $site['FriendlyId'] . '/emails/receipt.html'; // send email $content = $site['ReceiptEmail']; // walk through and replace values in associative array foreach ($replace as $key => &$value) { $content = str_replace($key, $value, $content); $subject = str_replace($key, $value, $subject); } // send site email Utilities::SendSiteEmail($site, $email, $site['PrimaryEmail'], $site['Name'], $subject, $content); } else { // IPN response was "INVALID"\ } $response = new Tonic\Response(Tonic\Response::OK); $response->contentType = 'text/HTML'; $response->body = 'Yah!!!'; return $response; }
public static function SendEmailFromFile($to, $from, $fromName, $subject, $replace, $file, $site = NULL) { $full_file = $file; if (file_exists($full_file)) { $content = file_get_contents($full_file); // walk through and replace values in associative array foreach ($replace as $key => &$value) { $content = str_replace($key, $value, $content); $subject = str_replace($key, $value, $subject); } // send email if ($site != NULL) { Utilities::SendSiteEmail($site, $to, $from, $fromName, $subject, $content); } else { Utilities::SendEmail($to, $from, $fromName, $subject, $content); } } }
/** * @method POST */ function post() { parse_str($this->request->data, $request); // parse request $siteId = $request['siteId']; $email = $request['email']; $password = $request['password']; $firstName = $request['firstName']; $lastName = $request['lastName']; $role = 'Member'; // get a reference to the site $site = Site::GetBySiteId($siteId); // set default language $language = $site['Language']; $isActive = 0; $user = User::Add($email, $password, $firstName, $lastName, $role, $language, $isActive, $siteId); // send welcome email $subject = SITE_WELCOME_EMAIL_SUBJECT; $subject = str_replace('{{site}}', $site['Name'], $subject); $content = $site['WelcomeEmail']; // send site email Utilities::SendSiteEmail($site, $email, $site['PrimaryEmail'], $site['Name'], $subject, $content); // return a json response $response = new Tonic\Response(Tonic\Response::OK); $response->contentType = 'application/json'; $response->body = json_encode($user); return $response; }