CancelData.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace App\Models\DTO\Toss;
  3. use Illuminate\Contracts\Support\Arrayable;
  4. // https://docs.tosspayments.com/reference#v1paymentspaymentkeycancelpost-cancelreason
  5. class CancelData implements Arrayable
  6. {
  7. public string $cancelReason; // 결제를 취소하는 이유입니다.
  8. public int $cancelAmount; // 취소할 금액입니다. 값이 없으면 전액 취소됩니다.
  9. public ?array $refundReceiveAccount; // 결제 취소 후 금액이 환불될 계좌의 정보입니다.
  10. public int $taxFreeAmount; // 취소할 금액 중 면세 금액입니다.
  11. public function __construct()
  12. {
  13. $this->cancelReason = "";
  14. $this->cancelAmount = 0;
  15. $this->refundReceiveAccount = null;
  16. $this->taxFreeAmount = 0;
  17. }
  18. public function toArray(): array
  19. {
  20. $result = [
  21. 'cancelReason' => $this->cancelReason
  22. ];
  23. if($this->cancelAmount) {
  24. $result['cancelAmount'] = $this->cancelAmount;
  25. }
  26. if($this->refundReceiveAccount) {
  27. $result['refundReceiveAccount'] = $this->refundReceiveAccount;
  28. }
  29. if($this->taxFreeAmount) {
  30. $result['taxFreeAmount'] = $this->taxFreeAmount;
  31. }
  32. return $result;
  33. }
  34. public function toString(): string|false
  35. {
  36. return serialize($this->toArray());
  37. }
  38. }