Skip to content

Commit

Permalink
Merge pull request #132 from recurly/bulk_and_unique_coupons
Browse files Browse the repository at this point in the history
Bulk coupon creation and generation
  • Loading branch information
cbarton committed Oct 2, 2015
2 parents 7dc9847 + bf04e24 commit 9c07b3d
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 9c07b3d

Please sign in to comment.