Webpack causes: jQuery not defined

Recently, I started using Webpack and I was requiring jQuery using ‘require(“jquery”)’ and then I started getting errors in my app like so:

Then I found this piece here which explained that Webpack doesn’t set any global variables, so you have to set them yourself. So I did this:

Happily this solved my issues.

Problems integrating PayPal

Recently, I’ve been trying to integrate PayPal subscriptions into a website of mine but I’ve hit a few problems which I’ve managed to resolve thanks to PayPal’s support. Hopefully this will help others. Here we go.

I followed this integration guide and I’ve managed to create a product and a plan and then subscription and then use the link from the subscription to redirect to PayPal. However, when I tried to pay for the subscription using my sandbox account I got this error:

I was baffled for a while but then I contacted PayPal’s support which told me that I don’t have balance in the same currency in which was the subscription (my case was euro) so I went on this page and I created a new sandbox account based in Germany which automatically filled the account with 5000 euro. However, when I tried to pay again for the subscription using the new account I hit another similar problem, here is the error:


So I contacted PayPal’s support again and after some back and forth they told me that the sandbox account wasn’t verified and that they’ve verified it and now it was working, which I tested immediately and yes it was working.

Problem is, why sandbox accounts with automatically generated email addresses, which look something like this: [email protected], have to be verified at all and how can you do that if you don’t own the email address? Baffling. Even worse, I have a sandbox account set up with one of my email addresses, which is not verified, and I tried to verify it but I never got a verification email!

So, generally, I am quite disappointed by PayPal even though I’ve managed to solved my problem. Lack of documentation is frustrating. I even found pieces of their documentation that simply don’t work.

Integrating PayPal subscriptions NOT the right way

Recently, I started trying to integrate PayPal subsriptions into a project of mine, however, it turns out I’ve started by using the old PayPal PHP SDK which is not the recommended way anymore. The recommended way is using the new Checkout PHP SDK, however that one doesn’t support subscriptions so the way to integrate PayPal subscriptions is by making direct https calls to their API. In this post I’ll show you how I started integrating the subscriptions using the old, deprecated SDK in case somebody needs it. Note that it’s not full integration (I’ve only gotten to a certain point) and it’s also Laravel specific.

Here is the code. I’ll explain the four main methods in the class. First, ‘activatePlan’ – this will create the billing plan and activate it. Second, ‘registerPrimaryWebhooks’ – which will register some webhooks with PayPal. Third, ‘validatePrimaryWebhooks’ – which will validate/handle the primary webhooks, when one is received. And last, ‘createBillingAgreement’ – which will create a billing agreement and return a redirect to the PayPal’s approval link for that agreement.

Here is also my ‘PaypalController’ which handles the requests and also has some PayPal logic to execute the billing agreement once the user is redirected to the success url after approval.

Here is also my PayPal routes in case you need it

WordPress permalinks not working

I just got an issue where the permalinks on a WordPress didn’t work even though I had an .htaccess file and I had selected “Post name” in the permalinks option page in WordPress.

The problem was to do with mod_rewrite not being enabled on my server. So I had to do “sudo a2enmod rewrite” and then restart Apache and the problem got fixed.

Sort files into folders by extension

 

Duplicity bash script to restore data from S3

Restore your S3 duplicity backup

 

Backup to S3 using duplicity

Backup a directory to S3. The script make full backups every 30 days and incremental backups the rest of the time.

 

JavaScript boilerplate file

 

Image under text in an HTML email