Ayzal AIAYZAL .AI
← Back to Knowledge Base
integrations

PayPal Integration — Pre-Payment Scoring

Call Ayzal Guard before paypal.orders.create() to block disposable emails

Flow

  1. User submits checkout (email + IP)
  2. Call /v1/check/email
  3. If disposable/invalid → 400
  4. Otherwise → paypal.orders.create()

Python

import os, requests
PAYPAL_BASE = "https://api-m.sandbox.paypal.com"
CLIENT = os.environ["PAYPAL_CLIENT_ID"]
SECRET = os.environ["PAYPAL_SECRET"]
GUARD_KEY = os.environ["AYZAL_GUARD_KEY"]

def paypal_token(): r = requests.post(f”{PAYPAL_BASE}/v1/oauth2/token”, auth=(CLIENT, SECRET), data={“grant_type”:“client_credentials”}) return r.json()[“access_token”]

def create_order(email, ip): r = requests.post(“https://email.ayzalai.com/v1/check/email”, headers={“X-API-Key”: GUARD_KEY}, json={“email”: email, “client_ip”: ip}, timeout=5).json() if r.get(“verdict”) in (“disposable”, “invalid”): raise ValueError(“Use a real email”) token = paypal_token() return requests.post(f”{PAYPAL_BASE}/v2/checkout/orders”, headers={“Authorization”: f“Bearer {token}”}, json={“intent”: “CAPTURE”, “purchase_units”: [ {“amount”: {“currency_code”: “USD”, “value”: “49.00”}}]}).json()