public function testPurchaseReturn() { $request = $this->gateway->completePurchase(array('amount' => '10.00')); $this->assertInstanceOf('Omnipay\\Mollie\\Message\\CompletePurchaseRequest', $request); $this->assertSame('10.00', $request->getAmount()); }
public function approveAndDeposit(FinancialTransactionInterface $transaction, $retry) { if ($transaction->getState() === FinancialTransactionInterface::STATE_NEW) { throw $this->createMollieRedirectActionException($transaction); } if (null !== ($trackingId = $transaction->getTrackingId())) { $response = $this->gateway->completePurchase(array('transactionReference' => $trackingId))->send(); if ($this->logger) { $this->logger->info('TransactionStatus: Status=' . $response->getStatus() . ", TransactionId=" . $response->getTransactionReference() . ", " . json_encode($response->getData())); } if ($response->isSuccessful()) { $transaction->setReferenceNumber($response->getTransactionReference()); $transaction->setProcessedAmount($response->getAmount()); $transaction->setResponseCode(PluginInterface::RESPONSE_CODE_SUCCESS); $transaction->setReasonCode(PluginInterface::REASON_CODE_SUCCESS); $data = $response->getData(); if (!empty($data['details'])) { if (!empty($data['details']['consumerName'])) { $transaction->getExtendedData()->set('consumer_name', $data['details']['consumerName']); } if (!empty($data['details']['consumerAccount'])) { $transaction->getExtendedData()->set('consumer_account_number', $data['details']['consumerAccount']); } } if ($this->logger) { $this->logger->info(sprintf('Payment is successful for transaction "%s".', $response->getTransactionReference())); } return; } if ($response->isCancelled()) { $ex = new FinancialException('Payment cancelled.'); $ex->setFinancialTransaction($transaction); $transaction->setResponseCode('CANCELLED'); $transaction->setReasonCode('CANCELLED'); $transaction->setState(FinancialTransactionInterface::STATE_CANCELED); if ($this->logger) { $this->logger->info(sprintf('Payment cancelled for transaction "%s".', $response->getTransactionReference())); } throw $ex; } if ($response->isExpired()) { $ex = new FinancialException('Payment expired.'); $ex->setFinancialTransaction($transaction); $transaction->setResponseCode('EXPIRED'); $transaction->setReasonCode('EXPIRED'); $transaction->setState(FinancialTransactionInterface::STATE_FAILED); if ($this->logger) { $this->logger->info(sprintf('Payment is expired for transaction "%s".', $response->getTransactionReference())); } throw $ex; } if ($response->isRedirect()) { $ex = new ActionRequiredException('Redirect the user to Mollie.'); $ex->setFinancialTransaction($transaction); $ex->setAction(new VisitUrl($response->getRedirectUrl())); if ($this->logger) { $this->logger->info(sprintf('Create a new redirect exception for transaction "%s".', $response->getTransactionReference())); } throw $ex; } if ($this->logger) { $this->logger->info(sprintf('Waiting for notification from Mollie for transaction "%s".', $response->getTransactionReference())); } throw new BlockedException("Waiting for notification from Mollie."); } $ex = new FinancialException('Payment failed.'); $ex->setFinancialTransaction($transaction); $transaction->setResponseCode('FAILED'); $transaction->setReasonCode('FAILED'); $transaction->setState(FinancialTransactionInterface::STATE_FAILED); throw $ex; }