public function mailerPreviewUsersPassword_reset_notification($event) { $options = []; $options['user'] = ['id' => new \MongoId(), 'first_name' => 'John', 'last_name' => 'Doe', 'email' => '*****@*****.**', 'forgot_password' => ['token' => new \MongoId()]]; $options['link'] = \Dsc\Url::base() . 'user/change-email/confirm?new_email&previewview'; $options['token'] = new \MongoId(); $event->setArgument('variables', $options); }
/** * Set the value of a cookie. * * @param string $name * @param string $value * @param int $expiration * @param string $path * @param string $domain * @param bool $secure * @return void */ public static function set($name, $value, $expiration = 0, $path = '/', $domain = null, $secure = false) { if ($expiration !== 0) { $expiration = time() + $expiration * 60; } // If the secure option is set to true, yet the request is not over HTTPS if ($secure && !\Dsc\Url::isSecure()) { throw new \Exception("Attempting to set secure cookie over HTTP."); } static::$jar[$name] = compact('name', 'value', 'expiration', 'path', 'domain', 'secure'); setcookie($name, $value, $expiration, $path, $domain, $secure); }
public function generate() { $routes = ['base' => []]; $event = \Dsc\System::instance()->trigger('siteMapRegisterRoutes', ['routes' => $routes]); $routes = $event->getArgument('routes'); $this->setDomain(\Dsc\Url::base()); $this->setPath(\Base::instance()->get('PATH_ROOT') . '/public/sitemaps/'); $this->setFilename('google'); foreach ($routes as $app => $routes) { foreach ($routes as $key => $route) { $this->addItem($route['loc'], $route['pri'], $route['change'], $route['mod']); } } $this->createSitemapIndex(\Dsc\Url::base() . 'sitemaps/', 'Today'); }
public function processPayment() { $cart = $this->model->cart(); $user = $this->auth->getIdentity(); $merchant_id = $this->model->{'settings.merchant_id'}; $working_key = $this->model->{'settings.encryption_key'}; $access_code = $this->model->{'settings.access_code'}; $signed_fields = array('merchant_id' => $merchant_id, 'order_id' => (string) $cart->id, 'currency' => 'INR', 'amount' => number_format($cart->total(), 2, '.', ''), 'redirect_url' => \Dsc\Url::base() . 'shop/checkout/gateway/ccavenue/completePurchase/' . $cart->id, 'cancel_url' => \Dsc\Url::base() . 'shop/checkout/payment', 'language' => 'EN'); $merchant_data = ''; foreach ($signed_fields as $key => $value) { $merchant_data .= $key . '=' . $value . '&'; } $encrypted_data = \Shop\PaymentMethods\CCAvenue\Lib\Encrypt::encrypt($merchant_data, $working_key); $hiddenFields = ' <input type=hidden name="encRequest" value="' . $encrypted_data . '"> <input type=hidden name="access_code" value="' . $access_code . '"> '; $output = '<!DOCTYPE html> <html> <head> <title>Redirecting...</title> </head> <body onload="document.forms[0].submit();"> <form action="%1$s" method="post" style="height: 1px; overflow: hidden;"> <p>Redirecting to payment page...</p> <p> %2$s <input type="submit" value="Continue" /> </p> </form> </body> </html>'; $output = sprintf($output, htmlentities($this->gatewayUrl() . '/transaction/transaction.do?command=initiateTransaction', ENT_QUOTES, 'UTF-8', false), $hiddenFields); \Symfony\Component\HttpFoundation\Response::create($output)->send(); exit; }
public function validatePayment() { $cart = $this->model->cart(); $paymentData = $this->model->paymentData(); $user = $this->auth->getIdentity(); $order = $this->model->order(); $gateway = $this->gateway(); /* Paypal Express returns this in the request after a checkout: Array ( [token] => EC-74S42539DC567584C [PayerID] => L3BUDRTU6MPKC ) */ $cardData = array('firstName' => $user->first_name, 'lastName' => $user->last_name); $card = new \Omnipay\Common\CreditCard($cardData); $paymentDetails = array('amount' => (double) $cart->total(), 'returnUrl' => \Dsc\Url::base() . 'shop/checkout/gateway/omnipay.paypal_express/completePurchase/' . $cart->id, 'cancelUrl' => \Dsc\Url::base() . 'shop/checkout/payment', 'transactionId' => (string) $cart->id, 'description' => 'Cart #' . $cart->id, 'currency' => 'USD', 'clientIp' => $_SERVER['REMOTE_ADDR'], 'card' => $card); $purchase_response = $gateway->completePurchase($paymentDetails)->send(); if (!$purchase_response->isSuccessful()) { throw new \Exception('Purchase was not successful'); } $purchase_data = $purchase_response->getData(); $payment_status = !empty($purchase_data['PAYMENTINFO_0_PAYMENTSTATUS']) ? $purchase_data['PAYMENTINFO_0_PAYMENTSTATUS'] : null; switch ($payment_status) { case "Completed": case "Processed": case "Completed-Funds-Held": break; default: throw new \Exception('Payment was not completed'); break; } $params = array('token' => @$paymentData['token']); $response = $gateway->fetchCheckout($params)->send(); $success = $response->isSuccessful(); if (!$success) { $order->payment_method_validation_result = $response->getData(); throw new \Exception('Payment was not successful'); } $data = $response->getData(); if (empty($data['INVNUM']) || (string) $data['INVNUM'] != (string) $cart->id) { throw new \Exception('Payment transaction not associated with this cart'); } // Is any further validation required on the payment response? $order->financial_status = \Shop\Constants\OrderFinancialStatus::paid; $order->payment_method_id = $this->identifier; $order->payment_method_result = $purchase_data; $order->payment_method_validation_result = $data; $order->payment_method_status = !empty($purchase_data['PAYMENTINFO_0_PAYMENTSTATUS']) ? $purchase_data['PAYMENTINFO_0_PAYMENTSTATUS'] : null; $order->payment_method_auth_id = !empty($purchase_data['TOKEN']) ? $purchase_data['TOKEN'] : null; $order->payment_method_tran_id = $purchase_response->getTransactionReference(); return $data; }
/** * \T (tab) delimited feed of products * * http://www.pepperjamnetwork.com/doc/product_feed_advanced.html * */ public function productsTxt() { $settings = \Shop\Models\Settings::fetch(); if (!$settings->{'feeds.pepperjam_products.enabled'}) { return; } $this->app->set('CACHE', true); $cache = \Cache::instance(); $cache_period = 3600 * 24; if ($cache->exists('pepperjam.products_text', $string)) { header('Content-Type: text/plain; charset=utf-8'); echo $string; exit; } $base = \Dsc\Url::base(); $model = (new \Shop\Models\Products())->setState('filter.published_today', true)->setState('filter.inventory_status', 'in_stock')->setState('filter.publication_status', 'published'); $conditions = $model->conditions(); $conditions['product_type'] = array('$nin' => array('giftcard', 'giftcards')); $cursor = \Shop\Models\Products::collection()->find($conditions)->sort(array('title' => 1)); //->limit(10); /** * name sku buy_url image_url description_short description_long price manufacturer */ $column_headers = array('name', 'sku', 'buy_url', 'image_url', 'description_short', 'description_long', 'price', 'manufacturer'); $string = implode("\t", $column_headers) . "\r\n"; foreach ($cursor as $product_doc) { $product = new \Shop\Models\Products($product_doc); foreach ($product->variantsInStock() as $variant) { $valid = true; $price = $product->price($variant['id']); // Skip products where price == 0.00 if (empty($price)) { continue; } $pieces = array('name' => null, 'sku' => null, 'buy_url' => null, 'image_url' => null, 'description_short' => null, 'description_long' => null, 'price' => null, 'manufacturer' => null); $pieces['name'] = $product->title; $sku = $variant['sku'] ? $variant['sku'] : $product->{'tracking.sku'}; if (!$sku) { $sku = $variant['id']; } $pieces['sku'] = $sku; $pieces['buy_url'] = $base . 'shop/product/' . $product->slug . '?variant_id=' . $variant['id']; // image_link if ($image = $variant['image'] ? $variant['image'] : $product->{'featured_image.slug'}) { $pieces['image_url'] = $base . 'asset/' . $image; } $pieces['description_short'] = $product->title . ' '; if ($attribute_title = \Dsc\ArrayHelper::get($variant, 'attribute_title')) { $pieces['description_short'] .= $attribute_title; } $pieces['description_short'] = trim($pieces['description_short']); $pieces['description_long'] = strip_tags($product->getAbstract()); $pieces['price'] = $price; if ($brand = $settings->{'feeds.pepperjam_products.brand'}) { $pieces['manufacturer'] = $brand; } global $product; //walk peices logging empty values and omiting them array_walk($pieces, function (&$value, $key) { global $product; if (empty($value)) { \Dsc\Mongo\Collections\Logs::add($product->title . ' | ID: ' . $product->id . ' is missing ' . $key, 'WARNING', 'PepperJam'); $valid = false; } }); if ($valid) { $string .= implode("\t", $pieces) . "\r\n"; } } } $cache->set('pepperjam.products_text', $string, $cache_period); header('Content-Type: text/plain; charset=utf-8'); echo $string; exit; }
public function productsXml() { $settings = \Shop\Models\Settings::fetch(); if (!$settings->{'feeds.gm_products.enabled'}) { return; } $this->app->set('CACHE', true); $cache = \Cache::instance(); $cache_period = 3600 * 24; if ($cache->exists('googlemerchant.products_xml', $string)) { header('Content-Type: application/xml; charset=utf-8'); echo $string; exit; } $base = \Dsc\Url::base(); $model = (new \Shop\Models\Products())->setState('filter.published_today', true)->setState('filter.inventory_status', 'in_stock')->setState('filter.publication_status', 'published'); $conditions = $model->conditions(); $conditions['product_type'] = array('$nin' => array('giftcard', 'giftcards')); $cursor = \Shop\Models\Products::collection()->find($conditions)->sort(array('title' => 1)); //->limit(10); /** * Generate XML */ $x = new \XMLWriter(); $x->openMemory(); $x->setIndent(true); $x->setIndentString(" "); $x->startDocument('1.0', 'UTF-8'); $x->startElement('rss'); $x->writeAttribute('version', '2.0'); $x->writeAttribute('xmlns:g', 'http://base.google.com/ns/1.0'); $x->startElement('channel'); $title = $settings->{'feeds.gm_products.title'} ? $settings->{'feeds.gm_products.title'} : 'Product Feed'; $x->startElement('title'); $x->text($title); $x->endElement(); // title $link = $base; $x->startElement('link'); $x->text($link); $x->endElement(); // link if ($description = $settings->{'feeds.gm_products.description'}) { $x->startElement('description'); $x->text($description); $x->endElement(); // description } foreach ($cursor as $product_doc) { $product = new \Shop\Models\Products($product_doc); foreach ($product->variantsInStock() as $variant) { $price = $product->price($variant['id']); // Skip products where price == 0.00 if (empty($price)) { continue; } $x->startElement('item'); $x->startElement('title'); $x->text($product->title); $x->endElement(); // title $x->startElement('description'); $x->text(strip_tags($product->getAbstract())); $x->endElement(); // description $x->startElement('g:link'); $x->text($base . 'shop/product/' . $product->slug); $x->endElement(); // g:link // image_link if ($image = $variant['image'] ? $variant['image'] : $product->{'featured_image.slug'}) { $x->startElement('g:image_link'); $x->text($base . 'asset/' . $image); $x->endElement(); // g:image_link } // google_product_category if ($product->{'gm_product_category'}) { $x->startElement('g:google_product_category'); $x->text($product->{'gm_product_category'}); $x->endElement(); // g:google_product_category } // TODO product_type // gender = female (or male, unisex) $gender = $settings->{'feeds.gm_products.gender'}; if ($product->{'gm_products.gender'}) { $gender = $product->{'gm_products.gender'}; } if ($gender) { $x->startElement('g:gender'); $x->text($gender); $x->endElement(); // g:gender } // age_group = adult (or newborn, infanct, toddler, kids) $age_group = $settings->{'feeds.gm_products.age_group'}; if ($product->{'gm_products.age_group'}) { $age_group = $product->{'gm_products.age_group'}; } if ($age_group) { $x->startElement('g:age_group'); $x->text($age_group); $x->endElement(); // g:age_group } // following handles color, size, pattern, material (if they are set as attributes) foreach ($product->attributes as $attribute) { $att_title = strtolower($attribute['title']); if (in_array($att_title, array('color', 'material', 'pattern', 'size'))) { $att_id = $attribute['id']; // get the attribute options $options = array(); foreach ($attribute['options'] as $option) { $options[] = $option['id']; } if ($found = array_intersect($options, $variant['attributes'])) { $key = array_search($found, $variant['attributes']); if (!empty($variant['attribute_titles'][$key])) { $x->startElement('g:' . $att_title); $x->text($variant['attribute_titles'][$key]); $x->endElement(); // g:$att_title } } } } // since we do variants: item_group_id $x->startElement('g:item_group_id'); $x->text($product->{'tracking.sku'}); $x->endElement(); // g:item_group_id $sku = $variant['sku'] ? $variant['sku'] : $product->{'tracking.sku'}; if (!$sku) { $sku = $variant['id']; } $x->startElement('g:id'); $x->text($sku); $x->endElement(); // g:id if ($brand = $settings->{'feeds.gm_products.brand'}) { $x->startElement('g:brand'); $x->text($brand); $x->endElement(); // g:brand } $x->startElement('g:mpn'); $x->text($sku); $x->endElement(); // g:mpn $x->startElement('g:price'); $x->text($price . ' USD'); $x->endElement(); // g:price $x->startElement('g:condition'); $x->text('new'); $x->endElement(); // g:condition $x->startElement('g:availability'); $x->text('in stock'); $x->endElement(); // g:availability $x->endElement(); // item } } $x->endElement(); // channel $x->endElement(); // rss $x->endDocument(); $string = $x->outputMemory(); $cache->set('googlemerchant.products_xml', $string, $cache_period); header('Content-Type: application/xml; charset=utf-8'); echo $string; }
/** * Send an email to this user to verify ownership of a new email address * * @return \Users\Models\Users */ public function sendEmailChangeEmailConfirmation() { $email = $this->{'change_email.email'}; $mailer = \Dsc\System::instance()->get('mailer'); if ($content = $mailer->getEmailContents('users.verify_change_email', array('user' => $this, 'link' => \Dsc\Url::base() . 'user/change-email/confirm?new_email=' . urlencode($this->{'change_email.email'}) . '&token=' . $this->{'change_email.token'}, 'token' => $this->{'change_email.token'}))) { $this->__sendEmailPasswordResetNotification = $mailer->sendEvent($email, $content); } return $this; }