I have made a test Shopify app in Django. What this app essentially does is downloads invoice of orders through Shopify admin dashboard admin links. The app was working fine on my local host when I was using ngrok tunnels. The invoices were being downloading on command but when I deployed this app on an AWS EC2 Instance the admin links are not working. The Invoice Pdf is being generated properly but I guess it is not being sent as an HttpResponse.
def download_invoice(request, raw_order, template_name):
raw_order['product_data'] = product_data
dir_path = settings.MEDIA_ROOT
with tempfile.TemporaryDirectory(dir=dir_path) as tmpdir:
output_filename = tmpdir + '\\' + "my-invoice.pdf"
path=os.path.join(os.path.dirname(__file__),'./templates/home')
templateLoader = jinja2.FileSystemLoader(searchpath=path)
templateEnv = jinja2.Environment(loader=templateLoader)
TEMPLATE_FILE = template_name
template = templateEnv.get_template(TEMPLATE_FILE)
outputText = template.render(data=raw_order)
pdfkit.from_string(outputText, output_filename)
filename = "my-invoice.pdf"
wrapper = FileWrapper(open(output_filename, 'rb'))
print(output_filename)
# breakpoint()
# pass
response = HttpResponse(wrapper, content_type=mimetypes.guess_type(output_filename)[0])
response['Content-Length'] = os.path.getsize(output_filename)
response['Content-Disposition'] = "attachment; filename=" + filename
return response
This function downloads the pdf when it is called on my app's interface but it does not download the invoice when it is called in Shopify Admin Link.
Maybe there is an issue EC2 security group. My Inbound Rules My Outbound Rules
As far as I think there is some problem with EC2 configuration because everything works properly when I use a Ngrok tunnel and run the application on localhost. And the document is being generated properly even when the application is deployed on EC2 instance but it is not being sent. If any additional detail is required please let me know. Any help would be appreciated.
This was solved. The problem was that the ec2 instance did not have SSL so shopify was rejecting any response that was 'non-secure' and it worked on localhost because browsers treat localhost differently than an 'http' connection.