1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Helix\Shopify\Order; |
4
|
|
|
|
5
|
|
|
use Helix\Shopify\Base\AbstractEntity; |
6
|
|
|
use Helix\Shopify\Base\AbstractEntity\CreateTrait; |
7
|
|
|
use Helix\Shopify\Base\AbstractEntity\ImmutableInterface; |
8
|
|
|
use Helix\Shopify\Order; |
9
|
|
|
use Helix\Shopify\Order\Refund\Adjustment; |
10
|
|
|
use Helix\Shopify\Order\Refund\RefundItem; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* A refund. |
14
|
|
|
* |
15
|
|
|
* @immutable Refunds can only be created. |
16
|
|
|
* |
17
|
|
|
* @see https://help.shopify.com/en/api/reference/orders/refund |
18
|
|
|
* |
19
|
|
|
* @method $this setCurrency (string $currency) @depends create-only |
20
|
|
|
* @method $this setDiscrepancyReason (string $reason) @depends create-only |
21
|
|
|
* @method $this setNote (string $note) @depends create-only |
22
|
|
|
* @method $this setNotify (bool $notify) @depends create-only |
23
|
|
|
* @method $this setProcessedAt (string $iso8601) @depends create-only |
24
|
|
|
* @method $this setRefundLineItems (RefundItem[] $items) @depends create-only |
25
|
|
|
* @method $this setTransactions (Transaction[] $transactions) @depends create-only |
26
|
|
|
* @method $this setUserId (string $id) @depends create-only |
27
|
|
|
* |
28
|
|
|
* @method string getCreatedAt () |
29
|
|
|
* @method string getId () |
30
|
|
|
* @method string getNote () |
31
|
|
|
* @method Adjustment[] getOrderAdjustments () |
32
|
|
|
* @method string getProcessedAt () |
33
|
|
|
* @method RefundItem[] getRefundLineItems () |
34
|
|
|
* @method Transaction[] getTransactions () |
35
|
|
|
* @method string getUserId () |
36
|
|
|
* |
37
|
|
|
* @method bool hasOrderAdjustments () |
38
|
|
|
* @method bool hasRefundLineItems () |
39
|
|
|
* @method bool hasTransactions () |
40
|
|
|
*/ |
41
|
|
|
class Refund extends AbstractEntity implements ImmutableInterface |
42
|
|
|
{ |
43
|
|
|
|
44
|
|
|
use CreateTrait; |
45
|
|
|
|
46
|
|
|
const TYPE = 'refund'; |
47
|
|
|
const DIR = 'refunds'; |
48
|
|
|
|
49
|
|
|
const REASON_CUSTOMER = 'customer'; |
50
|
|
|
const REASON_DAMAGE = 'damage'; |
51
|
|
|
const REASON_OTHER = 'other'; |
52
|
|
|
const REASON_RESTOCK = 'restock'; |
53
|
|
|
|
54
|
|
|
const MAP = [ |
55
|
|
|
'order_adjustments' => [Adjustment::class], |
56
|
|
|
'refund_line_items' => [RefundItem::class], |
57
|
|
|
'transactions' => [Transaction::class] |
58
|
|
|
]; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var Order |
62
|
|
|
*/ |
63
|
|
|
protected $order; |
64
|
|
|
|
65
|
|
|
public function __construct(Order $order, array $data = []) |
66
|
|
|
{ |
67
|
|
|
$this->order = $order; |
68
|
|
|
parent::__construct($order, $data); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
protected function _container() |
72
|
|
|
{ |
73
|
|
|
return $this->order; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @return Order |
78
|
|
|
*/ |
79
|
|
|
public function getOrder() |
80
|
|
|
{ |
81
|
|
|
return Order::load($this, $this->order->getId()); |
|
|
|
|
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @return RefundItem |
86
|
|
|
*/ |
87
|
|
|
public function newItem() |
88
|
|
|
{ |
89
|
|
|
return $this->api->factory($this, RefundItem::class); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return Transaction |
94
|
|
|
*/ |
95
|
|
|
public function newTransaction() |
96
|
|
|
{ |
97
|
|
|
return $this->api->factory($this, Transaction::class, [ |
98
|
|
|
'kind' => Transaction::KIND_REFUND |
99
|
|
|
]); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @depends create-only |
104
|
|
|
* @return $this |
105
|
|
|
*/ |
106
|
|
|
public function setFullShipping() |
107
|
|
|
{ |
108
|
|
|
return $this->_set('shipping', ['full_refund' => true]); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @depends create-only |
113
|
|
|
* @param string $amount |
114
|
|
|
* @return $this |
115
|
|
|
*/ |
116
|
|
|
public function setShippingAmount(string $amount) |
117
|
|
|
{ |
118
|
|
|
return $this->_set('shipping', ['amount' => $amount]); |
119
|
|
|
} |
120
|
|
|
} |