Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienheyd committed Mar 5, 2019
0 parents commit 78472ff
Showing 13 changed files with 611 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.idea
vendor
composer.lock
.phpunit.result.cache
25 changes: 25 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.PHONY:help
.DEFAULT_GOAL=help

COMPOSER=./composer.phar

help:
@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'

$(COMPOSER):
curl -sS https://getcomposer.org/installer | php -- --filename=composer.phar
chmod +x composer.phar

vendor: $(COMPOSER) composer.json
$(COMPOSER) update

check: vendor ## Check for coding standards
php vendor/bin/phpcs

test: vendor phpunit.xml ## Unit testing
php vendor/bin/phpunit --stop-on-error

clean: ## Remove files needed for tests
rm -rf ./vendor
rm -f ./composer.phar
rm -f ./composer.lock
154 changes: 154 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
# Systempay form generator for Laravel

![Package](https://img.shields.io/badge/Package-sebastienheyd%2Flaravel-systempay.svg)
![Laravel](https://img.shields.io/badge/For-Laravel%20%E2%89%A5%205.7-lightgrey.svg)
![MIT License](https://img.shields.io/github/license/restoore/laravel-systempay.svg)

## Features

* Fast and easy form generation for Systempay (by Banque Populaire)
* Support multiple site id for multiple stores within the same project
* Support sha1 and hmac-sha-256
* Blade extension for more flexibility

## Installation

1. Install the package

```
composer require sebastienheyd/laravel-systempay
```

2. Publish the config file

```
php artisan vendor:publish --provider="Sebastienheyd\Systempay\SystempayServiceProvider"
```

## Configuration

After publishing edit the default configuration file : [`config/systempay.php`](src/config/systempay.php)

```php
return [
'default' => [
'site_id' => 'YOUR_SITE_ID',
'key' => env('SYSTEMPAY_SITE_KEY', 'YOUR_KEY'),
'env' => env('SYSTEMPAY_ENV', 'PRODUCTION'),
'algo' => 'sha256',
]
];
```

You need to set `YOUR_SITE_ID` and `YOUR_KEY` with your own values. This two values are given by Systempay.

These values are set by default :

| name | default value | note |
|---|---|---|
| currency | 978 | [List of currency codes](https://www.iban.com/currency-codes) |
| payment_config | SINGLE | SINGLE or MULTIPLE |
| trans_date | [current datetime] | Generated automaticaly |
| page_action | PAYMENT | |
| action_mode | INTERACTIVE | |
| version | V2 | |
| signature | [generated] | Generated automaticaly |

Also see [Systempay documentation](https://paiement.systempay.fr/doc/fr-FR/form-payment/quick-start-guide/envoyer-un-formulaire-de-paiement-en-post.html)

**NB** : you don't have to add the `vads_` prefix to parameters, the prefix will be automaticaly added.
But you can also set the parameters with the `vads_` prefix, it will be automaticaly removed.

### Specific parameters

There is also possible to set some specific parameters to a configuration by setting `params` values.

Example :

```php
return [
'default' => [
// ...
'params' => [ // Specific parameters for "default" configuration
'currency' => '826' // GBP
]
]
];
```

In this case, default configuration will use the currency code 826.

### Additional configuration

You can add as many configuration as you need by adding a new key to the configuration file.

For example :

```php
return [
'default' => [
// ...
],
'store_uk' => [
'site_id' => '123456',
'key' => env('SYSTEMPAY_UK_SITE_KEY', '12345678'),
'env' => env('SYSTEMPAY_UK_ENV', 'PRODUCTION'),
'algo' => 'sha256'
]
];
```

To use another configuration, call the `config` method, for example :

```php
$systemPay = Systempay::config('store_uk')->set([
'amount' => 12.34,
'trans_id' => 123456
]);
```

## Usage

In your controller :

```php
<?php namespace App\Http\Controllers;

use Systempay; // Facade

class PaymentController extends Controller
{
public function payment()
{
$systemPay = Systempay::set([
'amount' => 12.34,
'trans_id' => 123456
]);

return view('payment', compact('systemPay'));
}
}
```

In your view

```blade
{!! $systemPay->render('<button type="submit" class="btn">Payment</button') !!}
```

Or with the Blade extension :

```blade
@systempay
<button class="btn btn-lg btn-success">Payment</button>
@endsystempay
```

**NB** : With the Blade extension, if your variable name passed to the view is not `$systemPay` you need to
set it like this :

```blade
@systempay('paymentData')
```

In this example it will use `$paymentData` instead of `$systemPay`
43 changes: 43 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "sebastienheyd/laravel-systempay",
"description": "Systempay form generator",
"type": "library",
"require": {
"php": ">=7.1.3",
"laravel/framework": "^5.7"
},
"require-dev": {
"phpunit/phpunit": "^8.0",
"squizlabs/php_codesniffer": "^3.0",
"orchestra/testbench": "^3.8"
},
"license": "MIT",
"authors": [
{
"name": "Sébastien HEYD",
"email": "contact@sheyd.fr"
}
],
"autoload": {
"psr-4": {
"Sebastienheyd\\Systempay\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Sebastienheyd\\Systempay\\Tests\\": "tests/"
}
},
"extra": {
"laravel": {
"providers": [
"Sebastienheyd\\Systempay\\SystempayServiceProvider"
],
"aliases": {
"Systempay": "Sebastienheyd\\Systempay\\Facade"
}
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
Binary file added composer.phar
Binary file not shown.
8 changes: 8 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?>
<ruleset name="laravel-systempay">
<description/>
<arg name="colors"/>
<arg value="p"/>
<file>src</file>
<rule ref="PSR2"/>
</ruleset>
22 changes: 22 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="MyPackage Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
</phpunit>
19 changes: 19 additions & 0 deletions src/Facade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php namespace Sebastienheyd\Systempay;

/**
* @method static \Sebastienheyd\Systempay\Systempay config(string $config = 'default')
* @method static \Sebastienheyd\Systempay\Systempay set($param, $value = null)
* @method static string render(string $button = '')
*
* @see \Sebastienheyd\Systempay\Systempay
*/
class Facade extends \Illuminate\Support\Facades\Facade
{
/**
* {@inheritDoc}
*/
protected static function getFacadeAccessor()
{
return Systempay::class;
}
}
Loading

0 comments on commit 78472ff

Please sign in to comment.