How to update order status in OpenCart - php

I'm currently building an OpenCart payment extension for a new payment gateway. Right now, I can successfully make payments and redirect back to the merchant site but I don't know how to write the code so that it updates the order status as well.
All my order are now showing under missing orders and I feel it's because of that. I don't have a callback function and I don't know how to go about it. I want to update the code so that it can update my order status as completed if payment is successful or redirect back to checkout if payment fails but still updates the order status.
This is my code below:
<?php
class ControllerExtensionPaymentSCPAY extends Controller {
public function index() {
$this->load->language('extension/payment/sc_pay');
$data['button_confirm'] = $this->language->get('button_confirm');
$data['testmode'] = $this->config->get('sc_pay_test');
$order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
$total = $order_info['total'];
$newbutton = str_replace("50", $total, $this->config->get('sc_pay_button_link'));
$newbutton = $newbutton . "&redirect_url=" .$this->url->link('checkout/success');
if (!$this->config->get('sc_pay_test')) {
$data['action'] = $newbutton;
}
else {
$data['action'] = '';
}
$this->load->model('checkout/order');
$order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
if ($order_info) {
$data['business'] = $this->config->get('sc_pay_email');
$data['item_name'] = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
$data['products'] = array();
foreach ($this->cart->getProducts() as $product) {
$option_data = array();
foreach ($product['option'] as $option) {
if ($option['type'] != 'file') {
$value = $option['value'];
}
else {
$upload_info = $this->model_tool_upload->getUploadByCode($option['value']);
if ($upload_info) {
$value = $upload_info['name'];
}
else {
$value = '';
}
}
$option_data[] = array(
'name' => $option['name'],
'value' => (utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value)
);
}
$data['products'][] = array(
'name' => htmlspecialchars($product['name']),
'model' => htmlspecialchars($product['model']),
'price' => $this->currency->format($product['price'], $order_info['currency_code'], false, false),
'quantity' => $product['quantity'],
'option' => $option_data,
'weight' => $product['weight']
);
}
$data['discount_amount_cart'] = 0;
$total = $this->currency->format($order_info['total'] - $this->cart->getSubTotal(), $order_info['currency_code'], false, false);
if ($total > 0) {
$data['products'][] = array(
'name' => $this->language->get('text_total'),
'model' => '',
'price' => $total,
'quantity' => 1,
'option' => array(),
'weight' => 0
);
}
else {
$data['discount_amount_cart'] -= $total;
}
$data['currency_code'] = $order_info['currency_code'];
$data['first_name'] = html_entity_decode($order_info['payment_firstname'], ENT_QUOTES, 'UTF-8');
$data['last_name'] = html_entity_decode($order_info['payment_lastname'], ENT_QUOTES, 'UTF-8');
$data['address1'] = html_entity_decode($order_info['payment_address_1'], ENT_QUOTES, 'UTF-8');
$data['address2'] = html_entity_decode($order_info['payment_address_2'], ENT_QUOTES, 'UTF-8');
$data['city'] = html_entity_decode($order_info['payment_city'], ENT_QUOTES, 'UTF-8');
$data['zip'] = html_entity_decode($order_info['payment_postcode'], ENT_QUOTES, 'UTF-8');
$data['country'] = $order_info['payment_iso_code_2'];
$data['email'] = $order_info['email'];
$data['invoice'] = $this->session->data['order_id'] . ' - ' . html_entity_decode($order_info['payment_firstname'], ENT_QUOTES, 'UTF-8') . ' ' . html_entity_decode($order_info['payment_lastname'], ENT_QUOTES, 'UTF-8');
$data['lc'] = $this->session->data['language'];
$data['return'] = $this->url->link('checkout/success');
$data['notify_url'] = $this->url->link('extension/payment/sc_pay/callback', '', true);
$data['cancel_return'] = $this->url->link('checkout/checkout', '', true);
$data['custom'] = $this->session->data['order_id'];
return $this->load->view('extension/payment/sc_pay', $data);
}
}
enter code here

I am assuming from your controller file that you are using 2.3.0.2 version of opencart.
//some validation here
$this->model_checkout_order->addOrderHistory($order_id, $order_status_id,print_r($callback,true),true,false);
// if order id is not 0, it will update order status to whatever you defined in admin / payment settings (integer). if 0, it will add new order

Related

I just got a new OpenCart Store and I got some PHP errors

www.efekten.comm This is my store. I get 2 messages saying that I have errors.
Notice: Undefined index: name in /home/efektenc/public_html/catalog/controller/extension/module/beauty_tab.php on line 28Notice: Undefined index: name in /home/efektenc/public_html/catalog/controller/extension/module/shoes_tab.php on line 28
It's ready template, so I started to delete the categories AND it happens when I deleted the very first one.
But there is no option in the admin menu where I can change them and if you can help me I would appreciate it.
I just needed to change those categories, but not able trough the panel, they are installed like modules... It's quite not good.
The code is:
class ControllerExtensionModuleShoesTab extends Controller {
public function index($setting) {
$this->load->language('extension/module/shoes_tab');
$this->load->model('catalog/category');
$this->load->model('catalog/product');
$this->load->model('tool/image');
$data['categories'] = array();
if (!$setting['limit']) {
$setting['limit'] = 4;
}
if (!empty($setting['category'])) {
//$categories = array_slice($setting['category'], 0, (int)$setting['limit']);
$categories = $setting['category'];
$data['template_name'] = $setting['name'];
foreach ($categories as $category_id) {
$category = $this->model_catalog_category->getCategory($category_id);
$datainfo['category'] = $category['name'];
$filter_data = array(
'filter_category_id' => $category_id,
'filter_sub_category' => true,
'limit' => (int)$setting['limit'],
'start' => 0
);
$category_info = $this->model_catalog_product->getProducts($filter_data);
if ($category_info) {
$datainfo['products'] = array(); // сбрасываем datainfo['products'] чтобы не было дубликата
foreach ($category_info as $key => $value) {
if ($value['image']) {
$image = $this->model_tool_image->resize($value['image'], $setting['width'], $setting['height']);
} else {
$image = $this->model_tool_image->resize('placeholder.png', $setting['width'], $setting['height']);
}
if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
$price = $this->currency->format($this->tax->calculate($value['price'], $value['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
} else {
$price = false;
}
if ((float)$value['special']) {
$special = $this->currency->format($this->tax->calculate($value['special'], $value['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
} else {
$special = false;
}
$datainfo['products'][] = array(
'product_id' => $value['product_id'],
'thumb' => $image,
'name' => $value['name'],
'description' => utf8_substr(strip_tags(html_entity_decode($value['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('theme_' . $this->config->get('config_theme') . '_product_description_length')) . '..',
'price' => $price,
'special' => $special,
'rating' => $value['rating'],
'href' => $this->url->link('product/product', 'product_id=' . $value['product_id'])
);
}
}
$data['categories'][] = $datainfo;
}
}
if ($data['categories']) {
return $this->load->view('extension/module/shoes_tab', $data);
}
}
}
And the next one:
class ControllerExtensionModuleBeautyTab extends Controller {
public function index($setting) {
$this->load->language('extension/module/beauty_tab');
$this->load->model('catalog/category');
$this->load->model('catalog/product');
$this->load->model('tool/image');
$data['categories'] = array();
if (!$setting['limit']) {
$setting['limit'] = 4;
}
if (!empty($setting['category'])) {
//$categories = array_slice($setting['category'], 0, (int)$setting['limit']);
$categories = $setting['category'];
$data['template_name'] = $setting['name'];
foreach ($categories as $category_id) {
$category = $this->model_catalog_category->getCategory($category_id);
$datainfo['category'] = $category['name'];
$filter_data = array(
'filter_category_id' => $category_id,
'filter_sub_category' => true,
'limit' => (int)$setting['limit'],
'start' => 0
);
$category_info = $this->model_catalog_product->getProducts($filter_data);
if ($category_info) {
$datainfo['products'] = array(); // сбрасываем datainfo['products'] чтобы не было дубликата
foreach ($category_info as $key => $value) {
if ($value['image']) {
$image = $this->model_tool_image->resize($value['image'], $setting['width'], $setting['height']);
} else {
$image = $this->model_tool_image->resize('placeholder.png', $setting['width'], $setting['height']);
}
if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
$price = $this->currency->format($this->tax->calculate($value['price'], $value['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
} else {
$price = false;
}
if ((float)$value['special']) {
$special = $this->currency->format($this->tax->calculate($value['special'], $value['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
} else {
$special = false;
}
$datainfo['products'][] = array(
'product_id' => $value['product_id'],
'thumb' => $image,
'name' => $value['name'],
'description' => utf8_substr(strip_tags(html_entity_decode($value['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('theme_' . $this->config->get('config_theme') . '_product_description_length')) . '..',
'price' => $price,
'special' => $special,
'rating' => $value['rating'],
'href' => $this->url->link('product/product', 'product_id=' . $value['product_id'])
);
}
}
$data['categories'][] = $datainfo;
}
}
if ($data['categories']) {
return $this->load->view('extension/module/beauty_tab', $data);
}
}
}
I got those codes in two different places, maybe even more...
I have them in both modules in admin folder, catalog folder as well. Maybe they are related somehow and when I have deleted the category there is obviously problem with the module... But how I can change those categories?
And If someone is Familiar with coding I WOULD LOVE IF HE EXPLAIN ME how to find the codes for the mobile version, because IF YOU CAN check the site trough the mobile version of www.efekten.com YOU CAN see that the LOGO itself is getting TO CLOSE to the TAB MENU BUTTON? Can this be fixed and how?
Can I make the button bigger for the MOBILE version or somehow separated from the logo, because it's hard to get in the menu.
Thank you, guys! I love you!
You can check if the index is defined like this..
the line:
$data['template_name'] = $setting['name'];
replace with:
if (!empty($setting['name'])) {
$data['template_name'] = $setting['name'];
} else {
$data['template_name'] = '';
}
Those are not Errors but warnings.
You can stop your error reporting for PHP from your Hosting plan (NS1), or you can add error_reporting(0); to PHP. Those Notifications are not fatal.
On making the buttons bigger, you can use CSS.

Fetch product details on page load in checkout page Opencart:2.3.0.2

I want to fetch the product details that are added to cart, on page load in checkout page.
As we know in checkout page there is generally six Steps to place order, where each step's information is in
<div class="panel-body"></div>
which remains empty until we reached to that step.
so, product details is under the last step(6th) to be fetched.
But i want to fetch the products details which i will show on right side in
<div classs="col-md-4"> </div>
Ideally you're going to want to create an OCMOD for this but that is outside of the scope of answering this question.
Since you're looking at inserting the contents of the "cart" into the page, you'll need to copy the controller logic from the cart "module" controller catalog/controller/common/cart.php and the markup from the view catalog/view/theme/default/template/common/cart.tpl (change according to your template).
Grab these lines from inside the controller file (Public function index()):
$this->load->language('common/cart');
// Totals
$this->load->model('extension/extension');
$totals = array();
$taxes = $this->cart->getTaxes();
$total = 0;
// Because __call can not keep var references so we put them into an array.
$total_data = array(
'totals' => &$totals,
'taxes' => &$taxes,
'total' => &$total
);
// Display prices
if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
$sort_order = array();
$results = $this->model_extension_extension->getExtensions('total');
foreach ($results as $key => $value) {
$sort_order[$key] = $this->config->get($value['code'] . '_sort_order');
}
array_multisort($sort_order, SORT_ASC, $results);
foreach ($results as $result) {
if ($this->config->get($result['code'] . '_status')) {
$this->load->model('extension/total/' . $result['code']);
// We have to put the totals in an array so that they pass by reference.
$this->{'model_extension_total_' . $result['code']}->getTotal($total_data);
}
}
$sort_order = array();
foreach ($totals as $key => $value) {
$sort_order[$key] = $value['sort_order'];
}
array_multisort($sort_order, SORT_ASC, $totals);
}
$data['text_empty'] = $this->language->get('text_empty');
$data['text_cart'] = $this->language->get('text_cart');
$data['text_checkout'] = $this->language->get('text_checkout');
$data['text_recurring'] = $this->language->get('text_recurring');
$data['text_items'] = sprintf($this->language->get('text_items'), $this->cart->countProducts() + (isset($this->session->data['vouchers']) ? count($this->session->data['vouchers']) : 0), $this->currency->format($total, $this->session->data['currency']));
$data['text_loading'] = $this->language->get('text_loading');
$data['button_remove'] = $this->language->get('button_remove');
$this->load->model('tool/image');
$this->load->model('tool/upload');
$data['products'] = array();
foreach ($this->cart->getProducts() as $product) {
if ($product['image']) {
$image = $this->model_tool_image->resize($product['image'], $this->config->get($this->config->get('config_theme') . '_image_cart_width'), $this->config->get($this->config->get('config_theme') . '_image_cart_height'));
} else {
$image = '';
}
$option_data = array();
foreach ($product['option'] as $option) {
if ($option['type'] != 'file') {
$value = $option['value'];
} else {
$upload_info = $this->model_tool_upload->getUploadByCode($option['value']);
if ($upload_info) {
$value = $upload_info['name'];
} else {
$value = '';
}
}
$option_data[] = array(
'name' => $option['name'],
'value' => (utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value),
'type' => $option['type']
);
}
// Display prices
if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
$price = $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
} else {
$price = false;
}
// Display prices
if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
$total = $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')) * $product['quantity'], $this->session->data['currency']);
} else {
$total = false;
}
$data['products'][] = array(
'cart_id' => $product['cart_id'],
'thumb' => $image,
'name' => $product['name'],
'model' => $product['model'],
'option' => $option_data,
'recurring' => ($product['recurring'] ? $product['recurring']['name'] : ''),
'quantity' => $product['quantity'],
'price' => $price,
'total' => $total,
'href' => $this->url->link('product/product', 'product_id=' . $product['product_id'])
);
}
// Gift Voucher
$data['vouchers'] = array();
if (!empty($this->session->data['vouchers'])) {
foreach ($this->session->data['vouchers'] as $key => $voucher) {
$data['vouchers'][] = array(
'key' => $key,
'description' => $voucher['description'],
'amount' => $this->currency->format($voucher['amount'], $this->session->data['currency'])
);
}
}
$data['totals'] = array();
foreach ($totals as $total) {
$data['totals'][] = array(
'title' => $total['title'],
'text' => $this->currency->format($total['value'], $this->session->data['currency']),
);
}
Create a new file in the catalog/controller/common/ folder, call it products.php and use the following structure:
<?php
class ControllerCommonProducts extends Controller {
public function index(){
//placeholder
return $data;
}
}
Paste the copied text it into the new file replacing the //placeholder line.
Edit the catalog/controller/checkout/checkout.php file, insert this line to load the data from the controller we have just created into the checkout page view:
$data['products_view'] = $this->load->controller('common/products'); insert it just above this line:
$this->response->setOutput($this->load->view('checkout/checkout', $data));
Now edit the view catalog/view/theme/default/template/checkout/checkout.tpl you will now have a new array products_view that you can use on the view as you need. Start with a var_dump of the array to see what data you have to work with.
Summary: What we've done here is replicate an existing controller (1, 2 & 3) - excluding the controller logic where it loads the data into a view. We then edited the controller's index action (3) of the page we're displaying data on and loaded the new controller (4) into an array to be used on the front end view (5).

Wordpress wp_insert_post fire multiple times on mobile devices

I have built a custom front-end multipage donation form on Wordpress, saving the data via session variables across the pages. I then use save_post hook to run a function to redirect the user, after submitting the form, to an online payment portal. The problem is, when users access the form via mobile, the function wp_insert_post fires multiple time.
This is the code that I have on the php page used for processing the data from the form.
<?php
header('Cache-Control: no cache'); //no cache
session_cache_limiter('private_no_expire'); // works
//session_cache_limiter('public'); // works too
//let's start the session
session_start();
require_once 'library/HTMLPurifier.auto.php';
$config = HTMLPurifier_Config::createDefault();
$purifier = new HTMLPurifier($config);
//LISTING ALL VARIABLES AVAILABLE FROM FRONTEND FORM
$negara = $_SESSION['negara'];
$binatang = $_SESSION['binatang'];
if($_SESSION['ekor']) {
$ekorBahagian = $_SESSION['ekor'];
} else {
$ekorBahagian = $_SESSION['bahagian'];
}
$nama1 = $_SESSION['nama'];
$kp1 = $_SESSION['kp'];
$telefon1 = $_SESSION['telefon'];
$emel1 = $_SESSION['emel'];
$alamat11 = $_SESSION['alamat1'];
$alamat21 = $_SESSION['alamat2'];
$poskod1 = $_SESSION['poskod'];
$bandar1 = $_SESSION['bandar'];
$negeri1 = $_SESSION['negeri'];
$peserta1 = $_SESSION['peserta'];
$kempen = $_POST['kempen'];
$bank = $_POST['bank'];
if($telefon1) {
$mobile = preg_replace("/[^0-9]/", "", $telefon1);
$custTel = $mobile;
$custTel2 = substr($mobile, 0, 1);
if ($custTel2 == '+') {
$custTel3 = substr($mobile, 1, 1);
if ($custTel3 != '6') {
$custTel = "+6" . $mobile;
}
} elseif ($custTel2 == '6') {
} else {
if ($custTel != '') {
$custTel = "+6" . $mobile;
}
}
}
//purifying the texts
$nama = $purifier->purify($nama1);
$kp = $purifier->purify($kp1);
$telefon = $purifier->purify($custTel);
$emel = $purifier->purify($emel1);
$alamat1 = $purifier->purify($alamat11);
$alamat2 = $purifier->purify($alamat21);
$poskod = $purifier->purify($poskod1);
$bandar = $purifier->purify($bandar1);
$negeri = $purifier->purify($negeri1);
$peserta = $purifier->purify($peserta1);
if($_SESSION['ekor']) {
$bil = $_SESSION['ekor']; //capturing bilangan ekor into a var
switch ($_SESSION['negara']){
case 'Malaysia':
$jumlahHarga = $bil*(650*7);
break;
case 'ASEAN':
$jumlahHarga = $bil*(450*7);
break;
case 'Timur Tengah':
$jumlahHarga = $bil*(1300*7);
break;
case 'Afrika':
$jumlahHarga = $bil*(350*7);
break;
default:
}
} else {
$bil = $_SESSION['bahagian']; //capturing bilangan bahagian into a var
switch ($_SESSION['negara']){
case 'Malaysia':
$jumlahHarga = $bil*650;
break;
case 'ASEAN':
$jumlahHarga = $bil*450;
break;
case 'Timur Tengah':
$jumlahHarga = $bil*1300;
break;
case 'Afrika':
$jumlahHarga = $bil*350;
break;
default:
}
}
$post = array(
'post_title' => wp_strip_all_tags( $nama ),
'post_status' => 'publish',
'post_type' => 'qurban',
'meta_input' => array(
'pilihan_negara' => $negara,
'pilihan_lembu' => $binatang,
'bilangan_ekorbahagian' => $ekorBahagian,
'jumlah_bayaran' => $jumlahHarga,
'nama_penuh' => $nama,
'nombor_kad_pengenalan' => $kp,
'nombor_telefon' => $telefon,
'emel' => $emel,
'alamat_rumah_1' => $alamat1,
'alamat_rumah_2' => $alamat2,
'poskod' => $poskod,
'bandar' => $bandar,
'negeri' => $negeri,
'senarai_nama_peserta' => $peserta,
'bank' => $bank,
'kempen' => $kempen
)
);
$post_id = wp_insert_post($post);
get_header();
?>
<?php
get_footer();
?>
Below is the code that uses save_post to redirect the user to external payment site:
?php
require_once "Mobile_Detect.php";
////////////////////////////
//// PAYMENT REDIRECTION FUNCTION
////////////////////////////
function my_save_post_iq( $post_id ) {
debug_to_console( "save post function fired" );
$billplzApi = get_field('iq_secret_key', 'option');
$billplzId = get_field('iq_collection_id', 'option');
// bail early if not a donation post
if( get_post_type($post_id) !== 'qurban' ) {
return;
}
// bail early if editing in admin
if( is_admin() ) {
return;
}
$post = get_post( $post_id);
$jumlah_bayaran_iq = get_field('jumlah_bayaran', $post_id);
//check & update user device type
$detect = new Mobile_Detect;
if($detect->isMobile()){
update_field('devices', 'mobile' , $post);
} else {
update_field('devices', 'desktop', $post);
}
$name = get_field('nama_penuh', $post);
$email = get_field('emel', $post);
$mobile = get_field('nombor_telefon', $post);
$bank = get_field('bank', $post);
$billplz_data = array(
'amount' => $jumlah_bayaran_iq * 100,
'name' => $name,
'mobile' => $mobile,
'email' => $email,
'collection_id' => $billplzId,
'deliver' => false,
'reference_1_label' => 'Bank Code',
'reference_1' => $bank,
'reference_2_label' => 'Post ID',
'reference_2' => $post_id,
'description' => 'xxx',
'redirect_url' => home_url('qurbanv2/paymentredirectv2'),
'callback_url' => home_url('paymentcallback')
);
$process = curl_init('https://www.billplz.com/api/v3/bills/');
curl_setopt($process, CURLOPT_HEADER, 0);
curl_setopt($process, CURLOPT_USERPWD, $billplzApi . ":");
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($process, CURLOPT_POSTFIELDS, http_build_query($billplz_data));
$return = curl_exec($process);
curl_close($process);
$arr = json_decode($return, true);
$billplz_url = $arr['url'];
$billplz_id = $arr['id'];
//update payment status
update_field('billplz_iq', $billplz_id , $post);
//$hzpost_name = array(
// 'ID' = $post,
// 'post_name' = $billplz_url
//);
//
//wp_update_post($hzpost_name);
header('Location: '. $billplz_url . '?auto_submit=true');
exit();
}
add_action('save_post', 'my_save_post_iq', 10, 1);
I am new to Wordpress development, so please help.
Found the bug. It's got to do with how the payment gateway treats mobile number. I've added a line to add '+' in front of the numbers, and the duplication stops.
if($telefon1) {
$mobile = preg_replace("/[^0-9]/", "", $telefon1);
$custTel = $mobile;
$custTel2 = substr($mobile, 0, 1);
if ($custTel2 == '+') {
$custTel3 = substr($mobile, 1, 1);
if ($custTel3 != '6') {
$custTel = "+6" . $mobile;
}
} elseif ($custTel2 == '6') {
$custTel = "+" . $mobile; //added this line.
} else {
if ($custTel != '') {
$custTel = "+6" . $mobile;
}
}
}

Sofort: Get Reponse After Successfull payment

I am Trying to get the Response back after the success payment with the sofort integration but not getting anything in response;
Error: Error: 7000:Invalid XML.
Here is the success function:
public function successAction()
{
$configkey = 'my_key';
$SofortLib_Notification = new Notification();
$TestNotification = $SofortLib_Notification->getNotification(file_get_contents('php://input'));
echo $SofortLib_Notification->getTransactionId();
echo '<br />';
echo $SofortLib_Notification->getTime();
echo '<br />';
$SofortLibTransactionData = new TransactionData($configkey);
$SofortLibTransactionData->addTransaction($TestNotification);
$SofortLibTransactionData->setApiVersion('2.0');
$SofortLibTransactionData->setTime('2012-11-14T18:00+02:00', '2012-12-13T00:00+02:00');
$SofortLibTransactionData->setNumber(5, 1);
$SofortLibTransactionData->sendRequest();
echo '<pre>'; print_r($SofortLibTransactionData);
//exit();
$output = array();
$methods = array(
'getAmount' => '',
'getAmountRefunded' => '',
'getCount' => '',
'getPaymentMethod' => '',
'getConsumerProtection' => '',
'getStatus' => '',
'getStatusReason' => '',
'getStatusModifiedTime' => '',
'getLanguageCode' => '',
'getCurrency' => '',
'getTransaction' => '',
'getSenderAccountNumber' => '',
'getSenderBankCode' => '',
'getSenderCountryCode' => '',
'getSenderBankName' => '',
'getSenderBic' => '',
'getSenderIban' => '',
);
foreach($methods as $method => $params) {
if(count($params) == 2) {
$output[] = $method . ': ' . $SofortLibTransactionData->$method($params[0], $params[1]);
} else if($params !== '') {
$output[] = $method . ': ' . $SofortLibTransactionData->$method($params);
} else {
$output[] = $method . ': ' . $SofortLibTransactionData->$method();
}
}
if($SofortLibTransactionData->isError()) {
echo $SofortLibTransactionData->getError();
} else {
echo implode('<br />', $output);
}
// $sofortTans = new TransactionData;
// echo '<pre>';print_r($sofortTans);
// $viewModel = new ViewModel(array('status' => $sofortTans));
// $viewModel->setTemplate('layout/pay_done');
// return $viewModel;
}
And Here the Action method in my contrller to send the request can you please guide me how i can get the Response back?
$configkey = 'my_config_key';
$Sofortueberweisung = new SofortUeberWeisung($configkey);
$Sofortueberweisung->setAmount($request->getPost('grandtotal_price'));
$Sofortueberweisung->setCurrencyCode('EUR');
$Sofortueberweisung->setReason('Single Coupon Order', 'Voucher Codes');
$Sofortueberweisung->setSuccessUrl('http://localhost:8088/payment/success', false);
$Sofortueberweisung->setCustomerprotection(true);
$Sofortueberweisung->sendRequest();
if($Sofortueberweisung->isError()) {
// SOFORT-API didn't accept the data
echo $Sofortueberweisung->getError();
} else {
// get unique transaction-ID useful for check payment status
$transactionId = $Sofortueberweisung->getTransactionId();
// buyer must be redirected to $paymentUrl else payment cannot be successfully completed!
$paymentUrl = $Sofortueberweisung->getPaymentUrl();
$this->redirect()->toUrl($paymentUrl);
//header('Location: '.$paymentUrl);
}
And I am Using this API Library, Sofort API Library
Add parameter ?transId=-TRANSACTION- with your success_url and than you will be able to get that from Response !
$transNumber = $this->getRequest()->getQuery('transId');
$fields = $sofortObj->getTransactionData($transNumber);
You've all transaction data with you in $fields

accessing 'blog' functionality / template in FUEL CMS

I'm having trouble getting the "stock" blog functionality / template working within FUEL CMS.
I have read that it is already there, stock with the download configuration of the CMS; I have also tried creating one from scratch and uploading a 'blog' theme from a project found in GitHub. None have worked so far.
I found the blog variable at:
_variables/global.php
I have created a 'blog' controller via interpretation of (gappy) docs.
By adding the below code within it; then making a corresponding 'blog.php' view. I get nothing but a 404 error.
<?php
class Blog extends CI_Controller {
public function view($page = 'home')
{
//you can acesse this http://example.com/blog/view/
}
public function new($page = 'home')
{
//you can acesse this http://example.com/blog/new/
}
}
Within the modules folder. I found this 'stock' blog controller file. But don't know how to use it? found at: /fuel/modules/blog/controller/blog.php
<?php
require_once(MODULES_PATH.'/blog/libraries/Blog_base_controller.php');
class Blog extends Blog_base_controller {
function __construct()
{
parent::__construct();
}
function _remap()
{
$year = ($this->uri->rsegment(2) != 'index') ? (int) $this->uri->rsegment(2) : NULL;
$month = (int) $this->uri->rsegment(3);
$day = (int) $this->uri->rsegment(4);
$slug = $this->uri->rsegment(5);
$limit = (int) $this->fuel->blog->config('per_page');
$view_by = 'page';
// we empty out year variable if it is page because we won't be querying on year'
if (preg_match('#\d{4}#', $year) && !empty($year) && empty($slug))
{
$view_by = 'date';
}
// if the first segment is id then treat the second segment as the id
else if ($this->uri->rsegment(2) === 'id' && $this->uri->rsegment(3))
{
$view_by = 'slug';
$slug = (int) $this->uri->rsegment(3);
$post = $this->fuel->blog->get_post($slug);
if (isset($post->id))
{
redirect($post->url);
}
}
else if (!empty($slug))
{
$view_by = 'slug';
}
// set this to false so that we can use segments for the limit
$cache_id = fuel_cache_id();
$cache = $this->fuel->blog->get_cache($cache_id);
if (!empty($cache))
{
$output =& $cache;
}
else
{
$vars = $this->_common_vars();
if ($view_by == 'slug')
{
return $this->post($slug);
}
else if ($view_by == 'date')
{
$page_title_arr = array();
$posts_date = mktime(0, 0, 0, $month, $day, $year);
if (!empty($day)) $page_title_arr[] = $day;
if (!empty($month)) $page_title_arr[] = date('M', strtotime($posts_date));
if (!empty($year)) $page_title_arr[] = $year;
// run before_posts_by_date hook
$hook_params = array('year' => $year, 'month' => $month, 'day' => $day, 'slug' => $slug, 'limit' => $limit);
$this->fuel->blog->run_hook('before_posts_by_date', $hook_params);
$vars = array_merge($vars, $hook_params);
$vars['page_title'] = $page_title_arr;
$vars['posts'] = $this->fuel->blog->get_posts_by_date($year, (int) $month, $day, $slug);
$vars['pagination'] = '';
}
else
{
$limit = $this->fuel->blog->config('per_page');
$this->load->library('pagination');
$config['uri_segment'] = 3;
$offset = $this->uri->segment($config['uri_segment']);
$this->config->set_item('enable_query_strings', FALSE);
$config = $this->fuel->blog->config('pagination');
$config['base_url'] = $this->fuel->blog->url('page/');
//$config['total_rows'] = $this->fuel->blog->get_posts_count();
$config['page_query_string'] = FALSE;
$config['per_page'] = $limit;
$config['num_links'] = 2;
//$this->pagination->initialize($config);
if (!empty($offset))
{
$vars['page_title'] = lang('blog_page_num_title', $offset, $offset + $limit);
}
else
{
$vars['page_title'] = '';
}
// run before_posts_by_date hook
$hook_params = array('offset' => $offset, 'limit' => $limit, 'type' => 'posts');
$this->fuel->blog->run_hook('before_posts_by_page', $hook_params);
$vars['offset'] = $offset;
$vars['limit'] = $limit;
$vars['posts'] = $this->fuel->blog->get_posts_by_page($limit, $offset);
// run hook again to get the proper count
$hook_params['type'] = 'count';
$this->fuel->blog->run_hook('before_posts_by_page', $hook_params);
//$config['total_rows'] = count($this->fuel->blog->get_posts_by_page());
$config['total_rows'] = $this->fuel->blog->get_posts_count();
// create pagination
$this->pagination->initialize($config);
$vars['pagination'] = $this->pagination->create_links();
}
// show the index page if the page doesn't have any uri_segment(3)'
$view = ($this->uri->rsegment(2) == 'index' OR ($this->uri->rsegment(2) == 'page' AND !$this->uri->segment(3))) ? 'index' : 'posts';
$output = $this->_render($view, $vars, TRUE);
$this->fuel->blog->save_cache($cache_id, $output);
}
$this->output->set_output($output);
}
function post($slug = null)
{
if (empty($slug))
{
redirect_404();
}
$this->load->library('session');
$blog_config = $this->fuel->blog->config();
// run before_posts_by_date hook
$hook_params = array('slug' => $slug);
$this->fuel->blog->run_hook('before_post', $hook_params);
$post = $this->fuel->blog->get_post($slug);
if (isset($post->id))
{
$vars = $this->_common_vars();
$vars['post'] = $post;
$vars['user'] = $this->fuel->blog->logged_in_user();
$vars['page_title'] = $post->title;
$vars['next'] = $this->fuel->blog->get_next_post($post);
$vars['prev'] = $this->fuel->blog->get_prev_post($post);
$vars['slug'] = $slug;
$vars['is_home'] = $this->fuel->blog->is_home();
$antispam = md5(random_string('unique'));
$field_values = array();
// post comment
if (!empty($_POST))
{
$field_values = $_POST;
// the id of "content" is a likely ID on the front end, so we use comment_content and need to remap
$field_values['content'] = $field_values['new_comment'];
unset($field_values['antispam']);
if (!empty($_POST['new_comment']))
{
$vars['processed'] = $this->_process_comment($post);
}
else
{
add_error(lang('blog_error_blank_comment'));
}
}
$cache_id = fuel_cache_id();
$cache = $this->fuel->blog->get_cache($cache_id);
if (!empty($cache) AND empty($_POST))
{
$output =& $cache;
}
else
{
$this->load->library('form');
if (is_true_val($this->fuel->blog->config('use_captchas')))
{
$captcha = $this->_render_captcha();
$vars['captcha'] = $captcha;
}
$vars['thanks'] = ($this->session->flashdata('thanks')) ? blog_block('comment_thanks', $vars, TRUE) : '';
$vars['comment_form'] = '';
$this->session->set_userdata('antispam', $antispam);
if ($post->allow_comments)
{
$this->load->module_model(BLOG_FOLDER, 'blog_comments_model');
$this->load->library('form_builder', $blog_config['comment_form']);
$fields['author_name'] = array('label' => 'Name', 'required' => TRUE);
$fields['author_email'] = array('label' => 'Email', 'required' => TRUE);
$fields['author_website'] = array('label' => 'Website');
$fields['new_comment'] = array('label' => 'Comment', 'type' => 'textarea', 'required' => TRUE);
$fields['post_id'] = array('type' => 'hidden', 'value' => $post->id);
$fields['antispam'] = array('type' => 'hidden', 'value' => $antispam);
if (!empty($vars['captcha']))
{
$fields['captcha'] = array('required' => TRUE, 'label' => 'Security Text', 'value' => '', 'after_html' => ' <span class="captcha">'.$vars['captcha']['image'].'</span><br /><span class="captcha_text">'.lang('blog_captcha_text').'</span>');
}
// now merge with config... can't do array_merge_recursive'
foreach($blog_config['comment_form']['fields'] as $key => $field)
{
if (isset($fields[$key])) $fields[$key] = array_merge($fields[$key], $field);
}
if (!isset($blog_config['comment_form']['label_layout'])) $this->form_builder->label_layout = 'left';
if (!isset($blog_config['comment_form']['submit_value'])) $this->form_builder->submit_value = 'Submit Comment';
if (!isset($blog_config['comment_form']['use_form_tag'])) $this->form_builder->use_form_tag = TRUE;
if (!isset($blog_config['comment_form']['display_errors'])) $this->form_builder->display_errors = TRUE;
$this->form_builder->form_attrs = 'method="post" action="'.site_url($this->uri->uri_string()).'#comments_form"';
$this->form_builder->set_fields($fields);
$this->form_builder->set_field_values($field_values);
$this->form_builder->set_validator($this->blog_comments_model->get_validation());
$vars['comment_form'] = $this->form_builder->render();
$vars['fields'] = $fields;
}
$output = $this->_render('post', $vars, TRUE);
// save cache only if we are not posting data
if (!empty($_POST))
{
$this->fuel->blog->save_cache($cache_id, $output);
}
}
if (!empty($output))
{
$this->output->set_output($output);
return;
}
}
else
{
show_404();
}
}
function _process_comment($post)
{
if (!is_true_val($this->fuel->blog->config('allow_comments'))) return;
$notified = FALSE;
// check captcha
if (!$this->_is_valid_captcha())
{
add_error(lang('blog_error_captcha_mismatch'));
}
// check that the site is submitted via the websit
if (!$this->_is_site_submitted())
{
add_error(lang('blog_error_comment_site_submit'));
}
// check consecutive posts
if (!$this->_is_not_consecutive_post())
{
add_error(lang('blog_error_consecutive_comments'));
}
$this->load->module_model(BLOG_FOLDER, 'blog_users_model');
$user = $this->blog_users_model->find_one(array('fuel_users.email' => $this->input->post('author_email', TRUE)));
// create comment
$this->load->module_model(BLOG_FOLDER, 'blog_comments_model');
$comment = $this->blog_comments_model->create();
$comment->post_id = $post->id;
$comment->author_id = (!empty($user->id)) ? $user->id : NULL;
$comment->author_name = $this->input->post('author_name', TRUE);
$comment->author_email = $this->input->post('author_email', TRUE);
$comment->author_website = $this->input->post('author_website', TRUE);
$comment->author_ip = $_SERVER['REMOTE_ADDR'];
$comment->content = trim($this->input->post('new_comment', TRUE));
$comment->date_added = NULL; // will automatically be added
//http://googleblog.blogspot.com/2005/01/preventing-comment-spam.html
//http://en.wikipedia.org/wiki/Spam_in_blogs
// check double posts by IP address
if ($comment->is_duplicate())
{
add_error(lang('blog_error_comment_already_submitted'));
}
// if no errors from above then proceed to submit
if (!has_errors())
{
// submit to akisment for validity
$comment = $this->_process_akismet($comment);
// process links and add no follow attribute
$comment = $this->_filter_comment($comment);
// set published status
if (is_true_val($comment->is_spam) OR $this->fuel->blog->config('monitor_comments'))
{
$comment->published = 'no';
}
// save comment if saveable and redirect
if (!is_true_val($comment->is_spam) OR (is_true_val($comment->is_spam) AND $this->fuel->blog->config('save_spam')))
{
if ($comment->save())
{
$notified = $this->_notify($comment, $post);
$this->load->library('session');
$vars['post'] = $post;
$vars['comment'] = $comment;
$this->session->set_flashdata('thanks', TRUE);
$this->session->set_userdata('last_comment_ip', $_SERVER['REMOTE_ADDR']);
$this->session->set_userdata('last_comment_time', time());
redirect($post->url);
}
else
{
add_errors($comment->errors());
}
}
else
{
add_error(lang('blog_comment_is_spam'));
}
}
return $notified;
}
// check captcha validity
function _is_valid_captcha()
{
$valid = TRUE;
// check captcha
if (is_true_val($this->fuel->blog->config('use_captchas')))
{
if (!$this->input->post('captcha'))
{
$valid = FALSE;
}
else if (!is_string($this->input->post('captcha')))
{
$valid = FALSE;
}
else
{
$post_captcha_md5 = $this->_get_encryption($this->input->post('captcha'));
$session_captcha_md5 = $this->session->userdata('comment_captcha');
if ($post_captcha_md5 != $session_captcha_md5)
{
$valid = FALSE;
}
}
}
return $valid;
}
// check to make sure the site issued a session variable to check against
function _is_site_submitted()
{
return ($this->session->userdata('antispam') AND $this->input->post('antispam') == $this->session->userdata('antispam'));
}
// disallow multiple successive submissions
function _is_not_consecutive_post()
{
$valid = TRUE;
$time_exp_secs = $this->fuel->blog->config('multiple_comment_submission_time_limit');
$last_comment_time = ($this->session->userdata('last_comment_time')) ? $this->session->userdata('last_comment_time') : 0;
$last_comment_ip = ($this->session->userdata('last_comment_ip')) ? $this->session->userdata('last_comment_ip') : 0;
if ($_SERVER['REMOTE_ADDR'] == $last_comment_ip AND !empty($time_exp_secs))
{
if (time() - $last_comment_time < $time_exp_secs)
{
$valid = FALSE;
}
}
return $valid;
}
// process through akisment
function _process_akismet($comment)
{
if ($this->fuel->blog->config('akismet_api_key'))
{
$this->load->module_library(BLOG_FOLDER, 'akismet');
$akisment_comment = array(
'author' => $comment->author_name,
'email' => $comment->author_email,
'body' => $comment->content
);
$config = array(
'blog_url' => $this->fuel->blog->url(),
'api_key' => $this->fuel->blog->config('akismet_api_key'),
'comment' => $akisment_comment
);
$this->akismet->init($config);
if ( $this->akismet->errors_exist() )
{
if ( $this->akismet->is_error('AKISMET_INVALID_KEY') )
{
log_message('error', 'AKISMET :: Theres a problem with the api key');
}
elseif ( $this->akismet->is_error('AKISMET_RESPONSE_FAILED') )
{
log_message('error', 'AKISMET :: Looks like the servers not responding');
}
elseif ( $this->akismet->is_error('AKISMET_SERVER_NOT_FOUND') )
{
log_message('error', 'AKISMET :: Wheres the server gone?');
}
}
else
{
$comment->is_spam = ($this->akismet->is_spam()) ? 'yes' : 'no';
}
}
return $comment;
}
// strip out
function _filter_comment($comment)
{
$this->load->helper('security');
$comment_attrs = array('content', 'author_name', 'author_email', 'author_website');
foreach($comment_attrs as $filter)
{
$text = $comment->$filter;
// first remove any nofollow attributes to clean up... not perfect but good enough
$text = preg_replace('/<a(.+)rel=["\'](.+)["\'](.+)>/Umi', '<a$1rel="nofollow"$3>', $text);
// $text = str_replace('<a ', '<a rel="nofollow"', $text);
$text = strip_image_tags($text);
$comment->$filter = $text;
}
return $comment;
}
function _notify($comment, $post)
{
// send email to post author
if (!empty($post->author))
{
$config['wordwrap'] = TRUE;
$this->load->library('email', $config);
$this->email->from($this->fuel->config('from_email'), $this->fuel->config('site_name'));
$this->email->to($post->author->email);
$this->email->subject(lang('blog_comment_monitor_subject', $this->fuel->blog->config('title')));
$msg = lang('blog_comment_monitor_msg');
$msg .= "\n".fuel_url('blog/comments/edit/'.$comment->id)."\n\n";
$msg .= (is_true_val($comment->is_spam)) ? lang('blog_email_flagged_as_spam')."\n" : '';
$msg .= lang('blog_email_published').": ".$comment->published."\n";
$msg .= lang('blog_email_author_name').": ".$comment->author_name."\n";
$msg .= lang('blog_email_author_email').": ".$comment->author_email."\n";
$msg .= lang('blog_email_author_website').": ".$comment->author_website."\n";
$msg .= lang('blog_email_author_ip').": ".gethostbyaddr($comment->author_ip)." (".$comment->author_ip.")\n";
$msg .= lang('blog_email_content').": ".$comment->content."\n";
$this->email->message($msg);
return $this->email->send();
}
else
{
return FALSE;
}
}
function _render_captcha()
{
$this->load->library('captcha');
$blog_config = $this->config->item('blog');
$assets_folders = $this->config->item('assets_folders');
$blog_folder = MODULES_PATH.BLOG_FOLDER.'/';
$captcha_path = $blog_folder.'assets/captchas/';
$word = strtoupper(random_string('alnum', 5));
$captcha_options = array(
'word' => $word,
'img_path' => $captcha_path, // system path to the image
'img_url' => captcha_path('', BLOG_FOLDER), // web path to the image
'font_path' => $blog_folder.'fonts/',
);
$captcha_options = array_merge($captcha_options, $blog_config['captcha']);
if (!empty($_POST['captcha']) AND $this->session->userdata('comment_captcha') == $this->input->post('captcha'))
{
$captcha_options['word'] = $this->input->post('captcha');
}
$captcha = $this->captcha->get_captcha_image($captcha_options);
$captcha_md5 = $this->_get_encryption($captcha['word']);
$this->session->set_userdata('comment_captcha', $captcha_md5);
return $captcha;
}
function _get_encryption($word)
{
$captcha_md5 = md5(strtoupper($word).$this->config->item('encryption_key'));
return $captcha_md5;
}
}
My goal is:
1.) Enable 'Blog' Module / template / functionality and understand how I did it. I find the docs lacking, I'm also new at code igniter so that could be why. I just want the most basic way to do this for now.
And 2.) I want to create a page 'from scratch' that resolves on the dashboard side as well. I have created pages in /views/ but they resolve with that whole string /fuel/application/views/page/ I want to create a normal page without all that in the URL. I have tried creating corresponding controllers even variables and haven't had much luck!!!!!!!
As of FUEL CMS 1.0 the blog module is no longer bundled with the CMS by default. You would need to do the following:
Download & setup FUEL CMS per the install instructions here: https://github.com/daylightstudio/FUEL-CMS
Next, once you've got that up and running you can download & setup the blog module per the instructions here: https://github.com/daylightstudio/FUEL-CMS-Blog-Module
Once the blog is setup, you should be able to access it at "yourdomain.com/blog". As far as creating themes, there is a views/themes folder in the blog module which contains a default theme and also where you can setup your custom theme. Additional information about the blog module & theming can be found here http://docs.getfuelcms.com/modules/blog

Categories