Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add upload order document operation #112

Merged

Conversation

mdumoulin
Copy link
Contributor

@mdumoulin mdumoulin commented Nov 15, 2023

Reason for this PR

Add upload order document operation

Out of scope

This PR contains some OOS :

  • Fixes php version used in DockerFile
  • Add composer scripts commands
  • Fixes unit tests to work with more recent version of PHPUnit

How to test

<?php
namespace ShoppingFeed\Sdk;

use Throwable;

require 'vendor/autoload.php';

// API client configuration
$apiUrl         = 'http://localhost';
$token          = '<TOKEN>';

// Order configuration
$reference   = '#1A';
$channel     = 'amazon';
$invoiceFile = '<PATH>/invoice.pdf';

$credential = new Credential\Token($token);
$options    = (new Client\ClientOptions())
    ->setBaseUri($apiUrl);

$operation = new Api\Order\OrderOperation();
$operation
    ->uploadDocument($reference, $channel, new Api\Order\Document\Invoice($invoiceFile));

try {
    $orderApi = Client\Client::createSession($credential, $options)->getMainStore()->getOrderApi();
    $orderApi->execute($operation);
} catch (Throwable $throwable) {
    echo $throwable;
}

@mdumoulin mdumoulin added the enhancement New feature or request label Nov 15, 2023
@mdumoulin mdumoulin self-assigned this Nov 15, 2023
$requests[] = $link->createRequest(
'POST',
['operation' => $type],
['order' => $chunk]
Psr7\Utils::streamFor(new Psr7\MultipartStream($body))
);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

y'aurait pas l'oubli du header ici justement ?
'Content-Type' => 'multipart/form-data',

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C'est volontaire, il est ajouté automatiquement par la librairie, ça ne fonctionne pas autrement.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

j'arrive à voir qu'en dessous, tu gères potentiellement le application/json, mais le "multipart/form-data", il est mis par défaut du coup ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C'est ajouté automatiquement par Guzzle si le body est un MultipartStream. Je pourrai d'ailleurs enlever le streamFor(), il ne sert à rien. J'avais ajouté la possibilité de définir le header dans un 1er temps car je définissais à 'multipart/form-data' au départ, mais ça ne fonctionne pas de faire comme ça.

@KevinFrydman
Copy link

Test fonctionnel ok

KevinFrydman
KevinFrydman previously approved these changes Nov 16, 2023
@mdumoulin mdumoulin merged commit 40d2020 into shoppingflux:master Nov 23, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants