How to send transactional emails for your Paypal Smart Button
Tags: wordpress, devjournal, todayilearned
Published: 2022-05-12 22:42:10

### TL;DR
* Use automation tools like zapier, make, integrately.
* Use Paypal IPN to send information to the automation tool that you choose.
* Use and connect mailersend (or other transactional email platform) to the automation tool to send the emails.


## Context

I have a client who needed his patients to be able to pay him using credit or debit cards. This client uses paypal in his daily life so it is practical for him that the payments made to him are made through this platform. That way he can pay for what he needs using paypal and at the same time " top up" his balance with patient payments.

The solution? Paypal Smart Button.

I added the Paypal Smart Button on a page of their site and configured it to be a flexible payment (like a donation) since not all patients always pay the same, I also edited the code to apply a validation that prevented entering an amount less than 25$, and also the amount entered is added the commission charged by paypal, that way my client always gets the full amount.

## The darkest hours

Now, my crisis moment? That moment was when my client wanted those who paid using that Smart Button to receive a transactional email with some "Thank you for your payment" or "Your payment has been received" type message. My response? "Of course I can do that". Did I know how to do it? Nope, of course not.

But as a developer, it's not an option to just sit back and do nothing, that's when I started to do extensive research. There were many options, create a plugin, use a plugin with a paid extension, "borrow" the code from that paid plugin and make it work the way I needed it to. 

Those options required me to know a bit of PHP (I hate php), plus I needed to know how to implement a plugin in wordpress. I also looked into webhooks, I could make it so that when a transaction was made on the Smart Button, it would be saved in the database, then notify the transactional email provider to send the email with the saved information. The last option sounds cool, right? Yes, I know... but it wasn't worth it, not for me at least.

Besides, as far as I know, developing a plugin means maintaining it (you can confirm me in the comments). And this guy over here doesn't want to do that.

So, what did I do?

## The Holy Grail 
Automation platforms.
![theoffice-episode-12-the-office-tv](https://media.giphy.com/media/ugOMVsKh9pMWxji7w4/giphy-downsized.gif)

There are many of these, such as [Zapier](https://zapier.com/), [Automate.io](https://automate.io/), [Make](https://www.make.com/), [Appypie](https://www.appypie.com/), [Integrately](https://integrately.com/), [SyncSpider](https://syncspider.com/), [LeadsBridge](https://leadsbridge.com/), and those are the ones I know about.

Zapier was the one recommended to me, so I started with that one. Result? None, I couldn't use it because the Paypal integration option is paid. But if you want to pay for it, it will probably work for you.

The solution, the salvation, came with Integrately, it's free and I could integrate it with paypal at no extra cost. A win-win situation.

I also found Make interesting, and it allows you to use filters (such as if and else statements) for free.

The road to glory was near.

## Ok, I don't have to create a plugin anymore, but now what?
So, the scenario where I created a plugin is out of the question. I found an automation platform, but how does that help me to send the Paypal Smart Button transactional emails? 

Simple, paypal has something called [IPN](https://developer.paypal.com/api/nvp-soap/ipn/) (Instant Payment Notification), As the name suggests, it notifies you when you receive payments. How does that integrate with the automation platform? Well, here's where the beloved [webhooks](https://youtube.com/shorts/-4sski7qC_c?feature=share) come in.

When integrating Integrately with paypal, it gives you a link that you must enter in paypal, so your paypal account when receiving a payment, will send an http request with the payment information to the integrately link.

Here you can see where Integrately gives you the link.
![Integrately-page-to-connect-paypal-to-integrately](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s8geq1nmeatny1brl8wm.png)
And here how to add that link to paypal.
![Paypal-IPN-Settings](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zvifsdua2fbtn53ik4y4.png)

(I won't go into too much detail, but you have an idea how to do that part)

Once I achieved that, and tested it using the [Paypal's IPN Simulator](https://developer.paypal.com/developer/ipnSimulator), I felt that there was a progress, the long and stressful investigation was bearing fruit.

![erik-killmonger-its-beautiful-black-panther](https://c.tenor.com/WEadQ5E6UVIAAAAC/erik-killmonger-its-beautiful.gif)


## Good, Good but what about the emails?
Welp, that was the easiest part. I used [Mailersend](https://www.mailersend.com/). Integrately even gives you a step-by-step on how to connect your Mailersend account. 
![Integrately-instrucctions-to-connect-mailersend](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cz2hlhca49mos92p8q4v.png)

How did I find Mailsersend? Well, Mailerlite had been recommended to me, while I was researching it I saw that it was practically like Mailchimp and that's not what I needed, but I found Mandrill which is Mailchimp's add-on for transactional emails. But I was not convinced and I found Mailersend (which is like Mandrill but by Mailerlite) while I was reading about Mailerlite.

Once Mailersend is connected to Integrately, you can choose to send a simple email (text only) or send a template. Mailersend offers several pre-made templates that you can edit, and you can use variables in the email so you can use the information that paypal sends you.

And that's all you need to know to send transational emails for your Paypal Smart Button. If you know a better way I would like to read it in the comments. Any feedback is appreciated.