Skip to content

partnero/partnero-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Partnero PHP SDK

MIT licensed

Table of Contents

Installation

Requirements

  • PHP 8.0
  • PSR-7 and PSR-18 based HTTP adapter
  • Partnero API key partnero.com

Setup

This library is built atop of PSR-7 and PSR-18.

composer require partnero/partnero-php

Usage

Partners for Affiliate program

Get a list of partners

use Partnero\Partnero;

$partnero = new Partnero('api_key');

$partnero->partners()->list(10);

Get partner

use Partnero\Partnero;

$partnero = new Partnero('api_key');

$partnero->partners()->find('partner-key');

Create partner

use Partnero\Partnero;
use Partnero\Models\Partner;

$partnero = new Partnero('api_key');

$partner = (new Partner())
  ->setEmail('test@mail.com')
  ->setName('Name')
  ->setKey('partner-key');

$partnero->partners()->create($partner);

Key is optional.
If key is not set, a random key will be generated for the partner.

Update partner

use Partnero\Partnero;
use Partnero\Models\Partner;

$partnero = new Partnero('api_key');

$partner = (new Partner())
  ->setEmail('john.doe@mail.com')
  ->setName('John')
  ->setKey('john-doe');

$partnero->partners()->update('partner-key', $partner);

Delete partner

use Partnero\Partnero;

$partnero = new Partnero('api_key');

$partnero->partners()->delete('john-doe');

Customers

Get a list of customers

use Partnero\Partnero;
use Partnero\Models\Partner;

$partnero = new Partnero('api_key');

$partner = (new Partner())
  ->setKey('partner-key');

$partnero->customers()->list(10, $partner);

Get customer

use Partnero\Partnero;

$partnero = new Partnero('api_key');

$partnero->customers()->find('customer-key');

Create customer

use Partnero\Partnero;
use Partnero\Models\Partner;
use Partnero\Models\Customer;

$partnero = new Partnero('api_key');

$partner = new Partner();
$partner->setKey('partner-key');

$customer = (new Customer())
  ->setKey('customer-key')
  ->setName('Name')
  ->setEmail('customer@mail.com');

$partnero->customers()->create($customer, $partner);

Update customer

use Partnero\Partnero;
use Partnero\Models\Customer;

$partnero = new Partnero('api_key');

$customer = (new Customer())
  ->setKey('new-customer-key')
  ->setName('John')
  ->setEmail('customer.john.doe@mail.com');

$partnero->customers()->update('customer-key', $customer);

Delete customer

use Partnero\Partnero;

$partnero = new Partnero('api_key');

$partnero->customers()->delete('new-customer-key');

Transactions

Create transaction

use Partnero\Partnero;
use Partnero\Models\Customer;
use Partnero\Models\Transaction;

$partnero = new Partnero('api_key');

$customer = (new Customer())
  ->setKey('customer-key');

$transaction = (new Transaction())
  ->setKey('transaction_123')
  ->setAmount(99.99)
  ->setAction('sale');

$partnero->transactions()->create($transaction, $customer);

Delete transaction

use Partnero\Partnero;

$partnero = new Partnero('api_key');

$partnero->transactions()->delete('transaction_123');

Webhooks

Get a list of webhooks

use Partnero\Partnero;

$partnero = new Partnero('api_key');

$partnero->webhooks()->list(50, 1);

Get webhook

use Partnero\Partnero;

$partnero = new Partnero('api_key');

$partnero->webhooks()->find('webhook-key');

Create webhook

use Partnero\Partnero;
use Partnero\Models\Webhook;

$partnero = new Partnero('api_key');

$webhook = (new Webhook())
  ->setName('Demo')
  ->setUrl('https://webhook.site/e68d154a-ad82')
  ->setEvents([
    'partner.created'
  ]);

$partnero->webhooks()->create($webhook);

Update webhook

use Partnero\Partnero;
use Partnero\Models\Webhook;

$partnero = new Partnero('api_key');

$webhook = (new Webhook())->setName('Demo 2');

$partnero->webhooks()->update('webhook-key', $webhook);

Delete webhook

use Partnero\Partnero;

$partnero = new Partnero('api_key');

$partnero->webhooks()->delete('webhook-key');

Referrals

Get a list of referrals

use Partnero\Partnero;

$partnero = new Partnero('api_key');

$partnero->referrals()->list(50, 1, 'referred')

Create referring customer

use Partnero\Partnero;
use Partnero\Models\Partner;

$partnero = new Partnero('api_key');

$customer = (new Partner())
  ->setId('partner-id')
  ->setName('John Doe')
  ->setEmail('john.doe@email.com');

$partnero->referrals()->createReferring($customer);

Create referred customer

use Partnero\Partnero;
use Partnero\Models\Partner;

$partnero = new Partnero('api_key');

$customer = (new Partner())
  ->setId('partner-id')
  ->setName('Jean Doe')
  ->setEmail('jean.doe@email.com');

$referringCustomer = (new Partner())
  ->setKey('partner-key');

$partnero->referrals()->createReferred($customer, $referringCustomer)

Get referral customer

use Partnero\Partnero;

$partnero = new Partnero('api_key');

$partnero->referrals()->find('partner-id');

Get referred customer list

use Partnero\Partnero;

$partnero = new Partnero('api_key');

$partnero->referrals()->listReferred('partner-id');

Get referral customer stats

use Partnero\Partnero;

$partnero = new Partnero('api_key');

$partnero->referrals()->stats('partner-id');

Search Referral Customer

use Partnero\Partnero;

$partnero = new Partnero('api_key');

$partnero->referrals()->search(['id' => 'partner-id']);

Update referral customer

use Partnero\Partnero;
use Partnero\Models\Partner;

$partnero = new Partnero('api_key');

$newCustomer = (new Partner())
  ->setName('Mark Doe');

$partnero->referrals()->update('partner-id', $newCustomer);

Delete referral customer

use Partnero\Partnero;

$partnero = new Partnero('api_key');

$partnero->referrals()->delete('partner-id');

Invite referral customer

use Partnero\Partnero;
use Partnero\Models\Partner;

$partnero = new Partnero('api_key');

$customer = (new Partner())
  ->setEmail('john.doe@email.com');

$partnero->referrals()->invite($customer, [
  'personalization_key_1' => 'personalization_value_1',
  'personalization_key_2' => 'personalization_value_2'
]);

Get referral customer balance

use Partnero\Partnero;

$partnero = new Partnero('api_key');

$partnero->referrals()->balance('partner-id');

Credit referral customer balance

use Partnero\Partnero;
use Partnero\Models\BalanceCredit;

$partnero = new Partnero('api_key');

$credit = (new BalanceCredit())
            ->setAmount(10)
            ->setAmountUnits('usd')
            ->setIsCurrency(true);

$partnero->referrals()->credit('partner-id', $credit);

Subscribers

Get a list of subscribers

use Partnero\Partnero;
use Partnero\Models\Subscriber;

$partnero = new Partnero('api_key');

$partnero->subscribers()->list();

Get subscriber

use Partnero\Partnero;

$partnero = new Partnero('api_key');

$partnero->subscribers()->find('subscriber-identifier-or-email');

Create subscriber

use Partnero\Partnero;
use Partnero\Models\Subscriber;

$partnero = new Partnero('api_key');

$subscriber = (new Subscriber())
    ->setName('Referral subscriber')
    ->setEmail('referral@subscriber.com')
    ->setApproved(true)
    ->setStatus('active')
    ->setTos(true)
    ->setMarketingConsent(true);;

$singleSubscriber = $partnero->subscribers()->create($subscriber);

// If you want to create a referred subscriber
$referredSubscriber = (new Subscriber())
    ->setName('Referred Subscriber')
    ->setEmail('referred@subscriber.com')
    ->setApproved(true)
    ->setStatus('active')
    ->setTos(true)
    ->setMarketingConsent(true);
  
$partnero->subscribers()->create($referredSubscriber, $singleSubscriber);

NOTE: To create a referred subscriber, pass the parent subscriber as the second argument. If you’re using a response like the one in the example above, make sure to extract the necessary data from the response (e.g., $singleSubscriber['body']['data']).

Alternatively, instead of passing the entire model as a second argument, you can pass the parent subscriber’s identifier or email as an array, for example: $partnero->subscribers()->create($referredSubscriber, ['email' => 'referral@subscriber.com']).

Update subscriber

use Partnero\Partnero;
use Partnero\Models\Subscriber;

$partnero = new Partnero('api_key');

$subscriber = (new Subscriber())
  ->setIdentifier('new-subscriber-esp-identifier')
  ->setName('John Surname')
  ->setEmail('subscriber.john.doe@mail.com')
  ->setApproved(true)
  ->setStatus('active')
  ->setTos(false)
  ->setMarketingConsent(false);

$partnero->subscribers()->update('subscriber-identifier-or-email', $subscriber);

Delete subscriber

use Partnero\Partnero;

$partnero = new Partnero('api_key');

$partnero->subscribers()->delete('subscriber-identifier-or-email');

Support and Feedback

In case you find any bugs, submit an issue directly here in GitHub.

If you have any troubles using our API or SDK feel free to contact our support by email hello@partnero.com

The official documentation is at https://developers.partnero.com