本文整理汇总了PHP中Coupon::create方法的典型用法代码示例。如果您正苦于以下问题:PHP Coupon::create方法的具体用法?PHP Coupon::create怎么用?PHP Coupon::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Coupon
的用法示例。
在下文中一共展示了Coupon::create方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSave
public function testSave()
{
self::authorizeFromEnv();
$id = 'test_coupon-' . self::randomString();
$c = Coupon::create(array('percent_off' => 25, 'duration' => 'repeating', 'duration_in_months' => 5, 'id' => $id));
$this->assertSame($id, $c->id);
// @codingStandardsIgnoreStart
$this->assertSame(25, $c->percent_off);
// @codingStandardsIgnoreEnd
$c->metadata['foo'] = 'bar';
$c->save();
$stripeCoupon = Coupon::retrieve($id);
$this->assertEquals($c->metadata, $stripeCoupon->metadata);
}
示例2: testDeletion
public function testDeletion()
{
self::authorizeFromEnv();
$id = 'test-coupon-' . self::randomString();
$coupon = Coupon::create(array('percent_off' => 25, 'duration' => 'repeating', 'duration_in_months' => 5, 'id' => $id));
$customer = self::createTestCustomer(array('coupon' => $id));
$this->assertTrue(isset($customer->discount));
$this->assertTrue(isset($customer->discount->coupon));
$this->assertSame($id, $customer->discount->coupon->id);
$customer->deleteDiscount();
$this->assertFalse(isset($customer->discount));
$customer = Customer::retrieve($customer->id);
$this->assertFalse(isset($customer->discount));
}
示例3: post
public function post()
{
$param = Input::only('player_id', 'points');
$rules = array('points' => 'required|numeric|min:1,max:1000000', 'player_id' => 'required|exists:acl_users,id');
//custom error messaging
$messages = array('points.required' => 'Please fill up the player points redemption.', 'merchant_id.exists' => 'Merchant id is not valid');
$validator = Validator::make($param, $rules, $messages);
if ($validator->passes()) {
$player_points = Points::where('account_id', $param['player_id'])->get()->first();
$param = array('player_id' => $param['player_id'], 'points' => $param['points'], 'redeem_by' => Auth::user()->id, 'coupon_code' => Utils::generateRandomString(), 'redeemed' => 1);
try {
$player_bet = Coupon::create($param);
$update = $player_points->decrement('credits', $param['points']);
$message = 'Points has been successfully redeemed.';
return Redirect::action('points.redeem')->with('success', $message);
} catch (Exception $e) {
print $e;
}
} else {
$messages = $validator->messages();
return Redirect::action('points.redeem')->with('error', $messages->all());
}
}
示例4: retrieveOrCreateCoupon
/**
* Verify that a coupon with a given ID exists, or create a new one if it
* does not.
*/
protected static function retrieveOrCreateCoupon($id)
{
self::authorizeFromEnv();
try {
$coupon = Coupon::retrieve($id);
} catch (Error\InvalidRequest $exception) {
$coupon = Coupon::create(array('id' => $id, 'duration' => 'forever', 'percent_off' => 25));
}
}