-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[payum][paypal] add suppor of instant notifactions. #725
Changes from 2 commits
c7e6838
9f2d1cd
c60fd42
3b2750d
5e28b37
41d9d92
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Paweł Jędrzejewski | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sylius\Bundle\PayumBundle\Payum\Paypal\Action; | ||
|
||
use Payum\Core\Action\PaymentAwareAction; | ||
use Payum\Core\Exception\RequestNotSupportedException; | ||
use Payum\Core\Request\SecuredNotifyRequest; | ||
use Payum\Core\Request\SyncRequest; | ||
use Sylius\Bundle\CoreBundle\Model\OrderInterface; | ||
use Sylius\Bundle\PaymentsBundle\SyliusPaymentEvents; | ||
use Sylius\Bundle\PayumBundle\Payum\Request\StatusRequest; | ||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
use Symfony\Component\EventDispatcher\GenericEvent; | ||
|
||
class NotifyOrderAction extends PaymentAwareAction | ||
{ | ||
/** | ||
* @var EventDispatcherInterface | ||
*/ | ||
protected $eventDispatcher; | ||
|
||
/** | ||
* @param EventDispatcherInterface $eventDispatcher | ||
*/ | ||
public function __construct(EventDispatcherInterface $eventDispatcher) | ||
{ | ||
$this->eventDispatcher = $eventDispatcher; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function execute($request) | ||
{ | ||
/** @var $request SecuredNotifyRequest */ | ||
if (!$this->supports($request)) { | ||
throw RequestNotSupportedException::createActionNotSupported($this, $request); | ||
} | ||
|
||
/** @var OrderInterface $order */ | ||
$order = $request->getModel(); | ||
$payment = $order->getPayment(); | ||
$previousState = $payment->getState(); | ||
|
||
$this->payment->execute(new SyncRequest($order)); | ||
|
||
$status = new StatusRequest($order); | ||
$this->payment->execute($status); | ||
$payment->setState($status->getStatus()); | ||
|
||
if ($previousState !== $payment->getState()) { | ||
$this->eventDispatcher->dispatch( | ||
SyliusPaymentEvents::PRE_STATE_CHANGE, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a question: is there already a listener listening this event and which actually confirms the order (send shipments, etc.)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I dont aware of any, @pjedrzejewski do you? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @winzou There is none. I assume you mean inventory updates only when order is paid, hm? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pjedrzejewski Yes. We really need to clean all these events (between |
||
new GenericEvent($order->getPayment(), array('previous_state' => $previousState)) | ||
); | ||
|
||
$this->eventDispatcher->dispatch( | ||
SyliusPaymentEvents::POST_STATE_CHANGE, | ||
new GenericEvent($order->getPayment(), array('previous_state' => $previousState)) | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function supports($request) | ||
{ | ||
return | ||
$request instanceof SecuredNotifyRequest && | ||
$request->getModel() instanceof OrderInterface | ||
; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
<parameter key="sylius.payum.checkout_step.purchase.class">Sylius\Bundle\PayumBundle\Checkout\Step\PurchaseStep</parameter> | ||
<parameter key="sylius.payum.paypal.action.capture_order_using_express_checkout.class">Sylius\Bundle\PayumBundle\Payum\Paypal\Action\CaptureOrderUsingExpressCheckoutAction</parameter> | ||
<parameter key="sylius.payum.stripe.action.capture_order_using_credit_card.class">Sylius\Bundle\PayumBundle\Payum\Stripe\Action\CaptureOrderUsingCreditCardAction</parameter> | ||
<parameter key="sylius.payum.paypal.action.notify_order.class">Sylius\Bundle\PayumBundle\Payum\Stripe\Action\NotifyOrderAction</parameter> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @makasim Should be Paypal\Action\NotifyOrderAction, not Stripe :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kayue indeed! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
<parameter key="sylius.payum.be2bill.action.capture_order_using_credit_card.class">Sylius\Bundle\PayumBundle\Payum\Be2bill\Action\CaptureOrderUsingCreditCardAction</parameter> | ||
<parameter key="sylius.payum.dummy.action.capture_order.class">Sylius\Bundle\PayumBundle\Payum\Dummy\Action\CaptureOrderAction</parameter> | ||
<parameter key="sylius.payum.dummy.action.order_status.class">Sylius\Bundle\PayumBundle\Payum\Dummy\Action\OrderStatusAction</parameter> | ||
|
@@ -35,7 +36,12 @@ | |
</call> | ||
<tag name="sylius.process.step" alias="sylius_checkout_purchase" /> | ||
</service> | ||
<service id="sylius.payum.paypal.action.capture_order_using_express_checkout" class="%sylius.payum.paypal.action.capture_order_using_express_checkout.class%" /> | ||
<service id="sylius.payum.paypal.action.capture_order_using_express_checkout" class="%sylius.payum.paypal.action.capture_order_using_express_checkout.class%"> | ||
<argument type="service" id="payum.security.token_factory" /> | ||
</service> | ||
<service id="sylius.payum.paypal.action.notify_order" class="%sylius.payum.paypal.action.notify_order.class%"> | ||
<argument type="service" id="event_dispatcher" /> | ||
</service> | ||
<service id="sylius.payum.stripe.action.capture_order_using_credit_card" class="%sylius.payum.stripe.action.capture_order_using_credit_card.class%" /> | ||
<service id="sylius.payum.be2bill.action.capture_order_using_credit_card" class="%sylius.payum.be2bill.action.capture_order_using_credit_card.class%"> | ||
<call method="setRequest"> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be done between the 2 dispatched events (pre and post), right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually not, The pre and post events expect to get new state from payment object where the previous one passed as an event parameter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant: what is the point of dispatching 2 events with exact same parameters? (the $order and $previousState variables don't vary)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here it mean 'just to be compatible". Pre event means before we actually saved anything to db, so you can change state to another one, post event means we cannot change anything in payment object.
Since the save will be done later (when we return from this action) we cannot do save between pre and post without injecting extra dependency. To keep things simple I decided to dispatch events so you can change state in post event too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So maybe just dispatch the "pre" event then, to avoid any confusion
Le 15 janv. 2014 15:58, "Maksim Kotlyar" notifications@github.com a écrit
:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@winzou I dont think its a good idea, One can have a listener subscribed to post event (let's say it sends an email to admin) and he would be surprised to see its not working. IMO it is better to dispatch both.