Get authorization id from express checkout - python

I'm using the paypal-python-sdk.
Currently, I'm redirecting the user to paypal where they log in, click confirm, and are redirected back to my site. No issues there. However, I have no idea how to get the authorization id so I can capture the amount authorized (or smaller). According to the docs its supposed to exist under related_resources but the list is always empty.
Will authorizations completed by logging into paypal return an authorization id?
Clarification: I know I can execute the payment with the payment_id. However, executing the payment is out of the question because I must be able to capture less than authorized.
request = {
"intent": "authorize",
"redirect_urls": {
"return_url": PAYPAL_RETURN_URL,
"cancel_url": PAYPAL_CANCEL_URL
},
"payer": {
"payment_method": "paypal"
},
"transactions": [{
"amount": {
"total": str(self.order.total),
"currency": "USD"
},
"description": "Lorem lipsum"
}]
}
payment = Payment(request, api=self._connection())

Related

can't create payment invoice without redirecting

I want to accept money through paypal. I need to send the user a link and get paid. The approval_link link is being created successfully. But it is not possible to pay using the link. I log in using this link, click pay, but I am redirected to return_url. I don't want this, I want the user not to be redirected anywhere. You just need to take the money from him and that's it. My project is not a website and I don't have any pages where you can redirect the client. Help to create a payment form without redirecting the client to other pages. I thank you in advance for the attention you paid to my problem and I apologize for my English.
I will repeat briefly: we need a payment form without redirecting to other pages. Just get the money. Please help to configure the parameters of paypalrestsdk.Payment()
import paypalrestsdk
api = paypalrestsdk.set_config(
mode="sandbox",
client_id="XXX",
client_secret="XXX")
token = api.get_access_token()
print(token)
payment = paypalrestsdk.Payment({
"intent": "sale",
"payer": {
"payment_method": "paypal"},
"redirect_urls": {
"return_url": "http://localhost:3000/process",
"cancel_url": "http://localhost:3000/cancel"
},
"transactions": [{
"item_list": {
"items": [{
"name": "item",
"sku": "item",
"price": "1.00",
"currency": "RUB",
"quantity": 1}]},
"amount": {
"total": "1.00",
"currency": "RUB"},
"description": "This is the payment transaction description."}]})
create = payment.create()
if create:
print("Payment created successfully")
else:
print(payment.error)
for link in payment.links:
if link.rel == "approval_url":
# Convert to str to avoid Google App Engine Unicode issue
# https://github.com/paypal/rest-api-sdk-python/pull/58
approval_url = str(link.href)
print("Redirect for approval: %s" % (approval_url))
I tried not to specify links for redirects. If they are not present, the payment is not created.
First of all you are using a deprecated v1/payments API and corresponding SDK. If you were going to implement a website checkout, you should use the current v2/checkout/orders API and its SDK instead; such an integration is documented here.
But your invoice use case is not a normal website checkout, as you've noted. Indeed there is a separate Invoicing API for it, see the invoicing integration guide.
There's no SDK for invoicing APIs--use direct HTTPS API calls to first obtain an oauth2 access token and then create your invoice.

How to get envelope link

In my application, after user register, it creates a docusign document and send in an envelope to user's email for signature.
My question is how do I also provide a link to the document from my application? I want it to be the same link that user would access in their email. I have tried to construct url from envelope_id which i get from the result of create_envelope, but that seems to be wrong. Is there actually a way to do this? Or the it has to be accessed from user's email?
An envelope uri: envelopes/ids
The flow you might be looking for is called Embedded Signing. With embedded signing, you can redirect your users to sign DocuSign envelopes instead of having them sign via email.
Two steps process:
First, you will create your envelope. Be sure to include clientUserId for each recipient object. This will be used when you want to generate unique signing URLs in the next step.
POST /accounts/{accountId}/envelopes
{
"status": "sent",
"emailSubject": "Envelope with Embedded Signer",
"documents": [{
"documentId": "1",
"name": "contract.pdf",
"documentBase64": "base64 document bytes...",
}],
"recipients": {
"signers": [{
"email": "john#email.com",
"name": "John Doe",
"recipientId": "1",
"clientUserId": "1234"
}]
}
}
Second, you will generate the RecipientViewURL for a given user.
POST /accounts/{accountId}/envelopes/{envelopeId}/views/recipient
{
"userName": "John Doe",
"email": "johndoe#email.com",
"recipientId": "1",
"clientUserId": "1234",
"authenticationMethod": "email",
"returnUrl": "https://www.docusign.com/devcenter"
}
Here is a guide that provides a more thorough background on the feature.

Facebook Chatbot postback don't respond

I am working on fb chatbot and use postback in the generic templates buttons. However, there is no response after I click the postback button.
"buttons": [
{
"type": "web_url",
"url": "https://maps.google.com/?q={lat},{lon}".format(lat=store['coordinates']['lat'], lon=store['coordinates']['lon']),
"title": u"店家位置"
},
{
"type": "postback",
"payload": Function.sendGourmetComments + "_{id}".format(id=store["id"]),
"title": u"觀看評論"
},
{
"type": "postback",
"payload": Function.sendStoreHearts + "_{upload}".format(upload=None) + "_{id}".format(id=store["id"]) + "_{push}".format(push=None) + "_{edit}".format(edit=None) + "_{search}".format(search=True),
"title": u"撰寫評論"
}
]
I guess I didn't check the message_postback event, however, I did. I didn't even receive any response from my webhook. So it's kind of mysterious to me what's going on.
It was working fine before, but it doesn't work without change after restart my computer. I am using ngork to expose my server API as callback url.
I've this problem two days ago.
You need the page_messaging facebook's approve to receive it Facebook's approved page_messaging permission

Location widget in messenger platform displays a search bar in mobile version but not in Desktop Version

By using bot functionality provided by facebook messenger platform,
I want users to be able to provide location by using search.
It's working as expected in mobile app of the messenger as it's showing search option. But in the desktop version of the messenger, search option is not showing in location widget.
I wanted to ask that is it expected behavior or I'm missing out something.
Also in browser console, it's showing some error:
ErrorUtils caught an error:
"navigator.permissions.query(...).then(...).done is not a function".
Subsequent errors won't be logged;
see https://fburl.com/debugjs.ja # qtaMy7UNoCv.js:47.
Here's what I've tried so far:
def send_location_with_quick_reply(self, recipient_id, message, quick_replies):
url = self.get_message_url()
payload = {
"recipient":{
"id":recipient_id
},
"message":{
"text": message,
"quick_replies":[{
"content_type": "location"
}]
}
}
# _do_post will hit the send_message API of `Messenger`.
return self._do_post(url, payload)
And here's the response I'm getting after the user chooses the location:
{
"object": "page",
"entry": [{
"id": "128922990987384",
"time": 1505890084176,
"messaging": [{
"sender": {
"id": "1456347437763847"
},
"recipient": {
"id": "128922990987384"
},
"timestamp": 1505890084065,
"message": {
"mid": "mid.$cAAAvskrTvY9kz1Bs4Vengsjpb9L_",
"seq": 2366,
"attachments": [{
"title": "User's Location",
"url": "https:\\/\\/l.facebook.com\\/l.php?u=https\\u00253A\\u00252F\\u00252Fwww.bing.com\\u00252Fmaps\\u00252Fdefault.aspx\\u00253Fv\\u00253D2\\u002526pc\\u00253DFACEBK\\u002526mid\\u00253D8100\\u002526where1\\u00253D12.9703749\\u0025252C\\u00252B77.6361206\\u002526FORM\\u00253DFBKPL1\\u002526mkt\\u00253Den-US&h=ATNsjbke0tPFGIFpCq4MA5l1W6wmiwp0cTfUZNXSSbMDHxygEM4GrVlZmtaebsN4elliFhMSJNmIFwQgn-p_fxnF2hW0VdKTj2z_0hsWnH4dlLZGdQ&s=1&enc=AZN9DwrutbtXSfRAdxQf4bzFSMSO3zujAb0LBOgUt9mz16ZnDn7CSZDBLmnISjfAMbLG6b6H6hn9a3KCb6wOo7dn",
"type": "location",
"payload": {
"coordinates": {
"lat": 12.9703749,
"long": 77.6361206
}
}
}]
}
}]
}]
}
I am using python and drf to integrate with messenger platform.
Yes, this is expected behavior currently.

PayPal Adaptive Payments - Preapproval request results in "Invalid request" error

I can't figure out what's happening with my Preapproval HTTP POST request. I'm just trying to do a basic call to PayPal's Adaptive Payments API, the Preapproval call specifically. And the PayPal error 580001 "Invalid request" is not that helpful in itself.
Request Headers (based on my Sandbox's account credentials, which I changed to xxx):
{
'X-PAYPAL-REQUEST-DATA-FORMAT': 'JSON',
'X-PAYPAL-SECURITY-PASSWORD': 'xxx',
'X-PAYPAL-RESPONSE-DATA-FORMAT': 'JSON',
'X-PAYPAL-SECURITY-SIGNATURE': 'xxx',
'X-PAYPAL-SECURITY-USERID': 'xx',
'X-PAYPAL-APPLICATION-ID': 'APP-80W284485P519543T'
}
My request payload (HTTP POST, body encoded in JSON):
{
"requireInstantFundingSource": "TRUE",
"returnUrl": "http://www.google.com/?paypal=ok",
"maxTotalAmountOfAllPayments": 1002,
"maxNumberOfPaymentsPerPeriod": 1,
"endingDate": "2014-03-14T16:49:36+0000",
"requestEnvelope.errorLanguage": "en_US",
"clientDetails.applicationId": "XXX",
"cancelUrl": "http://www.google.com/paypal=cancel",
"startingDate": "2013-09-15T16:49:36+0000",
"feesPayer": "PRIMARYRECEIVER",
"currencyCode": "SEK"
}
The above POST body is posted to:
https://svcs.sandbox.paypal.com/AdaptivePayments/Preapproval
Response from Paypal ("prettified" for understanding):
{
"responseEnvelope": {
"ack": "Failure",
"timestamp": "2013-09-10T09:56:43.031-07:00",
"build": "6941298",
"correlationId": "26d55e6bfcaa0"
},
"error": [
{
"category": "Application",
"domain": "PLATFORM",
"severity": "Error",
"message": "Invalid request: {0}",
"subdomain": "Application",
"errorId": "580001"
}
]
}
Any feedback is appreciated.
OK fixed. How?
Fix #1
The arguments requestEnvelope.errorLanguage and clientDetails.applicationId need to be "JSONified" into objects on their own, such as:
"requestEnvelope": {
"errorLanguage": "en_US"
},
and
"clientDetails": {
"applicationId": "APP-XXXXXXXXXXXXX"
},
respectively.
Fix #2
Date formats; date format should be of the form 2014-03-15T20:14:38.007+00:00 and not 2014-03-14T20:14:38+0000 as I was passing. Note the milliseconds, and the timezone with the colon in the utc offset.
Next time an Invalid request comes up the parameters I'm passing will be the first thing to look at.

Categories

Resources