Skip to content

otwarteklatki/PayPal-IPN-Listener

 
 

Repository files navigation

PayPal-IPN-Listener

This project listens for paypal IPNs from the OpenCages UK paypal account. It will then record these IPNs in mongodb and request this project to send a receipt email.

ENV VARS

  • MONGO_URI - Mongodb uri, point this at some mongodb instance and database.
  • SENDGRID_API_SERVICE_KEY - API key so that this project can request sending an email from this project, it has to match the IPN_LISTENER_API_KEY env var on the deployment of that project for a request to be successful.
  • SENDGRID_API_SERVICE_URL - url for the deployment of this project.

How do I test this?

Use https://developer.paypal.com/developer/ipnSimulator/ to test sending IPNs to the API. I would suggest using a local tunnel of some sort to test this on your local.

How to deploy

Push to master

PROD URL

https://ocuk-paypal-ipn-master-uepvew4upa-ew.a.run.app

The rest of the README

The readme from the forked repo is below... I copied the base of this API from some wonderful github account because getting paypal IPNs to work was a nightmare.

PayPal IPN Listener

A Node.js and MongoDB based listener for PayPal IPN events.

GitHub Workflow Status GitHub top language Docker Pulls GitHub last commit Lines of code License

Getting Started

Prerequisites

The following will need to be installed before proceeding:

  • Node v12+
  • MongoDB
  • Nginx

Clone the Project

# Clone it
git clone https://github.com/Fairbanks-io/PayPal-IPN-Listener.git
cd PayPal-IPN-Listener/

Run the Listener

# Install Dependencies
npm install

# Start Server
npm start

The IPN listener should now be running on http://localhost:8888

Docker

This IPN Listener is also available on Dockerhub.

To launch the Dockerfile, the following can be used as an example:

docker run -d -p 8888:8888 -e 'MONGO_URI=mongodb://user:password@localhost:27018/paypal' --restart unless-stopped --name 'paypal-ipn' fairbanksio/paypal-ipn-listener

The IPN listener should now be running on http://localhost:8888

If you need to get into the container for some reason, simply run the following on the Docker host:

docker exec -it paypal-ipn /bin/bash

Environment Variables

ENV Required? Details Example
MONGO_URI No What Mongo instance to use. If the ENV is not provided, mongodb://localhost/paypal is used. mongodb://user:password@localhost:27018/paypal
LOG_LOCATION No Override where the IPN log is written. By default the log is written into the app directory. /Logs/ipn.log
PORT No Override the application port. Defaults to 8888. 8889

Configure Nginx

PayPal requires that your IPN Listener be hosted on an HTTPS enabled domain. To achieve both of those, you can use an Nginx reverse proxy with the following configuration:

server {
    if ($host = ipn.mysite.io) {
        return 301 https://$host$request_uri;
    }
    listen 80;
    server_name ipn.mysite.io;
    return 301 https://$server_name$request_uri;
}
server {
    listen 443 ssl http2;
    ssl on;
    ssl_certificate fullchain.pem;
    ssl_certificate_key privkey.pem;
    server_name ipn.mysite.io;
    add_header X-Frame-Options "SAMEORIGIN";
    large_client_header_buffers 4 8k;
    location / {
        proxy_pass http://127.0.0.1:8888;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}

The IPN listener should now be available on the URL configured when setting up Nginx. To complete setup, update your IPN url on PayPal and run a test payment with the IPN Simulator.

About

Node.js & MongoDB based PayPal IPN Listener

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 81.3%
  • Smarty 16.8%
  • Dockerfile 1.9%