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
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"
}
]
}
]
}
Can't solve problem with POST and PUT request in strapi.io. My Relation is 1 to many (a ticket can have 1 category, a category can have many tickets).
GET request looks like this:
{
"data": {
"id": 1,
"attributes": {
"first_name": "Alex",
"last_name": "Porter",
"phone": "+74955978965",
"company": "Test",
"entry_time": null,
"entered": false,
"email": "test#test.com",
"count_entry": 0,
"createdAt": "2022-05-06T10:21:22.753Z",
"updatedAt": "2022-05-20T11:43:57.707Z",
"publishedAt": "2022-05-06T10:21:23.680Z",
"photo": {
"data": null
},
"category": {
"data": {
"id": 1,
"attributes": {
"name": "Junior",
"createdAt": "2022-05-20T11:36:46.360Z",
"updatedAt": "2022-05-20T11:37:17.517Z",
"publishedAt": "2022-05-20T11:37:17.516Z"
}
}
}
}
},
"meta": {}
}
This is what my function looks like with a PUT request:
def edit_member(self, member_id, first_name, last_name, phone, category):
url = config.SERVER + f'api/members/{member_id}?populate=%2A'
payload = {
'data': {
"attributes": {
"first_name": first_name,
"last_name": last_name,
"phone": phone,
},
"category": {
"data": {
"attributes": {
"name": category
}
}
}
}
}
headers = {
'Authorization': f'Bearer {config.TOKEN}',
'Content-Type': 'application/json'
}
requests.request("PUT", url, headers=headers, json=payload)
As a result, the data appears on the strapi, but the relation is lost (remains empty). Tell me, please, where to look?
Thank you in advance.
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.
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.
I have a response object that I am receiving from an api call. The response has several objects that are returned in a single call. What I want to do is grab information from each of the objects returned and store them in varialbes to use them within the application. I know to grab info from a json response when it returns a single objects but I am getting confused with multiples objects... I know how to automate the iteration process through something like a forloop... it wont iterate.
here is a sample response that I am getting:
I want to grab the _id from both items.
{
'user':"<class 'synapse_pay_rest.models.users.user.User'>(id=..622d)",
'json':{
'_id':'..6e80',
'_links':{
'self':{
'href':'https://uat-api.synapsefi.com/v3.1/users/..22d/nodes/..56e80'
}
},
'allowed':'CREDIT-AND-DEBIT',
'client':{
'id':'..26a34',
'name':'Charlie Brown LLC'
},
'extra':{
'note':None,
'other':{
},
'supp_id':''
},
'info':{
'account_num':'8902',
'address':'PO BOX 85139, RICHMOND, VA, US',
'balance':{
'amount':'750.00',
'currency':'USD'
},
'bank_long_name':'CAPITAL ONE N.A.',
'bank_name':'CAPITAL ONE N.A.',
'class':'SAVINGS',
'match_info':{
'email_match':'not_found',
'name_match':'not_found',
'phonenumber_match':'not_found'
},
'name_on_account':' ',
'nickname':'SynapsePay Test Savings Account - 8902',
'routing_num':'6110',
'type':'BUSINESS'
},
<class 'synapse_pay_rest.models.nodes.ach_us_node.AchUsNode'>({
'user':"<class 'synapse_pay_rest.models.users.user.User'>(id=..622d)",
'json':{
'_id':'..56e83',
'_links':{
'self':{
'href':'https://uat-api.synapsefi.com/v3.1/users/..d622d/nodes/..6e83'
}
},
'allowed':'CREDIT-AND-DEBIT',
'client':{
'id':'599378ec6aef1b0021026a34',
'name':'Charlie Brown LLC'
},
'extra':{
'note':None,
'other':{
},
'supp_id':''
},
'info':{
'account_num':'8901',
'address':'PO BOX 85139, RICHMOND, VA, US',
'balance':{
'amount':'800.00',
'currency':'USD'
},
'bank_long_name':'CAPITAL ONE N.A.',
'bank_name':'CAPITAL ONE N.A.',
'class':'CHECKING',
'match_info':{
'email_match':'not_found',
'name_match':'not_found',
'phonenumber_match':'not_found'
},
'name_on_account':' ',
'nickname':'SynapsePay Test Checking Account - 8901',
'routing_num':'6110',
'type':'BUSINESS'
},
})
Here is the code that I have:
It wont grab any values...
the iteration needs to be done to the nodes variable which is hte json response object.
def listedLinkAccounts(request):
currentUser = loggedInUser(request)
currentProfile = Profile.objects.get(user = currentUser)
user_id = currentProfile.synapse_id
synapseUser = SynapseUser.by_id(client, str(user_id))
options = {
'page':1,
'per_page':20,
'type': 'ACH-US',
}
nodes = Node.all(synapseUser, **options)
print(nodes)
response = nodes
_id = response["_id"]
print(_id)
return nodes
here is a sample api response from the api documenation:
{
"error_code": "0",
"http_code": "200",
"limit": 20,
"node_count": 5,
"nodes": [
{
"_id": "594e5c694d1d62002f17e3dc",
"_links": {
"self": {
"href": "https://uat-api.synapsefi.com/v3.1/users/594e0fa2838454002ea317a0/nodes/594e5c694d1d62002f17e3dc"
}
},
"allowed": "CREDIT-AND-DEBIT",
"client": {
"id": "589acd9ecb3cd400fa75ac06",
"name": "SynapseFI"
},
"extra": {
"other": {},
"supp_id": "ABC124"
},
"info": {
"account_num": "7443",
"address": "PLACE DE LA REPUBLIQUE 4 CROIX 59170 FR",
"balance": {
"amount": "0.00",
"currency": "USD"
},
"bank_long_name": "3 SUISSES INTERNATIONAL",
"bank_name": "3 SUISSES INTERNATIONAL",
"name_on_account": " ",
"nickname": "Some Account"
},
"is_active": true,
"timeline": [
{
"date": 1498307689471,
"note": "Node created."
},
{
"date": 1498307690130,
"note": "Unable to send micro deposits as node type is not ACH-US."
}
],
"type": "WIRE-INT",
"user_id": "594e0fa2838454002ea317a0"
},
{
...
},
{
...
},
...
],
"page": 1,
"page_count": 1,
"success": true
}