FROM CACHE - en_header

Creating a recurring charge in Python + Django

Shopify Partner
16 0 3




I'm trying to create a recurring charge in my Shopify Django app, based on Shopify's Django app repo

However, I can't figure out how to get the recurring charge working, I have the following code so far, with all url's setup, but I get the following error: 

The view shopify_app.decorators.confirm_charge didn't return an HttpResponse object. It returned None instead.


I'm not sure where to redirect to or how to make the POST and GET requests work in Django redirect to the correct Shopify confirmation url. Any help or pointers in the right direction would be much appreciated.


I followed the example from the forum found here, but unfortunately the part about the confirmation url is missing.


def confirm_charge(request, *args, **kwargs):

    shopify_url = request.session['shopify']['shop_url']
    token = request.session['shopify']['access_token']

    session = shopify.Session(shopify_url, token)

    charge = shopify.RecurringApplicationCharge()
    charge.test = True
    charge.return_url = shopify_url + "/admin/<app_name>/activate-plan"
    charge.price = 9.99 = "Test charge"

    print charge.attributes

    return process_charge(request)

def process_charge(request):

    shop = request.REQUEST.get('confirmation_url')
## shop prints: None
## the script gets to this part:
print "process charge" return activate_charge(request)
@shop_login_required def activate_charge(request): shopify.ApplicationCharge().activate



Shopify Specialist & App Developer
Reply 1 (1)
Shopify Staff
Shopify Staff
1561 81 329

What happens when you instead `return redirect(charge.confirmation_url)` in confirm_charge?


That looks to be the Django way to handle redirects. Remember you want to send the client to the confirmation_url, you don't need to fetch anything from there using your back end. When the client is redirected to the confirmation_url, they accept the charge and are redirected from Shopify to your specified `return_url`.


Hope that helps.



Alex | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog