/**
  * Complete payment
  *
  * @param Payment_transaction $transaction
  * @param ResponseInterface $response
  *
  * @throws \RuntimeException
  */
 public function complete(Payment_transaction $transaction, ResponseInterface $response)
 {
     if (!$transaction->isPending()) {
         throw new RuntimeException('Can complete only pending transaction.');
     }
     if (!$response->isSuccessful()) {
         throw new RuntimeException('Can process only success response.');
     }
     $infoExtractor = $this->infoExtractorFactory->create($response);
     $updateData = array('updated' => time(), 'status' => Payment_transaction::STATUS_COMPLETED, 'test_mode' => $infoExtractor->isTestMode(), 'payment_id' => $infoExtractor->getPaymentId());
     $transaction->from_array($updateData);
     $transaction->save();
     $this->processTarget($transaction);
 }
 public function __construct(ResponseInterface $response)
 {
     $this->response = $response;
     $this->responseData = $this->response->getData();
 }
Exemple #3
0
 /**
  * Process Omnipay Response
  *
  * @param OmnipayResponseInterface $response
  * @param Payment_transaction $transaction
  */
 protected function processResponse(OmnipayResponseInterface $response, Payment_transaction $transaction)
 {
     if ($response->isSuccessful()) {
         $this->get('core.payment.transactions.manager')->complete($transaction, $response);
         $redirectResponse = RedirectResponse::create(site_url('payment/success'));
         $this->sendResponse($transaction, $redirectResponse);
     } elseif ($response->isRedirect()) {
         $response->redirect();
         // this will automatically forward the customer
     } else {
         show_error($response->getMessage());
     }
 }
 /**
  * @param Market_TransactionModel $transaction
  * @param ResponseInterface       $response
  *
  * @throws Exception
  */
 private function updateTransaction(Market_TransactionModel $transaction, ResponseInterface $response)
 {
     if ($response->isSuccessful()) {
         $transaction->status = Market_TransactionRecord::SUCCESS;
     } elseif ($response->isRedirect()) {
         $transaction->status = Market_TransactionRecord::REDIRECT;
     } else {
         $transaction->status = Market_TransactionRecord::FAILED;
     }
     $transaction->reference = $response->getTransactionReference();
     $transaction->message = $response->getMessage();
     if ($response->isSuccessful()) {
         craft()->market_order->updateOrderPaidTotal($transaction->order);
     }
     $this->saveTransaction($transaction);
 }