mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-16 01:47:49 +00:00
[payum] Payum 1.0 upgrade
This commit is contained in:
parent
091525df5a
commit
857e717283
37 changed files with 970 additions and 1655 deletions
33
app/migrations/Version20151028183600.php
Normal file
33
app/migrations/Version20151028183600.php
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Sylius\Migrations;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Migrations\AbstractMigration;
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto-generated Migration: Please modify to your needs!
|
||||||
|
*/
|
||||||
|
class Version20151028183600 extends AbstractMigration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param Schema $schema
|
||||||
|
*/
|
||||||
|
public function up(Schema $schema)
|
||||||
|
{
|
||||||
|
$this->addSql("ALTER TABLE sylius_payment_security_token CHANGE payment_name gateway_name VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '';");
|
||||||
|
$this->addSql("ALTER TABLE sylius_payment_config CHANGE payment_name gateway_name VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '';");
|
||||||
|
$this->addSql('RENAME TABLE `sylius_payment_config` TO `sylius_gateway_config`;');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Schema $schema
|
||||||
|
*/
|
||||||
|
public function down(Schema $schema)
|
||||||
|
{
|
||||||
|
$this->addSql("ALTER TABLE payment_name gateway_name CHANGE sylius_payment_security_token VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '';");
|
||||||
|
$this->addSql("ALTER TABLE payment_name gateway_name CHANGE sylius_payment_config VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '';");
|
||||||
|
$this->addSql('RENAME TABLE `sylius_gateway_config` TO `sylius_payment_config`;');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -48,9 +48,9 @@
|
||||||
"knplabs/knp-snappy-bundle": "~1.2",
|
"knplabs/knp-snappy-bundle": "~1.2",
|
||||||
"liip/imagine-bundle": "~1.0",
|
"liip/imagine-bundle": "~1.0",
|
||||||
"omnipay/omnipay": "~2.3",
|
"omnipay/omnipay": "~2.3",
|
||||||
"payum/omnipay-bridge": "~0.14.0",
|
"payum/omnipay-bridge": "~1.0",
|
||||||
"payum/payum": "~0.14.0",
|
"payum/payum": "~1.0",
|
||||||
"payum/payum-bundle": "~0.14.2",
|
"payum/payum-bundle": "~1.0",
|
||||||
"sensio/distribution-bundle": "~2.3",
|
"sensio/distribution-bundle": "~2.3",
|
||||||
"stof/doctrine-extensions-bundle": "~1.1",
|
"stof/doctrine-extensions-bundle": "~1.1",
|
||||||
"swiftmailer/swiftmailer": "~5.0",
|
"swiftmailer/swiftmailer": "~5.0",
|
||||||
|
|
|
||||||
851
composer.lock
generated
851
composer.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -16,10 +16,9 @@ use Payum\Core\Security\GenericTokenFactoryInterface;
|
||||||
use Payum\Core\Security\HttpRequestVerifierInterface;
|
use Payum\Core\Security\HttpRequestVerifierInterface;
|
||||||
use Sylius\Bundle\CoreBundle\Event\PurchaseCompleteEvent;
|
use Sylius\Bundle\CoreBundle\Event\PurchaseCompleteEvent;
|
||||||
use Sylius\Bundle\FlowBundle\Process\Context\ProcessContextInterface;
|
use Sylius\Bundle\FlowBundle\Process\Context\ProcessContextInterface;
|
||||||
use Sylius\Bundle\PayumBundle\Payum\Request\GetStatus;
|
use Sylius\Bundle\PayumBundle\Request\GetStatus;
|
||||||
use Sylius\Component\Core\Model\PaymentInterface;
|
use Sylius\Component\Core\Model\PaymentInterface;
|
||||||
use Sylius\Component\Core\SyliusCheckoutEvents;
|
use Sylius\Component\Core\SyliusCheckoutEvents;
|
||||||
use Sylius\Component\Payment\PaymentTransitions;
|
|
||||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||||
|
|
||||||
class PurchaseStep extends CheckoutStep
|
class PurchaseStep extends CheckoutStep
|
||||||
|
|
@ -55,22 +54,15 @@ class PurchaseStep extends CheckoutStep
|
||||||
$this->getHttpRequestVerifier()->invalidate($token);
|
$this->getHttpRequestVerifier()->invalidate($token);
|
||||||
|
|
||||||
$status = new GetStatus($token);
|
$status = new GetStatus($token);
|
||||||
$this->getPayum()->getPayment($token->getPaymentName())->execute($status);
|
$this->getPayum()->getGateway($token->getGatewayName())->execute($status);
|
||||||
|
|
||||||
/** @var $payment PaymentInterface */
|
/** @var $payment PaymentInterface */
|
||||||
$payment = $status->getFirstModel();
|
$payment = $status->getFirstModel();
|
||||||
$order = $payment->getOrder();
|
$order = $payment->getOrder();
|
||||||
|
|
||||||
|
// Should it be here??
|
||||||
$this->dispatchCheckoutEvent(SyliusCheckoutEvents::PURCHASE_INITIALIZE, $order);
|
$this->dispatchCheckoutEvent(SyliusCheckoutEvents::PURCHASE_INITIALIZE, $order);
|
||||||
|
|
||||||
$nextState = $status->getValue();
|
|
||||||
|
|
||||||
$stateMachine = $this->get('sm.factory')->get($payment, PaymentTransitions::GRAPH);
|
|
||||||
|
|
||||||
if (null !== $transition = $stateMachine->getTransitionToState($nextState)) {
|
|
||||||
$stateMachine->apply($transition);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->dispatchCheckoutEvent(SyliusCheckoutEvents::PURCHASE_PRE_COMPLETE, $order);
|
$this->dispatchCheckoutEvent(SyliusCheckoutEvents::PURCHASE_PRE_COMPLETE, $order);
|
||||||
|
|
||||||
$this->getDoctrine()->getManager()->flush();
|
$this->getDoctrine()->getManager()->flush();
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,11 @@ payum:
|
||||||
token_storage:
|
token_storage:
|
||||||
Sylius\Bundle\PayumBundle\Model\PaymentSecurityToken: { doctrine: orm }
|
Sylius\Bundle\PayumBundle\Model\PaymentSecurityToken: { doctrine: orm }
|
||||||
|
|
||||||
dynamic_payments:
|
dynamic_gateways:
|
||||||
config_storage:
|
config_storage:
|
||||||
Sylius\Bundle\PayumBundle\Model\PaymentConfig: { doctrine: orm }
|
Sylius\Bundle\PayumBundle\Model\GatewayConfig: { doctrine: orm }
|
||||||
|
|
||||||
payments:
|
gateways:
|
||||||
paypal_express_checkout:
|
paypal_express_checkout:
|
||||||
paypal_express_checkout_nvp:
|
paypal_express_checkout_nvp:
|
||||||
username: %paypal.express_checkout.username%
|
username: %paypal.express_checkout.username%
|
||||||
|
|
@ -37,12 +37,4 @@ payum:
|
||||||
secret_key: %stripe.secret_key%
|
secret_key: %stripe.secret_key%
|
||||||
|
|
||||||
dummy:
|
dummy:
|
||||||
custom:
|
offline: ~
|
||||||
actions:
|
|
||||||
- sylius.payum.dummy.action.capture_payment
|
|
||||||
- sylius.payum.dummy.action.payment_status
|
|
||||||
|
|
||||||
offline:
|
|
||||||
offline:
|
|
||||||
actions:
|
|
||||||
- sylius.payum.offline.action.capture_payment
|
|
||||||
|
|
@ -12,21 +12,17 @@
|
||||||
namespace spec\Sylius\Bundle\CoreBundle\Checkout\Step;
|
namespace spec\Sylius\Bundle\CoreBundle\Checkout\Step;
|
||||||
|
|
||||||
use Doctrine\Common\Persistence\ObjectManager;
|
use Doctrine\Common\Persistence\ObjectManager;
|
||||||
use Payum\Core\PaymentInterface;
|
use Payum\Core\GatewayInterface;
|
||||||
use Payum\Core\Registry\RegistryInterface;
|
use Payum\Core\Registry\RegistryInterface;
|
||||||
use Payum\Core\Security\HttpRequestVerifierInterface;
|
use Payum\Core\Security\HttpRequestVerifierInterface;
|
||||||
use Payum\Core\Security\TokenInterface;
|
use Payum\Core\Security\TokenInterface;
|
||||||
use PhpSpec\ObjectBehavior;
|
use PhpSpec\ObjectBehavior;
|
||||||
use Prophecy\Argument;
|
use Prophecy\Argument;
|
||||||
use SM\Factory\FactoryInterface;
|
|
||||||
use Sylius\Bundle\FlowBundle\Process\Context\ProcessContextInterface;
|
use Sylius\Bundle\FlowBundle\Process\Context\ProcessContextInterface;
|
||||||
use Sylius\Component\Cart\Provider\CartProviderInterface;
|
use Sylius\Component\Cart\Provider\CartProviderInterface;
|
||||||
use Sylius\Component\Core\Model\Order;
|
use Sylius\Component\Core\Model\Order;
|
||||||
use Sylius\Component\Core\Model\Payment;
|
use Sylius\Component\Core\Model\Payment;
|
||||||
use Sylius\Component\Core\SyliusCheckoutEvents;
|
use Sylius\Component\Core\SyliusCheckoutEvents;
|
||||||
use Sylius\Component\Payment\PaymentTransitions;
|
|
||||||
use Sylius\Component\Payment\SyliusPaymentEvents;
|
|
||||||
use Sylius\Component\Resource\StateMachine\StateMachineInterface;
|
|
||||||
use Symfony\Bridge\Doctrine\RegistryInterface as DoctrinRegistryInterface;
|
use Symfony\Bridge\Doctrine\RegistryInterface as DoctrinRegistryInterface;
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
|
|
@ -46,19 +42,18 @@ class PurchaseStepSpec extends ObjectBehavior
|
||||||
Request $request,
|
Request $request,
|
||||||
CartProviderInterface $cartProvider,
|
CartProviderInterface $cartProvider,
|
||||||
RegistryInterface $payum,
|
RegistryInterface $payum,
|
||||||
PaymentInterface $payment,
|
GatewayInterface $gateway,
|
||||||
EventDispatcherInterface $eventDispatcher,
|
EventDispatcherInterface $eventDispatcher,
|
||||||
DoctrinRegistryInterface $doctrine,
|
DoctrinRegistryInterface $doctrine,
|
||||||
ObjectManager $objectManager,
|
ObjectManager $objectManager,
|
||||||
Session $session,
|
Session $session,
|
||||||
FlashBagInterface $flashBag,
|
FlashBagInterface $flashBag,
|
||||||
TranslatorInterface $translator,
|
TranslatorInterface $translator
|
||||||
FactoryInterface $factory
|
|
||||||
) {
|
) {
|
||||||
$session->getFlashBag()->willReturn($flashBag);
|
$session->getFlashBag()->willReturn($flashBag);
|
||||||
$doctrine->getManager()->willReturn($objectManager);
|
$doctrine->getManager()->willReturn($objectManager);
|
||||||
$token->getPaymentName()->willReturn('aPaymentName');
|
$token->getGatewayName()->willReturn('aGatewayName');
|
||||||
$payum->getPayment('aPaymentName')->willReturn($payment);
|
$payum->getGateway('aGatewayName')->willReturn($gateway);
|
||||||
$httpRequestVerifier->verify($request)->willReturn($token);
|
$httpRequestVerifier->verify($request)->willReturn($token);
|
||||||
$httpRequestVerifier->invalidate($token)->willReturn(null);
|
$httpRequestVerifier->invalidate($token)->willReturn(null);
|
||||||
|
|
||||||
|
|
@ -70,7 +65,6 @@ class PurchaseStepSpec extends ObjectBehavior
|
||||||
$container->get('doctrine')->willReturn($doctrine);
|
$container->get('doctrine')->willReturn($doctrine);
|
||||||
$container->has('doctrine')->willReturn(true);
|
$container->has('doctrine')->willReturn(true);
|
||||||
$container->get('translator')->willReturn($translator);
|
$container->get('translator')->willReturn($translator);
|
||||||
$container->get('sm.factory')->willReturn($factory);
|
|
||||||
|
|
||||||
$this->setName('purchase');
|
$this->setName('purchase');
|
||||||
|
|
||||||
|
|
@ -89,11 +83,9 @@ class PurchaseStepSpec extends ObjectBehavior
|
||||||
|
|
||||||
function it_must_dispatch_pre_and_post_payment_state_changed_if_state_changed(
|
function it_must_dispatch_pre_and_post_payment_state_changed_if_state_changed(
|
||||||
Request $request,
|
Request $request,
|
||||||
$factory,
|
|
||||||
ProcessContextInterface $context,
|
ProcessContextInterface $context,
|
||||||
PaymentInterface $payment,
|
GatewayInterface $gateway,
|
||||||
EventDispatcherInterface $eventDispatcher,
|
EventDispatcherInterface $eventDispatcher
|
||||||
StateMachineInterface $sm
|
|
||||||
) {
|
) {
|
||||||
$context->getRequest()->willReturn($request);
|
$context->getRequest()->willReturn($request);
|
||||||
|
|
||||||
|
|
@ -103,18 +95,14 @@ class PurchaseStepSpec extends ObjectBehavior
|
||||||
$paymentModel->setOrder($order);
|
$paymentModel->setOrder($order);
|
||||||
$order->addPayment($paymentModel);
|
$order->addPayment($paymentModel);
|
||||||
|
|
||||||
$payment
|
$gateway
|
||||||
->execute(Argument::type('Sylius\Bundle\PayumBundle\Payum\Request\GetStatus'))
|
->execute(Argument::type('Sylius\Bundle\PayumBundle\Request\GetStatus'))
|
||||||
->will(function ($args) use ($order, $paymentModel) {
|
->will(function ($args) use ($order, $paymentModel) {
|
||||||
$args[0]->markCaptured();
|
$args[0]->markCaptured();
|
||||||
$args[0]->setModel($paymentModel);
|
$args[0]->setModel($paymentModel);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
$factory->get($paymentModel, PaymentTransitions::GRAPH)->willReturn($sm);
|
|
||||||
$sm->getTransitionToState('completed')->willReturn(PaymentTransitions::SYLIUS_COMPLETE);
|
|
||||||
$sm->apply(PaymentTransitions::SYLIUS_COMPLETE)->shouldBeCalled();
|
|
||||||
|
|
||||||
$eventDispatcher
|
$eventDispatcher
|
||||||
->dispatch(
|
->dispatch(
|
||||||
SyliusCheckoutEvents::PURCHASE_INITIALIZE,
|
SyliusCheckoutEvents::PURCHASE_INITIALIZE,
|
||||||
|
|
@ -144,11 +132,9 @@ class PurchaseStepSpec extends ObjectBehavior
|
||||||
|
|
||||||
function it_must_not_dispatch_pre_and_post_payment_state_changed_if_state_not_changed(
|
function it_must_not_dispatch_pre_and_post_payment_state_changed_if_state_not_changed(
|
||||||
Request $request,
|
Request $request,
|
||||||
$factory,
|
|
||||||
ProcessContextInterface $context,
|
ProcessContextInterface $context,
|
||||||
PaymentInterface $payment,
|
GatewayInterface $gateway,
|
||||||
EventDispatcherInterface $eventDispatcher,
|
EventDispatcherInterface $eventDispatcher
|
||||||
StateMachineInterface $sm
|
|
||||||
) {
|
) {
|
||||||
$context->getRequest()->willReturn($request);
|
$context->getRequest()->willReturn($request);
|
||||||
|
|
||||||
|
|
@ -158,18 +144,14 @@ class PurchaseStepSpec extends ObjectBehavior
|
||||||
$paymentModel->setOrder($order);
|
$paymentModel->setOrder($order);
|
||||||
$order->addPayment($paymentModel);
|
$order->addPayment($paymentModel);
|
||||||
|
|
||||||
$payment
|
$gateway
|
||||||
->execute(Argument::type('Sylius\Bundle\PayumBundle\Payum\Request\GetStatus'))
|
->execute(Argument::type('Sylius\Bundle\PayumBundle\Request\GetStatus'))
|
||||||
->will(function ($args) use ($order, $paymentModel) {
|
->will(function ($args) use ($order, $paymentModel) {
|
||||||
$args[0]->markCaptured();
|
$args[0]->markCaptured();
|
||||||
$args[0]->setModel($paymentModel);
|
$args[0]->setModel($paymentModel);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
$factory->get($paymentModel, PaymentTransitions::GRAPH)->willReturn($sm);
|
|
||||||
$sm->getTransitionToState('completed')->willReturn(null);
|
|
||||||
$sm->apply(PaymentTransitions::SYLIUS_COMPLETE)->shouldNotBeCalled();
|
|
||||||
|
|
||||||
$eventDispatcher
|
$eventDispatcher
|
||||||
->dispatch(
|
->dispatch(
|
||||||
SyliusCheckoutEvents::PURCHASE_INITIALIZE,
|
SyliusCheckoutEvents::PURCHASE_INITIALIZE,
|
||||||
|
|
|
||||||
|
|
@ -28,10 +28,10 @@ class LoadChannelData extends DataFixture
|
||||||
public function load(ObjectManager $manager)
|
public function load(ObjectManager $manager)
|
||||||
{
|
{
|
||||||
$url = $this->container->getParameter('router.request_context.host');
|
$url = $this->container->getParameter('router.request_context.host');
|
||||||
$manager->persist($this->createChannel('WEB-UK', 'UK Webstore', $url, array('en_GB'), array('GBP'), array('Category', 'Brand'), array('DHL', 'UPS Ground'), array('Dummy', 'StripeCheckout')));
|
$manager->persist($this->createChannel('WEB-UK', 'UK Webstore', $url, array('en_GB'), array('GBP'), array('Category', 'Brand'), array('DHL', 'UPS Ground'), array('Offline', 'StripeCheckout')));
|
||||||
$manager->persist($this->createChannel('WEB-DE', 'Germany Webstore', null, array('de_DE'), array('EUR'), array('Category', 'Brand'), array('DHL', 'UPS Ground'), array('Dummy', 'StripeCheckout')));
|
$manager->persist($this->createChannel('WEB-DE', 'Germany Webstore', null, array('de_DE'), array('EUR'), array('Category', 'Brand'), array('DHL', 'UPS Ground'), array('Offline', 'StripeCheckout')));
|
||||||
$manager->persist($this->createChannel('WEB-US', 'United States Webstore', null, array('en_US'), array('USD'), array('Category', 'Brand'), array('FedEx', 'FedEx World Shipping'), array('Dummy', 'StripeCheckout')));
|
$manager->persist($this->createChannel('WEB-US', 'United States Webstore', null, array('en_US'), array('USD'), array('Category', 'Brand'), array('FedEx', 'FedEx World Shipping'), array('Offline', 'StripeCheckout')));
|
||||||
$manager->persist($this->createChannel('MOBILE', 'Mobile Store', null, array('en_GB', 'de_DE'), array('GBP', 'USD', 'EUR'), array('Category', 'Brand'), array('DHL', 'UPS Ground', 'FedEx'), array('Dummy', 'StripeCheckout')));
|
$manager->persist($this->createChannel('MOBILE', 'Mobile Store', null, array('en_GB', 'de_DE'), array('GBP', 'USD', 'EUR'), array('Category', 'Brand'), array('DHL', 'UPS Ground', 'FedEx'), array('Offline', 'StripeCheckout')));
|
||||||
|
|
||||||
$manager->flush();
|
$manager->flush();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,6 @@ class LoadPaymentMethodsData extends DataFixture
|
||||||
$manager->persist($this->createPaymentMethod('Be2bill', 'be2bill_direct', 'fixed', array('amount' => 100)));
|
$manager->persist($this->createPaymentMethod('Be2bill', 'be2bill_direct', 'fixed', array('amount' => 100)));
|
||||||
$manager->persist($this->createPaymentMethod('Be2billOffsite', 'be2bill_offsite', 'percent', array('percent' => 7)));
|
$manager->persist($this->createPaymentMethod('Be2billOffsite', 'be2bill_offsite', 'percent', array('percent' => 7)));
|
||||||
$manager->persist($this->createPaymentMethod('StripeCheckout', 'stripe_checkout', 'percent', array('percent' => 5)));
|
$manager->persist($this->createPaymentMethod('StripeCheckout', 'stripe_checkout', 'percent', array('percent' => 5)));
|
||||||
$manager->persist($this->createPaymentMethod('Offline', 'offline', 'fixed', array('amount' => 500)));
|
|
||||||
|
|
||||||
$manager->flush();
|
$manager->flush();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,81 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Sylius package.
|
||||||
|
*
|
||||||
|
* (c) Paweł Jędrzejewski
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Sylius\Bundle\PayumBundle\Action;
|
||||||
|
|
||||||
|
use Payum\Core\Action\GatewayAwareAction;
|
||||||
|
use Payum\Core\Bridge\Spl\ArrayObject;
|
||||||
|
use Payum\Core\Exception\RequestNotSupportedException;
|
||||||
|
use Payum\Core\Model\Payment as PayumPayment;
|
||||||
|
use Payum\Core\Request\Capture;
|
||||||
|
use Payum\Core\Request\Convert;
|
||||||
|
use Sylius\Bundle\PayumBundle\Request\GetStatus;
|
||||||
|
use Sylius\Component\Core\Model\PaymentInterface as SyliusPaymentInterface;
|
||||||
|
|
||||||
|
class CapturePaymentAction extends GatewayAwareAction
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*
|
||||||
|
* @param $request Capture
|
||||||
|
*/
|
||||||
|
public function execute($request)
|
||||||
|
{
|
||||||
|
RequestNotSupportedException::assertSupports($this, $request);
|
||||||
|
|
||||||
|
/** @var $payment SyliusPaymentInterface */
|
||||||
|
$payment = $request->getModel();
|
||||||
|
$order = $payment->getOrder();
|
||||||
|
|
||||||
|
$this->gateway->execute($status = new GetStatus($payment));
|
||||||
|
if ($status->isNew()) {
|
||||||
|
try {
|
||||||
|
$this->gateway->execute($convert = new Convert($payment, 'array', $request->getToken()));
|
||||||
|
$payment->setDetails($convert->getResult());
|
||||||
|
} catch (RequestNotSupportedException $e) {
|
||||||
|
$payumPayment = new PayumPayment();
|
||||||
|
$payumPayment->setNumber($order->getNumber());
|
||||||
|
$payumPayment->setTotalAmount($order->getTotal());
|
||||||
|
$payumPayment->setCurrencyCode($order->getCurrency());
|
||||||
|
$payumPayment->setClientEmail($order->getCustomer()->getEmail());
|
||||||
|
$payumPayment->setClientId($order->getCustomer()->getId());
|
||||||
|
$payumPayment->setDescription(sprintf(
|
||||||
|
'Payment contains %d items for a total of %01.2f',
|
||||||
|
$order->getItems()->count(), $order->getTotal() / 100
|
||||||
|
));
|
||||||
|
$payumPayment->setDetails($payment->getDetails());
|
||||||
|
|
||||||
|
$this->gateway->execute($convert = new Convert($payumPayment, 'array', $request->getToken()));
|
||||||
|
$payment->setDetails($convert->getResult());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$details = ArrayObject::ensureArrayObject($payment->getDetails());
|
||||||
|
|
||||||
|
try {
|
||||||
|
$request->setModel($details);
|
||||||
|
$this->gateway->execute($request);
|
||||||
|
} finally {
|
||||||
|
$payment->setDetails((array) $details);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function supports($request)
|
||||||
|
{
|
||||||
|
return
|
||||||
|
$request instanceof Capture &&
|
||||||
|
$request->getModel() instanceof SyliusPaymentInterface
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -9,32 +9,35 @@
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Sylius\Bundle\PayumBundle\Payum\Be2bill\Action;
|
namespace Sylius\Bundle\PayumBundle\Action;
|
||||||
|
|
||||||
|
use Payum\Core\Action\GatewayAwareAction;
|
||||||
|
use Payum\Core\Exception\RequestNotSupportedException;
|
||||||
|
use Payum\Core\Request\Convert;
|
||||||
use Payum\Core\Request\GetHttpRequest;
|
use Payum\Core\Request\GetHttpRequest;
|
||||||
use Payum\Core\Security\TokenInterface;
|
use Sylius\Component\Core\Model\PaymentInterface;
|
||||||
use Sylius\Bundle\PayumBundle\Payum\Action\AbstractCapturePaymentAction;
|
|
||||||
use Sylius\Component\Payment\Model\PaymentInterface;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Alexandre Bacco <alexandre.bacco@gmail.com>
|
* @author Alexandre Bacco <alexandre.bacco@gmail.com>
|
||||||
*/
|
*/
|
||||||
class CapturePaymentUsingCreditCardAction extends AbstractCapturePaymentAction
|
class ConvertPaymentToBe2BillAction extends GatewayAwareAction
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
|
*
|
||||||
|
* @param Convert $request
|
||||||
*/
|
*/
|
||||||
protected function composeDetails(PaymentInterface $payment, TokenInterface $token)
|
public function execute($request)
|
||||||
{
|
{
|
||||||
if ($payment->getDetails()) {
|
RequestNotSupportedException::assertSupports($this, $request);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->payment->execute($httpRequest = new GetHttpRequest());
|
|
||||||
|
|
||||||
|
/** @var PaymentInterface $payment */
|
||||||
|
$payment = $request->getSource();
|
||||||
$order = $payment->getOrder();
|
$order = $payment->getOrder();
|
||||||
|
|
||||||
$details = array();
|
$this->gateway->execute($httpRequest = new GetHttpRequest());
|
||||||
|
|
||||||
|
$details = [];
|
||||||
$details['AMOUNT'] = $order->getTotal();
|
$details['AMOUNT'] = $order->getTotal();
|
||||||
$details['CLIENTEMAIL'] = $order->getCustomer()->getEmail();
|
$details['CLIENTEMAIL'] = $order->getCustomer()->getEmail();
|
||||||
$details['CLIENTUSERAGENT'] = $httpRequest->userAgent ?: 'Unknown';
|
$details['CLIENTUSERAGENT'] = $httpRequest->userAgent ?: 'Unknown';
|
||||||
|
|
@ -43,6 +46,18 @@ class CapturePaymentUsingCreditCardAction extends AbstractCapturePaymentAction
|
||||||
$details['DESCRIPTION'] = sprintf('Order containing %d items for a total of %01.2f', $order->getItems()->count(), $order->getTotal() / 100);
|
$details['DESCRIPTION'] = sprintf('Order containing %d items for a total of %01.2f', $order->getItems()->count(), $order->getTotal() / 100);
|
||||||
$details['ORDERID'] = $payment->getId();
|
$details['ORDERID'] = $payment->getId();
|
||||||
|
|
||||||
$payment->setDetails($details);
|
$request->setResult($details);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function supports($request)
|
||||||
|
{
|
||||||
|
return
|
||||||
|
$request instanceof Convert &&
|
||||||
|
$request->getSource() instanceof PaymentInterface &&
|
||||||
|
$request->getTo() === 'array'
|
||||||
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,50 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Sylius package.
|
||||||
|
*
|
||||||
|
* (c) Paweł Jędrzejewski
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Sylius\Bundle\PayumBundle\Action;
|
||||||
|
|
||||||
|
use Payum\Core\Action\ActionInterface;
|
||||||
|
use Payum\Core\Exception\RequestNotSupportedException;
|
||||||
|
use Payum\Core\Model\PaymentInterface;
|
||||||
|
use Payum\Core\Request\Convert;
|
||||||
|
use Payum\Offline\Constants;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Antonio Peric <antonio@locastic.com>
|
||||||
|
*/
|
||||||
|
class ConvertPaymentToOfflineAction implements ActionInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*
|
||||||
|
* @param Convert $request
|
||||||
|
*/
|
||||||
|
public function execute($request)
|
||||||
|
{
|
||||||
|
RequestNotSupportedException::assertSupports($this, $request);
|
||||||
|
|
||||||
|
$request->setResult([
|
||||||
|
Constants::FIELD_PAID => true,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function supports($request)
|
||||||
|
{
|
||||||
|
return
|
||||||
|
$request instanceof Convert &&
|
||||||
|
$request->getSource() instanceof PaymentInterface &&
|
||||||
|
$request->getTo() === 'array'
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -9,25 +9,28 @@
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Sylius\Bundle\PayumBundle\Payum\Paypal\Action;
|
namespace Sylius\Bundle\PayumBundle\Action;
|
||||||
|
|
||||||
use Payum\Core\Security\TokenInterface;
|
use Payum\Core\Action\ActionInterface;
|
||||||
use Sylius\Bundle\PayumBundle\Payum\Action\AbstractCapturePaymentAction;
|
use Payum\Core\Exception\RequestNotSupportedException;
|
||||||
|
use Payum\Core\Request\Convert;
|
||||||
use Sylius\Component\Core\Model\AdjustmentInterface;
|
use Sylius\Component\Core\Model\AdjustmentInterface;
|
||||||
use Sylius\Component\Core\Model\OrderInterface;
|
use Sylius\Component\Core\Model\OrderInterface;
|
||||||
use Sylius\Component\Payment\Model\PaymentInterface;
|
use Sylius\Component\Core\Model\PaymentInterface;
|
||||||
|
|
||||||
class CapturePaymentUsingExpressCheckoutAction extends AbstractCapturePaymentAction
|
class ConvertPaymentToPaypalExpressAction implements ActionInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritDoc}
|
||||||
|
*
|
||||||
|
* @param Convert $request
|
||||||
*/
|
*/
|
||||||
protected function composeDetails(PaymentInterface $payment, TokenInterface $token)
|
public function execute($request)
|
||||||
{
|
{
|
||||||
if ($payment->getDetails()) {
|
RequestNotSupportedException::assertSupports($this, $request);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/** @var PaymentInterface $payment */
|
||||||
|
$payment = $request->getSource();
|
||||||
$order = $payment->getOrder();
|
$order = $payment->getOrder();
|
||||||
|
|
||||||
$details = array();
|
$details = array();
|
||||||
|
|
@ -66,9 +69,26 @@ class CapturePaymentUsingExpressCheckoutAction extends AbstractCapturePaymentAct
|
||||||
$details['L_PAYMENTREQUEST_0_QTY'.$m] = 1;
|
$details['L_PAYMENTREQUEST_0_QTY'.$m] = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$payment->setDetails($details);
|
$request->setResult($details);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function supports($request)
|
||||||
|
{
|
||||||
|
return
|
||||||
|
$request instanceof Convert &&
|
||||||
|
$request->getSource() instanceof PaymentInterface &&
|
||||||
|
$request->getTo() === 'array'
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param OrderInterface $order
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
private function calculateNonNeutralTaxTotal(OrderInterface $order)
|
private function calculateNonNeutralTaxTotal(OrderInterface $order)
|
||||||
{
|
{
|
||||||
$nonNeutralTaxTotal = 0;
|
$nonNeutralTaxTotal = 0;
|
||||||
|
|
@ -9,15 +9,15 @@
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Sylius\Bundle\PayumBundle\Payum\Action;
|
namespace Sylius\Bundle\PayumBundle\Action;
|
||||||
|
|
||||||
use Payum\Core\Action\PaymentAwareAction;
|
use Payum\Core\Action\GatewayAwareAction;
|
||||||
use Payum\Core\Bridge\Spl\ArrayObject;
|
use Payum\Core\Bridge\Spl\ArrayObject;
|
||||||
use Payum\Core\Exception\RequestNotSupportedException;
|
use Payum\Core\Exception\RequestNotSupportedException;
|
||||||
use Payum\Core\Request\Generic;
|
use Payum\Core\Request\Generic;
|
||||||
use Sylius\Component\Payment\Model\PaymentInterface;
|
use Sylius\Component\Payment\Model\PaymentInterface;
|
||||||
|
|
||||||
class ExecuteSameRequestWithPaymentDetailsAction extends PaymentAwareAction
|
class ExecuteSameRequestWithPaymentDetailsAction extends GatewayAwareAction
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
|
|
@ -26,9 +26,7 @@ class ExecuteSameRequestWithPaymentDetailsAction extends PaymentAwareAction
|
||||||
*/
|
*/
|
||||||
public function execute($request)
|
public function execute($request)
|
||||||
{
|
{
|
||||||
if (!$this->supports($request)) {
|
RequestNotSupportedException::assertSupports($this, $request);
|
||||||
throw RequestNotSupportedException::createActionNotSupported($this, $request);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @var PaymentInterface $payment */
|
/** @var PaymentInterface $payment */
|
||||||
$payment = $request->getModel();
|
$payment = $request->getModel();
|
||||||
|
|
@ -37,13 +35,9 @@ class ExecuteSameRequestWithPaymentDetailsAction extends PaymentAwareAction
|
||||||
try {
|
try {
|
||||||
$request->setModel($details);
|
$request->setModel($details);
|
||||||
|
|
||||||
$this->payment->execute($request);
|
$this->gateway->execute($request);
|
||||||
|
} finally {
|
||||||
$payment->setDetails((array) $details);
|
$payment->setDetails((array) $details);
|
||||||
} catch (\Exception $e) {
|
|
||||||
$payment->setDetails((array) $details);
|
|
||||||
|
|
||||||
throw $e;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -11,6 +11,9 @@
|
||||||
|
|
||||||
namespace Sylius\Bundle\PayumBundle\DependencyInjection;
|
namespace Sylius\Bundle\PayumBundle\DependencyInjection;
|
||||||
|
|
||||||
|
use Sylius\Bundle\PayumBundle\Model\GatewayConfig;
|
||||||
|
use Sylius\Bundle\PayumBundle\Model\PaymentSecurityToken;
|
||||||
|
use Sylius\Bundle\ResourceBundle\Controller\ResourceController;
|
||||||
use Sylius\Bundle\ResourceBundle\SyliusResourceBundle;
|
use Sylius\Bundle\ResourceBundle\SyliusResourceBundle;
|
||||||
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
|
||||||
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
||||||
|
|
@ -60,15 +63,15 @@ class Configuration implements ConfigurationInterface
|
||||||
->arrayNode('payment_security_token')
|
->arrayNode('payment_security_token')
|
||||||
->addDefaultsIfNotSet()
|
->addDefaultsIfNotSet()
|
||||||
->children()
|
->children()
|
||||||
->scalarNode('model')->defaultValue('Sylius\Bundle\PayumBundle\Model\PaymentSecurityToken')->end()
|
->scalarNode('model')->defaultValue(PaymentSecurityToken::class)->end()
|
||||||
->scalarNode('controller')->defaultValue('Sylius\Bundle\ResourceBundle\Controller\ResourceController')->end()
|
->scalarNode('controller')->defaultValue(ResourceController::class)->end()
|
||||||
->end()
|
->end()
|
||||||
->end()
|
->end()
|
||||||
->arrayNode('payment_config')
|
->arrayNode('payment_config')
|
||||||
->addDefaultsIfNotSet()
|
->addDefaultsIfNotSet()
|
||||||
->children()
|
->children()
|
||||||
->scalarNode('model')->defaultValue('Sylius\Bundle\PayumBundle\Model\PaymentConfig')->end()
|
->scalarNode('model')->defaultValue(GatewayConfig::class)->end()
|
||||||
->scalarNode('controller')->defaultValue('Sylius\Bundle\ResourceBundle\Controller\ResourceController')->end()
|
->scalarNode('controller')->defaultValue(ResourceController::class)->end()
|
||||||
->end()
|
->end()
|
||||||
->end()
|
->end()
|
||||||
->end()
|
->end()
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,94 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Sylius package.
|
||||||
|
*
|
||||||
|
* (c) Paweł Jędrzejewski
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Sylius\Bundle\PayumBundle\Extension;
|
||||||
|
|
||||||
|
use Payum\Core\Extension\Context;
|
||||||
|
use Payum\Core\Extension\ExtensionInterface;
|
||||||
|
use Payum\Core\Request\Generic;
|
||||||
|
use Payum\Core\Request\GetStatusInterface;
|
||||||
|
use SM\Factory\FactoryInterface;
|
||||||
|
use Sylius\Bundle\PayumBundle\Request\GetStatus;
|
||||||
|
use Sylius\Component\Core\Model\PaymentInterface;
|
||||||
|
use Sylius\Component\Payment\PaymentTransitions;
|
||||||
|
|
||||||
|
class UpdatePaymentStateExtension implements ExtensionInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var FactoryInterface
|
||||||
|
*/
|
||||||
|
protected $factory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param FactoryInterface $factory
|
||||||
|
*/
|
||||||
|
public function __construct(FactoryInterface $factory)
|
||||||
|
{
|
||||||
|
$this->factory = $factory;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function onPreExecute(Context $context)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function onExecute(Context $context)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function onPostExecute(Context $context)
|
||||||
|
{
|
||||||
|
if ($context->getPrevious()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var Generic $request */
|
||||||
|
$request = $context->getRequest();
|
||||||
|
if (false === $request instanceof Generic) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (false === $request instanceof GetStatusInterface) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var PaymentInterface $payment */
|
||||||
|
$payment = $request->getFirstModel();
|
||||||
|
if (false === $payment instanceof PaymentInterface) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$context->getGateway()->execute($status = new GetStatus($payment));
|
||||||
|
if ($payment->getState() !== $status->getValue()) {
|
||||||
|
$this->updatePaymentState($payment, $status->getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param PaymentInterface $payment
|
||||||
|
* @param string $nextState
|
||||||
|
*/
|
||||||
|
protected function updatePaymentState(PaymentInterface $payment, $nextState)
|
||||||
|
{
|
||||||
|
$stateMachine = $this->factory->get($payment, PaymentTransitions::GRAPH);
|
||||||
|
|
||||||
|
if (null !== $transition = $stateMachine->getTransitionToState($nextState)) {
|
||||||
|
$stateMachine->apply($transition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -11,9 +11,9 @@
|
||||||
|
|
||||||
namespace Sylius\Bundle\PayumBundle\Model;
|
namespace Sylius\Bundle\PayumBundle\Model;
|
||||||
|
|
||||||
use Payum\Core\Model\PaymentConfigInterface;
|
use Payum\Core\Model\GatewayConfigInterface;
|
||||||
|
|
||||||
class PaymentConfig implements PaymentConfigInterface
|
class GatewayConfig implements GatewayConfigInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var int
|
* @var int
|
||||||
|
|
@ -23,7 +23,7 @@ class PaymentConfig implements PaymentConfigInterface
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $paymentName;
|
protected $gatewayName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
|
|
@ -51,17 +51,17 @@ class PaymentConfig implements PaymentConfigInterface
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public function getPaymentName()
|
public function getGatewayName()
|
||||||
{
|
{
|
||||||
return $this->paymentName;
|
return $this->gatewayName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public function setPaymentName($paymentName)
|
public function setGatewayName($gatewayName)
|
||||||
{
|
{
|
||||||
$this->paymentName = $paymentName;
|
$this->gatewayName = $gatewayName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -40,7 +40,7 @@ class PaymentSecurityToken implements TokenInterface
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $paymentName;
|
protected $gatewayName;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
|
@ -116,16 +116,16 @@ class PaymentSecurityToken implements TokenInterface
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public function getPaymentName()
|
public function getGatewayName()
|
||||||
{
|
{
|
||||||
return $this->paymentName;
|
return $this->gatewayName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public function setPaymentName($paymentName)
|
public function setGatewayName($gatewayName)
|
||||||
{
|
{
|
||||||
$this->paymentName = $paymentName;
|
$this->gatewayName = $gatewayName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,67 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of the Sylius package.
|
|
||||||
*
|
|
||||||
* (c) Paweł Jędrzejewski
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Sylius\Bundle\PayumBundle\Payum\Action;
|
|
||||||
|
|
||||||
use Payum\Core\Action\PaymentAwareAction;
|
|
||||||
use Payum\Core\Bridge\Spl\ArrayObject;
|
|
||||||
use Payum\Core\Exception\RequestNotSupportedException;
|
|
||||||
use Payum\Core\Request\Capture;
|
|
||||||
use Payum\Core\Security\TokenInterface;
|
|
||||||
use Sylius\Component\Payment\Model\PaymentInterface;
|
|
||||||
|
|
||||||
abstract class AbstractCapturePaymentAction extends PaymentAwareAction
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*
|
|
||||||
* @param $request Capture
|
|
||||||
*/
|
|
||||||
public function execute($request)
|
|
||||||
{
|
|
||||||
RequestNotSupportedException::assertSupports($this, $request);
|
|
||||||
|
|
||||||
/** @var $payment PaymentInterface */
|
|
||||||
$payment = $request->getModel();
|
|
||||||
|
|
||||||
$this->composeDetails($payment, $request->getToken());
|
|
||||||
|
|
||||||
$details = ArrayObject::ensureArrayObject($payment->getDetails());
|
|
||||||
|
|
||||||
try {
|
|
||||||
$request->setModel($details);
|
|
||||||
$this->payment->execute($request);
|
|
||||||
|
|
||||||
$payment->setDetails($details);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
$payment->setDetails($details);
|
|
||||||
|
|
||||||
throw $e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function supports($request)
|
|
||||||
{
|
|
||||||
return
|
|
||||||
$request instanceof Capture &&
|
|
||||||
$request->getModel() instanceof PaymentInterface
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param PaymentInterface $payment
|
|
||||||
* @param TokenInterface $token
|
|
||||||
*/
|
|
||||||
abstract protected function composeDetails(PaymentInterface $payment, TokenInterface $token);
|
|
||||||
}
|
|
||||||
|
|
@ -1,41 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of the Sylius package.
|
|
||||||
*
|
|
||||||
* (c) Paweł Jędrzejewski
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Sylius\Bundle\PayumBundle\Payum\Action;
|
|
||||||
|
|
||||||
use Payum\Core\Action\PaymentAwareAction;
|
|
||||||
use SM\Factory\FactoryInterface;
|
|
||||||
use Sylius\Component\Payment\PaymentTransitions;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Alexandre Bacco <alexandre.bacco@gmail.com>
|
|
||||||
*/
|
|
||||||
abstract class AbstractPaymentStateAwareAction extends PaymentAwareAction
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var FactoryInterface
|
|
||||||
*/
|
|
||||||
protected $factory;
|
|
||||||
|
|
||||||
public function __construct(FactoryInterface $factory)
|
|
||||||
{
|
|
||||||
$this->factory = $factory;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function updatePaymentState($payment, $nextState)
|
|
||||||
{
|
|
||||||
$stateMachine = $this->factory->get($payment, PaymentTransitions::GRAPH);
|
|
||||||
|
|
||||||
if (null !== $transition = $stateMachine->getTransitionToState($nextState)) {
|
|
||||||
$stateMachine->apply($transition);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,69 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of the Sylius package.
|
|
||||||
*
|
|
||||||
* (c) Paweł Jędrzejewski
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Sylius\Bundle\PayumBundle\Payum\Action;
|
|
||||||
|
|
||||||
use Payum\Core\Action\PaymentAwareAction;
|
|
||||||
use Payum\Core\Exception\RequestNotSupportedException;
|
|
||||||
use Payum\Core\Model\Order;
|
|
||||||
use Payum\Core\Request\Capture;
|
|
||||||
use Sylius\Component\Core\Model\PaymentInterface;
|
|
||||||
|
|
||||||
class GenericCapturePaymentAction extends PaymentAwareAction
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*
|
|
||||||
* @param $request Capture
|
|
||||||
*/
|
|
||||||
public function execute($request)
|
|
||||||
{
|
|
||||||
RequestNotSupportedException::assertSupports($this, $request);
|
|
||||||
|
|
||||||
/** @var $payment PaymentInterface */
|
|
||||||
$payment = $request->getModel();
|
|
||||||
$order = $payment->getOrder();
|
|
||||||
|
|
||||||
$payumOrder = new Order();
|
|
||||||
$payumOrder->setNumber($order->getNumber());
|
|
||||||
$payumOrder->setTotalAmount($order->getTotal());
|
|
||||||
$payumOrder->setCurrencyCode($order->getCurrency());
|
|
||||||
$payumOrder->setClientEmail($order->getCustomer()->getEmail());
|
|
||||||
$payumOrder->setClientId($order->getCustomer()->getId());
|
|
||||||
$payumOrder->setDescription(sprintf(
|
|
||||||
'Order containing %d items for a total of %01.2f',
|
|
||||||
$order->getItems()->count(), $order->getTotal() / 100
|
|
||||||
));
|
|
||||||
$payumOrder->setDetails($payment->getDetails());
|
|
||||||
|
|
||||||
try {
|
|
||||||
$request->setModel($payumOrder);
|
|
||||||
$this->payment->execute($request);
|
|
||||||
|
|
||||||
$payment->setDetails($payumOrder->getDetails());
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
$payment->setDetails($payumOrder->getDetails());
|
|
||||||
|
|
||||||
throw $e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function supports($request)
|
|
||||||
{
|
|
||||||
return
|
|
||||||
$request instanceof Capture &&
|
|
||||||
$request->getModel() instanceof PaymentInterface
|
|
||||||
;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,56 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of the Sylius package.
|
|
||||||
*
|
|
||||||
* (c) Paweł Jędrzejewski
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Sylius\Bundle\PayumBundle\Payum\Action;
|
|
||||||
|
|
||||||
use Payum\Core\Action\PaymentAwareAction;
|
|
||||||
use Payum\Core\Exception\RequestNotSupportedException;
|
|
||||||
use Payum\Core\Request\GetStatusInterface;
|
|
||||||
use Sylius\Component\Payment\Model\PaymentInterface;
|
|
||||||
|
|
||||||
class PaymentStatusAction extends PaymentAwareAction
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*
|
|
||||||
* @param $request GetStatusInterface
|
|
||||||
*/
|
|
||||||
public function execute($request)
|
|
||||||
{
|
|
||||||
if (!$this->supports($request)) {
|
|
||||||
throw RequestNotSupportedException::createActionNotSupported($this, $request);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @var PaymentInterface $payment */
|
|
||||||
$payment = $request->getModel();
|
|
||||||
|
|
||||||
if ($payment->getDetails()) {
|
|
||||||
$request->setModel($payment->getDetails());
|
|
||||||
|
|
||||||
$this->payment->execute($request);
|
|
||||||
|
|
||||||
$request->setModel($payment);
|
|
||||||
} else {
|
|
||||||
$request->markNew();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public function supports($request)
|
|
||||||
{
|
|
||||||
return
|
|
||||||
$request instanceof GetStatusInterface &&
|
|
||||||
$request->getModel() instanceof PaymentInterface
|
|
||||||
;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,78 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of the Sylius package.
|
|
||||||
*
|
|
||||||
* (c) Paweł Jędrzejewski
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Sylius\Bundle\PayumBundle\Payum\Be2bill\Action;
|
|
||||||
|
|
||||||
use Payum\Core\Exception\LogicException;
|
|
||||||
use Payum\Core\Request\GetHttpRequest;
|
|
||||||
use Payum\Core\Security\TokenInterface;
|
|
||||||
use Sylius\Bundle\PayumBundle\Payum\Action\AbstractCapturePaymentAction;
|
|
||||||
use Sylius\Component\Payment\Model\PaymentInterface;
|
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Alexandre Bacco <alexandre.bacco@gmail.com>
|
|
||||||
*/
|
|
||||||
class CapturePaymentUsingBe2billFormAction extends AbstractCapturePaymentAction
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var Request
|
|
||||||
*/
|
|
||||||
protected $httpRequest;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Define the Symfony Request
|
|
||||||
*
|
|
||||||
* @param Request $request
|
|
||||||
*/
|
|
||||||
public function setRequest(Request $request = null)
|
|
||||||
{
|
|
||||||
$this->httpRequest = $request;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public function execute($request)
|
|
||||||
{
|
|
||||||
$this->httpRequest->getSession()->set('payum_token', $request->getToken()->getHash());
|
|
||||||
|
|
||||||
parent::execute($request);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param PaymentInterface $payment
|
|
||||||
* @param TokenInterface $token
|
|
||||||
*
|
|
||||||
* @throws LogicException
|
|
||||||
*/
|
|
||||||
protected function composeDetails(PaymentInterface $payment, TokenInterface $token)
|
|
||||||
{
|
|
||||||
if ($payment->getDetails()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->payment->execute($httpRequest = new GetHttpRequest());
|
|
||||||
$order = $payment->getOrder();
|
|
||||||
|
|
||||||
$details = array();
|
|
||||||
$details['AMOUNT'] = $order->getTotal();
|
|
||||||
$details['CLIENTEMAIL'] = $order->getCustomer()->getEmail();
|
|
||||||
$details['HIDECLIENTEMAIL'] = 'yes';
|
|
||||||
$details['CLIENTUSERAGENT'] = $httpRequest->userAgent ?: 'Unknown';
|
|
||||||
$details['CLIENTIP'] = $httpRequest->clientIp;
|
|
||||||
$details['CLIENTIDENT'] = $order->getCustomer()->getId();
|
|
||||||
$details['DESCRIPTION'] = sprintf('Order containing %d items for a total of %01.2f', $order->getItems()->count(), $order->getTotal() / 100);
|
|
||||||
$details['ORDERID'] = $payment->getId();
|
|
||||||
|
|
||||||
$payment->setDetails($details);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,134 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of the Sylius package.
|
|
||||||
*
|
|
||||||
* (c) Paweł Jędrzejewski
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Sylius\Bundle\PayumBundle\Payum\Be2bill\Action;
|
|
||||||
|
|
||||||
use Doctrine\Common\Persistence\ObjectManager;
|
|
||||||
use Payum\Be2Bill\Api;
|
|
||||||
use Payum\Core\ApiAwareInterface;
|
|
||||||
use Payum\Core\Bridge\Symfony\Reply\HttpResponse;
|
|
||||||
use Payum\Core\Exception\RequestNotSupportedException;
|
|
||||||
use Payum\Core\Exception\UnsupportedApiException;
|
|
||||||
use Payum\Core\Request\GetHttpRequest;
|
|
||||||
use Payum\Core\Request\Notify;
|
|
||||||
use SM\Factory\FactoryInterface;
|
|
||||||
use Sylius\Bundle\PayumBundle\Payum\Action\AbstractPaymentStateAwareAction;
|
|
||||||
use Sylius\Bundle\PayumBundle\Payum\Request\GetStatus;
|
|
||||||
use Sylius\Component\Resource\Repository\RepositoryInterface;
|
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
|
||||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Alexandre Bacco <alexandre.bacco@gmail.com>
|
|
||||||
*/
|
|
||||||
class NotifyAction extends AbstractPaymentStateAwareAction implements ApiAwareInterface
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var RepositoryInterface
|
|
||||||
*/
|
|
||||||
protected $paymentRepository;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var ObjectManager
|
|
||||||
*/
|
|
||||||
protected $objectManager;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $identifier;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var Api
|
|
||||||
*/
|
|
||||||
protected $api;
|
|
||||||
|
|
||||||
public function __construct(
|
|
||||||
RepositoryInterface $paymentRepository,
|
|
||||||
ObjectManager $objectManager,
|
|
||||||
FactoryInterface $factory,
|
|
||||||
$identifier
|
|
||||||
) {
|
|
||||||
parent::__construct($factory);
|
|
||||||
|
|
||||||
$this->paymentRepository = $paymentRepository;
|
|
||||||
$this->objectManager = $objectManager;
|
|
||||||
$this->identifier = $identifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public function setApi($api)
|
|
||||||
{
|
|
||||||
if (!$api instanceof Api) {
|
|
||||||
throw new UnsupportedApiException('Not supported.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->api = $api;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*
|
|
||||||
* @param $request Notify
|
|
||||||
*/
|
|
||||||
public function execute($request)
|
|
||||||
{
|
|
||||||
if (!$this->supports($request)) {
|
|
||||||
throw RequestNotSupportedException::createActionNotSupported($this, $request);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->payment->execute($httpRequest = new GetHttpRequest());
|
|
||||||
$details = $httpRequest->query;
|
|
||||||
|
|
||||||
if (!$this->api->verifyHash($details)) {
|
|
||||||
throw new BadRequestHttpException('Hash cannot be verified.');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($details['ORDERID'])) {
|
|
||||||
throw new BadRequestHttpException('Order id cannot be guessed');
|
|
||||||
}
|
|
||||||
|
|
||||||
$payment = $this->paymentRepository->findOneBy(array($this->identifier => $details['ORDERID']));
|
|
||||||
|
|
||||||
if (null === $payment) {
|
|
||||||
throw new BadRequestHttpException('Payment cannot be retrieved.');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((int) $details['AMOUNT'] !== $payment->getAmount()) {
|
|
||||||
throw new BadRequestHttpException('Request amount cannot be verified against payment amount.');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actually update payment details
|
|
||||||
$details = array_merge($payment->getDetails(), $details);
|
|
||||||
$payment->setDetails($details);
|
|
||||||
|
|
||||||
$status = new GetStatus($payment);
|
|
||||||
$this->payment->execute($status);
|
|
||||||
|
|
||||||
$nextState = $status->getValue();
|
|
||||||
|
|
||||||
$this->updatePaymentState($payment, $nextState);
|
|
||||||
|
|
||||||
$this->objectManager->flush();
|
|
||||||
|
|
||||||
throw new HttpResponse(new Response('OK', 200));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public function supports($request)
|
|
||||||
{
|
|
||||||
return $request instanceof Notify;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,40 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of the Sylius package.
|
|
||||||
*
|
|
||||||
* (c) Paweł Jędrzejewski
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Sylius\Bundle\PayumBundle\Payum\Dummy\Action;
|
|
||||||
|
|
||||||
use Payum\Core\Exception\RequestNotSupportedException;
|
|
||||||
use Payum\Core\Request\Capture;
|
|
||||||
use Sylius\Bundle\PayumBundle\Payum\Action\GenericCapturePaymentAction;
|
|
||||||
use Sylius\Component\Payment\Model\PaymentInterface;
|
|
||||||
|
|
||||||
class CapturePaymentAction extends GenericCapturePaymentAction
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*
|
|
||||||
* @param $request Capture
|
|
||||||
*/
|
|
||||||
public function execute($request)
|
|
||||||
{
|
|
||||||
if (!$this->supports($request)) {
|
|
||||||
throw RequestNotSupportedException::createActionNotSupported($this, $request);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @var $payment PaymentInterface */
|
|
||||||
$payment = $request->getModel();
|
|
||||||
if ($payment->getDetails()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$payment->setDetails(array('captured' => true));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,50 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of the Sylius package.
|
|
||||||
*
|
|
||||||
* (c) Paweł Jędrzejewski
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Sylius\Bundle\PayumBundle\Payum\Dummy\Action;
|
|
||||||
|
|
||||||
use Payum\Core\Exception\RequestNotSupportedException;
|
|
||||||
use Payum\Core\Request\GetStatusInterface;
|
|
||||||
use Sylius\Bundle\PayumBundle\Payum\Action\PaymentStatusAction as BasePaymentStatusAction;
|
|
||||||
use Sylius\Component\Payment\Model\PaymentInterface;
|
|
||||||
|
|
||||||
class PaymentStatusAction extends BasePaymentStatusAction
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*
|
|
||||||
* @param $request GetStatusInterface
|
|
||||||
*/
|
|
||||||
public function execute($request)
|
|
||||||
{
|
|
||||||
if (!$this->supports($request)) {
|
|
||||||
throw RequestNotSupportedException::createActionNotSupported($this, $request);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @var $payment PaymentInterface */
|
|
||||||
$payment = $request->getModel();
|
|
||||||
$paymentDetails = $payment->getDetails();
|
|
||||||
|
|
||||||
if (empty($paymentDetails)) {
|
|
||||||
$request->markNew();
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($paymentDetails['captured'])) {
|
|
||||||
$request->markCaptured();
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$request->markUnknown();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,42 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of the Sylius package.
|
|
||||||
*
|
|
||||||
* (c) Paweł Jędrzejewski
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Sylius\Bundle\PayumBundle\Payum\Offline\Action;
|
|
||||||
|
|
||||||
use Payum\Core\Exception\RequestNotSupportedException;
|
|
||||||
use Payum\Offline\Constants;
|
|
||||||
use Sylius\Bundle\PayumBundle\Payum\Action\GenericCapturePaymentAction;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Antonio Peric <antonio@locastic.com>
|
|
||||||
*/
|
|
||||||
class CapturePaymentAction extends GenericCapturePaymentAction
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function execute($request)
|
|
||||||
{
|
|
||||||
if (!$this->supports($request)) {
|
|
||||||
throw RequestNotSupportedException::createActionNotSupported($this, $request);
|
|
||||||
}
|
|
||||||
|
|
||||||
$payment = $request->getModel();
|
|
||||||
if ($payment->getDetails()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$payment->setDetails(array(
|
|
||||||
Constants::FIELD_PAID => false,
|
|
||||||
Constants::FIELD_STATUS => Constants::STATUS_PENDING
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,78 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of the Sylius package.
|
|
||||||
*
|
|
||||||
* (c) Paweł Jędrzejewski
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Sylius\Bundle\PayumBundle\Payum\Paypal\Action;
|
|
||||||
|
|
||||||
use Doctrine\Common\Persistence\ObjectManager;
|
|
||||||
use Payum\Core\Exception\RequestNotSupportedException;
|
|
||||||
use Payum\Core\Request\Notify;
|
|
||||||
use Payum\Core\Request\Sync;
|
|
||||||
use SM\Factory\FactoryInterface;
|
|
||||||
use Sylius\Bundle\PayumBundle\Payum\Action\AbstractPaymentStateAwareAction;
|
|
||||||
use Sylius\Bundle\PayumBundle\Payum\Request\GetStatus;
|
|
||||||
use Sylius\Component\Payment\Model\PaymentInterface;
|
|
||||||
|
|
||||||
class NotifyOrderAction extends AbstractPaymentStateAwareAction
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var ObjectManager
|
|
||||||
*/
|
|
||||||
protected $objectManager;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param ObjectManager $objectManager
|
|
||||||
* @param FactoryInterface $factory
|
|
||||||
*/
|
|
||||||
public function __construct(ObjectManager $objectManager, FactoryInterface $factory)
|
|
||||||
{
|
|
||||||
parent::__construct($factory);
|
|
||||||
|
|
||||||
$this->objectManager = $objectManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*
|
|
||||||
* @param $request Notify
|
|
||||||
*/
|
|
||||||
public function execute($request)
|
|
||||||
{
|
|
||||||
if (!$this->supports($request)) {
|
|
||||||
throw RequestNotSupportedException::createActionNotSupported($this, $request);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @var $payment PaymentInterface */
|
|
||||||
$payment = $request->getModel();
|
|
||||||
|
|
||||||
$this->payment->execute(new Sync($payment));
|
|
||||||
|
|
||||||
$status = new GetStatus($payment);
|
|
||||||
$this->payment->execute($status);
|
|
||||||
|
|
||||||
$nextState = $status->getValue();
|
|
||||||
|
|
||||||
$this->updatePaymentState($payment, $nextState);
|
|
||||||
|
|
||||||
$this->objectManager->flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public function supports($request)
|
|
||||||
{
|
|
||||||
return
|
|
||||||
$request instanceof Notify &&
|
|
||||||
$request->getToken() &&
|
|
||||||
$request->getModel() instanceof PaymentInterface
|
|
||||||
;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Sylius\Bundle\PayumBundle\Payum\Request;
|
namespace Sylius\Bundle\PayumBundle\Request;
|
||||||
|
|
||||||
use Payum\Core\Request\BaseGetStatus;
|
use Payum\Core\Request\BaseGetStatus;
|
||||||
use Sylius\Component\Payment\Model\PaymentInterface;
|
use Sylius\Component\Payment\Model\PaymentInterface;
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
|
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
|
||||||
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"
|
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"
|
||||||
>
|
>
|
||||||
<mapped-superclass name="Sylius\Bundle\PayumBundle\Model\PaymentConfig" table="sylius_payment_config">
|
<mapped-superclass name="Sylius\Bundle\PayumBundle\Model\GatewayConfig" table="sylius_gateway_config">
|
||||||
|
|
||||||
<id name="id" column="id" type="integer">
|
<id name="id" column="id" type="integer">
|
||||||
<generator strategy="AUTO" />
|
<generator strategy="AUTO" />
|
||||||
|
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
<field name="config" column="config" type="json_array" nullable="false" />
|
<field name="config" column="config" type="json_array" nullable="false" />
|
||||||
|
|
||||||
<field name="paymentName" column="payment_name" type="string" length="255" nullable="false" />
|
<field name="gatewayName" column="gateway_name" type="string" length="255" nullable="false" />
|
||||||
|
|
||||||
<field name="factoryName" column="factory_name" type="string" length="255" nullable="false" />
|
<field name="factoryName" column="factory_name" type="string" length="255" nullable="false" />
|
||||||
|
|
||||||
|
|
@ -26,7 +26,7 @@
|
||||||
|
|
||||||
<field name="targetUrl" column="target_url" type="text" nullable="false" />
|
<field name="targetUrl" column="target_url" type="text" nullable="false" />
|
||||||
|
|
||||||
<field name="paymentName" column="payment_name" type="string" length="255" nullable="false" />
|
<field name="gatewayName" column="gateway_name" type="string" length="255" nullable="false" />
|
||||||
|
|
||||||
</mapped-superclass>
|
</mapped-superclass>
|
||||||
</doctrine-mapping>
|
</doctrine-mapping>
|
||||||
|
|
|
||||||
|
|
@ -16,75 +16,35 @@
|
||||||
xsi:schemaLocation="http://symfony.com/schema/dic/services
|
xsi:schemaLocation="http://symfony.com/schema/dic/services
|
||||||
http://symfony.com/schema/dic/services/services-1.0.xsd">
|
http://symfony.com/schema/dic/services/services-1.0.xsd">
|
||||||
|
|
||||||
<parameters>
|
|
||||||
<parameter key="sylius.payum.paypal.action.capture_payment_using_express_checkout.class">Sylius\Bundle\PayumBundle\Payum\Paypal\Action\CapturePaymentUsingExpressCheckoutAction</parameter>
|
|
||||||
|
|
||||||
<parameter key="sylius.payum.paypal.action.notify_order.class">Sylius\Bundle\PayumBundle\Payum\Paypal\Action\NotifyOrderAction</parameter>
|
|
||||||
|
|
||||||
<parameter key="sylius.payum.be2bill.action.capture_payment_using_credit_card.class">Sylius\Bundle\PayumBundle\Payum\Be2bill\Action\CapturePaymentUsingCreditCardAction</parameter>
|
|
||||||
<parameter key="sylius.payum.be2bill.action.capture_payment_using_be2bill_form.class">Sylius\Bundle\PayumBundle\Payum\Be2bill\Action\CapturePaymentUsingBe2billFormAction</parameter>
|
|
||||||
<parameter key="sylius.payum.be2bill.action.notify.class">Sylius\Bundle\PayumBundle\Payum\Be2bill\Action\NotifyAction</parameter>
|
|
||||||
|
|
||||||
<parameter key="sylius.payum.dummy.action.capture_payment.class">Sylius\Bundle\PayumBundle\Payum\Dummy\Action\CapturePaymentAction</parameter>
|
|
||||||
<parameter key="sylius.payum.dummy.action.payment_status.class">Sylius\Bundle\PayumBundle\Payum\Dummy\Action\PaymentStatusAction</parameter>
|
|
||||||
|
|
||||||
<parameter key="sylius.payum.offline.action.capture_payment.class">Sylius\Bundle\PayumBundle\Payum\Offline\Action\CapturePaymentAction</parameter>
|
|
||||||
|
|
||||||
<parameter key="sylius.payum.action.generic_capture_payment.class">Sylius\Bundle\PayumBundle\Payum\Action\GenericCapturePaymentAction</parameter>
|
|
||||||
<parameter key="sylius.payum.action.payment_status.class">Sylius\Bundle\PayumBundle\Payum\Action\PaymentStatusAction</parameter>
|
|
||||||
<parameter key="sylius.payum.action.execute_same_request_with_payment_details.class">Sylius\Bundle\PayumBundle\Payum\Action\ExecuteSameRequestWithPaymentDetailsAction</parameter>
|
|
||||||
</parameters>
|
|
||||||
|
|
||||||
<services>
|
<services>
|
||||||
<!-- Generic -->
|
<!-- Generic -->
|
||||||
<service id="sylius.payum.action.payment_status" class="%sylius.payum.action.payment_status.class%">
|
<service id="sylius.payum.action.capture_payment" class="Sylius\Bundle\PayumBundle\Action\CapturePaymentAction">
|
||||||
<tag name="payum.action" all="true" alias="status_sylius_order" />
|
<tag name="payum.action" all="true" alias="sylius.capture_payment" />
|
||||||
</service>
|
</service>
|
||||||
<service id="sylius.payum.action.generic_capture_payment" class="%sylius.payum.action.generic_capture_payment.class%">
|
<service id="sylius.payum.action.execute_same_request_with_payment_details" class="Sylius\Bundle\PayumBundle\Action\ExecuteSameRequestWithPaymentDetailsAction">
|
||||||
<tag name="payum.action" all="true" alias="capture_sylius_order" />
|
|
||||||
</service>
|
|
||||||
<service id="sylius.payum.action.execute_same_request_with_payment_details" class="%sylius.payum.action.execute_same_request_with_payment_details.class%">
|
|
||||||
<tag name="payum.action" all="true" />
|
<tag name="payum.action" all="true" />
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<!-- PayPal -->
|
<service id="sylius.payum.extension.update_payment_state" class="Sylius\Bundle\PayumBundle\Extension\UpdatePaymentStateExtension">
|
||||||
<service id="sylius.payum.paypal.action.capture_payment_using_express_checkout" class="%sylius.payum.paypal.action.capture_payment_using_express_checkout.class%">
|
|
||||||
<tag name="payum.action" factory="paypal_express_checkout_nvp" alias="capture_sylius_order" />
|
|
||||||
</service>
|
|
||||||
<service id="sylius.payum.paypal.action.notify_order" class="%sylius.payum.paypal.action.notify_order.class%">
|
|
||||||
<argument type="service" id="sylius.manager.payment" />
|
|
||||||
<argument type="service" id="sm.factory" />
|
<argument type="service" id="sm.factory" />
|
||||||
|
|
||||||
<tag name="payum.action" factory="paypal_express_checkout_nvp" alias="notify_sylius_order" />
|
<tag name="payum.extension" all="true" />
|
||||||
|
</service>
|
||||||
|
|
||||||
|
<!-- PayPal -->
|
||||||
|
<service id="sylius.payum.action.convert_payment_to_paypal_express" class="Sylius\Bundle\PayumBundle\Action\ConvertPaymentToPaypalExpressAction">
|
||||||
|
<tag name="payum.action" factory="paypal_express_checkout_nvp" alias="sylius.convert_payment" />
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<!-- Be2bill -->
|
<!-- Be2bill -->
|
||||||
<service id="sylius.payum.be2bill.action.capture_payment_using_credit_card" class="%sylius.payum.be2bill.action.capture_payment_using_credit_card.class%">
|
<service id="sylius.payum.action.convert_payment_to_be2bill" class="Sylius\Bundle\PayumBundle\Action\ConvertPaymentToBe2BillAction">
|
||||||
<tag name="payum.action" factory="be2bill_direct" alias="capture_sylius_order" />
|
<tag name="payum.action" factory="be2bill_direct" alias="sylius.convert_payment" />
|
||||||
|
<tag name="payum.action" factory="be2bill_offsite" alias="sylius.convert_payment" />
|
||||||
</service>
|
</service>
|
||||||
<service id="sylius.payum.be2bill.action.capture_payment_using_be2bill_form" class="%sylius.payum.be2bill.action.capture_payment_using_be2bill_form.class%">
|
|
||||||
<call method="setRequest">
|
|
||||||
<argument type="service" id="request" on-invalid="null" strict="false" />
|
|
||||||
</call>
|
|
||||||
|
|
||||||
<tag name="payum.action" factory="be2bill_offsite" alias="capture_sylius_order" />
|
|
||||||
</service>
|
|
||||||
<service id="sylius.payum.be2bill.action.notify" class="%sylius.payum.be2bill.action.notify.class%">
|
|
||||||
<argument type="service" id="sylius.repository.payment" />
|
|
||||||
<argument type="service" id="sylius.manager.payment" />
|
|
||||||
<argument type="service" id="sm.factory" />
|
|
||||||
<argument>id</argument>
|
|
||||||
|
|
||||||
<tag name="payum.action" factory="be2bill_offsite" alias="notify_sylius_order" />
|
|
||||||
</service>
|
|
||||||
|
|
||||||
<!-- Dummy -->
|
|
||||||
<service id="sylius.payum.dummy.action.capture_payment" class="%sylius.payum.dummy.action.capture_payment.class%" />
|
|
||||||
<service id="sylius.payum.dummy.action.payment_status" class="%sylius.payum.dummy.action.payment_status.class%" />
|
|
||||||
|
|
||||||
<!-- Offline -->
|
<!-- Offline -->
|
||||||
<service id="sylius.payum.offline.action.capture_payment" class="%sylius.payum.offline.action.capture_payment.class%">
|
<service id="sylius.payum.offline.action.convert_payment" class="Sylius\Bundle\PayumBundle\Action\ConvertPaymentToOfflineAction">
|
||||||
<tag name="payum.action" factory="offline" />
|
<tag name="payum.action" factory="offline" alias="sylius.convert_payment" />
|
||||||
</service>
|
</service>
|
||||||
</services>
|
</services>
|
||||||
</container>
|
</container>
|
||||||
|
|
|
||||||
|
|
@ -31,8 +31,8 @@
|
||||||
"sylius/order-bundle": "0.16.*",
|
"sylius/order-bundle": "0.16.*",
|
||||||
"sylius/payment-bundle": "0.16.*",
|
"sylius/payment-bundle": "0.16.*",
|
||||||
"sylius/resource-bundle": "0.16.*",
|
"sylius/resource-bundle": "0.16.*",
|
||||||
"payum/payum": "~0.14.0",
|
"payum/payum": "~1.0",
|
||||||
"payum/payum-bundle": "~0.14.2",
|
"payum/payum-bundle": "~1.0",
|
||||||
"winzou/state-machine": "~0.1"
|
"winzou/state-machine": "~0.1"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
|
|
|
||||||
|
|
@ -1,27 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of the Sylius package.
|
|
||||||
*
|
|
||||||
* (c) Paweł Jędrzejewski
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace spec\Sylius\Bundle\PayumBundle\Model;
|
|
||||||
|
|
||||||
use PhpSpec\ObjectBehavior;
|
|
||||||
|
|
||||||
class PaymentSecurityTokenSpec extends ObjectBehavior
|
|
||||||
{
|
|
||||||
function it_is_initializable()
|
|
||||||
{
|
|
||||||
$this->shouldHaveType('Sylius\Bundle\PayumBundle\Model\PaymentSecurityToken');
|
|
||||||
}
|
|
||||||
|
|
||||||
function it_implements_payum_token_interface()
|
|
||||||
{
|
|
||||||
$this->shouldHaveType('Payum\Core\Security\TokenInterface');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,92 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of the Sylius package.
|
|
||||||
*
|
|
||||||
* (c) Paweł Jędrzejewski
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace spec\Sylius\Bundle\PayumBundle\Payum\Action;
|
|
||||||
|
|
||||||
use Payum\Core\PaymentInterface as PayumPaymentInterface;
|
|
||||||
use Payum\Core\Request\Generic;
|
|
||||||
use PhpSpec\ObjectBehavior;
|
|
||||||
use Prophecy\Argument;
|
|
||||||
use Sylius\Component\Payment\Model\PaymentInterface;
|
|
||||||
|
|
||||||
class ExecuteSameRequestWithPaymentDetailsActionSpec extends ObjectBehavior
|
|
||||||
{
|
|
||||||
function it_is_initializable()
|
|
||||||
{
|
|
||||||
$this->shouldHaveType('Sylius\Bundle\PayumBundle\Payum\Action\ExecuteSameRequestWithPaymentDetailsAction');
|
|
||||||
}
|
|
||||||
|
|
||||||
function it_extends_payum_payment_aware_action()
|
|
||||||
{
|
|
||||||
$this->shouldHaveType('Payum\Core\Action\PaymentAwareAction');
|
|
||||||
}
|
|
||||||
|
|
||||||
function it_should_support_request(Generic $request, PaymentInterface $payment)
|
|
||||||
{
|
|
||||||
$request->getModel()->willReturn($payment);
|
|
||||||
$payment->getDetails()->willReturn(array('foo' => 'foo'));
|
|
||||||
|
|
||||||
$this->supports($request)->shouldReturn(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
function it_should_not_support_generic_request_with_not_payment_model(Generic $request)
|
|
||||||
{
|
|
||||||
$request->getModel()->willReturn(new \stdClass);
|
|
||||||
|
|
||||||
$this->supports($request)->shouldReturn(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
function it_should_not_support_anything_not_model_request()
|
|
||||||
{
|
|
||||||
$this->supports(new \stdClass)->shouldReturn(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
function it_throws_exception_if_executing_not_supported_request()
|
|
||||||
{
|
|
||||||
$this
|
|
||||||
->shouldThrow('Payum\Core\Exception\RequestNotSupportedException')
|
|
||||||
->duringExecute($notSupportedRequest = 'foo')
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
function it_should_execute_same_request_with_details_wrapped_by_array_object(
|
|
||||||
Generic $request,
|
|
||||||
PaymentInterface $payment,
|
|
||||||
PayumPaymentInterface $payumPayment
|
|
||||||
) {
|
|
||||||
$this->setPayment($payumPayment);
|
|
||||||
|
|
||||||
$request->getModel()->willReturn($payment);
|
|
||||||
$payment->getDetails()->willReturn(array('foo' => 'fooValue'));
|
|
||||||
|
|
||||||
$request
|
|
||||||
->setModel(Argument::type('Payum\Core\Bridge\Spl\ArrayObject'))
|
|
||||||
->shouldBeCalled()
|
|
||||||
->will(function ($args) use ($request) {
|
|
||||||
$request->getModel()->willReturn($args[0]);
|
|
||||||
})
|
|
||||||
;
|
|
||||||
$request->getModel()->willReturn($payment);
|
|
||||||
|
|
||||||
$payumPayment
|
|
||||||
->execute($request)
|
|
||||||
->shouldBeCalled()
|
|
||||||
->will(function ($args) {
|
|
||||||
$details = $args[0]->getModel();
|
|
||||||
$details['bar'] = 'barValue';
|
|
||||||
})
|
|
||||||
;
|
|
||||||
|
|
||||||
$payment->setDetails(array('foo' => 'fooValue', 'bar' => 'barValue'))->shouldBeCalled();
|
|
||||||
|
|
||||||
$this->execute($request);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,93 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of the Sylius package.
|
|
||||||
*
|
|
||||||
* (c) Paweł Jędrzejewski
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace spec\Sylius\Bundle\PayumBundle\Payum\Action;
|
|
||||||
|
|
||||||
use Payum\Core\PaymentInterface as PayumPaymentInterface;
|
|
||||||
use Payum\Core\Request\GetStatusInterface;
|
|
||||||
use PhpSpec\ObjectBehavior;
|
|
||||||
use Sylius\Component\Payment\Model\PaymentInterface;
|
|
||||||
|
|
||||||
class PaymentStatusActionSpec extends ObjectBehavior
|
|
||||||
{
|
|
||||||
function it_is_initializable()
|
|
||||||
{
|
|
||||||
$this->shouldHaveType('Sylius\Bundle\PayumBundle\Payum\Action\PaymentStatusAction');
|
|
||||||
}
|
|
||||||
|
|
||||||
function it_extends_payum_payment_aware_action()
|
|
||||||
{
|
|
||||||
$this->shouldHaveType('Payum\Core\Action\PaymentAwareAction');
|
|
||||||
}
|
|
||||||
|
|
||||||
function it_should_support_status_request_with_order_model(
|
|
||||||
PaymentInterface $payment,
|
|
||||||
GetStatusInterface $statusRequest
|
|
||||||
) {
|
|
||||||
$statusRequest->getModel()->willReturn($payment);
|
|
||||||
|
|
||||||
$this->supports($statusRequest)->shouldReturn(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
function it_should_not_support_status_request_with_no_order_model(
|
|
||||||
GetStatusInterface $statusRequest
|
|
||||||
) {
|
|
||||||
$statusRequest->getModel()->willReturn('foo');
|
|
||||||
|
|
||||||
$this->supports($statusRequest)->shouldReturn(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
function it_should_not_support_any_no_status_requests()
|
|
||||||
{
|
|
||||||
$this->supports('foo')->shouldReturn(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
function it_throws_exception_if_executing_not_supported_request()
|
|
||||||
{
|
|
||||||
$notSupportedRequest = 'foo';
|
|
||||||
|
|
||||||
$this
|
|
||||||
->shouldThrow('Payum\Core\Exception\RequestNotSupportedException')
|
|
||||||
->duringExecute($notSupportedRequest)
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
function it_should_mark_new_if_order_have_empty_payment_details(
|
|
||||||
PaymentInterface $payment,
|
|
||||||
GetStatusInterface $statusRequest
|
|
||||||
) {
|
|
||||||
$payment->getDetails()->willReturn(array());
|
|
||||||
|
|
||||||
$statusRequest->getModel()->willReturn($payment);
|
|
||||||
$statusRequest->markNew()->shouldBeCalled();
|
|
||||||
|
|
||||||
$this->execute($statusRequest);
|
|
||||||
}
|
|
||||||
|
|
||||||
function it_should_do_status_subrequest_with_payment_details_as_model(
|
|
||||||
PayumPaymentInterface $payumPayment,
|
|
||||||
GetStatusInterface $statusRequest,
|
|
||||||
PaymentInterface $payment
|
|
||||||
) {
|
|
||||||
$details = array('foo' => 'foo', 'bar' => 'baz');
|
|
||||||
|
|
||||||
$statusRequest->getModel()->willReturn($payment);
|
|
||||||
$statusRequest->setModel($details)->shouldBeCalled();
|
|
||||||
$statusRequest->setModel($payment)->shouldBeCalled();
|
|
||||||
|
|
||||||
$payment->getDetails()->willReturn($details);
|
|
||||||
|
|
||||||
$payumPayment->execute($statusRequest)->shouldBeCalled();
|
|
||||||
$this->setPayment($payumPayment);
|
|
||||||
|
|
||||||
$this->execute($statusRequest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,161 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of the Sylius package.
|
|
||||||
*
|
|
||||||
* (c) Paweł Jędrzejewski
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace spec\Sylius\Bundle\PayumBundle\Payum\Paypal\Action;
|
|
||||||
|
|
||||||
use Doctrine\Common\Collections\Collection;
|
|
||||||
use Doctrine\Common\Persistence\ObjectManager;
|
|
||||||
use Payum\Core\Model\ModelAwareInterface;
|
|
||||||
use Payum\Core\PaymentInterface;
|
|
||||||
use Payum\Core\Request\Notify;
|
|
||||||
use Payum\Core\Security\TokenInterface;
|
|
||||||
use PhpSpec\ObjectBehavior;
|
|
||||||
use Prophecy\Argument;
|
|
||||||
use SM\Factory\FactoryInterface;
|
|
||||||
use Sylius\Component\Core\Model\OrderInterface;
|
|
||||||
use Sylius\Component\Payment\Model\Payment;
|
|
||||||
use Sylius\Component\Payment\Model\PaymentInterface as PaymentModelInterface;
|
|
||||||
use Sylius\Component\Payment\PaymentTransitions;
|
|
||||||
use Sylius\Component\Resource\StateMachine\StateMachineInterface;
|
|
||||||
|
|
||||||
class NotifyOrderActionSpec extends ObjectBehavior
|
|
||||||
{
|
|
||||||
function let(
|
|
||||||
ObjectManager $objectManager,
|
|
||||||
FactoryInterface $factory,
|
|
||||||
PaymentInterface $payment
|
|
||||||
) {
|
|
||||||
$this->beConstructedWith($objectManager, $factory);
|
|
||||||
$this->setPayment($payment);
|
|
||||||
}
|
|
||||||
|
|
||||||
function it_is_initializable()
|
|
||||||
{
|
|
||||||
$this->shouldHaveType('Sylius\Bundle\PayumBundle\Payum\Paypal\Action\NotifyOrderAction');
|
|
||||||
}
|
|
||||||
|
|
||||||
function it_extends_payum_payment_aware_action()
|
|
||||||
{
|
|
||||||
$this->shouldHaveType('Payum\Core\Action\PaymentAwareAction');
|
|
||||||
}
|
|
||||||
|
|
||||||
function it_should_supports_secured_notify_request_with_order_model(
|
|
||||||
Notify $request,
|
|
||||||
PaymentModelInterface $payment,
|
|
||||||
TokenInterface $token
|
|
||||||
) {
|
|
||||||
$request->getModel()->willReturn($payment);
|
|
||||||
$request->getToken()->willReturn($token);
|
|
||||||
|
|
||||||
$this->supports($request)->shouldReturn(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
function it_should_support_only_model_aware_request(ModelAwareInterface $request)
|
|
||||||
{
|
|
||||||
$this->supports($request)->shouldReturn(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
function it_should_not_support_notify_request_with_not_payment_model(
|
|
||||||
Notify $request,
|
|
||||||
TokenInterface $token
|
|
||||||
) {
|
|
||||||
$request->getModel()->willReturn(new \stdClass);
|
|
||||||
$request->getToken()->willReturn($token);
|
|
||||||
|
|
||||||
$this->supports($request)->shouldReturn(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
function it_should_not_support_anything_not_model_request()
|
|
||||||
{
|
|
||||||
$this->supports(new \stdClass)->shouldReturn(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
function it_throws_exception_if_executing_not_supported_request()
|
|
||||||
{
|
|
||||||
$this
|
|
||||||
->shouldThrow('Payum\Core\Exception\RequestNotSupportedException')
|
|
||||||
->duringExecute($notSupportedRequest = 'foo')
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
function it_must_not_dispatch_pre_and_post_payment_state_changed_if_state_not_changed(
|
|
||||||
$factory,
|
|
||||||
Notify $request,
|
|
||||||
OrderInterface $order,
|
|
||||||
PaymentModelInterface $paymentModel,
|
|
||||||
PaymentInterface $payment,
|
|
||||||
StateMachineInterface $sm,
|
|
||||||
Collection $payments,
|
|
||||||
TokenInterface $token
|
|
||||||
) {
|
|
||||||
$request->getModel()->willReturn($paymentModel);
|
|
||||||
$request->getToken()->willReturn($token);
|
|
||||||
|
|
||||||
$order->getPayments()->willReturn($payments);
|
|
||||||
$payments->last()->willReturn($payment);
|
|
||||||
|
|
||||||
$paymentModel->getState()->willReturn(Payment::STATE_COMPLETED);
|
|
||||||
|
|
||||||
$factory->get($paymentModel, PaymentTransitions::GRAPH)->willReturn($sm);
|
|
||||||
$sm->getTransitionToState('completed')->willReturn(null);
|
|
||||||
$sm->apply(PaymentTransitions::SYLIUS_COMPLETE)->shouldNotBeCalled();
|
|
||||||
|
|
||||||
$payment->execute(Argument::type('Payum\Core\Request\Sync'))->willReturn(null);
|
|
||||||
|
|
||||||
$payment
|
|
||||||
->execute(Argument::type('Sylius\Bundle\PayumBundle\Payum\Request\GetStatus'))
|
|
||||||
->will(function ($args) {
|
|
||||||
$args[0]->markCaptured();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->execute($request);
|
|
||||||
}
|
|
||||||
|
|
||||||
function it_must_dispatch_pre_and_post_payment_state_changed_if_state_changed(
|
|
||||||
$factory,
|
|
||||||
Notify $request,
|
|
||||||
OrderInterface $order,
|
|
||||||
PaymentModelInterface $paymentModel,
|
|
||||||
PaymentInterface $payment,
|
|
||||||
ObjectManager $objectManager,
|
|
||||||
StateMachineInterface $sm,
|
|
||||||
Collection $payments,
|
|
||||||
TokenInterface $token
|
|
||||||
) {
|
|
||||||
$request->getModel()->willReturn($paymentModel);
|
|
||||||
$request->getToken()->willReturn($token);
|
|
||||||
|
|
||||||
$order->getPayments()->willReturn($payments);
|
|
||||||
$payments->last()->willReturn($payment);
|
|
||||||
|
|
||||||
$paymentModel->getState()->willReturn(Payment::STATE_PENDING);
|
|
||||||
|
|
||||||
$factory->get($paymentModel, PaymentTransitions::GRAPH)->willReturn($sm);
|
|
||||||
$sm->getTransitionToState('cancelled')->willReturn(PaymentTransitions::SYLIUS_CANCEL);
|
|
||||||
$sm->apply(PaymentTransitions::SYLIUS_CANCEL)->shouldBeCalled()->will(function ($args) use ($paymentModel) {
|
|
||||||
$paymentModel->getState()->willReturn(Payment::STATE_CANCELLED);
|
|
||||||
});
|
|
||||||
|
|
||||||
$payment->execute(Argument::type('Payum\Core\Request\Sync'))->willReturn(null);
|
|
||||||
|
|
||||||
$payment
|
|
||||||
->execute(Argument::type('Sylius\Bundle\PayumBundle\Payum\Request\GetStatus'))
|
|
||||||
->will(function ($args) {
|
|
||||||
$args[0]->markCanceled();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
$objectManager->flush()->shouldBeCalled();
|
|
||||||
|
|
||||||
$this->execute($request);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,173 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of the Sylius package.
|
|
||||||
*
|
|
||||||
* (c) Paweł Jędrzejewski
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace spec\Sylius\Bundle\PayumBundle\Payum\Request;
|
|
||||||
|
|
||||||
use PhpSpec\ObjectBehavior;
|
|
||||||
use Sylius\Component\Payment\Model\PaymentInterface;
|
|
||||||
|
|
||||||
class GetStatusSpec extends ObjectBehavior
|
|
||||||
{
|
|
||||||
function let()
|
|
||||||
{
|
|
||||||
$this->beConstructedWith(new \stdClass);
|
|
||||||
}
|
|
||||||
|
|
||||||
function it_is_initializable()
|
|
||||||
{
|
|
||||||
$this->shouldHaveType('Sylius\Bundle\PayumBundle\Payum\Request\GetStatus');
|
|
||||||
}
|
|
||||||
|
|
||||||
function it_extends_base_status_class()
|
|
||||||
{
|
|
||||||
$this->shouldHaveType('Payum\Core\Request\BaseGetStatus');
|
|
||||||
}
|
|
||||||
|
|
||||||
function it_is_new_when_marked_as_new()
|
|
||||||
{
|
|
||||||
$this->markNew();
|
|
||||||
|
|
||||||
$this->isNew()->shouldReturn(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
function it_is_return_new_status_when_marked_as_new()
|
|
||||||
{
|
|
||||||
$this->markNew();
|
|
||||||
|
|
||||||
$this->getValue()->shouldReturn(PaymentInterface::STATE_NEW);
|
|
||||||
}
|
|
||||||
|
|
||||||
function it_is_captured_when_marked_as_captured()
|
|
||||||
{
|
|
||||||
$this->markCaptured();
|
|
||||||
|
|
||||||
$this->isCaptured()->shouldReturn(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
function it_is_return_completed_status_when_marked_as_captured()
|
|
||||||
{
|
|
||||||
$this->markCaptured();
|
|
||||||
|
|
||||||
$this->getValue()->shouldReturn(PaymentInterface::STATE_COMPLETED);
|
|
||||||
}
|
|
||||||
|
|
||||||
function it_is_authorized_when_marked_as_authorized()
|
|
||||||
{
|
|
||||||
$this->markAuthorized();
|
|
||||||
|
|
||||||
$this->isAuthorized()->shouldReturn(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
function it_is_return_authorized_status_when_marked_as_authorized()
|
|
||||||
{
|
|
||||||
$this->markAuthorized();
|
|
||||||
|
|
||||||
$this->getValue()->shouldReturn(PaymentInterface::STATE_AUTHORIZED);
|
|
||||||
}
|
|
||||||
|
|
||||||
function it_is_refunded_when_marked_as_refunded()
|
|
||||||
{
|
|
||||||
$this->markRefunded();
|
|
||||||
|
|
||||||
$this->isRefunded()->shouldReturn(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
function it_is_return_refunded_status_when_marked_as_refunded()
|
|
||||||
{
|
|
||||||
$this->markRefunded();
|
|
||||||
|
|
||||||
$this->getValue()->shouldReturn(PaymentInterface::STATE_REFUNDED);
|
|
||||||
}
|
|
||||||
|
|
||||||
function it_is_pending_when_marked_as_pending()
|
|
||||||
{
|
|
||||||
$this->markPending();
|
|
||||||
|
|
||||||
$this->isPending()->shouldReturn(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
function it_is_return_pending_status_when_marked_as_pending()
|
|
||||||
{
|
|
||||||
$this->markPending();
|
|
||||||
|
|
||||||
$this->getValue()->shouldReturn(PaymentInterface::STATE_PROCESSING);
|
|
||||||
}
|
|
||||||
|
|
||||||
function it_is_failed_when_marked_as_failed()
|
|
||||||
{
|
|
||||||
$this->markFailed();
|
|
||||||
|
|
||||||
$this->isFailed()->shouldReturn(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
function it_is_return_failed_status_when_marked_as_failed()
|
|
||||||
{
|
|
||||||
$this->markFailed();
|
|
||||||
|
|
||||||
$this->getValue()->shouldReturn(PaymentInterface::STATE_FAILED);
|
|
||||||
}
|
|
||||||
|
|
||||||
function it_is_canceled_when_marked_as_canceled()
|
|
||||||
{
|
|
||||||
$this->markCanceled();
|
|
||||||
|
|
||||||
$this->isCanceled()->shouldReturn(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
function it_is_return_void_status_when_marked_as_canceled()
|
|
||||||
{
|
|
||||||
$this->markCanceled();
|
|
||||||
|
|
||||||
$this->getValue()->shouldReturn(PaymentInterface::STATE_CANCELLED);
|
|
||||||
}
|
|
||||||
|
|
||||||
function it_is_suspended_when_marked_as_suspended()
|
|
||||||
{
|
|
||||||
$this->markSuspended();
|
|
||||||
|
|
||||||
$this->isSuspended()->shouldReturn(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
function it_is_return_void_status_when_marked_as_suspended()
|
|
||||||
{
|
|
||||||
$this->markSuspended();
|
|
||||||
|
|
||||||
$this->getValue()->shouldReturn(PaymentInterface::STATE_PROCESSING);
|
|
||||||
}
|
|
||||||
|
|
||||||
function it_is_expired_when_marked_as_expired()
|
|
||||||
{
|
|
||||||
$this->markExpired();
|
|
||||||
|
|
||||||
$this->isExpired()->shouldReturn(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
function it_is_return_failed_status_when_marked_as_expired()
|
|
||||||
{
|
|
||||||
$this->markExpired();
|
|
||||||
|
|
||||||
$this->getValue()->shouldReturn(PaymentInterface::STATE_FAILED);
|
|
||||||
}
|
|
||||||
|
|
||||||
function it_is_unknown_when_marked_as_unknown()
|
|
||||||
{
|
|
||||||
$this->markUnknown();
|
|
||||||
|
|
||||||
$this->isUnknown()->shouldReturn(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
function it_is_return_unknown_status_when_marked_as_unknown()
|
|
||||||
{
|
|
||||||
$this->markUnknown();
|
|
||||||
|
|
||||||
$this->getValue()->shouldReturn(PaymentInterface::STATE_UNKNOWN);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Add table
Reference in a new issue