exinone/laravel-mixin-sdk

MixinNetwork SDK for Laravel

1.2.8 2023-11-22 07:08 UTC

README

MixinNetwork SDK for Laravel 5

Requirement

  1. Laravel >= 5.1
  2. Composer
  3. PHP >= 7.0

Installation

$ composer require exinone/laravel-mixin-sdk -vvv

Configuration

  1. 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,
    ]
  2. Publish configuration

    $ php artisan vendor:publish --provider="ExinOne\MixinSDK\MixinSDKServiceProvider"
  3. You can configure it with any of methods below.

    1. 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

    2. 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();
    3. 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) {
    ...
}

MixinNetwork Error Codes

Other Exceptions

WARNING

  1. You can config iterator in the following way. The iterator 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
  2. Get raw Recponse content

    <?php
    $mixinSdk->wallet()->setRaw(true)->transfer($asset_id, $opponent_id, $pin, $amount, $memo);
    // Return MixinNetwork raw Response content

Alternatives

[exinone/mixin-sdk-php]

[zamseam/mixin]

LICENSE

MIT