Kan_Murota
(Kan Murota)
November 12, 2021, 10:52pm
1
Hi,
I’m trying to deploy a simle code that adds manual payment to an invoice with Infusionsoft SDK for Python.
It works fine locally but will fail on deploying.
Any tips to use it for GCF I’m missing?
Here is all the source.
Thank you in advance,
Kan_Murota
(Kan Murota)
November 13, 2021, 8:06am
2
I also did it like this but still not working.
from xmlrpc.client import ServerProxy, Error
class Infusionsoft(object):
base_uri = 'https://%s.infusionsoft.com/api/xmlrpc'
def __init__(self, name, api_key, use_datetime=False):
uri = self.base_uri % name
self.client = ServerProxy(uri, use_datetime=use_datetime)
self.client.error = Error
self.key = api_key
def __getattr__(self, service):
def function(method, *args):
call = getattr(self.client, service + '.' + method)
try:
return call(self.key, *args)
except self.client.error as v:
return "ERROR", v
return function
def server(self):
return self.client
class InfusionsoftOAuth(Infusionsoft):
base_uri = 'https://api.infusionsoft.com/crm/xmlrpc/v1?'
def __init__(self, access_token, use_datetime=False):
uri = '%saccess_token=%s' % (self.base_uri, access_token)
self.client = ServerProxy(uri, use_datetime=use_datetime)
self.client.error = Error
self.key = access_token
import json, requests, datetime,os
access_token = requests.get("https://****").text
private_code = os.getenv("private_code")
def orderCreation(request):
request_json = request.get_json()
if request_json["private_code"] != private_code:
return 'You need Private Code to run this function', 403
else:
infusionsoft = InfusionsoftOAuth(access_token)
invID = request_json["InvoiceId"]
amount = request_json["amount"]
date = request_json["date"]
payType = "From Shopify"
description = request_json["notes"]
bypassComm = False
req2 = infusionsoft.InvoiceService("addManualPayment",invID,amount,date,payType,description,bypassComm)
return req2, 200
Kan_Murota
(Kan Murota)
November 13, 2021, 8:46am
3
Turned out I uesed to dictate “requests” in requirements.txt and only recently that I carefully read this article . Thought “requests” was pre-installed, didn’t have to have it in requirements.txt but this was the cause of the error.
Adding
requests==2.26.0
Solved the issue.