PHP code example of techsolutions / euronet-simo-sdk
1. Go to this page and download the library: Download techsolutions/euronet-simo-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/ */
use Techsolutions\EuronetSimoSdk\Facades\SIMO;
// Gerar (entidade recai na configurada por omissão: 10203)
$ref = SIMO::generate('123456789');
$ref->reference(); // "12345678985" (RRRRRRRRRXX)
$ref->full(); // "1020312345678985" (EEEEE + referência)
// Validar
SIMO::validate('12345678985'); // true
SIMO::validate('12345678945', '12345'); // true, com entidade explícita
SIMO::validate('12345678945'); // false: dígitos de controlo de outra entidade
// Decompor
$parsed = SIMO::parse('12345678985');
$parsed?->baseReference; // "123456789"
$parsed?->checkDigits; // "85"
use Techsolutions\EuronetSimoSdk\Contracts\ValidatesPayments;
use Techsolutions\EuronetSimoSdk\DataTransferObjects\ValidatePaymentRequest;
use Techsolutions\EuronetSimoSdk\DataTransferObjects\ValidatePaymentResponse;
use Techsolutions\EuronetSimoSdk\Enums\PaymentStatus;
final class PaymentValidator implements ValidatesPayments
{
public function validate(ValidatePaymentRequest $request): ValidatePaymentResponse
{
$factura = Factura::where('referencia', $request->refNum)->first();
if ($factura === null) {
return ValidatePaymentResponse::decline(PaymentStatus::Invalid, 'Referência não encontrada.');
}
if ($factura->expirada()) {
return ValidatePaymentResponse::decline(PaymentStatus::Expired, 'Factura expirada.');
}
return ValidatePaymentResponse::allow();
}
}
use Techsolutions\EuronetSimoSdk\Contracts\HandlesPaymentNotifications;
use Techsolutions\EuronetSimoSdk\DataTransferObjects\NotifyPaymentRequest;
use Techsolutions\EuronetSimoSdk\DataTransferObjects\NotifyPaymentResponse;
use Techsolutions\EuronetSimoSdk\Enums\PaymentStatus;
final class PaymentNotificationHandler implements HandlesPaymentNotifications
{
public function handle(NotifyPaymentRequest $request): NotifyPaymentResponse
{
$factura = Factura::where('referencia', $request->refNum)->first();
if ($factura?->paga) {
return NotifyPaymentResponse::reject(PaymentStatus::Duplicated, 'Pagamento já confirmado.');
}
// Creditar a conta / registar o movimento.
return NotifyPaymentResponse::acknowledge();
}
}
bash
composer vendor:publish --tag="simo-config"
php artisan vendor:publish --tag="simo-migrations" # opcional, só para auditoria
php artisan migrate # opcional
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.