Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions src/Message/RefundRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

namespace Omnipay\Stripe\Message;

use Omnipay\Stripe\Message\PaymentIntents\AbstractRequest;

/**
* Stripe Refund Request.
*
Expand Down Expand Up @@ -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();
Expand All @@ -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';
}
}
3 changes: 3 additions & 0 deletions src/Message/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down