PHPackages                             tinker/payments-php-sdk - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. tinker/payments-php-sdk

ActiveLibrary[API Development](/categories/api)

tinker/payments-php-sdk
=======================

Official PHP SDK for Tinker Payments API

v0.0.4(4mo ago)014MITPHPPHP ^8.1CI passing

Since Nov 16Pushed 4mo agoCompare

[ Source](https://github.com/Tinker-Digital-Ltd/tinker-payments-php-sdk)[ Packagist](https://packagist.org/packages/tinker/payments-php-sdk)[ Docs](https://payments.tinker.co.ke)[ RSS](/packages/tinker-payments-php-sdk/feed)WikiDiscussions main Synced today

READMEChangelog (4)Dependencies (8)Versions (6)Used By (0)

Tinker Payments PHP SDK
=======================

[](#tinker-payments-php-sdk)

Official PHP SDK for Tinker Payments API.

Installation
------------

[](#installation)

```
composer require tinker/payments-php-sdk
```

Requirements
------------

[](#requirements)

- PHP 8.1 or higher
- PSR-18 compatible HTTP client (optional, defaults to built-in cURL)
- PSR-17 compatible HTTP factories (optional, defaults to built-in cURL)

Quick Start
-----------

[](#quick-start)

```
use Tinker\TinkerPayments;

$tinker = new TinkerPayments(
    apiPublicKey: 'your-public-key',
    apiSecretKey: 'your-secret-key'
);
```

The SDK auto-selects API environment by key prefix:

- `pk_test_` / `sk_test_` -&gt; sandbox (`https://sandbox-api.tinkerpayments.com/v1`)
- `pk_live_` / `sk_live_` -&gt; production (`https://api.tinkerpayments.com/v1`)

You can also override the API base URL explicitly:

```
$tinker = new TinkerPayments(
    apiPublicKey: 'pk_test_xxx',
    apiSecretKey: 'sk_test_xxx',
    baseUrl: 'http://localhost:8080/v1' // or http://localhost:8080
);
```

Usage
-----

[](#usage)

All standardized API responses follow:

```
{
  "success": true,
  "data": {},
  "meta": {
    "request_id": "uuid",
    "timestamp": "2026-02-11T22:52:45Z",
    "environment": "sandbox"
  }
}
```

The SDK returns the `data` payload directly and exposes the latest `meta` via:

- `transactions()->getLastMeta()`
- `subscriptions()->getLastMeta()`
- `getLastAuthMeta()`

### Initiate a Payment

[](#initiate-a-payment)

```
use Tinker\TinkerPayments;
use Tinker\Enum\Gateway;
use Tinker\Model\DTO\InitiatePaymentRequest;

try {
    $initiateRequest = new InitiatePaymentRequest(
        amount: 100.00,
        currency: 'KES',
        gateway: Gateway::MPESA,
        merchantReference: 'ORDER-12345',
        returnUrl: 'https://your-app.com/payment/return',
        customerPhone: '+254712345678',
        transactionDesc: 'Payment for order #12345',
        metadata: ['order_id' => '12345']
    );

    $transaction = $tinker->transactions()->initiate($initiateRequest);
    $initiationData = $transaction->getInitiationData();

    if ($initiationData->authorizationUrl) {
        // Redirect user to authorization URL (Paystack, Stripe, etc.)
        header('Location: ' . $initiationData->authorizationUrl);
    }
} catch (\Tinker\Exception\ApiException $e) {
    echo "API Error: " . $e->getMessage();
} catch (\Tinker\Exception\NetworkException $e) {
    echo "Network Error: " . $e->getMessage();
}
```

**Note:** The `returnUrl` is where users are redirected after payment completion. Webhooks are configured separately in your dashboard.

### Query a Transaction

[](#query-a-transaction)

```
use Tinker\Model\DTO\QueryPaymentRequest;

$queryRequest = new QueryPaymentRequest(
    paymentReference: 'TXN-abc123xyz',
    gateway: Gateway::MPESA
);

$transaction = $tinker->transactions()->query($queryRequest);

if ($transaction->isSuccessful()) {
    $queryData = $transaction->getQueryData();
    echo "Amount: " . $queryData->amount . " " . $queryData->currency;
}

// Standard response metadata from backend
$meta = $tinker->transactions()->getLastMeta();
echo $meta?->requestId;   // e.g. UUID request_id
echo $meta?->environment; // sandbox | production
```

### Manage Merchant Subscriptions

[](#manage-merchant-subscriptions)

```
use Tinker\Model\DTO\CreateSubscriptionPlanRequest;
use Tinker\Model\DTO\CreateSubscriptionRequest;
use Tinker\Model\DTO\SubscriptionCustomer;

// 1) Create a plan
$plan = $tinker->subscriptions()->createPlan(
    new CreateSubscriptionPlanRequest(
        name: 'Pro Monthly',
        amount: 29.99,
        currency: 'USD',
        intervals: ['monthly']
    )
);

// 2) Create a customer subscription
$subscription = $tinker->subscriptions()->create(
    new CreateSubscriptionRequest(
        planId: $plan['id'],
        gateway: 'stripe',
        billingPeriod: 'monthly',
        customer: new SubscriptionCustomer(
            externalCustomerId: 'cust_001',
            name: 'Jane Doe',
            email: 'jane@example.com'
        )
    )
);

// 3) List and cancel
$allSubscriptions = $tinker->subscriptions()->list();
$tinker->subscriptions()->cancel($subscription['subscription_id']);

// Metadata is available here too
$meta = $tinker->subscriptions()->getLastMeta();
```

### Handle Webhooks

[](#handle-webhooks)

Webhooks support multiple event types: payment, subscription, invoice, and settlement. Check the event type and handle accordingly:

```
use Tinker\TinkerPayments;

$event = $tinker->webhooks()->handleFromRequest();

if (!$tinker->webhooks()->verifySignature($event, 'your-webhook-secret')) {
    http_response_code(401);
    exit('Invalid signature');
}

// Check event type
if ($event->isPaymentEvent()) {
    $paymentData = $event->getPaymentData();
    // Handle payment.completed, payment.failed, etc.
} elseif ($event->isSubscriptionEvent()) {
    $subscriptionData = $event->getSubscriptionData();
    // Handle subscription.created, subscription.cancelled, etc.
} elseif ($event->isInvoiceEvent()) {
    $invoiceData = $event->getInvoiceData();
    // Handle invoice.paid, invoice.failed
} elseif ($event->isSettlementEvent()) {
    $settlementData = $event->getSettlementData();
    // Handle settlement.processed
}

// Access event details
echo "Event type: " . $event->type;        // e.g., "payment.completed"
echo "Event source: " . $event->source;    // e.g., "payment"
echo "App ID: " . $event->meta->appId;
echo "Signature: " . $event->security->signature;
```

Authentication metadata is also available after token fetch:

```
$tinker->transactions()->query($queryRequest); // triggers auth if token not cached
$authMeta = $tinker->getLastAuthMeta();
echo $authMeta?->requestId;
```

For payment events only, you can convert to a `Transaction` object:

```
$transaction = $tinker->webhooks()->handleAsTransaction(file_get_contents('php://input'));
if ($transaction && $transaction->isSuccessful()) {
    $callbackData = $transaction->getCallbackData();
    echo "Payment successful: " . $callbackData->reference;
}
```

Custom HTTP Client
------------------

[](#custom-http-client)

You can use your own PSR-18/PSR-17 compatible client:

```
use Tinker\TinkerPayments;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\HttpFactory;

$tinker = new TinkerPayments(
    apiPublicKey: 'your-public-key',
    apiSecretKey: 'your-secret-key',
    httpClient: new Client(),
    requestFactory: new HttpFactory()
);
```

Documentation
-------------

[](#documentation)

For detailed API documentation, use your Tinker Payments frontend docs route (`/docs`).

License
-------

[](#license)

MIT License

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance74

Regular maintenance activity

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~28 days

Total

4

Last Release

141d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1ed2a7cbb04da56306700e1a24969a31e5118fdfe2023d9d39b88e0b342bd875?d=identicon)[edgarchris](/maintainers/edgarchris)

---

Top Contributors

[![edgar4](https://avatars.githubusercontent.com/u/1897453?v=4)](https://github.com/edgar4 "edgar4 (20 commits)")

---

Tags

mpesa-apiphpsdkapisdkTinkerstripepaymentspayment gatewaympesakenyapaystack

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tinker-payments-php-sdk/health.svg)

```
[![Health](https://phpackages.com/badges/tinker-payments-php-sdk/health.svg)](https://phpackages.com/packages/tinker-payments-php-sdk)
```

###  Alternatives

[telnyx/telnyx-php

Official Telnyx PHP SDK — APIs for Voice, SMS, MMS, WhatsApp, Fax, SIP Trunking, Wireless IoT, Call Control, and more. Build global communications on Telnyx's private carrier-grade network.

35789.4k2](/packages/telnyx-telnyx-php)[openai-php/client

OpenAI PHP is a supercharged PHP API client that allows you to interact with the Open AI API

5.8k28.0M318](/packages/openai-php-client)[mollie/mollie-api-php

Mollie API client library for PHP. Mollie is a European Payment Service provider and offers international payment methods such as Mastercard, VISA, American Express and PayPal, and local payment methods such as iDEAL, Bancontact, SOFORT Banking, SEPA direct debit, Belfius Direct Net, KBC Payment Button and various gift cards such as Podiumcadeaukaart and fashioncheque.

60216.0M83](/packages/mollie-mollie-api-php)[getbrevo/brevo-php

Official Brevo provided RESTFul API V3 php library

1003.9M50](/packages/getbrevo-brevo-php)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[mozex/anthropic-php

PHP client for the Anthropic API: messages, streaming, tool use, thinking, web search, code execution, batches, and more.

49552.5k18](/packages/mozex-anthropic-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
