Skip to content

Latest commit

 

History

History
592 lines (402 loc) · 18.2 KB

README.md

File metadata and controls

592 lines (402 loc) · 18.2 KB

Customers

(customers)

Overview

Available Operations

list

List customers.

Scopes: customers:read customers:write

Example Usage

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\CustomersListRequest(
    organizationId: [
        '1dbfc517-0bbf-4301-9ba8-555ca42b9737',
    ],
);

$responses = $sdk->customers->list(
    request: $request
);


foreach ($responses as $response) {
    if ($response->statusCode === 200) {
        // handle response
    }
}

Parameters

Parameter Type Required Description
$request Operations\CustomersListRequest ✔️ The request object to use for the request.

Response

?Operations\CustomersListResponse

Errors

Error Type Status Code Content Type
Errors\HTTPValidationError 422 application/json
Errors\APIException 4XX, 5XX */*

create

Create a customer.

Scopes: customers:write

Example Usage

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\CustomerCreate(
    externalId: 'usr_1337',
    email: 'customer@example.com',
    name: 'John Doe',
    billingAddress: new Components\Address(
        country: 'SE',
    ),
    taxId: [
        'FR61954506077',
        'eu_vat',
    ],
    organizationId: '1dbfc517-0bbf-4301-9ba8-555ca42b9737',
);

$response = $sdk->customers->create(
    request: $request
);

if ($response->customer !== null) {
    // handle response
}

Parameters

Parameter Type Required Description
$request Components\CustomerCreate ✔️ The request object to use for the request.

Response

?Operations\CustomersCreateResponse

Errors

Error Type Status Code Content Type
Errors\HTTPValidationError 422 application/json
Errors\APIException 4XX, 5XX */*

get

Get a customer by ID.

Scopes: customers:read customers:write

Example Usage

declare(strict_types=1);

require 'vendor/autoload.php';

use Polar;

$sdk = Polar\Polar::builder()
    ->setSecurity(
        '<YOUR_BEARER_TOKEN_HERE>'
    )
    ->build();



$response = $sdk->customers->get(
    id: '<value>'
);

if ($response->customer !== null) {
    // handle response
}

Parameters

Parameter Type Required Description
id string ✔️ The customer ID.

Response

?Operations\CustomersGetResponse

Errors

Error Type Status Code Content Type
Errors\ResourceNotFound 404 application/json
Errors\HTTPValidationError 422 application/json
Errors\APIException 4XX, 5XX */*

update

Update a customer.

Scopes: customers:write

Example Usage

declare(strict_types=1);

require 'vendor/autoload.php';

use Polar;
use Polar\Models\Components;

$sdk = Polar\Polar::builder()
    ->setSecurity(
        '<YOUR_BEARER_TOKEN_HERE>'
    )
    ->build();

$customerUpdate = new Components\CustomerUpdate(
    externalId: 'usr_1337',
    email: 'customer@example.com',
    name: 'John Doe',
    billingAddress: new Components\Address(
        country: 'FR',
    ),
    taxId: [
        'FR61954506077',
        'eu_vat',
    ],
);

$response = $sdk->customers->update(
    id: '<value>',
    customerUpdate: $customerUpdate

);

if ($response->customer !== null) {
    // handle response
}

Parameters

Parameter Type Required Description
id string ✔️ The customer ID.
customerUpdate Components\CustomerUpdate ✔️ N/A

Response

?Operations\CustomersUpdateResponse

Errors

Error Type Status Code Content Type
Errors\ResourceNotFound 404 application/json
Errors\HTTPValidationError 422 application/json
Errors\APIException 4XX, 5XX */*

delete

Delete a customer.

This action cannot be undone and will immediately:

  • Cancel any active subscriptions for the customer
  • Revoke all their benefits
  • Clear any external_id

Use it only in the context of deleting a user within your own service. Otherwise, use more granular API endpoints to cancel a specific subscription or revoke certain benefits.

Note: The customers information will nonetheless be retained for historic orders and subscriptions.

Scopes: customers:write

Example Usage

declare(strict_types=1);

require 'vendor/autoload.php';

use Polar;

$sdk = Polar\Polar::builder()
    ->setSecurity(
        '<YOUR_BEARER_TOKEN_HERE>'
    )
    ->build();



$response = $sdk->customers->delete(
    id: '<value>'
);

if ($response->statusCode === 200) {
    // handle response
}

Parameters

Parameter Type Required Description
id string ✔️ The customer ID.

Response

?Operations\CustomersDeleteResponse

Errors

Error Type Status Code Content Type
Errors\ResourceNotFound 404 application/json
Errors\HTTPValidationError 422 application/json
Errors\APIException 4XX, 5XX */*

getExternal

Get a customer by external ID.

Scopes: customers:read customers:write

Example Usage

declare(strict_types=1);

require 'vendor/autoload.php';

use Polar;

$sdk = Polar\Polar::builder()
    ->setSecurity(
        '<YOUR_BEARER_TOKEN_HERE>'
    )
    ->build();



$response = $sdk->customers->getExternal(
    externalId: '<id>'
);

if ($response->customer !== null) {
    // handle response
}

Parameters

Parameter Type Required Description
externalId string ✔️ The customer external ID.

Response

?Operations\CustomersGetExternalResponse

Errors

Error Type Status Code Content Type
Errors\ResourceNotFound 404 application/json
Errors\HTTPValidationError 422 application/json
Errors\APIException 4XX, 5XX */*

updateExternal

Update a customer by external ID.

Scopes: customers:write

Example Usage

declare(strict_types=1);

require 'vendor/autoload.php';

use Polar;
use Polar\Models\Components;

$sdk = Polar\Polar::builder()
    ->setSecurity(
        '<YOUR_BEARER_TOKEN_HERE>'
    )
    ->build();

$customerUpdate = new Components\CustomerUpdate(
    externalId: 'usr_1337',
    email: 'customer@example.com',
    name: 'John Doe',
    billingAddress: new Components\Address(
        country: 'US',
    ),
    taxId: [
        'FR61954506077',
        'eu_vat',
    ],
);

$response = $sdk->customers->updateExternal(
    externalId: '<id>',
    customerUpdate: $customerUpdate

);

if ($response->customer !== null) {
    // handle response
}

Parameters

Parameter Type Required Description
externalId string ✔️ The customer external ID.
customerUpdate Components\CustomerUpdate ✔️ N/A

Response

?Operations\CustomersUpdateExternalResponse

Errors

Error Type Status Code Content Type
Errors\ResourceNotFound 404 application/json
Errors\HTTPValidationError 422 application/json
Errors\APIException 4XX, 5XX */*

deleteExternal

Delete a customer by external ID.

Immediately cancels any active subscriptions and revokes any active benefits.

Scopes: customers:write

Example Usage

declare(strict_types=1);

require 'vendor/autoload.php';

use Polar;

$sdk = Polar\Polar::builder()
    ->setSecurity(
        '<YOUR_BEARER_TOKEN_HERE>'
    )
    ->build();



$response = $sdk->customers->deleteExternal(
    externalId: '<id>'
);

if ($response->statusCode === 200) {
    // handle response
}

Parameters

Parameter Type Required Description
externalId string ✔️ The customer external ID.

Response

?Operations\CustomersDeleteExternalResponse

Errors

Error Type Status Code Content Type
Errors\ResourceNotFound 404 application/json
Errors\HTTPValidationError 422 application/json
Errors\APIException 4XX, 5XX */*

getState

Get a customer state by ID.

The customer state includes information about the customer's active subscriptions and benefits.

It's the ideal endpoint to use when you need to get a full overview of a customer's status.

Scopes: customers:read customers:write

Example Usage

declare(strict_types=1);

require 'vendor/autoload.php';

use Polar;

$sdk = Polar\Polar::builder()
    ->setSecurity(
        '<YOUR_BEARER_TOKEN_HERE>'
    )
    ->build();



$response = $sdk->customers->getState(
    id: '<value>'
);

if ($response->customerState !== null) {
    // handle response
}

Parameters

Parameter Type Required Description
id string ✔️ The customer ID.

Response

?Operations\CustomersGetStateResponse

Errors

Error Type Status Code Content Type
Errors\ResourceNotFound 404 application/json
Errors\HTTPValidationError 422 application/json
Errors\APIException 4XX, 5XX */*

getStateExternal

Get a customer state by external ID.

The customer state includes information about the customer's active subscriptions and benefits.

It's the ideal endpoint to use when you need to get a full overview of a customer's status.

Scopes: customers:read customers:write

Example Usage

declare(strict_types=1);

require 'vendor/autoload.php';

use Polar;

$sdk = Polar\Polar::builder()
    ->setSecurity(
        '<YOUR_BEARER_TOKEN_HERE>'
    )
    ->build();



$response = $sdk->customers->getStateExternal(
    externalId: '<id>'
);

if ($response->customerState !== null) {
    // handle response
}

Parameters

Parameter Type Required Description
externalId string ✔️ The customer external ID.

Response

?Operations\CustomersGetStateExternalResponse

Errors

Error Type Status Code Content Type
Errors\ResourceNotFound 404 application/json
Errors\HTTPValidationError 422 application/json
Errors\APIException 4XX, 5XX */*