dev-master
9999999-devA Symfony service in order to interact with the Pwinty API
MIT
The Requires
- php >=5.5.9
- pwinty/php-pwinty dev-api_2.3
The Development Requires
by Buendon
symfony print pwinty
A Symfony service in order to interact with the Pwinty API
This Symfony Bundle propose a service to communicate with the Pwinty API., (*1)
It uses the simple PHP implementation from php-pwinty and adds on top of it: * An oriented-object API * A Symfony service that can be used in a Symfony project., (*2)
Warning: This bundle still in construction, hence there is no official release yet., (*3)
Update your composer.json in your Symfony project:, (*4)
"repositories" : [{ "type": "vcs", "url": "https://github.com/Buendon/php-pwinty" }], ... "require": { ... "pwinty/php-pwinty" : "dev-api_2.3", "buendon/pwinty-bundle": "dev-master" }, ...
Update your AppKernel.php
, (*5)
// ... new \Buendon\PwintyBundle\BuendonPwintyBundle(), // ...
Then, run composer update buendon/pwinty-bundle pwinty/php-pwinty
, (*6)
Note that you need to declare a specific GitHub repository for the php-pwinty bundle., (*7)
Indeed, this one is a fork of Pwinty/php-pwinty., (*8)
A push request needs to be sent to the original one in order for it to be compatible with the 2.3 version of the Pwinty API., (*9)
This will be done when this module will be released., (*10)
Edit your config.yml
file and add this:, (*11)
buendon_pwinty: apiType: 'sandbox' merchantId: 'yourPwintyMerchantId' apiKey: 'yourPwintyAPIKey'
The apiType
can take the following values:
* sandbox
* production, (*12)
This will be used to configure the Pwinty URL for the requests., (*13)
As it is stated in the Pwinty documentation, the tests and developments must be done with the sandbox apiType
if you don't want to be billed with the submitted orders., (*14)
<?php use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Buendon\PwintyBundle\Catalogue\Catalogue; use Buendon\PwintyBundle\Order\OrderException; use Buendon\PwintyBundle\Order\Photo; use Buendon\PwintyBundle\Service\PwintyService; use Buendon\PwintyBundle\Order\Order; class OrderController extends Controller { public function createOrderAction() { $service = $this->container->get(PwintyService::NAME); $order = new Order(); $order->setRecipientName("Chuck Norris"); $order->setAddress1("123 Some Road"); $order->setAddress2("Some place"); $order->setAddressTownOrCity("Some town"); $order->setStateOrCounty("Some state"); $order->setPostalOrZipCode("12345"); $order->setCountryCode("FR"); $order->setDestinationCountryCode("FR"); $order->setPayment(Order::PAYMENT_INVOICE_ME); $order->setQualityLevel(Catalogue::QUALITY_STANDARD); try { $response = $service->createOrder($order); } catch (OrderException $e) { // If the call fails, it will throw an exception // Handle here the error } // The response will give you the order Id you can use to track it within the Pwinty API $response->getId(); } public function getOrderDetailsAction() { $orderId = '12357'; $service = $this->container->get(PwintyService::NAME); try { $order = $service->getOrder($orderId); } catch (OrderException $e) { // If the call fails, it will throw an exception // Handle here the error } } public function getOrderSubmissionStatusAction() { $orderId = '12357'; $service = $this->container->get(PwintyService::NAME); try { // Give the Submision status // See Pwinty documentation for details $submissionStatus = $service->getOrderSubmissionStatus($orderId); } catch (OrderException $e) { // If the call fails, it will throw an exception // Handle here the error } } public function addPhotoToOrderAction() { $orderId = '12357'; $service = $this->container->get(PwintyService::NAME); $photo = new Photo(); $photo->setType('9x12_cm'); $photo->setSizing(Photo::SIZING_CROP); $photo->setCopies(10); $photo->setFile("Path/to/the/picture"); try { $service->addPhoto($orderId, $photo); } catch (OrderException $e) { // If the call fails, it will throw an exception // Handle here the error } } public function submitOrderAction() { // Once you have added all the pictures, you need to submit the order $orderId = '12357'; $service = $this->container->get(PwintyService::NAME); try { $service->updateOrderStatus($orderId, Order::UPDATE_STATUS_SUBMITTED); } catch (OrderException $e) { // If the call fails, it will throw an exception // Handle here the error } } }
A Symfony service in order to interact with the Pwinty API
MIT
symfony print pwinty