Setting up payments with Durianpay 💰
Durianpay is an Indonesian payment processor similar to global players like Stripe and Square. It provides entry into the Indonesian market with a relatively low barrier to entry, decent documentation good developer support. In this article, we will go through integrating checkout into an expo or web project. I will be spinning up a backend to return an access token as well as fire some logic on successful payment in a webhook. You’ll need a durianpay account and relevant API keys Link to Durianpay documentation
How to integrate Durianpay Checkout
Pull in Durianpay script in HTML file
- Since I’m using expo, I need to run
expo customize:web
to expose an HTML file, which I can then use to pull in Durianpay. If you’re not using expo, you can skip this point. Just use your index.html - Paste this script into the head of your HTML file to pull in the library:
Set up server
- Spin up a node.js server and pull in
dpay-node-sdk
via your package manager of choice. - Initialise Durianpay like so:
const dpay = new Durianpay({ secret_key: "your_secret_key", // Use your Sandbox or LIVE key });
- Spin up a node.js server and pull in
Create endpoint to return access token
This /create-order endpoint will generate an access token which the client will use to initialise the checkout.
Initialise checkout on client-side
- Create checkout with previously obtained access_token and your API key.
createDurianPayOrder
is a method that hits the create-order endpoint via POST request.
- Be sure to handle
onSuccess
,onClose
andonError
callbacks.
Webhook
A known limitation I’ve come across is that Durianpay will force a refresh and take users to redirect_url
if user does not click the (x) button. This results in onSuccess
, onClose
and onError
callbacks not firing, meaning there is a risk of successful payment but fulfilment logic not being executed.
According to Durianpay, setting up a webhook is an optional step. I highly recommend it. Although it does not fix the refresh, it ensures logic is fired on your backend once payments and/or orders are completed regardless of client status.
Set up your webhook URL on Durianpay dashboard. Listen to
order.completed
eventThis URL should be whatever route your webhook is sitting on. In my case I have the route set up like so
app.post("/api/dpay/webhook", DurianpayWebhook);
Therefore my webhook url is
https://yourServerDomain/api/dpay/webhook
Webhook Signature Verification (optional)
- Your webhook will work without verifying event signatures but it is highly encouraged to make sure the events are actually yours:
- Fire logic on event, assuming signatures tally:
if (event === "order.completed") { //onSuccess logic here }
In this use case I am adding a user to a lobby on successful payment, alter this accordingly to suit your needs.
Deployment
I have this backend deployed via fly.io and the frontend on vercel. Fly has been very impressive so far, similar to heroku but less salesforce bloat and a better experience all around.
Final thoughts
Durianpay has an overall decent developer experience. What it lacks in documentation clarity has been more than made up for with prompt response to techincal queries. They even went as far as to add my team to a whatsapp group with some of their engineers which was and continues to be invaluable
The business impact has been fantastic, the ability to enter the indonesian market and gain access to the many country specific payment options proves to be extremely useful.
Seeing how bigger players like stripe, square and xendit all have rather high barriers to entry and or a lack of support for the market, I would recommend Durianpay to any startup looking to break into the space.
Come have a look at Playard’s implementation of Durianpay. Users pay for a slot in a curated game of sport catered to their needs and preferences. There are also wallet, payout and lobby monetisation features, all of which are powered by durianpay.
Join a game, sweat it out and make some friends in the process 😎