https://github.com/polarsource/polar-php
Polar SDK for PHP
https://github.com/polarsource/polar-php
Last synced: 3 months ago
JSON representation
Polar SDK for PHP
- Host: GitHub
- URL: https://github.com/polarsource/polar-php
- Owner: polarsource
- Created: 2024-12-19T14:16:15.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2026-03-28T00:29:26.000Z (3 months ago)
- Last Synced: 2026-03-28T17:34:12.018Z (3 months ago)
- Language: PHP
- Homepage: https://docs.polar.sh/developers/sdk
- Size: 3.09 MB
- Stars: 41
- Watchers: 3
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
Awesome Lists containing this project
README
# polar-sh/sdk
Developer-friendly & type-safe Php SDK specifically catered to leverage *polar-sh/sdk* API.
> [!IMPORTANT]
> This SDK is not yet ready for production use. To complete setup please follow the steps outlined in your [workspace](https://app.speakeasy.com/org/polar/polar). Delete this section before > publishing to a package manager.
## Summary
Polar API: Polar HTTP and Webhooks API
Read the docs at https://polar.sh/docs/api-reference
## Table of Contents
* [polar-sh/sdk](#polar-shsdk)
* [SDK Installation](#sdk-installation)
* [SDK Example Usage](#sdk-example-usage)
* [Authentication](#authentication)
* [Available Resources and Operations](#available-resources-and-operations)
* [Pagination](#pagination)
* [Error Handling](#error-handling)
* [Server Selection](#server-selection)
* [Development](#development)
* [Maturity](#maturity)
* [Contributions](#contributions)
## SDK Installation
The SDK relies on [Composer](https://getcomposer.org/) to manage its dependencies.
To install the SDK and add it as a dependency to an existing `composer.json` file:
```bash
composer require "polar-sh/sdk"
```
## SDK Example Usage
### Example
```php
declare(strict_types=1);
require 'vendor/autoload.php';
use Polar;
$sdk = Polar\Polar::builder()
->setSecurity(
''
)
->build();
$responses = $sdk->organizations->list(
page: 1,
limit: 10
);
foreach ($responses as $response) {
if ($response->statusCode === 200) {
// handle response
}
}
```
## Authentication
### Per-Client Security Schemes
This SDK supports the following security scheme globally:
| Name | Type | Scheme |
| ------------- | ---- | ----------- |
| `accessToken` | http | HTTP Bearer |
To authenticate with the API the `accessToken` parameter must be set when initializing the SDK. For example:
```php
declare(strict_types=1);
require 'vendor/autoload.php';
use Polar;
$sdk = Polar\Polar::builder()
->setSecurity(
''
)
->build();
$responses = $sdk->organizations->list(
page: 1,
limit: 10
);
foreach ($responses as $response) {
if ($response->statusCode === 200) {
// handle response
}
}
```
### Per-Operation Security Schemes
Some operations in this SDK require the security scheme to be specified at the request level. For example:
```php
declare(strict_types=1);
require 'vendor/autoload.php';
use Polar;
use Polar\Models\Operations;
$sdk = Polar\Polar::builder()->build();
$request = new Operations\CustomerPortalBenefitGrantsListRequest();
$requestSecurity = new Operations\CustomerPortalBenefitGrantsListSecurity(
customerSession: '',
);
$responses = $sdk->customerPortal->benefitGrants->list(
request: $request,
security: $requestSecurity
);
foreach ($responses as $response) {
if ($response->statusCode === 200) {
// handle response
}
}
```
## Available Resources and Operations
Available methods
### [BenefitGrants](docs/sdks/benefitgrants/README.md)
* [list](docs/sdks/benefitgrants/README.md#list) - List Benefit Grants
### [Benefits](docs/sdks/benefits/README.md)
* [list](docs/sdks/benefits/README.md#list) - List Benefits
* [create](docs/sdks/benefits/README.md#create) - Create Benefit
* [get](docs/sdks/benefits/README.md#get) - Get Benefit
* [delete](docs/sdks/benefits/README.md#delete) - Delete Benefit
* [update](docs/sdks/benefits/README.md#update) - Update Benefit
* [grants](docs/sdks/benefits/README.md#grants) - List Benefit Grants
### [CheckoutLinks](docs/sdks/checkoutlinks/README.md)
* [list](docs/sdks/checkoutlinks/README.md#list) - List Checkout Links
* [create](docs/sdks/checkoutlinks/README.md#create) - Create Checkout Link
* [get](docs/sdks/checkoutlinks/README.md#get) - Get Checkout Link
* [delete](docs/sdks/checkoutlinks/README.md#delete) - Delete Checkout Link
* [update](docs/sdks/checkoutlinks/README.md#update) - Update Checkout Link
### [Checkouts](docs/sdks/checkouts/README.md)
* [list](docs/sdks/checkouts/README.md#list) - List Checkout Sessions
* [create](docs/sdks/checkouts/README.md#create) - Create Checkout Session
* [get](docs/sdks/checkouts/README.md#get) - Get Checkout Session
* [update](docs/sdks/checkouts/README.md#update) - Update Checkout Session
* [clientGet](docs/sdks/checkouts/README.md#clientget) - Get Checkout Session from Client
* [clientUpdate](docs/sdks/checkouts/README.md#clientupdate) - Update Checkout Session from Client
* [clientConfirm](docs/sdks/checkouts/README.md#clientconfirm) - Confirm Checkout Session from Client
### [CustomFields](docs/sdks/customfields/README.md)
* [list](docs/sdks/customfields/README.md#list) - List Custom Fields
* [create](docs/sdks/customfields/README.md#create) - Create Custom Field
* [get](docs/sdks/customfields/README.md#get) - Get Custom Field
* [delete](docs/sdks/customfields/README.md#delete) - Delete Custom Field
* [update](docs/sdks/customfields/README.md#update) - Update Custom Field
### [CustomerMeters](docs/sdks/customermeters/README.md)
* [list](docs/sdks/customermeters/README.md#list) - List Customer Meters
* [get](docs/sdks/customermeters/README.md#get) - Get Customer Meter
### [CustomerPortal.BenefitGrants](docs/sdks/polarbenefitgrants/README.md)
* [list](docs/sdks/polarbenefitgrants/README.md#list) - List Benefit Grants
* [get](docs/sdks/polarbenefitgrants/README.md#get) - Get Benefit Grant
* [update](docs/sdks/polarbenefitgrants/README.md#update) - Update Benefit Grant
### [CustomerPortal.CustomerMeters](docs/sdks/polarcustomermeters/README.md)
* [list](docs/sdks/polarcustomermeters/README.md#list) - List Meters
* [get](docs/sdks/polarcustomermeters/README.md#get) - Get Customer Meter
### [CustomerPortal.CustomerSession](docs/sdks/customersession/README.md)
* [introspect](docs/sdks/customersession/README.md#introspect) - Introspect Customer Session
* [getAuthenticatedUser](docs/sdks/customersession/README.md#getauthenticateduser) - Get Authenticated Portal User
### [CustomerPortal.Customers](docs/sdks/polarcustomers/README.md)
* [get](docs/sdks/polarcustomers/README.md#get) - Get Customer
* [update](docs/sdks/polarcustomers/README.md#update) - Update Customer
* [listPaymentMethods](docs/sdks/polarcustomers/README.md#listpaymentmethods) - List Customer Payment Methods
* [addPaymentMethod](docs/sdks/polarcustomers/README.md#addpaymentmethod) - Add Customer Payment Method
* [confirmPaymentMethod](docs/sdks/polarcustomers/README.md#confirmpaymentmethod) - Confirm Customer Payment Method
* [deletePaymentMethod](docs/sdks/polarcustomers/README.md#deletepaymentmethod) - Delete Customer Payment Method
### [CustomerPortal.Downloadables](docs/sdks/downloadables/README.md)
* [list](docs/sdks/downloadables/README.md#list) - List Downloadables
### [CustomerPortal.LicenseKeys](docs/sdks/polarlicensekeys/README.md)
* [list](docs/sdks/polarlicensekeys/README.md#list) - List License Keys
* [get](docs/sdks/polarlicensekeys/README.md#get) - Get License Key
* [validate](docs/sdks/polarlicensekeys/README.md#validate) - Validate License Key
* [activate](docs/sdks/polarlicensekeys/README.md#activate) - Activate License Key
* [deactivate](docs/sdks/polarlicensekeys/README.md#deactivate) - Deactivate License Key
### [CustomerPortal.Members](docs/sdks/polarmembers/README.md)
* [listMembers](docs/sdks/polarmembers/README.md#listmembers) - List Members
* [addMember](docs/sdks/polarmembers/README.md#addmember) - Add Member
* [removeMember](docs/sdks/polarmembers/README.md#removemember) - Remove Member
* [updateMember](docs/sdks/polarmembers/README.md#updatemember) - Update Member
### [CustomerPortal.Orders](docs/sdks/polarorders/README.md)
* [list](docs/sdks/polarorders/README.md#list) - List Orders
* [get](docs/sdks/polarorders/README.md#get) - Get Order
* [update](docs/sdks/polarorders/README.md#update) - Update Order
* [invoice](docs/sdks/polarorders/README.md#invoice) - Get Order Invoice
* [generateInvoice](docs/sdks/polarorders/README.md#generateinvoice) - Generate Order Invoice
* [getPaymentStatus](docs/sdks/polarorders/README.md#getpaymentstatus) - Get Order Payment Status
* [confirmRetryPayment](docs/sdks/polarorders/README.md#confirmretrypayment) - Confirm Retry Payment
### [CustomerPortal.Organizations](docs/sdks/polarorganizations/README.md)
* [get](docs/sdks/polarorganizations/README.md#get) - Get Organization
### [CustomerPortal.Seats](docs/sdks/seats/README.md)
* [listSeats](docs/sdks/seats/README.md#listseats) - List Seats
* [assignSeat](docs/sdks/seats/README.md#assignseat) - Assign Seat
* [revokeSeat](docs/sdks/seats/README.md#revokeseat) - Revoke Seat
* [resendInvitation](docs/sdks/seats/README.md#resendinvitation) - Resend Invitation
* [listClaimedSubscriptions](docs/sdks/seats/README.md#listclaimedsubscriptions) - List Claimed Subscriptions
### [CustomerPortal.Subscriptions](docs/sdks/polarsubscriptions/README.md)
* [list](docs/sdks/polarsubscriptions/README.md#list) - List Subscriptions
* [get](docs/sdks/polarsubscriptions/README.md#get) - Get Subscription
* [cancel](docs/sdks/polarsubscriptions/README.md#cancel) - Cancel Subscription
* [update](docs/sdks/polarsubscriptions/README.md#update) - Update Subscription
### [CustomerPortal.Wallets](docs/sdks/wallets/README.md)
* [list](docs/sdks/wallets/README.md#list) - List Wallets
* [get](docs/sdks/wallets/README.md#get) - Get Wallet
### [CustomerSeats](docs/sdks/customerseats/README.md)
* [listSeats](docs/sdks/customerseats/README.md#listseats) - List Seats
* [assignSeat](docs/sdks/customerseats/README.md#assignseat) - Assign Seat
* [revokeSeat](docs/sdks/customerseats/README.md#revokeseat) - Revoke Seat
* [resendInvitation](docs/sdks/customerseats/README.md#resendinvitation) - Resend Invitation
* [getClaimInfo](docs/sdks/customerseats/README.md#getclaiminfo) - Get Claim Info
* [claimSeat](docs/sdks/customerseats/README.md#claimseat) - Claim Seat
### [CustomerSessions](docs/sdks/customersessions/README.md)
* [create](docs/sdks/customersessions/README.md#create) - Create Customer Session
### [Customers](docs/sdks/customers/README.md)
* [list](docs/sdks/customers/README.md#list) - List Customers
* [create](docs/sdks/customers/README.md#create) - Create Customer
* [export](docs/sdks/customers/README.md#export) - Export Customers
* [get](docs/sdks/customers/README.md#get) - Get Customer
* [delete](docs/sdks/customers/README.md#delete) - Delete Customer
* [update](docs/sdks/customers/README.md#update) - Update Customer
* [getExternal](docs/sdks/customers/README.md#getexternal) - Get Customer by External ID
* [deleteExternal](docs/sdks/customers/README.md#deleteexternal) - Delete Customer by External ID
* [updateExternal](docs/sdks/customers/README.md#updateexternal) - Update Customer by External ID
* [getState](docs/sdks/customers/README.md#getstate) - Get Customer State
* [getStateExternal](docs/sdks/customers/README.md#getstateexternal) - Get Customer State by External ID
### [Discounts](docs/sdks/discounts/README.md)
* [list](docs/sdks/discounts/README.md#list) - List Discounts
* [create](docs/sdks/discounts/README.md#create) - Create Discount
* [get](docs/sdks/discounts/README.md#get) - Get Discount
* [delete](docs/sdks/discounts/README.md#delete) - Delete Discount
* [update](docs/sdks/discounts/README.md#update) - Update Discount
### [Disputes](docs/sdks/disputes/README.md)
* [list](docs/sdks/disputes/README.md#list) - List Disputes
* [get](docs/sdks/disputes/README.md#get) - Get Dispute
### [EventTypes](docs/sdks/eventtypes/README.md)
* [list](docs/sdks/eventtypes/README.md#list) - List Event Types
* [update](docs/sdks/eventtypes/README.md#update) - Update Event Type
### [Events](docs/sdks/events/README.md)
* [list](docs/sdks/events/README.md#list) - List Events
* [listNames](docs/sdks/events/README.md#listnames) - List Event Names
* [get](docs/sdks/events/README.md#get) - Get Event
* [ingest](docs/sdks/events/README.md#ingest) - Ingest Events
### [Files](docs/sdks/files/README.md)
* [list](docs/sdks/files/README.md#list) - List Files
* [create](docs/sdks/files/README.md#create) - Create File
* [uploaded](docs/sdks/files/README.md#uploaded) - Complete File Upload
* [delete](docs/sdks/files/README.md#delete) - Delete File
* [update](docs/sdks/files/README.md#update) - Update File
### [LicenseKeys](docs/sdks/licensekeys/README.md)
* [list](docs/sdks/licensekeys/README.md#list) - List License Keys
* [get](docs/sdks/licensekeys/README.md#get) - Get License Key
* [update](docs/sdks/licensekeys/README.md#update) - Update License Key
* [getActivation](docs/sdks/licensekeys/README.md#getactivation) - Get Activation
* [validate](docs/sdks/licensekeys/README.md#validate) - Validate License Key
* [activate](docs/sdks/licensekeys/README.md#activate) - Activate License Key
* [deactivate](docs/sdks/licensekeys/README.md#deactivate) - Deactivate License Key
### [Members](docs/sdks/members/README.md)
* [listMembers](docs/sdks/members/README.md#listmembers) - List Members
* [createMember](docs/sdks/members/README.md#createmember) - Create Member
* [getMember](docs/sdks/members/README.md#getmember) - Get Member
* [deleteMember](docs/sdks/members/README.md#deletemember) - Delete Member
* [updateMember](docs/sdks/members/README.md#updatemember) - Update Member
### [Meters](docs/sdks/meters/README.md)
* [list](docs/sdks/meters/README.md#list) - List Meters
* [create](docs/sdks/meters/README.md#create) - Create Meter
* [get](docs/sdks/meters/README.md#get) - Get Meter
* [update](docs/sdks/meters/README.md#update) - Update Meter
* [quantities](docs/sdks/meters/README.md#quantities) - Get Meter Quantities
### [Metrics](docs/sdks/metrics/README.md)
* [get](docs/sdks/metrics/README.md#get) - Get Metrics
* [limits](docs/sdks/metrics/README.md#limits) - Get Metrics Limits
* [listDashboards](docs/sdks/metrics/README.md#listdashboards) - List Metric Dashboards
* [createDashboard](docs/sdks/metrics/README.md#createdashboard) - Create Metric Dashboard
* [getDashboard](docs/sdks/metrics/README.md#getdashboard) - Get Metric Dashboard
* [deleteDashboard](docs/sdks/metrics/README.md#deletedashboard) - Delete Metric Dashboard
* [updateDashboard](docs/sdks/metrics/README.md#updatedashboard) - Update Metric Dashboard
### [Oauth2](docs/sdks/oauth2/README.md)
* [authorize](docs/sdks/oauth2/README.md#authorize) - Authorize
* [token](docs/sdks/oauth2/README.md#token) - Request Token
* [revoke](docs/sdks/oauth2/README.md#revoke) - Revoke Token
* [introspect](docs/sdks/oauth2/README.md#introspect) - Introspect Token
* [userinfo](docs/sdks/oauth2/README.md#userinfo) - Get User Info
#### [Oauth2.Clients](docs/sdks/clients/README.md)
* [create](docs/sdks/clients/README.md#create) - Create Client
* [get](docs/sdks/clients/README.md#get) - Get Client
* [update](docs/sdks/clients/README.md#update) - Update Client
* [delete](docs/sdks/clients/README.md#delete) - Delete Client
### [Orders](docs/sdks/orders/README.md)
* [list](docs/sdks/orders/README.md#list) - List Orders
* [export](docs/sdks/orders/README.md#export) - Export Orders
* [get](docs/sdks/orders/README.md#get) - Get Order
* [update](docs/sdks/orders/README.md#update) - Update Order
* [invoice](docs/sdks/orders/README.md#invoice) - Get Order Invoice
* [generateInvoice](docs/sdks/orders/README.md#generateinvoice) - Generate Order Invoice
### [OrganizationAccessTokens](docs/sdks/organizationaccesstokens/README.md)
* [list](docs/sdks/organizationaccesstokens/README.md#list) - List
* [create](docs/sdks/organizationaccesstokens/README.md#create) - Create
* [delete](docs/sdks/organizationaccesstokens/README.md#delete) - Delete
* [update](docs/sdks/organizationaccesstokens/README.md#update) - Update
### [Organizations](docs/sdks/organizations/README.md)
* [list](docs/sdks/organizations/README.md#list) - List Organizations
* [create](docs/sdks/organizations/README.md#create) - Create Organization
* [get](docs/sdks/organizations/README.md#get) - Get Organization
* [update](docs/sdks/organizations/README.md#update) - Update Organization
### [Payments](docs/sdks/payments/README.md)
* [list](docs/sdks/payments/README.md#list) - List Payments
* [get](docs/sdks/payments/README.md#get) - Get Payment
### [Products](docs/sdks/products/README.md)
* [list](docs/sdks/products/README.md#list) - List Products
* [create](docs/sdks/products/README.md#create) - Create Product
* [get](docs/sdks/products/README.md#get) - Get Product
* [update](docs/sdks/products/README.md#update) - Update Product
* [updateBenefits](docs/sdks/products/README.md#updatebenefits) - Update Product Benefits
### [Refunds](docs/sdks/refunds/README.md)
* [list](docs/sdks/refunds/README.md#list) - List Refunds
* [create](docs/sdks/refunds/README.md#create) - Create Refund
### [Subscriptions](docs/sdks/subscriptions/README.md)
* [list](docs/sdks/subscriptions/README.md#list) - List Subscriptions
* [create](docs/sdks/subscriptions/README.md#create) - Create Subscription
* [export](docs/sdks/subscriptions/README.md#export) - Export Subscriptions
* [get](docs/sdks/subscriptions/README.md#get) - Get Subscription
* [revoke](docs/sdks/subscriptions/README.md#revoke) - Revoke Subscription
* [update](docs/sdks/subscriptions/README.md#update) - Update Subscription
### [Webhooks](docs/sdks/webhooks/README.md)
* [listWebhookEndpoints](docs/sdks/webhooks/README.md#listwebhookendpoints) - List Webhook Endpoints
* [createWebhookEndpoint](docs/sdks/webhooks/README.md#createwebhookendpoint) - Create Webhook Endpoint
* [getWebhookEndpoint](docs/sdks/webhooks/README.md#getwebhookendpoint) - Get Webhook Endpoint
* [deleteWebhookEndpoint](docs/sdks/webhooks/README.md#deletewebhookendpoint) - Delete Webhook Endpoint
* [updateWebhookEndpoint](docs/sdks/webhooks/README.md#updatewebhookendpoint) - Update Webhook Endpoint
* [resetWebhookEndpointSecret](docs/sdks/webhooks/README.md#resetwebhookendpointsecret) - Reset Webhook Endpoint Secret
* [listWebhookDeliveries](docs/sdks/webhooks/README.md#listwebhookdeliveries) - List Webhook Deliveries
* [redeliverWebhookEvent](docs/sdks/webhooks/README.md#redeliverwebhookevent) - Redeliver Webhook Event
## Pagination
Some of the endpoints in this SDK support pagination. To use pagination, you make your SDK calls as usual, but the
returned object will be a `Generator` instead of an individual response.
Working with generators is as simple as iterating over the responses in a `foreach` loop, and you can see an example below:
```php
declare(strict_types=1);
require 'vendor/autoload.php';
use Polar;
$sdk = Polar\Polar::builder()
->setSecurity(
''
)
->build();
$responses = $sdk->organizations->list(
page: 1,
limit: 10
);
foreach ($responses as $response) {
if ($response->statusCode === 200) {
// handle response
}
}
```
## Error Handling
Handling errors in this SDK should largely match your expectations. All operations return a response object or throw an exception.
By default an API error will raise a `Errors\APIException` exception, which has the following properties:
| Property | Type | Description |
|----------------|-----------------------------------------|-----------------------|
| `$message` | *string* | The error message |
| `$statusCode` | *int* | The HTTP status code |
| `$rawResponse` | *?\Psr\Http\Message\ResponseInterface* | The raw HTTP response |
| `$body` | *string* | The response content |
When custom error responses are specified for an operation, the SDK may also throw their associated exception. You can refer to respective *Errors* tables in SDK docs for more details on possible exception types for each operation. For example, the `list` method throws the following exceptions:
| Error Type | Status Code | Content Type |
| -------------------------- | ----------- | ---------------- |
| Errors\HTTPValidationError | 422 | application/json |
| Errors\APIException | 4XX, 5XX | \*/\* |
### Example
```php
declare(strict_types=1);
require 'vendor/autoload.php';
use Polar;
use Polar\Models\Errors;
$sdk = Polar\Polar::builder()
->setSecurity(
''
)
->build();
try {
$responses = $sdk->organizations->list(
page: 1,
limit: 10
);
foreach ($responses as $response) {
if ($response->statusCode === 200) {
// handle response
}
}
} catch (Errors\HTTPValidationErrorThrowable $e) {
// handle $e->$container data
throw $e;
} catch (Errors\APIException $e) {
// handle default exception
throw $e;
}
```
## Server Selection
### Select Server by Name
You can override the default server globally using the `setServer(string $serverName)` builder method when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the names associated with the available servers:
| Name | Server | Description |
| ------------ | ------------------------------ | ---------------------- |
| `production` | `https://api.polar.sh` | Production environment |
| `sandbox` | `https://sandbox-api.polar.sh` | Sandbox environment |
#### Example
```php
declare(strict_types=1);
require 'vendor/autoload.php';
use Polar;
$sdk = Polar\Polar::builder()
->setServer('production')
->setSecurity(
''
)
->build();
$responses = $sdk->organizations->list(
page: 1,
limit: 10
);
foreach ($responses as $response) {
if ($response->statusCode === 200) {
// handle response
}
}
```
### Override Server URL Per-Client
The default server can also be overridden globally using the `setServerUrl(string $serverUrl)` builder method when initializing the SDK client instance. For example:
```php
declare(strict_types=1);
require 'vendor/autoload.php';
use Polar;
$sdk = Polar\Polar::builder()
->setServerURL('https://api.polar.sh')
->setSecurity(
''
)
->build();
$responses = $sdk->organizations->list(
page: 1,
limit: 10
);
foreach ($responses as $response) {
if ($response->statusCode === 200) {
// handle response
}
}
```
# Development
## Maturity
This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage
to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally
looking for the latest version.
## Contributions
While we value open-source contributions to this SDK, this library is generated programmatically. Any manual changes added to internal files will be overwritten on the next generation.
We look forward to hearing your feedback. Feel free to open a PR or an issue with a proof of concept and we'll do our best to include it in a future release.
### SDK Created by [Speakeasy](https://www.speakeasy.com/?utm_source=polar-sh/sdk&utm_campaign=php)