예제 #1
0
 /**
  * Complete a payment by creating a transaction using Paymill's API, i.e.
  * call JMSPaymentCore's approveAndDeposit method.
  *
  * @param PaymentInstructionInterface $instruction  PaymentInstruction instance
  * @param string                      $successRoute The name of the route to redirect the user
  *                                                  when payment is successful
  * @param array                       $routeParams  The params to construct the url from the route
  *
  * @return JsonResponse
  */
 protected function completePayment(PaymentInstructionInterface $instruction, $route, $routeParams = array())
 {
     $ppc = $this->get('payment.plugin_controller');
     $translator = $this->get('translator');
     if (null === ($pendingTransaction = $instruction->getPendingTransaction())) {
         $amount = $instruction->getAmount() - $instruction->getDepositedAmount();
         $payment = $ppc->createPayment($instruction->getId(), $amount);
     } else {
         $payment = $pendingTransaction->getPayment();
     }
     $result = $ppc->approveAndDeposit($payment->getId(), $payment->getTargetAmount());
     if (Result::STATUS_SUCCESS === $result->getStatus()) {
         // payment was successful
         $response = array('error' => false, 'successUrl' => $this->generateUrl($route, $routeParams));
     } else {
         $response = array('error' => true, 'message' => $translator->trans('default', array(), 'errors'), 'code' => $result->getFinancialTransaction()->getReasonCode());
         // We might have a better error message
         if (null !== $response['code']) {
             $translated = $translator->trans($response['code'], array(), 'errors');
             if ($translated != $response['code']) {
                 $response['message'] = $translated;
             }
         }
     }
     return new JsonResponse($response);
 }
예제 #2
0
 /**
  * @param PaymentInstructionInterface $instruction
  * @param $ogonePlugin
  * @return mixed
  * @throws NoPendingTransactionException
  */
 private function init(PaymentInstructionInterface $instruction, $ogonePlugin)
 {
     if (null === ($pendingTransaction = $instruction->getPendingTransaction())) {
         throw new NoPendingTransactionException(sprintf('[Ogone - callback] no pending transaction found for the payment instruction [%d]', $instruction->getId()));
     }
     foreach ($this->feedbackResponse->getValues() as $field => $value) {
         $pendingTransaction->getExtendedData()->set($field, $value);
     }
     $ogonePlugin->setFeedbackResponse($this->feedbackResponse);
     $pendingTransaction->setReferenceNumber($this->feedbackResponse->getPaymentId());
     return $pendingTransaction;
 }