-
Notifications
You must be signed in to change notification settings - Fork 858
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #989 from stripe/remi/codegen-f71053e
Add support for the `PromotionCode` resource and APIs
- Loading branch information
Showing
15 changed files
with
269 additions
and
9 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
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,33 @@ | ||
<?php | ||
|
||
// File generated from our OpenAPI spec | ||
|
||
namespace Stripe; | ||
|
||
/** | ||
* A Promotion Code represents a customer-redeemable code for a coupon. It can be | ||
* used to create multiple codes for a single coupon. | ||
* | ||
* @property string $id Unique identifier for the object. | ||
* @property string $object String representing the object's type. Objects of the same type share the same value. | ||
* @property bool $active Whether the promotion code is currently active. A promotion code is only active if the coupon is also valid. | ||
* @property string $code The customer-facing code. Regardless of case, this code must be unique across all active promotion codes for each customer. | ||
* @property \Stripe\Coupon $coupon A coupon contains information about a percent-off or amount-off discount you might want to apply to a customer. Coupons may be applied to <a href="https://stripe.com/docs/api#invoices">invoices</a> or <a href="https://stripe.com/docs/api#create_order-coupon">orders</a>. Coupons do not work with conventional one-off <a href="https://stripe.com/docs/api#create_charge">charges</a>. | ||
* @property int $created Time at which the object was created. Measured in seconds since the Unix epoch. | ||
* @property null|string|\Stripe\Customer $customer The customer that this promotion code can be used by. | ||
* @property null|int $expires_at Date at which the promotion code can no longer be redeemed. | ||
* @property bool $livemode Has the value <code>true</code> if the object exists in live mode or the value <code>false</code> if the object exists in test mode. | ||
* @property null|int $max_redemptions Maximum number of times this promotion code can be redeemed. | ||
* @property \Stripe\StripeObject $metadata Set of <a href="https://stripe.com/docs/api/metadata">key-value pairs</a> that you can attach to an object. This can be useful for storing additional information about the object in a structured format. | ||
* @property \Stripe\StripeObject $restrictions | ||
* @property int $times_redeemed Number of times this promotion code has been used. | ||
*/ | ||
class PromotionCode extends ApiResource | ||
{ | ||
const OBJECT_NAME = 'promotion_code'; | ||
|
||
use ApiOperations\All; | ||
use ApiOperations\Create; | ||
use ApiOperations\Retrieve; | ||
use ApiOperations\Update; | ||
} |
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,72 @@ | ||
<?php | ||
|
||
// File generated from our OpenAPI spec | ||
|
||
namespace Stripe\Service; | ||
|
||
class PromotionCodeService extends \Stripe\Service\AbstractService | ||
{ | ||
/** | ||
* Returns a list of your promotion codes. | ||
* | ||
* @param null|array $params | ||
* @param null|array|\Stripe\Util\RequestOptions $opts | ||
* | ||
* @throws \Stripe\Exception\ApiErrorException if the request fails | ||
* | ||
* @return \Stripe\Collection | ||
*/ | ||
public function all($params = null, $opts = null) | ||
{ | ||
return $this->requestCollection('get', '/v1/promotion_codes', $params, $opts); | ||
} | ||
|
||
/** | ||
* A promotion code points to a coupon. You can optionally restrict the code to a | ||
* specific customer, redemption limit, and expiration date. | ||
* | ||
* @param null|array $params | ||
* @param null|array|\Stripe\Util\RequestOptions $opts | ||
* | ||
* @throws \Stripe\Exception\ApiErrorException if the request fails | ||
* | ||
* @return \Stripe\PromotionCode | ||
*/ | ||
public function create($params = null, $opts = null) | ||
{ | ||
return $this->request('post', '/v1/promotion_codes', $params, $opts); | ||
} | ||
|
||
/** | ||
* Retrieves the promotion code with the given ID. | ||
* | ||
* @param string $id | ||
* @param null|array $params | ||
* @param null|array|\Stripe\Util\RequestOptions $opts | ||
* | ||
* @throws \Stripe\Exception\ApiErrorException if the request fails | ||
* | ||
* @return \Stripe\PromotionCode | ||
*/ | ||
public function retrieve($id, $params = null, $opts = null) | ||
{ | ||
return $this->request('get', $this->buildPath('/v1/promotion_codes/%s', $id), $params, $opts); | ||
} | ||
|
||
/** | ||
* Updates the specified promotion code by setting the values of the parameters | ||
* passed. Most fields are, by design, not editable. | ||
* | ||
* @param string $id | ||
* @param null|array $params | ||
* @param null|array|\Stripe\Util\RequestOptions $opts | ||
* | ||
* @throws \Stripe\Exception\ApiErrorException if the request fails | ||
* | ||
* @return \Stripe\PromotionCode | ||
*/ | ||
public function update($id, $params = null, $opts = null) | ||
{ | ||
return $this->request('post', $this->buildPath('/v1/promotion_codes/%s', $id), $params, $opts); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
namespace Stripe; | ||
|
||
/** | ||
* @internal | ||
* @covers \Stripe\PromotionCode | ||
*/ | ||
final class PromotionCodeTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
use TestHelper; | ||
|
||
const TEST_RESOURCE_ID = 'promo_123'; | ||
|
||
public function testIsListable() | ||
{ | ||
$this->expectsRequest( | ||
'get', | ||
'/v1/promotion_codes' | ||
); | ||
$resources = PromotionCode::all(); | ||
static::assertInternalType('array', $resources->data); | ||
static::assertInstanceOf(\Stripe\PromotionCode::class, $resources->data[0]); | ||
} | ||
|
||
public function testIsRetrievable() | ||
{ | ||
$this->expectsRequest( | ||
'get', | ||
'/v1/promotion_codes/' . self::TEST_RESOURCE_ID | ||
); | ||
$resource = PromotionCode::retrieve(self::TEST_RESOURCE_ID); | ||
static::assertInstanceOf(\Stripe\PromotionCode::class, $resource); | ||
} | ||
|
||
public function testIsCreatable() | ||
{ | ||
$this->expectsRequest( | ||
'post', | ||
'/v1/promotion_codes' | ||
); | ||
$resource = PromotionCode::create([ | ||
'coupon' => 'co_123', | ||
'code' => 'MYCODE', | ||
]); | ||
static::assertInstanceOf(\Stripe\PromotionCode::class, $resource); | ||
} | ||
|
||
public function testIsSaveable() | ||
{ | ||
$resource = PromotionCode::retrieve(self::TEST_RESOURCE_ID); | ||
$resource->metadata['key'] = 'value'; | ||
$this->expectsRequest( | ||
'post', | ||
'/v1/promotion_codes/' . self::TEST_RESOURCE_ID | ||
); | ||
$resource->save(); | ||
static::assertInstanceOf(\Stripe\PromotionCode::class, $resource); | ||
} | ||
|
||
public function testIsUpdatable() | ||
{ | ||
$this->expectsRequest( | ||
'post', | ||
'/v1/promotion_codes/' . self::TEST_RESOURCE_ID | ||
); | ||
$resource = PromotionCode::update(self::TEST_RESOURCE_ID, [ | ||
'metadata' => ['key' => 'value'], | ||
]); | ||
static::assertInstanceOf(\Stripe\PromotionCode::class, $resource); | ||
} | ||
} |
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,75 @@ | ||
<?php | ||
|
||
namespace Stripe\Service; | ||
|
||
/** | ||
* @internal | ||
* @covers \Stripe\Service\PromotionCodeService | ||
*/ | ||
final class PromotionCodeServiceTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
use \Stripe\TestHelper; | ||
|
||
const TEST_RESOURCE_ID = 'promo_123'; | ||
|
||
/** @var \Stripe\StripeClient */ | ||
private $client; | ||
|
||
/** @var PromotionCodeService */ | ||
private $service; | ||
|
||
/** | ||
* @before | ||
*/ | ||
protected function setUpService() | ||
{ | ||
$this->client = new \Stripe\StripeClient(['api_key' => 'sk_test_123', 'api_base' => MOCK_URL]); | ||
$this->service = new PromotionCodeService($this->client); | ||
} | ||
|
||
public function testAll() | ||
{ | ||
$this->expectsRequest( | ||
'get', | ||
'/v1/promotion_codes' | ||
); | ||
$resources = $this->service->all(); | ||
static::assertInternalType('array', $resources->data); | ||
static::assertInstanceOf(\Stripe\PromotionCode::class, $resources->data[0]); | ||
} | ||
|
||
public function testCreate() | ||
{ | ||
$this->expectsRequest( | ||
'post', | ||
'/v1/promotion_codes' | ||
); | ||
$resource = $this->service->create([ | ||
'coupon' => 'co_123', | ||
'code' => 'MYCODE', | ||
]); | ||
static::assertInstanceOf(\Stripe\PromotionCode::class, $resource); | ||
} | ||
|
||
public function testRetrieve() | ||
{ | ||
$this->expectsRequest( | ||
'get', | ||
'/v1/promotion_codes/' . self::TEST_RESOURCE_ID | ||
); | ||
$resource = $this->service->retrieve(self::TEST_RESOURCE_ID); | ||
static::assertInstanceOf(\Stripe\PromotionCode::class, $resource); | ||
} | ||
|
||
public function testUpdate() | ||
{ | ||
$this->expectsRequest( | ||
'post', | ||
'/v1/promotion_codes/' . self::TEST_RESOURCE_ID | ||
); | ||
$resource = $this->service->update(self::TEST_RESOURCE_ID, [ | ||
'metadata' => ['key' => 'value'], | ||
]); | ||
static::assertInstanceOf(\Stripe\PromotionCode::class, $resource); | ||
} | ||
} |
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