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); }
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)); }
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()); } }
/** * 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)); } }