Skip to content

Commit

Permalink
bulk coupon creation and generation
Browse files Browse the repository at this point in the history
  • Loading branch information
bhelx committed Sep 29, 2015
1 parent 157b25b commit bf04e24
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion recurly/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import recurly
import recurly.js as js
from recurly.errors import *
from recurly.resource import Resource, Money, PageError
from recurly.resource import Resource, Money, PageError, Page


"""
Expand Down Expand Up @@ -331,6 +331,9 @@ class Coupon(Resource):
'plan_codes',
'hosted_description',
'max_redemptions_per_account',
'coupon_type',
'unique_code_template',
'unique_coupon_codes',
)

@classmethod
Expand Down Expand Up @@ -385,6 +388,20 @@ def all_maxed_out(cls, **kwargs):
def has_unlimited_redemptions_per_account(self):
return self.max_redemptions_per_account == None

def generate(self, amount):
elem = ElementTree.Element(self.nodename)
elem.append(Resource.element_for_value('number_of_unique_codes', amount))

url = urljoin(self._url, '%s/generate' % (self.coupon_code, ))
body = ElementTree.tostring(elem, encoding='UTF-8')

response = self.http_request(url, 'POST', body, { 'Content-Type':
'application/xml; charset=utf-8' })

if response.status not in (200, 201, 204):
self.raise_http_error(response)

return Page.page_for_url(response.getheader('Location'))

class Redemption(Resource):

Expand Down

0 comments on commit bf04e24

Please sign in to comment.