Skip to content

Commit

Permalink
first version
Browse files Browse the repository at this point in the history
  • Loading branch information
alessiodionisi committed Jan 22, 2019
0 parents commit 08c5336
Show file tree
Hide file tree
Showing 17 changed files with 747 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/vendor
/examples/authentication.json
composer.lock
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Satispay <business@satispay.com>

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.
57 changes: 57 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Satispay GBusiness API PHP SDK
[![Packagist Version](https://img.shields.io/packagist/v/satispay/gbusiness-api-php-sdk.svg?style=flat-square)](https://packagist.org/packages/satispay/gbusiness-api-php-sdk)
[![Packagist Downloads](https://img.shields.io/packagist/dt/satispay/gbusiness-api-php-sdk.svg?style=flat-square)](https://packagist.org/packages/satispay/gbusiness-api-php-sdk)

## Installation
Run the following command:

```bash
composer require satispay/gbusiness-api-php-sdk
```

If you do not wish to use Composer, import the `init.php` file.

```php
require_once("/path/init.php");
```

## Documentation
https://developers.satispay.com

## Authenticate with RSA Signature
Sign in to your [Dashboard](https://business.satispay.com) at [business.satispay.com](https://business.satispay.com), click "Negozi Online" or "Negozi Fisici", and then click on "Genera un token di attivazione" to generate an activation token.

Use the activation token with the `authenticateWithToken` function to generate and exchange a pair of RSA keys.

Save the keys in your database or in a **safe place** not accesibile from your website.
```php
// Authenticate and generate the keys
$authentication = \SatispayGBusiness\Api::authenticateWithToken("XXXXXX");

// Export keys
$publicKey = $authentication->publicKey;
$privateKey = $authentication->privateKey;
$keyId = $authentication->keyId;
```

Reuse the keys after authentication.
```php
// Keys variables
$publicKey = "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhk...";
$privateKey = "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBg...";
$keyId = "ldg9sbq283og7ua1abpj989kbbm2g60us6f18c1sciq...";

// Set keys
\SatispayGBusiness\Api::setPublicKey($publicKey);
\SatispayGBusiness\Api::setPrivateKey($privateKey);
\SatispayGBusiness\Api::setKeyId($keyId);

// Test the authentication
\SatispayGBusiness\Api::testAuthentication();
```

## Enable Sandbox
To enable sandbox use `setSandbox` function.
```php
\SatispayGBusiness\Api::setSandbox(true);
```
31 changes: 31 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "satispay/gbusiness-api-php-sdk",
"description": "Satispay GBusiness API PHP SDK",
"license": "MIT",
"keywords": [
"satispay",
"gbusiness",
"api",
"php",
"sdk"
],
"homepage": "https://www.satispay.com",
"version": "1.0.0",
"authors": [
{
"name": "Satispay",
"homepage": "https://www.satispay.com"
}
],
"require": {
"php": ">=5.4.0",
"ext-curl": "*",
"ext-json": "*",
"ext-mbstring": "*"
},
"autoload": {
"psr-4": {
"SatispayGBusiness\\": "lib/"
}
}
}
17 changes: 17 additions & 0 deletions examples/auth-with-token.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

require_once("../init.php");

\SatispayGBusiness\Api::setSandbox(true);

$authentication = \SatispayGBusiness\Api::authenticateWithToken("WG5MUC");

$publicKey = $authentication->publicKey;
$privateKey = $authentication->privateKey;
$keyId = $authentication->keyId;

file_put_contents("authentication.json", json_encode(array(
"public_key" => $publicKey,
"private_key" => $privateKey,
"key_id" => $keyId
), JSON_PRETTY_PRINT));
19 changes: 19 additions & 0 deletions examples/create-payment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

require_once("../init.php");

\SatispayGBusiness\Api::setSandbox(true);

$authData = json_decode(file_get_contents("authentication.json"));

\SatispayGBusiness\Api::setPublicKey($authData->public_key);
\SatispayGBusiness\Api::setPrivateKey($authData->private_key);
\SatispayGBusiness\Api::setKeyId($authData->key_id);

$payment = \SatispayGBusiness\Payment::create(array(
"flow" => "MATCH_CODE",
"amount_unit" => 199,
"currency" => "EUR"
));

var_dump($payment);
15 changes: 15 additions & 0 deletions examples/get-consumer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

require_once("../init.php");

\SatispayGBusiness\Api::setSandbox(true);

$authData = json_decode(file_get_contents("authentication.json"));

\SatispayGBusiness\Api::setPublicKey($authData->public_key);
\SatispayGBusiness\Api::setPrivateKey($authData->private_key);
\SatispayGBusiness\Api::setKeyId($authData->key_id);

$consumer = \SatispayGBusiness\Consumer::get("+390000000000");

var_dump($consumer);
15 changes: 15 additions & 0 deletions examples/get-payment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

require_once("../init.php");

\SatispayGBusiness\Api::setSandbox(true);

$authData = json_decode(file_get_contents("authentication.json"));

\SatispayGBusiness\Api::setPublicKey($authData->public_key);
\SatispayGBusiness\Api::setPrivateKey($authData->private_key);
\SatispayGBusiness\Api::setKeyId($authData->key_id);

$payment = \SatispayGBusiness\Payment::get("5f11eb3d-e442-441c-af7c-7c1d707e1f4e");

var_dump($payment);
15 changes: 15 additions & 0 deletions examples/get-payments.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

require_once("../init.php");

\SatispayGBusiness\Api::setSandbox(true);

$authData = json_decode(file_get_contents("authentication.json"));

\SatispayGBusiness\Api::setPublicKey($authData->public_key);
\SatispayGBusiness\Api::setPrivateKey($authData->private_key);
\SatispayGBusiness\Api::setKeyId($authData->key_id);

$payments = \SatispayGBusiness\Payment::all();

var_dump($payments);
13 changes: 13 additions & 0 deletions examples/test-auth-with-bearer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

require_once("../init.php");

\SatispayGBusiness\Api::setSandbox(true);

$authData = json_decode(file_get_contents("authentication.json"));

\SatispayGBusiness\Api::setSecurityBearer($authData->security_bearer);

$result = \SatispayGBusiness\Api::testAuthentication();

var_dump($result);
15 changes: 15 additions & 0 deletions examples/test-auth-with-rsa.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

require_once("../init.php");

\SatispayGBusiness\Api::setSandbox(true);

$authData = json_decode(file_get_contents("authentication.json"));

\SatispayGBusiness\Api::setPublicKey($authData->public_key);
\SatispayGBusiness\Api::setPrivateKey($authData->private_key);
\SatispayGBusiness\Api::setKeyId($authData->key_id);

$result = \SatispayGBusiness\Api::testAuthentication();

var_dump($result);
25 changes: 25 additions & 0 deletions examples/update-payment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

require_once("../init.php");

\SatispayGBusiness\Api::setSandbox(true);

$authData = json_decode(file_get_contents("authentication.json"));

\SatispayGBusiness\Api::setPublicKey($authData->public_key);
\SatispayGBusiness\Api::setPrivateKey($authData->private_key);
\SatispayGBusiness\Api::setKeyId($authData->key_id);

$payment = \SatispayGBusiness\Payment::create(array(
"flow" => "MATCH_CODE",
"amount_unit" => 199,
"currency" => "EUR"
));

var_dump($payment);

$upayment = \SatispayGBusiness\Payment::update($payment->id, array(
"action" => "CANCEL"
));

var_dump($upayment);
6 changes: 6 additions & 0 deletions init.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
require_once(dirname(__FILE__) . "/lib/Api.php");

require_once(dirname(__FILE__) . "/lib/Payment.php");
require_once(dirname(__FILE__) . "/lib/Request.php");
require_once(dirname(__FILE__) . "/lib/Consumer.php");
Loading

0 comments on commit 08c5336

Please sign in to comment.