/** * @Transform /^"([^"]+)" payment(s)?$/ */ public function getPaymentMethodByName($paymentMethodName) { $paymentMethod = $this->paymentMethodRepository->findOneByName($paymentMethodName); if (null === $paymentMethod) { throw new \InvalidArgumentException(sprintf('Payment method with name "%s" does not exist.', $paymentMethodName)); } return $paymentMethod; }
/** * {@inheritdoc} */ public function getDefaultPaymentMethod(PaymentInterface $payment) { $paymentMethods = $this->paymentMethodRepository->findBy(['enabled' => true]); if (empty($paymentMethods)) { throw new UnresolvedDefaultPaymentMethodException(); } return $paymentMethods[0]; }
/** * @Given the store allows paying :paymentMethodName * @Given the store allows paying with :paymentMethodName */ public function storeAllowsPaying($paymentMethodName) { $paymentMethod = $this->paymentMethodFactory->createNew(); $paymentMethod->setCode('PM_' . $paymentMethodName); $paymentMethod->setName(ucfirst($paymentMethodName)); $paymentMethod->setGateway($this->paymentMethodNameToGatewayConverter->convert($paymentMethodName)); $paymentMethod->setDescription('Payment method'); $channel = $this->sharedStorage->get('channel'); $channel->addPaymentMethod($paymentMethod); $this->paymentMethodRepository->add($paymentMethod); }
/** * @param string $name * @param string $code * @param bool $addForCurrentChannel * @param string $description */ private function createPaymentMethodFromNameAndCode($name, $code, $description = '', $addForCurrentChannel = true) { /** @var PaymentMethodInterface $paymentMethod */ $paymentMethod = $this->paymentMethodFactory->createNew(); $paymentMethod->setName(ucfirst($name)); $paymentMethod->setCode($code); $paymentMethod->setGateway($this->paymentMethodNameToGatewayConverter->convert($name)); $paymentMethod->setDescription($description); if ($addForCurrentChannel && $this->sharedStorage->has('channel')) { $channel = $this->sharedStorage->get('channel'); $channel->addPaymentMethod($paymentMethod); } $this->sharedStorage->set('payment_method', $paymentMethod); $this->paymentMethodRepository->add($paymentMethod); }
function it_throws_exception_if_there_are_no_enabled_payment_methods(PaymentMethodRepositoryInterface $paymentMethodRepository, PaymentInterface $payment) { $paymentMethodRepository->findBy(['enabled' => true])->willReturn([]); $this->shouldThrow(UnresolvedDefaultPaymentMethodException::class)->during('getDefaultPaymentMethod', [$payment]); }
/** * @Given the store has a payment method :paymentMethodName with a code :paymentMethodCode */ public function theStoreHasAPaymentMethodWithACode($paymentMethodName, $paymentMethodCode) { $paymentMethod = $this->createPaymentMethodFromNameAndCode($paymentMethodName, $paymentMethodCode); $this->sharedStorage->set('payment_method', $paymentMethod); $this->paymentMethodRepository->add($paymentMethod); }
/** * @Transform /^"([^"]+)" payment(s)?$/ * @Transform :paymentMethod */ public function getPaymentMethodByName($paymentMethodName) { $paymentMethod = $this->paymentMethodRepository->findOneByName($paymentMethodName); Assert::notNull($paymentMethod, sprintf('Payment method with name "%s" does not exist', $paymentMethodName)); return $paymentMethod; }
/** * @Transform :paymentMethod */ public function getPaymentMethodByName($name) { $paymentMethod = $this->paymentMethodRepository->findOneByName($name); Assert::notNull($paymentMethod, sprintf('Cannot find payment method named %s', $name)); return $paymentMethod; }
function it_throws_element_not_found_exception_if_payment_method_has_not_been_found(PaymentMethodRepositoryInterface $paymentMethodRepository) { $paymentMethodRepository->findOneByName('Free')->willReturn(null); $this->shouldThrow(\InvalidArgumentException::class)->during('getPaymentMethodByName', ['Free']); }
/** * @Transform /^"([^"]+)" payment(s)?$/ * @Transform :paymentMethod */ public function getPaymentMethodByName($paymentMethodName) { $paymentMethods = $this->paymentMethodRepository->findByName($paymentMethodName, 'en_US'); Assert::eq(1, count($paymentMethods), sprintf('%d payment methods has been found with name "%s".', count($paymentMethods), $paymentMethodName)); return $paymentMethods[0]; }