Pular para o conteúdo
← Voltar para projetos

Laravel Partnerstack

PartnerStack partner and affiliate program API integration for Laravel

Laravel PartnerStack

#Laravel PartnerStack

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads License

A Laravel client for the PartnerStack partner and affiliate program API. A fluent PartnerStack facade covers partnerships, customers, transactions, deals, actions, rewards, leads, groups and webhooks, authenticates every request with your public and secret keys as HTTP Basic credentials, and throws a PartnerStackException on a non-2xx response instead of returning a silent error array.

#Features

  • PartnershipslistPartnerships(), getPartnership(), createPartnership(), updatePartnership()
  • CustomerslistCustomers(), getCustomer(), createCustomer(), updateCustomer(), deleteCustomer()
  • TransactionslistTransactions(), getTransaction(), createTransaction(), deleteTransaction()
  • DealslistDeals(), getDeal(), createDeal(), updateDeal(), archiveDeal()
  • ActionslistActions(), createAction()
  • RewardslistRewards(), createReward()
  • LeadslistLeads(), getLead(), createLead(), updateLead()
  • GroupslistGroups()
  • WebhookslistWebhooks(), getWebhook(), createWebhook(), deleteWebhook()
  • Thin by design — every method returns the raw decoded JSON response as an array, no DTOs
  • Fails loud — a non-2xx API response throws PartnerStackException carrying the API's error message and HTTP status code

#Installation

You can install the package via composer:

composer require jeffersongoncalves/laravel-partnerstack

Optionally publish the config file:

php artisan vendor:publish --tag="partnerstack-config"

#Configuration

Add to your .env:

PARTNERSTACK_PUBLIC_KEY=your-public-key
PARTNERSTACK_SECRET_KEY=your-secret-key

Both keys live in your PartnerStack dashboard under Settings > Integrations > API keys.

#Config Options

// config/partnerstack.php
return [
    'public_key' => env('PARTNERSTACK_PUBLIC_KEY'),
    'secret_key' => env('PARTNERSTACK_SECRET_KEY'),
    'base_url' => env('PARTNERSTACK_BASE_URL', 'https://api.partnerstack.com/api/v2'),
];

#Usage

use JeffersonGoncalves\PartnerStack\Exceptions\PartnerStackException;
use JeffersonGoncalves\PartnerStack\Facades\PartnerStack;

Every list*() method accepts the API's cursor pagination options — limit, starting_after, ending_before and order_by:

PartnerStack::listPartnerships(['limit' => 50, 'order_by' => 'created_at']);

#Partnerships

PartnerStack::listPartnerships();
PartnerStack::getPartnership('partnership-key');

PartnerStack::createPartnership([
    'email' => 'jane@example.com',
    'group_key' => 'group-key',
    'first_name' => 'Jane',
    'last_name' => 'Doe',
]);

PartnerStack::updatePartnership('partnership-key', ['name' => 'Jane Doe']);

#Customers

PartnerStack::listCustomers();
PartnerStack::getCustomer('customer-key');

PartnerStack::createCustomer([
    'email' => 'john@example.com',
    'partner_key' => 'partner-key',
    'customer_key' => 'your-internal-id',
]);

PartnerStack::updateCustomer('customer-key', ['name' => 'John Doe']);
PartnerStack::deleteCustomer('customer-key');

#Transactions

Amounts are in cents.

PartnerStack::listTransactions();
PartnerStack::getTransaction('transaction-key');

PartnerStack::createTransaction([
    'customer_key' => 'customer-key',
    'amount' => 4990,
    'currency' => 'usd',
    'category' => 'subscription',
]);

PartnerStack::deleteTransaction('transaction-key');

#Deals

PartnerStack::listDeals();
PartnerStack::getDeal('deal-key');

PartnerStack::createDeal([
    'partner_key' => 'partner-key',
    'name' => 'Acme Corp',
    'amount' => 250000,
    'stage' => 'proposal',
]);

PartnerStack::updateDeal('deal-key', ['stage' => 'won', 'status' => 'closed']);
PartnerStack::archiveDeal('deal-key');

#Actions

PartnerStack::listActions();

PartnerStack::createAction([
    'customer_key' => 'customer-key',
    'key' => 'signup',
    'value' => 1,
]);

#Rewards

Amounts are in cents.

PartnerStack::listRewards();

PartnerStack::createReward([
    'partner_key' => 'partner-key',
    'amount' => 10000,
    'description' => 'Q1 bonus',
    'currency' => 'usd',
]);

#Leads

PartnerStack::listLeads();
PartnerStack::getLead('lead-key');

PartnerStack::createLead([
    'partner_key' => 'partner-key',
    'email' => 'lead@example.com',
    'company' => 'Acme Corp',
]);

PartnerStack::updateLead('lead-key', ['status' => 'qualified']);

#Groups

PartnerStack::listGroups();

#Webhooks

PartnerStack::listWebhooks();
PartnerStack::getWebhook('webhook-key');

PartnerStack::createWebhook([
    'target' => 'https://example.com/hooks/partnerstack',
    'events' => ['customer.created', 'transaction.created'],
]);

PartnerStack::deleteWebhook('webhook-key');

#Handling errors

try {
    $partnership = PartnerStack::getPartnership('partnership-key');
} catch (PartnerStackException $e) {
    // $e->getMessage()  — the API's error message, or the raw response body
    // $e->statusCode    — the HTTP status code returned by PartnerStack
}

#Testing

composer test

#Static Analysis

composer analyse

#Code Formatting

composer format

#Changelog

Please see CHANGELOG for more information on what has changed recently.

#Contributing

Please see CONTRIBUTING for details.

#Security

Please review our security policy on how to report security vulnerabilities.

#Credits

#License

The MIT License (MIT). Please see License File for more information.

Nova versão disponível.