/** * 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()); }
/** * (non-PHPdoc) * @see \JMS\Payment\CoreBundle\Plugin\AbstractPlugin::checkPaymentInstruction() */ public function checkPaymentInstruction(PaymentInstructionInterface $paymentInstruction) { // TODO: use validators $errorBuilder = new ErrorBuilder(); $extendedData = $paymentInstruction->getExtendedData(); // if (!$extendedData->has('price')) { // $errorBuilder->addDataError('price', 'form.error.required'); // } // if ($extendedData->get('price')<=0) { // $errorBuilder->addDataError('price', 'form.error.invalid'); // } // if (!$extendedData->has('currency')) { // $errorBuilder->addDataError('currency', 'form.error.required'); // } // if (!$extendedData->has('orderId')) { // $errorBuilder->addDataError('orderId', 'form.error.required'); // } // if (!$extendedData->has('posData')) { // $errorBuilder->addDataError('posData', 'form.error.required'); // } // if (!$extendedData->has('options')) { // $errorBuilder->addDataError('options', 'form.error.required'); // } if ($errorBuilder->hasErrors()) { throw $errorBuilder->getException(); } }
/** * 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; }
public function checkPaymentInstruction(PaymentInstructionInterface $instruction) { $errorBuilder = new ErrorBuilder(); /** * @var \JMS\Payment\CoreBundle\Entity\ExtendedData $data */ $data = $instruction->getExtendedData(); if (!$data->get('bank')) { $errorBuilder->addDataError('data_multisafepay_ideal.bank', 'form.error.bank_required'); } if ($errorBuilder->hasErrors()) { throw $errorBuilder->getException(); } }
/** * This method checks whether all required parameters exist in the given * PaymentInstruction, and whether they are syntactically correct. * * This method is meant to perform a fast parameter validation; no connection * to any payment back-end system should be made at this stage. * * In case, this method is not implemented. The PaymentInstruction will * be considered to be valid. * * @param PaymentInstructionInterface $instruction * * @throws \JMS\Payment\CoreBundle\Plugin\Exception\InvalidPaymentInstructionException if the the PaymentInstruction is not valid */ public function checkPaymentInstruction(PaymentInstructionInterface $instruction) { // define form validators $constraints = new Assert\Collection(array('name' => array(new Assert\NotBlank(array('message' => 'Required'))), 'number' => array(new Assert\NotBlank(array('message' => 'Required')), new Assert\Length(array('min' => 12, 'max' => 19, 'minMessage' => 'Invalid card number 1', 'maxMessage' => 'Invalid card number 2')), new Assert\Luhn(array('message' => 'Invalid card number'))), 'exp_month' => array(new Assert\NotBlank(array('message' => 'Required')), new Assert\Range(array('min' => 1, 'max' => 12, 'minMessage' => 'Invalid code value', 'maxMessage' => 'Invalid code value'))), 'exp_year' => array(new Assert\NotBlank(array('message' => 'Required')), new Assert\Range(array('min' => date('Y'), 'max' => date('Y', strtotime('+20 years')), 'minMessage' => 'Invalid date', 'maxMessage' => 'Invalid date'))), 'cvc' => array(new Assert\NotBlank(array('message' => 'Required')), new Assert\Length(array('min' => 3, 'max' => 4, 'minMessage' => 'Invalid code value', 'maxMessage' => 'Invalid code value'))), 'address_line1' => array(new Assert\NotBlank(array('message' => 'Required'))), 'address_line2' => array(), 'address_city' => array(new Assert\NotBlank(array('message' => 'Required'))), 'address_state' => array(new Assert\NotBlank(array('message' => 'Required'))), 'address_country' => array(new Assert\NotBlank(array('message' => 'Required'))), 'address_zip' => array(new Assert\NotBlank(array('message' => 'Required'))))); // extract form values from extended data $dateToValidate = array(); foreach ($constraints->fields as $name => $constraint) { $dateToValidate[$name] = $instruction->getExtendedData()->get($name); } // validate input data $errors = $this->validator->validateValue($dateToValidate, $constraints); // transform validator errors into payment exceptions $errorBuilder = new ErrorBuilder(); foreach ($errors as $error) { // KLUDGE: remove [] around field name $field = substr($error->getPropertyPath(), 1, -1); $errorBuilder->addDataError('data_stripe_credit_card.' . $field, $error->getMessage()); } if ($errorBuilder->hasErrors()) { throw $errorBuilder->getException(); } }
/** * @param PaymentInstructionInterface $paymentInstruction * @param string $operation * @return string */ private function buildFile(PaymentInstructionInterface $paymentInstruction, $operation = self::PAYMENT) { $this->logger->info('Building INV file...'); $file = $this->ogoneFileBuilder->buildInv($paymentInstruction->getExtendedData()->get('ORDERID'), $paymentInstruction->getExtendedData()->get('CLIENTID'), $paymentInstruction->getExtendedData()->get('CLIENTREF'), $paymentInstruction->getExtendedData()->get('ALIASID'), $operation, $paymentInstruction->getExtendedData()->get('ARTICLES'), $paymentInstruction->getExtendedData()->get('PAYID')); $this->logger->info('INV file content is {content}', array('content' => $file)); return $file; }
protected function onUnsuccessfulPaymentInstructionValidation(PaymentInstructionInterface $instruction, PluginInvalidPaymentInstructionException $invalid) { $instruction->setState(PaymentInstructionInterface::STATE_INVALID); $result = $this->buildPaymentInstructionResult($instruction, Result::STATUS_FAILED, PluginInterface::REASON_CODE_INVALID); $result->setPluginException($invalid); return $result; }
/** * This method checks whether all required parameters exist in the given * PaymentInstruction, and whether they are syntactically correct. * * This method is meant to perform a fast parameter validation; no connection * to any payment back-end system should be made at this stage. * * In case, this method is not implemented. The PaymentInstruction will * be considered to be valid. * * @param PaymentInstructionInterface $paymentInstruction * * @throws \JMS\Payment\CoreBundle\Plugin\Exception\InvalidPaymentInstructionException if the the PaymentInstruction is not valid */ public function checkPaymentInstruction(PaymentInstructionInterface $paymentInstruction) { $errorBuilder = new ErrorBuilder(); if (!$paymentInstruction->getExtendedData()->has('lang')) { $errorBuilder->addDataError('lang', 'form.error.required'); } if ($errorBuilder->hasErrors()) { throw $errorBuilder->getException(); } }
/** * @param PaymentInstructionInterface $paymentInstruction * * @throws \JMS\Payment\CoreBundle\Plugin\Exception\InvalidPaymentInstructionException */ public function checkPaymentInstruction(PaymentInstructionInterface $paymentInstruction) { $errorBuilder = new ErrorBuilder(); $data = $paymentInstruction->getExtendedData(); // TODO Check requirements here if ($errorBuilder->hasErrors()) { throw $errorBuilder->getException(); } }