forked from stripe/stripe-php
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
dc9a5c7
commit 9fec0f7
Showing
6 changed files
with
97 additions
and
0 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
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,36 @@ | ||
<?php | ||
|
||
class Stripe_Refund extends Stripe_ApiResource | ||
{ | ||
/** | ||
* @return string The API URL for this Stripe refund. | ||
*/ | ||
public function instanceUrl() | ||
{ | ||
$id = $this['id']; | ||
$charge = $this['charge']; | ||
if (!$id) { | ||
throw new Stripe_InvalidRequestError( | ||
"Could not determine which URL to request: " . | ||
"class instance has invalid ID: $id", | ||
null | ||
); | ||
} | ||
$id = Stripe_ApiRequestor::utf8($id); | ||
$charge = Stripe_ApiRequestor::utf8($charge); | ||
|
||
$base = self::classUrl('Stripe_Charge'); | ||
$chargeExtn = urlencode($charge); | ||
$extn = urlencode($id); | ||
return "$base/$chargeExtn/refunds/$extn"; | ||
} | ||
|
||
/** | ||
* @return Stripe_Refund The saved refund. | ||
*/ | ||
public function save() | ||
{ | ||
$class = get_class(); | ||
return self::_scopedSave($class); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
class Stripe_RefundTest extends StripeTestCase | ||
{ | ||
|
||
public function testCreate() | ||
{ | ||
$charge = self::createTestCharge(); | ||
$ref = $charge->refunds->create(array('amount' => 100)); | ||
$this->assertEqual(100, $ref->amount); | ||
$this->assertEqual($charge->id, $ref->charge); | ||
} | ||
|
||
public function testUpdateAndRetrieve() | ||
{ | ||
$charge = self::createTestCharge(); | ||
$ref = $charge->refunds->create(array('amount' => 100)); | ||
$ref->metadata["key"] = "value"; | ||
$ref->save(); | ||
$ref = $charge->refunds->retrieve($ref->id); | ||
$this->assertEqual("value", $ref->metadata["key"], "value"); | ||
} | ||
|
||
public function testList() | ||
{ | ||
$charge = self::createTestCharge(); | ||
$refA = $charge->refunds->create(array('amount' => 50)); | ||
$refB = $charge->refunds->create(array('amount' => 50)); | ||
|
||
$all = $charge->refunds->all(); | ||
$this->assertEqual(false, $all->has_more); | ||
$this->assertEqual(2, count($all->data)); | ||
$this->assertEqual($refA->id, $all->data[0]->id); | ||
$this->assertEqual($refB->id, $all->data[1]->id); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -7,6 +7,28 @@ | |
abstract class StripeTestCase extends UnitTestCase | ||
{ | ||
|
||
/** | ||
* Create a valid test charge. | ||
*/ | ||
protected static function createTestCharge(array $attributes = array()) | ||
{ | ||
authorizeFromEnv(); | ||
|
||
return Stripe_Charge::create( | ||
$attributes + array( | ||
"amount" => 2000, | ||
"currency" => "usd", | ||
"description" => "Charge for [email protected]", | ||
'card' => array( | ||
'number' => '4242424242424242', | ||
'exp_month' => 5, | ||
'exp_year' => date('Y') + 3, | ||
), | ||
) | ||
); | ||
} | ||
|
||
|
||
/** | ||
* Create a valid test customer. | ||
*/ | ||
|