zero-to-prod/spapi-lwa

Connect to Amazons Selling Partner API with Login With Amazon (LWA).

v4.1.0 2025-02-02 00:00 UTC

README

Repo GitHub Actions Workflow Status GitHub Actions Workflow Status Packagist Downloads php Packagist Version License wakatime Hits-of-Code

Contents

Introduction

Connect to Amazons Selling Partner API with Login With Amazon ( LWA).

Requirements

  • PHP 7.1 or higher.

Installation

Install Zerotoprod\SpapiLwa via Composer:

composer require zero-to-prod/spapi-lwa

This will add the package to your project's dependencies and create an autoloader entry for it.

Documentation Publishing

You can publish this README to your local documentation directory.

This can be useful for providing documentation for AI agents.

This can be done using the included script:

# Publish to default location (./docs/zero-to-prod/spapi-lwa)
vendor/bin/zero-to-prod-spapi-lwa

# Publish to custom directory
vendor/bin/zero-to-prod-spapi-lwa /path/to/your/docs

Automatic Documentation Publishing

You can automatically publish documentation by adding the following to your composer.json:

{
    "scripts": {
        "post-install-cmd": [
            "zero-to-prod-spapi-lwa"
        ],
        "post-update-cmd": [
            "zero-to-prod-spapi-lwa"
        ]
    }
}

Usage

Access Toke from Refresh Token

Use this for calling operations that require authorization from a selling partner. All operations that are not grantless operations require authorization from a selling partner. When specifying this value, include the rrefresh_token parameter.

use Zerotoprod\SpapiLwa\SpapiLwa;

$response = SpapiLwa::from('client_id','client_secret')
    ->refreshToken('refresh_token');

$access_token = $response['response']['access_token'];

Access Token from Scope

Use this for calling grantless operations. When specifying this value, include the scope parameter.

use Zerotoprod\SpapiLwa\SpapiLwa;

$response = SpapiLwa::from('client_id','client_secret')
    ->clientCredentials('scope');

$access_token = $response['response']['access_token'];

Testing

You can test the api by faking the response:

use Zerotoprod\SpapiLwa\SpapiLwa;
use Zerotoprod\SpapiLwa\Support\Testing\SpapiLwaResponseFactory;

$response = SpapiLwaResponseFactory::factory()
    ->asRefreshTokenResponse()
    ->make()

SpapiLwaFake::fake($response);

SpapiLwa::from('client_id', 'client_secret')

Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page if you want to contribute.

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature-branch).
  3. Commit changes (git commit -m 'Add some feature').
  4. Push to the branch (git push origin feature-branch).
  5. Create a new Pull Request.