Skip to main content

PayPal Community

  • Dashboard
  • Send and Request
  • Wallet
  • Business
  • Help
Log in
  • Welcome
    • Guidelines
    • News and Events
    • Suggestions for PayPal
    • General Discussions
  • PayPal Help Community
    • Managing Account
    • Transactions
    • Wallet
    • Security and Fraud
    • Products & Services
    • Reporting
  • MTS Community
    • PayPal Upgrade Community
    • PayPal Payments Standard
    • REST APIs
    • NVP/SOAP APIs
    • SDKs
    • Sandbox Environment
    • PayPal Reporting
    • Payflow
    • Ideas for MTS
    • Client-side Integration
    • Server-side Integration
  • The Archives
    • PayPal Help Community Archives
      • Managing Account Archives
      • Transactions Archives
      • Wallet Archives
      • Security and Fraud Archives
      • Products & Services Archives
      • Reporting Archives
    • Help Community
      • PayPal Basics Archives
      • Payments Archives
      • My Money Archives
      • My Account Archives
      • Disputes and Limitations Archives
      • Products and Services Archives
      • PayPal Credit Archives
    • Merchant Community
      • Merchant Products
      • Business Tools Archives
      • Reporting Archives
      • Managing Risk and Fraud Archives
    • Help Archives
      • About Business (Archive)
      • About Payments (Archive)
      • About Settings (Archive)
      • About eBay (Archive)
      • About Protections (Archive)
      • About Products (Archive)
    • Social and Your Voice Archives
      • Off Topic (Archive)
      • My Feedback for PayPal (Archive)
    • About PayPal Archives
      • Watercooler (Archive)
      • Tax Information (Archive)
      • Fees (Archive)
      • eBay and PayPal (Archive)
      • Coupons and promotions (Archive)
    • My Account Archives
      • My account settings (Archive)
      • Account limits and verification (Archive)
      • Account balance (Archive)
      • Bank accounts and credit cards (Archive)
    • Payments Archives
      • Sending money (Archive)
      • Receiving money (Archive)
      • Refunds (Archive)
      • Donations and Fundraising (Archive)
    • Disputes and Security Archives
      • Disputes and claims (Archive)
      • Fraud, phishing and spoof (Archive)
    • My Business Archives
      • Merchant services (Archive)
      • Reporting and tracking (Archive)
      • Shipping (Archive)
    • PayPal Products Archives
      • PayPal Debit Mastercard (Archive)
      • PayPal Extras MasterCard (Archive)
      • PayPal Mobile & Other Services (Archive)
      • Student Accounts (Archive)
      • Bill Me Later (Archive)
    • Getting to know PayPal
      • My PayPal account
      • Security and protection
    • Receiving and sending money
      • Buying with PayPal
      • Selling with PayPal
    • PayPal Here UK
      • PayPal Here News and Events
      • PayPal Here Community
      • Chip and Pin Card Reader
      • PayPal Here App

The Community Forum is not available for new posts or responses; previous posts remain available to review. For comprehensive support options, please visit PayPal.com/HelpCenter
Merchant Technical Support: For technical support and related questions, please visit our Technical Support Help Center or Developer Central

If you want to report illegal content under the EU Digital Services Act, please do so here

since ‎Feb-11-2024
Country: Morocco
Type: Business
Ayoub78
Ayoub78 Contributor
Contributor
1
Post
0
Kudos
0
Solutions
The Return
Active
View all
Latest Contributions by Ayoub78
  • Topics Ayoub78 has Participated In
  • Latest Contributions by Ayoub78

I Have PayPal API Billing Authentication Failure P...

by Ayoub78 Contributor in REST APIs
‎Feb-11-2024 06:54 AM
‎Feb-11-2024 06:54 AM
I'm encountering an authentication failure issue while using the PayPal API to create billing plans and handle subscriptions. Here's the error message I'm receiving: {"name":"AUTHENTICATION_FAILURE","message":"Authentication failed due to invalid authentication credentials or a missing Authorization header.","links":[{"href":"https://developer.paypal.com/docs/api/overview/#error","rel":"information_link"}]} This error occurs when attempting to access the URL https://api.sandbox.paypal.com/v1/billing/plans/P-054793526X109145CMXEAUWQ Below is the my code:   @app.route('/purchase', methods=['POST']) @login_required def purchase_subscription(): plan = request.form.get('plan') selected_gateway = request.form.get('payment_gateway') plan_settings = get_plan_settings() if not plan_settings: flash('Failed to fetch plan settings from the database.', 'danger') return redirect(url_for('subscription')) credits_to_add = 0 credits_price = 0 subscription_type = None subscription_start_date = None subscription_end_date = None subscription_type_mapping = { 'plan1': 'monthly', 'plan2': 'monthly', 'plan3': 'monthly', 'plan4': 'yearly', 'plan5': 'yearly', 'plan6': 'yearly' } if plan in subscription_type_mapping: subscription_type = subscription_type_mapping[plan] if subscription_type == 'monthly': frequency = "MONTH" elif subscription_type == 'yearly': frequency = "YEAR" credits_to_add = plan_settings[plan + "_credits"] credits_price = plan_settings[plan + "_price"] else: flash('Invalid plan selected.', 'danger') return redirect(url_for('subscription')) ACCESS_TOKEN = get_access_token(PAYPAL_CLIENT_ID, PAYPAL_CLIENT_SECRET) if ACCESS_TOKEN: print("Access token obtained successfully:", ACCESS_TOKEN) product_id = create_product(plan, credits_price, ACCESS_TOKEN) if product_id: billing_plan = create_billing_plan(plan, frequency, credits_price, product_id, ACCESS_TOKEN) print(billing_plan) return billing_plan # Return the result of create_billing_plan else: flash('Failed to create product.', 'danger') else: print("Failed to obtain access token.") flash('Failed to obtain access token.', 'danger') return redirect(url_for('subscription')) def create_product(plan, amount, access_token): auth_url = 'https://api.sandbox.paypal.com/v1/oauth2/token' product_url = 'https://api.sandbox.paypal.com/v1/catalogs/products' print(f"Access token in app.py {access_token}") headers = { 'Content-Type': 'application/json', 'Accept-Language': 'en_US', 'Authorization': f'Bearer {access_token}' } # Create product product_data = { "name": f"{plan.capitalize()} Subscription", "description": f"{plan.capitalize()} Subscription", "type": "SERVICE", "category": "SOFTWARE" } response = requests.post(product_url, headers=headers, json=product_data) if response.status_code == 201: return response.json().get('id') else: print(f"Failed to create product: {response.text}") return None def create_billing_plan(plan, frequency, amount, product_id, access_token): auth_url = 'https://api.sandbox.paypal.com/v1/oauth2/token' plan_url = 'https://api.sandbox.paypal.com/v1/billing/plans' headers = { 'Accept': 'application/json', 'Accept-Language': 'en_US', 'Authorization': f'Bearer {access_token}' } # Create billing plan plan_data = { "product_id": product_id, "name": f"{plan.capitalize()} Subscription", "description": f"{plan.capitalize()} Subscription", "billing_cycles": [{ "frequency": { "interval_unit": frequency, "interval_count": 1 }, "tenure_type": "REGULAR", "sequence": 1, "total_cycles": 0, "pricing_scheme": { "fixed_price": { "value": str(amount), "currency_code": "USD" } } }], "payment_preferences": { "auto_bill_outstanding": True, "setup_fee": { "value": "0", "currency_code": "USD" }, "setup_fee_failure_action": "CONTINUE", "payment_failure_threshold": 3 }, "quantity_supported": False, "taxes": { "percentage": "0", "inclusive": False } } response = requests.post(plan_url, headers=headers, json=plan_data) if response.status_code == 201: plan_response = response.json() plan_id = plan_response.get('id') redirect_url = f'{plan_url}/{plan_id}' return redirect(redirect_url) else: print(f"Failed to create billing plan: {response.text}") return None Im' 100% sure the access token & client id and secret are correct and i have "Subscription" permission checked Any insights or suggestions on how to troubleshoot and resolve this issue would be greatly appreciated. Thank you! ... View more
Paypal Logo
  • Help
  • Contact Us
  • Security
  • Fees
  • © 1999-2025 PayPal, Inc. All rights reserved.
  • Privacy
  • Legal
  • Cookies
  • Policy Updates

The money in your balance is eligible for pass-through FDIC insurance.

The PayPal Cash Mastercard is issued by The Bancorp Bank pursuant to a license by Mastercard International Incorporated. The Bancorp Bank; Member FDIC.

Powered by Khoros
Welcome to the PayPal Community!