I'm working with PayPals API which is really badly documented and need to ask for some help.
I am extending my site on the PayPal Adaptive API which allows me to setup Preapproved payments before.
Along with the details sent I'd like to add some user information.
It seems like it can be done according to their documentation, but nowhere in the IPN does it get captured.
simple payment
def test_pay():
response = paypal.pay(
actionType = 'PAY',
cancelUrl = cancelUrl,
currencyCode = currencyCode,
senderEmail = EMAIL_ACCOUNT,
feesPayer = 'EACHRECEIVER',
memo = 'Simple payment example',
preapprovalKey = 'PA-0HA01893HK6322232',
receiverList = { 'receiver': [
{ 'amount':"10.0", 'email':API_EMAIL, 'primary':True },
{ 'amount':"5.0", 'email':SECONDARY_EMAIL, 'primary':False }
]},
clientDetailsType = { 'customerId': 1, 'customerType': 'Normal' },
returnUrl = returnUrl,
ipnNotificationUrl = notificationUrl
)
# if response['responseEnvelope']['ack'] == "Success":
print response['responseEnvelope']['ack']
# if response['paymentExecStatus'] == "COMPLETED":
print response['paymentExecStatus']
# if response.has_key('payKey'):
print response['payKey']
print response
test_pay()
The IPN response
pay_key=AP-8J7165865F7541310&transaction%5B0%5D.id_for_sender_txn=4GL2853573576212V&transaction%5B0%5D.pending_reason=NONE&charset=windows-1252&log_default_shipping_address_in_transaction=false&transaction%5B0%5D.id=6XD76450JV9737605¬ify_version=UNVERSIONED&preapproval_key=PA-93P236141R834703C&transaction%5B1%5D.id=9R07347926768733A&test_ipn=1&transaction%5B0%5D.status=Completed&status=COMPLETED&action_type=PAY&memo=Simple+payment+example&transaction%5B0%5D.receiver=a.smit_1329744569_biz%40mac.com&transaction%5B1%5D.status=Completed&payment_request_date=Wed+Feb+22+05%3A30%3A49+PST+2012&transaction%5B1%5D.id_for_sender_txn=2D9633797C888500H&verify_sign=AIDiik4kxSLiNqbMmTDHplFnCnz3A3ORrDVlBVOzrtltyUx-NoxxgSc6&transaction%5B1%5D.pending_reason=NONE&transaction%5B0%5D.status_for_sender_txn=Completed&transaction%5B1%5D.status_for_sender_txn=Completed&transaction%5B0%5D.is_primary_receiver=true&transaction%5B1%5D.receiver=a.smit_1298362298_per%40mac.com&transaction%5B1%5D.amount=USD+5.00&ipn_notification_url=http%3A%2F%2F108.166.107.74%2Fyour-ipn-location%2F&transaction%5B0%5D.amount=USD+10.00&transaction_type=Adaptive+Payment+PAY&cancel_url=http%3A%2F%2F108.166.107.74%2F&reverse_all_parallel_payments_on_error=false&sender_email=a.smit_1329128659_per%40mac.com&transaction%5B1%5D.is_primary_receiver=false&fees_payer=EACHRECEIVER&return_url=http%3A%2F%2F108.166.107.74%2F
Nowhere in the response can I see the customerType or customerId
Any ideas?
customerId and customerType aren't returned according to the PayPal API. I imagine it's a field that will show up in your transaction history on the PayPal site. Why there is no API function to return customer data is beyond me, as well.
Related
Hoping you are good
I am trying to get data from zendisk by API and Python Json
i can get any data Value under Audits LikeTicket_id and auther_id but when tried get data under Events such as Body
keep get this error
print(audit['body'])
KeyError: 'body'
JSON Output
{
"audits":[
{
"id":1727876301271,
"ticket_id":54010951,
"created_at":"2021-10-21T10:58:06Z",
"author_id":12306596687,
"metadata":{
"system":{
"client":"GuzzleHttp/6.2.1 curl/7.29.0 PHP/7.1.2",
"ip_address":"x.x.x.x",
"location":"Boardman, OR, United States",
"latitude":45.8491,
"longitude":-119.7143
},
"custom":{
}
},
"events":[
{
"id":1727876301291,
"type":"Comment",
"author_id":366289833251,
"body":"Sehr geehrte Damen und Herren,\n\nIn unserer Bestellung fehlt das Kleid, es war nicht mit dabei, obwohl es hätte drin sein müssen.\nFreundliche Grüße",
"attachments":[
],
"audit_id":1727876301271
},
{
"id":1727876301311,
"type":"Create",
"value":"366289833251",
"field_name":"requester_id"
},
Python Code
import requests
import csv
# Settings
auth = 'xxxxxxx', 'xxxxxx'
view_tickets = []
view_id = 214459268
view_audits = []
ticket_id = 54010951
view_events =[]
print(f'Getting tickets from ticket_id ID {ticket_id}')
url = f'https://xxxx.zendesk.com/api/v2/tickets/54010951/audits.json'
while url:
response = requests.get(url, auth=auth)
page_data = response.json()
audits = page_data['audits'] # extract the "tickets" list from the page
view_audits.extend(audits)
url = page_data['next_page']
for audit in audits:
print(audit['body'])
You know you're overwriting, not adding, to audits right? (in this line: audits = page_data['audits']). I don't think that makes sense, but it's hard to know your intent.
To fix the error itself, your json structure has the body key inside the events key. So you can access it with:
print(audit['events'][0]['body'])
or, using another loop:
for audit in audits:
for event in audit['events']
print(event['body'])
You might get an error for the 2nd one because it doesn't appear to have the body key. You can add an if statement to handle that if you want.
I have a problem using the jaeger open tracing project within our microservice system.
The config I use is as below.
config = Config(
config={
'sampler': {
'type': 'const',
'param': 1,
},
'local_agent': {
'reporting_host': '127.0.0.1',
},
'logging': True,
},
service_name='DB - API',
validate=True,
)
tracer = config.initialize_tracer()
active_span_source = FixedActiveSpanSource()
tracer_interceptor = open_tracing_client_interceptor(
tracer,
log_payloads=True,
active_span_source=active_span_source)
The origin of the trace is the same as this.
with t.tracer.start_span('Request Post') as span:
print(
f"Created span: trace_id:{span.trace_id:x}, span_id:{span.span_id:x}, parent_id:{span.parent_id}, flags:{span.flags:x}")
span.log_kv({'event': 'Request Posted', 'life': 42})
with t.tracer.start_span('GraphQl', child_of=span) as span2:
span2.log_kv({'event': 'Graphql Executed', 'life': 42})
carrier = {}
t.tracer.inject(span, Format.HTTP_HEADERS, carrier)
print(carrier)
This works fine and is logged within the UI and with printed results below.
Created span: trace_id:2b55203a8773aa14, span_id:77cceca94f4cfe74, parent_id:None, flags:1
{'uber-trace-id': '2b55203a8773aa14:77cceca94f4cfe74:0:1'}
But then when I extract {'uber-trace-id': '2b55203a8773aa14:77cceca94f4cfe74:0:1'} within another service it says a new span has been created as expected, but nothing is logged within the UI.
carrier = {'uber-trace-id': '2b55203a8773aa14:77cceca94f4cfe74:0:1'}
parentspan = t.tracer.extract(Format.HTTP_HEADERS, carrier)
print(t.tracer.sampler)
with t.tracer.start_span('TEST', child_of=parentspan) as span3:
print(
f"Created span: trace_id:{span3.trace_id:x}, span_id:{span3.span_id:x}, parent_id:{span3.parent_id:x}, flags:{span3.flags:x}")
span3.log_kv({'event': 'test', 'life': 42})
time.sleep(1)
span3.log_kv({'event': 'test34', 'life': 43})
time.sleep(30)
Print result:
Created span: trace_id:2b55203a8773aa14, span_id:af7fef928ff1cd13, parent_id:77cceca94f4cfe74, flags:1
With both Format.HTTP_HEADERS and Format.TEXT_MAP it is the same result.
Does anyone know why nothing is logged in the UI and how to fix this?
Thanks in advance.
I migrated from parse.com to an hosted ParseSever. Most of the things are working, however I found that for one class, the fields are not updated. The HTTP request returns 200 in logs and in Python, updatedAt field shows the recent timestamp, but the fields are not changed. In the python code and its printout below, fields field1 and field2 continue to show old values even when updatedAt and HTTP response check out. Updates to other classes from REST API are generally working (have not checked exhaustively). Updates from SDK are working. Was working flawlessly on parse.com. ACL of class and entries are public.
def updateObjectWithId(self,objectId, objectJson):
self.connection.connect()
if(objectId == ""):
self.connection.request('POST','/parse/classes/'+self._className,objectJson,
{
"X-Parse-Application-Id": self.appId,
"X-Parse-Master-Key": self.masterApiKey
})
else:
print "ParseArchiver.updateObjectWithId: id: ", objectId, " of Class: ", self._className, " with json: ", objectJson
self.connection.request('PUT','/parse/classes/'+self._className+'/'+objectId,objectJson,
{
"X-Parse-Application-Id": self.appId,
"X-Parse-Master-Key": self.masterApiKey
})
result = json.loads(self.connection.getresponse().read())
time.sleep(ParseArchiver.ParseSleepTime)
print "*** ParseArchiver.updateObjectWithId: Result object is:",result
return
The output:
PredictionObject.write(): updating existing object with ID: On6AdEnPVb
ParseArchiver.updateObjectWithId: id: correct_id of Class: correct_class with json: {"field1": ["2016-06-07T22:00:00.000Z|0.267835319042|-0700", "2016-06-08T10:00:00.000Z|0.446276366711|-0700", "2016-06-08T22:00:00.000Z|0.778348565102|-0700", "2016-06-09T10:00:00.000Z|0.00348118506372|-0700", "2016-06-09T22:00:00.000Z|0.0183897037059|-0700", "2016-06-10T10:00:00.000Z|0.562650620937|-0700", "2016-06-10T22:00:00.000Z|0.079613097012|-0700", "2016-06-11T10:00:00.000Z|0.562650620937|-0700", "2016-06-11T22:00:00.000Z|0.0199579093605|-0700", "2016-06-12T10:00:00.000Z|0.629606068134|-0700", "2016-06-12T22:00:00.000Z|0.292343884706|-0700", "2016-06-13T10:00:00.000Z|0.0342484489083|-0700", "2016-06-13T22:00:00.000Z|0.0746899694204|-0700", "2016-06-14T10:00:00.000Z|0.0594595149159|-0700", "2016-06-14T22:00:00.000Z|0.424203515053|-0700", "2016-06-15T10:00:00.000Z|0.0349752865732|-0700", "2016-06-15T22:00:00.000Z|0.00455725379288|-0700", "2016-06-16T10:00:00.000Z|0.0987700968981|-0700", "2016-06-16T22:00:00.000Z|0.30742970109|-0700", "2016-06-17T10:00:00.000Z|0.0781866833568|-0700", "2016-06-17T22:00:00.000Z|0.367497861385|-0700", "2016-06-18T10:00:00.000Z|0.225806906819|-0700", "2016-06-18T22:00:00.000Z|0.0179004631937|-0700", "2016-06-19T10:00:00.000Z|0.11387591809|-0700", "2016-06-19T22:00:00.000Z|0.103792026639|-0700", "2016-06-20T10:00:00.000Z|0.710064172745|-0700", "2016-06-20T22:00:00.000Z|0.728509664536|-0700", "2016-06-22T10:00:00.000Z|0.140641510487|-0700"], "uid": "correct_uid", "field2": ["2016-06-20T22:00:00.000Z|0.728509664536|-0700", "2016-06-22T10:00:00.000Z|0.140641510487|-0700"]}
*** ParseArchiver.updateObjectWithId: Result object is: {u'updatedAt': u'2016-06-22T16:38:55.690Z'}
I found that every non-GET request must have a "Content-Type" field now. This was not required on parse.com. I am thinking may be ParseServer can be set-up with a default content type that would allow one to omit this parameter and then old code will work w/o modifications. The modified working code snippet is below:
def updateObjectWithId(self,objectId, objectJson):
self.connection.connect()
if(objectId == ""):
self.connection.request('POST','/parse/classes/'+self._className,objectJson,
{
"X-Parse-Application-Id": self.appId,
"X-Parse-Master-Key": self.masterApiKey,
"Content-Type": "application/json" #This made it work
})
else:
print "ParseArchiver.updateObjectWithId: id: ", objectId, " of Class: ", self._className, " with json: ", objectJson
self.connection.request('PUT','/parse/classes/'+self._className+'/'+objectId,objectJson,
{
"X-Parse-Application-Id": self.appId,
"X-Parse-Master-Key": self.masterApiKey,
"Content-Type": "application/json" #This made it work.
})
result = json.loads(self.connection.getresponse().read())
time.sleep(ParseArchiver.ParseSleepTime)
print "*** ParseArchiver.updateObjectWithId: Result object is:",result
return
I'm using facebookads python api, v2.6.
I'm trying to create an AdSet with optimization goal = lead_generation.
This is my code:
ad_set = AdSet(parent_id = 'act_%s' % FB_ACCOUNT)
ad_set[AdSet.Field.name]= 'Teste AdSet'
ad_set[AdSet.Field.campaign_id]='6043402838999'
ad_set[AdSet.Field.status]=AdSet.Status.paused
ad_set[AdSet.Field.billing_event] = AdSet.BillingEvent.impressions
ad_set[AdSet.Field.optimization_goal] = AdSet.OptimizationGoal.lead_generation
ad_set[AdSet.Field.daily_budget]= 100
ad_set[AdSet.Field.bid_amount]= 1
ad_set[AdSet.Field.start_time]= '2016-07-01'
ad_set[AdSet.Field.promoted_object]=
ad_set[AdSet.Field.targeting]= {Targeting.Field.geo_locations: { 'countries': ['BR']},Targeting.Field.genders: [1],Targeting.Field.age_min: 20,Targeting.Field.age_max: 24}
ad_set.remote_create()
But when I run this I get this error:
Status: 400
Response:
{
"error": {
"code": 100,
"is_transient": false,
"error_subcode": 1885024,
"error_user_msg": "When creating an ad set within a campaign using the Body of an error/warning message. Title is: Promoted Object Missing objective, a promoted object must be specified.",
"error_user_title": "Promoted Object Missing",
"message": "Invalid parameter",
"type": "OAuthException",
"fbtrace_id": "B9hyZlpzS7O"
}
}
I tried to find any documentation about this, but could not. On the official docs I don't see LEAD_GENERATION on the promoted objects options:
https://developers.facebook.com/docs/marketing-api/reference/ad-campaign#Creating
Anyone had this problem?
In case anyone has the same issue, you have to use page_id.
The ad set must have its promoted_object set to the corresponding <PAGE_ID>.
reference:
https://developers.facebook.com/docs/marketing-api/guides/lead-ads/create#create
you have to specify your associated page_id
promoted_object={"page_id": "<PAGE_ID>"}
Below code may help u
from facebook_business.adobjects.adaccount import AdAccount
from facebook_business.adobjects.adset import AdSet
from facebook_business.api import FacebookAdsApi
access_token = '<ACCESS_TOKEN>'
app_secret = '<APP_SECRET>'
app_id = '<APP_ID>'
id = '<AD_ACCOUNT_ID>'
FacebookAdsApi.init(access_token=access_token)
fields = [
]
params = {
'name': 'A CPA Ad Set',
'campaign_id': '<adCampaignLinkClicksID>',
'daily_budget': '5000',
'start_time': '2019-01-09T21:31:19-0800',
'end_time': '2019-01-16T21:31:19-0800',
'billing_event': 'IMPRESSIONS',
'optimization_goal': 'REACH',
'bid_amount': '1000',
'promoted_object': {'page_id':'<pageID>'},
'targeting': {'geo_locations':{'countries':['US']}},
'user_os': 'iOS',
'publisher_platforms': 'facebook',
'device_platforms': 'mobile',
}
print AdAccount(id).create_ad_set(
fields=fields,
params=params,
)
I have a problem coding a bot in Python that works with the new inline mode.
The bot gets the query, and while trying to answer, it receives error 400.
Here is a sample of data sent by the bot at this time:
{
'inline_query_id': '287878416582808857',
'results': [
{
'type': 'article',
'title': 'Convertion',
'parse_mode': 'Markdown',
'id': '287878416582808857/0',
'message_text': 'blah blah'
}
]
}
I use requests library in to make requests, and here is the line that does it in the code:
requests.post(url = "https://api.telegram.org/bot%s%s" % (telegram_bot_token, "/answerInlineQuery"), data = myData)
With myData holding the data described in the sample.
Can you help me solve this, please?
I suspect it is because you haven't JSON-serialized the results parameter.
import json
results = [{'type': 'article',
'title': 'Convertion',
'parse_mode': 'Markdown',
'id': '287878416582808857/0',
'message_text': 'blah blah'}]
my_data = {
'inline_query_id': '287878416582808857',
'results': json.dumps(results),
}
requests.post(url="https://api.telegram.org/bot%s%s" % (telegram_bot_token, "/answerInlineQuery"),
params=my_data)
Note that I use params to supply the data.
I am getting the correct response after doing some POC. I am using java com.github.pengrad.
Below the code.
GetUpdatesResponse updatesResponse = bot.execute(new GetUpdates());
List updates = updatesResponse.updates();
for(Update update:updates){
InlineQuery inlineQuery = update.inlineQuery();
System.out.println(update);
System.out.println(inlineQuery);
System.out.println("----------------");
if(inlineQuery!=null) {
InlineQueryResult r1 = new InlineQueryResultPhoto("AgADBQADrqcxG5q8tQ0EKSz5JaZjzDWgvzIABL0Neit4ar9MsXYBAAEC", "https://api.telegram.org/file/bot230014106:AAGtWr8xUCqUy8HjSgSFrY3aCs4IZs00Omg/photo/file_1.jpg", "https://api.telegram.org/file/bot230014106:AAGtWr8xUCqUy8HjSgSFrY3aCs4IZs00Omg/photo/file_1.jpg");
BaseResponse baseResponse = bot.execute(new AnswerInlineQuery(inlineQuery.id(), r1)
.cacheTime(6000)
.isPersonal(true)
.nextOffset("offset")
.switchPmParameter("pmParam")
.switchPmText("pmText"));
System.out.println(baseResponse.isOk());
System.out.println(baseResponse.toString());
System.out.println(baseResponse.description());
}
}
Below the console output:
Update{update_id=465103212, message=null, edited_message=null, inline_query=InlineQuery{id='995145139265927135', from=User{id=231700283, first_name='Manabendra', last_name='Maji', username='null'}, location=null, query='hi', offset=''}, chosen_inline_result=null, callback_query=null}
InlineQuery{id='995145139265927135', from=User{id=231700283, first_name='Manabendra', last_name='Maji', username='null'}, location=null, query='hi', offset=''}
true
BaseResponse{ok=true, error_code=0, description='null'}
null
And I am getting proper response in my mobile telegram app also.