-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Joe Linn
committed
Jul 28, 2014
1 parent
8a770d0
commit 6daff63
Showing
8 changed files
with
323 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
/** | ||
* User: Joe Linn | ||
* Date: 7/28/2014 | ||
* Time: 3:14 PM | ||
*/ | ||
|
||
namespace Stripe\Api; | ||
|
||
|
||
use Stripe\Request\Refunds\CreateRefundRequest; | ||
use Stripe\Response\Refunds\ListRefundsResponse; | ||
use Stripe\Response\Refunds\RefundResponse; | ||
|
||
class Refunds extends AbstractApi | ||
{ | ||
const REFUND_RESPONSE_CLASS = 'Stripe\Response\Refunds\RefundResponse'; | ||
const LIST_REFUNDS_RESPONSE_CLASS = 'Stripe\Response\Refunds\ListRefundsResponse'; | ||
|
||
/** | ||
* Create a refund | ||
* @param string $chargeId | ||
* @param CreateRefundRequest $request | ||
* @return RefundResponse | ||
* @link https://stripe.com/docs/api#create_refund | ||
*/ | ||
public function createRefund($chargeId, CreateRefundRequest $request = null) | ||
{ | ||
return $this->client->post($this->buildUrl($chargeId), self::REFUND_RESPONSE_CLASS, $request); | ||
} | ||
|
||
/** | ||
* Retrieve a refund | ||
* @param string $chargeId | ||
* @param string $refundId | ||
* @return RefundResponse | ||
* @link https://stripe.com/docs/api#retrieve_refund | ||
*/ | ||
public function getRefund($chargeId, $refundId) | ||
{ | ||
return $this->client->get($this->buildUrl($chargeId, $refundId), self::REFUND_RESPONSE_CLASS); | ||
} | ||
|
||
/** | ||
* Update a refund | ||
* @param string $chargeId | ||
* @param string $refundId | ||
* @param array $metadata | ||
* @return RefundResponse | ||
* @link https://stripe.com/docs/api#update_refund | ||
*/ | ||
public function updateRefund($chargeId, $refundId, array $metadata) | ||
{ | ||
return $this->client->post($this->buildUrl($chargeId, $refundId), self::REFUND_RESPONSE_CLASS, array('metadata' => $metadata)); | ||
} | ||
|
||
/** | ||
* List refunds associated with the given charge | ||
* @param string $chargeId | ||
* @param int $limit | ||
* @param string $startingAfter | ||
* @param string $endingBefore | ||
* @return ListRefundsResponse | ||
* @link https://stripe.com/docs/api#list_refunds | ||
*/ | ||
public function listRefunds($chargeId, $limit = 10, $startingAfter = null, $endingBefore = null) | ||
{ | ||
return $this->client->get($this->buildUrl($chargeId), self::LIST_REFUNDS_RESPONSE_CLASS, null, array( | ||
"ending_before" => $endingBefore, | ||
"starting_after" => $startingAfter, | ||
"limit" => $limit | ||
)); | ||
} | ||
|
||
/** | ||
* Build a URL for a refund request | ||
* @param string $chargeId | ||
* @param string $refundId | ||
* @return string | ||
*/ | ||
protected function buildUrl($chargeId, $refundId = null) | ||
{ | ||
$url = "charges/" . $chargeId . "/refunds"; | ||
if (!is_null($refundId)) { | ||
$url .= "/" . $refundId; | ||
} | ||
return $url; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
/** | ||
* User: Joe Linn | ||
* Date: 7/28/2014 | ||
* Time: 3:13 PM | ||
*/ | ||
|
||
namespace Stripe\Request\Refunds; | ||
|
||
|
||
class CreateRefundRequest | ||
{ | ||
/** | ||
* @var int | ||
*/ | ||
protected $amount; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
protected $refundApplicationFee; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $metadata; | ||
|
||
/** | ||
* @param int $amount | ||
* @return $this | ||
*/ | ||
public function setAmount($amount) | ||
{ | ||
$this->amount = $amount; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @param array $metadata | ||
* @return $this | ||
*/ | ||
public function setMetadata($metadata) | ||
{ | ||
$this->metadata = $metadata; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @param boolean $refundApplicationFee | ||
* @return $this | ||
*/ | ||
public function setRefundApplicationFee($refundApplicationFee) | ||
{ | ||
$this->refundApplicationFee = $refundApplicationFee; | ||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.