Make Payment Completion Flows using Moneris API and Postman Flows

Who am I?

Hello everyone, my name is Houssem, API Architect at Moneris, Canada’s leading payment processor.1.

I am here today to show you how we can use Moneris APIs and Postman Flows to design intuitive solutions for some of our everyday developer tasks.

What are we looking to solve?

Let’s say, in another life, we are the technology department of an online store. For the purpose of this example, our stakeholders would like to setup an online payment process that allows customers a same-day cancellation grace period until 11 PM.

What are we looking to build?

Looking at what’s in The Postman API Network, we discovered Moneris.

They recently launched a new set of RESTful APIs that are secure and easy to set up, with awesome customer support!

We will use the Moneris Two-Step payment flow to:

  1. Perform a temporary hold on the customer’s credit card (called “Authorization”).
  2. Complete/capture the purchases that were not cancelled (also known as “Void”).

Now to present this process to business owners/stakeholders, we need something that is engaging and visual.

Enter Postman Flows! This tool allows us to effectively illustrate and demonstrate the API flow for better understanding.

We will create a Flow that:

  1. Retrieves all Moneris Payments performed during the same day.
  2. Complete all Payments that are in the AUTHORIZED state.

The flow will be triggered daily at 11 PM using a Postman monitor.

Step 0: Fork the latest collection of Moneris APIs

Postman Flows runs on the platform’s top collections. Let’s get started by forking the latest collection of Moneris APIs as well as the Moneris Sandbox Environment (Moneris API’s testing environment).

Fork Moneris APIs Latest collection

Of course, we also explored the Moneris Payment API and discovered that it supports OAuth 2.0 Client Credentials.
So we navigated to the Moneris API Developer Portal, where we signed up for a test merchant account. As part of the process, we obtained a Merchant ID, along with a pair of Client ID And Client Secret credentials.
The process was simple and straightforward!

The Moneris API Developer portal

Step 1: Generate Access Token

Using the Open API specification provided by Moneris, another team seamlessly integrated their order management system to create Pre-Authorizations.

Now, it’s our turn to retrieve those payments using the List Payments API call. The API supports cursor pagination through a cursor and limit query parameters. It also supports filtering Payments by creation time, using the created_from and created_to parameters.

To implement this in Flows, let’s start by getting an OAuth 2.0 Access Token:

  1. First, we will drag the Start output connector and select the Send Request block.
    a. We can then select the Moneris API collection that we forked earlier and navigate to Access Token Generation.
    b. In the “Add Environment” box, let’s select Sandbox. Since clientId and clientSecret are environment variables, Flows will automatically populate the required parameters for us. It’s that intuitive!
    Retrieve Moneris API Access Token

  2. Since we plan to use the Access Token for future calls, we need to extract it using a Select block before saving it in a variable using the Create Variable block.

  3. We can now start running the flow!
    Store Moneris API Access Token

Step 2: Retrieve Payments

Now that we’ve generated an access token, let’s proceed to retrieve the payment data.

  1. From Access Token request block, drag another success connector and select “Send Request”. Configure it to use the List Payments API.
    Call List Payments API

  2. To enable cursor pagination and handle Bearer tokens, we need to update the collection to include variables for the cursor and set the authorization to Bearer Token, using the token as a collection variable.
    a. Optionally we can set created_from and created_to parameters to filter payments by a specific date range. By default, the API fetches payments created on the same day.
    Adjust List Payments for cursor pagination

  3. To implement continuous looping over the pages, we will make use of the If block to evaluate whether next property is set.
    Test If next property is set
    a. To fetch the next page, we will connect the Then output to an Evaluate block to get the cursor from the next link property.
    Retrieve pagination cursor
    b. Inside the Evaluate block, we will set the code to TypeScript. Then, we can add the necessary code to extract the cursor value from the next link’s query string.
    Get pagination cursor using TypeScript
    c. Next, we will connect output to the input of another Send List Payments Request block.
    Set cursor as input for List Payments

  4. To make the process a loop, let’s connect the success output of the List Payments block to the previous If block.
    Looping through Payments pages

  5. To prepare for the next step, we will connect both the Then output and the Else output of the flow to a Select block that is set to body.data to get the payments list.
    Using Select block

  6. We can now run the program to execute the workflow!

Step 3: Complete Authorized Payments

Completing the payments is our pièce de résistance. To get started,

  1. Let’s filter the Authorized Payments by looping through the Select block’s output from the previous step, using an Evaluate block that filters by paymentStatus = AUTHORIZED.
    Filtering Authorized Payments

  2. To loop over the list, we connect the Authorized Payments Evaluate block output to a For block.
    Looping through Authorized Payments

  3. We will then connect the Item’s output to a Send Request block, which will execute the Complete Payment request.
    Creating a Send Complete Payment block

  4. Similarly to other calls, we will adapt the paymentId path parameter to be a collection variable and connect the For loop to it.
    Passing paymentId to Send Request block

Step 4: Creating a Webhook trigger

Now that we have created a flow that works, how do we trigger it on demand from outside the app? The Webhook trigger will allow us to call the flow using an HTTP request.

  1. On the bottom left corner of the flows screen, there is a section called Applications.
    We can click on the Create button for the Webhook option, which will generate a HTTP link that we can use to call the flow whenever we need it.
  2. We can now grab the generated Webhook link and test it using Postman. We just need to send a request to the link and we should see the flow spring into action. Pretty neat, right?
    Triggering the Flow from HTTP Webhook

Step 5: Automating the flow using Postman Monitors

For our final step, we will make use of Postman Monitors to call our Completion Flow every night at 11 PM.

  1. First, we need to convert the Flow’s Webhook trigger into a Postman Collection. Let’s call it Moneris API - Automation
    Creating a Webhook Trigger Collection

  2. Once the collection is ready, we can go ahead and set up a Monitor:
    a. In the Collection box, we will select Moneris API – Automation.
    b. In the Environment dropdown, let’s choose the Sandbox option.
    c. We can then set this monitor to run on a weekly timer, every day at 11 PM.
    d. And finally, we will just need to click “Create Monitor” to complete the setup.
    Setting up Postman Monitor

And that’s a wrap! We’re all set to automate payment workflows using Moneris APIs and Postman Flows.

10 Likes

Wow, the effort you put into this presentation really shows. Amazing work!

2 Likes

Thank you very much @gladwingt ! It means a lot !

2 Likes

@gladwingt I’m so glad you both connected! @houssem-gharssallah check out what @gladwingt is working on here! :slight_smile:

3 Likes

@houssem-gharssallah, wow, this is really cool. I even learned some new things about Flows I wasn’t aware of. Thanks for taking the time to build this out!

4 Likes

@felipemtz27 reading your comment made me :smiling_face_with_tear:
It’s what we are here for… advocating for APIs and exchanging experiences!
I enjoyed every second working on this article and looking to bring more soon :rocket:

3 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.