Skip to content
This repository was archived by the owner on Sep 30, 2020. It is now read-only.

Commit d1e15a3

Browse files
committed
Add the BlackCard payment gateway
1 parent f7f41b5 commit d1e15a3

File tree

5 files changed

+141
-0
lines changed

5 files changed

+141
-0
lines changed

config/services.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,23 @@ services:
3333
App\Controller\:
3434
resource: '../src/Controller'
3535
tags: ['controller.service_arguments']
36+
37+
App\Payment\Factory\AppGatewayFactory: ~
38+
39+
app.black_card_paiement:
40+
class: Payum\Core\Bridge\Symfony\Builder\GatewayFactoryBuilder
41+
arguments:
42+
- '@App\Payment\Factory\AppGatewayFactory'
43+
tags:
44+
- {name: payum.gateway_factory_builder, factory: black_card_paiement}
45+
46+
App\Form\Type\BlackCardConfigurationType:
47+
tags:
48+
- {name: form.type}
49+
- {name: sylius.gateway_configuration_type, type: black_card_paiement, label: 'Paiement par BlackCard'}
50+
51+
52+
App\Payment\Action\CaptureAction:
53+
public: true
54+
tags:
55+
- {name: payum.action, factory: black_card_paiement, alias: payum.ation.capture}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace App\Form\Type;
4+
5+
use Payum\Core\Bridge\Symfony\Form\Type\CreditCardType;
6+
use Payum\Core\Model\CreditCard;
7+
use Symfony\Component\Form\AbstractType;
8+
use Symfony\Component\Form\Extension\Core\Type\TextType;
9+
use Symfony\Component\Form\FormBuilderInterface;
10+
use Symfony\Component\OptionsResolver\OptionsResolver;
11+
12+
class BlackCardConfigurationType extends AbstractType
13+
{
14+
public function buildForm(FormBuilderInterface $builder, array $options)
15+
{
16+
$builder
17+
->add('api_key', TextType::class)
18+
;
19+
}
20+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace App\Payment\Action;
4+
5+
use Payum\Core\Action\ActionInterface;
6+
use Payum\Core\Request\Capture;
7+
use Psr\Log\LoggerInterface;
8+
use Sylius\Component\Core\Model\PaymentInterface;
9+
10+
class CaptureAction implements ActionInterface
11+
{
12+
/**
13+
* @var LoggerInterface
14+
*/
15+
private $logger;
16+
17+
public function __construct(LoggerInterface $logger)
18+
{
19+
$this->logger = $logger;
20+
}
21+
22+
public function execute($request)
23+
{
24+
$payment = $request->getModel();
25+
26+
// TODO call an API, or a custom binary
27+
$this->logger->debug('Calling the fake Payment API, yeah !!!');
28+
29+
$payment->setDetails([
30+
'status' => 200,
31+
]);
32+
}
33+
34+
public function supports($request)
35+
{
36+
return
37+
$request instanceof Capture &&
38+
$request->getModel() instanceof PaymentInterface
39+
;
40+
}
41+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace App\Payment\Action;
4+
5+
use Payum\Core\Action\ActionInterface;
6+
use Payum\Core\Exception\RequestNotSupportedException;
7+
use Payum\Core\Request\GetStatusInterface;
8+
use Sylius\Component\Core\Model\PaymentInterface;
9+
10+
class StatusAction implements ActionInterface
11+
{
12+
public function execute($request): void
13+
{
14+
RequestNotSupportedException::assertSupports($this, $request);
15+
16+
/** @var PaymentInterface $payment */
17+
$payment = $request->getFirstModel();
18+
19+
$details = $payment->getDetails();
20+
21+
if (200 === $details['status']) {
22+
$request->markCaptured();
23+
24+
return;
25+
}
26+
27+
if (400 === $details['status']) {
28+
$request->markFailed();
29+
30+
return;
31+
}
32+
}
33+
34+
public function supports($request): bool
35+
{
36+
return
37+
$request instanceof GetStatusInterface &&
38+
$request->getFirstModel() instanceof PaymentInterface
39+
;
40+
}
41+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace App\Payment\Factory;
4+
5+
use App\Payment\Action\StatusAction;
6+
use Payum\Core\Bridge\Spl\ArrayObject;
7+
use Payum\Core\GatewayFactory;
8+
9+
class AppGatewayFactory extends GatewayFactory
10+
{
11+
protected function populateConfig(ArrayObject $config)
12+
{
13+
$config->defaults([
14+
'payum.factory_name' => 'black_card_payment',
15+
'payum.factory_title' => 'Paiement par BlackCard',
16+
'payum.action.status' => new StatusAction(),
17+
]);
18+
}
19+
}

0 commit comments

Comments
 (0)