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