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 your app
  • 2.1 Configure your repository with PaySwitcher dependency
  • 2.2 Add the PaySwitcher dependency
  • 2.3 Implement the HyperInterface
  • 2.4 Setup the SDK and fetch a Payment
  • 3. Complete the payment on your app
  • Next step:
  1. PaySwitcher Cloud
  2. Integration guide
  3. Android

Kotlin with Node Backend

Integrate hyper SDK to your Kotlin App using payswitcher-node

PreviousAndroidNextCustomization

Last updated 11 months ago

In this section, you will get detailed instructions for integrating the PaySwitcher native Android SDK for your Android app

Use this guide to integrate hyper SDK to your Android app. You can use this as a reference with your PaySwitcher credentials to test the setup. You can also checkout the to test the payment flow.

Requirements

  • Android 5.0 (API level 21) and above

  • 7.3.1

  • 7.5.1+

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

Before creating a payment, import the payswitcher-node dependencies and initialize it with your API key.

const hyper = require("@payswitcher/hyperwitch-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 your app

2.1 Configure your repository with PaySwitcher dependency

Add the following maven repository to the settings.gradle file

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
           maven {
            url "https://maven.payswitcher.com/release/production/android/maven/1.2.7"
        }
    }
}

2.2 Add the PaySwitcher dependency

Add payswitcher-android to the dependencies block of your build.gradle file to install the SDK

dependencies {

    // PaySwitcher Android SDK
    implementation 'io.payswitcher:payswitcher-android:+'
}

2.3 Implement the HyperInterface

Implement the HyperInterface to your CheckoutActivity

class CheckoutActivity : AppCompatActivity(), HyperInterface {

    // ...
}

2.4 Setup the SDK and fetch a Payment

Setup the SDK with your publishable key

PaymentConfiguration.init(applicationContext, "YOUR_PUBLISHABLE_KEY");

Note: For the Setup, initialise PaymentConfiguration as:

PaymentConfiguration.initWithBackend(applicationContext, "YOUR_PUBLISHABLE_KEY", "YOUR_SERVER_URL");

Fetch a payment by requesting your server for a payment as soon as your view is loaded. Store a reference to the client_secret returned by the server; the Payment Sheet will use this secret to complete the payment later.

3. Complete the payment on your app

Create a PaymentSheet instance using the client_secret retrieved from the previous step. Present the payment page from your view controller and use the PaymentSheet.Configuration struct for customising your payment page.

val configuration = PaymentSheet.Configuration("Your_app, Inc.")

// Present Payment Page
paymentSheet.presentWithPaymentIntent(paymentIntentClientSecret, configuration)

Handle the payment result in the completion block and display appropriate messages to your customer based on whether the payment fails with an error or succeeds.

private fun onPaymentSheetResult(paymentResult: PaymentSheetResult) {
        when (paymentResult) {
            is PaymentSheetResult.Completed -> {
                showToast("Payment complete!")
            }
            is PaymentSheetResult.Canceled -> {
                Log.i(TAG, "Payment canceled!")
            }
            is PaymentSheetResult.Failed -> {
                showAlert("Payment failed", paymentResult.error.localizedMessage)
            }
        }
    }

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

Next step:

πŸ“¦
πŸ“±
App on Google Play Store
Android Gradle Plugin
Gradle
AndroidX
πŸ’³Payment methods setup