Search code examples
paypalodooodoo-12

PayPal Refund Transaction Authorisation Issue


I'm working on Odoo version 12.0, developing the process of Refund Sale Transaction using their API. I've taken reference from the following link: https://developer.paypal.com/docs/api/payments/v1/#sale_refund

But there is some authorization issue with their API of the refund transaction.

I've example request/response parameters like the following:

import requests

headers = {'Content-Type': 'application/json','Authorization': 'Bearer Access-Token'}

data = '{\n  "amount": {\n    "total": "2.34",\n    "currency": "USD"\n  },\n  "invoice_number": "INV-1234567"\n}'

response = requests.post('https://api.sandbox.paypal.com/v1/payments/sale/2MU78835H4515710F/refund', headers=headers, data=data)

It gives me the following response:

{'message': 'Authentication failed due to invalid authentication credentials or a missing Authorization header.', 'links': [{'rel': 'information_link', 'href': 'https://developer.paypal.com/docs/api/overview/#error'}], 'name': 'AUTHENTICATION_FAILURE'}

Can anyone help me to resolve this issue?

And how to generate bearer token using PayPal Payment API?


Solution

  • The Authorization header needs to contain an actual Access Token after the word 'Bearer '. Sending the string 'Access Token' will not work.

    Here is how to obtain an actual access token: https://developer.paypal.com/docs/api/overview/#get-an-access-token