This project provides automation scripts to synchronize payment statuses between Shopify and PayPal. It helps ensure that order statuses on Shopify reflect the actual transaction outcomes on PayPal, particularly for payments made via eCheck or other pending methods.
- Sync Pending Orders: Fetches Shopify orders with a
pendingfinancial status.- If the corresponding PayPal transaction is
COMPLETED, the Shopify order is marked asPaid. - If the PayPal transaction is
DECLINED, the Shopify order isCancelled.
- If the corresponding PayPal transaction is
- Sync Cancelled Orders: Fetches recently cancelled Shopify orders to process refunds on PayPal for completed eCheck payments.
- Slack Notifications: Sends detailed daily reports to a designated Slack channel, including a summary table and a comprehensive CSV file attachment.
Follow these steps to set up and run the project.
- Python 3.8+
- pip
-
Clone the repository:
git clone git@github.com:mhaider97/payment-status-sync.git cd payment-status-sync -
Install dependencies: It's recommended to use a virtual environment.
python -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate` pip install -r requirements.txt
-
Set up environment variables: Create a
.envfile in the root directory of the project by copying the example file:cp .env.example .env
Then, fill in the required values in the
.envfile.
Your .env file should contain the following API keys and configuration details:
# Shopify API Credentials
SHOPIFY_API_KEY="your_shopify_admin_api_access_token"
SHOPIFY_STORE_DOMAIN="your-store.myshopify.com"
# PayPal API Credentials
PAYPAL_CLIENT_ID="your_paypal_client_id"
PAYPAL_CLIENT_SECRET="your_paypal_client_secret"
PAYPAL_CLIENT_URL="https://api-m.sandbox.paypal.com" # Use https://api-m.paypal.com for production
# Slack Bot Credentials
SLACK_TOKEN="your-slack-bot-token"
BOT_CHANNEL="C0123456789" # Slack Channel ID
BOT_USER="Payment Bot"
The project contains two main scripts that can be run independently.
To check PayPal transaction statuses for pending Shopify orders and update them accordingly:
python sync_pending_orders.pyTo process refunds on PayPal for recently cancelled Shopify orders:
python sync_cancelled_orders.pyFor complete automation, you can schedule these scripts to run daily using a cron job.
Example cron job (runs every day at 8 AM):
0 8 * * * /path/to/your/project/venv/bin/python /path/to/your/project/sync_pending_orders.py
0 8 * * * /path/to/your/project/venv/bin/python /path/to/your/project/sync_cancelled_orders.py