PaySwitcher
  • About PaySwitcher
    • πŸ›’For Online Businesses
    • πŸͺœFor Small & Medium Enterprises
    • 🏒For Enterprises
    • πŸ–₯️For SaaS Providers
    • πŸ›οΈFor E-Commerce Businesses
    • πŸ“¦For Marketplace/Platforms
    • 🏦For Banks & Financial Institutions
  • PaySwitcher Cloud
    • ⚑Quickstart
      • πŸ“₯Migrate from Stripe
        • Web
        • Android
        • iOS
        • React Native
      • πŸ₯—Payment Recipes
        • Use PayPal With Stripe
    • βš™οΈControl Centre Account setup
    • πŸ“¦Integration guide
      • 🌐Web
        • Node And React
        • Customization
        • Error Codes
        • Node and HTML
        • Vanilla JS and REST API Integration
      • πŸ“±Android
        • Kotlin with Node Backend
        • Customization
        • Features
      • πŸ“±iOS
        • Swift with Node Backend
        • Customization
        • Features
      • ⏺️React Native
        • React Native with Node Backend (Beta)
        • Card Widget (Beta)
        • Customization
      • ⏺️Flutter
        • Flutter with Node Backend
        • Customization
      • Headless SDK
      • Payment Methods Management
    • πŸ’³Payment methods setup
      • πŸ’³Cards
      • πŸ“±Wallets
        • Apple Pay
          • Web Domain
          • iOS Application
        • Google Pay
        • PayPal
      • πŸ“†Pay Later
      • 🏦Banks
        • Bank Debits
        • Bank Redirects
        • Bank Transfers
      • πŸͺ™Crypto
      • πŸ”‘Test Credentials
    • πŸ”ŒConnectors
      • πŸ–²οΈAvailable Connectors
        • ACI
        • Adyen
        • Airwallex
        • Authorizedotnet
        • Bambora
        • Bank of America
        • Billwerk
        • Bluesnap
        • Braintree
        • Checkout
        • Coinbase
        • Cybersource
          • Apple Pay
          • Google Pay
        • dLocal
        • Fiserv
        • GlobalPayments
        • GoCardless
        • Klarna
        • Mollie
        • MultiSafepay
        • Nuvei
        • OpenNode
        • Paypal
        • PayU
        • Prophetpay
        • Rapyd
        • Shift4
        • Stripe
        • TrustPay
        • Volt
        • Worldline
        • Worldpay
        • Zen
      • Activate connector on PaySwitcher
      • Test a Payment with connector
    • πŸͺWebhooks
  • Features
    • πŸ”€Payment flows
      • πŸ”Saving payment methods & recurring payments
      • πŸ’΅Payouts
        • βž•Get started with payouts!
        • πŸ”—Process payouts using saved payment methods
        • πŸ›£οΈRoute your payout transactions using Smart Router
        • ♻️Smart Retries in Payout
        • πŸ”—Payout links
      • 0️ 0️ 0️ Zero Amount Authorization
      • πŸ”“Tokenization & saved cards
      • πŸ”—Payment links
      • ⏭️External Authentication for 3DS
      • πŸ’°Manual Capture
      • πŸ›‘Fraud Blocklist
      • πŸ”Subscriptions
      • πŸ”ƒPG Agnostic Recurring Payments
    • πŸ•ΉοΈMerchant controls
      • πŸ›£οΈSmart Router
        • Rule Based Routing
        • Volume Based Routing
        • Default Fallback Routing
      • πŸ›‘οΈFraud & risk management
      • πŸ”ƒSmart retries
      • πŸŽ›οΈAnalytics & operations
      • πŸ“‹3DS decision manager
        • Setup guide
      • πŸ“‹Surcharge
        • Surcharge Setup guide
      • πŸ”Ό3DS Step-up retries
      • 🚩Disputes/Chargebacks Management
      • 🀝Reconciliation
        • Getting Started with Recon
    • πŸ”‘Account management
      • πŸ”’Exporting payments data
      • 🀹Multiple accounts & profiles
      • πŸ›‚Manage your team
    • πŸ›οΈE-commerce platform plugins
      • WooCommerce Plugin
        • Setup
        • Compatibility
        • FAQs
  • SECURITY AND COMPLIANCE
    • πŸ”Overview
    • πŸ’³PCI Compliance
    • πŸ”Data Security
    • πŸ’½GDPR compliance
    • πŸ•΅οΈIdentity and Access Management
  • Learn more
    • 🍑SDK Reference
      • Node
      • React
      • JS
    • πŸ“PaySwitcher Architecture
      • Router
      • Storage
      • A Payments Switch with virtually zero overhead
    • 🌊Payment flows
Powered by GitBook
On this page
  • Requirements
  • 1. Setup the server
  • 1.1 Install the payswitcher-node library
  • 1.2 Create a payment
  • 2. Build checkout page on the client
  • 2.1 Install the flutter_payswitcher library
  • 3. Complete the checkout on the client
  • 3.1 Initialise the PaySwitcher SDK
  • 3.2 Create a Payment Intent
  • 3.3 Initialize your Payment Session
  • 3.4 Present payment sheet and handle response
  • Next step:
  1. PaySwitcher Cloud
  2. Integration guide
  3. Flutter

Flutter with Node Backend

Integrate hyper SDK to your Flutter App using payswitcher-node

PreviousFlutterNextCustomization

Last updated 11 months ago

Use this guide to integrate hyper SDK to your Flutter app.

Before following these steps, please configure your payment methods.

Requirements

  • Android 5.0 (API level 21) and above

  • 7.3.1

  • 7.5.1+

  • iOS 13.0 and above

  • CocoaPods

  • npm

1. Setup the server

1.1 Install the payswitcher-node library

Install the package and import it in your code

$ npm install @payswitcher/payswitcher-node

1.2 Create a payment

const hyper = require("@payswitcher/payswitcher-node")(β€˜YOUR_API_KEY’);

Add an endpoint on your server that creates a Payment. Creating a Payment helps to establish the intent of the customer to start a payment. It also helps to track the customer’s payment lifecycle, keeping track of failed payment attempts and ensuring the customer is only charged once. Return the client_secret obtained in the response to securely complete the payment on the client.

// Create a Payment with the order amount and currency
app.post("/create-payment", async (req, res) => {
  try {
    const paymentIntent = await hyper.paymentIntents.create({
      currency: "USD",
      amount: 100,
    });
    // Send publishable key and PaymentIntent details to client
    res.send({
      clientSecret: paymentIntent.client_secret,
    });
  } catch (err) {
    return res.status(400).send({
      error: {
        message: err.message,
      },
    });
  }
});

2. Build checkout page on the client

2.1 Install the flutter_payswitcher library

Add flutter_payswitcher to your pubspec.yaml file

dependencies:
  flutter_payswitcher: ^version_number

Run the following command to fetch and install the dependencies.

flutter pub get

3. Complete the checkout on the client

3.1 Initialise the PaySwitcher SDK

import 'package:flutter_payswitcher/flutter_payswitcher.dart';
final _hyper = FlutterPaySwitcher();
_hyper.init(HyperConfig(publishableKey: 'YOUR_PUBLISHABLE_KEY', customBackendUrl: 'YOUR_CUSTOM_BACKEND_URL'));

When utilising a custom backend or logging system, you can add the customBackendUrl to HyperConfig

3.2 Create a Payment Intent

Future<String> fetchPaymentParams() async {
    try {
      var response = await http.get(Uri.parse("$API_URL/create-payment"),
      return jsonDecode(response.body)["clientSecret"];
    } catch (error) {
      throw Exception("Create Payment API call failed");
    }
  }

3.3 Initialize your Payment Session

Initialize a Payment Session by passing the clientSecret to the initPaymentSession

final params = PaymentMethodParams(clientSecret: 'YOUR_PAYMENT_INTENT_CLIENT_SECRET');
Session? _sessionId = await _hyper.initPaymentSession(params);

3.4 Present payment sheet and handle response

To display the Payment Sheet, integrate a "Pay Now" button within the checkout page, which, when clicked, invokes the presentPaymentSheet()method and handles the payment response.

Consider the below function, it invokes presentPaymentSheet and handles payment results.

Future<void> _presentPaymentSheet() async {
  final presentPaymentSheetResponse = await _hyper.presentPaymentSheet(_sessionId!);
  if (presentPaymentSheetResponse != null) {
    final message = presentPaymentSheetResponse.message;
    setState(() {
      if (message.isLeft) {
        _statusText =
            "${presentPaymentSheetResponse.status.name}\n${message.left!.name}";
      } else {
        _statusText =
            "${presentPaymentSheetResponse.status.name}\n${message.right}";
      }
    });
  }
}

Next step:

Before creating a payment, import the hyper dependencies and initialize it with your API key. Get your API key from .

Initialise Hyper onto your app with your publishable key with the Hyper constructor. To get a PublishableKey please find it .

Make a network request to the backend endpoint you created in the . The clientSecret returned by your endpoint is used to complete the payment.

Congratulations! Now that you have integrated the Flutter SDK, you can the payment sheet to blend with the rest of your app.

πŸ“¦
⏺️
Android Gradle Plugin
Gradle
AndroidX
PaySwitcher dashboard
here
previous step
customize
πŸ’³Payment methods setup