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.
@shop_login_required 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) shopify.ShopifyResource.activate_session(session) charge = shopify.RecurringApplicationCharge() charge.test = True charge.return_url = shopify_url + "/admin/<app_name>/activate-plan" charge.price = 9.99 charge.name = "Test charge" charge.save() print charge.attributes return process_charge(request) @shop_login_required 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
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.
Have you created a collection on your online store and experienced an issue with adding yo...By Ollie Aug 24, 2022
Connect your PayPal account to allow your customers to checkout using the PayPal gateway a...By Ollie Jul 28, 2022