|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace BigCommerce\ApiV3\Orders; |
| 4 | + |
| 5 | +use BigCommerce\ApiV3\Api\V3ApiBase; |
| 6 | +use BigCommerce\ApiV3\ResourceModels\Order\OrderRefundItem; |
| 7 | +use BigCommerce\ApiV3\ResponseModels\Order\RefundQuoteResponse; |
| 8 | +use BigCommerce\ApiV3\ResponseModels\Order\RefundResponse; |
| 9 | +use BigCommerce\ApiV3\ResponseModels\Order\RefundsResponse; |
| 10 | +use GuzzleHttp\RequestOptions; |
| 11 | + |
| 12 | +class RefundsApi extends V3ApiBase |
| 13 | +{ |
| 14 | + private const ORDER_REFUNDS_ENDPOINT = 'orders/%d/payment_actions'; |
| 15 | + private const REFUND_QUOTE_ENDPOINT = self::ORDER_REFUNDS_ENDPOINT . '/refund_quotes'; |
| 16 | + private const REFUND_ENDPOINT = self::ORDER_REFUNDS_ENDPOINT . '/refunds'; |
| 17 | + |
| 18 | + /** |
| 19 | + * @param OrderRefundItem[] $items |
| 20 | + * @param string $reason |
| 21 | + * @return RefundResponse |
| 22 | + * @throws \GuzzleHttp\Exception\GuzzleException |
| 23 | + */ |
| 24 | + public function create(array $items, string $reason): RefundResponse |
| 25 | + { |
| 26 | + $response = $this->getClient()->getRestClient()->post( |
| 27 | + sprintf(self::REFUND_ENDPOINT, $this->getParentResourceId()), |
| 28 | + [ |
| 29 | + RequestOptions::JSON => [] |
| 30 | + ] |
| 31 | + ); |
| 32 | + |
| 33 | + return new RefundResponse($response); |
| 34 | + } |
| 35 | + |
| 36 | + public function createQuote(): RefundQuoteResponse |
| 37 | + { |
| 38 | + $response = $this->getClient()->getRestClient()->post( |
| 39 | + sprintf(self::REFUND_QUOTE_ENDPOINT, $this->getParentResourceId()), |
| 40 | + [ |
| 41 | + RequestOptions::JSON => [] |
| 42 | + ] |
| 43 | + ); |
| 44 | + |
| 45 | + return new RefundQuoteResponse($response); |
| 46 | + } |
| 47 | + |
| 48 | + public function getAll(): RefundsResponse |
| 49 | + { |
| 50 | + $response = $this->getClient()->getRestClient()->get( |
| 51 | + sprintf(self::REFUND_ENDPOINT, $this->getParentResourceId()) |
| 52 | + ); |
| 53 | + |
| 54 | + return new RefundsResponse($response); |
| 55 | + } |
| 56 | +} |
0 commit comments