- list - List Subscriptions
- create - Create Subscription
- export - Export Subscriptions
- get - Get Subscription
- revoke - Revoke Subscription
- update - Update Subscription
List subscriptions.
Scopes: subscriptions:read subscriptions:write
declare(strict_types=1);
require 'vendor/autoload.php';
use Polar;
use Polar\Models\Operations;
$sdk = Polar\Polar::builder()
->setSecurity(
'<YOUR_BEARER_TOKEN_HERE>'
)
->build();
$request = new Operations\SubscriptionsListRequest(
organizationId: '1dbfc517-0bbf-4301-9ba8-555ca42b9737',
);
$responses = $sdk->subscriptions->list(
request: $request
);
foreach ($responses as $response) {
if ($response->statusCode === 200) {
// handle response
}
}| Parameter | Type | Required | Description |
|---|---|---|---|
$request |
Operations\SubscriptionsListRequest | ✔️ | The request object to use for the request. |
?Operations\SubscriptionsListResponse
| Error Type | Status Code | Content Type |
|---|---|---|
| Errors\HTTPValidationError | 422 | application/json |
| Errors\APIException | 4XX, 5XX | */* |
Create a subscription programmatically.
This endpoint only allows to create subscription on free products. For paid products, use the checkout flow.
No initial order will be created and no confirmation email will be sent.
Scopes: subscriptions:write
declare(strict_types=1);
require 'vendor/autoload.php';
use Polar;
use Polar\Models\Components;
$sdk = Polar\Polar::builder()
->setSecurity(
'<YOUR_BEARER_TOKEN_HERE>'
)
->build();
$request = new Components\SubscriptionCreateCustomer(
productId: 'd8dd2de1-21b7-4a41-8bc3-ce909c0cfe23',
customerId: '992fae2a-2a17-4b7a-8d9e-e287cf90131b',
);
$response = $sdk->subscriptions->create(
request: $request
);
if ($response->subscription !== null) {
// handle response
}| Parameter | Type | Required | Description |
|---|---|---|---|
$request |
Components\SubscriptionCreateCustomer|Components\SubscriptionCreateExternalCustomer | ✔️ | The request object to use for the request. |
?Operations\SubscriptionsCreateResponse
| Error Type | Status Code | Content Type |
|---|---|---|
| Errors\HTTPValidationError | 422 | application/json |
| Errors\APIException | 4XX, 5XX | */* |
Export subscriptions as a CSV file.
Scopes: subscriptions:read subscriptions:write
declare(strict_types=1);
require 'vendor/autoload.php';
use Polar;
$sdk = Polar\Polar::builder()
->setSecurity(
'<YOUR_BEARER_TOKEN_HERE>'
)
->build();
$response = $sdk->subscriptions->export(
organizationId: '1dbfc517-0bbf-4301-9ba8-555ca42b9737'
);
if ($response->any !== null) {
// handle response
}| Parameter | Type | Required | Description |
|---|---|---|---|
organizationId |
string|array|null | ➖ | Filter by organization ID. |
?Operations\SubscriptionsExportResponse
| Error Type | Status Code | Content Type |
|---|---|---|
| Errors\HTTPValidationError | 422 | application/json |
| Errors\APIException | 4XX, 5XX | */* |
Get a subscription by ID.
Scopes: subscriptions:read subscriptions:write
declare(strict_types=1);
require 'vendor/autoload.php';
use Polar;
$sdk = Polar\Polar::builder()
->setSecurity(
'<YOUR_BEARER_TOKEN_HERE>'
)
->build();
$response = $sdk->subscriptions->get(
id: '<value>'
);
if ($response->subscription !== null) {
// handle response
}| Parameter | Type | Required | Description |
|---|---|---|---|
id |
string | ✔️ | The subscription ID. |
?Operations\SubscriptionsGetResponse
| Error Type | Status Code | Content Type |
|---|---|---|
| Errors\ResourceNotFound | 404 | application/json |
| Errors\HTTPValidationError | 422 | application/json |
| Errors\APIException | 4XX, 5XX | */* |
Revoke a subscription, i.e cancel immediately.
Scopes: subscriptions:write
declare(strict_types=1);
require 'vendor/autoload.php';
use Polar;
$sdk = Polar\Polar::builder()
->setSecurity(
'<YOUR_BEARER_TOKEN_HERE>'
)
->build();
$response = $sdk->subscriptions->revoke(
id: '<value>'
);
if ($response->subscription !== null) {
// handle response
}| Parameter | Type | Required | Description |
|---|---|---|---|
id |
string | ✔️ | The subscription ID. |
?Operations\SubscriptionsRevokeResponse
| Error Type | Status Code | Content Type |
|---|---|---|
| Errors\AlreadyCanceledSubscription | 403 | application/json |
| Errors\ResourceNotFound | 404 | application/json |
| Errors\SubscriptionLocked | 409 | application/json |
| Errors\HTTPValidationError | 422 | application/json |
| Errors\APIException | 4XX, 5XX | */* |
Update a subscription.
Scopes: subscriptions:write
declare(strict_types=1);
require 'vendor/autoload.php';
use Polar;
use Polar\Models\Components;
$sdk = Polar\Polar::builder()
->setSecurity(
'<YOUR_BEARER_TOKEN_HERE>'
)
->build();
$response = $sdk->subscriptions->update(
id: '<value>',
subscriptionUpdate: new Components\SubscriptionUpdateProduct(
productId: '<value>',
)
);
if ($response->subscription !== null) {
// handle response
}| Parameter | Type | Required | Description |
|---|---|---|---|
id |
string | ✔️ | The subscription ID. |
subscriptionUpdate |
Components\SubscriptionUpdateProduct|Components\SubscriptionUpdateDiscount|Components\SubscriptionUpdateTrial|Components\SubscriptionUpdateSeats|Components\SubscriptionUpdateBillingPeriod|Components\SubscriptionCancel|Components\SubscriptionRevoke | ✔️ | N/A |
?Operations\SubscriptionsUpdateResponse
| Error Type | Status Code | Content Type |
|---|---|---|
| Errors\PaymentFailed | 402 | application/json |
| Errors\AlreadyCanceledSubscription | 403 | application/json |
| Errors\ResourceNotFound | 404 | application/json |
| Errors\SubscriptionLocked | 409 | application/json |
| Errors\HTTPValidationError | 422 | application/json |
| Errors\APIException | 4XX, 5XX | */* |