I’m developing a way to use Keap to help track purchases made in our retail store. When I save a new order using the PHP SDK, the status is of course marked as “Unpaid”. We’re not using Keap to track payments; our retail store collects payments in an entirely different way. However, I’d like to mark the order as paid in Keap just to avoid any confusion in the future. How do I immediately send a second call that updates the order so it shows as Paid in Keap?
HI Sean! You can create an order and immediately mark it as paid in Keap by registering a payment for the total order amount using the PHP SDK (full docs here: Keap PHP SDK OrdersApi):
<?php
require_once '../../vendor/autoload.php';
use Keap\Core\V2\Api\OrdersApi;
use Keap\Core\V2\Configuration;
use Keap\Core\V2\HeaderSelector;
use Keap\Core\V2\Model\RestCreateOrderRequest;
use Keap\Core\V2\Model\CreateOrderItemRequest;
use Keap\Core\V2\Model\CreatePaymentRequest;
use GuzzleHttp\Client;
use Dotenv\Dotenv;
// Load environment variables
$dotenv = Dotenv::createImmutable(__DIR__ . '/../../');
$dotenv->safeLoad();
$accessToken = $_ENV['KEAP_REST_API_SERVICE_ACCESS_TOKEN'] ?? '';
if (!$accessToken) exit("❌ No access token found\n");
// Keap client configuration
$config = new Configuration();
$config->setAccessToken($accessToken);
// Custom header selector to add Authorization
$headerSelector = new class extends HeaderSelector {
public function selectHeaders(array $accept, string $contentType, bool $isMultipart): array {
$headers = parent::selectHeaders($accept, $contentType, $isMultipart);
$headers['Authorization'] = 'Bearer ' . $_ENV['KEAP_REST_API_SERVICE_ACCESS_TOKEN'];
return $headers;
}
};
$ordersApi = new OrdersApi(new Client(), $config, $headerSelector);
try {
// Create the order item
$orderItem = new CreateOrderItemRequest();
$orderItem->setProductId('7')
->setQuantity(2)
->setPricePerUnit(50.00)
->setName('Test Product')
->setDescription('Test product description')
->setItemType('PRODUCT');
// Create the order
$createOrderRequest = new RestCreateOrderRequest();
$createOrderRequest->setContactId('2')
->setOrderTitle('Test Order - PHP SDK')
->setOrderType('OFFLINE')
->setOrderItems([$orderItem])
->setOrderTime('2025-11-07T23:00:00Z');
$newOrder = $ordersApi->createOrder($createOrderRequest);
$orderId = $newOrder->getId();
// Get the order before payment
$orderBeforePayment = $ordersApi->getOrder($orderId);
$totalDueAmount = $orderBeforePayment->getTotalDue() ? $orderBeforePayment->getTotalDue()->getAmount() / 100.0 : 0.0;
// Register a payment for the total order amount
$paymentRequest = new CreatePaymentRequest();
$paymentRequest->setPaymentAmount($totalDueAmount)
->setPaymentMethodType('Cash')
->setNotes('Payment made via PHP SDK')
->setPaymentTime(date('c'));
$payment = $ordersApi->createPaymentForAnOrder($orderId, $paymentRequest);
// Get the order after payment
$orderAfterPayment = $ordersApi->getOrder($orderId);
// Display final order status
echo "Order ID: {$orderAfterPayment->getId()}\n";
echo "Status: {$orderAfterPayment->getStatus()}\n";
echo "Total Due: " . ($orderAfterPayment->getTotalDue()?->getFormattedAmount() ?? '$0.00') . "\n";
echo "Total Paid: " . ($orderAfterPayment->getTotalPaid()?->getFormattedAmount() ?? '$0.00') . "\n";
} catch (Exception $e) {
echo "Error: " . $e->getMessage() . "\n";
}
This looks like exactly what I needed. Thanks!
Following up on this: I’m looking at your sample code and trying to work it into my code, and I’m confused. The application I’m working on says it’s using the Infusionsoft PHP SDK, and it’s stored in the app repo under vendors/infusionsoft/php-sdk. But it doesn’t look like this code, and it doesn’t call these libraries. It loads a single library called “Infusionsoft\Infusionsoft.” When I look into some of the source code files , they use namespace “Infusionsoft/Api/Rest”, and the base URL is “https://api.infusionsoft.com/crm/rest/v1/” with different endings for different specific libraries - orders, contacts, etc.
Am I using an older version of the Keap PHP SDK?
Yes, what you have is the old, deprecated PHP SDK. It uses Infusionsoft\Infusionsoft and the v1 endpoints (https://api.infusionsoft.com/crm/rest/v1/). The new version uses the REST v2 API and can be found here: Keap PHP SDK
Will the new version of the SDK work with PHP v7.4, or does it require 8.0 or higher? Is there a way to do what I want with the old SDK?
PHP 8.1 or later is required.
You can adapt any SDK as the PHP code is accessible. I still use the original SDK, and have adapted it to work with newer versions of PHP.
You just need to look at the code to and make the necessary changes, or create your own code that interacts with the API.
All right, buried deep in the old SDK I found a function addPayment() in the class OrderService, but I can’t find what data it requires. The signature shows a single parameter, $payment Details, but what does that have to contain? I can’t find that information anywhere.
Thanks for your help on this.
never mind, I figured it out. $paymentDetails has to be the object defined in the ‘Create Payment’ call in the old SDK.