/** * test the URLC callback action * * @param PaymentInstructionInterface $paymentInstruction * * @depends testNewPaymentInstruction */ public function testUrlcAction(PaymentInstructionInterface $paymentInstruction) { $route = $this->get('router')->generate('ets_payment_dotpay_callback_urlc', array('id' => $paymentInstruction->getId()), true); static::$client->request('POST', $route, array('id' => 424242, 't_id' => '424242-TST1', 'control' => '', 'orginal_amount' => '42.00 EUR', 'amount' => 42.0, 'email' => '*****@*****.**', 'description' => 'Test transaction', 't_status' => DotpayDirectPlugin::STATUS_NEW, 'code' => '', 'service' => '', 'md5' => md5(sprintf("%s:%s:%s:%s:%s:%s:%s:%s:%s:%s:%s", $this->getContainer()->getParameter('payment.dotpay.direct.pin'), $this->getContainer()->getParameter('payment.dotpay.direct.id'), '', '424242-TST1', 42.0, '*****@*****.**', '', '', '', '', DotpayDirectPlugin::STATUS_NEW)))); $this->assertTrue(static::$client->getResponse()->isSuccessful(), static::$client->getResponse()->getContent()); $this->assertEquals('OK', static::$client->getResponse()->getContent()); }
/** * 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); }
/** * @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; }
/** * @param PaymentInstructionInterface $paymentInstruction * @throws InvalidPaymentInstructionException */ public function validatePaymentInstruction(PaymentInstructionInterface $paymentInstruction) { $this->logger->debug('validating payment instruction {id}...', array('id' => $paymentInstruction->getId())); try { $file = $this->buildFile($paymentInstruction, self::AUTHORIZATION); $this->logger->debug('Sending authorization request to Ogone with file {file}', array('file' => $file)); $xmlResponse = $this->sendBatchRequest($file); $response = new BatchResponse($xmlResponse); $this->logger->debug('response status is {status}', array('status' => $response->getStatus())); if (!$response->hasError() && $response->isIncomplete()) { $paymentInstruction->getExtendedData()->set('PAYID', $response->getPaymentId()); } else { throw new \LogicException(sprintf('status %s, description %s.', $response->getStatus(), $response->getErrorDescription())); } } catch (\Exception $e) { $this->logger->error(sprintf('Authorization failed: %s.', $e->getMessage())); throw new InvalidPaymentInstructionException($e->getMessage(), $e->getCode()); } }