-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
13980a8
commit a5a77bf
Showing
18 changed files
with
747 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.idea/ | ||
vendor/ | ||
|
||
# VM & Ansible | ||
.vagrant/ | ||
ansible/roles/.downloads | ||
ansible/roles/manala.* | ||
|
||
# Binaries | ||
bin/* | ||
!bin/.gitkeep | ||
|
||
# PHP-CS-Fixer | ||
.php_cs.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
$finder = PhpCsFixer\Finder::create() | ||
->in([__DIR__.'/src']) | ||
->name('*.php'); | ||
|
||
return PhpCsFixer\Config::create() | ||
->setRiskyAllowed(true) | ||
->setRules([ | ||
'@Symfony' => true, | ||
'array_syntax' => [ | ||
'syntax' => 'short', | ||
], | ||
'binary_operator_spaces' => [ | ||
'align_double_arrow' => true, | ||
'align_equals' => true | ||
], | ||
'no_unreachable_default_argument_value' => false, | ||
'braces' => [ | ||
'allow_single_line_closure' => true, | ||
], | ||
'heredoc_to_nowdoc' => false, | ||
'phpdoc_summary' => false, | ||
'declare_strict_types' => true, | ||
]) | ||
->setFinder($finder); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
dist: trusty | ||
language: php | ||
|
||
notifications: | ||
email: false | ||
|
||
cache: | ||
directories: | ||
- ~/.composer/cache/files | ||
- vendor | ||
|
||
jobs: | ||
include: | ||
- php: 7.2 | ||
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" | ||
- php: 7.3 | ||
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" | ||
- php: 7.3 | ||
|
||
before_install: | ||
- phpenv config-rm xdebug.ini | ||
|
||
install: | ||
- composer update ${COMPOSER_FLAGS} --prefer-dist --no-interaction | ||
|
||
script: | ||
- make run-composer-validate | ||
- make run-phpstan | ||
- make run-phpunit | ||
- make run-php-cs-fixer@travis |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 Yproximité | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
.SILENT: | ||
.PHONY: build test | ||
|
||
## Colors | ||
COLOR_RESET = \033[0m | ||
COLOR_INFO = \033[32m | ||
COLOR_COMMENT = \033[33m | ||
|
||
## Help | ||
help: | ||
printf "${COLOR_COMMENT}Usage:${COLOR_RESET}\n" | ||
printf " make [target]\n\n" | ||
printf "${COLOR_COMMENT}Available targets:${COLOR_RESET}\n" | ||
awk '/^[a-zA-Z\-\_0-9\.@]+:/ { \ | ||
helpMessage = match(lastLine, /^## (.*)/); \ | ||
if (helpMessage) { \ | ||
helpCommand = substr($$1, 0, index($$1, ":")); \ | ||
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \ | ||
printf " ${COLOR_INFO}%-16s${COLOR_RESET} %s\n", helpCommand, helpMessage; \ | ||
} \ | ||
} \ | ||
{ lastLine = $$0 }' $(MAKEFILE_LIST) | ||
|
||
############### | ||
# Environment # | ||
############### | ||
|
||
## Setup environment | ||
setup: | ||
vagrant up --no-provision | ||
vagrant provision | ||
vagrant ssh -- "cd /srv/app && make install-app" | ||
|
||
## Update environment | ||
update: export ANSIBLE_TAGS = manala.update | ||
update: | ||
vagrant provision | ||
|
||
## Update ansible | ||
update-ansible: export ANSIBLE_TAGS = manala.update | ||
update-ansible: | ||
vagrant provision --provision-with ansible | ||
|
||
## Provision environment | ||
provision: export ANSIBLE_EXTRA_VARS = {"manala":{"update":false}} | ||
provision: | ||
vagrant provision --provision-with app | ||
|
||
## Provision nginx | ||
provision-nginx: export ANSIBLE_TAGS = manala_nginx | ||
provision-nginx: provision | ||
|
||
## Provision php | ||
provision-php: export ANSIBLE_TAGS = manala_php | ||
provision-php: provision | ||
|
||
############ | ||
# Commands # | ||
############ | ||
|
||
install-app: install-git-hooks | ||
composer install | ||
|
||
install-git-hooks: | ||
wget --output-document=.git/hooks/pre-commit https://gist.githubusercontent.com/tristanbes/6f968b45d40fbf9da144bf86f8846d32/raw/0dfc2c44a10678dbeaad29e538b8a6d2d00fa496/pre-commit | ||
chmod +x .git/hooks/pre-commit | ||
|
||
############ | ||
# Commands # | ||
############ | ||
|
||
run-phpstan: | ||
php bin/phpstan analyse src --level max --autoload-file=vendor/autoload.php | ||
|
||
run-phpunit: | ||
php bin/phpunit | ||
|
||
run-php-cs-fixer: | ||
php bin/php-cs-fixer fix | ||
|
||
run-php-cs-fixer@travis: | ||
php bin/php-cs-fixer fix -v --diff --dry-run | ||
|
||
run-composer-validate: | ||
composer validate --strict |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,171 @@ | ||
# payum-axepta-bnp | ||
# Payum Axepta by BNP | ||
|
||
> A Payum gateway to use [Axepta](https://docs.axepta.bnpparibas/display/DOCBNP/Documentation+Axepta+BNP+Paribas+-++Home) (a French payment system) | ||
[![Latest Stable Version](https://poser.pugx.org/yproximite/payum-axepta-bnp/version)](https://packagist.org/packages/yproximite/payum-axepta-bnp) | ||
[![Build Status](https://travis-ci.com/Yproximite/payum-axepta-bnp.svg?token=pNBs2oaRpfxdyhqWf28h&branch=master)](https://travis-ci.com/Yproximite/payum-axepta-bnp) | ||
|
||
## Requirements | ||
|
||
- PHP 7.2+ | ||
- [Payum](https://github.com/Payum/Payum) | ||
- Optionally [PayumBundle](https://github.com/Payum/PayumBundle) and Symfony 3 or 4+ | ||
|
||
## Installation | ||
|
||
```bash | ||
$ composer require yproximite/payum-axepta-bnp | ||
``` | ||
|
||
## Configuration | ||
|
||
### With PayumBundle (Symfony) | ||
|
||
First register the gateway factory in your services definition: | ||
```yaml | ||
# config/services.yaml or app/config/services.yml | ||
services: | ||
yproximite.axepta_gateway_factory: | ||
class: Payum\Core\Bridge\Symfony\Builder\GatewayFactoryBuilder | ||
arguments: [Yproximite\Payum\Axepta\AxeptaGatewayFactory] | ||
tags: | ||
- { name: payum.gateway_factory_builder, factory: axepta } | ||
``` | ||
|
||
Then configure the gateway: | ||
|
||
```yaml | ||
# config/packages/payum.yaml or app/config/config.yml | ||
|
||
payum: | ||
gateways: | ||
axepta: | ||
factory: axepta | ||
``` | ||
|
||
### With Payum | ||
|
||
```php | ||
<?php | ||
//config.php | ||
|
||
use Payum\Core\PayumBuilder; | ||
use Payum\Core\Payum; | ||
|
||
/** @var Payum $payum */ | ||
$payum = (new PayumBuilder()) | ||
->addDefaultStorages() | ||
|
||
->addGateway('gatewayName', [ | ||
'factory' => 'axepta', | ||
]) | ||
|
||
->getPayum() | ||
; | ||
``` | ||
|
||
## Usage | ||
|
||
Make sure your `Payment` entity overrides `getNumber()` method like this: | ||
```php | ||
<?php | ||
|
||
namespace App\Entity\Payment; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
use Payum\Core\Model\Payment as BasePayment; | ||
|
||
/** | ||
* @ORM\Table | ||
* @ORM\Entity | ||
*/ | ||
class Payment extends BasePayment | ||
{ | ||
/** | ||
* @ORM\Column(name="id", type="integer") | ||
* @ORM\Id | ||
* @ORM\GeneratedValue(strategy="IDENTITY") | ||
* | ||
* @var int | ||
*/ | ||
protected $id; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getNumber() | ||
{ | ||
return (string) $this->id; | ||
} | ||
} | ||
``` | ||
|
||
By doing this, the library will be able to pick the payment's id and use it for the payment with System Pay (we should send a transaction id between `000000` and `999999`). | ||
|
||
### Payment in several installments | ||
|
||
If you planned to support payments in several instalments, somewhere in your code you will need to call `Payment#setPartialAmount` to keep a trace of the amount per payment: | ||
|
||
```php | ||
<?php | ||
class Payment extends BasePayment | ||
{ | ||
// ... | ||
|
||
/** | ||
* @ORM\Column(type="integer", nullable=true) | ||
*/ | ||
protected $partialAmount; | ||
|
||
public function getPartialAmount(): ?int | ||
{ | ||
return $this->partialAmount; | ||
} | ||
|
||
public function setPartialAmount(?int $partialAmount): void | ||
{ | ||
$this->partialAmount = $partialAmount; | ||
} | ||
} | ||
``` | ||
|
||
#### Usage | ||
|
||
```php | ||
<?php | ||
|
||
use App\Entity\Payment; | ||
use Yproximite\Payum\Axepta\Api; | ||
use Yproximite\Payum\Axepta\PaymentConfigGenerator; | ||
|
||
// Define the periods | ||
$periods = [ | ||
['amount' => 1000, 'date' => new \DateTime()], | ||
['amount' => 2000, 'date' => (new \DateTime())->add(new \DateInterval('P1M'))], | ||
['amount' => 3000, 'date' => (new \DateTime())->add(new \DateInterval('P2M'))], | ||
]; | ||
|
||
// Compute total amount | ||
$totalAmount = array_sum(array_column($periods, 'amount')); | ||
|
||
// Compute `paymentConfig` fields that will be sent to the API | ||
// It will generates something like this: MULTI_EXT:20190102=1000;20190202=2000;20190302=3000 | ||
$paymentConfig = (new PaymentConfigGenerator())->generate($periods); | ||
|
||
// Then create payments | ||
$storage = $payum->getStorage(Payment::class); | ||
$payments = []; | ||
|
||
foreach ($periods as $period) { | ||
$payment = $storage->create(); | ||
$payment->setTotalAmount($totalAmount); | ||
$payment->setPartialAmount($period['amount']); | ||
|
||
$details = $payment->getDetails(); | ||
$details[Api::FIELD_VADS_PAYMENT_CONFIG] = $generatedPaymentConfig; | ||
$payment->setDetails($details); | ||
|
||
$storage->update($payment); | ||
$payments[] = $payment; | ||
} | ||
``` |
Oops, something went wrong.