Giter Site home page Giter Site logo

allegro-api-client-php's Introduction

Allegro Api PHP Client

Helper model and connector classes for allegro integration.

Parts of the library is automatically generated by the OpenAPI Generator project using swagger definition from allegro:

https://developer.allegro.pl/swagger.yaml

Installation with composer

composer require coffeedesk/allegro-api-client-php

Api documentation

This package was implemented according to:

https://developer.allegro.pl/documentation/

Usage

OAuth

Implementation OAuth according to https://developer.allegro.pl/auth/

1 Stage: Get code from callback

<?php

require_once(__DIR__ . '/vendor/autoload.php');

$authenticator = new \AllegroApi\Authentication\Authenticator(
    new \GuzzleHttp\Client(),
    'https://allegro.pl.allegrosandbox.pl',
    'ALLEGRO_CLIENT_ID', // after add this app to allegro sandbox panel you will get this
    'ALLEGRO_CLIENT_SECRET', // after add this app to allegro sandbox panel you will get this
    'http://uri.where.is.sent.callback/authorization_callback' // after authorization callback will be sent on url (you can use serveo.net localy)
);

echo $authenticator->getAuthorizeUrl();

// This shows url to allegro OAuth, you can redirect in your app to this url in your controller.

?>

2 Stage: Get tokens from callback after authorization - e.g. http://uri.where.is.sent.callback/authorization_callback

Make controller under your callback url, allegro will send you tokens after login.

$authorizationToken = $_GET['code'];
$tokens = $authenticator->getAuthenticationTokensFromAuthorizationToken($authorizationToken);

3 Stage: Use received access token in every request

<?php

require_once(__DIR__ . '/vendor/autoload.php');

$configuration = (new \AllegroApi\Configuration())
    ->setHost('https://api.allegro.pl.allegrosandbox.pl')
    ->setAccessToken('access.token.received.from.callback.authorize.url');

$offerManagmentApi = new \AllegroApi\Client\OfferManagementApi(
    new \GuzzleHttp\Client(),
    $configuration
);

$categories = $offerManagmentApi->getCategoriesUsingGET();

var_dump($categories);

?>

Refresh token

To refresh allegro token you might need get current token from your repository


<?php

require_once(__DIR__ . '/vendor/autoload.php');

$authenticator = new \AllegroApi\Authentication\Authenticator(
    new \GuzzleHttp\Client(),
    'https://allegro.pl.allegrosandbox.pl',
    'ALLEGRO_CLIENT_ID', // after add this app to allegro sandbox panel you will get this
    'ALLEGRO_CLIENT_SECRET', // after add this app to allegro sandbox panel you will get this
    'http://uri.where.is.sent.callback/authorization_callback' // after authorization callback will be sent on url (you can use serveo.net localy)
);

// your repository 
$tokenData = $allegroTokenRepository->getCurrentToken();

$newTokenData = $authenticator->getNewTokensFromCurrentTokens($tokenData['refresh_token']);

// your repository 
$allegroTokenRepository->allegroTokenRepository->saveToken($newTokenData);

Code Notice: Best way to use authenticator and AllegroApi classes is Dependency Injection. To define configuration(\AllegroApi\Configuration) you can use factory pattern.

Development

Generate php classes using openapi-generator

ATTENTION!

Please look at commit 070d13ed2d031c8361597aead4071a78b6317ba6 in this repo. Package openapi-generator always generate wrong CategoryParameters.php. You have to fix it every time you regenerate this code.

To generate new clients and models run:

docker run --rm \
-v ${PWD}:/local/project \
-v ${PWD}/src:/local/out/php/lib \
openapitools/openapi-generator-cli generate \
-i /local/project/swagger.yaml \
-g php \
-o /local/out/php \
--invoker-package AllegroApi \
--api-package Client \
--model-package Model

allegro-api-client-php's People

Contributors

arkowsky avatar lukaszwit avatar lwillems avatar nediam avatar tomaszdurka avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

allegro-api-client-php's Issues

Content is lost when deserializing offer

Hi

First : thanks for your work, very useful to deal with Allegro.

I have encountered a bug when working with offer where description is defined.
Calling getOfferUsingGET on UsersOfferInformationApi class.

On raw API reply description is ok

  "description": {
    "sections": [
      {
        "items": [
          {
            "type": "TEXT",
            "content": "<h1>A description</h1>"
          }
        ]
      }
    ]
  },

But when deseriazing items model is hardcoded to parent ($openApiTypes) which does not handle content (only type) so content is lost

//vendor/coffeedesk/allegro-api-client-php/src/Model/DescriptionSection.php
    protected static $openAPITypes = [
        'items' => '\AllegroApi\Model\DescriptionSectionItem[]'
    ];

Instead child model shoud be used

  • vendor/coffeedesk/allegro-api-client-php/src/Model/DescriptionSectionItemText.php
  • vendor/coffeedesk/allegro-api-client-php/src/Model/DescriptionSectionItemImage.php

Regards

No FULFILLMENT_STATUS_CHANGED status in \AllegroApi\Model\CheckoutFormStatus

Hi, while calling getOrderEventsUsingGET method I'm getting an error like:

Uncaught PHP Exception InvalidArgumentException: "Invalid value for enum '\AllegroApi\Model\CheckoutFormStatus', must be one of: 'BOUGHT', 'FILLED_IN', 'READY_FOR_PROCESSING'" at ../vendor/coffeedesk/allegro-api-client-php/src/ObjectSerializer.php line 300

As I see in response theres event type named FULFILLMENT_STATUS_CHANGED
image

image

I've checked swagger.yaml file and found that there is that status but in different enum
image

Any solution for this? ;)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.