exinone / laravel-mixin-sdk
MixinNetwork SDK for Laravel
Installs: 1 867
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 7
Forks: 4
Open Issues: 0
Requires
- php: ^7.0 || ^8.0
- ext-json: *
- ext-openssl: *
- ext-zlib: *
- exinone/mixin-sdk-php: *
- illuminate/support: ^5.1 || ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0
Requires (Dev)
- phpunit/phpunit: ^7.0 || ^8.0
- symfony/var-dumper: ^4.2
This package is not auto-updated.
Last update: 2025-01-01 12:02:23 UTC
README
MixinNetwork SDK for Laravel 5
Requirement
Laravel
>= 5.1Composer
PHP
>= 7.0
Installation
$ composer require exinone/laravel-mixin-sdk -vvv
Configuration
-
Add the provider and facade in
config/app.php
, Laravel 5.5+ supports package discovery automatically, you should skip this step.'providers' => [ ... ExinOne\MixinSDK\MixinSDKServiceProvider::class, ], 'aliases' => [ ... 'MixinSDK' => ExinOne\MixinSDK\Facades\MixinSDK::class, ]
-
Publish configuration
$ php artisan vendor:publish --provider="ExinOne\MixinSDK\MixinSDKServiceProvider"
-
You can configure it with any of methods below.
-
Edit
config/mixin-sdk.php
and.env
:// account information 'keys' => [ // default use is config 'default' => [ 'mixin_id' => env('MIXIN_SDK_MIXIN_ID'), 'client_id' => env('MIXIN_SDK_CLIENT_ID'), 'client_secret' => env('MIXIN_SDK_CLIENT_SECRET'), 'pin' => env('MIXIN_SDK_PIN'), 'pin_token' => env('MIXIN_SDK_PIN_TOKEN'), 'session_id' => env('MIXIN_SDK_SESSION_ID'), 'private_key' => str_replace("\\n", "\n", env('MIXIN_SDK_PRIVATE_KEY')), //import your private_key 'safe_key' => env('MIXIN_SDK_SAFE_KEY'), ], 'myConfig-A'=>[ ... ] ],
these configurations will be automatically loaded.
// then you can MixinSDK::user()->readProfile(); // or MixinSDK::use('myConfig-A')->user()->readProfile();
If you don't want your private key stored in the VCS,refer to link
-
else you can call it as follows:
// use setConfig method to save config MixinSDK::setConfig('myConfig-A',$config0); MixinSDK::setConfig('myConfig-B',$config1); // then you can MixinSDK::use('myConfig-A')->user()->readProfile(); //------- // Or more simple way, using the 'use' method , chained with other methods MixinSDK::use('myConfig-A',$config)->user()->readProfile(); // then you can MixinSDK::use('myConfig-A')->user()->readProfile();
-
You can also use your own way packing them up in your project to make it easy to switch configs.
-
Use
Run
Exceptions
If MixinNetwork response with an error,An Exception ExinOne\MixinSDK\Exceptions\MixinNetworkRequestException
will be thrown. Developers need to capture and handle this exception.
<?php try { // If the transfer fails here, an error will be thrown. MixinSDK::wallet()->transfer($asset_id, $opponent_id, $pin, $amount, $memo); } catch (MixinNetworkRequestException $e) { // Here errCode and errMessage are the same as MixinNetwork, refer to the following link. $errCode = $e->getCode(); $errMessage = $e->getMessage(); ... } catch (\Throwable $e) { ... }
Other Exceptions
WARNING
-
You can config
iterator
in the following way. Theiterator
is used when a PIN is encrypted. Generally,iterator
should not be modified. If you want ot modify this variable, be sure to know what you are doing. More details on iterator<?php $iterator = [time()]; // if use it by MixinSDK::pin()->updatePin($oldPin,$pin), // $iterator need have two element (count($iterator) == 2) MixinSDK::wallet()->setIterator($iterator)->transfer($asset_id, $opponent_id, $pin, $amount, $memo); // By default, microtime(true) * 100000 is used as iterator
-
Get raw Recponse content
<?php $mixinSdk->wallet()->setRaw(true)->transfer($asset_id, $opponent_id, $pin, $amount, $memo); // Return MixinNetwork raw Response content
Alternatives
LICENSE
MIT