I need to make payment transaction for an application and I saw JSMPaymentCoreBundle.
I read the documentation of JSMPaymentCoreBundel but I wonder me how I can pass object to the controller detailsAction(Order $order) and completeAction(Order $order).
For example, in the detailAction controller, the redirect response looks like this :
return new RedirectResponse($this->router->generate('payment_complete', array('orderNumber' => $order->getOrderNumber(),)));
For me, we don"t pass the required Order object in param to the completeAction controller below but only orderNumer:
/**
* @Route("/{orderNumber}/complete", name = "payment_complete")
*/
public function completeAction(Order $order){
...
}
I think that if I don't pass an Order object, I'll get error. So what is the best way to do that and how ?
New in development and Symfony, I really want to understand and not simply make a copy/paste.
Any help would be appreciate.
You can use @ParamConverter annotation to conver an orderNumber to its entity
http://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/converters.html
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
...
/**
* @Route("/{orderNumber}/complete", name = "payment_complete")
* @ParamConverter("order", options={"mapping": {"orderNumber": "orderNumber"}})
*/
public function completeAction(Order $order){
...
}
Update: read your question again and little bit confused. So do you have a problem (error) to get $order or do you just confused why you pass OrderNumber, but getting Order entity?
If so,just ignore my first example that do same as shown:
/**
* @Route("/{orderNumber}/details", name = "payment_details")
* @Template
*/
public function detailsAction(Order $order)
It means that ParameterConverter will do a magic for your to convert passed orderNumber to an entity Order, that actually is "best practice" approach recommended by Symfony doc: http://symfony.com/doc/2.3/best_practices/controllers.html#using-the-paramconverter
And you do not need to add an additional annotation for such case
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With