Skip to content

Commit

Permalink
upgrade libreria satispay
Browse files Browse the repository at this point in the history
  • Loading branch information
madbob committed Nov 13, 2023
1 parent f9eb90a commit 66f92c6
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 31 deletions.
27 changes: 22 additions & 5 deletions code/app/Http/Controllers/GasController.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,35 @@ private function configBanking($gas, $request)

$gas->setConfig('rid', $rid_info);

$satispay_info = null;

if ($request->has('enable_satispay')) {
$satispay_info = (object) [
'secret' => $request->input('satispay->secret')
];
$auth_code = $request->input('satispay_auth_code');
if ($auth_code) {
try {
$authentication = \SatispayGBusiness\Api::authenticateWithToken($auth_code);
$satispay_info = (object) [
'public' => $authentication->publicKey,
'secret' => $authentication->privateKey,
'key' => $authentication->keyId,
];
}
catch(\Exception $e) {
\Log::error('Impossibile completare procedura di verifica su Satispay: ' . $e->getMessage());
}
}
}
else {
$satispay_info = (object) [
'secret' => ''
'public' => '',
'secret' => '',
'key' => '',
];
}

$gas->setConfig('satispay', $satispay_info);
if ($satispay_info) {
$gas->setConfig('satispay', $satispay_info);
}

if ($request->has('enable_integralces')) {
$integralces_info = (object) [
Expand Down
49 changes: 27 additions & 22 deletions code/app/Http/Controllers/PaymentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Session;
use Cache;
use Auth;
use Log;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;

use App\Movement;

Expand All @@ -16,12 +15,16 @@ class PaymentController extends Controller
private function initSatispayContext()
{
$user = Auth::user();
if ($user == null)
if ($user == null) {
$gas = currentAbsoluteGas();
else
}
else {
$gas = $user->gas;
}

\SatispayOnline\Api::setSecurityBearer($gas->satispay['secret']);
\SatispayGBusiness\Api::setPublicKey($gas->satispay['public']);
\SatispayGBusiness\Api::setPrivateKey($gas->satispay['secret']);
\SatispayGBusiness\Api::setKeyId($gas->satispay['key']);

return $user;
}
Expand All @@ -31,7 +34,7 @@ public function doPayment(Request $request)
$type = $request->input('type');

if ($type == 'satispay') {
$user = self::initSatispayContext();
$user = $this->initSatispayContext();

$charge = null;

Expand All @@ -41,19 +44,21 @@ public function doPayment(Request $request)
$phone = $request->input('mobile');
$phone = str_replace('+', '00', $phone);
$phone = preg_replace('/^[^0-9]$/', '', $phone);
if (substr($phone, 0, 4) != '0039')

if (substr($phone, 0, 4) != '0039') {
$phone = '0039' . $phone;
}

$phone = preg_replace('/^0039/', '+39', $phone);

try {
$satispay_user = \SatispayOnline\User::create([
'phone_number' => $phone
]);
$satispay_user = \SatispayGBusiness\Consumer::get($phone);

$charge = \SatispayOnline\Charge::create([
'user_id' => $satispay_user->id,
$charge = \SatispayGBusiness\Payment::create([
'flow' => 'MATCH_USER',
'consumer_uid' => $satispay_user->id,
'currency' => 'EUR',
'amount' => $amount * 100,
'amount_unit' => $amount * 100,
'description' => $notes,
'callback_url' => urldecode(route('payment.status_satispay', ['charge_id' => '{uuid}']))
]);
Expand All @@ -71,7 +76,7 @@ public function doPayment(Request $request)
*/
if ($charge != null) {
$movement = new Movement();
$movement->identifier = $charge->uuid;
$movement->identifier = $charge->id;
$movement->type = 'user-credit';
$movement->target_type = get_class($user);
$movement->target_id = $user->id;
Expand All @@ -81,7 +86,7 @@ public function doPayment(Request $request)
$movement->notes = $notes;
$movement->method = 'satispay';

Cache::put('satispay_movement_' . $charge->uuid, $movement, 16 * 60);
Cache::put('satispay_movement_' . $charge->id, $movement, 16 * 60);
}
}

Expand All @@ -90,12 +95,12 @@ public function doPayment(Request $request)

public function statusPaymentSatispay(Request $request)
{
self::initSatispayContext();
$this->initSatispayContext();

$charge_id = $request->input('charge_id');
$charge = \SatispayOnline\Charge::get($charge_id);
$charge_id = $request->input('payment_id');
$charge = \SatispayGBusiness\Payment::get($charge_id);

if ($charge->status == 'SUCCESS') {
if ($charge->status == 'ACCEPTED') {
$movement = Cache::pull('satispay_movement_' . $charge_id);
if ($movement != null) {
$movement->save();
Expand Down
4 changes: 3 additions & 1 deletion code/app/Parameters/Config/Satispay.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ public function type()
public function default()
{
return (object) [
'secret' => ''
'public' => '',
'secret' => '',
'key' => '',
];
}
}
2 changes: 1 addition & 1 deletion code/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"madbob/larastrap": "dev-master",
"madbob/laravel-log2rss": "0.5.0",
"madbob/laravel-queue-loopback": "0.5.0",
"satispay/online-api-php-sdk": "^1.6",
"satispay/gbusiness-api-php-sdk": "^1.3",
"spatie/db-dumper": "^3.0",
"symfony/http-client": "^6.2",
"symfony/psr-http-message-bridge": "^2.1",
Expand Down
8 changes: 6 additions & 2 deletions code/resources/views/gas/accounting.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@
<x-larastrap::text name="rid->org" :label="_i('Codice Univoco Azienda')" :value="$gas->rid['org'] ?? ''" />
</x-larastrap::collapse>

<x-larastrap::check name="enable_satispay" :label="_i('Abilita Satispay')" triggers_collapse="enable_satispay" :value="$gas->hasFeature('satispay')" :pophelp="_i('Abilitando questa opzione e popolando i relativi campi verranno attivati i pagamenti con Satispay, con cui gli utenti potranno autonomamente ricaricare il proprio credito direttamente da GASdotto. Per ottenere le credenziali visita https://business.satispay.com/')" />
<x-larastrap::check name="enable_satispay" :label="_i('Abilita Satispay')" triggers_collapse="enable_satispay" :value="$gas->hasFeature('satispay')" :pophelp="_i('Abilitando questa opzione verranno attivati i pagamenti con Satispay, con cui gli utenti potranno autonomamente ricaricare il proprio credito direttamente da GASdotto. Per ottenere il codice di attivazione è necessario un account business: visita il sito https://business.satispay.com/')" />
<x-larastrap::collapse id="enable_satispay">
<x-larastrap::text name="satispay->secret" :label="_i('Security Bearer')" :value="$gas->satispay['secret']" />
@if($gas->hasFeature('satispay'))
{{ _i("L'integrazione Satispay risulta attualmente configurata. Disabilita Satispay e salva queste impostazioni per ricominciare la procedura di configurazione.") }}
@else
<x-larastrap::text name="satispay_auth_code" :label="_i('Codice di Attivazione')" :pophelp="_i('Puoi ottenere un codice di attivazione dalla tua dashboard Satispay')" value="" />
@endif
</x-larastrap::collapse>

<x-larastrap::check name="enable_integralces" :label="_i('Abilita IntegralCES')" triggers_collapse="enable_integralces" :value="$gas->hasFeature('integralces')" :pophelp="_i('Abilitando questa opzione sarà possibile gestire la contabilità (saldi, pagamenti, movimenti...) con una moneta complementare, ed accedere ad alcune funzioni di integrazione con IntegralCES')" />
Expand Down

0 comments on commit 66f92c6

Please sign in to comment.