@@ -6,8 +6,8 @@ class Recurly_Coupon extends Recurly_Resource
66 protected static $ _updatableAttributes ;
77 protected $ _redeemUrl ;
88
9- function __construct () {
10- parent ::__construct ();
9+ function __construct ($ href = null , $ client = null ) {
10+ parent ::__construct ($ href , $ client );
1111 $ this ->discount_in_cents = new Recurly_CurrencyList ('discount_in_cents ' );
1212 }
1313
@@ -18,7 +18,7 @@ public static function init()
1818 'duration ' , 'temporal_unit ' , 'temporal_amount ' ,
1919 'max_redemptions ' ,'applies_to_all_plans ' ,'discount_percent ' ,'discount_in_cents ' ,'plan_codes ' ,
2020 'hosted_description ' ,'invoice_description ' , 'applies_to_non_plan_charges ' , 'redemption_resource ' ,
21- 'max_redemptions_per_account '
21+ 'max_redemptions_per_account ' , ' coupon_type ' , ' unique_code_template ' , ' unique_coupon_codes '
2222 );
2323 Recurly_Coupon::$ _updatableAttributes = array ('name ' , 'max_redemptions ' ,
2424 'max_redemptions_per_account ' , 'hosted_description ' , 'invoice_description ' , 'redeem_by_date '
@@ -86,6 +86,24 @@ public function createUpdateXML() {
8686 return $ this ->renderXML ($ doc );
8787 }
8888
89+ public function generate ($ number ) {
90+ $ doc = $ this ->createDocument ();
91+
92+ $ root = $ doc ->appendChild ($ doc ->createElement ($ this ->getNodeName ()));
93+ $ root ->appendChild ($ doc ->createElement ('number_of_unique_codes ' , $ number ));
94+
95+ $ response = $ this ->_client ->request (Recurly_Client::POST , $ this ->uri () . '/generate ' , $ this ->renderXML ($ doc ));
96+ $ response ->assertValidResponse ();
97+
98+ $ coupons = array ();
99+ foreach (new Recurly_UniqueCouponCodeList ($ response ->headers ['Location ' ], $ this ->_client ) as $ coupon ) {
100+ $ coupons [] = $ coupon ;
101+ if (count ($ coupons ) == $ number ) break ;
102+ }
103+
104+ return $ coupons ;
105+ }
106+
89107 protected function uri () {
90108 if (!empty ($ this ->_href ))
91109 return $ this ->getHref ();
0 commit comments