Mondo Event Webhook - Transaction.Created

I’m one of the lucky few to have a Mondo Card. At the time of writing it’s in open BETA, so anyone can apply but the waiting list is huge (80k+ last time I looked) and only 11k cards are in circulation.

Mondo

I’m not going to go into detail about why Mondo is so great (it’s widely documented…) - but what I will do is delve into one of the components of their API. Yes a sorta-bank* with an API - I’m so excited to see what they (and other developers) can do with it! Mondo are maintaining an awesome-mondo github listing - check it out for inspiration.

For me - one of the most powerful parts of their API is the webhook feature. Head over to developers.getmondo.co.uk and you can register your own webhook to receive events.

At the moment the only event is the transaction.created event documented.

I’ve thrown together a quick PHP script that accepts the JSON POST value, parses this data, then sends a quick text messages to my mobile to let me know I’ve spent some money (or if I have been refunded).

<?php

require 'Twilio.php';

//fill these in from twilio
$account_sid = 'xxxx';
$auth_token = 'xxxx';
$to_number = '+44xxxx';
$from_number = '+44xxxx';

$client = new Services_Twilio($account_sid, $auth_token);

$rawData = file_get_contents('php://input');
$json = json_decode($rawData);

$logfilename = 'events/' . time();
file_put_contents($logfilename . '.json', $rawData);

switch ($json->type) {
case 'transaction.created':

    $amount = number_format(abs($json->data->amount) / 100, 2);

    $verb = ($json->data->amount < 0) ? 'spent at' : 'refunded from';

    $body = $json->data->merchant->emoji . ' £' . $amount . ' ' . 
                   $verb . ' ' . $json->data->merchant->name;

    if ($json->data->local_currency != 'GBP') {
        $amountForeign = number_format(abs(
                 $json->data->local_amount) / 100, 2);
        $body .= "\n" . 'Paid as ' . $json->data->local_currency . ' ' .             
                 $amountForeign;
    }

    $client->account->messages->create(array(
        'To' => $to_number,
        'From' => $from_number,
        'Body' => $body,
    ));

    break;
}

Instructions to use

If you have a Stripe account, this is a great way to test it, you can charge your card and refund it to see the webhook in action. Also you’ll see the charges come up in your iPhone app immediately too.

*It doesn’t have a banking license… yet - but it has applied. The Mondo Card is a prepaid Mastercard Debit.

Did this webhook work for you? Give me a shout if you have any questions

 
3
Kudos
 
3
Kudos

Now read this

Today is International Backup Awareness Day

Of course, that’s the joke. Everyday is International Backup Awareness Day. You should go and check your backups now. It’s OK - I can wait… I should probably go and check mine too. You have backups right? As I mentioned in a previous... Continue →