diff --git a/src/Action/CaptureAction.php b/src/Action/CaptureAction.php index 04283fc..5463789 100644 --- a/src/Action/CaptureAction.php +++ b/src/Action/CaptureAction.php @@ -1,5 +1,7 @@ - * @author Patryk Drapik - */ final class CaptureAction implements ActionInterface, ApiAwareInterface { use GatewayAwareTrait; - /** - * @var Payum - */ + /** @var Payum */ private $payum; - /** - * @var MercanetBnpParibasBridgeInterface - */ + /** @var MercanetBnpParibasBridgeInterface */ private $mercanetBnpParibasBridge; - /** - * @param Payum $payum - */ public function __construct(Payum $payum) { $this->payum = $payum; @@ -61,7 +52,7 @@ public function setApi($mercanetBnpParibasBridge): void } /** - * {@inheritDoc} + * @inheritDoc * * @param Capture $request */ @@ -78,12 +69,10 @@ public function execute($request): void /** @var TokenInterface $token */ $token = $request->getToken(); - $transactionReference = isset($model['transactionReference']) ? $model['transactionReference'] : null; + $transactionReference = $model['transactionReference'] ?? null; if ($transactionReference !== null) { - if ($this->mercanetBnpParibasBridge->isPostMethod()) { - $model['status'] = $this->mercanetBnpParibasBridge->paymentVerification() ? PaymentInterface::STATE_COMPLETED : PaymentInterface::STATE_CANCELLED ; @@ -96,7 +85,6 @@ public function execute($request): void } if ($model['status'] === PaymentInterface::STATE_COMPLETED) { - return; } } @@ -121,7 +109,7 @@ public function execute($request): void /** @var OrderInterface $order */ $order = $payment->getOrder(); - $transactionReference = "MercanetWS" . uniqid() . "OR" . $order->getNumber(); + $transactionReference = 'MercanetWS' . uniqid() . 'OR' . $order->getNumber(); $model['transactionReference'] = $transactionReference; @@ -134,7 +122,7 @@ public function execute($request): void $targetUrl, $currencyCode, $transactionReference, - $automaticResponseUrl + $automaticResponseUrl, ); $request->setModel($model); @@ -151,12 +139,12 @@ private function createNotifyToken($gatewayName, $model) { return $this->payum->getTokenFactory()->createNotifyToken( $gatewayName, - $model + $model, ); } /** - * {@inheritDoc} + * @inheritDoc */ public function supports($request) { diff --git a/src/Action/ConvertPaymentAction.php b/src/Action/ConvertPaymentAction.php index 5bd8c9a..0191b45 100644 --- a/src/Action/ConvertPaymentAction.php +++ b/src/Action/ConvertPaymentAction.php @@ -1,5 +1,7 @@ - * @author Patryk Drapik - */ final class ConvertPaymentAction implements ActionInterface, GatewayAwareInterface { use GatewayAwareTrait; /** - * {@inheritDoc} + * @inheritDoc * * @param Convert $request */ diff --git a/src/Action/NotifyAction.php b/src/Action/NotifyAction.php index f2c16ee..c2a17e7 100644 --- a/src/Action/NotifyAction.php +++ b/src/Action/NotifyAction.php @@ -1,5 +1,7 @@ - */ final class NotifyAction implements ActionInterface, ApiAwareInterface { use GatewayAwareTrait; @@ -38,13 +37,14 @@ public function __construct(FactoryInterface $stateMachineFactory) $this->stateMachineFactory = $stateMachineFactory; } + /** + * @param $request Notify + */ public function execute($request): void { - /** @var $request Notify */ RequestNotSupportedException::assertSupports($this, $request); if ($this->mercanetBnpParibasBridge->paymentVerification()) { - /** @var PaymentInterface $payment */ $payment = $request->getFirstModel(); diff --git a/src/Action/StatusAction.php b/src/Action/StatusAction.php index efba1f9..3c12756 100644 --- a/src/Action/StatusAction.php +++ b/src/Action/StatusAction.php @@ -1,5 +1,7 @@ - * @author Patryk Drapik - */ final class StatusAction implements ActionInterface { - private RequestStack $requestStack; - /** - * @param RequestStack $requestStack - */ public function __construct(RequestStack $requestStack) { $this->requestStack = $requestStack; } /** - * {@inheritDoc} + * @inheritDoc * * @param GetStatusInterface $request */ @@ -49,25 +43,22 @@ public function execute($request): void /** @var Request $requestCurrent */ $requestCurrent = $this->requestStack->getCurrentRequest(); - $transactionReference = isset($model['transactionReference']) ? $model['transactionReference'] : null; + $transactionReference = $model['transactionReference'] ?? null; - $status = isset($model['status']) ? $model['status'] : null; + $status = $model['status'] ?? null; if ((null === $transactionReference) && !$requestCurrent->isMethod('POST')) { - $request->markNew(); return; } if ($status === PaymentInterface::STATE_CANCELLED) { - $request->markCanceled(); return; } if ($status === PaymentInterface::STATE_COMPLETED) { - $request->markCaptured(); return; @@ -77,7 +68,7 @@ public function execute($request): void } /** - * {@inheritDoc} + * @inheritDoc */ public function supports($request) { diff --git a/src/BitBagMercanetBnpParibasPlugin.php b/src/BitBagMercanetBnpParibasPlugin.php index 77d0835..befa3e2 100644 --- a/src/BitBagMercanetBnpParibasPlugin.php +++ b/src/BitBagMercanetBnpParibasPlugin.php @@ -1,5 +1,7 @@ - */ final class BitBagMercanetBnpParibasPlugin extends Bundle { use SyliusPluginTrait; -} \ No newline at end of file +} diff --git a/src/Bridge/MercanetBnpParibasBridge.php b/src/Bridge/MercanetBnpParibasBridge.php index a3ee391..fbf2c4d 100644 --- a/src/Bridge/MercanetBnpParibasBridge.php +++ b/src/Bridge/MercanetBnpParibasBridge.php @@ -1,5 +1,7 @@ - */ final class MercanetBnpParibasBridge implements MercanetBnpParibasBridgeInterface { - private RequestStack $requestStack; /** @phpstan-ignore-next-line We should not change our business logic now*/ @@ -48,7 +46,6 @@ public function createMercanet(ShaComposer $secretKey): Mercanet public function paymentVerification(): bool { if ($this->isPostMethod()) { - $this->mercanet = new Mercanet($this->secretKey); $this->mercanet->setResponse($_POST); diff --git a/src/Bridge/MercanetBnpParibasBridgeInterface.php b/src/Bridge/MercanetBnpParibasBridgeInterface.php index c663779..0c0d869 100644 --- a/src/Bridge/MercanetBnpParibasBridgeInterface.php +++ b/src/Bridge/MercanetBnpParibasBridgeInterface.php @@ -1,5 +1,7 @@ - */ interface MercanetBnpParibasBridgeInterface { /** @phpstan-ignore-next-line We should not change our business logic now*/ diff --git a/src/DependencyInjection/BitBagMercanetBnpParibasExtension.php b/src/DependencyInjection/BitBagMercanetBnpParibasExtension.php index 5a84a37..599c7fd 100644 --- a/src/DependencyInjection/BitBagMercanetBnpParibasExtension.php +++ b/src/DependencyInjection/BitBagMercanetBnpParibasExtension.php @@ -1,5 +1,7 @@ - */ final class BitBagMercanetBnpParibasExtension extends Extension { /** - * {@inheritdoc} + * @inheritdoc */ public function load(array $configs, ContainerBuilder $container) { diff --git a/src/Form/Type/MercanetBnpParibasGatewayConfigurationType.php b/src/Form/Type/MercanetBnpParibasGatewayConfigurationType.php index eb11428..0b37adf 100644 --- a/src/Form/Type/MercanetBnpParibasGatewayConfigurationType.php +++ b/src/Form/Type/MercanetBnpParibasGatewayConfigurationType.php @@ -1,5 +1,7 @@ - */ final class MercanetBnpParibasGatewayConfigurationType extends AbstractType { /** - * {@inheritdoc} + * @inheritdoc */ public function buildForm(FormBuilderInterface $builder, array $options) { @@ -43,8 +42,8 @@ public function buildForm(FormBuilderInterface $builder, array $options) 'constraints' => [ new NotBlank([ 'message' => 'bitbag.mercanet_bnp_paribas.secure_key.not_blank', - 'groups' => ['sylius'] - ]) + 'groups' => ['sylius'], + ]), ], ]) ->add('merchant_id', TextType::class, [ @@ -52,8 +51,8 @@ public function buildForm(FormBuilderInterface $builder, array $options) 'constraints' => [ new NotBlank([ 'message' => 'bitbag.mercanet_bnp_paribas.merchant_id.not_blank', - 'groups' => ['sylius'] - ]) + 'groups' => ['sylius'], + ]), ], ]) ->add('key_version', TextType::class, [ @@ -61,8 +60,8 @@ public function buildForm(FormBuilderInterface $builder, array $options) 'constraints' => [ new NotBlank([ 'message' => 'bitbag.mercanet_bnp_paribas.key_version.not_blank', - 'groups' => ['sylius'] - ]) + 'groups' => ['sylius'], + ]), ], ]) ->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) { diff --git a/src/Legacy/Mercanet.php b/src/Legacy/Mercanet.php index d48bc87..a568d38 100755 --- a/src/Legacy/Mercanet.php +++ b/src/Legacy/Mercanet.php @@ -1,5 +1,7 @@ READ THE FILE HEADER. - */ class Mercanet { - const TEST = "https://payment-webinit-mercanet.test.sips-services.com/rs-services/v2/paymentInit"; - const SIMULATION = "https://payment-webinit.simu.mercanet.bnpparibas.net/rs-services/v2/paymentInit"; - const PRODUCTION = "https://payment-webinit.mercanet.bnpparibas.net/rs-services/v2/paymentInit"; + public const TEST = 'https://payment-webinit-mercanet.test.sips-services.com/rs-services/v2/paymentInit'; + + public const SIMULATION = 'https://payment-webinit.simu.mercanet.bnpparibas.net/rs-services/v2/paymentInit'; + + public const PRODUCTION = 'https://payment-webinit.mercanet.bnpparibas.net/rs-services/v2/paymentInit'; - const INTERFACE_VERSION = "IR_WS_2.17"; - const INSTALMENT = "INSTALMENT"; - const BYPASS3DS_ALL = "ALL"; - const BYPASS3DS_MERCHANTWALLET = "MERCHANTWALLET"; + public const INTERFACE_VERSION = 'IR_WS_2.17'; - private array $brandsmap = array( + public const INSTALMENT = 'INSTALMENT'; + + public const BYPASS3DS_ALL = 'ALL'; + + public const BYPASS3DS_MERCHANTWALLET = 'MERCHANTWALLET'; + + private array $brandsmap = [ 'ACCEPTGIRO' => 'CREDIT_TRANSFER', 'AMEX' => 'CARD', 'BCMC' => 'CARD', @@ -46,8 +48,8 @@ class Mercanet 'VPAY' => 'CARD', 'VISA ELECTRON' => 'CARD', 'CBCONLINE' => 'CREDIT_TRANSFER', - 'KBCONLINE' => 'CREDIT_TRANSFER' - ); + 'KBCONLINE' => 'CREDIT_TRANSFER', + ]; /** @phpstan-ignore-next-line We should not change our business logic now*/ private ShaComposer $secretKey; @@ -56,9 +58,9 @@ class Mercanet private string $responseData; - private array $parameters = array(); + private array $parameters = []; - private array $pspFields = array( + private array $pspFields = [ 'amount', 'cardExpiryDate', 'cardNumber', 'cardCSCValue', 'currencyCode', 'merchantId', 'interfaceVersion', 'sealAlgorithm', 'transactionReference', 'keyVersion', 'paymentMeanBrand', 'customerLanguage', @@ -76,38 +78,42 @@ class Mercanet 'templateName', 'paymentMeanBrandList', 'instalmentData.number', 'instalmentData.datesList', 'instalmentData.transactionReferencesList', 'instalmentData.amountsList', 'paymentPattern', 'captureDay', 'captureMode', 'merchantTransactionDateTime', 'fraudData.bypass3DS', 'seal', - 'orderChannel', 'orderId', 'returnContext', 'transactionOrigin', 'merchantWalletId', 'paymentMeanId' - ); + 'orderChannel', 'orderId', 'returnContext', 'transactionOrigin', 'merchantWalletId', 'paymentMeanId', + ]; - private array $requiredFields = array( + private array $requiredFields = [ 'amount', 'currencyCode', 'interfaceVersion', 'keyVersion', 'merchantId', 'normalReturnUrl', 'orderChannel', - 'transactionReference' - ); + 'transactionReference', + ]; - public array $allowedlanguages = array( - 'nl', 'fr', 'de', 'it', 'es', 'cy', 'en' - ); + public array $allowedlanguages = [ + 'nl', 'fr', 'de', 'it', 'es', 'cy', 'en', + ]; - private static array $currencies = array( + private static array $currencies = [ 'EUR' => '978', 'USD' => '840', 'CHF' => '756', 'GBP' => '826', 'CAD' => '124', 'JPY' => '392', 'MXP' => '484', 'TRY' => '949', 'AUD' => '036', 'NZD' => '554', 'NOK' => '578', 'BRC' => '986', 'ARP' => '032', 'KHR' => '116', 'TWD' => '901', 'SEK' => '752', 'DKK' => '208', 'KRW' => '410', 'SGD' => '702', 'XPF' => '953', - 'XOF' => '952' - ); + 'XOF' => '952', + ]; public static function convertCurrencyToCurrencyCode(string $currency): string { - if (!in_array($currency, array_keys(self::$currencies))) + if (!in_array($currency, array_keys(self::$currencies))) { throw new \InvalidArgumentException("Unknown currencyCode $currency."); + } + return self::$currencies[$currency]; } public static function convertCurrencyCodeToCurrency(string $code): int|string|false { - if (!in_array($code, array_values(self::$currencies))) + if (!in_array($code, array_values(self::$currencies))) { throw new \InvalidArgumentException("Unknown Code $code."); + } + return array_search($code, self::$currencies); } @@ -136,10 +142,11 @@ public function shaCompose(array $parameters): string } } } - $shaString = str_replace("[", "", $shaString); - $shaString = str_replace("]", "", $shaString); - $shaString = str_replace("\",\"", "", $shaString); - $shaString = str_replace("\"", "", $shaString); + $shaString = str_replace('[', '', $shaString); + $shaString = str_replace(']', '', $shaString); + $shaString = str_replace('","', '', $shaString); + $shaString = str_replace('"', '', $shaString); + return $shaString; } @@ -176,7 +183,7 @@ public function setAutomaticResponseUrl(string $url): void public function setTransactionReference(string $transactionReference): void { if (preg_match('/[^a-zA-Z0-9_-]/', $transactionReference)) { - throw new \InvalidArgumentException("TransactionReference cannot contain special characters"); + throw new \InvalidArgumentException('TransactionReference cannot contain special characters'); } $this->parameters['transactionReference'] = $transactionReference; } @@ -184,13 +191,12 @@ public function setTransactionReference(string $transactionReference): void public function setAmount(int $amount): void { if (!is_int($amount)) { - throw new \InvalidArgumentException("Integer expected. Amount is always in cents"); + throw new \InvalidArgumentException('Integer expected. Amount is always in cents'); } if ($amount <= 0) { - throw new \InvalidArgumentException("Amount must be a positive number"); + throw new \InvalidArgumentException('Amount must be a positive number'); } $this->parameters['amount'] = $amount; - } public function setMerchantId(string $merchantId): void @@ -206,7 +212,7 @@ public function setKeyVersion(string $keyVersion): void public function setCurrency(string $currency): void { if (!array_key_exists(strtoupper($currency), self::getCurrencies())) { - throw new \InvalidArgumentException("Unknown currency"); + throw new \InvalidArgumentException('Unknown currency'); } $this->parameters['currencyCode'] = self::convertCurrencyToCurrencyCode($currency); } @@ -214,7 +220,7 @@ public function setCurrency(string $currency): void public function setLanguage(string $language): void { if (!in_array($language, $this->allowedlanguages)) { - throw new \InvalidArgumentException("Invalid language locale"); + throw new \InvalidArgumentException('Invalid language locale'); } $this->parameters['customerLanguage'] = $language; } @@ -236,10 +242,10 @@ public function setPaymentBrand(string $brand): void public function setBillingContactEmail(string $email): void { if (strlen($email) > 50) { - throw new \InvalidArgumentException("Email is too long"); + throw new \InvalidArgumentException('Email is too long'); } - if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { - throw new \InvalidArgumentException("Email is invalid"); + if (!filter_var($email, \FILTER_VALIDATE_EMAIL)) { + throw new \InvalidArgumentException('Email is invalid'); } $this->parameters['billingContact.email'] = $email; } @@ -247,7 +253,7 @@ public function setBillingContactEmail(string $email): void public function setBillingAddressStreet(string $street): void { if (strlen($street) > 35) { - throw new \InvalidArgumentException("street is too long"); + throw new \InvalidArgumentException('street is too long'); } $this->parameters['billingAddress.street'] = \Normalizer::normalize($street); } @@ -255,7 +261,7 @@ public function setBillingAddressStreet(string $street): void public function setBillingAddressStreetNumber(string $nr): void { if (strlen($nr) > 10) { - throw new \InvalidArgumentException("streetNumber is too long"); + throw new \InvalidArgumentException('streetNumber is too long'); } $this->parameters['billingAddress.streetNumber'] = \Normalizer::normalize($nr); } @@ -263,7 +269,7 @@ public function setBillingAddressStreetNumber(string $nr): void public function setBillingAddressZipCode(string $zipCode): void { if (strlen($zipCode) > 10) { - throw new \InvalidArgumentException("zipCode is too long"); + throw new \InvalidArgumentException('zipCode is too long'); } $this->parameters['billingAddress.zipCode'] = \Normalizer::normalize($zipCode); } @@ -271,7 +277,7 @@ public function setBillingAddressZipCode(string $zipCode): void public function setBillingAddressCity(string $city): void { if (strlen($city) > 25) { - throw new \InvalidArgumentException("city is too long"); + throw new \InvalidArgumentException('city is too long'); } $this->parameters['billingAddress.city'] = \Normalizer::normalize($city); } @@ -279,25 +285,25 @@ public function setBillingAddressCity(string $city): void public function setBillingContactPhone(string $phone): void { if (strlen($phone) > 30) { - throw new \InvalidArgumentException("phone is too long"); + throw new \InvalidArgumentException('phone is too long'); } $this->parameters['billingContact.phone'] = $phone; } public function setBillingContactFirstname(string $firstname): void { - $this->parameters['billingContact.firstname'] = str_replace(array("'", '"'), '', \Normalizer::normalize($firstname)); // replace quotes + $this->parameters['billingContact.firstname'] = str_replace(["'", '"'], '', \Normalizer::normalize($firstname)); // replace quotes } - public function setBillingContactLastname(string $lastname):void + public function setBillingContactLastname(string $lastname): void { - $this->parameters['billingContact.lastname'] = str_replace(array("'", '"'), '', \Normalizer::normalize($lastname)); // replace quotes + $this->parameters['billingContact.lastname'] = str_replace(["'", '"'], '', \Normalizer::normalize($lastname)); // replace quotes } public function setCaptureDay(string $number): void { if (strlen($number) > 2) { - throw new \InvalidArgumentException("captureDay is too long"); + throw new \InvalidArgumentException('captureDay is too long'); } $this->parameters['captureDay'] = $number; } @@ -305,7 +311,7 @@ public function setCaptureDay(string $number): void public function setCaptureMode(string $value): void { if (strlen($value) > 20) { - throw new \InvalidArgumentException("captureMode is too long"); + throw new \InvalidArgumentException('captureMode is too long'); } $this->parameters['captureMode'] = $value; } @@ -313,7 +319,7 @@ public function setCaptureMode(string $value): void public function setMerchantTransactionDateTime(string $value): void { if (strlen($value) > 25) { - throw new \InvalidArgumentException("merchantTransactionDateTime is too long"); + throw new \InvalidArgumentException('merchantTransactionDateTime is too long'); } $this->parameters['merchantTransactionDateTime'] = $value; } @@ -331,7 +337,7 @@ public function setSealAlgorithm(string $value): void public function setOrderChannel(string $value): void { if (strlen($value) > 20) { - throw new \InvalidArgumentException("orderChannel is too long"); + throw new \InvalidArgumentException('orderChannel is too long'); } $this->parameters['orderChannel'] = $value; } @@ -339,7 +345,7 @@ public function setOrderChannel(string $value): void public function setOrderId(string $value): void { if (strlen($value) > 32) { - throw new \InvalidArgumentException("orderId is too long"); + throw new \InvalidArgumentException('orderId is too long'); } $this->parameters['orderId'] = $value; } @@ -347,7 +353,7 @@ public function setOrderId(string $value): void public function setReturnContext(string $value): void { if (strlen($value) > 255) { - throw new \InvalidArgumentException("returnContext is too long"); + throw new \InvalidArgumentException('returnContext is too long'); } $this->parameters['returnContext'] = $value; } @@ -355,7 +361,7 @@ public function setReturnContext(string $value): void public function setTransactionOrigin(string $value): void { if (strlen($value) > 20) { - throw new \InvalidArgumentException("transactionOrigin is too long"); + throw new \InvalidArgumentException('transactionOrigin is too long'); } $this->parameters['transactionOrigin'] = $value; } @@ -363,10 +369,10 @@ public function setTransactionOrigin(string $value): void public function setCardNumber(string $number): void { if (strlen($number) > 19) { - throw new \InvalidArgumentException("cardNumber is too long"); + throw new \InvalidArgumentException('cardNumber is too long'); } if (strlen($number) < 12) { - throw new \InvalidArgumentException("cardNumber is too short"); + throw new \InvalidArgumentException('cardNumber is too short'); } $this->parameters['cardNumber'] = $number; } @@ -374,7 +380,7 @@ public function setCardNumber(string $number): void public function setCardExpiryDate(string $date): void { if (strlen($date) != 6) { - throw new \InvalidArgumentException("cardExpiryDate value is invalid"); + throw new \InvalidArgumentException('cardExpiryDate value is invalid'); } $this->parameters['cardExpiryDate'] = $date; } @@ -382,7 +388,7 @@ public function setCardExpiryDate(string $date): void public function setCardCSCValue(string $value): void { if (strlen($value) > 4) { - throw new \InvalidArgumentException("cardCSCValue value is invalid"); + throw new \InvalidArgumentException('cardCSCValue value is invalid'); } $this->parameters['cardCSCValue'] = $value; } @@ -390,7 +396,7 @@ public function setCardCSCValue(string $value): void public function setFraudDataBypass3DS(string $value): void { if (strlen($value) > 128) { - throw new \InvalidArgumentException("fraudData.bypass3DS is too long"); + throw new \InvalidArgumentException('fraudData.bypass3DS is too long'); } $this->parameters['fraudData.bypass3DS'] = $value; } @@ -398,7 +404,7 @@ public function setFraudDataBypass3DS(string $value): void public function setMerchantWalletId(string $wallet): void { if (strlen($wallet) > 21) { - throw new \InvalidArgumentException("merchantWalletId is too long"); + throw new \InvalidArgumentException('merchantWalletId is too long'); } $this->parameters['merchantWalletId'] = $wallet; } @@ -406,7 +412,7 @@ public function setMerchantWalletId(string $wallet): void public function setPaymentMeanId(string $value): void { if (strlen($value) > 6) { - throw new \InvalidArgumentException("paymentMeanId is too long"); + throw new \InvalidArgumentException('paymentMeanId is too long'); } $this->parameters['paymentMeanId'] = $value; } @@ -414,10 +420,10 @@ public function setPaymentMeanId(string $value): void public function setInstalmentDataNumber(string $number): void { if (strlen($number) > 2) { - throw new \InvalidArgumentException("instalmentData.number is too long"); + throw new \InvalidArgumentException('instalmentData.number is too long'); } if (($number < 2) || ($number > 50)) { - throw new \InvalidArgumentException("instalmentData.number invalid value : value must be set between 2 and 50"); + throw new \InvalidArgumentException('instalmentData.number invalid value : value must be set between 2 and 50'); } $this->parameters['instalmentData.number'] = $number; } @@ -448,6 +454,7 @@ public function __call(string $method, array $args): ?string $field = lcfirst(substr($method, 3)); if (in_array($field, $this->pspFields)) { $this->parameters[$field] = $args[0]; + return null; } } @@ -465,6 +472,7 @@ public function __call(string $method, array $args): ?string public function toArray(): array { ksort($this->parameters); + return $this->parameters; } @@ -472,55 +480,55 @@ public function toParameterString(): string { ksort($this->parameters); - $dataName = ""; - $parameterArray = array(); + $dataName = ''; + $parameterArray = []; $chaine = '{'; foreach ($this->parameters as $key => $val) { - $dataArray = explode(".", $key); + $dataArray = explode('.', $key); if (count($dataArray) > 1) { if ($dataName == $dataArray[0]) { $parameterArray[$dataArray[1]] = $val; } else { - if ($dataName != "") { + if ($dataName != '') { if (strlen($chaine) != 1) { - $chaine .= ","; + $chaine .= ','; } $chaine .= '"' . $dataName . '":' . json_encode($parameterArray); } unset($parameterArray); - $parameterArray = array(); + $parameterArray = []; $dataName = $dataArray[0]; $parameterArray[$dataArray[1]] = $val; } } else { - if ($dataName != "") { + if ($dataName != '') { if (strlen($chaine) != 1) { - $chaine .= ","; + $chaine .= ','; } $chaine .= '"' . $dataName . '":' . json_encode($parameterArray); - $dataName = ""; + $dataName = ''; } if (strlen($chaine) != 1) { - $chaine .= ","; + $chaine .= ','; } $chaine .= '"' . $key . '":"' . $val . '"'; } } - if ($dataName != "") { + if ($dataName != '') { if (strlen($chaine) != 1) { - $chaine .= ","; + $chaine .= ','; } $chaine .= '"' . $dataName . '":' . json_encode($parameterArray); } $chaine .= ',"seal" : "' . $this->getShaSign() . '" }'; - $chaine = str_replace(":\"[", ":[", $chaine); - $chaine = str_replace("]\"", "]", $chaine); - $chaine = str_replace("\\\"", "\"", $chaine); + $chaine = str_replace(':"[', ':[', $chaine); + $chaine = str_replace(']"', ']', $chaine); + $chaine = str_replace('\\"', '"', $chaine); + return $chaine; } - /** @phpstan-ignore-next-line We should not change our business logic now*/ public static function createFromArray(ShaComposer $shaComposer, array $parameters): PaymentRequest|static { @@ -529,6 +537,7 @@ public static function createFromArray(ShaComposer $shaComposer, array $paramete foreach ($parameters as $key => $value) { $instance->{"set$key"}($value); } + return $instance; } @@ -536,28 +545,28 @@ public function validate(): void { foreach ($this->requiredFields as $field) { if (empty($this->parameters[$field])) { - throw new \RuntimeException($field . " can not be empty"); + throw new \RuntimeException($field . ' can not be empty'); } } } protected function validateUri(string $uri): void { - if (!filter_var($uri, FILTER_VALIDATE_URL)) { - throw new \InvalidArgumentException("Uri is not valid"); + if (!filter_var($uri, \FILTER_VALIDATE_URL)) { + throw new \InvalidArgumentException('Uri is not valid'); } if (strlen($uri) > 200) { - throw new \InvalidArgumentException("Uri is too long"); + throw new \InvalidArgumentException('Uri is too long'); } } - const SHASIGN_FIELD = "SEAL"; + public const SHASIGN_FIELD = 'SEAL'; - const DATA_FIELD = "DATA"; + public const DATA_FIELD = 'DATA'; public function setResponse(array $httpRequest): void { - $httpRequest = array_change_key_case($httpRequest, CASE_UPPER); + $httpRequest = array_change_key_case($httpRequest, \CASE_UPPER); $this->shaSign = $this->extractShaSign($httpRequest); $this->parameters = $this->filterRequestParameters($httpRequest); } @@ -578,7 +587,7 @@ private function filterRequestParameters(array $httpRequest): array if (!array_key_exists(self::DATA_FIELD, $httpRequest) || $httpRequest[self::DATA_FIELD] == '') { throw new \InvalidArgumentException('Data parameter not present in parameters.'); } - $parameters = array(); + $parameters = []; $this->responseData = $httpRequest[self::DATA_FIELD]; $dataString = $httpRequest[self::DATA_FIELD]; $this->dataString = $dataString; @@ -612,23 +621,25 @@ public function isValid(): bool $signature = $this->responseData; $compute = hash('sha256', utf8_encode($signature . $this->secretKey)); if (strcmp($this->shaSign, $compute) == 0) { - if ((strcmp($this->parameters['responseCode'], "00") == 0) || (strcmp($this->parameters['responseCode'], "60") == 0)) { + if ((strcmp($this->parameters['responseCode'], '00') == 0) || (strcmp($this->parameters['responseCode'], '60') == 0)) { $resultat = true; } } + return $resultat; } - function getXmlValueByTag(string $inXmlset, string $needle): ?string + public function getXmlValueByTag(string $inXmlset, string $needle): ?string { $resource = xml_parser_create(); xml_parse_into_struct($resource, $inXmlset, $outArray); - xml_parser_free($resource);//Free an XML parser - for ($i = 0; $i < count($outArray); $i++) { + xml_parser_free($resource); //Free an XML parser + for ($i = 0; $i < count($outArray); ++$i) { if ($outArray[$i]['tag'] == strtoupper($needle)) { $tagValue = $outArray[$i]['value']; } } + return $tagValue ?? null; } @@ -645,47 +656,47 @@ public function getResponseRequest(): string public function executeRequest(): ?string { $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $this->getUrl()); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_POST, true); - curl_setopt($ch, CURLOPT_POSTFIELDS, $this->toParameterString()); - curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Accept:application/json')); - curl_setopt($ch, CURLOPT_PORT, 443); - curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); + curl_setopt($ch, \CURLOPT_URL, $this->getUrl()); + curl_setopt($ch, \CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, \CURLOPT_POST, true); + curl_setopt($ch, \CURLOPT_POSTFIELDS, $this->toParameterString()); + curl_setopt($ch, \CURLOPT_HTTPHEADER, ['Content-Type: application/json', 'Accept:application/json']); + curl_setopt($ch, \CURLOPT_PORT, 443); + curl_setopt($ch, \CURLOPT_SSL_VERIFYHOST, false); /** @var string $result */ $result = curl_exec($ch); $info = curl_getinfo($ch); if (!$result) { - Print "curl error: " . curl_error($ch) . "\n"; + echo 'curl error: ' . curl_error($ch) . "\n"; curl_close($ch); die(); } if ($info['http_code'] != 200) { - Print "service error: " . $info['http_code'] . "\n"; - Print "return: " . $result . "\n"; + echo 'service error: ' . $info['http_code'] . "\n"; + echo 'return: ' . $result . "\n"; curl_close($ch); die(); } curl_close($ch); if (strlen($result) == 0) { - Print "service did not sent back data\n"; + echo "service did not sent back data\n"; die(); } $result_array = json_decode($result); - if ($result_array->redirectionStatusCode == "00" ) { - - return "
redirectionUrl . "\">" . - "redirectionVersion . "\">" . - "redirectionData . "\">" . - "
" . - "" . - ""; + if ($result_array->redirectionStatusCode == '00') { + return '
' . + '' . + '' . + '
' . + '' . + ''; } + return null; } } diff --git a/src/Legacy/SimplePayment.php b/src/Legacy/SimplePayment.php index beb3458..1cde608 100755 --- a/src/Legacy/SimplePayment.php +++ b/src/Legacy/SimplePayment.php @@ -1,5 +1,7 @@ - * @author Patryk Drapik - */ final class SimplePayment { - private Mercanet $mercanet; private string $environment; @@ -46,9 +43,8 @@ public function __construct( string $targetUrl, string $currency, string $transactionReference, - string $automaticResponseUrl - ) - { + string $automaticResponseUrl, + ) { $this->automaticResponseUrl = $automaticResponseUrl; $this->transactionReference = $transactionReference; $this->mercanet = $mercanet; @@ -69,7 +65,7 @@ public function execute(): void $this->mercanet->setKeyVersion($this->keyVersion); $this->mercanet->setAmount($this->amount); $this->mercanet->setCurrency($this->currency); - $this->mercanet->setOrderChannel("INTERNET"); + $this->mercanet->setOrderChannel('INTERNET'); $this->mercanet->setTransactionReference($this->transactionReference); $this->mercanet->setNormalReturnUrl($this->targetUrl); $this->mercanet->setAutomaticResponseUrl($this->automaticResponseUrl); @@ -106,8 +102,12 @@ private function resolveEnvironment(): void } throw new \InvalidArgumentException( - sprintf('The "%s" environment is invalid. Expected %s or %s', - $this->environment, Mercanet::PRODUCTION, Mercanet::TEST) + sprintf( + 'The "%s" environment is invalid. Expected %s or %s', + $this->environment, + Mercanet::PRODUCTION, + Mercanet::TEST, + ), ); } } diff --git a/src/MercanetBnpParibasGatewayFactory.php b/src/MercanetBnpParibasGatewayFactory.php index d4846c3..d931eea 100644 --- a/src/MercanetBnpParibasGatewayFactory.php +++ b/src/MercanetBnpParibasGatewayFactory.php @@ -1,5 +1,7 @@ - */ final class MercanetBnpParibasGatewayFactory extends GatewayFactory { /** - * {@inheritDoc} + * @inheritDoc */ protected function populateConfig(ArrayObject $config): void { diff --git a/tests/Behat/Context/Setup/ChannelContext.php b/tests/Behat/Context/Setup/ChannelContext.php index 0beeff8..8af4f90 100644 --- a/tests/Behat/Context/Setup/ChannelContext.php +++ b/tests/Behat/Context/Setup/ChannelContext.php @@ -1,5 +1,7 @@ - */ final class ChannelContext implements Context { - /** - * @var DefaultChannelFactory - */ + /** @var DefaultChannelFactory */ private $defaultChannelFactory; - /** - * @param DefaultChannelFactory $defaultChannelFactory - */ public function __construct(DefaultChannelFactory $defaultChannelFactory) { $this->defaultChannelFactory = $defaultChannelFactory; @@ -38,4 +32,4 @@ public function addingANewChannelIn() { $this->defaultChannelFactory->create('FR', 'France', 'EUR'); } -} \ No newline at end of file +} diff --git a/tests/Behat/Context/Setup/MercanetBnpParibasContext.php b/tests/Behat/Context/Setup/MercanetBnpParibasContext.php index c1802a0..f217d24 100644 --- a/tests/Behat/Context/Setup/MercanetBnpParibasContext.php +++ b/tests/Behat/Context/Setup/MercanetBnpParibasContext.php @@ -1,5 +1,7 @@ - */ final class MercanetBnpParibasContext implements Context { - /** - * @var SharedStorageInterface - */ + /** @var SharedStorageInterface */ private $sharedStorage; - /** - * @var PaymentMethodRepositoryInterface - */ + /** @var PaymentMethodRepositoryInterface */ private $paymentMethodRepository; - /** - * @var ExampleFactoryInterface - */ + /** @var ExampleFactoryInterface */ private $paymentMethodExampleFactory; - /** - * @var FactoryInterface - */ + /** @var FactoryInterface */ private $paymentMethodTranslationFactory; - /** - * @var ObjectManager - */ + /** @var ObjectManager */ private $paymentMethodManager; - /** - * @param SharedStorageInterface $sharedStorage - * @param PaymentMethodRepositoryInterface $paymentMethodRepository - * @param ExampleFactoryInterface $paymentMethodExampleFactory - * @param FactoryInterface $paymentMethodTranslationFactory - * @param ObjectManager $paymentMethodManager - */ public function __construct( SharedStorageInterface $sharedStorage, PaymentMethodRepositoryInterface $paymentMethodRepository, ExampleFactoryInterface $paymentMethodExampleFactory, FactoryInterface $paymentMethodTranslationFactory, - ObjectManager $paymentMethodManager + ObjectManager $paymentMethodManager, ) { $this->sharedStorage = $sharedStorage; $this->paymentMethodRepository = $paymentMethodRepository; @@ -75,7 +57,7 @@ public function __construct( */ public function theStoreHasAPaymentMethodWithACodeAndMercanetBnpParibasCheckoutGateway( $paymentMethodName, - $paymentMethodCode + $paymentMethodCode, ) { $paymentMethod = $this->createPaymentMethod($paymentMethodName, $paymentMethodCode, 'Mercanet Bnp Paribas'); $paymentMethod->getGatewayConfig()->setConfig([ @@ -103,9 +85,8 @@ private function createPaymentMethod( $code, $description = '', $addForCurrentChannel = true, - $position = null + $position = null, ) { - /** @var PaymentMethodInterface $paymentMethod */ $paymentMethod = $this->paymentMethodExampleFactory->create([ 'name' => ucfirst($name), diff --git a/tests/Behat/Context/Ui/Admin/ManagingPaymentMethodsContext.php b/tests/Behat/Context/Ui/Admin/ManagingPaymentMethodsContext.php index 11f8013..d0b8ef4 100644 --- a/tests/Behat/Context/Ui/Admin/ManagingPaymentMethodsContext.php +++ b/tests/Behat/Context/Ui/Admin/ManagingPaymentMethodsContext.php @@ -1,5 +1,7 @@ - */ final class ManagingPaymentMethodsContext implements Context { - /** - * @var CreatePageInterface - */ + /** @var CreatePageInterface */ private $createPage; - /** - * @param CreatePageInterface $createPage - */ public function __construct(CreatePageInterface $createPage) { $this->createPage = $createPage; diff --git a/tests/Behat/Context/Ui/Shop/MercanetBnpParibasContext.php b/tests/Behat/Context/Ui/Shop/MercanetBnpParibasContext.php index 9029708..67a8339 100644 --- a/tests/Behat/Context/Ui/Shop/MercanetBnpParibasContext.php +++ b/tests/Behat/Context/Ui/Shop/MercanetBnpParibasContext.php @@ -1,5 +1,7 @@ - */ final class MercanetBnpParibasContext implements Context { - /** - * @var MercanetBnpParibasMocker - */ + /** @var MercanetBnpParibasMocker */ private $mercanetBnpParibasMocker; - /** - * @var CompletePageInterface - */ + /** @var CompletePageInterface */ private $summaryPage; - /** - * @var MercanetBnpParibasCheckoutPageInterface - */ + /** @var MercanetBnpParibasCheckoutPageInterface */ private $mercanetBnpParibasCheckoutPage; - /** - * @var ShowPageInterface - */ + /** @var ShowPageInterface */ private $orderDetails; - /** - * @param CompletePageInterface $summaryPage - * @param MercanetBnpParibasMocker $mercanetBnpParibasMocker - * @param MercanetBnpParibasCheckoutPageInterface $mercanetBnpParibasCheckoutPage - * @param ShowPageInterface $orderDetails - */ public function __construct( MercanetBnpParibasMocker $mercanetBnpParibasMocker, CompletePageInterface $summaryPage, MercanetBnpParibasCheckoutPageInterface $mercanetBnpParibasCheckoutPage, - ShowPageInterface $orderDetails - ) - { + ShowPageInterface $orderDetails, + ) { $this->orderDetails = $orderDetails; $this->mercanetBnpParibasCheckoutPage = $mercanetBnpParibasCheckoutPage; $this->summaryPage = $summaryPage; @@ -74,7 +58,7 @@ public function iConfirmMyOrderWithMercanetBnpParibasPayment() */ public function iSignInToMercanetBnpParibasAndPaySuccessfully() { - $this->mercanetBnpParibasMocker->completedPayment(function (){ + $this->mercanetBnpParibasMocker->completedPayment(function () { $this->mercanetBnpParibasCheckoutPage->pay(); }); } @@ -85,7 +69,7 @@ public function iSignInToMercanetBnpParibasAndPaySuccessfully() */ public function iCancelMyMercanetBnpParibasPayment() { - $this->mercanetBnpParibasMocker->canceledPayment(function (){ + $this->mercanetBnpParibasMocker->canceledPayment(function () { $this->mercanetBnpParibasCheckoutPage->cancel(); }); } @@ -95,8 +79,8 @@ public function iCancelMyMercanetBnpParibasPayment() */ public function iTryToPayAgainMercanetBnpParibasPayment() { - $this->mercanetBnpParibasMocker->completedPayment(function (){ + $this->mercanetBnpParibasMocker->completedPayment(function () { $this->orderDetails->pay(); }); } -} \ No newline at end of file +} diff --git a/tests/Behat/Mocker/MercanetBnpParibasMocker.php b/tests/Behat/Mocker/MercanetBnpParibasMocker.php index e45f880..718146b 100644 --- a/tests/Behat/Mocker/MercanetBnpParibasMocker.php +++ b/tests/Behat/Mocker/MercanetBnpParibasMocker.php @@ -1,5 +1,7 @@ - */ final class MercanetBnpParibasMocker { - /** - * @var Mocker - */ + /** @var Mocker */ private $mocker; - /** - * @param Mocker $mocker - */ public function __construct(Mocker $mocker) { $this->mocker = $mocker; } - /** - * @param callable $action - */ public function completedPayment(callable $action) { $openMercanetBnpParibasWrapper = $this->mocker @@ -81,9 +72,6 @@ public function completedPayment(callable $action) $this->mocker->unmockAll(); } - /** - * @param callable $action - */ public function canceledPayment(callable $action) { $openMercanetBnpParibasWrapper = $this->mocker diff --git a/tests/Behat/Page/Admin/PaymentMethod/CreatePage.php b/tests/Behat/Page/Admin/PaymentMethod/CreatePage.php index 025604a..9f973a6 100644 --- a/tests/Behat/Page/Admin/PaymentMethod/CreatePage.php +++ b/tests/Behat/Page/Admin/PaymentMethod/CreatePage.php @@ -1,5 +1,7 @@ - */ class CreatePage extends BaseCreatePage implements CreatePageInterface { /** - * {@inheritdoc} + * @inheritdoc */ public function setMercanetBnpParibasPluginGatewaySecretKey($secretKey) { @@ -27,7 +26,7 @@ public function setMercanetBnpParibasPluginGatewaySecretKey($secretKey) } /** - * {@inheritdoc} + * @inheritdoc */ public function setMercanetBnpParibasPluginGatewayMerchantId($merchantId) { @@ -35,7 +34,7 @@ public function setMercanetBnpParibasPluginGatewayMerchantId($merchantId) } /** - * {@inheritdoc} + * @inheritdoc */ public function setMercanetBnpParibasPluginGatewayKeyVersion($keyVersion) { @@ -43,7 +42,7 @@ public function setMercanetBnpParibasPluginGatewayKeyVersion($keyVersion) } /** - * {@inheritdoc} + * @inheritdoc */ public function setMercanetBnpParibasPluginGatewayEnvironment($environment) { @@ -51,7 +50,7 @@ public function setMercanetBnpParibasPluginGatewayEnvironment($environment) } /** - * {@inheritdoc} + * @inheritdoc */ public function findValidationMessage($message) { diff --git a/tests/Behat/Page/Admin/PaymentMethod/CreatePageInterface.php b/tests/Behat/Page/Admin/PaymentMethod/CreatePageInterface.php index 1013605..2c2617d 100644 --- a/tests/Behat/Page/Admin/PaymentMethod/CreatePageInterface.php +++ b/tests/Behat/Page/Admin/PaymentMethod/CreatePageInterface.php @@ -1,5 +1,7 @@ - */ interface CreatePageInterface extends BaseCreatePageInterface { /** diff --git a/tests/Behat/Page/External/MercanetBnpParibasCheckoutPage.php b/tests/Behat/Page/External/MercanetBnpParibasCheckoutPage.php index d2642a9..e77febf 100644 --- a/tests/Behat/Page/External/MercanetBnpParibasCheckoutPage.php +++ b/tests/Behat/Page/External/MercanetBnpParibasCheckoutPage.php @@ -1,5 +1,7 @@ - */ final class MercanetBnpParibasCheckoutPage extends Page implements MercanetBnpParibasCheckoutPageInterface { - /** - * @var RepositoryInterface - */ + /** @var RepositoryInterface */ private $securityTokenRepository; - /** - * @param Session $session - * @param array $parameters - * @param RepositoryInterface $securityTokenRepository - */ public function __construct(Session $session, array $parameters, RepositoryInterface $securityTokenRepository) { parent::__construct($session, $parameters); @@ -38,7 +30,7 @@ public function __construct(Session $session, array $parameters, RepositoryInter } /** - * {@inheritDoc} + * @inheritDoc */ public function pay() { @@ -46,7 +38,7 @@ public function pay() } /** - * {@inheritDoc} + * @inheritDoc */ public function cancel() { @@ -54,8 +46,6 @@ public function cancel() } /** - * @param array $urlParameters - * * @return string */ protected function getUrl(array $urlParameters = []) @@ -81,4 +71,4 @@ private function findCaptureToken() throw new \RuntimeException('Cannot find capture token, check if you are after proper checkout steps'); } -} \ No newline at end of file +} diff --git a/tests/Behat/Page/External/MercanetBnpParibasCheckoutPageInterface.php b/tests/Behat/Page/External/MercanetBnpParibasCheckoutPageInterface.php index 8676553..36e5b1b 100644 --- a/tests/Behat/Page/External/MercanetBnpParibasCheckoutPageInterface.php +++ b/tests/Behat/Page/External/MercanetBnpParibasCheckoutPageInterface.php @@ -1,5 +1,7 @@ - */ interface MercanetBnpParibasCheckoutPageInterface extends PageInterface { /** @@ -30,4 +29,4 @@ public function pay(); * @throws DriverException */ public function cancel(); -} \ No newline at end of file +}