1. Go to this page and download the library: Download smlv/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/ */
smlv / sdk example snippets
use Smlv\Sdk\SmlvClient;
$smlv = new SmlvClient([
'api_url' => 'https://api.smlvcoin.com',
'api_key' => 'your-api-key',
'api_secret' => 'your-api-secret',
'widget_secret' => 'your-widget-secret',
]);
use Smlv\Sdk\SmlvWidgetGenerator;
$widget = new SmlvWidgetGenerator($smlv);
// $subscriber->id — the subscriber ID in your system.
// One user may have multiple subscribers — pass the subscriber ID, not the user ID!
//
// email — optional, used only to pre-fill the account creation form on first visit.
// Recommended order: 1) main contact email of the subscriber, 2) current user's email.
// If email is unknown — pass an empty string.
echo $widget->generateDepositWidget(
externalSubscriberId: (string) $subscriber->id,
email: $subscriber->contactEmail ?? $currentUser->email ?? '',
returnUrl: 'https://your-app.com/billing'
);
// CDN <script> tag only (place in <head> or before </body>)
echo $widget->buildScriptTag(); // async
echo $widget->buildScriptTag(defer: true); // defer
// Inline init only (place after the <div>)
echo $widget->generateInitSnippet(
externalSubscriberId: $subscriber->id,
email: $email, // optional — see email sourcing note above
type: 'balance',
options: ['theme' => 'dark'],
selector: '#my-balance-widget'
);
// Signed JWT token only (for manual JS queue push)
$token = $widget->generateToken($subscriber->id, $email, 'deposit');
use Smlv\Sdk\Yii2\SmlvChargeBehavior;
class Order extends ActiveRecord
{
public function behaviors(): array
{
return [
'smlvCharge' => [
'class' => SmlvChargeBehavior::class,
'email' => fn() => $this->user->email,
'amount' => fn() => $this->subtotal * 0.02, // e.g. 2% fee
'description' => fn() => 'Order #' . $this->id,
'metadata' => fn() => [
'order_id' => $this->id,
'plan' => $this->plan_name,
],
],
];
}
}
// common/traits/smlv/SmlvChargeableTrait.php (your SaaS code)
namespace common\traits\smlv;
use Smlv\Sdk\Yii2\SmlvChargeBehavior;
trait SmlvChargeableTrait
{
protected function smlvBehaviorConfig(): array
{
return [
'class' => SmlvChargeBehavior::class,
'email' => fn() => $this->getChargeEmail(),
'amount' => fn() => $this->getChargeAmount(),
'description' => fn() => $this->getChargeDescription(),
'metadata' => fn() => $this->getChargeMetadata(),
];
}
abstract protected function getSmlvActionType(): ?string;
public function getChargeAmount(): ?float
{
// Opt-in guard: skip SMLV charge when the subscriber has no SMLV account
// (returns null) — traditional bank billing will apply instead.
$accountRef = Yii::$app->smlv->billing->resolveAccountByEmail($this->getChargeEmail());
if ($accountRef === null) {
return null;
}
$eurPrice = SmlvPricelist::getPriceFor($this->getSmlvActionType());
$rate = $this->fetchSmlvRate();
return ($eurPrice && $rate > 0) ? round($eurPrice / $rate, 8) : null;
}
// ... getChargeEmail(), getChargeDescription(), getChargeMetadata(), fetchSmlvRate()
}
// common/models/bill/Bill.php
use common\traits\smlv\SmlvChargeableTrait;
class Bill extends BaseDoc
{
use SmlvChargeableTrait;
public function behaviors(): array
{
return ArrayHelper::merge(parent::behaviors(), [
'smlvCharge' => $this->smlvBehaviorConfig(),
]);
}
// The only method you must implement — everything else is handled by the trait
protected function getSmlvActionType(): ?string
{
return $this->doc_type === 'job_request'
? SmlvPricelist::TYPE_ORDER
: SmlvPricelist::TYPE_BILL;
}
}