Skip to content
Snippets Groups Projects
Commit 7f750c4f authored by Nicolas Morand's avatar Nicolas Morand Committed by Dominique CLAUSE
Browse files

Resolve #3503519 "Commerce 3 compatibility"

parent fd04b4e4
No related branches found
No related tags found
2 merge requests!4Draft: Quick fix 'Class contains 1 abstract method and must therefore be declared...,!2Resolve #3503519 "Commerce 3 compatibility"
......@@ -3,17 +3,14 @@
namespace Drupal\commerce_payplug\Plugin\Commerce\PaymentGateway;
use Drupal\commerce_order\Entity\OrderInterface;
use Drupal\commerce_payment\Attribute\CommercePaymentGateway;
use Drupal\commerce_payment\Entity\PaymentInterface;
use Drupal\commerce_payment\Exception\PaymentGatewayException;
use Drupal\commerce_payment\PaymentMethodTypeManager;
use Drupal\commerce_payment\PaymentTypeManager;
use Drupal\commerce_payment\Plugin\Commerce\PaymentGateway\OffsitePaymentGatewayBase;
use Drupal\commerce_payplug\Services\PayPlugServiceInterface;
use Drupal\commerce_payplug\PluginForm\OffsitePayPlug\OffsitePayPlugForm;
use Drupal\commerce_price\Price;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Payplug\Exception\BadRequestException;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
......@@ -21,20 +18,17 @@ use Symfony\Component\HttpFoundation\Request;
/**
* Provides the off-site PayPlug payment gateway.
*
* @CommercePaymentGateway(
* id = "offsite_payplug",
* label = "PayPlug (Off-site redirect)",
* display_label = "Payment via PayPlug",
* forms = {
* "offsite-payment" = "Drupal\commerce_payplug\PluginForm\OffsitePayPlug\OffsitePayPlugForm",
* },
* payment_method_types = {"credit_card"},
* credit_card_types = {
* "visa", "mastercard"
* },
* )
*/
#[CommercePaymentGateway(
id: 'offsite_payplug',
label: new TranslatableMarkup('PayPlug (Off-site redirect)'),
display_label: new TranslatableMarkup('Payment via PayPlug'),
forms: [
'offsite-payment' => OffsitePayPlugForm::class,
],
payment_method_types: ['credit_card'],
credit_card_types: ['visa', 'mastercard'],
)]
class OffsitePayPlug extends OffsitePaymentGatewayBase implements OffsitePayPlugInterface {
/**
......@@ -51,49 +45,14 @@ class OffsitePayPlug extends OffsitePaymentGatewayBase implements OffsitePayPlug
*/
protected $messenger;
/**
* Constructs a new OffsitePayPlug object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\commerce_payment\PaymentTypeManager $payment_type_manager
* The payment type manager.
* @param \Drupal\commerce_payment\PaymentMethodTypeManager $payment_method_type_manager
* The payment method type manager.
* @param \Drupal\commerce_payplug\Services\PayplugServiceInterface
* The PayPlug payment service interface.
* @param \Drupal\Component\Datetime\TimeInterface $time
* The time service.
* @param \Drupal\Core\Messenger\MessengerInterface $messenger
* The messenger.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, PaymentTypeManager $payment_type_manager, PaymentMethodTypeManager $payment_method_type_manager, PayPlugServiceInterface $payplug_service, TimeInterface $time, MessengerInterface $messenger) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $entity_type_manager, $payment_type_manager, $payment_method_type_manager, $time);
$this->payPlugService = $payplug_service;
$this->messenger = $messenger;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('entity_type.manager'),
$container->get('plugin.manager.commerce_payment_type'),
$container->get('plugin.manager.commerce_payment_method_type'),
$container->get('commerce_payplug.payplug.service'),
$container->get('datetime.time'),
$container->get('messenger')
);
$instance = parent::create($container, $configuration, $plugin_id, $plugin_definition);
$instance->payPlugService = $container->get('commerce_payplug.payplug.service');
$instance->messenger = $container->get('messenger');
return $instance;
}
/**
......@@ -188,7 +147,7 @@ class OffsitePayPlug extends OffsitePaymentGatewayBase implements OffsitePayPlug
$this->payPlugService->setApiKey($api_key);
$data = [
'amount' => (int) $payment_gateway_plugin->toMinorUnits($amount)
'amount' => (int) $this->minorUnitsConverter->toMinorUnits($amount)
];
try {
if ($this->payPlugService->createPayPlugRefund($payment->getRemoteId(), $data)) {
......
......@@ -24,11 +24,19 @@ class OffsitePayPlugForm extends BasePaymentOffsiteForm {
*/
protected $payPlugService;
/**
* The minor units converter.
*
* @var \Drupal\commerce_price\MinorUnitsConverterInterface
*/
protected $minorUnitsConverter;
/**
* Constructs a new PaymentOffsiteForm object.
*/
function __construct() {
public function __construct() {
$this->payPlugService = \Drupal::service('commerce_payplug.payplug.service');
$this->minorUnitsConverter = \Drupal::service('commerce_price.minor_units_converter');
}
/**
......@@ -58,7 +66,7 @@ class OffsitePayPlugForm extends BasePaymentOffsiteForm {
$payplug_payment = NULL;
try {
$object = [
'amount' => (int) $payment_gateway_plugin->toMinorUnits($payment->getAmount()),
'amount' => (int) $this->minorUnitsConverter->toMinorUnits($payment->getAmount()),
'currency' => $payment->getAmount()->getCurrencyCode(),
'billing' => [
'first_name' => $address->getGivenName() ? $address->getGivenName() : 'N/A',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment