I try to make payment requesets for different users via https://api.paypal.com/v1/payments/payment, but for some requests, 40%, PayPal api returns HTTP 400 response and for the rest they are fine. the body of requests is similar to:
{
"intent": "sale",
"payer": {
"payment_method": "PAYPAL",
"funding_instruments": [
{
"billing": {
"billing_agreement_id": "B-XXXXX"
}
}
]
},
"transactions": [
{
"amount": {
"currency": "EUR",
"details": {
"subtotal": "11.99",
"tax": "0.0",
"shipping": "0.0",
"handling_fee": "0.0",
"shipping_discount": "0.0",
"insurance": "0.0"
},
"total": "11.99"
},
"invoice_number": "pp_XXXX",
"custom": "\"{\"payment_id\": \"6102645598795\", \"user_id\": \"28233184743\", \"cid\": \"DE:282331858548:30\"}\""
}
],
"redirect_urls": {
"return_url": "https://example.com/return",
"cancel_url": "https://example.com/cancel"
}
}
and the response is similar to
{
"name": "TRANSACTION_REFUSED",
"message": "The request was refused",
"information_link": "https://developer.paypal.com/docs/api/payments/#errors",
"debug_id": "8e0a927a12",
"code": "TRANSACTION_REFUSED"
}
the response is not informativ.
any idea?
After contacting PayPal support and sharing the debug_id, They inform me that the error is related to an invalid funding source. The issue means the funding source, credit card or bank account is deleted.
Related
I am trying to create an Invoice in Xero accounting using one of the Xero provided rest api, i used a Python requests library to access the certain Invoice rest api but unable to create an invoice. It raise following error
{'ErrorNumber': 17, 'Type': 'NoDataProcessedException', 'Message': 'No data has been processed for this endpoint. This endpoint is expecting Invoice data to be specifed in the request body.'}
Here is my my python code,
def XeroRequests():
new_tokens = XeroRefreshToken('*****************************')
xero_tenant_id = XeroTenants(new_tokens[0])
get_url = 'https://api.xero.com/api.xro/2.0/Invoices'
response = requests.post(get_url,
headers = {
'Authorization': 'Bearer ' + new_tokens[0],
'Xero-tenant-id': xero_tenant_id,
'Accept': 'application/json'
},
data = {
"Type": "ACCREC",
"Contact": {
"ContactID": "eaa28f49-6028-4b6e-bb12-d8f6278073fc"
},
"Date": "\/Date(1518685950940+0000)\/",
"DueDate": "\/Date(1518685950940+0000)\/",
"DateString": "2009-05-27T00:00:00",
"DueDateString": "2009-06-06T00:00:00",
"LineAmountTypes": "Exclusive",
"LineItems": [
{
"Description": "Consulting services as agreed (20% off standard rate)",
"Quantity": "10",
"UnitAmount": "100.00",
"AccountCode": "200",
"DiscountRate": "20"
}
]
})
json_response = response.json()
print("POST response ", json_response)
Whats wrong i did here?
You need to give data like this as per the API documentation
data = {
"Invoices": [{
"Type": "ACCREC",
"Contact": {
"ContactID": "eaa28f49-6028-4b6e-bb12-d8f6278073fc"
},
"Date": "\/Date(1518685950940+0000)\/",
"DueDate": "\/Date(1518685950940+0000)\/",
"DateString": "2009-05-27T00:00:00",
"DueDateString": "2009-06-06T00:00:00",
"LineAmountTypes": "Exclusive",
"LineItems": [
{
"Description": "Consulting services as agreed (20% off standard rate)",
"Quantity": "10",
"UnitAmount": "100.00",
"AccountCode": "200",
"DiscountRate": "20"
}
]
}
]
}
payment = Payment({
"intent": "sale",
"application_context": {
"locale": "en_IN",
"user_action": "commit",
"shipping_preference": "NO_SHIPPING",
"landing_page": "billing"
},
# Set payment method
"payer": {
"payment_method": "paypal",
"payer_info": {
"email": email,
"first_name": first_name,
"last_name": last_name,
"shipping_address": {
"phone": phone,
}
}
},
# Set redirect URLs
"redirect_urls": {
"return_url": "example.com/confpayment/",
"cancel_url": "examplecom/payment_fail/"
},
# Set transaction object
"transactions": [{
"amount": {
"total": str(amount),
# "total": "1",
"currency": "INR"
},
"description": "payment description"
}]
})
I am getting Incoming JSON request does not map to API request
Error:{'name': 'MALFORMED_REQUEST', 'message': 'Incoming JSON request does not map to API request', 'information_link': 'https://developer.paypal.com/webapps/developer/docs/api/#MALFORMED_REQUEST', 'debug_id': '51397a89429bd'}
All other things are prefilled except for mobile number.
Please help me out on this.
I am not sure whether the API format is correct or not.
Edit preview code is wrong :
Documentation of the payer property here (link corrected to V2) :
https://developer.paypal.com/docs/api/orders/v2/?mark=payer#definition-payer
Error, remove the extra comma at : "phone": "",
"payer_info": {
...
"shipping_address": {
"phone": ""
}
}
THIS CODE SEEMS TO BE WRONG :
Move the phone outside the shipping_address :
"payer_info": {
...
"shipping_address": {
...
},
"phone": ""
}
Full samples here : http://www.seneca-re.com/wp-content/plugins/estatik/vendor/paypal/rest-api-sdk-php/sample/payments/ListPayments.php
In my python project I have to implement paypal recurring payments.
I have installed the paypal sdk and created a file to create a PayPal payment page, like this:
import paypalrestsdk
from paypalrestsdk import BillingPlan
from paypalrestsdk import BillingAgreement
from paypalrestsdk import Payment
import webbrowser
from urllib import parse
paypalrestsdk.configure({
'mode': 'sandbox', # sandbox or live
'client_id': <my app client id>,
'client_secret': <my app secret>})
def create_bill():
billing_plan = BillingPlan({
"name": "Plan with Regular and Trial Payment Definitions",
"description": "Plan with regular and trial payment definitions.",
"type": "INFINITE",
"payment_definitions": [
{
"name": "Regular payment definition",
"type": "REGULAR",
"frequency": "MONTH",
"frequency_interval": "1",
"amount": {
"value": "100",
"currency": "USD"
},
"cycles": "0",
"charge_models": [
{
"type": "SHIPPING",
"amount": {
"value": "10",
"currency": "USD"
}
},
{
"type": "TAX",
"amount": {
"value": "12",
"currency": "USD"
}
}
]
},
{
"name": "Trial payment definition",
"type": "TRIAL",
"frequency": "WEEK",
"frequency_interval": "5",
"amount": {
"value": "9.19",
"currency": "USD"
},
"cycles": "2",
"charge_models": [
{
"type": "SHIPPING",
"amount": {
"value": "1",
"currency": "USD"
}
},
{
"type": "TAX",
"amount": {
"value": "2",
"currency": "USD"
}
}
]
}
],
"merchant_preferences": {
"setup_fee": {
"value": "1",
"currency": "USD"
},
"return_url": "https://example.com",
"cancel_url": "https://example.com/cancel",
"auto_bill_amount": "YES",
"initial_fail_amount_action": "CONTINUE",
"max_fail_attempts": "0"
}
})
# Create billing plan
if billing_plan.create():
print("Billing Plan [%s] created successfully" % billing_plan.id)
# Activate billing plan
if billing_plan.activate():
billing_plan = BillingPlan.find(billing_plan.id)
print("Billing Plan [%s] state changed to %s" % (billing_plan.id, billing_plan.state))
return billing_plan
else:
print(billing_plan.error)
else:
print(billing_plan.error)
def create_agreement(ret_bil):
billing_agreement = BillingAgreement({
"name": "Fast Speed Agreement",
"description": "Agreement for Fast Speed Plan",
"start_date": "2018-03-29T00:37:04Z",
"plan": {
"id": str(ret_bil.id)
},
"payer": {
"payment_method": "paypal"
},
"shipping_address": {
"line1": "StayBr111idge Suites",
"line2": "Cro12ok Street",
"city": "San Jose",
"state": "CA",
"postal_code": "95112",
"country_code": "US"
}
})
if billing_agreement.create():
# Extract redirect url
for link in billing_agreement.links:
if link.method == "REDIRECT":
# Capture redirect url
redirect_url = str(link.href)
# REDIRECT USER TO redirect_url
webbrowser.open(redirect_url)
else:
print(billing_agreement.error)
if __name__ == "__main__":
create_agreement(create_bill())
But when I run the code above, Paypal starts with agreement description but I can't see the item details and description defined in the BilingPlan (I expected to see the detail about items, trial period, amount, recurrence etc)
Is there something wrong in my code? This is the first time I implement Paypal in my project; have I written my code correctly to implement recurrent payments?
So many Thanks in advance
PayPal will not show the recurring period, amount and service details.
You have to show that in your website's page and proceed to PayPal.
When I post to the Connector Service after receiving a message from Microsoft teams I am getting a 404 response with this in the body.
{"error":{"code":"Unclassified","message":""}}
The service is working with skype and was working with teams until about 10 days ago.
I have tried both the ReplyToActivity and RespondToConversation endpoints. I also tried encoding the : in the conversation.id.
The code can be see here: https://github.com/Grungnie/microsoftbotframework/blob/FixTeamsError732/microsoftbotframework/response.py in the method reply_to_activity.
The message received from Microsoft (id tags changed slightly)
{
"text": "Test Message",
"textFormat": "plain",
"type": "message",
"timestamp": "2017-03-27T11:55:33.983Z",
"id": "1490615736123",
"channelId": "msteams",
"serviceUrl": "https://smba.trafficmanager.net/apac-client-ss.msg/",
"from": {
"id": "29:10U0pO0yzCqc_TZQImyaX1JGhe9KWpagDIwqtTl0moeT2lNC4PMrm9B2W_0w-Cr9tr5rty8vEZErb4yoyautked",
"name": "Matthew Brown"
},
"conversation": {
"id": "a:1lRzVTZeip__5jthfxCqiWX8koXTOg5OsFsnefe2kesHxvJAcJxNJs-TT3NvR1ote1PZZ_DQVkd5u5wsKmw2TQy53bvXOlXydDJjUUcolfphZWu2N-HuX8181rfRIMj7Q"
},
"recipient": {
"id": "28:5e21d7a8-d1b5-4534-f549-f521712f5a64",
"name": "PythonBotFramework"
},
"entities": [
{
"locale": "en-AU",
"country": "AU",
"platform": "Android",
"type": "clientInfo"
}
],
"channelData": {
"tenant": {
"id": "5ghtef8a-55a8-4263-bd84-e03688a2ab2d"
}
}
}
Headers
Host: microsoftbotframework.herokuapp.com
Connection: close
Contextid: tcid=5448949784053522007, server=EAP010254248242
Authorization: Bearer eyJ0eXAiOiJ....
User-Agent: Microsoft-SkypeBotApi (Microsoft-BotFramework/3.0)
Content-Type: application/json; charset=utf-8
X-Request-Id: 6d8510c4-e3ba-4e34-80b2-45305a38d022
X-Forwarded-For: 13.75.95.64
X-Forwarded-Proto: https
X-Forwarded-Port: 443
Via: 1.1 vegur
Connect-Time: 0
X-Request-Start: 1490615736123
Total-Route-Time: 0
Content-Length: 747
My Response
URL
https://smba.trafficmanager.net/v3/conversations/a:1lRzVTZeip__5jthfxCqiWX8koXTOg5OsFsnefe2kesHxvJAcJxNJs-TT3NvR1ote1PZZ_DQVkd5u5wsKmw2TQy53bvXOlXydDJjUUcolfphZWu2N-HuX8181rfRIMj7Q/activities/1490615736123
Headers
Authorization: Bearer eyJ0eXAgibJ....
Body
{
"from": {
"id": "28:5e21d7a8-d1b5-4534-f549-f521712f5a64",
"name": "PythonBotFramework"
},
"type": "message",
"timestamp": "2017-03-27T11:55:36.463971Z",
"conversation": {
"id": "a:1lRzVTZeip__5jthfxCqiWX8koXTOg5OsFsnefe2kesHxvJAcJxNJs-TT3NvR1ote1PZZ_DQVkd5u5wsKmw2TQy53bvXOlXydDJjUUcolfphZWu2N-HuX8181rfRIMj7Q"
},
"recipient": {
"id": "29:10U0pO0yzCqc_TZQImyaX1JGhe9KWpagDIwqtTl0moeT2lNC4PMrm9B2W_0w-Cr9tr5rty8vEZErb4yoyautked",
"name": "Matthew BROWN"
},
"text": "How bout no",
"replyToId": "1490615736123",
"serviceUrl": "https://smba.trafficmanager.net/apac-client-ss.msg/",
"channelId": "msteams",
"channelData": {
"tenant": {
"id": "5ghtef8a-55a8-4263-bd84-e03688a2ab2d"
}
},
"textFormat": "plain"
}
** Updated after the error code changed on the 29/3. Previous error code below.
{"errorCode":732,"message":""}
So I made a mistake,
response_url = urljoin(self["serviceUrl"], "/v3/conversations/{}/activities/{}".format( conversation_id, reply_to_id))
urljoin is stripping the last part of the url off self["serviceUrl"]. This is the expected behaviour. There doesn't seem to be a method that joins 2 parts of a url together. I wanted to do this as microsoft sometimes sends the url ending with a "/" and sometimes not. I guess I will just write my own method.
While following the example of create-shipments ,i am getting this error response
{
"errors": [
{
"message": "The request failed authentication",
"error_code": "API_001",
"error_name": "Unauthenticated request"
}
]
}
here is my example code:
import json,requests
headers = {"account-number":"1234567890",'auth-key':'aaaaaaaa-1111-2222-927d-c793f4fb1461','Content-Type': 'application/json'}
print requests.post('https://digitalapi.auspost.com.au/shipping/v1/shipments', data=json.dumps(data), headers=headers).content
and data is something like:
data={
"shipments":[
{
"shipment_reference":"XYZ-s001-01",
"customer_reference_1":"Order S00o1",
"customer_reference_2":"SKU-1",
"email_tracking_enabled":True,
"from":{
"name":"prakash sharma",
"lines": [
"1 Main Street"
],
"suburb": "MELBOURNE",
"state": "VIC",
"postcode": "3000",
"phone": "0401234567",
"email":"prakashsharmacs24#gmail.com"
},
"to":{
"name":"Jane Smith",
"business_name":"Smith Pty Ltd",
"lines":[
"123 Centre Road"
],
"suburb":"Sydney",
"state":"NSW",
"postcode":"2000",
"phone":"0412345678",
"email":"jane.smith#smith.com"
},
"items":[
{
"item_reference":"SKU-1",
"product_id":"T28S",
"length":"10",
"height":"10",
"width":"10",
"weight":"1",
"authority_to_leave":False,
"allow_partial_delivery":True,
"features":{
"TRANSIT_COVER":{
"attributes":{
"cover_amount":1000
}
}
}
}
]
}
]
}
My auth key and account-number are valid as it work in case of GET request over /postage/parcel/international/service.json and /postage/parcel/domestic/service.json
Problem is solved, as shipping/v1/shipments required Basic Authorization so we need to set the header as
:
headers={'Content-Type':'application/json',
'Authorization':'Basic '+base64.b64encode(API_Key+":"+Password_Secret),
'Account-Number':AccountNumber}
OR
we can use HTTPBasicAuth as auth=HTTPBasicAuth(API_Key, Password_Secret) in the requests.post.