PHP code example of sureyee / laravel-rock-fintech

1. Go to this page and download the library: Download sureyee/laravel-rock-fintech 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/ */

    

sureyee / laravel-rock-fintech example snippets


       // 注册账户
       $mobile = '18666666666';
       $response = Rock::createAccountP($mobile)->send();
       // 同步回调
       if ($response->isSuccess()) {
           // do...sth...
       }  else {
           // notify wrong things
       }
        

        namespace App\Transformers;
        
        use Sureyee\LaravelRockFinTech\Contracts\TransformerInterface;
        use Sureyee\RockFinTech\RockConfig;
        
        class RepayTransformer implements TransformerInterface
        {
        
            public function __construct()
            {

            }
        
            public function format($incomeRecord): array
            {
                return [
                    'out_card_no' => $incomeRecord->out_card_no,
                    'amount' => $incomeRecord->amount,
                    'interest_amount' => $incomeRecord->interest_amount,
                    'in_card_no' => $incomeRecord->in_card_no,
                    'currency' => RockConfig::CNY,
                    'out_fee_mode' => 0,
                    'out_fee_amount' => 0,
                    'in_fee_mode' => 0,
                    'in_fee_amount' => 0,
                    'assets_no' => $incomeRecord->asset_no,
                    'auth_code' => $incomeRecord->auth_code,
                    'serial_no' => $incomeRecord->serial_no,
                    'third_reserved' => '',
                    'penalty_interest_amount' => 0,
                    'reserved' => $this->reserved($incomeRecord),
                ];
            }

            /**
             * 自定义参数
             * @param IncomeRecord $incomeRecord
             * @return string
             */
            protected function reserved(IncomeRecord $incomeRecord)
            {
                return json_encode([
                    'income_record' => $incomeRecord->id
                ]);
            }
        }  
       

        $itemsRequest = new ItemsRequest($collect, new RepayTransformer);
        
        $response = Rock::batchRepaymentB($itemsRequest)->send();
        

   // config
   'callback' => [
       'create_account_p' =>  \Sureyee\LaravelRockFinTech\Events\CreateAccountCallback::class,
   ],
    // EventServiceProvider.php
   protected $listen = [
       BatchRepaymentCallback::class => [
           TestListener::class
       ]
   ];

    // listener
   namespace App\Listeners;
   
   use Illuminate\Queue\InteractsWithQueue;
   use Illuminate\Contracts\Queue\ShouldQueue;
   use Sureyee\LaravelRockFinTech\Exceptions\EventFailedException;
   
   class TestListener
   {
       /**
        * Create the event listener.
        *
        * @return void
        */
       public function __construct()
       {
           //
       }
   
       /**
        * Handle the event.
        *
        * @param  object  $event
        * @return void
        */
       public function handle($event)
       {
           // 执行业务逻辑
        
           // 失败抛出 EventFailed 错误即可
           throw new EventFailedException('failed');
       }
   }