2017 © Pedro Peláez
 

library cpa-integration

CPA Networks postback integration

image

wearesho-team/cpa-integration

CPA Networks postback integration

  • Sunday, September 10, 2017
  • by Horat1us
  • Repository
  • 1 Watchers
  • 0 Stars
  • 66 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 2 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

CPA Integration

codecov Build Status License Latest Stable Version, (*1)

PHP7 is required, (*2)

This package created for commercial products of Wearesho Team, (*3)

This class includes postback integration to following services: 1. SalesDoubler #Supported 3. PrimeLead #Supported 2. admitad #Future 4. Loangate #Future, (*4)

Other services may be integrated in future. Pull requests is welcome., (*5)

Installation

composer require wearesho-team/cpa-integration

Usage

Sending conversion to CPA network

You should put this code on some action in your system, (*6)

<?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, (*7)

<?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, (*8)

The Versions

10/09 2017

dev-master

9999999-dev

CPA Networks postback integration

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Letnikow

extension admitad cpa salesdoubler horat1us wearesho loangate primelead

10/09 2017

1.1.3

1.1.3.0

CPA Networks postback integration

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Letnikow

extension admitad cpa salesdoubler horat1us wearesho loangate primelead

10/09 2017

dev-feature/admitad

dev-feature/admitad

CPA Networks postback integration

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Letnikow

extension admitad cpa salesdoubler horat1us wearesho loangate primelead

10/09 2017

1.1.2

1.1.2.0

CPA Networks postback integration

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Letnikow

extension admitad cpa salesdoubler horat1us wearesho loangate primelead

09/09 2017

1.1.1

1.1.1.0

CPA Networks postback integration

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Letnikow

extension admitad cpa salesdoubler horat1us wearesho loangate primelead

09/09 2017

1.1.0

1.1.0.0

CPA Networks postback integration

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Letnikow

extension admitad cpa salesdoubler horat1us wearesho loangate primelead

09/09 2017

1.0.0

1.0.0.0

CPA Networks postback integration

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Letnikow