/** * @param PaymentMethodInterface $method * @param integer $amount * * @throws PaymentException */ public function processPayment(PaymentMethodInterface $method, $amount) { /** * @var RedsysApiMethod $method */ $paymentData = array('number' => $method->getCreditCartNumber(), 'holder' => $method->getCreditCartOwner(), 'expiration' => sprintf('%s%s', substr($method->getCreditCartExpirationYear(), -2, 2), str_pad($method->getCreditCartExpirationMonth(), 2, '0', STR_PAD_LEFT)), 'cvc' => $method->getCreditCartSecurity(), 'amount' => $amount); $this->setPayment($paymentData); try { $r = $this->_callSoap(); } catch (\Exception $e) { /* * The Soap call failed */ $this->eventDispatcher->notifyPaymentOrderFail($this->paymentBridge, $method); throw new PaymentException($e->getMessage()); } $this->storeTransaction($r); $this->eventDispatcher->notifyPaymentOrderLoad($this->paymentBridge, $method); if (!$this->isAuthorized($r)) { $this->paymentBridge->setError($this->getError($r)); $this->paymentBridge->setErrorCode($this->getErrorCode($r)); /** * The payment was not successful */ $this->eventDispatcher->notifyPaymentOrderFail($this->paymentBridge, $method); throw new PaymentException($this->getErrorCode($r)); } /* * Everything is ok, emitting the * payment.order.create event */ $transaction = $this->getResponseData($r); $method->setTransactionId($transaction['DS_AUTHORISATIONCODE'])->setTransactionStatus('paid')->setTransactionResponse($transaction); $this->eventDispatcher->notifyPaymentOrderCreated($this->paymentBridge, $method); /* * Return if we are only authorizing, meaning * we don't have to fire a payment success * event */ if ($this->transactionType == '1') { return; } /** * Payment process has returned control */ $this->eventDispatcher->notifyPaymentOrderDone($this->paymentBridge, $method); /** * Payment paid successfully * * Paid process has ended successfully */ $this->eventDispatcher->notifyPaymentOrderSuccess($this->paymentBridge, $method); }