Skip to content

Commit

Permalink
Merge pull request #7 from rushi/XOL-3125
Browse files Browse the repository at this point in the history
Support `reverse_transfer` flag for Stripe Connect refunds
  • Loading branch information
rushi authored Sep 30, 2016
2 parents a03983f + 3aebd9b commit 066e101
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/Message/RefundRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,31 @@ public function setRefundApplicationFee($value)
return $this->setParameter('refundApplicationFee', $value);
}

/**
* @return bool Whether the charge transfer should be reversed
*/
public function getReverseTransfer()
{
return $this->getParameter('reverseTransfer');
}

/**
* Whether to reverse the transfer associated with the charge.
*
* When refunding a charge that has a destination value, by default the destination account will keep the funds that
* were transferred to it, leaving the platform account to cover the negative balance from the refund. To pull back
* the funds from the connected account to cover the refund, set the reverse_transfer parameter to true when
* creating the refund
*
* @param bool $value Whether the transfer should be reversed or not
*
* @return \Omnipay\Common\Message\AbstractRequest
*/
public function setReverseTransfer($value)
{
return $this->setParameter('reverseTransfer', $value);
}

public function getData()
{
$this->validate('transactionReference', 'amount');
Expand All @@ -89,6 +114,10 @@ public function getData()
$data['refund_application_fee'] = 'true';
}

if ($this->getReverseTransfer()) {
$data['reverse_transfer'] = 'true';
}

return $data;
}

Expand Down
13 changes: 13 additions & 0 deletions tests/Message/RefundRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

class RefundRequestTest extends TestCase
{
/** @var RefundRequest $request */
private $request;

public function setUp()
{
$this->request = new RefundRequest($this->getHttpClient(), $this->getHttpRequest());
Expand All @@ -30,6 +33,16 @@ public function testRefundApplicationFee()
$this->assertEquals("true", $data['refund_application_fee']);
}

public function testShouldSetReverseTransferFlag()
{
$this->request->setTransactionReference('ch_12RgN9L7XhO9mI')->setAmount('10.00');
$this->request->setReverseTransfer(true);

$data = $this->request->getData();

$this->assertEquals("true", $data['reverse_transfer']);
}

public function testSendSuccess()
{
$this->setMockHttpResponse('RefundSuccess.txt');
Expand Down

0 comments on commit 066e101

Please sign in to comment.