I test my application in the live server and got an error: after finishing my Actions in controller he doesn't won't redirecting me to another route. This error can be from SSL(cloudflare) or Nginx because on dev/local server works fine
My Code:
->Action:
public function addAction(Request $request)
{
$cookies = $request->cookies;
$cart = $cookies->get('SHOP_CART');
$post_id = $request->request->get('id');
$r = $this->getDoctrine()->getRepository('AppBundle:Product');
$product = $r->find($post_id);
if ($cart == null) {
$cart = [
'items' => [$product->getId()],
'price' => $product->getPriceUah(),
'count_items' => 1,
];
} else {
$cart = unserialize($cart);
if (in_array($product->getId(), $cart['items']) === false) {
array_push($cart['items'], $product->getId());
$cart = [
'items' => $cart['items'],
'price' => $cart['price'] + $product->getPriceUah(),
'count_items' => $cart['count_items'] + 1,
];
}
}
$cart = new Cookie(
'SHOP_CART', // Имя.
serialize($cart), // Значение.
time() + (31 * 24 * 60 * 60) // Время жизни куки 1 месяц.
);
$res = new Response();
$res->headers->setCookie($cart);
$res->send();
return new RedirectResponse($this->generateUrl('client_index_product_page', ['id' => $product->getId()]));
}
->Routing:
client_cart_add:
path: /cart/add
methods: [POST]
defaults: { _controller: AppBundle:Client/Component/CartActions:add, _locale: ru }
requirements:
_locale: ru|ua
options:
expose: true
I made another working variant, but on live/prod still not working:
$request->getSession()
->getFlashBag()
->add('notice', 'success');
return $this->redirect($request->headers->get('referer'));
I am having an issue with a cakephp script. It was written with cakephp version 2.5.1.
I'm getting fatal error: Fatal error: Cannot call constructor in /lib/Cake/Controller/CakeErrorController.php on line 46.
The original AppController.php file looked like this:
<?php
if (session_id() == '') {
session_start();
}
class AppController
{
public $components = array('Auth');
public $helpers = array(
0 => 'Form',
'Html' => array('className' => 'MyHtml')
);
public function beforeFilter()
{
global $loguser;
global $username;
global $siteChanges;
global $paypalAdaptive;
global $user_level;
global $setngs;
global $price;
global $colors;
global $parent_categori;
global $googlecode;
parent::beforeFilter();
$this->Auth->loginAction = array('controller' => '/', 'action' => '/login');
$this->Auth->logoutRedirect = array('controller' => '/', 'action' => '/');
$this->Auth->authenticate = array(
AuthComponent::ALL => array(
'fields' => array('username' => 'email', 'password' => 'password'),
'userModel' => 'Users.User'
),
0 => 'Form'
);
if ($this->params['controller'] == 'api') {
$this->Auth->allow();
}
if ($this->params['controller'] == 'fantasyhelps') {
$this->Auth->allow();
}
if ($this->params['controller'] == 'paypals') {
App::import('Vendor', 'PayPal');
}
$this->Auth->allow(, , 'login', 'signup', 'emailverification', 'verification', 'index', 'setpassword', 'userprofiles', 'viewshops', 'addto', 'press', 'about', 'toppeople', 'findpeople', 'storeprofiles', 'getstoreprofile', 'listings', 'show_color', 'show_price', 'showByCategory', 'getMorePosts', 'ipnprocess', 'getmorepricecolor', 'getItemByCategory', 'ajaxSearch', 'captcha', 'forgotpassword', 'showByRelation', 'getItemByRelation', 'faq', 'contact', 'item_comments', 'changePassword', 'copyrights', 'termsofsale', 'termsofservice', 'termsofmerchant', 'privacy', 'loginwith', 'loginwithtwitter', 'changecurrency', 'downimage', 'sitemaintenance', 'getviewmore', 'customviewmore', 'orderstatus', 'getsizeqty', 'searches', 'getmoregallery', 'viewitemdesc', 'followersList', 'getmoreprofile', 'getmorestorycomment', 'followingList', 'twittlogin_save', 'item_favorited', 'merupdate', 'custupdatend', 'testing', 'bookmarklet', 'getmorecomments', 'adaptiveipnprocess', 'additemusingurl', 'giftcardipnIpn', 'ggipn', 'ggcronjob', 'nearme', 'getMorenearme', 'gifts', 'story');
$loguser = $this->Auth->user();
$userid = $loguser[0]['User']['id'];
$username = $loguser[0]['User']['username'];
$first_name = $loguser[0]['User']['first_name'];
$username_url = $loguser[0]['User']['username_url'];
$user_level = $loguser[0]['User']['user_level'];
$profile_image = $loguser[0]['User']['profile_image'];
$this->set('loguser', $loguser);
$this->set('username', $username);
$this->set('username_url', $username_url);
$this->set('user_level', $user_level);
$this->set('first_name', $first_name);
$this->set('profile_image', $profile_image);
$this->set('currentaction', $this->params['action']);
$this->loadModel('User');
$user_datas = $this->User->findById($userid);
if (!empty($loguser) && empty($user_datas)) {
$this->Auth->logout();
}
$user_status_val = $this->User->find('first', array(
'conditions' => array('User.id' => $userid)
));
$user_status = $user_status_val['User']['user_status'];
if ($user_status == 'disable') {
$this->Session->setFlash(__('Your account has been disabled please contact our support'), 'default', array(), 'bad');
$this->redirect($this->Auth->logout());
$this->redirect('/login');
}
$this->loadModel('Sitesetting');
$this->loadModel('Cart');
$this->loadModel('Orders');
$this->loadModel('Item');
$this->loadModel('Price');
$this->loadModel('Color');
$this->loadModel('Category');
$this->loadModel('Forexrate');
$this->loadModel('Managemodule');
$this->loadModel('Googlecode');
$this->loadModel('Contactseller');
$this->loadModel('Story');
$orderdetails = $this->Orders->find('all', array(
'conditions' => array('Orders.merchant_id' => $userid)
));
$this->set('orderdetails', $orderdetails);
$storyCount = $this->Story->find('count', array(
'conditions' => array('userid' => $userid)
));
$this->set('storyCounts', $storyCount);
$managemoduleModel = $this->Managemodule->find('first');
$this->set('managemoduleModel', $managemoduleModel);
$params = $this->params;
$action = $params['action'];
if ($this->params['controller'] != 'api') {
$this->_setLanguage();
}
if (($action != 'sitemaintenance') && ($action != 'login') && ($this->params['controller'] != 'api')) {
if (!$this->isauthenticated() || ($user_level != 'god')) {
if ($managemoduleModel['Managemodule']['site_maintenance_mode'] == 'yes') {
$this->redirect('/sitemaintenance');
}
}
}
$messageCount = $this->Contactseller->find('count', array(
'conditions' => array(
'OR' => array(
array('merchantid' => $userid, 'sellerread' => 1),
array('buyerid' => $userid, 'buyerread' => 1)
)
)
));
$_SESSION['userMessageCount'] = $messageCount;
if (!isset($_SESSION['language_settings'])) {
$languageJson = file_get_contents(SITE_URL . 'language_settings.json');
$_SESSION['language_settings'] = json_decode($languageJson, true);
$defaultLanguage = $_SESSION['language_settings']['settings']['default'];
Configure::write('Config.language', $defaultLanguage);
}
if (!isset($_SESSION['currency_value'])) {
$forexrateModel = $this->Forexrate->find('first', array(
'conditions' => array('status' => 'default')
));
$_SESSION['currency_symbol'] = $forexrateModel['Forexrate']['currency_symbol'];
$_SESSION['currency_value'] = $forexrateModel['Forexrate']['price'];
$_SESSION['currency_code'] = $forexrateModel['Forexrate']['currency_code'];
$_SESSION['default_currency_code'] = $forexrateModel['Forexrate']['currency_code'];
$_SESSION['default_currency_symbol'] = $forexrateModel['Forexrate']['currency_symbol'];
}
$setngs = $this->Sitesetting->find('all');
$price = ('all');
$forexrateModel = $this->Forexrate->find('all', array(
'conditions' => array('status <>' => 'disable')
));
$colors = $this->Color->find('all');
$UserDetailss = $this->User->findById($userid);
$this->set('UserDetailss', $UserDetailss);
$this->loadModel('Shop');
$sellerDetails = $this->Shop->find('all', array(
'conditions' => array('user_id' => $userid)
));
$this->set('sellerDetails', $sellerDetails);
$shopDetails = $this->Shop->find('first', array(
'conditions' => array('user_id' => $userid)
));
$this->set('shop_name', $shopDetails['Shop']['shop_name']);
$parent_categori = $this->Category->find('all', array(
'conditions' => array('category_parent' => 0)
));
$googlecode = $this->Googlecode->find('all');
if (!empty($userid)) {
if (!empty($carts)) {
foreach ($carts as $crt) {
$itmids[] = $crt['Cart']['item_id'];
}
$itm_datas = $this->Item->find('all', array(
'conditions' => array('Item.id' => $itmids, 'Item.status' => 'publish')
));
$total_itms = count($itm_datas);
$this->set('total_itms', $total_itms);
}
}
$this->set('price', $price);
$this->set('colors', $colors);
$this->set('forexrateModel', $forexrateModel);
$this->set('parent_categori', $parent_categori);
$this->set('googlecode', $googlecode);
$this->set('media_url', $setngs[0]['Sitesetting']['media_url']);
$this->set('setngs', $setngs);
$siteChanges = $setngs[0]['Sitesetting']['site_changes'];
$siteChanges = json_decode($siteChanges, true);
$paypalAdaptive = $setngs[0]['Sitesetting']['paypaladaptive'];
$paypalAdaptive = json_decode($paypalAdaptive, true);
$this->set('siteChanges', $siteChanges);
$_SESSION['site_url'] = SITE_URL;
$_SESSION['media_url'] = SITE_URL;
if (!empty($setngs[0]['Sitesetting']['media_url'])) {
$_SESSION['media_host_name'] = $setngs[0]['Sitesetting']['media_server_hostname'];
$_SESSION['media_url'] = $setngs[0]['Sitesetting']['media_url'];
$_SESSION['media_server_username'] = $setngs[0]['Sitesetting']['media_server_username'];
$_SESSION['media_server_password'] = $setngs[0]['Sitesetting']['media_server_password'];
}
$params = $this->params;
$action = $params['action'];
$this->set('action', $action);
if ($this->params['controller'] != 'api') {
$this->_setLanguage();
}
}
public function isauthenticated()
{
$user = $this->Auth->user();
if (!empty($user)) {
return true;
}
return false;
}
public function isauthorized()
{
$user = $this->Auth->user();
if (($user[0]['User']['user_level'] == 'god') || ($user[0]['User']['user_level'] == 'moderator')) {
return true;
}
return false;
}
public function isauthorizedpersn()
{
$user = ();
if (($user[0]['User']['user_level'] == 'god') || ($user[0]['User']['user_level'] == 'shop')) {
return true;
}
return false;
}
public function _setLanguage()
{
if (isset($this->Cookie) && $this->Cookie->read('lang') && !$this->Session->check('Config.language')) {
$this->Session->write('Config.language', $this->Cookie->read('lang'));
}
else if (isset($this->params['language']) && ($this->params['language'] != $this->Session->read('Config.language'))) {
$this->Session->write('Config.language', $this->params['language']);
$this->Cookie->write('lang', $this->params['language'], false, '20 days');
}
}
}
$config['Settings'] = Configure::read('Settings');
define('SITE_URL', $config['Settings']['SITE_URL']);
define('SITE_NAME', $config['Settings']['SITE_TITLE']);
define('FB_ID', $config['Settings']['FB_ID']);
define('FB_SECRET', $config['Settings']['FB_SECRET']);
define('GOOGLE_ID', $config['Settings']['GOOGLE_ID']);
define('GOOGLE_SECRET', $config['Settings']['GOOGLE_SECRET']);
define('TWITTER_ID', $config['Settings']['TWITTER_ID']);
define('TWITTER_SECRET', $config['Settings']['TWITTER_SECRET']);
define('GMAIL_CLIENT_SECRET', $config['Settings']
['GMAIL_CLIENT_SECRET']);
define('GMAIL_CLIENT_ID', $config['Settings']['GMAIL_CLIENT_ID']);
?>
The first error pointed to this line:
$this->Auth->allow(, , 'login', 'signup', 'emailverification',
so I removed the , , and hence it became:
$this->Auth->allow('login', 'signup', 'emailverification',
The second error pointed to this line $user = ();
So I changed it to $user = $this->Auth->user();
But this change from $user = (); to $user = $this->Auth->user(); throws a fatal error:
Fatal error: Cannot call constructor in /lib/Cake/Controller/CakeErrorController.php on line 46
Below is the content of CakeErrorController.php. I'm told that CakeErrorController.php is a core file so I shouldn't really need to change it?
<?php
/**
* Error Handling Controller
*
* Controller used by ErrorHandler to render error views.
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc.
(http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the
LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* #copyright Copyright (c) Cake Software Foundation, Inc.
(http://cakefoundation.org)
* #link http://cakephp.org CakePHP(tm) Project
* #package Cake.Controller
* #since CakePHP(tm) v 2.0
* #license http://www.opensource.org/licenses/mit-license.php MIT
License
*/
App::uses('AppController', 'Controller');
/**
* Error Handling Controller
*
* Controller used by ErrorHandler to render error views.
*
* #package Cake.Controller
*/
class CakeErrorController extends AppController {
/**
* Uses Property
*
* #var array
*/
public $uses = array();
/**
* Constructor
*
* #param CakeRequest $request
* #param CakeResponse $response
*/
public function __construct($request = null, $response = null) {
parent::__construct($request, $response);
$this->constructClasses();
if (count(Router::extensions()) &&
!$this->Components->attached('RequestHandler')
) {
$this->RequestHandler = $this->Components-
>load('RequestHandler');
}
if ($this->Components->enabled('Auth')) {
$this->Components->disable('Auth');
}
if ($this->Components->enabled('Security')) {
$this->Components->disable('Security');
}
$this->_set(array('cacheAction' => false, 'viewPath' => 'Errors'));
}
}
I need help in fixing any issues you notice with the AppController.php file. I'm new at this. Any help will be much appreciated.
Thanks.
First of all, and I don't want to step on anyone's toes, but, that code looks horrible, there's so much wrong with it I don't even know where to start... global usage, accessing superglobals directly, manually starting a session via native calls, code outside of the class definition, public controller methods that aren't actual actions, massive amounts of unrelated code that should be in concrete controllers and/or components, etc... you really need to get that cleaned up.
That being said, your AppController class doesn't extend Controller (which it must do) and has no constructor itself, so there's no constructor to invoke via parent::__construct() in CakeErrorController::__construct(), hence the error.
See also Cookbook > Controllers
I followed a serie on creating a shopping cart on codecourse - and it was just what I was looking for.
In the series the payment happens on creating the order - but now my client says that they don't want the payment on creating order - first when they have processed the order - they want to send an email with payment or an link to a payment site.
I thought no big deal - just move the BraintreePayment par out of the create class - create a new class called payment and thats that - but no - so now I am stuck.
I am using swiftmailer to send the mail with the link and that works fine - but the payment part fails.
I am new to this MVC / Slim thing - so please can someone help me in the right direction.
The error it throws say:
Type: TypeError Message: Argument 1 passed to
Cart\Events\OrderWasCreated::__construct() must be an instance of
Cart\Models\Order, integer given, called in
/Applications/AMPPS/www/testshop.dev/cart/app/Controllers/OrderController.php
on line 160 File:
/Applications/AMPPS/www/testshop.dev/cart/app/Events/OrderWasCreated.php
Line: 17
My ordercontroller with the payment class - looks like this:
<?php
namespace Cart\Controllers;
use Slim\Router;
use Slim\Views\Twig;
use Cart\Basket\Basket;
use Cart\Models\Order;
use Cart\Models\Product;
use Cart\Models\Address;
use Cart\Models\Delivery;
use Cart\Models\Customer;
use Cart\Controllers\MailController;
use Cart\Validation\Contracts\ValidatorInterface;
use Cart\Validation\Forms\OrderForm;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Braintree_transaction;
class OrderController
{
protected $basket;
protected $mailcontroller;
protected $router;
protected $validator;
public function __construct(Basket $basket, Mailcontroller $mailcontroller, Router $router, ValidatorInterface $validator)
{
$this->basket = $basket;
$this->mailcontroller = $mailcontroller;
$this->router = $router;
$this->validator = $validator;
}
public function index(Request $request, Response $response, Twig $view)
{
$this->basket->refresh();
if (!$this->basket->subTotal()) {
return $response->withRedirect($this->router->pathFor('cart.index'));
}
return $view->render($response, 'order/index.twig');
}
public function show($hash, Request $request, Response $response, twig $view, Order $order)
{
$order = $order->with('address', 'products')->where('hash', $hash)->first();
$this->mailcontroller->mailLisbeth($hash);
if (!$order) {
return $response->withRedirect($this->router->pathFor('home'));
}
return $view->render($response, 'order/show.twig', [
'order' => $order,
]);
}
public function create(Request $request, Response $response, Customer $customer, Address $address, Delivery $delivery, Order $order)
{
$this->basket->refresh();
$validation = $this->validator->validate($request, OrderForm::rules());
if (!$this->basket->subTotal()) {
return $response->withRedirect($this->router->pathFor('cart.index'));
}
if ($validation->fails()) {
return $response->withRedirect($this->router->pathFor('order.index'));
}
$hash = bin2hex(random_bytes(32));
$customer = $customer->firstOrCreate([
'email' => $request->getParam('email'),
'name' => $request->getParam('name'),
]);
$delivery = $delivery->firstOrCreate([
'delivery' => $request->getParam('delivery'),
'deliverydate' => $request->getParam('deliverydate'),
'deliverytime' => $request->getParam('deliverytime'),
]);
$address = $address->firstOrCreate([
'address1' => $request->getParam('address1'),
'address2' => $request->getParam('address2'),
'city' => $request->getParam('city'),
'postal_code' => $request->getParam('postal_code'),
]);
$order = $customer->orders()->create([
'hash' => $hash,
'accepted' => "2",
'paid' => false,
'total' => $this->basket->subTotal() + 150,
]);
$address->order()->save($order);
$delivery->order()->save($order);
$allItems = $this->basket->all();
$order->products()->saveMany(
$allItems,
$this->getQuantities($allItems)
);
$event = new \Cart\Events\OrderWasCreated($order, $this->basket);
$event->attach([
// new \Cart\Handlers\MarkOrderPaid,
// new \Cart\Handlers\RecordSuccessfulPayment($result->transaction->id),
new \Cart\Handlers\UpdateStock,
new \Cart\Handlers\Emptybasket,
]);
$event->dispatch();
return $view->render($response, 'order/show.twig', [
'order' => $order,
]);
}
//
public function payment($slug, Request $request, Response $response, twig $view, Customer $customer, Address $address, Delivery $delivery, Order $order)
{
$order = $order->with('address', 'products')->where('id', $slug)->first();
// var_dump($order);
// die();
// if (!$request->getParam('payment_method_nonce')) {
// return $response->withRedirect($this->router->pathFor('order.index'));
// }
$order = $customer->orders()->update([
'paid' => true,
]);
$result = Braintree_Transaction::sale([
'amount' => $this->basket->subTotal() + 150,
'paymentMethodNonce' => $request->getParam('payment_method_nonce'),
'options' => [
'submitForSettlement' => true,
]
]);
$event = new \Cart\Events\OrderWasCreated($order, $this->basket);
if (!$result->success) {
$event->attach(new \Cart\Handlers\RecordFailedPayment);
$event->dispatch();
return $response->withRedirect($this->router->pathFor('order.index'));
}
$event->attach([
new \Cart\Handlers\MarkOrderPaid,
new \Cart\Handlers\RecordSuccessfulPayment($result->transaction->id),
// new \Cart\Handlers\UpdateStock,
// new \Cart\Handlers\Emptybasket,
]);
}
protected function getQuantities($items)
{
$quantities = [];
foreach ($items as $item) {
$quantities[] = ['quantity' => $item->quantity];
}
return $quantities;
}
}
The error occures on line 160:
$event = new \Cart\Events\OrderWasCreated($order, $this->basket);
because you invoke Cart\Events\OrderWasCreated constructor, which requires instance of Cart\Models\Order class as first argument. Instead your first argument ($order) is integer.
Now latest assignment of $order is on line 147:
$order = $customer->orders()->update([
'paid' => true,
]);
I'll have a guess and say that this is an operation that returns integer as result (be that a simple 1/0 success/fauilure or the id of the order being updated). Are you sure that you need that? Asking because:
You are assigning $order a value on line 138:
$order = $order->with('address', 'products')->where('id', $slug)->first();
And you're passing $order as an argument to the OrderController::payment.
So, my guess is: you want to remove lines 138 and 147.
Recently, I've been working on a system using the Phalcon PHP framework. And up until now, it's been plain sailing.
I seem to be having an issue when pulling data from a MySQL database using a model. Everything else seems to be working fine, but a few fields are returning empty data despite there being data within those fields in the MySQL table.
After scanning the database itself, I can't seem to find the reason why these particular fields are empty because similar fields are returned with the data intact.
I've inserted the model data into an array to make it easier for me to browse it and find out what's going on, and this is the result:
[applications] =>
[application_id] => 5
[application_user] => 1
[application_servers] => skybuild
[application_approved] =>
[application_denied] =>
[application_reviewed] =>
[application_approvals] => 0
[application_denials] => 0
[application_date] => 1470739996
[application_message] => This is just a test application to see whether the system is working.
[user] =>
[user_id] => 1
[user_fname] => Leo
[user_lname] => **********
[user_birthday] => ****-**-**
[user_email] => **********#**********.**.**
[user_uname] => Leo_V117
[user_upass] => ********************************
[user_account] => ********-****-****-****-************
[user_active] => Y
[user_banned] =>
[user_suspended] =>
[user_registered] =>
The fields in question are:
application
application_approved
application_denied
application_reviewed
user
user_banned
user_suspended
user_registered
The question is:
WHY are these particular fields returning empty data and, ultimately, HOW can I go about fixing it.
PHP Code
Bootstrap
<?php ########################
##############################
use Phalcon\Mvc\Application;
error_reporting(E_ALL);
try {
/**
* Define some useful constants
*/
define('BASE_DIR', dirname(__DIR__));
define('APP_DIR', BASE_DIR . '/app');
\Phalcon\Mvc\Model::setup(array(
'notNullValidations' => false
));
/**
* Read the configuration
*/
$config = include APP_DIR . '/config/config.php';
/**
* Read auto-loader
*/
include APP_DIR . '/config/loader.php';
/**
* Read services
*/
include APP_DIR . '/config/services.php';
/**
* Handle the request
*/
$application = new Application($di);
echo $application->handle()->getContent();
} catch (Exception $e) {
echo '<pre>';
print_r ( $e->getMessage() );
print_r ( nl2br( htmlentities( $e->getTraceAsString() ) ) );
echo '</pre>';
}
##############################
########################### ?>
Accounts
<?php ########################
##############################
namespace ProjectRogue\Models;
use Phalcon\Mvc\Model;
use Phalcon\Mvc\Model\Validator\Uniqueness;
class Accounts extends Model {
public $user_id; // User ID
public $user_fname; // Field: First Name
public $user_lname; // Field: Last Name
public $user_birthday; // Field: Date of Birth
public $user_email; // Field: E-Mail
public $user_uname; // Field: Username
public $user_upass; // Field: Password
public $user_account; // Minecraft Account UUID
public $user_active; // Active
public $user_banned; // Banned
public $user_suspended; // Suspended
public $user_registered;
public function beforeValidationOnCreate() {
$this->user_active = 'N';
$this->user_banned = 'N';
$this->user_suspended = 'N';
$this->user_code = $this->generateCode();
$this->user_registered = time();
}
public function afterSave() {
if( $this->user_active == 'N' ) {
// Check E-Mail Status;
$email = new EmailConfirmation();
$email->email_user = $this->user_id;
$email->email_code = $this->generateCode();
$email->email_created = date("Y-m-d H:i:s", time());
if( $email->save() ) {
$this->getDI()->getFlash()->notice('A confirmation E-Mail has been sent to '.$this->user_email);
}
// Send Commands;
$service_servers = new ServiceServers();
$service_commands = array();
$servers = $service_servers::find();
$json_response['data']['servers_size'] = count($servers);
foreach( $servers as $server ) {
$service_commands[ $server->server_id ] = new ServiceCommands();
// Insert Data;
$service_commands[ $server->server_id ]->assign(array(
'command_server' => $server->server_token,
'command_body' => 'broadcast &6&l[player]&r &fhas just registered an account to our website!',
'command_player' => $this->user_account,
'command_player_online' => 'Y'
));
// Save;
$service_commands[ $server->server_id ]->save();
}
}
}
public function validation() {
$this->validate(new Uniqueness(array(
'field' => 'user_uname',
'message' => 'This Username is already in use.'
)));
$this->validate(new Uniqueness(array(
'field' => 'user_email',
'message' => 'This E-Mail is already in use.'
)));
$this->validate(new Uniqueness(array(
'field' => 'user_account',
'message' => 'This Minecraft Account is already in use.'
)));
return $this->validationHasFailed() != true;
}
}
##############################
########################### ?>
ApplicationStaff
<?php ########################
##############################
namespace ProjectRogue\Models;
use Phalcon\Mvc\Model;
use Phalcon\Mvc\Model\Validator\Uniqueness;
class ApplicationsStaff extends Model {
public $application_id; // Application ID;
public $application_user; // Application User;
public $application_servers; // Application Servers;
public $application_approved;
public $application_denied;
public $application_reviewed;
public $application_approvals; // Application Approvals;
public $application_denials; // Application Denials;
public $application_date; // Application Date;
public $application_message; // Application Message;
public function beforeValidationOnCreate() {
$this->application_date = time();
$this->application_approvals = 0;
$this->application_denials = 0;
$this->application_approved = "N";
$this->application_denied = "N";
$this->application_reviewed = "N";
}
public function validation() {
return $this->validationHasFailed() != true;
}
}
##############################
########################### ?>
It actually turns out that the data from each model was cached in my service. Deleting said cache forced the models to return the data as expected.
I'm new to Payum. A lot thing quite confuse to me. I'm try to build up a simple paypal express checkout like the example show on the Payum document.However, when I tried to process the payment, it shows up an exception:
"Payum payment named my_paypal_express_checkout does not exist.
500 Internal Server Error - InvalidArgumentException"
Here is the config:
payum:
security:
token_storage:
Acme\PaymentBundle\Entity\PayumSecurityToken:
doctrine:
driver: orm
storages:
Acme\PaymentBundle\Entity\PaymentDetails:
doctrine:
driver: orm
contexts:
Ibase_paypal_express:
paypal_express_checkout_nvp:
...codes...
Here are the code of prepare and done action in controller:
public function preparePaypalAction(Request $request)
{
$paymentName = 'ibase_paypal_express_checkout';
$form = $this->createPurchaseForm();
$form->handleRequest($request);
if ($form->isValid()) {
$data = $form->getData();
$storage = $this->get('payum')->getStorage('Ibase\PaymentBundle\Entity\PaymentDetails');
/** #var \Ibase\CartBundle\Entity\PaymentDetails $paymentDetails */
$paymentDetails = $storage->createModel();
$paymentDetails['PAYMENTREQUEST_0_CURRENCYCODE'] = $data['currency'];
$paymentDetails['PAYMENTREQUEST_0_AMT'] = $data['amount'];//total amount ??
$storage->updateModel($paymentDetails);
$captureToken = $this->get('payum.security.token_factory')->createCaptureToken(
$paymentName,
$paymentDetails,
'payment_done' // the route to redirect after capture;
);
$paymentDetails['INVNUM'] = $paymentDetails->getId();
$paymentDetails['RETURNURL'] = $captureToken->getTargetUrl();
$paymentDetails['CANCELURL'] = $captureToken->getTargetUrl();
$storage->updateModel($paymentDetails);
return $this->redirect($captureToken->getTargetUrl());
}
return $this->render('PaymentBundle:PaypalExpress:paypalPrepare.html.twig', array(
'form' => $form->createView(),
'paymentName' => $paymentName
));
}
public function doneAction(Request $request)
{
$token = $this->get('payum.security.http_request_verifier')->verify($request);
$payment = $this->get('payum')->getPayment($token->getPaymentName());
$status = new BinaryMaskStatusRequest($token);
$payment->execute($status);
if ($status->isSuccess()) {
$this->getUser()->addCredits(100);
$this->get('session')->getFlashBag()->set(
'notice',
'Payment success. Credits were added'
);
} else if ($status->isPending()) {
$this->get('session')->getFlashBag()->set(
'notice',
'Payment is still pending. Credits were not added'
);
} else {
$this->get('session')->getFlashBag()->set('error', 'Payment failed');
}
return $this->redirect('home');
}
/**
* #return \Symfony\Component\Form\Form
*/
protected function createPurchaseForm()
{
return $this->createFormBuilder()
->add('amount', null, array(
'data' => 1,
'constraints' => array(new Range(array('max' => 2)))
))
->add('currency', null, array('data' => 'AUD'))
->getForm()
;
}
Anyone can help will be appreciate!
Look at your YML file
contexts:
Ibase_paypal_express:
and your code :
$paymentName = 'ibase_paypal_express_checkout';
Notice the capital 'I' and string name? Those two names/values should be the same.
So either
$paymentName = 'Ibase_paypal_express';
or
contexts:
ibase_paypal_express_checkout: