PHP code example of emanuelecoppola / satispay-php-sdk
1. Go to this page and download the library: Download emanuelecoppola/satispay-php-sdk library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
emanuelecoppola / satispay-php-sdk example snippets
$yourPublicKey = getenv('SATISPAY_PUBLIC_KEY');
$yourPrivateKey = getenv('SATISPAY_PRIVATE_KEY');
$yourKeyId = getenv('SATISPAY_KEY_ID');
$satispayGBusinessClient = new SatispayGBusinessClient([
// authentication
// set these three keys only if you are already authenticated
// if you're not, then follow the authentication example
'public_key' => $yourPublicKey,
'private_key' => $yourPrivateKey,
'key_id' => $yourKeyId,
'sandbox' => true
]);
$payment = $satispayGBusinessClient->payments->create([
'flow' => 'MATCH_CODE',
'currency' => 'EUR',
'amount_unit' => 12.99 * 100, // 12,99€
]);
echo $payment->toJson();
use Psr\Http\Client\ClientInterface;
$yourPublicKey = getenv('SATISPAY_PUBLIC_KEY');
$yourPrivateKey = getenv('SATISPAY_PRIVATE_KEY');
$yourKeyId = getenv('SATISPAY_KEY_ID');
$satispayGBusinessClient = new SatispayGBusinessClient([
// authentication
// set these three keys only if you are already authenticated
// if you're not, then follow the authentication example
'public_key' => $yourPublicKey,
'private_key' => $yourPrivateKey,
'key_id' => $yourKeyId,
'psr' => [
ClientInterface::class => new \GuzzleHttp\Client([])
],
'sandbox' => true
]);
$payment = $satispayGBusinessClient->payments->create([
'flow' => 'MATCH_CODE',
'currency' => 'EUR',
'amount_unit' => 12.99 * 100, // 12,99€
]);
echo $payment->toJson();
use EmanueleCoppola\Satispay\SatispayGAgentClient;
use EmanueleCoppola\Satispay\SatispayGBusinessClient;
use Psr\Http\Client\ClientInterface;
use EmanueleCoppola\Satispay\Services\RSAService\OpenSSL_RSAService;
use EmanueleCoppola\Satispay\Services\RSAService\SeclibRSAService;
use EmanueleCoppola\Satispay\SatispayHeaders;
$yourPublicKey = getenv('SATISPAY_PUBLIC_KEY');
$yourPrivateKey = getenv('SATISPAY_PRIVATE_KEY');
$yourKeyId = getenv('SATISPAY_KEY_ID');
// you could either instantiate a SatispayGBusinessClient instance
// or a SatispayGAgentClient instance based on your needs
// the constructor is the same in both classes
$satispayGBusinessClient = new SatispayGBusinessClient([
// authentication
// set these three keys only if you are already authenticated
// if you're not, then follow the authentication example
'public_key' => $yourPublicKey,
'private_key' => $yourPrivateKey,
'key_id' => $yourKeyId,
// here you can specify the passphrase set in the RSA keys
'passphrase' => null,
// here you can tell which environment to use
// true for sandbox
// false for production
'sandbox' => false,
// RSA encryption strategy
// here you can pass an array of RSAServiceContract implementations
// by default are like this:
'rsa_service' => [
OpenSSL_RSAService::class,
SeclibRSAService::class
],
// custom PSR interfaces
// here you can specify all the custom PSR interfaces that you want to user
// by default each instance will be resolved from the dependencies
'psr' => [
ClientInterface::class => new \GuzzleHttp\Client([])
],
// headers
// here you can specify more details about your integration
// to better help Satispay technician to investigate in your issues
'headers' => [
// the two OS_ headers have a default value set by reading your PHP installation
SatispayHeaders::OS => 'your os',
SatispayHeaders::OS_VERSION => 'your os version',
// the following headers are highly suggested
SatispayHeaders::APP_SOFTWARE_HOUSE => 'your software house name',
SatispayHeaders::APP_VERSION => 'your app version',
SatispayHeaders::APP_NAME => 'your app name',
SatispayHeaders::DEVICE_TYPE => 'your device type (e.g. POS)',
]
]);
use EmanueleCoppola\Satispay\SatispayGAgentClient;
use EmanueleCoppola\Satispay\SatispayGBusinessClient;
// for the authentication
// you could either instantiate a SatispayGBusinessClient instance
// or a SatispayGAgentClient instance based on your needs
$satispayGBusinessClient = new SatispayGBusinessClient([
// this is optional, if you use the password in the first authentication
// you must use it in every instance that you will create with the same credentials
// 'passphrase' => 'my-passphrase',
'sandbox' => true
]);
$satispayGBusinessClient->authentication->authenticate('QHPYXD');
$publicKey = $satispayGBusinessClient->authentication->publicKey;
$privateKey = $satispayGBusinessClient->authentication->privateKey;
$keyId = $satispayGBusinessClient->authentication->keyId;
if ($satispayGBusinessClient->authentication->ready()) {
// store the $publicKey, $privateKey and the $keyId
}
// once done, just reuse them in every client instance to correctly authenticate to the Satispay APIs
// you can find an example below
$newSatispayGBusinessClient = new SatispayGBusinessClient([
'public_key' => $publicKey,
'private_key' => $privateKey,
'key_id' => $keyId,
// this is optional, if you use the password in the first authentication
// you must use it in every instance that you will create with the same credentials
// 'passphrase' => 'my-passphrase',
'sandbox' => true
]);
use EmanueleCoppola\Satispay\SatispayGBusinessClient;
use EmanueleCoppola\Satispay\SatispayHeaders;
$satispayGBusinessClient = new SatispayGBusinessClient([...]);
// Create payment
$satispayPayment = $satispayGBusinessClient->payments->create(
[
'flow' => 'MATCH_CODE',
'currency' => 'EUR',
'amount_unit' => 12.99 * 100, // 12,99€
],
[
// list of headers to be sent
SatispayHeaders::IDEMPOTENCY_KEY => rand(10, 1000)
]
);
// Get payment
$satispayPayment = $satispayGBusinessClient->payments->get('7b5g32m5-3166-4c01-4617-edrb41558ce7');
// Get payment list
$satispayPayments = $satispayGBusinessClient->payments->all([
'status' => 'ACCEPTED'
]);
// Update payment
$satispayPayment = $satispayGBusinessClient->payments->update(
'7b5g32m5-3166-4c01-4617-edrb41558ce7',
[
'action' => 'ACCEPT',
]
);
use EmanueleCoppola\Satispay\SatispayGBusinessClient;
$satispayGBusinessClient = new SatispayGBusinessClient([...]);
// Get daily closure
$satispayConsumer = $satispayGBusinessClient->dailyClosures->get('20230119', ['generate_pdf' => true]);
use EmanueleCoppola\Satispay\SatispayGBusinessClient;
$satispayGBusinessClient = new SatispayGBusinessClient([...]);
// Get consumer
$satispayConsumer = $satispayGBusinessClient->consumers->get('+393337777888');
use EmanueleCoppola\Satispay\SatispayGBusinessClient;
$satispayGBusinessClient = new SatispayGBusinessClient([...]);
// Get profile
$satispayProfile = $satispayGBusinessClient->profile->me();
use EmanueleCoppola\Satispay\SatispayGBusinessClient;
$satispayGBusinessClient = new SatispayGBusinessClient([...]);
$satispayGBusinessClient->mqtt->authenticate();
if ($satispayGBusinessClient->mqtt->ready()) {
$clientCertificate = $satispayGBusinessClient->mqtt->clientCertificate;
$clientCertificateKey = $satispayGBusinessClient->mqtt->clientCertificateKey;
$shopUid = $satispayGBusinessClient->mqtt->shopUid;
}
// once done, you can use them in an MQTT client to the Satispay APIs
use EmanueleCoppola\Satispay\SatispayGAgentClient;
$satispayGAgentClient = new SatispayGAgentClient([...]);
// Get PagoPA receipt
$satispayPayment = $satispayGAgentClient->receipts->get('1f4b5397-f60a-4a98-81f0-6f3aef88bb80');
use EmanueleCoppola\Satispay\SatispayGAgentClient;
$satispayGAgentClient = new SatispayGAgentClient([...]);
// Get PagoPA invoice
$pagoPaInvoice = $satispayGAgentClient->invoices->get('2c79cb93-e48b-42a5-9a53-e7faf32d1f9d');
// Get PagoPA invoices
$pagoPaInvoices = $satispayGAgentClient->invoices->all();
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.