Skip to content

Commit

Permalink
Merge pull request #1 from Yproximite/feat/base
Browse files Browse the repository at this point in the history
  • Loading branch information
RomulusED69 committed May 11, 2021
2 parents a5a77bf + bd45061 commit ab26b91
Show file tree
Hide file tree
Showing 14 changed files with 6,469 additions and 82 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ jobs:
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest"
- php: 7.3
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest"
- php: 7.3
- php: 7.4
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest"
- php: 7.4

before_install:
- phpenv config-rm xdebug.ini
Expand Down
90 changes: 15 additions & 75 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ $ composer require yproximite/payum-axepta-bnp
### 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 }
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:
Expand All @@ -41,6 +42,9 @@ payum:
gateways:
axepta:
factory: axepta
merchant_id: 'change it' # required
hmac: 'change it' # required
crypt_key: 'change it' # required
```

### With Payum
Expand All @@ -57,7 +61,10 @@ $payum = (new PayumBuilder())
->addDefaultStorages()

->addGateway('gatewayName', [
'factory' => 'axepta',
'factory' => 'axepta',
'merchant_id' => 'change it', // required
'hmac' => 'change it', // required
'crypt_key' => 'change it', // required
])

->getPayum()
Expand All @@ -67,6 +74,7 @@ $payum = (new PayumBuilder())
## Usage

Make sure your `Payment` entity overrides `getNumber()` method like this:

```php
<?php

Expand Down Expand Up @@ -100,72 +108,4 @@ class Payment extends BasePayment
}
```

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;
}
```
By doing this, the library will be able to pick the payment's id and use it for the payment with Axepta.
2 changes: 1 addition & 1 deletion Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
app = {
:name => 'payum-axepta',
:box => 'manala/app-dev-debian',
:box_version => '~> 4.0.3',
:box_version => '~> 4.0.7',
:box_memory => 1024
}

Expand Down
8 changes: 4 additions & 4 deletions ansible/ansible.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
- hosts: app
vars:
manala_ansible_galaxy_roles:
- manala.ansible-galaxy
- manala.ansible_galaxy
- manala.skeleton
roles:
- manala.ansible-galaxy
- manala.ansible_galaxy

# Global
- hosts: all
vars:
manala_ansible_galaxy_roles_path: "{{ playbook_dir }}/roles"
manala_ansible_galaxy_roles:
- manala.ansible-galaxy
- manala.ansible_galaxy
roles:
- manala.ansible-galaxy
- manala.ansible_galaxy
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
"description": "Axepta gateway for Payum",
"keywords": ["payum", "payment", "axepta"],
"license": "MIT",
"require": {
"payum/core": "^1.5"
},
"require-dev": {
"payum/core": "^1.5.1",
"php-http/guzzle6-adapter": "^1.0",
"phpstan/phpstan": "^0.11.1",
"phpstan/phpstan-strict-rules": "^0.11.0",
Expand Down
Loading

0 comments on commit ab26b91

Please sign in to comment.