Skip to content

Commit

Permalink
Merge pull request #27 from sequra/chore/add-set-up-script
Browse files Browse the repository at this point in the history
Add script to launch Magento instance with the sequra plugin.
  • Loading branch information
m1k3lm authored Sep 24, 2024
2 parents 1384f1b + 7e7e309 commit 97d3433
Show file tree
Hide file tree
Showing 21 changed files with 426 additions and 626 deletions.
49 changes: 49 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
MAGENTO_VERSION=2

SQ_M2_CORE_VERSION=*
# Use "local" to run code in local directory
#SQ_M2_CORE_VERSION=local
SQ_MERCHANT_REF=dummy
SQ_USER_NAME=dummy
SQ_USER_SECRET=ZqbjrN6bhPYVIyram3wcuQgHUmP1C4
SQ_ASSETS_KEY=ADc3ZdOLh4
SQ_ENDPOINT=https://sandbox.sequrapi.com/orders

MAGENTO_HTTP_PORT=8018
MAGENTO_EXTERNAL_HTTP_PORT_NUMBER=${MAGENTO_HTTP_PORT}
MAGENTO_HTTPS_PORT=8019
MAGENTO_EXTERNAL_HTTPS_PORT_NUMBER=${MAGENTO_HTTPS_PORT}
MAGENTO_MYSQL_PORT=8020

# More options available at https://hub.docker.com/r/bitnami/magento
MAGENTO_HOST=localhost
MAGENTO_DATABASE_HOST=mariadb
MAGENTO_DATABASE_PORT_NUMBER=3306
MAGENTO_DATABASE_USER=bn_magento
MAGENTO_DATABASE_NAME=bitnami_magento
ELASTICSEARCH_HOST=elasticsearch
ELASTICSEARCH_PORT_NUMBER=9200
MAGENTO_EMAIL=magento@sequra.com
MAGENTO_FIRST_NAME=admin_first_name
MAGENTO_LAST_NAME=admin_last_name
MAGENTO_USERNAME=admin
MAGENTO_PASSWORD=password123
MAGENTO_FRONTNAME=admin
MAGENTO_COUNTRY=ES

MAGENTO_LOCALE=es_ES
MAGENTO_CURRENCY=EUR
MAGENTO_TIMEZONE=Europe/Berlin
MAGENTO_SAMPLEDATA=yes
MAGENTO_EXTRA_INSTALL_ARGS="--currency=${MAGENTO_CURRENCY} --timezone=${MAGENTO_TIMEZONE} --language=${MAGENTO_LOCALE} --cleanup-database"
MAGENTO_ENABLE_HTTP_CACHE=no

# ALLOW_EMPTY_PASSWORD is recommended only for development.
ALLOW_EMPTY_PASSWORD=yes
#MAGENTO_DATABASE_PASSWORD=supersecret
COMPOSER_AUTH='{"http-basic":{"repo.magento.com":{"username":"<public-key>","password":"<private-key>"}}}'
# Outside /bitnami/magento/
COMPOSER_CACHE_DIR=/opt/.composer/cache
# Enable xdebug
PHP_XDEBUG_ENABLED=no
BITNAMI_DEBUG=false
8 changes: 7 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@
.env* export-ignore
.gitignore export-ignore
.gitattributes export-ignore
docker-compose.yml export-ignore
docker-compose.override.sample.yml export-ignore

# Exclude specific directories
.github export-ignore
docs export-ignore
docker export-ignore
bin export-ignore
bin export-ignore
docker-entrypoint-init.d export-ignore

# Exclude scripts
*.sh export-ignore
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
.idea
vendor
docker-compose.override.yml
.composer_cache
.env
default.vcl
id_rsa
43 changes: 41 additions & 2 deletions Console/Configure.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
use SeQura\Core\BusinessLogic\Domain\CountryConfiguration\Services\SellingCountriesService;
use SeQura\Core\BusinessLogic\Domain\GeneralSettings\Models\GeneralSettings;
use SeQura\Core\BusinessLogic\Domain\GeneralSettings\Services\GeneralSettingsService;
use SeQura\Core\BusinessLogic\Domain\Multistore\StoreContext;
use SeQura\Core\BusinessLogic\Domain\PromotionalWidgets\Models\WidgetSettings;
use SeQura\Core\BusinessLogic\Domain\PromotionalWidgets\Services\WidgetSettingsService;
use SeQura\Core\BusinessLogic\SeQuraAPI\BaseProxy;
use SeQura\Core\Infrastructure\Logger\Logger;
use SeQura\Core\Infrastructure\ServiceRegister;
use Sequra\Core\Services\Bootstrap;

Expand Down Expand Up @@ -55,6 +57,10 @@ class Configure extends Command
* Values of input arguments or options
*/
const INPUT_KEY_PASSWORD = 'password';
/**
* Values of input arguments or options
*/
const INPUT_KEY_STOREID = 'store_id';

/**
* @var ConnectionService
Expand Down Expand Up @@ -124,6 +130,12 @@ protected function configure()
null,
InputOption::VALUE_OPTIONAL,
'Password'
)
->addOption(
self::INPUT_KEY_STOREID,
null,
InputOption::VALUE_OPTIONAL,
'Coma separated store ids'
);
parent::configure();
}
Expand All @@ -139,6 +151,34 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$storeIds = $this->getStoreIds($input);
foreach ($storeIds as $storeId) {
try {
echo "Saving configuration to store Id " . $storeId;
Logger::logError('Saving configuration to store Id ' . $storeId);
StoreContext::doWithStore(
$storeId,
function () use ($input) {
$this->safeConfigDataForStore($input);
}
);
} catch (Exception $e) {
Logger::logError('Configuration could not be saved for store Id ' .
$storeId . ' because ' . $e->getMessage());
}
}
return 0;
}

protected function getStoreIds($input){
$storeIds = explode(',', $input->getOption(self::INPUT_KEY_STOREID)??1);
if (count($storeIds) < 1) {
$storeIds = [1];
}
return $storeIds;
}

protected function safeConfigDataForStore($input){
$this->saveConnectionData(
$input->getOption(self::INPUT_KEY_ENDPOINT),
$input->getOption(self::INPUT_KEY_USERNAME),
Expand All @@ -157,10 +197,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
);
$this->getGeneralSettingsService()->saveGeneralSettings($generalSettings);
$this->saveWidgetSettings($input->getOption(self::INPUT_KEY_ASSETS_KEY));
return 0;
}

/**
/**
* @param string $endpoint
* @param string $username
* @param string $password
Expand Down
127 changes: 125 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,125 @@
# sequra-magento2-rework
SeQura magento2 payment gateway module.
# Magento module for SeQura payment gateway

1. [About seQura](#about-sequra)
2. [Installation guide](https://sequra.atlassian.net/wiki/spaces/DOC/pages/1377304583/MAGENTO+2)
3. [Sign-up](#sign-up)
4. [For developers](#for-developers)

## About seQura
### Description

seQura is the flexible payment platform that will help your business improve conversion and recurrence.
The easiest, safest, and quickest way for your customers to pay on installments.

+6.000 e-commerce and +1.5 million delight shoppers already use seQura. Are you still thinking about it?

This WooCommerce plugin allows you to make payments with [seQura](https://sequra.es).

### Benefits for merchants

> Flexible payment solutions adapted to your business.
Widest flexible payment solutions in the market:

* Buy now pay later
* Pay in 3, no interest
* Installments, up to 24 months
* Flexi, combines interest-free BNPL with long-term financing in a single purchase experience

Your customers in good hands:

* Cost transparency and clarity
* Local support teams to deliver the best shopper experience
* Secure data, we don’t share your data with anyone or use your information to sell our own or third-party products


Obsessed with conversion and recurrence

* We adapt to your business, solutions for every sector, and buyer profile
* The highest acceptance rate in Southern Europe thanks to our own risk algorithm, created and optimized for the local market
* Instant approval. A frictionless credit-purchase experience, buy-in seconds without document uploads
* seQura marketing collateral to support your campaigns

### Benefits for customers

* Widest range of flexible payment solutions available on the market, up to 4 different solutions to pay as you want.
* Access to credit with no paperwork, just complete 5 fields to be instantly approved
* Security and privacy, we do not sell your personal data to third parties nor share with other companies

## Installation guide

Check the [installation guide](https://sequra.atlassian.net/wiki/spaces/DOC/pages/1377304583/MAGENTO+2)

## Sign-up

Si tu comercio no está dado de alta en seQura, puedes hacerlo [aquí](https://sqra.es/signupmes) para recibir credenciales de sandbox y empezar.

If you are not a seQura merchant yet, you can sign up [here](https://sqra.es/signupmen) to get sandbox credentials and get started.

## For developers

### How to try the module
The repository includes a docker-compose file to easily test the module. You can start the environment with the following command:

```bash
./setup.sh
```

This will start a Magento 2 instance with the seQura module installed. You can access the admin panel at `http://localhost:8018/admin` with the credentials `admin`/`password123`.

Once installed you could start/stop the magento instance with `docker compose up` and `docker compose down` commands.

### Customizing the environment
You could create you own .env file to customize the environment. You can copy the .env.example file and modify the values as needed.

In order to use magento sample data you MUST set your credentials for https://repo.magento.com/ in you .env file at

```bash
COMPOSER_AUTH='{"http-basic":{"repo.magento.com":{"username":"<public-key>","password":"<private-key>"}}}'
```

Otherwise you will get a warning message:
> "warning": "You haven't provided your Magento authentication keys. For instructions, visit https://devdocs.magento.com/guides/v2.3/install-gde/prereq/connect-auth.html"
and the installation will fail.

#### Other examples
* You can customize the Magento version by setting the `MAGENTO_VERSION` environment variable.
* You can customize the sequra/magento module version by setting the `SQ_M2_CORE_VERSION` environment variable. Leave it as local to use the local version of the module.
* You can customize the host and ports by setting the `MAGENTO_HOST` and `MAGENTO_HTTP_PORT` environment variable.

### Loading sample data
You can load sample data with the following command:

```bash
./bin/install-sampledata
```

or setting the `MAGENTO_SAMPLEDATA` environment variable to `yes` when before running the ./setup.sh script.


> After installing sample data you may get 404 errors for http://${MAGENTO_HOST}/%7B%7BMEDIA_URL%7D%7Dstyles.css.
> To fix this issue go to Content -> Design -> Configuration -> Edit your theme -> HTML Head -> Scripts and Style Sheets and change the line with `{{MEDIA_URL}}styles.css` to `media/styles.css`
### Other helper scripts
You can run commands in the Magento container with the following command:

```bash
./bin/magento <command>
```
To run magento commands in the container.

```bash
./bin/composer <command>
```
To run composer commands in the container.

```bash
./bin/mysql
```
To open mysql terminal in the container.

```bash
./bin/shell
```
To open a bash shell commands in the container.
2 changes: 2 additions & 0 deletions bin/composer
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
docker compose exec -u daemon -w /bitnami/magento magento php vendor/bin/composer $@
7 changes: 7 additions & 0 deletions bin/install-sampledata
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
echo " Installing sample data..."
docker compose exec -w /bitnami/magento magento bash -c "rm -rf var/di/* var/generation/*"
docker compose exec -u daemon -w /bitnami/magento magento bin/magento sampledata:deploy
docker compose exec -u daemon -w /bitnami/magento magento bin/magento setup:upgrade
docker compose exec -u daemon -w /bitnami/magento magento bin/magento cache:clean
docker compose exec -u daemon -w /bitnami/magento magento bin/magento cache:flush
2 changes: 2 additions & 0 deletions bin/magento
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
docker compose exec -u daemon -w /bitnami/magento magento bin/magento $@
3 changes: 3 additions & 0 deletions bin/mysql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
docker compose exec -u daemon -w /bitnami/magento magento bash -c \
"mysql -h \$MAGENTO_DATABASE_HOST -P \$MAGENTO_DATABASE_PORT_NUMBER -u \$MAGENTO_DATABASE_USER \$MAGENTO_DATABASE_NAME"
4 changes: 4 additions & 0 deletions bin/n98-magerun2
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
docker compose exec -u daemon -w /bitnami/magento magento bash -c \
"[ ! -f 'vendor/bin/n98-magerun2' ] && vendor/bin/composer require n98/magerun2-dist"
docker compose exec -u daemon -w /bitnami/magento magento vendor/bin/n98-magerun2 $@
6 changes: 6 additions & 0 deletions bin/shell
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
if [ -z "$1" ]; then
docker compose exec -u daemon -w /bitnami/magento magento bash
else
docker compose exec -u daemon -w /bitnami/magento magento bash -c "$@"
fi
2 changes: 2 additions & 0 deletions bin/xdebug
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
docker compose exec magento /docker-entrypoint-init.d/xdebug.sh
Loading

0 comments on commit 97d3433

Please sign in to comment.