Skip to content

Commit

Permalink
Completed documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Franck Allimant committed Jan 25, 2024
1 parent 3c847e0 commit 06405d5
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 42 deletions.
17 changes: 15 additions & 2 deletions Axepta.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,26 @@ class Axepta extends AbstractPaymentModule
public const PAYMENT_FEATURE = 'active_payment_feature';

public const PAYMENT_FEATURE_UNIQUE = 'unique';
public const PAYMENT_FEATURE_FIXED_AMOUNT_SUBSCRIPTION = 'fas';
public const PAYMENT_FEATURE_VARIABLE_AMOUNT_SUBSCRIPTION = 'vas';
public const PAYMENT_FEATURE_FIXED_AMOUNT_SUBSCRIPTION = 'fixed_subscription';
public const PAYMENT_FEATURE_VARIABLE_AMOUNT_SUBSCRIPTION = 'variable_subscription';

public const SEND_CONFIRMATION_MESSAGE_ONLY_IF_PAID = 'send_confirmation_message_only_if_paid';

public const AXCEPTA_CREATE_PAYMENT_EVENT = 'axepta.axcepta_create_payment_event';

public static function isSubscriptionMode() : bool
{
return in_array(self::getConfigValue(Axepta::PAYMENT_FEATURE), [
self::PAYMENT_FEATURE_VARIABLE_AMOUNT_SUBSCRIPTION,
self::PAYMENT_FEATURE_FIXED_AMOUNT_SUBSCRIPTION
], true);
}

public static function isUniqueMode() : bool
{
return self::getConfigValue(Axepta::PAYMENT_FEATURE) === self::PAYMENT_FEATURE_UNIQUE;
}

/**
* @throws \JsonException
* @throws \Propel\Runtime\Exception\PropelException
Expand Down
19 changes: 15 additions & 4 deletions Command/CreatePayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ protected function configure(): void

protected function execute(InputInterface $input, OutputInterface $output)
{
if (! Axepta::isSubscriptionMode()) {
$output->writeln(
'<error>This command is intended for use when the subscription payment feature is enabled.'
.'Subscription feature is not currently activated. ($feat is activated)</error>'
);

return Command::INVALID;
}

$this->initRequest();

$orderRef = $input->getArgument('original_order_ref');
Expand All @@ -62,7 +71,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
throw new TheliaProcessException("Unknown order $orderRef");
}

$newOrderRef = $input->getArgument('original_order_ref');
$newOrderRef = $input->getArgument('new_order_ref');

if (null === $newOrder = OrderQuery::create()->findOneByRef($newOrderRef)) {
throw new TheliaProcessException("Unknown order $newOrderRef");
Expand All @@ -72,10 +81,12 @@ protected function execute(InputInterface $input, OutputInterface $output)

$this->getDispatcher()->dispatch($event, Axepta::AXCEPTA_CREATE_PAYMENT_EVENT);

$output->writeln('Payment status : '. ($event->isSuccess() ? 'success' : 'failure'));
$output->writeln('Payment status : '.($event->isSuccess() ? 'success' : 'failure'));

if (!$event->isSuccess()) {
$output->writeln('<error> : '.$event->getErrorMessage().'</error>');

if (! $event->isSuccess()) {
$output->writeln('<error> : '. $event->getErrorMessage() .'</error>');
return Command::FAILURE;
}

return Command::SUCCESS;
Expand Down
6 changes: 6 additions & 0 deletions Config/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
<name>Nicolas Barbey</name>
<email>nbarbey@openstudio.fr</email>
</author>
<author>
<name>Franck Allimant</name>
<company>OpenStudio</company>
<email>fallimant@openstudio.fr</email>
<website>www.openstudio.fr</website>
</author>
</authors>
<type>classic</type>
<thelia>2.4.0</thelia>
Expand Down
6 changes: 0 additions & 6 deletions Controller/NotificationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,13 @@
namespace Axepta\Controller;

use Axepta\Axepta;
use Axepta\Model\AxceptaScheme;
use Axepta\Model\AxceptaSchemeQuery;
use Axepta\Model\AxceptaSchemes;
use Axepta\Service\PaymentService;
use Axepta\Util\Axepta as AxeptaPayment;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Thelia\Core\Event\Order\OrderEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\HttpFoundation\Request;
use Thelia\Core\HttpFoundation\Response;
use Thelia\Core\Translation\Translator;
use Thelia\Exception\TheliaProcessException;
use Thelia\Model\OrderQuery;
use Thelia\Model\OrderStatusQuery;
use Thelia\Module\BasePaymentModuleController;

Expand Down
11 changes: 5 additions & 6 deletions EventListener/SubscriptionPaymentListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ public function createPayment(CreatePaymentEvent $event): void
try {
$result = $this->sendPaymentRequest($data);

parse_str($result, $resultArray);

$action = $this->paymentService->processNotification(
explode('&', $result),
$resultArray,
Tlog::getInstance(),
$order,
$paymentResponse
Expand Down Expand Up @@ -97,15 +99,12 @@ protected function sendPaymentRequest(array $data): string
{
$ch = curl_init();

$postFields = implode('&', $data);
$postData = http_build_query($data);

curl_setopt($ch, \CURLOPT_URL, AxeptaPayment::DIRECT);
curl_setopt($ch, \CURLOPT_HTTP_VERSION, 1.0);
curl_setopt($ch, \CURLOPT_POST, 1);
curl_setopt($ch, \CURLOPT_POSTFIELDS, $postFields);
curl_setopt($ch, \CURLOPT_HEADER, 0);
curl_setopt($ch, \CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, \CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, \CURLOPT_TIMEOUT, 120);
curl_setopt($ch, \CURLOPT_FAILONERROR, 1);

Expand Down
30 changes: 24 additions & 6 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
# Axepta

This module adds the payment solution Axepta from BNP Paribas
This module adds the Axepta payment solution from BNP Paribas to your Thelia shop.

## Installation
This module supports two payment features :

- One time payment.
- Recurring card payments (Subscription), for variable amount and/or frequency.

### Manually
/!\ Recurring payments for a fixed amount and frequency is not yet supported.

* Copy the module into ```<thelia_root>/local/modules/``` directory and be sure that the name of the module is Axepta.
* Activate it in your thelia administration panel
You have to select the operating mode you want to use in the module configuration.
The module does not support both operating modes at the same time

### Composer
## Installation

Add it in your main thelia composer.json file

Expand All @@ -20,10 +23,25 @@ composer require thelia/axepta-module
## Usage
* Contact Axepta to create an account, or get test environment parameters (see below).
* Go to the module configuration and add your HMAC key, Blowfish encryption key, and your merchant id (MID).
* Select the payment feature you want to use (One-time payment / Subscription)
* Set the operation mode to production

Documentation : https://docs.axepta.bnpparibas

Test environment parameters : https://docs.axepta.bnpparibas/display/DOCBNP/3DSV2+Test+environment

If you want to test your configuration you can use this credit cards : https://docs.axepta.bnpparibas/display/DOCBNP/Test+Cards+-+Authentication

Axepta is based on Computop Paygate solution, a very detailed documentation is here : https://developer.computop.com/display/EN/Paygate+EN

## Command

When in subscription mode, you can use the `create-axcepta-payment` command to create en new payment. You have to
provide the first order of the subscription, and the order of the new payment.

Exemple : `create-axcepta-payment ORD000000000031 ORD000000000046`

ORD000000000031 is the first payement of the subscription, ORD000000000046 is the new
payment.

The result of the payment, and the potential error message is displayed on, the console.
21 changes: 5 additions & 16 deletions Service/PaymentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,6 @@ public function createPaymentData(Order $order, AxceptaScheme $schemeData = null

$paymentRequest->setCredentialOnFile(base64_encode(json_encode($cof)));

/*
if (!$schemeData) {
$paymentRequest->setThreeDSPolicy(
base64_encode(
json_encode([
'challengePreference' => 'mandateChallenge',
], \JSON_THROW_ON_ERROR)
)
);
}
*/
if ($schemeData) {
$paymentRequest->setSchemeReferenceID($schemeData->getSchemeReferenceId());

Expand All @@ -135,8 +124,6 @@ public function createPaymentData(Order $order, AxceptaScheme $schemeData = null
$order->getCustomer()->getFirstname().' '.$order->getCustomer()->getLastname()
);

$paymentRequest->validate();

$data = $paymentRequest->getBfishCrypt();
$len = $paymentRequest->getLen();

Expand Down Expand Up @@ -191,13 +178,15 @@ public function processNotification(array $parameters, Tlog $log, &$order, &$pay
$event->setStatus(OrderStatusQuery::getPaidStatus()?->getId());
$this->dispatcher->dispatch($event, TheliaEvents::ORDER_UPDATE_STATUS);

// Store recurring payment data
if (isset($paymentResponse->parameters['schemeReferenceID'])
// Store recurring payment data for subscriptions
if (isset($paymentResponse->parameters['schemeReferenceID'], $paymentResponse->parameters['card'])
&&
isset($paymentResponse->parameters['card'])
Axepta::isSubscriptionMode()
) {
$schemeId = $paymentResponse->parameters['schemeReferenceID'];

// Store SchemeReferenceId the first time we get it. See transaction chaining here
// https://docs.axepta.bnpparibas/pages/viewpage.action?pageId=41585166#Recurringcardpayments(Subscription)-Principles
if (null === AxceptaSchemeQuery::create()->findOneBySchemeReferenceId($schemeId)) {
(new AxceptaScheme())
->setOrderId($order->getId())
Expand Down
3 changes: 1 addition & 2 deletions Util/Axepta.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
class Axepta extends Blowfish
{
public const PAYSSL = 'https://paymentpage.axepta.bnpparibas/payssl.aspx';
//public const DIRECT = 'https://paymentpage.axepta.bnpparibas/direct.aspx';
public const DIRECT = 'https://www.computop-paygate.com/direct.aspx';
public const DIRECT = 'https://paymentpage.axepta.bnpparibas/direct.aspx';

public const DIRECT3D = 'https://paymentpage.axepta.bnpparibas/direct3d.aspx';
public const CAPTURE = 'https://paymentpage.axepta.bnpparibas/capture.aspx';
Expand Down

0 comments on commit 06405d5

Please sign in to comment.