PHP code example of artjoker / cpa

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

    

artjoker / cpa example snippets


 namespace App\Http;

use Illuminate\Foundation\Http\Kernel as HttpKernel;

class Kernel extends HttpKernel {
    /**
    * The application's route middleware.
    *
    * @var array
    */
    protected $routeMiddleware = [
        /**** OTHER MIDDLEWARE ****/
        'lead.check' => \Artjoker\Cpa\Middleware\LeadCheckMiddleware::class
    ];
}

Route::group(
    [
        'middleware' => [ 'lead.check' ]
    ], 
    function(){ //...
});

CpaLead::createFromCookie(auth()->user());
// or
CpaLead::createFromCookie($userId);

CpaConversion::register($user, $transactionId, 'sale');

use App\Models\CpaNetwork;

CpaNetwork::create([
    'name' => 'Super CPA',
    'slug' => 'supercpa',
    'base_url' => 'https://api.supercpa.com',
    'config' => [
        'method' => 'get',
        'default_params' => [
            'api_key' => 'your-key',
            'click_id' => '{click_id}',
        ],
        'events' => [
            'register' => [
                'path' => 'register',
                'params' => [
                    'action' => 'register',
                    'status' => 'pending',
                ],
            ],
            'lead' => [
                'path' => 'lead',
                'params' => [
                    'action' => 'lead',
                    'status' => 'approved',
                ],
            ],
            'first_loan' => [
                'path' => 'loan',
                'params' => [
                    'action' => 'first_loan',
                    'conversion_id' => '{conversion_id}',
                    'amount' => '{amount}',
                ],
            ],
        ],
    ],
    'is_active' => true,
]);

// config/cpa.php
'logging' => [
    'enabled'        => env('CPA_LOGGING_ENABLED', true),
    'level'          => env('CPA_LOGGING_LEVEL', 'info'), // debug, info, warning, error
    'log_requests'   => env('CPA_LOG_REQUESTS', true),    // логувати відправлені запити
    'log_responses'  => env('CPA_LOG_RESPONSES', true),   // логувати відповіді
],

php artisan vendor:publish --provider="Artjoker\Cpa\CpaServiceProvider"
bash
php artisan migrate