/** * Process Paypal IPN response to payment. * * When the IPN mesage is validated, a payment success event * should be dispatched. * * @param int $orderId Order Id * @param array $parameters parameter array coming from Paypal IPN notification * * @throws ParameterNotReceivedException * @throws PaymentException */ public function processPaypalIPNMessage($orderId, array $parameters) { /** * Retrieving the order object. */ $order = $this->paymentBridge->findOrder($orderId); if (!$order) { throw new PaymentOrderNotFoundException(sprintf('Order #%s not found', $orderId)); } $this->paymentBridge->setOrder($order); /** * Check that we receive the mandatory parameters. */ $this->checkResultParameters($parameters); /** * Initializing PaypalWebCheckoutMethod, which is * an object representation of the payment information * coming from the payment processor. */ $paypalMethod = $this->paymentMethodFactory->create($parameters['mc_gross'], $parameters['payment_status'], $parameters['notify_version'], $parameters['payer_status'], $parameters['business'], null, $parameters['verify_sign'], $parameters['payer_email'], $parameters['txn_id'], $parameters['payment_type'], $parameters['receiver_email'], null, $parameters['txn_type'], null, $parameters['mc_currency'], null, $parameters['test_ipn'], $parameters['ipn_track_id']); /** * Notifying payment.done, which means that the * payment has been received, although we still * do not know if it is succesful or not. * Listening fot this event is useful when one * wants to record transaction informations. */ $this->paymentEventDispatcher->notifyPaymentOrderDone($this->paymentBridge, $paypalMethod); /** * Check if the transaction is successful. */ if (!$this->transactionSuccessful($parameters)) { $this->paymentEventDispatcher->notifyPaymentOrderFail($this->paymentBridge, $paypalMethod); throw new PaymentException(); } /** * Payment paid successfully. * * Paid process has ended successfully */ $this->paymentEventDispatcher->notifyPaymentOrderSuccess($this->paymentBridge, $paypalMethod); }