From 6966127116a0d6c79aa271a6085cebfa5cd03128 Mon Sep 17 00:00:00 2001 From: Andreas Radloff Date: Thu, 4 Dec 2025 10:29:45 +0100 Subject: [PATCH] Use new refunds endpoint, accept either charge id or payment intent id --- src/Message/RefundRequest.php | 36 +++++++++++++++++++++++++++++++++-- src/Message/Response.php | 3 +++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/Message/RefundRequest.php b/src/Message/RefundRequest.php index 9668747d..f77fdfc4 100644 --- a/src/Message/RefundRequest.php +++ b/src/Message/RefundRequest.php @@ -6,6 +6,8 @@ namespace Omnipay\Stripe\Message; +use Omnipay\Stripe\Message\PaymentIntents\AbstractRequest; + /** * Stripe Refund Request. * @@ -108,9 +110,27 @@ public function setReverseTransfer($value) return $this->setParameter('reverseTransfer', $value); } + /** + * @return mixed + */ + public function getPaymentIntentReference() + { + return $this->getParameter('paymentIntentReference'); + } + + /** + * @param string $value + * + * @return AbstractRequest provides a fluent interface. + */ + public function setPaymentIntentReference($value) + { + return $this->setParameter('paymentIntentReference', $value); + } + public function getData() { - $this->validate('transactionReference', 'amount'); + $this->validate('amount'); $data = array(); $data['amount'] = $this->getAmountInteger(); @@ -123,11 +143,23 @@ public function getData() $data['reverse_transfer'] = 'true'; } + if ($this->getPaymentIntentReference()) { + $data['payment_intent'] = $this->getPaymentIntentReference(); + } + + if ($this->getTransactionReference()) { + $data['charge'] = $this->getTransactionReference(); + } + + if (!$this->getTransactionReference() && !$this->getPaymentIntentReference()) { + throw new \Omnipay\Common\Exception\InvalidRequestException('Either transactionReference or paymentIntentReference is required.'); + } + return $data; } public function getEndpoint() { - return $this->endpoint.'/charges/'.$this->getTransactionReference().'/refund'; + return $this->endpoint.'/refunds'; } } diff --git a/src/Message/Response.php b/src/Message/Response.php index 46d263c0..3c1424f9 100644 --- a/src/Message/Response.php +++ b/src/Message/Response.php @@ -96,6 +96,9 @@ public function getTransactionReference() if (isset($this->data['error']) && isset($this->data['error']['charge'])) { return $this->data['error']['charge']; } + if (isset($this->data['object']) && 'refund' === $this->data['object']) { + return $this->data['charge']; + } return null; }