PHP code example of nikolag / core

1. Go to this page and download the library: Download nikolag/core 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/ */

    

nikolag / core example snippets


return [
    /*
    |--------------------------------------------------------------------------
    | Nikolag Configuration
    |--------------------------------------------------------------------------
    |
    | This represents the default connection name that will be used when
    | u have multiple available connections. For all available connections
    | take a look a the code documentation of 'connections' just below.
    |
    */
    'default' => '{$default}',

    /*
    |--------------------------------------------------------------------------
    | Nikolag Connections
    |--------------------------------------------------------------------------
    |
    | Here you will find all available connections you have in your project.
    | For all available connections you can take a look at the link below.
    |
    | https://github.com/NikolaGavric94/nikolag-core/blob/master/DRIVERS.md
    |
    */
    'connections' => [
      /*
      |--------------------------------------------------------------------------
      | {$default} Configuration
      |--------------------------------------------------------------------------
      |
      | The {$default} configuration determines the default application_id
      | and {$default} token when doing any of the calls to {$default}. These values will
      | be used when there is no merchant provided as a seller. You have to change
      | these values.
      |
      */
      '{$default}' => [
        'namespace' => '{$namespace}',
        'application_id' => env('{$default}_APPLICATION_ID'),
        'access_token' => env('{$default}_TOKEN'),
        'sandbox' => env('{$default}_SANDBOX', false),

        /*
        |--------------------------------------------------------------------------
        | {$default} Merchant Configuration
        |--------------------------------------------------------------------------
        |
        | The {$default} merchant configuration determines the default namespace for
        | merchant model and it's identifier which will be used in various
        | relationships when retrieving models. You are encouraged to change these
        | values to better reflect your application.
        |
        */
        'user' => [
          'namespace' => env('{$default}_USER_NAMESPACE', '\App\User'),
          'identifier' => env('{$default}_USER_IDENTIFIER', 'id')
        ],

        /*
        |--------------------------------------------------------------------------
        | {$default} Order Configuration
        |--------------------------------------------------------------------------
        |
        | The {$default} order configuration determines the default namespace for
        | order model and it's identifier which CAN be used when charging a customer.
        | You can relate that model to a certain transaction. You are encouraged to
        | change these values to better reflect your application.
        |
        */
        'order' => [
          'namespace' => env('{$default}_ORDER_NAMESPACE', '\App\Order'),
          'identifier' => env('{$default}_ORDER_IDENTIFIER', 'id'),
          'service_identifier' => env('SQUARE_PAYMENT_IDENTIFIER', 'payment_service_id')
        ]
      ],
    ]
];

//Facades
$this->app->alias(SquareService::class, 'square');

/**
 * The model's attributes.
 *
 * @var array
 */
protected $attributes = [
  //where `{$serviceName}` is the name of service you are trying to integrate with nikolag packages and Laravel
  //example: 'paypal', 'payoneer', 'payeer'
  'payment_service_type' => {$serviceName}
];

src/
tests/
  integration/
  unit/

/**
 * Returns instance of the specified service
 *
 * @param string $driver
 * @return Nikolag\Core\Contracts\PaymentServiceContract
 */
public function use(string $driver) {}

/**
 * Returns instance of the default service
 *
 * @return Nikolag\Core\Contracts\PaymentServiceContract
 */
public function default() {}

/**
 * Returns all available drivers
 * which u have installed.
 *
 * @return array
 */
public function availableDrivers() {}

$squareAPI = Nikolag\Core\Facades\CoreService::use('square');
$squareAPI->setCustomer($customer)->charge($options);

//or

$myServiceAPI = Nikolag\Core\Facades\CoreService::use('my-service');
$myServiceAPI->setCustomer($customer)->charge($options);

$api = Nikolag\Core\Facades\CoreService::default();

$api->setCustomer($customer)->charge($options);

$drivers = Nikolag\Core\Facades\CoreService::availableDrivers();

echo json_decode(json_encode($drivers));
//or Laravel specific helper method
dd($drivers);

//or plain php
var_dump($drivers);
die();