Server adventures 4

My friend hopes to push for a working demo-able MVP by Wednesday, so I have to pause my other freelance work to crunch on the NodeJS project full-time since last Sunday. I worked on implementing and testing Paypal payment gateway, and finally had the chance to see what Braintree was about.


To put it briefly in relevant-to-what-I-wanted terms, Braintree is a standardised gateway for receiving payments from clients, regardless of whether they are Paypal or not. If you’re using Paypal API directly, you can only perform actions with their platform.


I tried using Braintree at first, but later I decided to just use Paypal’s API because I also needed to pay customers (which Braintree doesn’t seem to support at the moment). Since my friend’s startup service requires both receiving and giving payments to customers (think Uber or AirBnB), I had to figure out the API to:

  • Receive payment request
  • Store the invoice for unpaid payment
  • Confirm payment, then update invoice and database
  • After the seller delivers the product and customer confirms it, update product status
  • Add a new invoice for payment from company-to-seller
  • Confirm transfer, then update invoice and database

Here is the gist of how payment gateways work (from what I’ve learned in two days so far):

  • You first tell Paypal you want to “create” a new payment (by the customer), and provide a callback URL (Paypal will use this URL to redirect the user after successful payments)
  • If you configured the “create payment” correctly, Paypal will respond with a payment ID (which I will regard as the invoice ID), along with an “approval URL”.
  • You will then have to redirect the user to Paypal via the “approval URL”, and let the user make a payment securely.
  • Upon successful payment, Paypal will redirect the user to your callback URL (naturally, your website) with the invoice ID.
  • You then use the invoice ID and update your database accordingly, to confirm the product purchase.

It seems Paypal’s documentations have changed drastically, as StackOverflow’s solutions seemed to point to broken links or pages that don’t seem to contain the correct info. Thankfully, the documentation has changed for the better, and seems to be a lot easier to use too.

Next I had to figure out a way to pay customers, but I haven’t gotten to that part yet so I’ll leave it for part 5.