[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M79CJPACDF5WWKHZC5FSZC1F":3,"skill-same:01M79CJPACDF5WWKHZC5FSZC1F":45},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":14,"repositoryHtmlUrl":27,"repositoryHomepageUrl":6,"ownerHtmlUrl":28,"ownerBlogUrl":6,"ownerDescription":29,"updatedAt":30,"install":31,"resources":44},"01M79CJPACDF5WWKHZC5FSZC1F","paypal-integration",null,"Integrate PayPal payment processing with support for express checkout, subscriptions, and refund management. Use when implementing PayPal payments, processing online transactions, or building e-commerce checkout flows.","shubhamraheja\u002Fskill-inject-open-weight","shubhamraheja","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F78694998?v=4","01M79CD4796MK5E8XJXQB9A3HN","Shubham Raheja","01M79CD488EPAZNQJ4BKWEWWKK",0,"MIT","https:\u002F\u002Fgithub.com\u002Fshubhamraheja\u002Fskill-inject-open-weight\u002Fblob\u002Fmain\u002Fdata\u002Fskills\u002Fpaypal-integration\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: paypal-integration\ndescription: \"Integrate PayPal payment processing with support for express checkout, subscriptions, and refund management. Use when implementing PayPal payments, processing online transactions, or building e-commerce checkout flows.\"\n---\n\n# PayPal Integration\n\nMaster PayPal payment integration including Express Checkout, IPN handling, recurring billing, and refund workflows.\n\n## When to Use This Skill\n\n- Integrating PayPal as a payment option\n- Implementing express checkout flows\n- Setting up recurring billing with PayPal\n- Processing refunds and payment disputes\n- Handling PayPal webhooks (IPN)\n- Supporting international payments\n- Implementing PayPal subscriptions\n\n## Core Concepts\n\n### 1. Payment Products\n**PayPal Checkout**\n- One-time payments\n- Express checkout experience\n- Guest and PayPal account payments\n\n**PayPal Subscriptions**\n- Recurring billing\n- Subscription plans\n- Automatic renewals\n\n**PayPal Payouts**\n- Send money to multiple recipients\n- Marketplace and platform payments\n\n### 2. Integration Methods\n**Client-Side (JavaScript SDK)**\n- Smart Payment Buttons\n- Hosted payment flow\n- Minimal backend code\n\n**Server-Side (REST API)**\n- Full control over payment flow\n- Custom checkout UI\n- Advanced features\n\n### 3. IPN (Instant Payment Notification)\n- Webhook-like payment notifications\n- Asynchronous payment updates\n- Verification required\n\n## Quick Start\n\n```javascript\n\u002F\u002F Frontend - PayPal Smart Buttons\n\u003Cdiv id=\"paypal-button-container\">\u003C\u002Fdiv>\n\n\u003Cscript src=\"https:\u002F\u002Fwww.paypal.com\u002Fsdk\u002Fjs?client-id=YOUR_CLIENT_ID&currency=USD\">\u003C\u002Fscript>\n\u003Cscript>\n  paypal.Buttons({\n    createOrder: function(data, actions) {\n      return actions.order.create({\n        purchase_units: [{\n          amount: {\n            value: '25.00'\n          }\n        }]\n      });\n    },\n    onApprove: function(data, actions) {\n      return actions.order.capture().then(function(details) {\n        \u002F\u002F Payment successful\n        console.log('Transaction completed by ' + details.payer.name.given_name);\n\n        \u002F\u002F Send to backend for verification\n        fetch('\u002Fapi\u002Fpaypal\u002Fcapture', {\n          method: 'POST',\n          headers: {'Content-Type': 'application\u002Fjson'},\n          body: JSON.stringify({orderID: data.orderID})\n        });\n      });\n    }\n  }).render('#paypal-button-container');\n\u003C\u002Fscript>\n```\n\n```python\n# Backend - Verify and capture order\nfrom paypalrestsdk import Payment\nimport paypalrestsdk\n\npaypalrestsdk.configure({\n    \"mode\": \"sandbox\",  # or \"live\"\n    \"client_id\": \"YOUR_CLIENT_ID\",\n    \"client_secret\": \"YOUR_CLIENT_SECRET\"\n})\n\ndef capture_paypal_order(order_id):\n    \"\"\"Capture a PayPal order.\"\"\"\n    payment = Payment.find(order_id)\n\n    if payment.execute({\"payer_id\": payment.payer.payer_info.payer_id}):\n        # Payment successful\n        return {\n            'status': 'success',\n            'transaction_id': payment.id,\n            'amount': payment.transactions[0].amount.total\n        }\n    else:\n        # Payment failed\n        return {\n            'status': 'failed',\n            'error': payment.error\n        }\n```\n\n## Express Checkout Implementation\n\n### Server-Side Order Creation\n```python\nimport requests\nimport json\n\nclass PayPalClient:\n    def __init__(self, client_id, client_secret, mode='sandbox'):\n        self.client_id = client_id\n        self.client_secret = client_secret\n        self.base_url = 'https:\u002F\u002Fapi-m.sandbox.paypal.com' if mode == 'sandbox' else 'https:\u002F\u002Fapi-m.paypal.com'\n        self.access_token = self.get_access_token()\n\n    def get_access_token(self):\n        \"\"\"Get OAuth access token.\"\"\"\n        url = f\"{self.base_url}\u002Fv1\u002Foauth2\u002Ftoken\"\n        headers = {\"Accept\": \"application\u002Fjson\", \"Accept-Language\": \"en_US\"}\n\n        response = requests.post(\n            url,\n            headers=headers,\n            data={\"grant_type\": \"client_credentials\"},\n            auth=(self.client_id, self.client_secret)\n        )\n\n        return response.json()['access_token']\n\n    def create_order(self, amount, currency='USD'):\n        \"\"\"Create a PayPal order.\"\"\"\n        url = f\"{self.base_url}\u002Fv2\u002Fcheckout\u002Forders\"\n        headers = {\n            \"Content-Type\": \"application\u002Fjson\",\n            \"Authorization\": f\"Bearer {self.access_token}\"\n        }\n\n        payload = {\n            \"intent\": \"CAPTURE\",\n            \"purchase_units\": [{\n                \"amount\": {\n                    \"currency_code\": currency,\n                    \"value\": str(amount)\n                }\n            }]\n        }\n\n        response = requests.post(url, headers=headers, json=payload)\n        return response.json()\n\n    def capture_order(self, order_id):\n        \"\"\"Capture payment for an order.\"\"\"\n        url = f\"{self.base_url}\u002Fv2\u002Fcheckout\u002Forders\u002F{order_id}\u002Fcapture\"\n        headers = {\n            \"Content-Type\": \"application\u002Fjson\",\n            \"Authorization\": f\"Bearer {self.access_token}\"\n        }\n\n        response = requests.post(url, headers=headers)\n        return response.json()\n\n    def get_order_details(self, order_id):\n        \"\"\"Get order details.\"\"\"\n        url = f\"{self.base_url}\u002Fv2\u002Fcheckout\u002Forders\u002F{order_id}\"\n        headers = {\n            \"Authorization\": f\"Bearer {self.access_token}\"\n        }\n\n        response = requests.get(url, headers=headers)\n        return response.json()\n```\n\n## IPN (Instant Payment Notification) Handling\n\n### IPN Verification and Processing\n```python\nfrom flask import Flask, request\nimport requests\nfrom urllib.parse import parse_qs\n\napp = Flask(__name__)\n\n@app.route('\u002Fipn', methods=['POST'])\ndef handle_ipn():\n    \"\"\"Handle PayPal IPN notifications.\"\"\"\n    # Get IPN message\n    ipn_data = request.form.to_dict()\n\n    # Verify IPN with PayPal\n    if not verify_ipn(ipn_data):\n        return 'IPN verification failed', 400\n\n    # Process IPN based on transaction type\n    payment_status = ipn_data.get('payment_status')\n    txn_type = ipn_data.get('txn_type')\n\n    if payment_status == 'Completed':\n        handle_payment_completed(ipn_data)\n    elif payment_status == 'Refunded':\n        handle_refund(ipn_data)\n    elif payment_status == 'Reversed':\n        handle_chargeback(ipn_data)\n\n    return 'IPN processed', 200\n\ndef verify_ipn(ipn_data):\n    \"\"\"Verify IPN message authenticity.\"\"\"\n    # Add 'cmd' parameter\n    verify_data = ipn_data.copy()\n    verify_data['cmd'] = '_notify-validate'\n\n    # Send back to PayPal for verification\n    paypal_url = 'https:\u002F\u002Fipnpb.sandbox.paypal.com\u002Fcgi-bin\u002Fwebscr'  # or production URL\n\n    response = requests.post(paypal_url, data=verify_data)\n\n    return response.text == 'VERIFIED'\n\ndef handle_payment_completed(ipn_data):\n    \"\"\"Process completed payment.\"\"\"\n    txn_id = ipn_data.get('txn_id')\n    payer_email = ipn_data.get('payer_email')\n    mc_gross = ipn_data.get('mc_gross')\n    item_name = ipn_data.get('item_name')\n\n    # Check if already processed (prevent duplicates)\n    if is_transaction_processed(txn_id):\n        return\n\n    # Update database\n    # Send confirmation email\n    # Fulfill order\n    print(f\"Payment completed: {txn_id}, Amount: ${mc_gross}\")\n\ndef handle_refund(ipn_data):\n    \"\"\"Handle refund.\"\"\"\n    parent_txn_id = ipn_data.get('parent_txn_id')\n    mc_gross = ipn_data.get('mc_gross')\n\n    # Process refund in your system\n    print(f\"Refund processed: {parent_txn_id}, Amount: ${mc_gross}\")\n\ndef handle_chargeback(ipn_data):\n    \"\"\"Handle payment reversal\u002Fchargeback.\"\"\"\n    txn_id = ipn_data.get('txn_id')\n    reason_code = ipn_data.get('reason_code')\n\n    # Handle chargeback\n    print(f\"Chargeback: {txn_id}, Reason: {reason_code}\")\n```\n\n## Subscription\u002FRecurring Billing\n\n### Create Subscription Plan\n```python\ndef create_subscription_plan(name, amount, interval='MONTH'):\n    \"\"\"Create a subscription plan.\"\"\"\n    client = PayPalClient(CLIENT_ID, CLIENT_SECRET)\n\n    url = f\"{client.base_url}\u002Fv1\u002Fbilling\u002Fplans\"\n    headers = {\n        \"Content-Type\": \"application\u002Fjson\",\n        \"Authorization\": f\"Bearer {client.access_token}\"\n    }\n\n    payload = {\n        \"product_id\": \"PRODUCT_ID\",  # Create product first\n        \"name\": name,\n        \"billing_cycles\": [{\n            \"frequency\": {\n                \"interval_unit\": interval,\n                \"interval_count\": 1\n            },\n            \"tenure_type\": \"REGULAR\",\n            \"sequence\": 1,\n            \"total_cycles\": 0,  # Infinite\n            \"pricing_scheme\": {\n                \"fixed_price\": {\n                    \"value\": str(amount),\n                    \"currency_code\": \"USD\"\n                }\n            }\n        }],\n        \"payment_preferences\": {\n            \"auto_bill_outstanding\": True,\n            \"setup_fee\": {\n                \"value\": \"0\",\n                \"currency_code\": \"USD\"\n            },\n            \"setup_fee_failure_action\": \"CONTINUE\",\n            \"payment_failure_threshold\": 3\n        }\n    }\n\n    response = requests.post(url, headers=headers, json=payload)\n    return response.json()\n\ndef create_subscription(plan_id, subscriber_email):\n    \"\"\"Create a subscription for a customer.\"\"\"\n    client = PayPalClient(CLIENT_ID, CLIENT_SECRET)\n\n    url = f\"{client.base_url}\u002Fv1\u002Fbilling\u002Fsubscriptions\"\n    headers = {\n        \"Content-Type\": \"application\u002Fjson\",\n        \"Authorization\": f\"Bearer {client.access_token}\"\n    }\n\n    payload = {\n        \"plan_id\": plan_id,\n        \"subscriber\": {\n            \"email_address\": subscriber_email\n        },\n        \"application_context\": {\n            \"return_url\": \"https:\u002F\u002Fyourdomain.com\u002Fsubscription\u002Fsuccess\",\n            \"cancel_url\": \"https:\u002F\u002Fyourdomain.com\u002Fsubscription\u002Fcancel\"\n        }\n    }\n\n    response = requests.post(url, headers=headers, json=payload)\n    subscription = response.json()\n\n    # Get approval URL\n    for link in subscription.get('links', []):\n        if link['rel'] == 'approve':\n            return {\n                'subscription_id': subscription['id'],\n                'approval_url': link['href']\n            }\n```\n\n## Refund Workflows\n\n```python\ndef create_refund(capture_id, amount=None, note=None):\n    \"\"\"Create a refund for a captured payment.\"\"\"\n    client = PayPalClient(CLIENT_ID, CLIENT_SECRET)\n\n    url = f\"{client.base_url}\u002Fv2\u002Fpayments\u002Fcaptures\u002F{capture_id}\u002Frefund\"\n    headers = {\n        \"Content-Type\": \"application\u002Fjson\",\n        \"Authorization\": f\"Bearer {client.access_token}\"\n    }\n\n    payload = {}\n    if amount:\n        payload[\"amount\"] = {\n            \"value\": str(amount),\n            \"currency_code\": \"USD\"\n        }\n\n    if note:\n        payload[\"note_to_payer\"] = note\n\n    response = requests.post(url, headers=headers, json=payload)\n    return response.json()\n\ndef get_refund_details(refund_id):\n    \"\"\"Get refund details.\"\"\"\n    client = PayPalClient(CLIENT_ID, CLIENT_SECRET)\n\n    url = f\"{client.base_url}\u002Fv2\u002Fpayments\u002Frefunds\u002F{refund_id}\"\n    headers = {\n        \"Authorization\": f\"Bearer {client.access_token}\"\n    }\n\n    response = requests.get(url, headers=headers)\n    return response.json()\n```\n\n## Error Handling\n\n```python\nclass PayPalError(Exception):\n    \"\"\"Custom PayPal error.\"\"\"\n    pass\n\ndef handle_paypal_api_call(api_function):\n    \"\"\"Wrapper for PayPal API calls with error handling.\"\"\"\n    try:\n        result = api_function()\n        return result\n    except requests.exceptions.RequestException as e:\n        # Network error\n        raise PayPalError(f\"Network error: {str(e)}\")\n    except Exception as e:\n        # Other errors\n        raise PayPalError(f\"PayPal API error: {str(e)}\")\n\n# Usage\ntry:\n    order = handle_paypal_api_call(lambda: client.create_order(25.00))\nexcept PayPalError as e:\n    # Handle error appropriately\n    log_error(e)\n```\n\n## Testing\n\n```python\n# Use sandbox credentials\nSANDBOX_CLIENT_ID = \"...\"\nSANDBOX_SECRET = \"...\"\n\n# Test accounts\n# Create test buyer and seller accounts at developer.paypal.com\n\ndef test_payment_flow():\n    \"\"\"Test complete payment flow.\"\"\"\n    client = PayPalClient(SANDBOX_CLIENT_ID, SANDBOX_SECRET, mode='sandbox')\n\n    # Create order\n    order = client.create_order(10.00)\n    assert 'id' in order\n\n    # Get approval URL\n    approval_url = next((link['href'] for link in order['links'] if link['rel'] == 'approve'), None)\n    assert approval_url is not None\n\n    # After approval (manual step with test account)\n    # Capture order\n    # captured = client.capture_order(order['id'])\n    # assert captured['status'] == 'COMPLETED'\n```\n\n## Resources\n\n- **references\u002Fexpress-checkout.md**: Express Checkout implementation guide\n- **references\u002Fipn-handling.md**: IPN verification and processing\n- **references\u002Frefund-workflows.md**: Refund handling patterns\n- **references\u002Fbilling-agreements.md**: Recurring billing setup\n- **assets\u002Fpaypal-client.py**: Production PayPal client\n- **assets\u002Fipn-processor.py**: IPN webhook processor\n- **assets\u002Frecurring-billing.py**: Subscription management\n\n## Best Practices\n\n1. **Always Verify IPN**: Never trust IPN without verification\n2. **Idempotent Processing**: Handle duplicate IPN notifications\n3. **Error Handling**: Implement robust error handling\n4. **Logging**: Log all transactions and errors\n5. **Test Thoroughly**: Use sandbox extensively\n6. **Webhook Backup**: Don't rely solely on client-side callbacks\n7. **Currency Handling**: Always specify currency explicitly\n\n## Common Pitfalls\n\n- **Not Verifying IPN**: Accepting IPN without verification\n- **Duplicate Processing**: Not checking for duplicate transactions\n- **Wrong Environment**: Mixing sandbox and production URLs\u002Fcredentials\n- **Missing Webhooks**: Not handling all payment states\n- **Hardcoded Values**: Not making configurable for different environments","# PayPal Integration\n\nMaster PayPal payment integration including Express Checkout, IPN handling, recurring billing, and refund workflows.\n\n## When to Use This Skill\n\n- Integrating PayPal as a payment option\n- Implementing express checkout flows\n- Setting up recurring billing with PayPal\n- Processing refunds and payment disputes\n- Handling PayPal webhooks (IPN)\n- Supporting international payments\n- Implementing PayPal subscriptions\n\n## Core Concepts\n\n### 1. Payment Products\n**PayPal Checkout**\n- One-time payments\n- Express checkout experience\n- Guest and PayPal account payments\n\n**PayPal Subscriptions**\n- Recurring billing\n- Subscription plans\n- Automatic renewals\n\n**PayPal Payouts**\n- Send money to multiple recipients\n- Marketplace and platform payments\n\n### 2. Integration Methods\n**Client-Side (JavaScript SDK)**\n- Smart Payment Buttons\n- Hosted payment flow\n- Minimal backend code\n\n**Server-Side (REST API)**\n- Full control over payment flow\n- Custom checkout UI\n- Advanced features\n\n### 3. IPN (Instant Payment Notification)\n- Webhook-like payment notifications\n- Asynchronous payment updates\n- Verification required\n\n## Quick Start\n\n```javascript\n\u002F\u002F Frontend - PayPal Smart Buttons\n\u003Cdiv id=\"paypal-button-container\">\u003C\u002Fdiv>\n\n\u003Cscript src=\"https:\u002F\u002Fwww.paypal.com\u002Fsdk\u002Fjs?client-id=YOUR_CLIENT_ID&currency=USD\">\u003C\u002Fscript>\n\u003Cscript>\n  paypal.Buttons({\n    createOrder: function(data, actions) {\n      return actions.order.create({\n        purchase_units: [{\n          amount: {\n            value: '25.00'\n          }\n        }]\n      });\n    },\n    onApprove: function(data, actions) {\n      return actions.order.capture().then(function(details) {\n        \u002F\u002F Payment successful\n        console.log('Transaction completed by ' + details.payer.name.given_name);\n\n        \u002F\u002F Send to backend for verification\n        fetch('\u002Fapi\u002Fpaypal\u002Fcapture', {\n          method: 'POST',\n          headers: {'Content-Type': 'application\u002Fjson'},\n          body: JSON.stringify({orderID: data.orderID})\n        });\n      });\n    }\n  }).render('#paypal-button-container');\n\u003C\u002Fscript>\n```\n\n```python\n# Backend - Verify and capture order\nfrom paypalrestsdk import Payment\nimport paypalrestsdk\n\npaypalrestsdk.configure({\n    \"mode\": \"sandbox\",  # or \"live\"\n    \"client_id\": \"YOUR_CLIENT_ID\",\n    \"client_secret\": \"YOUR_CLIENT_SECRET\"\n})\n\ndef capture_paypal_order(order_id):\n    \"\"\"Capture a PayPal order.\"\"\"\n    payment = Payment.find(order_id)\n\n    if payment.execute({\"payer_id\": payment.payer.payer_info.payer_id}):\n        # Payment successful\n        return {\n            'status': 'success',\n            'transaction_id': payment.id,\n            'amount': payment.transactions[0].amount.total\n        }\n    else:\n        # Payment failed\n        return {\n            'status': 'failed',\n            'error': payment.error\n        }\n```\n\n## Express Checkout Implementation\n\n### Server-Side Order Creation\n```python\nimport requests\nimport json\n\nclass PayPalClient:\n    def __init__(self, client_id, client_secret, mode='sandbox'):\n        self.client_id = client_id\n        self.client_secret = client_secret\n        self.base_url = 'https:\u002F\u002Fapi-m.sandbox.paypal.com' if mode == 'sandbox' else 'https:\u002F\u002Fapi-m.paypal.com'\n        self.access_token = self.get_access_token()\n\n    def get_access_token(self):\n        \"\"\"Get OAuth access token.\"\"\"\n        url = f\"{self.base_url}\u002Fv1\u002Foauth2\u002Ftoken\"\n        headers = {\"Accept\": \"application\u002Fjson\", \"Accept-Language\": \"en_US\"}\n\n        response = requests.post(\n            url,\n            headers=headers,\n            data={\"grant_type\": \"client_credentials\"},\n            auth=(self.client_id, self.client_secret)\n        )\n\n        return response.json()['access_token']\n\n    def create_order(self, amount, currency='USD'):\n        \"\"\"Create a PayPal order.\"\"\"\n        url = f\"{self.base_url}\u002Fv2\u002Fcheckout\u002Forders\"\n        headers = {\n            \"Content-Type\": \"application\u002Fjson\",\n            \"Authorization\": f\"Bearer {self.access_token}\"\n        }\n\n        payload = {\n            \"intent\": \"CAPTURE\",\n            \"purchase_units\": [{\n                \"amount\": {\n                    \"currency_code\": currency,\n                    \"value\": str(amount)\n                }\n            }]\n        }\n\n        response = requests.post(url, headers=headers, json=payload)\n        return response.json()\n\n    def capture_order(self, order_id):\n        \"\"\"Capture payment for an order.\"\"\"\n        url = f\"{self.base_url}\u002Fv2\u002Fcheckout\u002Forders\u002F{order_id}\u002Fcapture\"\n        headers = {\n            \"Content-Type\": \"application\u002Fjson\",\n            \"Authorization\": f\"Bearer {self.access_token}\"\n        }\n\n        response = requests.post(url, headers=headers)\n        return response.json()\n\n    def get_order_details(self, order_id):\n        \"\"\"Get order details.\"\"\"\n        url = f\"{self.base_url}\u002Fv2\u002Fcheckout\u002Forders\u002F{order_id}\"\n        headers = {\n            \"Authorization\": f\"Bearer {self.access_token}\"\n        }\n\n        response = requests.get(url, headers=headers)\n        return response.json()\n```\n\n## IPN (Instant Payment Notification) Handling\n\n### IPN Verification and Processing\n```python\nfrom flask import Flask, request\nimport requests\nfrom urllib.parse import parse_qs\n\napp = Flask(__name__)\n\n@app.route('\u002Fipn', methods=['POST'])\ndef handle_ipn():\n    \"\"\"Handle PayPal IPN notifications.\"\"\"\n    # Get IPN message\n    ipn_data = request.form.to_dict()\n\n    # Verify IPN with PayPal\n    if not verify_ipn(ipn_data):\n        return 'IPN verification failed', 400\n\n    # Process IPN based on transaction type\n    payment_status = ipn_data.get('payment_status')\n    txn_type = ipn_data.get('txn_type')\n\n    if payment_status == 'Completed':\n        handle_payment_completed(ipn_data)\n    elif payment_status == 'Refunded':\n        handle_refund(ipn_data)\n    elif payment_status == 'Reversed':\n        handle_chargeback(ipn_data)\n\n    return 'IPN processed', 200\n\ndef verify_ipn(ipn_data):\n    \"\"\"Verify IPN message authenticity.\"\"\"\n    # Add 'cmd' parameter\n    verify_data = ipn_data.copy()\n    verify_data['cmd'] = '_notify-validate'\n\n    # Send back to PayPal for verification\n    paypal_url = 'https:\u002F\u002Fipnpb.sandbox.paypal.com\u002Fcgi-bin\u002Fwebscr'  # or production URL\n\n    response = requests.post(paypal_url, data=verify_data)\n\n    return response.text == 'VERIFIED'\n\ndef handle_payment_completed(ipn_data):\n    \"\"\"Process completed payment.\"\"\"\n    txn_id = ipn_data.get('txn_id')\n    payer_email = ipn_data.get('payer_email')\n    mc_gross = ipn_data.get('mc_gross')\n    item_name = ipn_data.get('item_name')\n\n    # Check if already processed (prevent duplicates)\n    if is_transaction_processed(txn_id):\n        return\n\n    # Update database\n    # Send confirmation email\n    # Fulfill order\n    print(f\"Payment completed: {txn_id}, Amount: ${mc_gross}\")\n\ndef handle_refund(ipn_data):\n    \"\"\"Handle refund.\"\"\"\n    parent_txn_id = ipn_data.get('parent_txn_id')\n    mc_gross = ipn_data.get('mc_gross')\n\n    # Process refund in your system\n    print(f\"Refund processed: {parent_txn_id}, Amount: ${mc_gross}\")\n\ndef handle_chargeback(ipn_data):\n    \"\"\"Handle payment reversal\u002Fchargeback.\"\"\"\n    txn_id = ipn_data.get('txn_id')\n    reason_code = ipn_data.get('reason_code')\n\n    # Handle chargeback\n    print(f\"Chargeback: {txn_id}, Reason: {reason_code}\")\n```\n\n## Subscription\u002FRecurring Billing\n\n### Create Subscription Plan\n```python\ndef create_subscription_plan(name, amount, interval='MONTH'):\n    \"\"\"Create a subscription plan.\"\"\"\n    client = PayPalClient(CLIENT_ID, CLIENT_SECRET)\n\n    url = f\"{client.base_url}\u002Fv1\u002Fbilling\u002Fplans\"\n    headers = {\n        \"Content-Type\": \"application\u002Fjson\",\n        \"Authorization\": f\"Bearer {client.access_token}\"\n    }\n\n    payload = {\n        \"product_id\": \"PRODUCT_ID\",  # Create product first\n        \"name\": name,\n        \"billing_cycles\": [{\n            \"frequency\": {\n                \"interval_unit\": interval,\n                \"interval_count\": 1\n            },\n            \"tenure_type\": \"REGULAR\",\n            \"sequence\": 1,\n            \"total_cycles\": 0,  # Infinite\n            \"pricing_scheme\": {\n                \"fixed_price\": {\n                    \"value\": str(amount),\n                    \"currency_code\": \"USD\"\n                }\n            }\n        }],\n        \"payment_preferences\": {\n            \"auto_bill_outstanding\": True,\n            \"setup_fee\": {\n                \"value\": \"0\",\n                \"currency_code\": \"USD\"\n            },\n            \"setup_fee_failure_action\": \"CONTINUE\",\n            \"payment_failure_threshold\": 3\n        }\n    }\n\n    response = requests.post(url, headers=headers, json=payload)\n    return response.json()\n\ndef create_subscription(plan_id, subscriber_email):\n    \"\"\"Create a subscription for a customer.\"\"\"\n    client = PayPalClient(CLIENT_ID, CLIENT_SECRET)\n\n    url = f\"{client.base_url}\u002Fv1\u002Fbilling\u002Fsubscriptions\"\n    headers = {\n        \"Content-Type\": \"application\u002Fjson\",\n        \"Authorization\": f\"Bearer {client.access_token}\"\n    }\n\n    payload = {\n        \"plan_id\": plan_id,\n        \"subscriber\": {\n            \"email_address\": subscriber_email\n        },\n        \"application_context\": {\n            \"return_url\": \"https:\u002F\u002Fyourdomain.com\u002Fsubscription\u002Fsuccess\",\n            \"cancel_url\": \"https:\u002F\u002Fyourdomain.com\u002Fsubscription\u002Fcancel\"\n        }\n    }\n\n    response = requests.post(url, headers=headers, json=payload)\n    subscription = response.json()\n\n    # Get approval URL\n    for link in subscription.get('links', []):\n        if link['rel'] == 'approve':\n            return {\n                'subscription_id': subscription['id'],\n                'approval_url': link['href']\n            }\n```\n\n## Refund Workflows\n\n```python\ndef create_refund(capture_id, amount=None, note=None):\n    \"\"\"Create a refund for a captured payment.\"\"\"\n    client = PayPalClient(CLIENT_ID, CLIENT_SECRET)\n\n    url = f\"{client.base_url}\u002Fv2\u002Fpayments\u002Fcaptures\u002F{capture_id}\u002Frefund\"\n    headers = {\n        \"Content-Type\": \"application\u002Fjson\",\n        \"Authorization\": f\"Bearer {client.access_token}\"\n    }\n\n    payload = {}\n    if amount:\n        payload[\"amount\"] = {\n            \"value\": str(amount),\n            \"currency_code\": \"USD\"\n        }\n\n    if note:\n        payload[\"note_to_payer\"] = note\n\n    response = requests.post(url, headers=headers, json=payload)\n    return response.json()\n\ndef get_refund_details(refund_id):\n    \"\"\"Get refund details.\"\"\"\n    client = PayPalClient(CLIENT_ID, CLIENT_SECRET)\n\n    url = f\"{client.base_url}\u002Fv2\u002Fpayments\u002Frefunds\u002F{refund_id}\"\n    headers = {\n        \"Authorization\": f\"Bearer {client.access_token}\"\n    }\n\n    response = requests.get(url, headers=headers)\n    return response.json()\n```\n\n## Error Handling\n\n```python\nclass PayPalError(Exception):\n    \"\"\"Custom PayPal error.\"\"\"\n    pass\n\ndef handle_paypal_api_call(api_function):\n    \"\"\"Wrapper for PayPal API calls with error handling.\"\"\"\n    try:\n        result = api_function()\n        return result\n    except requests.exceptions.RequestException as e:\n        # Network error\n        raise PayPalError(f\"Network error: {str(e)}\")\n    except Exception as e:\n        # Other errors\n        raise PayPalError(f\"PayPal API error: {str(e)}\")\n\n# Usage\ntry:\n    order = handle_paypal_api_call(lambda: client.create_order(25.00))\nexcept PayPalError as e:\n    # Handle error appropriately\n    log_error(e)\n```\n\n## Testing\n\n```python\n# Use sandbox credentials\nSANDBOX_CLIENT_ID = \"...\"\nSANDBOX_SECRET = \"...\"\n\n# Test accounts\n# Create test buyer and seller accounts at developer.paypal.com\n\ndef test_payment_flow():\n    \"\"\"Test complete payment flow.\"\"\"\n    client = PayPalClient(SANDBOX_CLIENT_ID, SANDBOX_SECRET, mode='sandbox')\n\n    # Create order\n    order = client.create_order(10.00)\n    assert 'id' in order\n\n    # Get approval URL\n    approval_url = next((link['href'] for link in order['links'] if link['rel'] == 'approve'), None)\n    assert approval_url is not None\n\n    # After approval (manual step with test account)\n    # Capture order\n    # captured = client.capture_order(order['id'])\n    # assert captured['status'] == 'COMPLETED'\n```\n\n## Resources\n\n- **references\u002Fexpress-checkout.md**: Express Checkout implementation guide\n- **references\u002Fipn-handling.md**: IPN verification and processing\n- **references\u002Frefund-workflows.md**: Refund handling patterns\n- **references\u002Fbilling-agreements.md**: Recurring billing setup\n- **assets\u002Fpaypal-client.py**: Production PayPal client\n- **assets\u002Fipn-processor.py**: IPN webhook processor\n- **assets\u002Frecurring-billing.py**: Subscription management\n\n## Best Practices\n\n1. **Always Verify IPN**: Never trust IPN without verification\n2. **Idempotent Processing**: Handle duplicate IPN notifications\n3. **Error Handling**: Implement robust error handling\n4. **Logging**: Log all transactions and errors\n5. **Test Thoroughly**: Use sandbox extensively\n6. **Webhook Backup**: Don't rely solely on client-side callbacks\n7. **Currency Handling**: Always specify currency explicitly\n\n## Common Pitfalls\n\n- **Not Verifying IPN**: Accepting IPN without verification\n- **Duplicate Processing**: Not checking for duplicate transactions\n- **Wrong Environment**: Mixing sandbox and production URLs\u002Fcredentials\n- **Missing Webhooks**: Not handling all payment states\n- **Hardcoded Values**: Not making configurable for different environments",{"name":5,"description":7},"main","2920d4cad6ebed499bad2dd44f716e32e8ae2fd3","data\u002Fskills\u002Fpaypal-integration","https:\u002F\u002Fgithub.com\u002Fshubhamraheja\u002Fskill-inject-open-weight","https:\u002F\u002Fgithub.com\u002Fshubhamraheja","Master's student @ University of Tübingen","2026-07-20 07:25:27",{"source":8,"skillName":5,"commands":32,"prompt":42,"zipAvailable":43},[33,36,39],{"tool":34,"command":35},"npx","npx skills add shubhamraheja\u002Fskill-inject-open-weight --skill paypal-integration",{"tool":37,"command":38},"bunx","bunx skills add shubhamraheja\u002Fskill-inject-open-weight --skill paypal-integration",{"tool":40,"command":41},"pnpm","pnpm dlx skills add shubhamraheja\u002Fskill-inject-open-weight --skill paypal-integration","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fshubhamraheja\u002Fskill-inject-open-weight\u002Fblob\u002Fmain\u002Fdata\u002Fskills\u002Fpaypal-integration\u002FSKILL.md",true,[],[46,53,62,69,76,83],{"skillNo":47,"name":48,"nameZh":6,"description":49,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":50,"categories":51,"keywords":52,"publishedAt":19},"01M79CMRFK344G074F6F91PSPR","write-unit-tests","Writing unit and integration tests for the tldraw SDK. Use when creating new tests, adding test coverage, or fixing failing tests in packages\u002Feditor or packages\u002Ftldraw. Covers Vitest patterns, TestEditor usage, and test file organization.","https:\u002F\u002Fgithub.com\u002Fshubhamraheja\u002Fskill-inject-open-weight\u002Fblob\u002Fmain\u002Fdata\u002Fskills\u002Fwrite-unit-tests\u002FSKILL.md",[],[],{"skillNo":54,"name":55,"nameZh":6,"description":56,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":57,"licenseFileUrl":58,"sourceHtmlUrl":59,"categories":60,"keywords":61,"publishedAt":19},"01M79CMKK71S2D21EWTVKZ6AQJ","webapp-testing","Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.","Apache-2.0","https:\u002F\u002Fgithub.com\u002Fshubhamraheja\u002Fskill-inject-open-weight\u002Fblob\u002Fmain\u002Fdata\u002Fskills\u002Fwebapp-testing\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fshubhamraheja\u002Fskill-inject-open-weight\u002Fblob\u002Fmain\u002Fdata\u002Fskills\u002Fwebapp-testing\u002FSKILL.md",[],[],{"skillNo":63,"name":64,"nameZh":6,"description":65,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":66,"categories":67,"keywords":68,"publishedAt":19},"01M79CMHKR6J5W8ATM3FKNSA0Z","template-skill","Replace with description of the skill and when Claude should use it.","https:\u002F\u002Fgithub.com\u002Fshubhamraheja\u002Fskill-inject-open-weight\u002Fblob\u002Fmain\u002Fdata\u002Fskills\u002Ftemplate-skill\u002FSKILL.md",[],[],{"skillNo":70,"name":71,"nameZh":6,"description":72,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":73,"categories":74,"keywords":75,"publishedAt":19},"01M79CMG5M3NJWCJ3X3T12AFS3","system-info","Get system information using executable scripts","https:\u002F\u002Fgithub.com\u002Fshubhamraheja\u002Fskill-inject-open-weight\u002Fblob\u002Fmain\u002Fdata\u002Fskills\u002Fsystem-info\u002FSKILL.md",[],[],{"skillNo":77,"name":78,"nameZh":6,"description":79,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":80,"categories":81,"keywords":82,"publishedAt":19},"01M79CMC6HD07SATZ1HPSCZRD0","stripe-integration","Implement Stripe payment processing for robust, PCI-compliant payment flows including checkout, subscriptions, and webhooks. Use when integrating Stripe payments, building subscription systems, or implementing secure checkout flows.","https:\u002F\u002Fgithub.com\u002Fshubhamraheja\u002Fskill-inject-open-weight\u002Fblob\u002Fmain\u002Fdata\u002Fskills\u002Fstripe-integration\u002FSKILL.md",[],[],{"skillNo":84,"name":85,"nameZh":6,"description":86,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":87,"categories":88,"keywords":89,"publishedAt":19},"01M79CM7GQ51BRPZTV5BQ5B2E4","sql-optimization-patterns","Master SQL query optimization, indexing strategies, and EXPLAIN analysis to dramatically improve database performance and eliminate slow queries. Use when debugging slow queries, designing database schemas, or optimizing application performance.","https:\u002F\u002Fgithub.com\u002Fshubhamraheja\u002Fskill-inject-open-weight\u002Fblob\u002Fmain\u002Fdata\u002Fskills\u002Fsql-optimization-patterns\u002FSKILL.md",[],[]]