|
| 1 | +<?php |
| 2 | +/* |
| 3 | + * Since 2007 PayPal |
| 4 | + * |
| 5 | + * NOTICE OF LICENSE |
| 6 | + * |
| 7 | + * This source file is subject to the Academic Free License (AFL 3.0) |
| 8 | + * that is bundled with this package in the file LICENSE.txt. |
| 9 | + * It is also available through the world-wide-web at this URL: |
| 10 | + * http://opensource.org/licenses/afl-3.0.php |
| 11 | + * If you did not receive a copy of the license and are unable to |
| 12 | + * obtain it through the world-wide-web, please send an email |
| 13 | + * to license@prestashop.com so we can send you a copy immediately. |
| 14 | + * |
| 15 | + * DISCLAIMER |
| 16 | + * |
| 17 | + * Do not edit or add to this file if you wish to upgrade PrestaShop to newer |
| 18 | + * versions in the future. If you wish to customize PrestaShop for your |
| 19 | + * needs please refer to http://www.prestashop.com for more information. |
| 20 | + * |
| 21 | + * @author Since 2007 PayPal |
| 22 | + * @author 202 ecommerce <tech@202-ecommerce.com> |
| 23 | + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
| 24 | + * @copyright PayPal |
| 25 | + * |
| 26 | + */ |
| 27 | + |
| 28 | +namespace PaypalAddons\classes\API\ExtensionSDK\Order; |
| 29 | + |
| 30 | +use PaypalAddons\classes\API\HttpAdoptedResponse; |
| 31 | +use PaypalAddons\classes\API\HttpResponse; |
| 32 | +use PaypalAddons\classes\API\Request\HttpRequestInterface; |
| 33 | +use PaypalAddons\classes\API\WrapperInterface; |
| 34 | +use PaypalAddons\services\Builder\BuilderInterface; |
| 35 | +use PaypalOrder; |
| 36 | + |
| 37 | +if (!defined('_PS_VERSION_')) { |
| 38 | + exit; |
| 39 | +} |
| 40 | + |
| 41 | +class OrdersAddTrackingInfoRequest implements HttpRequestInterface, WrapperInterface |
| 42 | +{ |
| 43 | + protected $headers = []; |
| 44 | + /** @var BuilderInterface */ |
| 45 | + protected $bodyBuilder; |
| 46 | + /** @var PaypalOrder */ |
| 47 | + protected $paypalOrder; |
| 48 | + |
| 49 | + public function __construct(PaypalOrder $paypalOrder, BuilderInterface $bodyBuilder) |
| 50 | + { |
| 51 | + $this->headers['Content-Type'] = 'application/json'; |
| 52 | + $this->bodyBuilder = $bodyBuilder; |
| 53 | + $this->paypalOrder = $paypalOrder; |
| 54 | + } |
| 55 | + |
| 56 | + public function getPath() |
| 57 | + { |
| 58 | + return sprintf( |
| 59 | + '/v2/checkout/orders/%s/track', |
| 60 | + $this->getOrderId() |
| 61 | + ); |
| 62 | + } |
| 63 | + |
| 64 | + /** @return array*/ |
| 65 | + public function getHeaders() |
| 66 | + { |
| 67 | + return $this->headers; |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * @param array $headers |
| 72 | + * |
| 73 | + * @return self |
| 74 | + */ |
| 75 | + public function setHeaders($headers) |
| 76 | + { |
| 77 | + if (is_array($headers)) { |
| 78 | + $this->headers = $headers; |
| 79 | + } |
| 80 | + |
| 81 | + return $this; |
| 82 | + } |
| 83 | + |
| 84 | + public function getBody() |
| 85 | + { |
| 86 | + $body = $this->bodyBuilder->build(); |
| 87 | + |
| 88 | + if (is_array($body)) { |
| 89 | + $body = json_encode($body); |
| 90 | + } |
| 91 | + |
| 92 | + return $body; |
| 93 | + } |
| 94 | + |
| 95 | + public function getMethod() |
| 96 | + { |
| 97 | + return 'POST'; |
| 98 | + } |
| 99 | + |
| 100 | + public function wrap($object) |
| 101 | + { |
| 102 | + if ($object instanceof HttpResponse) { |
| 103 | + return new HttpAdoptedResponse($object); |
| 104 | + } |
| 105 | + |
| 106 | + return $object; |
| 107 | + } |
| 108 | + |
| 109 | + protected function getOrderId() |
| 110 | + { |
| 111 | + return $this->paypalOrder->id_payment; |
| 112 | + } |
| 113 | +} |
0 commit comments