Today, I created my own marketplace with Stripe

Today, I created my own marketplace with Stripe

Today, I created my own marketplace with Stripe and it was fun!

As part of GitHub’s student developer pack, Stripe comes with a transaction fee waiver for the first 1000$ processed (or so I thought).

Now, I can use this marketplace to sell my stuff to my neighbors at École polytechnique… and they can pay me by credit card!

As a matter of fact it actually is easy to use Stripe’s API: it comes with snippets of code that you can directly use in your application. Even your sandbox keys are pre-filled.

I had a good experience using Trello’s API and using Stripe’s API gave similar satisfaction (much to the contrary of the RATP’s API).

First, encrypt!

The first obstacle I encountered was that Stripe obviously requires TLS encryption. Hopefully, Let’s Encrypt allows that super easily. Like you just install certbot and type certbot certonly and it does the work.

This was very rewarding. As you can see, this blog now uses HTTPS. I will also be able able to use my own server for building a Facebook Messenger Chatbot without using Heroku!

Then, configure the nginx server

I also had some trouble configuring the nginx server just like I wanted: with PHP, TLS and .htpassw. At the end, it looked like this:

server {
        listen 80;
        server_name sold.varal7.fr;
        return 301 https://$server_name$request_uri;
}

# HTTPS server

server {
    listen 443;
    root /var/www/sold;
    server_name sold.varal7.fr;
    index index.html index.htm index.php;
    client_max_body_size 10M;

    ssl on;
    ssl_certificate /etc/letsencrypt/live/sold.varal7.fr/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/sold.varal7.fr/privkey.pem;

    ssl_session_timeout 5m;

    ssl_protocols SSLv3 TLSv1;
    ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv3:+EXP;
    ssl_prefer_server_ciphers on;

    location /admin/ {
        auth_basic "Restricted";
        auth_basic_user_file /etc/nginx/.htpasswd;

        location ~ \.php {
             fastcgi_index index.php;
             fastcgi_pass unix:/var/run/php5-fpm.sock;
             fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
             include fastcgi_params;
         }
    }

    location ~ \.php {
         fastcgi_index index.php;
         fastcgi_pass unix:/var/run/php5-fpm.sock;
         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
         include fastcgi_params;
     }
}

(Yeah, sorry I only serve ipv4 for now…)

To generate the .htpsswd file, I simply typed sudo htpasswd -c /etc/nginx/.htpassw varal7 in terminal.

Finally, the coding part

I wanted to do produce the easiest possible code for my MVP. So I used vanilla PHP.

The code is available as a GitHub repository.

End of the day, I don’t think it was the best thing to do, as I had to recode a lot of useful (and therefore existing) functions. I could have used a simple framework like Silex.

Success! Less than 24 hours after starting the project, I had my first customers and will soon cash in some money 🙂

Sadly, as you can see, Stripe does seem to take a transaction fee anyway. I have wrote them an email about that.

Bonus: receiving SMS notification

Stripe doesn’t notify anyone automatically, so you have to do it yourself.

Sadly, I don’t have my own email server yet. But I already have a SMS server ready!

More precisely, I have a Raspberry Pi equipped with a SIM card, connected to the same VPN as my VPS and listening on a certain port for a GET request. If it gets the correct one, it sends me a text with a certain message. I guess this setup could be the subject for another article and it will, when I feel like writing it.

Finally, adding this SMS notification was not difficult and I now have this feature in production 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *