1. Go to this page and download the library: Download tinker/payments-php-sdk library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tinker / payments-php-sdk example snippets
use Tinker\TinkerPayments;
$tinker = new TinkerPayments(
apiPublicKey: 'your-public-key',
apiSecretKey: 'your-secret-key'
);
$tinker = new TinkerPayments(
apiPublicKey: 'pk_test_xxx',
apiSecretKey: 'sk_test_xxx',
baseUrl: 'http://localhost:8080/v1' // or http://localhost:8080
);
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();
}
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
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: '[email protected]'
)
)
);
// 3) List and cancel
$allSubscriptions = $tinker->subscriptions()->list();
$tinker->subscriptions()->cancel($subscription['subscription_id']);
// Metadata is available here too
$meta = $tinker->subscriptions()->getLastMeta();
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()
);
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.