Skip to content

Commit

Permalink
Merge pull request #11 from srishaharidas/XOL-3591
Browse files Browse the repository at this point in the history
XOL-3591 Store balance_transaction in remoteData for Stripe refunds
  • Loading branch information
anush authored Aug 1, 2017
2 parents 0697e5f + b08971f commit c0c8187
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/Message/RefundRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,17 @@ public function getData()

public function getEndpoint()
{
return $this->endpoint.'/charges/'.$this->getTransactionReference().'/refund';
$endPoint = $this->endpoint.'/charges/'.$this->getTransactionReference().'/refund';
$expandParams = $this->getExpand();
if ($expandParams && is_array($expandParams)) {
$endPoint = $endPoint . '?';
foreach ($expandParams as $idx => $param) {
$endPoint .= "expand[]=" . urlencode($param);
if ($idx !== count($expandParams) - 1) {
$endPoint .= "&";
}
}
}
return $endPoint;
}
}
23 changes: 23 additions & 0 deletions tests/Message/RefundRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,27 @@ public function testSendError()
$this->assertNull($response->getCardReference());
$this->assertSame('Charge ch_12RgN9L7XhO9mI has already been refunded.', $response->getMessage());
}

public function testShouldReturnEndpointWhenExpandParamNotPresent()
{
$endPoint = $this->request->getEndpoint();

$this->assertEquals("https://api.stripe.com/v1/charges/ch_12RgN9L7XhO9mI/refund", $endPoint);
}

public function testShouldAppendExpandQueryParamsToEndpointIfPresent()
{
$this->request->initialize(
array(
'amount' => '10.00',
'transactionReference' => "ch_12RgN9L7XhO9mI",
'expand' => array('foo', 'bar')
)
);
$expected ="https://api.stripe.com/v1/charges/ch_12RgN9L7XhO9mI/refund?expand[]=foo&expand[]=bar";

$endPoint = $this->request->getEndpoint();

$this->assertEquals($expected, $endPoint);
}
}

0 comments on commit c0c8187

Please sign in to comment.