wearesho-team/cpa-integration

This package is abandoned and no longer maintained. No replacement package was suggested.

CPA Networks postback integration

1.1.3 2017-09-10 14:44 UTC

This package is auto-updated.

Last update: 2020-07-03 07:54:51 UTC


README

codecov Build Status License Latest Stable Version

PHP7 is required

This package created for commercial products of Wearesho Team

This class includes postback integration to following services:

  1. SalesDoubler #Supported
  2. PrimeLead #Supported
  3. admitad #Future
  4. Loangate #Future

Other services may be integrated in future. Pull requests is welcome.

Installation

composer require wearesho-team/cpa-integration

Usage

Sending conversion to CPA network

You should put this code on some action in your system

<?php
use Wearesho\Cpa\Postback\PostbackService;
use Wearesho\Cpa\Repository\ConversionMemoryRepository;
use Wearesho\Cpa\Postback\PostbackServiceConfig;
use Wearesho\Cpa\Lead\LeadFactory;
use Wearesho\Cpa\Exceptions\DuplicatedConversionException;
use Wearesho\Cpa\Exceptions\UnsupportedConversionTypeException;

$servicesConfig = yaml_parse('your_config_file.yml'); // Or another config loader (array must be provided), see Configuration section
$repository = new ConversionMemoryRepository(); // Or use your implementation of interface
$client = new \GuzzleHttp\Client(); // Or another implementation of \GuzzleHttp\ClientInterface
$config = new PostbackServiceConfig($servicesConfig);
$service = new PostbackService(
    $repository,
    $client,
    $config
);

$leadFactory = new LeadFactory(); 
$lead = $leadFactory->fromUrl($_REQUEST['REQUEST_URI']); // Or parse it on each request and load from database on user action
$lead = $leadFactory->fromCookie($_COOKIE['CPA_PROVIDER']); // Or you can store lead between request and load it from cookie

$userOrActionId = 1;
$conversion = $lead->createConversion($userOrActionId);

try {
    $response = $service->send($conversion);   
}
catch(DuplicatedConversionException $duplicationException) {
    // If your code may generate few conversion with same id
}
catch(UnsupportedConversionTypeException $invalidConversion) {
    // If you did not configure conversion for current lead CPA network
}
catch(\GuzzleHttp\Exception\RequestException $connectionException) {
    // If CPA network url is unavailable or your config is not accepted
}

Storing lead between request in cookies

<?php
use Wearesho\Cpa\Lead\LeadFactory;

$cookieKey = "CPA_PROVIDER";

$factory = new LeadFactory();
$lead = $factory->fromUrl($_REQUEST['REQUEST_URI']); // Or use your handling request implementation
$cookie = $factory->toCookie($lead);
setcookie($cookieKey, $cookie); // Or use your library to handle cookies

Configuration

Your documentation should look like

<?php
function get_config() {
    // This function may load values from file (in your implementation)
    return [
        'SomeCpaNetwork' => false, // Put false (or just not add config) if you want to switch off postback to network
        
        'SalesDoubler' => [
            'baseUrl' => 'http://rdr.salesdoubler.com.ua/', // optional
            'token' => 'YourToken',
            'id' => 'YourId',        
        ],
        
        'PrimeLead' => [
            'baseUrl' => 'https://primeadv.go2cloud.org/', // optional
            'id' => 'YourId',
        ],
    ];
}

Contributors

  1. Alexander Letnikow

License

MIT