Attempted to call method "getClientId" on class "ArrayObject" - payum

I'm using Payum 0.12 + Paypal Express Checkout and got this error on complete action:
Attempted to call method "getClientId" on class "ArrayObject" in
DetailsController.php on line...
Here is controller code:
<?php
namespace Custom\CustomBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Payum\Core\Registry\RegistryInterface;
use Payum\Core\Security\HttpRequestVerifierInterface;
use Payum\Core\Exception\RequestNotSupportedException;
use Payum\Core\Model\OrderInterface;
use Payum\Core\Request\GetHumanStatus;
use Payum\Core\Request\Sync;
class DetailsController extends Controller
{
public function completeAction(Request $request) {
$token = $this->get('payum.security.http_request_verifier')->verify($request);
$payment = $this->get('payum')->getPayment($token->getPaymentName());
try {
$payment->execute(new Sync($token));
} catch (RequestNotSupportedException $e) {}
$payment->execute($status = new GetHumanStatus($token));
/** #var OrderInterface $order */
$order = $status->getModel();
return $this->render('CustomBundle:Default:complete.html.twig', array(
'status' => $status->getValue(),
'order' => htmlspecialchars(json_encode(
array(
'client' => array(
'id' => $order->getClientId(), //<--- Error here
'email' => $order->getClientEmail(),
),
'number' => $order->getNumber(),
'description' => $order->getCurrencyCode(),
'total_amount' => $order->getTotalAmount(),
'currency_code' => $order->getCurrencyCode(),
'currency_digits_after_decimal_point' => $order->getCurrencyDigitsAfterDecimalPoint(),
'details' => $order->getDetails(),
),
JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE
)),
'paymentTitle' => ucwords(str_replace(array('_', '-'), ' ', $token->getPaymentName()))
));
}
}
Even if i use 'offline' payment option without Paypal Exress Checkout, i'm getting this error. Am i missing something maybe?

Related

Sendmail Subject in Laravel 5.1

I want send email with subject using variable , this is code
public function sendmail(Request $request)
{
$data = [
'subject' => $request->input('subject'),
'name' => $request->input('name'),
'phone' => $request->input('phone'),
'email' => $request->input('email')
];
Mail::send('mail.sendmail' , $data, function($msg){
$msg->from('mygmail.com', 'Avil');
$msg->to('mygmail#gmail.com', 'Avil')->subject('Welcome to Laravel 5.1');
});
return redirect()->route('contact.index');
}
I wanna subject not "Welcome to Laravel 5.1", Subject is
public function sendmail(Request $request)
{
$data = [
'subject' => $request->input('subject'),
'name' => $request->input('name'),
'phone' => $request->input('phone'),
'email' => $request->input('email')
];
Mail::send('mail.sendmail' , $data, function($msg){
$msg->from('mygmail#gmail.com', 'Hung Nguyen');
$msg->to('mygmail#gmail.com', 'Hung Manh')->subject($data['subject']);
});
return redirect()->route('contact.index');
}
When I running display error :
Undefined variable: data
Please help me. Thank you so much
You have to pass along $data to the callback in your send method. Refer the line where Mail façade is used.
public function sendmail(Request $request)
{
$data = [
'subject' => $request->input('subject'),
'name' => $request->input('name'),
'phone' => $request->input('phone'),
'email' => $request->input('email')
];
Mail::send('mail.sendmail' , function($msg) use($data){
$msg->from('mygmail#gmail.com', 'Hung Nguyen');
$msg->to('mygmail#gmail.com', 'Hung Manh')->subject($data['subject']);
});
return redirect()->route('contact.index');
}

Transform forms from Symfony2 to Symfony3

I want to transform a form like this to comply with Symfony3 code :
$form = $this->createForm(new AjoutQC(array('idcolle' => $idColle,'idqc' => $question->getId())),
$question,
array('action' => $this->generateUrl('paces_colle_qc_update',
array(
'id' => $question->getId(),
'idColle' => $idColle,
'idTuteur' => $idTuteur)
),
'method' => 'PUT',
));
$form->add('submit', SubmitType::class, array('label' => 'Sauvegarder'));
Symfony3 asks for something like :
AjoutQC::class
instead of :
new AjoutQC...
I didn't find anything about it after some research.
Check these upgrade notes for forms.
It says:
Passing type instances to Form::add(), FormBuilder::add() and the FormFactory::create*() methods is not supported anymore. Pass the fully-qualified class name of the type instead.
Before:
$form = $this->createForm(new MyType());
After:
$form = $this->createForm(MyType::class);
You can use OptionsResolver and pass your data array('idcolle' => $idColle,'idqc' => $question->getId()) that you are currently passing to your form type as a third argument to createForm method:
$form = $this->createForm(AjoutQC::class, $question, array(
'action' => $this->generateUrl('paces_colle_qc_update', array(
'id' => $question->getId(),
'idColle' => $idColle,
'idTuteur' => $idTuteur,
)),
'method' => 'PUT',
'idcolle' => $idColle,
'idqc' => $question->getId(),
));
Then in your AjoutQC type you need to do something like:
use Symfony\Component\OptionsResolver\OptionsResolver;
// ..
public function buildForm(FormBuilderInterface $builder, array $options)
{
$this->idcolle = $options['idcolle'];
$this->idqc = $options['idqc'];
$builder
->add(...)
// ..
;
}
// ..
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setRequired(array('idcolle', 'idqc'));
}
This will set idcolle, idqc options as required, that must be passed to your form type (AjoutQC).
In Symfony 3 you need to use FQCN (fully-qualified class name) instead of an instance of the form (or a string reference to a service).
$form = $this->createForm(
AjoutQC::class,
$question,
array(
'action' => $this->generateUrl(
'paces_colle_qc_update',
array(
'id' => $question->getId(),
'idColle' => $idColle,
'idTuteur' => $idTuteur
)
),
'method' => 'PUT',
'idColle' => $idColle,
'idQc' => $question->getId()
)
)
In your AjoutQC class you need to go to your configureOptions method and add the idcolle and idqc options:
class AjoutQC extends AbstractType {
/**
* #param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setRequired(array('idColle','idQc'));
$resolver->setDefaults(
array(
'data_class' => 'Your\Entity\Path',
'idColle' => null,
'idQc' => null
)
);
}
}
If you are just wondering about the ::class notation, you can find information about that here: http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.class.class
::class requires php >= 5.5
If you are using <5.5 you can just simply use the FQCN e.g. MyLong\Namespace\Fully\Qualified\ClassNameType

Zend Framework 2 - Gobal Variable that are accessible to controller/model that are initialize in local.php or global.php

Hello everyone please someone help me how to create a global variable in zend framework 2 to be use in table prefix that are accessible in controller and model.
Thanks and regards to all.
In your config/database.local.php you can define which you want globally
<?
return array(
'service_manager' => array(
'factories' => array(
//'Zend\Db\Adapter\Adapter' => 'Zend\Db\Adapter\AdapterServiceFactory',
'Zend\Db\Adapter\Adapter' => function ($serviceManager) {
$adapterFactory = new Zend\Db\Adapter\AdapterServiceFactory();
$adapter = $adapterFactory->createService($serviceManager);
\Zend\Db\TableGateway\Feature\GlobalAdapterFeature::setStaticAdapter($adapter);
return $adapter;
}
),
),
'db' => array(
'driver' => 'pdo',
'dsn' => 'mysql:dbname=testdb;host=localhost',
'username' => 'root',
'password' => '',
),
'msg' => array(
'add' => 'Data Inserted Successfully',
'edit' => 'Data Updated Successfully',
'delete' => 'Data Deleted Successfully',
),
);
?>
Controller File:
DemoController.php
<?php
namespace Demo\Controller;
use Zend\Mvc\Controller\AbstractActionController;
class DemoController extends AbstractActionController
{
public function indexAction($cms_page_name='whyus')
{
/*Call config file to fetch current cms page id-- fetch config file from database.local.php*/
$config = $this->getServiceLocator()->get('Config');
$all_msg = $config['msg'];
}
}
?>

Cake PHP custom validation rule

I got a problem with a custom validation rule in Cake 2.X
I want to check if the entered zipcode is valid and therefore a function in the class zipcode is called from the class post.
But the validation returns false all the time.
Appmodel in class post (rule-3 is it):
'DELIVERYAREA' => array(
'rule-1' => array(
'rule' => array('between', 5, 5),
'message' => 'Bitte eine fünfstellige Postleitzahl eingeben'
),
'rule-2' => array(
'rule' => 'Numeric',
'message' => 'Bitte nur Zahlen eingeben'
),
'rule-3' => array(
'exists' => array(
'rule' => 'ZipExists',
'message' => 'Postleitzahl existiert nicht!'
)
)
),
Appmodel in class zipcode:
class Zipcode extends AppModel {
var $name = 'Zipcode';
var $validate = array(
'zipcode' => array(
'length' => array(
'rule' => array('maxLength', 5),
'message' => 'Bitte einen Text eingeben'
),
'exists' => array(
'rule' => array('ZipExists'),
'message' => 'Postleitzahl existiert nicht!'
)
)
);
function ZipExists($zipcode){
$valid = $this->find('count', array('conditions'=> array('Zipcode.zipcode' =>$zipcode)));
if ($valid >= 1){
return true;
}
else{
return false;
}
}
I hope it´s something stupidly easy?
Thanks in advance
I think this:
'Zipcode.zipcode' =>$zipcode
...needs to be this:
'Zipcode.zipcode' =>$zipcode['zipcode']
Careful what you expect inside the validation rule. Use debug() etc to find out what exactly is coming in. $data is always an array here.
public function zipExists($data) {
$zipcode = array_shift($data); // use the value of the key/value pair
$code = $this->find('first', array('conditions'=> array('Zipcode.zipcode' =>$zipcode)));
return !empty($code);
}
try this for only model validation.
function ZipExists(){
$valid = $this->find('count', array('conditions'=> array('Zipcode.zipcode' =>$this->data['Zipcode']['zipcode'])));
if ($valid >= 1){
return true;
}
else{
return false;
}
I found the solution.
Cake wants the custom validation rules to be in the certain class where the rule is called. So, when you call a custom rule in class post, the custom function has to be written down in class post, otherwise cake won´t find it and validate it to false everytime.
The magic to do here is to import the appmodel-class you want to use in the class you call the validation-function. That works with the following statement:
$Zipcode = ClassRegistry::init('Class to use - in my case "Zipcode"');
But if your tables are associated with each other with hasAny or belongsTo and stuff, the custom function works without that. Another important point you mustn´t miss is, that all validation functions has to be introduced with "public function xyz" otherwise cake won´t find them too.

Get all parameters after action in Zend?

When I call a router like below in Zend:
coupon/index/search/cat/1/page/1/x/111/y/222
And inside the controller when I get $this->_params, I get an array:
array(
'module' => 'coupon',
'controller' => 'index',
'action' => 'search',
'cat' => '1',
'page' => '1',
'x' => '111',
'y' => '222'
)
But I want to get only:
array(
'cat' => '1',
'page' => '1',
'x' => '111',
'y' => '222'
)
Could you please tell me a way to get the all the params just after the action?
IMHO this is more elegant and includes changes in action, controller and method keys.
$request = $this->getRequest();
$diffArray = array(
$request->getActionKey(),
$request->getControllerKey(),
$request->getModuleKey()
);
$params = array_diff_key(
$request->getUserParams(),
array_flip($diffArray)
);
As far as I know, you will always get the controller, action and module in the params list as it is part of the default. You could do something like this to remove the three from the array you get:
$url_params = $this->getRequest()->getUserParams();
if(isset($url_params['controller']))
unset($url_params['controller']);
if(isset($url_params['action']))
unset($url_params['action']);
if (isset($url_params['module']))
unset($url_params['module']);
Alternatively as you don't want to be doing that every time you need the list, create a helper to do it for you, something like this:
class Helper_Myparams extends Zend_Controller_Action_Helper_Abstract
{
public $params;
public function __construct()
{
$request = Zend_Controller_Front::getInstance()->getRequest();
$this->params = $request->getParams();
}
public function myparams()
{
if(isset($this->params['controller']))
unset($this->params['controller']);
if(isset($this->params['action']))
unset($this->params['action']);
if (isset($this->params['module']))
unset($this->params['module']);
return $this->params;
}
public function direct()
{
return $this->myparams();
}
}
And you can simply call this from your controller to get the list:
$this->_helper->myparams();
So for example using the url:
http://127.0.0.1/testing/urls/cat/1/page/1/x/111/y/222
And the code:
echo "<pre>";
print_r($this->_helper->myparams());
echo "</pre>";
I get the following array printed:
Array
(
[cat] => 1
[page] => 1
[x] => 111
[y] => 222
)
How about this?
In controller:
$params = $this->getRequest()->getParams();
unset($params['module'];
unset($params['controller'];
unset($params['action'];
Pretty clunky; might need some isset() checks to avoid warnings; could jam this segment into its own method or helper. But it would do the job, right?