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.

paypal-logo

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.

braintree-logo

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.

Server adventures 2

After days of struggling to write SQL in Knex/Bookshelf for NodeJS, I decided to give up and just write raw SQL queries.

Both Bookshelf and Knex’s documentation are outdated, it seems. A lot of the methods I tried to use usually spew “method doesn’t exist” errors, and I spent most of my time just figuring out how to get the method to work rather than test for query results. That was just plain frustrating.

Server adventures

I was asked by a friend to help him out with his project recently. He needed a trustable server guy to do all the back-end work because it involves payment and all that. I decided to take the chance to learn NodeJS, as well as handle all that server admin stuff that I have always thought of doing but was too intimidated to, because of how complex Amazon Services were.

Then, a senior (who happens to be a very awesome server guy) told me about Digital Ocean.

DigitalOcean_logo

I’ve only ever heard of VPS thanks to my ex-company using it, and at that time they already hit the ground running with Amazon AWS and EC2 and all that difficult stuff. I needed a place to get my feet wet, and this is it. What is DO (Digital Ocean)? It’s a cheap VPS hosting. Uhm… I’m not familiar with this stuff, but it’s like a blank slate for you to do whatever you want on.

Typical webhosting services provide a CPanel or some very restrictive SSH access, which limits the things you can do for your server, like installing necessary software or tinkering with system settings. Most of the time, they have pre-installed services for you (e.g. an older, stabler Ruby on Rails, or WordPress) and you can’t change them because you don’t have the permission to.

OpenShift-LogoType

Previously, I used OpenShift and Heroku, but found them to be opinionated and limiting, especially since I didn’t know what I could (or couldn’t) do. Although those are free services, I think paying a mere 5USD per month for DO is a better investment for learning and future projects.

Heroku_logo

Anyway, this is just a post to say I like DO very much. The control panel is minimal and easy to use. The “droplets” & “snapshot” feature is all I need. They have tutorials for almost anything to get you started. I installed NodeJS, MySQL, Git, setup user accounts other than root, and other Linux-y stuff, which I haven’t done in 3 years, all rather easily, thanks to the easy-to-follow tutorials.

With the way things are going, my hopes to write a NodeJS game server one day doesn’t feel that impossible after all.

Side Project

Even though I am officially unemployed, I have been fortunate enough to have a friend offer me a (sort of) freelance gig. He needs someone trustable to build a backend system for him. I told him I’m more experienced in front-end and gamedev, but he was okay with it. So there we have it, a proper reason for me to learn backend programming.

After some deliberating, I picked up NodeJS, with hopes that the experience will be useful in gamedev (HTML5 multiplayer games, perhaps). I contemplated RoR and GoLang, but decided against those because I had no prior knowledge in Ruby nor Go. Learning a new language -and- figuring out a server framework is going to take longer compared to NodeJS (I’m familiar with Javascript already).

nodejs-icon

But anyway the point of this post is some nuggets of knowledge I picked up so far. NodeJS has NPM (node package manager), which is similar to how RoR has Gems. One of them is Bookshelf.js, a library (built on top of Knex.js) to handle database queries.

Most of the tutorials on Google have sample code that looks something like this:

The last part, catch() , was supposed to catch query errors, but I hit the wall for a couple of hours because Node was telling me that catch()  is not a function. Turns out, it has been changed to otherwise(...) .

Thanks to Que, in his more recent blog posts for using the function, that gave me the revelation. Phew!