Mastering Flutter: An introduction to Pay plugin

It has passed a while from when Flutter was a “new thing” and it had quite a wild run. One thing did miss however was a pure dart support for paying physical goods but now we have the boringly named “pay” plugin (here’s the page)! Let’s get on with it and let’s check how to start integrating payment on our app!

The basics

First thing first we need to create a payment account both from Apple and Google. For Apple we should need to:

For Google Pay we need to

We can also use a gateway for our payment, like Stripe. Unfortunately not all services are supported and, also, on iOS some other payment methods can be completely not working at the moment (check out this issue).



Done the basics we can then start configuring our client. First we’ll obviously need to add our dependency to our .yaml file.

Main configuration is handled by creating a json file inside our assets folder. It is needed to have 2 separate files, one for Apple Pay and one for Google Pay. If you wish to use only one you can skip the other. You can find full specifications on how your json should be created here for an example and here for all the possible variables (Apple Pay and Google Pay). You can find below a example of a Google Pay json with Stripe configuration:

Implementation on code

Code implementation is pretty straight-forward. First we need to initalize our Pay object with the json files.

Then we’ll have to create our array of payment items (we can also use only one with the total amount we want our user to pay) and then show the payment selector.

The plugin will automatically show the main UI for our OS and handle all the 3D secure and other boring stuff herself. Be aware that according to your configuration you may not need to check out your payment or obtain the same result object.

You can also use a Pay button directly from the plugin, which will show the native button directly. Refer on the official plugin page for discovering more.


Wrapping all up

Using pay can be not really easy, especially if you need to use a gateway to confirm your payment. Anyway this plugin has just started to show its potential and we are sure that in the near future it will start being absolutely great to use.